There’s (of course) a lot of ways to do this, it can involve a bit of plugin programming too, but not necessarily.
In your case volatile output is perfectly normal (and valid) : several pixels can have the same depth. So you can return a different pixel at times.
So I would separate your technique into 2 stages:
- Find the min depth (without pixel location)
- Extract pixel(s) where pixel depth=min depth.
To find the minimum depth, there’s a lot of ways, easiest one will likely be:
render to a 1x1 texture (R32_Float) in vertex shader set all your pixels to write to 0,0,0,1 coordinate and pass depth value as texture coordinate. write this depth value as final color.
Set blend state to minimum.
In a second pass create a buffer of stride 12 (float3 for position/depth), which should be appendable, reset counter every frame in renderer.
In compute shader process every pixel and append when depth <= min depth.
That’s more or less it.