I’ve implemented mouse picking in my app by using a stencil buffer.
Here’s the pixel shader that reads value under the mouse:
Texture2DMS<uint2> depthStencilTexture : register( t0 );
cbuffer ReadDepthInput : register( b2 )
{
int2 readPosition;
}
// Produces vector3( x, y, stencilValue )
float4 main() : SV_Target0
{
uint2 res = depthStencilTexture.Load( readPosition, 1 );
float stencil = res.y;
// Scale the result from integers to 0..1
stencil /= 255.0f;
return float4( float( readPosition.x ) / 65535.0f, float( readPosition.y ) / 65535.0f, stencil, 0 );
}
The code works on nVidia and AMD GPUs, works on Intel Iris 550.
The code fails on Intel Haswell GPUs (Intel HD 5000, Intel HD 4600). Texture2DMS.Load just returns 0. Any ideas what might be wrong?
Update: Only happens with 8x MSAA. Decreasing it to 4x works OK even on those affected Intel GPUs.