SM5.1 中的位元組程式代碼變更
SM5.1 會變更如何在指示中宣告和參考資源緩存器。
SM5.1 會向宣告緩存器「變數」的方向移動,類似於群組共用記憶體緩存器的完成方式,如下列範例所示:
Texture2D<float4> tex0 : register(t5, space0);
Texture2D<float4> tex1[][5][3] : register(t10, space0);
Texture2D<float4> tex2[8] : register(t0, space1);
SamplerState samp0 : register(s5, space0);
float4 main(float4 coord : COORD) : SV_TARGET
{
float4 r = coord;
r += tex0.Sample(samp0, r.xy);
r += tex2[r.x].Sample(samp0, r.xy);
r += tex1[r.x][r.y][r.z].Sample(samp0, r.xy);
return r;
}
此範例的反組譯如下:
// Resource Bindings:
//
// Name Type Format Dim Space Slot Elements
// ------------------------------ ---------- ------- ----------- ----- ---- ---------
// samp0 sampler NA NA 0 5 1
// tex0 texture float4 2d 0 5 1
// tex1[0][5][3] texture float4 2d 0 10 unbounded
// tex2[8] texture float4 2d 1 0 8
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// COORD 0 xyzw 0 NONE float xyzw
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_5_1
dcl_globalFlags refactoringAllowed
dcl_sampler s0[5:5], mode_default, space=0
dcl_resource_texture2d (float,float,float,float) t0[5:5], space=0
dcl_resource_texture2d (float,float,float,float) t1[10:*], space=0
dcl_resource_texture2d (float,float,float,float) t2[0:7], space=1
dcl_input_ps linear v0.xyzw
dcl_output o0.xyzw
dcl_temps 2
sample r0.xyzw, v0.xyxx, t0[0].xyzw, s0[5]
add r0.xyzw, r0.xyzw, v0.xyzw
ftou r1.x, r0.x
sample r1.xyzw, r0.xyxx, t2[r1.x + 0].xyzw, s0[5]
add r0.xyzw, r0.xyzw, r1.xyzw
ftou r1.xyz, r0.zyxz
imul null, r1.yz, r1.zzyz, l(0, 15, 3, 0)
iadd r1.y, r1.z, r1.y
iadd r1.x, r1.x, r1.y
sample r1.xyzw, r0.xyxx, t1[r1.x + 10].xyzw, s0[5]
add o0.xyzw, r0.xyzw, r1.xyzw
ret
// Approximately 12 instruction slots used
每個著色器資源範圍現在都有著色器位元組程序代碼中的標識元(名稱)。 例如,tex1 紋理陣列會在著色器位元組程式代碼中變成 't1'。 為每個資源範圍提供唯一標識碼可讓兩件事:
- 明確識別指令中正在編製索引的資源範圍(請參閱dcl_resource_texture2d)。請參閱範例指示。
- 將一組屬性附加至宣告,例如元素類型、步幅大小、點陣作業模式等等。
請注意,範圍標識碼與 HLSL 下限宣告無關。
反映資源系結和著色器宣告指令的順序相同,有助於識別 HLSL 變數與位元組程式代碼識別碼的對應。
SM5.1 中的每個宣告指令都會使用 3D作數來定義:範圍標識元、下限和上限。 發出額外的令牌以指定緩存器空間。 其他令牌也可以發出,以傳達範圍的其他屬性,例如 cbuffer 或結構化緩衝區宣告指令會發出 cbuffer 或 結構的大小。 您可以在 d3d12TokenizedProgramFormat.h 和 D3D10ShaderBinary::CShaderCodeParser 中找到編碼的確切詳細數據。
SM5.1 指令不會發出其他資源作數資訊作為指令的一部分(如 SM5.0 所示)。 這項信息現在已移至宣告指示。 在SM5.0中,指示索引資源所需的資源屬性,以在擴充的opcode令牌中描述,因為索引混淆了宣告的關聯。 在 SM5.1 中,每個標識碼(例如 't1') 都明確與描述必要資源資訊的單一宣告相關聯。 因此,不再發出用於描述資源資訊的指示上的擴充 opcode 令牌。
在非宣告指示中,取樣器、SRV 和 UAV 的資源作數是 2D 作數。 第一個索引是指定範圍標識碼的常值常數。 第二個索引代表索引的線性化值。 此值會相對於對應緩存器空間的開頭計算(而不是邏輯範圍的開頭),以更好地與根簽章相互關聯,並減少調整索引的驅動程式編譯程序負擔。
CBV 的資源作數是 3D作數:範圍常值標識碼、cbuffer 的索引、位移到 cbuffer 的特定實例。
相關主題