DirectX 12 Render to Stencil Heap

Started by
5 comments, last by NikiTo 6 years, 1 month ago

I need to share heap between RTV and Stencil. I need to render to a texture and without copying it(only changing the barriers, etc) to be able to use that texture as stencil. without copying nothing around. But the creating of the placed resource fails. I think it could be because of the D3D12_RESOURCE_DESC has 8_UINT format, but D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL enabled too, and MSDN says Stencil does not support that format. Is the format the problem? And if the format is the problem, what format I have to use?

For the texture of that resource I have the flags like: "D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL" and it fails, but when I remove the allow-stencil flag, it works.

Advertisement

As far as I know, you can't make an RTV for a stencil buffer. 

However, some GPUs do allow pixel shaders to write arbitrary values into a stencil buffer via a DSV, using the SV_StencilRef output: https://msdn.microsoft.com/en-us/library/windows/desktop/dn914602(v=vs.85).aspx

Heap aliasing doesn't allow for data inheritance between multiple placed resources, only for memory re-use. If you need your data to be in a stencil buffer, you'll need to figure out a way to write it as stencil.

Thanks, guys! Judging by the example given in the link to MSDN, I guess it would be complicated to render to multiple render targets, plus a stencil.
Now I am rendering to 5 multiple render targets and 4 of them are regular textures, but the fifth is gonna be used as a stencil. I will try later to compile a shader where one of the MRTs is a stencil output.

The pixel shader does not compile with shader model 5.1.
I checked for PSSpecifiedStencilRefSupported and one of the adapters does support it, but it keeps failing for that adapter. (integrated Intel lacks support, but ATI/AMD has it)

In the shader I have like:

struct PSOutput
{
  float color0 : SV_Target0;
  float color1 : SV_Target1;
  float color2 : SV_Target2;
  float color3 : SV_Target3;
  int stnc : SV_StencilRef;     // When I delete this line, it compiles
}

I don't know how to read that BLOP where the error message comes in. Anyways, maybe the solution is something simple you could point me to.

ok, it compiles if I return the SV_StencilRef semantic from another function. I haven't tested yet if it actually does something. I will not bump this topic anymore.

This topic is closed to new replies.

Advertisement