Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shaders and Named StructuredBuffers


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
2 replies to this topic

#1 NiteLordz   Members   -  Reputation: 369

Like
0Likes
Like

Posted 23 February 2012 - 09:50 AM

So i have a couple of shaders, not a couple, but that doesn't really matter. More concerned with one in particular. I have a custom offline shader compiler that compiles the code, variations of the shader, and saves out the information to a custom format my engine then loads. This works great for all of my previous shaders.

I use reflection to get the named parameters

ex.
cbuffer PerFrame {
float4 something;
}

I get the name something back, and then i can use that name ( stringhash ) to set my shader constants. Now i have moved onto using StructuredBuffers as they give me a little more speed, however, all the examples i have seen that use StructuredBuffers, when they set hte shader resource, they set it as an index value

ex.
pd3dImmediateContext->CSSetUnorderedAccessViews( 0, 1, ppUAViewNULL, NULL );

ex.
pd3dImmediateContext->CSSetShaderResources( 0, 2, ppSRVNULL );

inside my offline compiler, when i step thru, and examine the refection code, i notice that the buffer is named "$Element", which doesn't do me any good for the most part.

My question is, is it possible to name StructuredBuffers and be able to gain access to that name thru reflection?

if not, i am afraid that hardcoding the startSlot of the buffers will become troublesome, if i start adding in additional buffers, and then manipulate the shader, but forget to change the start slot numbers

Thanks much for any help
Code makes the man

Sponsor:

#2 MJP   Moderators   -  Reputation: 10539

Like
2Likes
Like

Posted 23 February 2012 - 04:30 PM

Once you get your ID3D11ShaderReflection interface, loop through all of the resource binding descriptions using GetResourceBindingDesc (you can get the number of resource bindings by calling GetDesc and checking the BoundResources member of the D3D11_SHADER_DESC struct). The D3D11_SHADER_INPUT_BIND_DESC struct you get back will have the name, type, and slot of the resource. So for a structured buffer the type will be D3D11_SIT_STRUCTURED if it's an SRV, and D3D11_SIT_UAV_RWSTRUCTURED if it's a UAV. The slot that you use for SetShaderResources will be in the BindPoint member.

#3 NiteLordz   Members   -  Reputation: 369

Like
0Likes
Like

Posted 23 February 2012 - 06:14 PM

Thanks very much, this is exactly what i was looking for
Code makes the man




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