Shaders and Named StructuredBuffers

Started by
1 comment, last by NiteLordz 12 years, 1 month ago
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
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.
Thanks very much, this is exactly what i was looking for
Code makes the man

This topic is closed to new replies.

Advertisement