Sign in to follow this  
NiteLordz

Shaders and Named StructuredBuffers

Recommended Posts

NiteLordz    808
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.
[code]cbuffer PerFrame {
float4 something;
}[/code]

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.
[code]pd3dImmediateContext->CSSetUnorderedAccessViews( 0, 1, ppUAViewNULL, NULL );[/code]

ex.
[code]pd3dImmediateContext->CSSetShaderResources( 0, 2, ppSRVNULL );[/code]

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
MJP    19786
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this