Jump to content

  • Log In with Google      Sign In   
  • Create Account


Compute Shader - Shader Resource View


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 NiteLordz   Members   -  Reputation: 369

Like
0Likes
Like

Posted 20 February 2012 - 11:39 AM

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
Code makes the man

Sponsor:

#2 Tsus   Members   -  Reputation: 988

Like
0Likes
Like

Posted 20 February 2012 - 12:38 PM

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!

Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)


#3 NiteLordz   Members   -  Reputation: 369

Like
0Likes
Like

Posted 20 February 2012 - 01:09 PM

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
Code makes the man

#4 MJP   Moderators   -  Reputation: 10243

Like
0Likes
Like

Posted 20 February 2012 - 01:35 PM

ftou will directly interpret the bits of a floating-point number as an unsigned integer, it won't do any conversions.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS