Jump to content
  • Advertisement
Sign in to follow this  
NiteLordz

Shaders and Named StructuredBuffers

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

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

Share this post


Link to post
Share on other sites
Advertisement
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!