Commit 5e5b12e9 by LoopDawg

HLSL: add geometry stage support for clip/cull distance

Changes: (1) Allow clip/cull builtins as both input and output in the same shader stage. Previously, not enough data was tracked to handle this. (2) Handle the extra array dimension in GS inputs. The synthesized external variable can now be created with the extra array dimension if needed, and the form conversion code is able to handle it as well. For example, both of these GS inputs would result in the same synthesized external type: triangle in float4 clip[3] : SV_ClipDistance triangle in float2 clip[3][2] : SV_ClipDistance In the second case, the inner array dimension packs with the 2-vector of floats into an array[4], which there is an array[3] of due to the triangle geometry.
parent ea0c1643
struct S { struct S {
float4 pos : SV_Position; float4 pos : SV_Position;
float clip : SV_ClipDistance0; float2 clip : SV_ClipDistance0;
float cull : SV_CullDistance0;
}; };
[maxvertexcount(3)] [maxvertexcount(3)]
void main(triangle in float4 pos[3] : SV_Position, void main(triangle in float4 pos[3] : SV_Position,
triangle in uint VertexID[3] : VertexID, triangle in uint VertexID[3] : VertexID,
inout LineStream<S> OutputStream, inout LineStream<S> OutputStream,
triangle in float clip[3] : SV_ClipDistance, // scalar float triangle in float4 clip[3] : SV_ClipDistance) // externally: an array 3 of array 4 (not vec4!) of float.
triangle in float cull[3] : SV_CullDistance) // scalar float
{ {
S s; S s;
s.pos = pos[0]; s.pos = pos[0];
s.clip = clip[0]; s.clip = clip[0].xy;
s.cull = cull[0];
OutputStream.Append(s); OutputStream.Append(s);
} }
......
...@@ -7,7 +7,7 @@ struct S { ...@@ -7,7 +7,7 @@ struct S {
void main(triangle in float4 pos[3] : SV_Position, void main(triangle in float4 pos[3] : SV_Position,
triangle in uint VertexID[3] : VertexID, triangle in uint VertexID[3] : VertexID,
inout LineStream<S> OutputStream, inout LineStream<S> OutputStream,
triangle in float2 clip[3][2] : SV_ClipDistance) // scalar float triangle in float2 clip[3][2] : SV_ClipDistance) // externally: an array 3 of array 4 of float.
{ {
S s; S s;
......
...@@ -4,5 +4,3 @@ float4 main(in float4 pos : SV_Position, ...@@ -4,5 +4,3 @@ float4 main(in float4 pos : SV_Position,
{ {
return pos + clip[0] + cull[0]; return pos + clip[0] + cull[0];
} }
struct S {
float4 pos : SV_Position;
float2 clip0 : SV_ClipDistance0; // clip0 and clip1 form an array of float[4] externally.
float2 clip1 : SV_ClipDistance1;
};
[maxvertexcount(3)]
void main(triangle in float4 pos[3] : SV_Position,
triangle in uint VertexID[3] : VertexID,
inout LineStream<S> OutputStream,
triangle in float4 clip[3] : SV_ClipDistance) // externally: an array 3 of array 4 (not vec4!) of float.
{
S s;
s.pos = pos[0];
s.clip0 = clip[0].xy;
s.clip1 = clip[0].zw;
OutputStream.Append(s);
}
struct S {
float4 pos : SV_Position;
float2 clip0 : SV_ClipDistance0; // clip0 and clip1 form an array of float[4] externally.
float2 clip1 : SV_ClipDistance1;
};
[maxvertexcount(3)]
void main(triangle in float4 pos[3] : SV_Position,
triangle in uint VertexID[3] : VertexID,
inout LineStream<S> OutputStream,
triangle in float2 clip0[3] : SV_ClipDistance0, // test input arrayed semantic vars
triangle in float2 clip1[3] : SV_ClipDistance1)
{
S s;
s.pos = pos[0];
s.clip0 = clip0[0];
s.clip1 = clip1[0];
OutputStream.Append(s);
}
...@@ -104,8 +104,10 @@ INSTANTIATE_TEST_CASE_P( ...@@ -104,8 +104,10 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.clipdistance-2.geom", "main"}, {"hlsl.clipdistance-2.geom", "main"},
{"hlsl.clipdistance-2.vert", "main"}, {"hlsl.clipdistance-2.vert", "main"},
{"hlsl.clipdistance-3.frag", "main"}, {"hlsl.clipdistance-3.frag", "main"},
{"hlsl.clipdistance-3.geom", "main"},
{"hlsl.clipdistance-3.vert", "main"}, {"hlsl.clipdistance-3.vert", "main"},
{"hlsl.clipdistance-4.frag", "main"}, {"hlsl.clipdistance-4.frag", "main"},
{"hlsl.clipdistance-4.geom", "main"},
{"hlsl.clipdistance-4.vert", "main"}, {"hlsl.clipdistance-4.vert", "main"},
{"hlsl.clipdistance-5.frag", "main"}, {"hlsl.clipdistance-5.frag", "main"},
{"hlsl.clipdistance-5.vert", "main"}, {"hlsl.clipdistance-5.vert", "main"},
......
...@@ -435,12 +435,16 @@ protected: ...@@ -435,12 +435,16 @@ protected:
TVariable* gsStreamOutput; // geometry shader stream outputs, for emit (Append method) TVariable* gsStreamOutput; // geometry shader stream outputs, for emit (Append method)
TVariable* clipDistanceVariable; // synthesized clip distance variable (shader might have >1) TVariable* clipDistanceOutput; // synthesized clip distance out variable (shader might have >1)
TVariable* cullDistanceVariable; // synthesized cull distance variable (shader might have >1) TVariable* cullDistanceOutput; // synthesized cull distance out variable (shader might have >1)
TVariable* clipDistanceInput; // synthesized clip distance in variable (shader might have >1)
TVariable* cullDistanceInput; // synthesized cull distance in variable (shader might have >1)
static const int maxClipCullRegs = 2; static const int maxClipCullRegs = 2;
std::array<int, maxClipCullRegs> clipSemanticNSize; // vector, indexed by clip semantic ID std::array<int, maxClipCullRegs> clipSemanticNSizeIn; // vector, indexed by clip semantic ID
std::array<int, maxClipCullRegs> cullSemanticNSize; // vector, indexed by cull semantic ID std::array<int, maxClipCullRegs> cullSemanticNSizeIn; // vector, indexed by cull semantic ID
std::array<int, maxClipCullRegs> clipSemanticNSizeOut; // vector, indexed by clip semantic ID
std::array<int, maxClipCullRegs> cullSemanticNSizeOut; // vector, indexed by cull semantic ID
// This tracks the first (mip level) argument to the .mips[][] operator. Since this can be nested as // This tracks the first (mip level) argument to the .mips[][] operator. Since this can be nested as
// in tx.mips[tx.mips[0][1].x][2], we need a stack. We also track the TSourceLoc for error reporting // in tx.mips[tx.mips[0][1].x][2], we need a stack. We also track the TSourceLoc for error reporting
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment