2011-09-26 58 views
4

PSSetShaderResource()的第一個參數:什麼的佔用ID3D11DeviceContext :: PSSetShaderResource()

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

StartSlot:‘索引到設備的從零開始的數組,開始設置着色器資源’

那麼,有什麼整數索引和你的.hlsl變量之間的關係?在d3d9中,所有內容都是基於字符串的名稱。現在,這些整數指數似乎缺了點什麼......

假設你有一個着色器文件:

// shader_1.psh 
Texture2D tex ; 

而另一..

// shader_2.psh 
TextureCube cubeTex ; 

如果你只使用shader_1.psh,當他們在不同的文件中時,你怎麼區分它們?

// something like this.. 
d3d11devicecontext->PSSetShaderResources(0, 1, &texture2d) ; 
// index 0 sets 0th texture.. 
// what index is the tex cube? 

回答

3

這仍然是一個實驗驗證猜想(未找到引用文檔),但我相信你能做到這一點,像這樣:

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

所以,現在,從C++代碼,綁定一個D3D11Texture2D*在着色器tex,領帶起來就是:

// C++ 
d3d11devicecontext->PSSetShaderResources(0, 1, &texture2d) ; // SETS TEX @ register(t0) 
d3d11devicecontext->PSSetShaderResources(1, 1, &textureCUBE) ;//SETS TEX @ register(t1) 
+2

看來,在DirectX 11 API參數名「插槽」的概念是實際上意味着直接的「寄存」的概念,以對應在HLSL。目前在DX11 MSDN文章中沒有任何記載,但這是一個關鍵信息。此外,「t」前綴表示「紋理寄存器插槽」,「b」表示「恆定緩衝寄存器插槽」等等。 –

相關問題