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.

仅能在支持流式资源的设备上使用 Shader 模型 5 的 HLSL 语法。The HLSL syntax for Shader Model 5 is allowed only on devices with streaming resources support. 下表中用于流式资源的每个相关 HLSL 方法接受一个(反馈)或两个(以此顺序的固定和反馈)其他的可选参数。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 状态,则需要向 Sample 显式提供 offset 和 clamp 参数,即使在逻辑上可能不需要它们。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.

以下是更改为支持 feedback 和/或 clamp 的 HLSL 方法的摘要表。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








































相关主题Related topics

对流式资源的管道访问Pipeline access to streaming resources