Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

DX11 DirectCompute UAV between CS and PS

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

(I apologize if this is a bit verbose, but I want to make sure I cite everything I'm doing).

 

I am trying to get the basics of DirectCompute up and running.  I want to have a compute shader that fills out an array, which I can then use in my pixel shader.  I am specifically trying to get an array of data here, not a texture, because of how I eventually intend to use this.

 

So I do my calls to D3DX11CompileFromFile, CreateComputeShader, CSSetShader, and everything seems fine (no error messages).  My target buffer is a 32x32 array of float4 data.  I called CreateUnorderedAccessView with a buffer and a descriptor calling out that size.  Here is what my compute shader looks like:

.

RWStructuredBuffer<float4> dataBuffer : register(u0);

[numthreads(16, 16, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
	dataBuffer[DTid.y * 32 + DTid.x] = float4(DTid.x / 32.0, 0.0, DTid.y / 32.0, 1.0);
}

.

I call UseProgram, CSSetUnorderedAccessViews(0, 1, &UAV, &initCounts), and then Dispatch(2, 2, 1).  Everything seems fine.  Now I want to see this data in the pixel shader, just as a debugging exercise.  So this is my pixel shader (it's just being performed on a quad):

.

struct PixelInputType
{
	float4 position : SV_POSITION;
	float2 uv : TEXCOORD0;
};

RWStructuredBuffer<float4> dataBuffer : register(u1);

float4 main(PixelInputType input) : SV_TARGET
{
	int x = (int)(input.uv.x * 32.0);
	int y = (int)(input.uv.y * 32.0);
	return dataBuffer[y * 32 + x];
}

.

The intention being to just see a red/blue gradient.  I render this like I've rendered countless other quads, but I try to bind the UAV with OMSetRenderTargetsAndUnorderedAccessViews(D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, NULL, NULL, 1, 1, &UAV, &initCounts);

 

 

...

 

 

I get no errors, but my pixel shader shows me absolutely nothing.  Does that at least look like the right sequence of calls?  I'm scratching my head as to what could have went wrong and where.

Share this post


Link to post
Share on other sites
Advertisement

3 things:

 

1. If you haven't done it already, make sure that you've created your device with D3D11_CREATE_DEVICE_DEBUG, and then check your native debugging output stream for any errors or warnings. I also prefer to use ID3D11InfoQueue::SetBreakOnSeverity to make the device break into the debugger on warnings and errors. 

 

2. Try using a debugging tool such as RenderDoc or the Visual Studio Graphics Debugger to inspect your context state at the time of your draw call, so that you can verify that the resource is bound to the appropriate slot. EDIT: you can also use these tools to inspect the contents of your buffer, in order to make sure that your compute shader is actually writing the data that you expect.

 

3. If you're just reading from a buffer or texture in a shader, then you probably want to use a shader resource view instead of an unordered access view. Doing this is kind of like enforcing const-correctness, in that it allows you to guarantee that the shader isn't going to modify the resource. It can also potentially allow the driver to handle things more optimally if it knows that you're not going to write to a resource.

Edited by MJP

Share this post


Link to post
Share on other sites

I thought that the compute shaded had to use a UAV in order to run in parallel?  Or do you mean to just use an SRV on the pixel shader side?  If so, do I just bind the same buffer but declare it as a cbuffer in the pixel shader?  Are there performance implications for doing it one way or another?  (I'm sorry if this information is already out there, I've searched around quite a bit and haven't really found a solid resource yet on getting the compute shader outputs into the rendering pipeline)

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.

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!