Jump to content
  • Advertisement
penguinnn

DX12 How can I specify which render target I'm binding to with a RWTexture2D?

Recommended Posts

I'm very new to D3D programming, and previously I always bind explicitly my texture to a render target. This time since I need to write values to a texture and then use that texture as an input, I want to try RWTexture2D. However, since I'm also using my previous method to specify other render target (I have a output color texture and other outputs), I have no idea how the order of the render targets will be..

 

    pDstFbo->attachColorTarget(pDstTex, 0);
    pDstFbo->attachColorTarget(pMomentsTex, 1);

(I'm using some frameworks but the code should be straightforward.)

 

What if I want to bind my RWTexture2D texture to render target at slot 2? Can I specify this in the shader code? 

RWTexture2D gPrevMoments;	// current code, which do not specify which slot in the render target it is bound to

Can I do

RWTexture2D gPrevMoments : register(u2);	// bind to render target SV_TARGET2?

 

Share this post


Link to post
Share on other sites
Advertisement

Unordered Access Views (UAVs) work differently in D3D12 than they did in D3D11, since D3D12 has entirely new binding model. In D3D11 if you wanted to write to a UAV (such as a RWBuffer or RWTexture2D) from a pixel shader, you had to use OMSetRenderTargetsAndUnorderedAccessViews and bind all of your render targets and UAVs to shared render target slots. In D3D12 you instead need to build a root signature that includes a UAV descriptor range, and then make sure that you bind a descriptor table containing UAV descriptors to the corresponding root descriptor slot on the command list. It's basically if the same thing that you do for binding SRVs (read-only textures and buffers), if you're familiar with how that works.

FYI you can bind a RWTexture2D to a UAV slot using that "register" syntax that you mentioned. In D3D11 that UAV slot will correspond to a render target slot (so the same slot as SV_Target2), while in D3D12 you need to specify how that slot maps to your descriptor table(s) when building your root signature.

Share this post


Link to post
Share on other sites
Posted (edited)
On 4/1/2019 at 9:50 PM, MJP said:

Unordered Access Views (UAVs) work differently in D3D12 than they did in D3D11, since D3D12 has entirely new binding model. In D3D11 if you wanted to write to a UAV (such as a RWBuffer or RWTexture2D) from a pixel shader, you had to use OMSetRenderTargetsAndUnorderedAccessViews and bind all of your render targets and UAVs to shared render target slots. In D3D12 you instead need to build a root signature that includes a UAV descriptor range, and then make sure that you bind a descriptor table containing UAV descriptors to the corresponding root descriptor slot on the command list. It's basically if the same thing that you do for binding SRVs (read-only textures and buffers), if you're familiar with how that works.

FYI you can bind a RWTexture2D to a UAV slot using that "register" syntax that you mentioned. In D3D11 that UAV slot will correspond to a render target slot (so the same slot as SV_Target2), while in D3D12 you need to specify how that slot maps to your descriptor table(s) when building your root signature.

@MJP Hi thanks for the reply. I'm actually really not very familiar with how D3D work behind. Is there any good resources to understand that?

 

So basically why am I having this question is because it seems for one draw call, D3D can only draw to 8 render target. So if I use a RWTexture2D, does that occupy a render target slot? If it does, then how can I know which one I bind to so that I can manipulate..

Edited by penguinnn

Share this post


Link to post
Share on other sites

You tagged your thread with "DX12" so I was assuming that this was the API that you were using. Is that the case here, or are you using D3D11?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!