共用方式為


串流輸出語法

具有數據流輸出的幾何著色器會以特定語法宣告。 本主題描述語法。 在效果運行時間中,此語法會轉換成呼叫 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 <= Buffer < 4,指定值將移至哪個數據流輸出緩衝區。
語意 字串以及 SemanticIndex,指定要輸出的值。
SemanticIndex 自選。 與 Semantic 相關聯的索引。
遮罩 自選。 元件遮罩,表示要輸出之值的哪些元件。

 

有一個標示為「$SKIP」的特殊語意,表示空的語意,讓數據流中的對應記憶體保持不變。 $SKIP語意不能有 SemanticIndex,但可以有 Mask。

整個資料串流輸出宣告可以 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)