HLSL: Intercept flatten aggregates passed to a function input, and copy member-by-member.
diff --git a/Test/baseResults/hlsl.entry-in.frag.out b/Test/baseResults/hlsl.entry-in.frag.out
index e1a55bc..a5f8c7e 100755
--- a/Test/baseResults/hlsl.entry-in.frag.out
+++ b/Test/baseResults/hlsl.entry-in.frag.out
@@ -2,37 +2,91 @@
Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
-0:8 Function Definition: PixelShaderFunction(struct-InParam-vf2-vf4-vi21; (global 4-component vector of float)
+0:8 Function Definition: fun(struct-InParam-vf2-vf4-vi21; (global float)
0:8 Function Parameters:
-0:8 'i' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:8 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Sequence
+0:9 Branch: Return with expression
+0:9 add (temp float)
+0:9 direct index (temp float)
+0:9 v: direct index for structure (temp 2-component vector of float)
+0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:9 Constant:
+0:9 0 (const int)
+0:9 Constant:
+0:9 1 (const int)
+0:9 direct index (temp float)
+0:9 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:9 Constant:
+0:9 1 (const int)
+0:9 Constant:
+0:9 0 (const int)
+0:13 Function Definition: PixelShaderFunction(struct-InParam-vf2-vf4-vi21; (global 4-component vector of float)
+0:13 Function Parameters:
+0:13 'i' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
0:? Sequence
0:? Sequence
-0:10 move second child to first child (temp 2-component vector of float)
-0:10 v: direct index for structure (temp 2-component vector of float)
-0:10 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:10 Constant:
-0:10 0 (const int)
+0:15 move second child to first child (temp 2-component vector of float)
+0:15 v: direct index for structure (temp 2-component vector of float)
+0:15 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:15 Constant:
+0:15 0 (const int)
0:? 'v' (layout(location=0 ) in 2-component vector of float)
-0:10 move second child to first child (temp 4-component vector of float)
-0:10 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
-0:10 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:10 Constant:
-0:10 1 (const int)
+0:15 move second child to first child (temp 4-component vector of float)
+0:15 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:15 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:15 Constant:
+0:15 1 (const int)
0:? 'fragCoord' (in 4-component vector of float FragCoord)
-0:10 move second child to first child (temp 2-component vector of int)
-0:10 i2: direct index for structure (temp 2-component vector of int)
-0:10 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:10 Constant:
-0:10 2 (const int)
+0:15 move second child to first child (temp 2-component vector of int)
+0:15 i2: direct index for structure (temp 2-component vector of int)
+0:15 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:15 Constant:
+0:15 2 (const int)
0:? 'i2' (layout(location=1 ) in 2-component vector of int)
-0:12 Sequence
-0:12 move second child to first child (temp 4-component vector of float)
+0:16 Sequence
+0:16 move second child to first child (temp float)
+0:16 'ret1' (temp float)
+0:16 Function Call: fun(struct-InParam-vf2-vf4-vi21; (global float)
+0:16 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:17 Sequence
+0:17 move second child to first child (temp float)
+0:17 'ret2' (temp float)
+0:17 Function Call: fun(struct-InParam-vf2-vf4-vi21; (global float)
+0:? Comma (temp float)
+0:? Sequence
+0:? move second child to first child (temp 2-component vector of float)
+0:? v: direct index for structure (temp 2-component vector of float)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Constant:
+0:? 0 (const int)
+0:? 'v' (layout(location=0 ) in 2-component vector of float)
+0:? move second child to first child (temp 4-component vector of float)
+0:? fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Constant:
+0:? 1 (const int)
+0:? 'fragCoord' (in 4-component vector of float FragCoord)
+0:? move second child to first child (temp 2-component vector of int)
+0:? i2: direct index for structure (temp 2-component vector of int)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Constant:
+0:? 2 (const int)
+0:? 'i2' (layout(location=1 ) in 2-component vector of int)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:19 Sequence
+0:19 move second child to first child (temp 4-component vector of float)
0:? '@entryPointOutput' (layout(location=0 ) out 4-component vector of float)
-0:12 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
-0:12 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:12 Constant:
-0:12 1 (const int)
-0:12 Branch: Return
+0:19 vector-scale (temp 4-component vector of float)
+0:19 vector-scale (temp 4-component vector of float)
+0:19 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:19 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:19 Constant:
+0:19 1 (const int)
+0:19 'ret1' (temp float)
+0:19 'ret2' (temp float)
+0:19 Branch: Return
0:? Linker Objects
0:? '@entryPointOutput' (layout(location=0 ) out 4-component vector of float)
0:? 'v' (layout(location=0 ) in 2-component vector of float)
@@ -46,37 +100,91 @@
Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
-0:8 Function Definition: PixelShaderFunction(struct-InParam-vf2-vf4-vi21; (global 4-component vector of float)
+0:8 Function Definition: fun(struct-InParam-vf2-vf4-vi21; (global float)
0:8 Function Parameters:
-0:8 'i' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:8 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Sequence
+0:9 Branch: Return with expression
+0:9 add (temp float)
+0:9 direct index (temp float)
+0:9 v: direct index for structure (temp 2-component vector of float)
+0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:9 Constant:
+0:9 0 (const int)
+0:9 Constant:
+0:9 1 (const int)
+0:9 direct index (temp float)
+0:9 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:9 Constant:
+0:9 1 (const int)
+0:9 Constant:
+0:9 0 (const int)
+0:13 Function Definition: PixelShaderFunction(struct-InParam-vf2-vf4-vi21; (global 4-component vector of float)
+0:13 Function Parameters:
+0:13 'i' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
0:? Sequence
0:? Sequence
-0:10 move second child to first child (temp 2-component vector of float)
-0:10 v: direct index for structure (temp 2-component vector of float)
-0:10 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:10 Constant:
-0:10 0 (const int)
+0:15 move second child to first child (temp 2-component vector of float)
+0:15 v: direct index for structure (temp 2-component vector of float)
+0:15 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:15 Constant:
+0:15 0 (const int)
0:? 'v' (layout(location=0 ) in 2-component vector of float)
-0:10 move second child to first child (temp 4-component vector of float)
-0:10 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
-0:10 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:10 Constant:
-0:10 1 (const int)
+0:15 move second child to first child (temp 4-component vector of float)
+0:15 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:15 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:15 Constant:
+0:15 1 (const int)
0:? 'fragCoord' (in 4-component vector of float FragCoord)
-0:10 move second child to first child (temp 2-component vector of int)
-0:10 i2: direct index for structure (temp 2-component vector of int)
-0:10 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:10 Constant:
-0:10 2 (const int)
+0:15 move second child to first child (temp 2-component vector of int)
+0:15 i2: direct index for structure (temp 2-component vector of int)
+0:15 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:15 Constant:
+0:15 2 (const int)
0:? 'i2' (layout(location=1 ) in 2-component vector of int)
-0:12 Sequence
-0:12 move second child to first child (temp 4-component vector of float)
+0:16 Sequence
+0:16 move second child to first child (temp float)
+0:16 'ret1' (temp float)
+0:16 Function Call: fun(struct-InParam-vf2-vf4-vi21; (global float)
+0:16 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:17 Sequence
+0:17 move second child to first child (temp float)
+0:17 'ret2' (temp float)
+0:17 Function Call: fun(struct-InParam-vf2-vf4-vi21; (global float)
+0:? Comma (temp float)
+0:? Sequence
+0:? move second child to first child (temp 2-component vector of float)
+0:? v: direct index for structure (temp 2-component vector of float)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Constant:
+0:? 0 (const int)
+0:? 'v' (layout(location=0 ) in 2-component vector of float)
+0:? move second child to first child (temp 4-component vector of float)
+0:? fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Constant:
+0:? 1 (const int)
+0:? 'fragCoord' (in 4-component vector of float FragCoord)
+0:? move second child to first child (temp 2-component vector of int)
+0:? i2: direct index for structure (temp 2-component vector of int)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:? Constant:
+0:? 2 (const int)
+0:? 'i2' (layout(location=1 ) in 2-component vector of int)
+0:? 'aggShadow' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:19 Sequence
+0:19 move second child to first child (temp 4-component vector of float)
0:? '@entryPointOutput' (layout(location=0 ) out 4-component vector of float)
-0:12 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
-0:12 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
-0:12 Constant:
-0:12 1 (const int)
-0:12 Branch: Return
+0:19 vector-scale (temp 4-component vector of float)
+0:19 vector-scale (temp 4-component vector of float)
+0:19 fragCoord: direct index for structure (temp 4-component vector of float FragCoord)
+0:19 'local' (temp structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2})
+0:19 Constant:
+0:19 1 (const int)
+0:19 'ret1' (temp float)
+0:19 'ret2' (temp float)
+0:19 Branch: Return
0:? Linker Objects
0:? '@entryPointOutput' (layout(location=0 ) out 4-component vector of float)
0:? 'v' (layout(location=0 ) in 2-component vector of float)
@@ -85,28 +193,35 @@
// Module Version 10000
// Generated by (magic number): 80001
-// Id's are bound by 37
+// Id's are bound by 71
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
- EntryPoint Fragment 4 "PixelShaderFunction" 16 22 28 33
+ EntryPoint Fragment 4 "PixelShaderFunction" 32 37 43 63
ExecutionMode 4 OriginUpperLeft
Name 4 "PixelShaderFunction"
Name 11 "InParam"
MemberName 11(InParam) 0 "v"
MemberName 11(InParam) 1 "fragCoord"
MemberName 11(InParam) 2 "i2"
- Name 13 "local"
- Name 16 "v"
- Name 22 "fragCoord"
- Name 28 "i2"
- Name 33 "@entryPointOutput"
+ Name 15 "fun(struct-InParam-vf2-vf4-vi21;"
+ Name 14 "p"
+ Name 30 "local"
+ Name 32 "v"
+ Name 37 "fragCoord"
+ Name 43 "i2"
+ Name 47 "ret1"
+ Name 48 "param"
+ Name 51 "ret2"
+ Name 52 "aggShadow"
+ Name 59 "param"
+ Name 63 "@entryPointOutput"
MemberDecorate 11(InParam) 1 BuiltIn FragCoord
- Decorate 16(v) Location 0
- Decorate 22(fragCoord) BuiltIn FragCoord
- Decorate 28(i2) Location 1
- Decorate 33(@entryPointOutput) Location 0
+ Decorate 32(v) Location 0
+ Decorate 37(fragCoord) BuiltIn FragCoord
+ Decorate 43(i2) Location 1
+ Decorate 63(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@@ -116,34 +231,75 @@
10: TypeVector 9(int) 2
11(InParam): TypeStruct 7(fvec2) 8(fvec4) 10(ivec2)
12: TypePointer Function 11(InParam)
- 14: 9(int) Constant 0
- 15: TypePointer Input 7(fvec2)
- 16(v): 15(ptr) Variable Input
- 18: TypePointer Function 7(fvec2)
- 20: 9(int) Constant 1
- 21: TypePointer Input 8(fvec4)
- 22(fragCoord): 21(ptr) Variable Input
- 24: TypePointer Function 8(fvec4)
- 26: 9(int) Constant 2
- 27: TypePointer Input 10(ivec2)
- 28(i2): 27(ptr) Variable Input
- 30: TypePointer Function 10(ivec2)
- 32: TypePointer Output 8(fvec4)
-33(@entryPointOutput): 32(ptr) Variable Output
+ 13: TypeFunction 6(float) 12(ptr)
+ 17: 9(int) Constant 0
+ 18: TypeInt 32 0
+ 19: 18(int) Constant 1
+ 20: TypePointer Function 6(float)
+ 23: 9(int) Constant 1
+ 24: 18(int) Constant 0
+ 31: TypePointer Input 7(fvec2)
+ 32(v): 31(ptr) Variable Input
+ 34: TypePointer Function 7(fvec2)
+ 36: TypePointer Input 8(fvec4)
+ 37(fragCoord): 36(ptr) Variable Input
+ 39: TypePointer Function 8(fvec4)
+ 41: 9(int) Constant 2
+ 42: TypePointer Input 10(ivec2)
+ 43(i2): 42(ptr) Variable Input
+ 45: TypePointer Function 10(ivec2)
+ 62: TypePointer Output 8(fvec4)
+63(@entryPointOutput): 62(ptr) Variable Output
4(PixelShaderFunction): 2 Function None 3
5: Label
- 13(local): 12(ptr) Variable Function
- 17: 7(fvec2) Load 16(v)
- 19: 18(ptr) AccessChain 13(local) 14
- Store 19 17
- 23: 8(fvec4) Load 22(fragCoord)
- 25: 24(ptr) AccessChain 13(local) 20
- Store 25 23
- 29: 10(ivec2) Load 28(i2)
- 31: 30(ptr) AccessChain 13(local) 26
- Store 31 29
- 34: 24(ptr) AccessChain 13(local) 20
- 35: 8(fvec4) Load 34
- Store 33(@entryPointOutput) 35
+ 30(local): 12(ptr) Variable Function
+ 47(ret1): 20(ptr) Variable Function
+ 48(param): 12(ptr) Variable Function
+ 51(ret2): 20(ptr) Variable Function
+ 52(aggShadow): 12(ptr) Variable Function
+ 59(param): 20(ptr) Variable Function
+ 33: 7(fvec2) Load 32(v)
+ 35: 34(ptr) AccessChain 30(local) 17
+ Store 35 33
+ 38: 8(fvec4) Load 37(fragCoord)
+ 40: 39(ptr) AccessChain 30(local) 23
+ Store 40 38
+ 44: 10(ivec2) Load 43(i2)
+ 46: 45(ptr) AccessChain 30(local) 41
+ Store 46 44
+ 49: 11(InParam) Load 30(local)
+ Store 48(param) 49
+ 50: 6(float) FunctionCall 15(fun(struct-InParam-vf2-vf4-vi21;) 48(param)
+ Store 47(ret1) 50
+ 53: 7(fvec2) Load 32(v)
+ 54: 34(ptr) AccessChain 52(aggShadow) 17
+ Store 54 53
+ 55: 8(fvec4) Load 37(fragCoord)
+ 56: 39(ptr) AccessChain 52(aggShadow) 23
+ Store 56 55
+ 57: 10(ivec2) Load 43(i2)
+ 58: 45(ptr) AccessChain 52(aggShadow) 41
+ Store 58 57
+ 60: 11(InParam) Load 52(aggShadow)
+ Store 59(param) 60
+ 61: 6(float) FunctionCall 15(fun(struct-InParam-vf2-vf4-vi21;) 59(param)
+ Store 51(ret2) 61
+ 64: 39(ptr) AccessChain 30(local) 23
+ 65: 8(fvec4) Load 64
+ 66: 6(float) Load 47(ret1)
+ 67: 8(fvec4) VectorTimesScalar 65 66
+ 68: 6(float) Load 51(ret2)
+ 69: 8(fvec4) VectorTimesScalar 67 68
+ Store 63(@entryPointOutput) 69
Return
FunctionEnd
+15(fun(struct-InParam-vf2-vf4-vi21;): 6(float) Function None 13
+ 14(p): 12(ptr) FunctionParameter
+ 16: Label
+ 21: 20(ptr) AccessChain 14(p) 17 19
+ 22: 6(float) Load 21
+ 25: 20(ptr) AccessChain 14(p) 23 24
+ 26: 6(float) Load 25
+ 27: 6(float) FAdd 22 26
+ ReturnValue 27
+ FunctionEnd
diff --git a/Test/hlsl.entry-in.frag b/Test/hlsl.entry-in.frag
index 4d4ba50..e15955d 100644
--- a/Test/hlsl.entry-in.frag
+++ b/Test/hlsl.entry-in.frag
@@ -4,10 +4,17 @@
int2 i2;
};
+float fun(InParam p)
+{
+ return p.v.y + p.fragCoord.x;
+}
+
float4 PixelShaderFunction(InParam i) : COLOR0
{
InParam local;
local = i;
+ float ret1 = fun(local);
+ float ret2 = fun(i);
- return local.fragCoord;
+ return local.fragCoord * ret1 * ret2;
}
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index 2d58c26..8469dcf 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -3,4 +3,4 @@
// For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1493"
-#define GLSLANG_DATE "18-Sep-2016"
+#define GLSLANG_DATE "19-Sep-2016"
diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp
index cb52805..07d96ea 100755
--- a/hlsl/hlslParseHelper.cpp
+++ b/hlsl/hlslParseHelper.cpp
@@ -2241,6 +2241,16 @@
void HlslParseContext::addInputArgumentConversions(const TFunction& function, TIntermNode*& arguments) const
{
TIntermAggregate* aggregate = arguments->getAsAggregate();
+ const auto setArg = [&](int argNum, TIntermNode* arg) {
+ if (function.getParamCount() == 1)
+ arguments = arg;
+ else {
+ if (aggregate)
+ aggregate->getSequence()[argNum] = arg;
+ else
+ arguments = arg;
+ }
+ };
// Process each argument's conversion
for (int i = 0; i < function.getParamCount(); ++i) {
@@ -2254,16 +2264,20 @@
// convert to the correct type.
arg = intermediate.addConversion(EOpFunctionCall, *function[i].type, arg);
arg = intermediate.addShapeConversion(EOpFunctionCall, *function[i].type, arg);
- if (arg) {
- if (function.getParamCount() == 1)
- arguments = arg;
- else {
- if (aggregate)
- aggregate->getSequence()[i] = arg;
- else
- arguments = arg;
- }
- }
+ setArg(i, arg);
+ }
+ } else {
+ if (shouldFlatten(arg->getType())) {
+ TSourceLoc dummyLoc;
+ dummyLoc.init();
+ TVariable* internalAggregate = makeInternalVariable("aggShadow", *function[i].type);
+ TIntermSymbol* internalSymbolNode = new TIntermSymbol(internalAggregate->getUniqueId(),
+ internalAggregate->getName(),
+ internalAggregate->getType());
+ TIntermAggregate* assignAgg = handleAssign(dummyLoc, EOpAssign, internalSymbolNode, arg)->getAsAggregate();
+ assignAgg = intermediate.growAggregate(assignAgg, internalSymbolNode);
+ assignAgg->setOperator(EOpComma);
+ setArg(i, assignAgg);
}
}
}