流出语法

使用特定语法声明带流出的几何着色器。 本主题介绍语法。 在效果运行时中,此语法将转换为对 ID3D11Device::CreateGeometryShaderWithStreamOutput的调用。

构造语法

[ StreamingShaderVar = ] ConstructGSWithSO( ShaderVar, "OutputDecl0" )
名字 描述
StreamingShaderVar 自选。 唯一标识流出几何着色器变量名称的 ASCI 字符串。这是可选的,因为 ConstructGSWithSO 可以直接放置在 SetGeometryShader 或 BindInterfaces 调用中。
ShaderVar 几何着色器或顶点着色器变量。
OutputDecl0 定义流 0 中的着色器输出的字符串。有关语法,请参阅下文。

 

这是在fx_4_0文件中定义的语法。 请注意,在gs_4_0和vs_x着色器中,只有一个数据流。 生成的着色器会将一个流输出到流输出单元和光栅器单元。

[ StreamingShaderVar = ] ConstructGSWithSO( ShaderVar, "OutputDecl0", "OutputDecl1", "OutputDecl2", 
"OutputDecl3", RasterizedStream )
名字 描述
StreamingShaderVar 自选。 唯一标识流出几何着色器变量名称的 ASCI 字符串。这是可选的,因为 ConstructGSWithSO 可以直接放置在 SetGeometryShader 或 BindInterfaces 调用中。
ShaderVar 几何着色器或顶点着色器变量。
OutputDecl0 定义流 0 中的着色器输出的字符串。有关语法,请参阅下文。
OutputDecl1 定义流 1 中的着色器输出的字符串。有关语法,请参阅下文。
OutputDecl2 定义流 2 中的着色器输出的字符串。有关语法,请参阅下文。
OutputDecl3 定义流 3 中的着色器输出的字符串。有关语法,请参阅下文。
RasterizedStream 一个整数,指定将发送到光栅器的流。

 

请注意,gs_5_0着色器最多可以定义四个数据流。 生成的着色器会将一个流输出到每个非NULL 的流输出单元, 输出声明和一个流式传输光栅器单元。

流出声明语法

" [ Buffer: ] Semantic[ SemanticIndex ] [ .Mask ]; [ ... ; ] ... [ ... ;]"
名字 描述
缓冲区 自选。 整数,0 <= 缓冲区 < 4,指定值将转到的流出缓冲区。
语义 一个字符串,以及 SemanticIndex,指定要输出的值。
SemanticIndex 自选。 与 Semantic 关联的索引。
掩码 自选。 组件掩码,指示要输出的值的哪些组件。

 

有一个特殊的语义,标记为“$SKIP”,指示空语义,将相应的内存保留在流外缓冲区中不受触摸。 $SKIP语义不能有 SemanticIndex,但可以有掩码。

整个流出声明可以 NULL

struct GSOutput
{
int4 Pos : Position;
int4 Color : Color;
int4 Texcoord : Texcoord;
};

[maxvertexcount(1)]
void gsBase (inout PointStream<GSOutput> OutputStream, inout PointStream<GSOutput> OutputStream1)
{
GSOutput output;
output.Pos = int4(1,2,3,4);
output.Color = int4(5,6,7,8);
output.Texcoord = int4(9,10,11,12);
OutputStream.Append(output);

output.Pos = int4(1,2,3,4);
    output.Color = int4(5,6,7,8);
output.Texcoord = int4(9,10,11,12);
OutputStream1.Append(output);
};


GeometryShader pGSComp = CompileShader(gs_5_0, gsBase());
GeometryShader pGSwSO = ConstructGSWithSO(pGSComp, "0:Position.xy; 1:Position.zw; 2:Color.xy", 
                                                   "3:Texcoord.xyzw; 3:$SKIP.x;", NULL, NULL, 1);

// The following two passes perform the same operation
technique11 SOPoints
{
    pass 
    {
        SetGeometryShader(ConstructGSWithSO(pGSComp, "0:Position.xy; 1:Position.zw; 2:Color.xy", 
                                                     "3:Texcoord.xyzw; 3:$SKIP.x;", NULL, NULL, 1));
    }
    pass 
    {
        SetGeometryShader(pGSwSO);
    }
}

效果 (Direct3D 11)