共用方式為


串流輸出語法

具有資料流程輸出的幾何著色器會以特定語法宣告。 本主題描述語法。 在效果執行時間中,此語法會轉換成 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 輸出宣告的資料流程輸出單位,以及一個資料流程轉譯器單位。

Stream Out 宣告語法

" [ Buffer: ] Semantic[ SemanticIndex ] [ .Mask ]; [ ... ; ] ... [ ... ;]"
名稱 描述
Buffer 選擇性。 整數 0 < = 緩衝區 < 4,指定值將移至哪個資料流程輸出緩衝區。
語義 字串以及 SemanticIndex,指定要輸出的值。
SemanticIndex 選擇性。 與 Semantic 相關聯的索引。
Mask 選擇性。 元件遮罩,表示要輸出的值元件。

 

有一個特殊語意,標示為「$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 (效果)