HLSL 串流資源曝光HLSL streaming resources exposure

需要特定的 Microsoft 高階著色器語言 (HLSL) 語法,才能在 著色器模型 5中支援串流資源。A specific Microsoft High Level Shader Language (HLSL) syntax is required to support streaming resources in Shader Model 5.

著色器模型 5 的 HLSL 語意只允許在支援串流資源的裝置上使用。The HLSL syntax for Shader Model 5 is allowed only on devices with streaming resources support. 下表中串流資源的每一種相關的 HLSL 方法都可接受一個 (feedback) 或兩個 (clamp 和 feedback,依此順序) 額外的選用參數。Each relevant HLSL method for streaming resources in the following table accepts either one (feedback) or two (clamp and feedback in this order) additional optional parameters. 例如,Sample 方法為:For example, a Sample method is:

**範例 (取樣器、位置 [ 、位移 [ 、夾具 [ 、意見反應 ] ] ]) **Sample(sampler, location [, offset [, clamp [, feedback] ] ])

Sample 方法的範例為 Texture2D.Sample(S,float,int,float,uint)An example of a Sample method is Texture2D.Sample(S,float,int,float,uint).

offset、clamp 和 feedback 參數為選用。The offset, clamp and feedback parameters are optional. 您必須指定所有選用參數,直到您需要的參數,這與 C++ 對於預設函數引數的規則相同。You must specify all optional parameters up to the one you need, which is consistent with the C++ rules for default function arguments. 例如,如果需要 feedback 狀態,offset 和 clamp 兩個參數就需要明確提供給 Sample,即使邏輯上可能不需要它們。For example, if the feedback status is needed, both offset and clamp parameters need to be explicitly supplied to Sample, even though they may not be logically needed.

clamp 參數是純量浮點值。The clamp parameter is a scalar float value. clamp=0.0f 的常值表示 clamp 作業未執行。The literal value of clamp=0.0f indicates that the clamp operation isn't performed.

feedback 參數是 uint 變數,您可以將它提供給記憶體存取查詢內建 CheckAccessFullyMapped 函數。The feedback parameter is a uint variable that you can supply to the memory-access querying intrinsic CheckAccessFullyMapped function. 您不得修改或解譯 feedback 參數值;不過編譯器不會提供任何進階分析和診斷,來偵測您是否修改此值。You must not modify or interpret the value of the feedback parameter; but, the compiler doesn't provide any advanced analysis and diagnostics to detect whether you modified the value.

以下是 CheckAccessFullyMapped 的語法:Here is the syntax of CheckAccessFullyMapped:

bool CheckAccessFullyMapped(in uint FeedbackVar);bool CheckAccessFullyMapped(in uint FeedbackVar);

CheckAccessFullyMapped 解譯 FeedbackVar 的值,並傳回 true,如果所有存取的資料都在資源中對應;否則 CheckAccessFullyMapped 傳回 false。CheckAccessFullyMapped interprets the value of FeedbackVar and returns true if all data being accessed was mapped in the resource; otherwise, CheckAccessFullyMapped returns false.

如果 clamp 或 feedback 參數存在,編譯器會發出基本指令的變化。If either the clamp or feedback parameter is present, the compiler emits a variant of the basic instruction. 例如,串流資源的範例會產生 sample_cl_s 指令。For example, sample of a streaming resource generates the sample_cl_s instruction.

如果 clamp 和 feedback 都未指定,編譯器就會發出基本指令,目前行為也就沒有變更。If neither clamp nor feedback is specified, the compiler emits the basic instruction, so that there is no change from the current behavior.

clamp 值為 0.0f,表示不會執行 clamp;因此,驅動程式編譯器可進一步依照目標硬體建立指令。The clamp value of 0.0f indicates that no clamp is performed; thus, the driver compiler can further tailor the instruction to the target hardware. 如果 feedback 為指令中的 NULL 暫存器,則 feedback 未使用;因此,驅動程式編譯器可以進一步依照目標架構建立指令。If feedback is a NULL register in an instruction, the feedback is unused; thus, the driver compiler can further tailor the instruction to the target architecture.

如果 HLSL 編譯器推斷 clamp 為 0.0f 且 feedback 未使用,則編譯器會發出對應的基本指令 (例如 sample 而非 sample_cl_s)。If the HLSL compiler infers that clamp is 0.0f and feedback is unused, the compiler emits the corresponding basic instruction (for example, sample rather than sample_cl_s).

如果串流資源存取是由數個要素位元組程式碼指令所組成,例如結構化資源,則編譯器會透過 OR 作業彙總個別 feedback 值,產生最終的 feedback 值。If a streaming resource access consists of several constituent byte code instructions, for example, for structured resources, the compiler aggregates individual feedback values via the OR operation to produce the final feedback value. 因此,您會看到這類複雜存取的單一 feedback 值。Therefore, you see a single feedback value for such a complex access.

這是 HLSL 方法的摘要表,已變更為支援 feedback 和/或 clamp。This is the summary table of HLSL methods that are changed to support feedback and/or clamp. 這些全都可在所有維度的拼接和非串流資源上運作。These all work on tiled and non-streaming resources of all dimensions. 非串流資源一律顯示為完整對應。Non-streaming resources always appear to be fully mapped.

HLSL 物件 HLSL objects 包含 feedback 選項 (\*) 的內建方法 - 也有 clamp 選項Intrinsic methods with feedback option (\*) - also has clamp option

[RW]Texture2D[RW]Texture2D

[RW]Texture2DArray[RW]Texture2DArray

TextureCUBETextureCUBE

TextureCUBEArrayTextureCUBEArray

GatherGather

GatherRedGatherRed

GatherGreenGatherGreen

GatherBlueGatherBlue

GatherAlphaGatherAlpha

GatherCmpGatherCmp

GatherCmpRedGatherCmpRed

GatherCmpGreenGatherCmpGreen

GatherCmpBlueGatherCmpBlue

GatherCmpAlphaGatherCmpAlpha

[RW]Texture1D[RW]Texture1D

[RW]Texture1DArray[RW]Texture1DArray

[RW]Texture2D[RW]Texture2D

[RW]Texture2DArray[RW]Texture2DArray

[RW]Texture3D[RW]Texture3D

TextureCUBETextureCUBE

TextureCUBEArrayTextureCUBEArray

Sample\*Sample\*

SampleBias\*SampleBias\*

SampleCmp\*SampleCmp\*

SampleCmpLevelZeroSampleCmpLevelZero

SampleGrad\*SampleGrad\*

SampleLevelSampleLevel

[RW]Texture1D[RW]Texture1D

[RW]Texture1DArray[RW]Texture1DArray

[RW]Texture2D[RW]Texture2D

Texture2DMSTexture2DMS

[RW]Texture2DArray[RW]Texture2DArray

Texture2DArrayMSTexture2DArrayMS

[RW]Texture3D[RW]Texture3D

[RW]Buffer[RW]Buffer

[RW]ByteAddressBuffer[RW]ByteAddressBuffer

[RW]StructuredBuffer[RW]StructuredBuffer

載入Load

 

相關主題Related topics

串流資源的存取管線Pipeline access to streaming resources