Jump to content
  • Advertisement
Sign in to follow this  

Relationship between resource input slot and HLSL side resource

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

I've been setting shader resources in many a shader for quite a while but embarassingly I've never understood one basic thing: Lets say in HLSL I declare a few textures and a structured buffer and use them in a vertexx and pixel shader (this is a hypothetical example, I know its not realistic)

Texture2D albedoMap;
Texture2D surfaceMap;
Texture2D normalMap;
StructuredBuffer<SomeStruct> someBuffer

PixelShaderIn VertexShader( VertexShaderIn input )
// use albedoMap, normalMap and someBuffer

PixelShaderOut PixelShader( PixelShaderIn input )
// use surfaceMap and someBuffer

Now when I am setting these client side with

ImmediateContext->VSSetShaderResources( ?, ?, &SRV )


ImmediateContext->PSSetShaderResources( ?, ?, &SRV )

How do the start and end slots correspond to the resources as declared in the shader? For example if I set the start slot to 0 and end slot to 1 with the above HLSL code for the PixelShader would I be setting albedoMap or surfaceMap and would it be different for the vertex shader? In other words what determines what HLSL side shader variable each client side input slot corresponds to. Is it the order they are declared? Is it the order they are declared but only for the ones a given shader program uses?

This is probably an extremely nooby question but I haven't been able to find the answer on MSDN or elsewhere (perhaps its just too obvious to even be said, but hell it confuses me)

Share this post

Link to post
Share on other sites
If you don't explicitly specify the slot yourself in the HLSL code, the compiler binds it to a slot for you. The method used for binding isn't defined (so you shouldn't rely on it), but it usually just does it in the order that the resources are declared starting with slot 0. Either way, you can always query the resource slot at runtime through ID3D11ShaderReflection::GetResourceBindingDesc and ID3D11ShaderReflection::GetResourceBindingDescByName (the resource bind slot is in the "BindPoint" member of the D3D11_SHADER_INPUT_BIND_DESC struct that you get back.

Also if you don't know how to manually bind resources to slots, it's done like this:

// Constant buffers
cbuffer SomeConstants : register(cb0)
float4x4 World : packoffset(c0);
float4x4 View : packoffset(c4);
float4x4 WorldViewProjection : packoffset(c8);

// Shader resources
Texture2D<float2> SomeTexture : register(t0);

// Samplers
SamplerState SomeSampler : register(s0);

// Outputs
RWTexture2D<float2> SomeOutputTexture : register(u0);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!