Jump to content
  • Advertisement
Sign in to follow this  
NiteLordz

DX11 Compute Shader - Shader Resource View

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

Currently i am working on my first attempt at integrating Compute Shaders into my engine. Recently i ported my engine over to DX11. Currently i support VS, GS, and PS. so the next step is logically, CS.

I have gone thru and "wrapped" the functionality that allows me to create the Buffer, UAV and the SRV for the buffer.

I can set the CS, the UAV and i dispatch, which executes the CS, and i verify the output by copying the UAV to a staging buffer ( ala DX SDK examples ). the UAV contains the expected values.

The problem comes when i try to set the associated Shader Resource View for the buffer. Using pix, the Shader Resource says the buffer is filled with 0's. However, it should be filled with 1's ( just for debug purposes ).

The shader i am using, works if i hard code the values to output, so i know the shader is executing. I have even tried to index into the StructuredBuffer with a constant ( 1 ), so that i know that the threads are not mixing up.

Setting the UAV - This works and has been verified
ID3D11UnorderedAccessView* uav = buffers_[buffer]->GetUnorderedAccess();
immediateContext_->CSSetUnorderedAccessViews(0, 1, &uav, 0);


Passing the Shader Resource to the Shader
ID3D11ShaderResourceView* pFromRV = buffers_[buffer]->GetShaderResource();
ID3D11ShaderResourceView* aRViews[ 1 ] = { pFromRV };
immediateContext_->PSSetShaderResources(0, 1, aRViews);


CopyToFrame Shader - Takes in a buffer, and returns the value
StructuredBuffer<float4> buffer : register( t0 );
cbuffer cbPS : register( b0 ) {
uint4 g_param;
};
void VS(uint VertexID: SV_VertexID, out float2 oTexCoord : TexCoord, out float4 oPosition : SV_Position) {
// Produce a fullscreen triangle
oPosition.x = (VertexID == 2) ? 3.0f : -1.0f;
oPosition.y = (VertexID == 0) ? -3.0f : 1.0f;
oPosition.zw = 1.0f;
oTexCoord = oPosition.xy * float2(0.5f, -0.5f) + 0.5f;
}
void PS(float4 iPosition : SV_Position, out float4 oColor : SV_Target) {
oColor = buffer[1];
}


Thanks for any help you can provide

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Two possible things come to my mind.
Do you unbind the UAV, when your CS was executed?
ID3D11UnorderedAccessView* nouav[] = {NULL};
immediateContext_->CSSetUnorderedAccessViews(0, 1, nouav, 0);

That’s necessary, otherwise d3d will yell warnings at you, when you try to bind a SRV on the resource somewhere else, because you have the buffer still bound as output (i.e. as UAV).

Second, does the shader display the right values when you just clear and not bind the UAV?
float clear[] = {1,0,0,1}; // red color
ID3D11UnorderedAccessView* uav = buffers_[buffer]->GetUnorderedAccess();
immediateContext->ClearUnorderedAccessViewFloat(uav, clear);


Cheers!

Share this post


Link to post
Share on other sites
Yes, i was unbinding it, and it was clearing. My problem was in the CS Shader the buffer was designed as uint4, but the shader resource view buffer was float4. this caused the shader assembly code to do a utof which makes a very large number. making them both uint4, or float4 works.

any thoughts on why ftou turns 16.0 into a very large unsigned number. instead of just making it 16?

thanks much

Share this post


Link to post
Share on other sites
ftou will directly interpret the bits of a floating-point number as an unsigned integer, it won't do any conversions.

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!