Commit 9cee73e0 by steve-lunarg

HLSL: support per control point patch const fn invocation

This PR emulates per control point inputs to patch constant functions. Without either an extension to look across SIMD lanes or a dedicated stage, the emulation must use separate invocations of the wrapped entry point to obtain the per control point values. This is provided since shaders are wanting this functionality now, but such an extension is not yet available. Entry point arguments qualified as an invocation ID are replaced by the current control point number when calling the wrapped entry point. There is no particular optimization for the case of the entry point not having such an input but the PCF still accepting ctrl pt frequency data. It'll work, but anyway makes no so much sense. The wrapped entry point must return the per control point data by value. At this time it is not supported as an output parameter.
parent e434ad92
...@@ -50,8 +50,8 @@ vertices = 4 ...@@ -50,8 +50,8 @@ vertices = 4
0:? 'pid' ( in uint PrimitiveID) 0:? 'pid' ( in uint PrimitiveID)
0:? Sequence 0:? Sequence
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -62,8 +62,8 @@ vertices = 4 ...@@ -62,8 +62,8 @@ vertices = 4
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 1 (const int) 0:? 1 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -104,7 +104,8 @@ vertices = 4 ...@@ -104,7 +104,8 @@ vertices = 4
0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint}) 0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'm_cpid' ( in uint InvocationID) 0:? 'm_cpid' ( in uint InvocationID)
0:? 'pid' ( in uint PrimitiveID) 0:? 'pid' ( in uint PrimitiveID)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput' (layout( location=1) patch out structure{})
0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
Linked tessellation control stage: Linked tessellation control stage:
...@@ -161,8 +162,8 @@ vertices = 4 ...@@ -161,8 +162,8 @@ vertices = 4
0:? 'pid' ( in uint PrimitiveID) 0:? 'pid' ( in uint PrimitiveID)
0:? Sequence 0:? Sequence
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -173,8 +174,8 @@ vertices = 4 ...@@ -173,8 +174,8 @@ vertices = 4
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 1 (const int) 0:? 1 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -215,16 +216,17 @@ vertices = 4 ...@@ -215,16 +216,17 @@ vertices = 4
0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint}) 0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'm_cpid' ( in uint InvocationID) 0:? 'm_cpid' ( in uint InvocationID)
0:? 'pid' ( in uint PrimitiveID) 0:? 'pid' ( in uint PrimitiveID)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput' (layout( location=1) patch out structure{})
0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 85 // Id's are bound by 88
Capability Tessellation Capability Tessellation
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint TessellationControl 4 "main" 40 44 47 62 67 EntryPoint TessellationControl 4 "main" 40 44 47 62 67 87
ExecutionMode 4 OutputVertices 4 ExecutionMode 4 OutputVertices 4
Name 4 "main" Name 4 "main"
Name 8 "VS_OUT" Name 8 "VS_OUT"
...@@ -251,11 +253,16 @@ vertices = 4 ...@@ -251,11 +253,16 @@ vertices = 4
Name 63 "param" Name 63 "param"
Name 67 "@patchConstantOutput_edges" Name 67 "@patchConstantOutput_edges"
Name 77 "output" Name 77 "output"
Name 85 "HS_CONSTANT_OUT"
Name 87 "@patchConstantOutput"
Decorate 40(ip) Location 0 Decorate 40(ip) Location 0
Decorate 44(m_cpid) BuiltIn InvocationId Decorate 44(m_cpid) BuiltIn InvocationId
Decorate 47(@entryPointOutput) Location 0 Decorate 47(@entryPointOutput) Location 0
Decorate 62(pid) BuiltIn PrimitiveId Decorate 62(pid) BuiltIn PrimitiveId
Decorate 67(@patchConstantOutput_edges) Patch
Decorate 67(@patchConstantOutput_edges) BuiltIn TessLevelOuter Decorate 67(@patchConstantOutput_edges) BuiltIn TessLevelOuter
Decorate 87(@patchConstantOutput) Patch
Decorate 87(@patchConstantOutput) Location 1
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
...@@ -294,6 +301,9 @@ vertices = 4 ...@@ -294,6 +301,9 @@ vertices = 4
73: 29(int) Constant 1 73: 29(int) Constant 1
78: 6(float) Constant 1073741824 78: 6(float) Constant 1073741824
80: 6(float) Constant 1090519040 80: 6(float) Constant 1090519040
85(HS_CONSTANT_OUT): TypeStruct
86: TypePointer Output 85(HS_CONSTANT_OUT)
87(@patchConstantOutput): 86(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
38(ip): 12(ptr) Variable Function 38(ip): 12(ptr) Variable Function
......
...@@ -46,8 +46,8 @@ vertices = 4 ...@@ -46,8 +46,8 @@ vertices = 4
0:? 'pos' ( in 4-component vector of float Position) 0:? 'pos' ( in 4-component vector of float Position)
0:? Sequence 0:? Sequence
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -58,8 +58,8 @@ vertices = 4 ...@@ -58,8 +58,8 @@ vertices = 4
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 1 (const int) 0:? 1 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -102,7 +102,8 @@ vertices = 4 ...@@ -102,7 +102,8 @@ vertices = 4
0:? 'pid' ( in uint PrimitiveID) 0:? 'pid' ( in uint PrimitiveID)
0:? 'pos' ( in 4-component vector of float Position) 0:? 'pos' ( in 4-component vector of float Position)
0:? 'InvocationId' ( in uint InvocationID) 0:? 'InvocationId' ( in uint InvocationID)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput' (layout( location=1) patch out structure{})
0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
Linked tessellation control stage: Linked tessellation control stage:
...@@ -155,8 +156,8 @@ vertices = 4 ...@@ -155,8 +156,8 @@ vertices = 4
0:? 'pos' ( in 4-component vector of float Position) 0:? 'pos' ( in 4-component vector of float Position)
0:? Sequence 0:? Sequence
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -167,8 +168,8 @@ vertices = 4 ...@@ -167,8 +168,8 @@ vertices = 4
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? move second child to first child ( temp float) 0:? move second child to first child ( temp float)
0:? direct index ( out float TessLevelOuter) 0:? direct index ( patch out float TessLevelOuter)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
0:? Constant: 0:? Constant:
0:? 1 (const int) 0:? 1 (const int)
0:? direct index ( temp float) 0:? direct index ( temp float)
...@@ -211,16 +212,17 @@ vertices = 4 ...@@ -211,16 +212,17 @@ vertices = 4
0:? 'pid' ( in uint PrimitiveID) 0:? 'pid' ( in uint PrimitiveID)
0:? 'pos' ( in 4-component vector of float Position) 0:? 'pos' ( in 4-component vector of float Position)
0:? 'InvocationId' ( in uint InvocationID) 0:? 'InvocationId' ( in uint InvocationID)
0:? '@patchConstantOutput_edges' ( out 2-element array of float TessLevelOuter) 0:? '@patchConstantOutput' (layout( location=1) patch out structure{})
0:? '@patchConstantOutput_edges' ( patch out 2-element array of float TessLevelOuter)
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 87 // Id's are bound by 90
Capability Tessellation Capability Tessellation
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint TessellationControl 4 "main" 42 45 52 60 62 69 EntryPoint TessellationControl 4 "main" 42 45 52 60 62 69 89
ExecutionMode 4 OutputVertices 4 ExecutionMode 4 OutputVertices 4
Name 4 "main" Name 4 "main"
Name 8 "VS_OUT" Name 8 "VS_OUT"
...@@ -247,12 +249,17 @@ vertices = 4 ...@@ -247,12 +249,17 @@ vertices = 4
Name 65 "param" Name 65 "param"
Name 69 "@patchConstantOutput_edges" Name 69 "@patchConstantOutput_edges"
Name 79 "output" Name 79 "output"
Name 87 "HS_CONSTANT_OUT"
Name 89 "@patchConstantOutput"
Decorate 42(ip) Location 0 Decorate 42(ip) Location 0
Decorate 45(@entryPointOutput) Location 0 Decorate 45(@entryPointOutput) Location 0
Decorate 52(InvocationId) BuiltIn InvocationId Decorate 52(InvocationId) BuiltIn InvocationId
Decorate 60(pid) BuiltIn PrimitiveId Decorate 60(pid) BuiltIn PrimitiveId
Decorate 62(pos) BuiltIn Position Decorate 62(pos) BuiltIn Position
Decorate 69(@patchConstantOutput_edges) Patch
Decorate 69(@patchConstantOutput_edges) BuiltIn TessLevelOuter Decorate 69(@patchConstantOutput_edges) BuiltIn TessLevelOuter
Decorate 89(@patchConstantOutput) Patch
Decorate 89(@patchConstantOutput) Location 1
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
...@@ -295,6 +302,9 @@ vertices = 4 ...@@ -295,6 +302,9 @@ vertices = 4
75: 31(int) Constant 1 75: 31(int) Constant 1
80: 6(float) Constant 1073741824 80: 6(float) Constant 1073741824
82: 6(float) Constant 1090519040 82: 6(float) Constant 1090519040
87(HS_CONSTANT_OUT): TypeStruct
88: TypePointer Output 87(HS_CONSTANT_OUT)
89(@patchConstantOutput): 88(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
40(ip): 12(ptr) Variable Function 40(ip): 12(ptr) Variable Function
......
...@@ -38,7 +38,8 @@ vertices = 3 ...@@ -38,7 +38,8 @@ vertices = 3
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? true case 0:? true case
0:? Function Call: PCF( ( temp void) 0:? Sequence
0:? Function Call: PCF( ( temp void)
0:33 Function Definition: PCF( ( temp void) 0:33 Function Definition: PCF( ( temp void)
0:33 Function Parameters: 0:33 Function Parameters:
0:? Linker Objects 0:? Linker Objects
...@@ -89,7 +90,8 @@ vertices = 3 ...@@ -89,7 +90,8 @@ vertices = 3
0:? Constant: 0:? Constant:
0:? 0 (const int) 0:? 0 (const int)
0:? true case 0:? true case
0:? Function Call: PCF( ( temp void) 0:? Sequence
0:? Function Call: PCF( ( temp void)
0:33 Function Definition: PCF( ( temp void) 0:33 Function Definition: PCF( ( temp void)
0:33 Function Parameters: 0:33 Function Parameters:
0:? Linker Objects 0:? Linker Objects
......
// ***
// per-control-point invocation of PCF from entry point return value
// ***
struct hs_in_t
{
float3 val : TEXCOORD0;
};
struct hs_pcf_t
{
float tfactor[3] : SV_TessFactor;
float flInFactor : SV_InsideTessFactor;
};
struct hs_out_t
{
float3 val : TEXCOORD0;
};
[ domain ("tri") ]
[ partitioning ("fractional_odd") ]
[ outputtopology ("triangle_cw") ]
[ outputcontrolpoints (3) ]
[ patchconstantfunc ( "PCF" ) ]
hs_out_t main (InputPatch <hs_in_t, 3> i , uint cpid : SV_OutputControlPointID)
{
hs_out_t o;
o.val = cpid;
return o;
}
hs_pcf_t PCF( const OutputPatch <hs_out_t, 3> pcf_out)
{
hs_pcf_t o;
o.tfactor[0] = pcf_out[0].val.x;
o.tfactor[1] = pcf_out[1].val.x;
o.tfactor[2] = pcf_out[2].val.x;
o.flInFactor = 4;
return o;
}
...@@ -125,6 +125,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -125,6 +125,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.hull.1.tesc", "main"}, {"hlsl.hull.1.tesc", "main"},
{"hlsl.hull.2.tesc", "main"}, {"hlsl.hull.2.tesc", "main"},
{"hlsl.hull.void.tesc", "main"}, {"hlsl.hull.void.tesc", "main"},
{"hlsl.hull.ctrlpt-1.tesc", "main"},
{"hlsl.identifier.sample.frag", "main"}, {"hlsl.identifier.sample.frag", "main"},
{"hlsl.if.frag", "PixelShaderFunction"}, {"hlsl.if.frag", "PixelShaderFunction"},
{"hlsl.inoutquals.frag", "main"}, {"hlsl.inoutquals.frag", "main"},
......
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