Sign in to follow this  

[D3D12] Writing to UAV from pixel shader

This topic is 735 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

Hello everyone,

?

D3D11 offered OMSetRenderTargetsAndUnorderedAccessViews to bind UAV for direct writing from the pixel shader, which is not exposed explicitly in D3D12.  

 

In my D3D12 app I bind UAV buffer via descriptor table to the pixel shader but do not set render target as it does not make much sense in my case.

As a result pixel shader is never invoked.

 

If I specify render target and a viewport, the pixel shader will be invoked and write to UAV will happen.

 

?Is it possible in D3D12 to write to UAV from the pixel shader without specifying render target?

?

Tx?

 

Share this post


Link to post
Share on other sites

Adam, many thanks for the help!

 

Indeed, I am using 0 for ForcedSampleCount. However, setting it 1 did not solve it. Have never heard of this option.

 

Could you please elaborate on it? Googling did not reveal much information.

 

Also, viewport should it be still specified for the rasterizer?

Edited by _void_

Share this post


Link to post
Share on other sites

You say that you're not binding render targets, but does that include a depth stencil too?

Viewport and Scissor both likely need to be set, but it's a while since I've tried using it. Have you tried using VS2015's Graphics Debugger?

Share this post


Link to post
Share on other sites

Depth test is disabled and DSV is not attached.

 

Actually, I am using VS 2015 graphics debugger to check the content of the buffer after render pass.

 

Also, in the graphics debugger I can see that depth buffer is indeed attached from the render pass I did before.

I do Reset on the command list before I start recording commands for this pass.

 

Shouldn't Reset clear previously recorded commands on the command list? Also, I am waiting for the command list to be executed before resetting it.

Why do I have depth buffer attached from the previous pass according to the graphics debugger?

Edited by _void_

Share this post


Link to post
Share on other sites

I double checked it again. I had different viewport/scissor rect sizes when I was checking buffer content.

Now, buffer content is the same both for with and without render target passes.

 

However, I still have DSV attached in VS graphics debugger.

 

Capture for WithRTV pass

https://www.dropbox.com/s/w6pemgf3pywvq3m/WithRTV.7z?dl=0?

 

WithRTVScreenShot

https://www.dropbox.com/s/beg1nnn12owm7eu/WithRTVScreenShot.png?dl=0?

 

Capture for WithoutRTV pass

https://www.dropbox.com/s/m1zk89e5l1q4wpi/WithoutRTV.7z?dl=0?

 

WithoutRTVScreenShot

https://www.dropbox.com/s/zv8gd04d2sqjfpc/WithoutRTVScreenShot.png?dl=0

 

You can see on the screen shots that buffers have the same content from 18000 entry.

WithRTVScreenShot has no DSV attached only RTV.

WithoutRTVScreenShot? has both RTV and DSV attached.

 

PS: I am using WARP D3D12 mode and checking on AMD R9 290. 

 

Thanks a million for the help!

Edited by _void_

Share this post


Link to post
Share on other sites

So to be clear, you now have ForceSampledCount working now that the viewport and scissor are set correctly?

 

The RTV and DSV will remain bound from earlier command list executions unless you set them to be unbound by passing nullptr through to OMSetRenderTargets, Resetting a command lists simply starts a new command list, it doesn't implicitly unbind everything that has been bound by previously executed command lists. Inserting a ClearState at the start of each Command List would give you that behaviour, but it's not what you want to be doing.

 

Your PSO for your UAV-only draw has no render target formats specified and your Pixel Shader returns void, exactly as it should do. The fact that there still appears to be an RTV and DSV bound for your last draw isn't important since the draw won't attempt to draw to them.

 

If you explicitly unbind them in that last command list does everything continue to work?

Share this post


Link to post
Share on other sites

I was checking with different viewport sizes for with RTV (924X668) and without RTV (64X64) passes.

 

That is why, I was getting less writes to the buffer from the pixel shader.

I gather viewport size still matters for the rasterizer. The pixel shader will not be invoked magically more times even if it writes to the buffer rolleyes.gif

 

Right now, everything is working with unbounded RTV, DSV and ForcedSampleCount = 0.

 

I have never really paid attention to ForcedSampleCount option. Could you please expand on its usage scenarios.

I was able to find only this description https://msdn.microsoft.com/en-us/library/windows/desktop/hh404489(v=vs.85).aspx which is not that obvious to me.

 

Many thanks!?

Share this post


Link to post
Share on other sites

This topic is 735 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.

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

Sign in to follow this