Stencil Write with Clip/Discard

Started by
6 comments, last by Adam Miles 7 years, 6 months ago

Hi, quick question.

If I have stencil write enabled and I'm using clip() in the shader, will a pixel that gets clipped/discarded, still write to the stencil?

This is aimed at D3D11 and D3D12.

Cheers..

Advertisement
A discarded Pixel should not influence anything. So I think it won't write to the stencil buffer.

No, unless you've forced early Z via earlydepthstencil (HLSL) or early_fragment_tests (GLSL) as the stencil operation will happen before the pixel shader discards the fragment.

No, unless you've forced early Z via earlydepthstencil (HLSL) or early_fragment_tests (GLSL) as the stencil operation will happen before the pixel shader discards the fragment.

Wow, I didn't know we could do this in PC. But the document is so brief, it didn't even mention where to put the 'earlydepthstencil'. Is it right before ps main function signature? or it is set during PSO creation? It will be great if you could provide a code snippet :-)

Thanks~~~~

Just before the entry point is fine, i.e.:


[earlydepthstencil]
float4 main() : SV_TARGET
{
   return 0;
}

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Just before the entry point is fine, i.e.:


[earlydepthstencil]
float4 main() : SV_TARGET
{
   return 0;
}

Thanks for such a quick reply, then how to enable ReZ in PC? (sorry for being such a greedy asker, but I can't find related attributes to try)

Big Thanks Again.

Thanks for such a quick reply, then how to enable ReZ in PC? (sorry for being such a greedy asker, but I can't find related attributes to try)
Big Thanks Again.

I don't know what ReZ in PC means.

Just take in mind that the driver will automatically use early depth if it doesn't affect the rendering result. There is no need to explicitly enabled.
Forcing it will not produce the same results when:

  • Using UAVs.
  • Using discard / clip (unless depth writes are off).
  • Using depth out writes (IIRC OpenGL says writes to depth out will be ignored when early Z is forced; I don't recall what D3D11 says it will do)

Just before the entry point is fine, i.e.:


[earlydepthstencil]
float4 main() : SV_TARGET
{
   return 0;
}

Thanks for such a quick reply, then how to enable ReZ in PC? (sorry for being such a greedy asker, but I can't find related attributes to try)

Big Thanks Again.

ReZ cannot be enabled or requested by anything you have control over in DirectX. Whether it's used or not is up to AMD's driver.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

This topic is closed to new replies.

Advertisement