Jump to content
  • Advertisement
Sign in to follow this  
Xeile

DX11 [DX11] [SlimDX] Compute Shaders: Clearing graphic buffers

This topic is 2999 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,

Hobbying away on my project I decided to use compute shaders for the operations I would normally use a fullscreen quad render for.

I am writing a deferred renderer using 6 graphic buffers. For now I clear the graphic buffers with the following compute shader:


//----------------------------------------
// Variables
//----------------------------------------
RWTexture2D<float2> RT_Ambient : register(u0);
RWTexture2D<float4> RT_Color : register(u1);
RWTexture2D<float2> RT_Depth : register(u2);
RWTexture2D<float4> RT_Emissive : register(u3);
RWTexture2D<float4> RT_Final : register(u4);
RWTexture2D<float4> RT_Normal : register(u5);
RWTexture2D<float4> RT_Specular : register(u6);

//----------------------------------------
// Shaders
//----------------------------------------
[numthreads(32, 32, 1)]
void CS
(
uint3 index : SV_DispatchThreadID
)
{
RT_Ambient [index.xy] = float2(1.0, 1.0);
RT_Color [index.xy] = float4(0.0, 0.0, 0.0, 0.0);
RT_Depth [index.xy] = float2(1.0, 1.0);
RT_Emissive [index.xy] = float4(0.0, 0.0, 0.0, 0.0);
RT_Final [index.xy] = float4(0.0, 0.0, 0.0, 1.0);
RT_Normal [index.xy] = float4(0.5, 0.5, 0.5, 0.0);
RT_Specular [index.xy] = float4(0.0, 0.0, 0.0, 0.0);
}




RT_Final is the swapchain here. As you can see, this involves binding 7 view to the device context and also 7 writes.

My other two options are using the ordinary fullscreen quads and writing a value to each bound render target or using ID3D11DeviceContext::ClearUnorderedAccessViewFloat method.

What is the cheapest method to use or how do I determine what is the cheapest method?

Share this post


Link to post
Share on other sites
Advertisement
Any clear function such as clear RTV or clear UAV is probably going to be a fast path for the graphics card. I wouldn't even considering doing it differently unless there is more work to be done during the clear.

Share this post


Link to post
Share on other sites
Quote:
Original post by DieterVW
Any clear function such as clear RTV or clear UAV is probably going to be a fast path for the graphics card. I wouldn't even considering doing it differently unless there is more work to be done during the clear.


Aye, and the only case where you might need to use a shader was if you were setting the backbuffer to a value whose format wasn't the same as that of the input clear color. However (using PIX to examine the contents of the buffer on the DX11 cards I've used), even then it still fills in the correct values every time I've checked.

Share this post


Link to post
Share on other sites
Hmmm, the fast path explanation does sounds logical from a hardware manufacturer POV.

Thanks guys.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!