4

PSSetShaderResource()'s first parameter:

void PSSetShaderResources(
  [in]  UINT StartSlot,
  [in]  UINT NumViews,
  [in]  ID3D11ShaderResourceView *const *ppShaderResourceViews
);

StartSlot: "Index into the device's zero-based array to begin setting shader resources"

So what's the tie up between integer indices and your .hlsl variables? In d3d9, everything was by string-based name. Now these integer indices seem to have something missing......

Say you have one shader file:

// shader_1.psh
Texture2D tex ;

And another..

// shader_2.psh
TextureCube cubeTex ;

If you're only using shader_1.psh, how do you distinguish between them when they are in separate files?

// something like this..
d3d11devicecontext->PSSetShaderResources( 0, 1, &texture2d ) ;
// index 0 sets 0th texture..
// what index is the tex cube?
bobobobo
  • 64,917
  • 62
  • 258
  • 363

1 Answers1

3

This is still an experimentally verified guess (didn't find reference documentation), but I believe you can do it like so:

// HLSL shader
Texture2D tex : register( t0 );
Texture2D cubeTex : register( t1 );
SamplerState theSampler : register( s0 );

So now, from the C++ code, to bind a D3D11Texture2D* to tex in the shader, the tie up is:

// C++
d3d11devicecontext->PSSetShaderResources( 0, 1, &texture2d ) ; // SETS TEX @ register( t0 )
d3d11devicecontext->PSSetShaderResources( 1, 1, &textureCUBE ) ;//SETS TEX @ register( t1 )
bobobobo
  • 64,917
  • 62
  • 258
  • 363
  • 2
    It seems that the notion of "Slot" in the DirectX 11 API parameter-names is actually meant to correspond directly with the notion of "registers" in the HLSL. This is not documented anywhere in the DX11 MSDN articles at the moment, but it's a critical bit of info. Also, the "t" prefix means, "texture register-slot", "b" means "constant-buffer register-slot", etc... – Will Bradley Sep 14 '12 at 20:30