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

## 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 on other sites
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 on other sites
Quote:
 Original post by DieterVWAny 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 on other sites
Hmmm, the fast path explanation does sounds logical from a hardware manufacturer POV.

Thanks guys.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011319
• ### Who's Online (See full list)

There are no registered users currently online

×