What's the tie up ID3D11DeviceContext::PSSetShaderResource()
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?
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 )
精彩评论