• Advertisement
Sign in to follow this  

Stencil Write with Clip/Discard

This topic is 574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Share this post


Link to post
Share on other sites
Advertisement

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~~~~

Share this post


Link to post
Share on other sites

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

[earlydepthstencil]
float4 main() : SV_TARGET
{
   return 0;
}
Edited by Adam Miles

Share this post


Link to post
Share on other sites

 

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. 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

 

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.

Edited by Adam Miles

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement