mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-09 12:00:05 +00:00
AST: Have type deepCopy() preserve type graphs as graphs.
Previously, a type graph would turn into a type tree. That is, a deep node that is shared would have multiple copies made. This is important when creating IO and non-IO versions of deep types.
This commit is contained in:
parent
02467d8d94
commit
0fe106afd2
127
Test/baseResults/hlsl.typeGraphCopy.vert.out
Executable file
127
Test/baseResults/hlsl.typeGraphCopy.vert.out
Executable file
@ -0,0 +1,127 @@
|
|||||||
|
hlsl.typeGraphCopy.vert
|
||||||
|
Shader version: 450
|
||||||
|
0:? Sequence
|
||||||
|
0:22 Function Definition: @main( (temp float)
|
||||||
|
0:22 Function Parameters:
|
||||||
|
0:? Sequence
|
||||||
|
0:23 Branch: Return with expression
|
||||||
|
0:23 b: direct index for structure (temp float)
|
||||||
|
0:23 s2: direct index for structure (temp structure{temp int a, temp float b})
|
||||||
|
0:23 t3: direct index for structure (temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2})
|
||||||
|
0:23 foo: direct index for structure (layout(offset=0 ) uniform structure{temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t1, temp structure{temp int a, temp float b} t2, temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t3})
|
||||||
|
0:23 'anon@0' (layout(row_major std140 ) uniform block{layout(offset=0 ) uniform structure{temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t1, temp structure{temp int a, temp float b} t2, temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t3} foo})
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 0 (const uint)
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 2 (const int)
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 1 (const int)
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 1 (const int)
|
||||||
|
0:22 Function Definition: main( (temp void)
|
||||||
|
0:22 Function Parameters:
|
||||||
|
0:? Sequence
|
||||||
|
0:22 move second child to first child (temp float)
|
||||||
|
0:? '@entryPointOutput' (layout(location=0 ) out float)
|
||||||
|
0:22 Function Call: @main( (temp float)
|
||||||
|
0:? Linker Objects
|
||||||
|
0:? '@entryPointOutput' (layout(location=0 ) out float)
|
||||||
|
0:? 'anon@0' (layout(row_major std140 ) uniform block{layout(offset=0 ) uniform structure{temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t1, temp structure{temp int a, temp float b} t2, temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t3} foo})
|
||||||
|
|
||||||
|
|
||||||
|
Linked vertex stage:
|
||||||
|
|
||||||
|
|
||||||
|
Shader version: 450
|
||||||
|
0:? Sequence
|
||||||
|
0:22 Function Definition: @main( (temp float)
|
||||||
|
0:22 Function Parameters:
|
||||||
|
0:? Sequence
|
||||||
|
0:23 Branch: Return with expression
|
||||||
|
0:23 b: direct index for structure (temp float)
|
||||||
|
0:23 s2: direct index for structure (temp structure{temp int a, temp float b})
|
||||||
|
0:23 t3: direct index for structure (temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2})
|
||||||
|
0:23 foo: direct index for structure (layout(offset=0 ) uniform structure{temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t1, temp structure{temp int a, temp float b} t2, temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t3})
|
||||||
|
0:23 'anon@0' (layout(row_major std140 ) uniform block{layout(offset=0 ) uniform structure{temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t1, temp structure{temp int a, temp float b} t2, temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t3} foo})
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 0 (const uint)
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 2 (const int)
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 1 (const int)
|
||||||
|
0:23 Constant:
|
||||||
|
0:23 1 (const int)
|
||||||
|
0:22 Function Definition: main( (temp void)
|
||||||
|
0:22 Function Parameters:
|
||||||
|
0:? Sequence
|
||||||
|
0:22 move second child to first child (temp float)
|
||||||
|
0:? '@entryPointOutput' (layout(location=0 ) out float)
|
||||||
|
0:22 Function Call: @main( (temp float)
|
||||||
|
0:? Linker Objects
|
||||||
|
0:? '@entryPointOutput' (layout(location=0 ) out float)
|
||||||
|
0:? 'anon@0' (layout(row_major std140 ) uniform block{layout(offset=0 ) uniform structure{temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t1, temp structure{temp int a, temp float b} t2, temp structure{temp structure{temp int a, temp float b} s1, temp structure{temp int a, temp float b} s2} t3} foo})
|
||||||
|
|
||||||
|
// Module Version 10000
|
||||||
|
// Generated by (magic number): 80001
|
||||||
|
// Id's are bound by 28
|
||||||
|
|
||||||
|
Capability Shader
|
||||||
|
1: ExtInstImport "GLSL.std.450"
|
||||||
|
MemoryModel Logical GLSL450
|
||||||
|
EntryPoint Vertex 4 "main" 26
|
||||||
|
Name 4 "main"
|
||||||
|
Name 8 "@main("
|
||||||
|
Name 11 "N1"
|
||||||
|
MemberName 11(N1) 0 "a"
|
||||||
|
MemberName 11(N1) 1 "b"
|
||||||
|
Name 12 "N2"
|
||||||
|
MemberName 12(N2) 0 "s1"
|
||||||
|
MemberName 12(N2) 1 "s2"
|
||||||
|
Name 13 "N3"
|
||||||
|
MemberName 13(N3) 0 "t1"
|
||||||
|
MemberName 13(N3) 1 "t2"
|
||||||
|
MemberName 13(N3) 2 "t3"
|
||||||
|
Name 14 "$Global"
|
||||||
|
MemberName 14($Global) 0 "foo"
|
||||||
|
Name 16 ""
|
||||||
|
Name 26 "@entryPointOutput"
|
||||||
|
MemberDecorate 11(N1) 0 Offset 0
|
||||||
|
MemberDecorate 11(N1) 1 Offset 4
|
||||||
|
MemberDecorate 12(N2) 0 Offset 0
|
||||||
|
MemberDecorate 12(N2) 1 Offset 16
|
||||||
|
MemberDecorate 13(N3) 0 Offset 0
|
||||||
|
MemberDecorate 13(N3) 1 Offset 32
|
||||||
|
MemberDecorate 13(N3) 2 Offset 48
|
||||||
|
MemberDecorate 14($Global) 0 Offset 0
|
||||||
|
Decorate 14($Global) Block
|
||||||
|
Decorate 16 DescriptorSet 0
|
||||||
|
Decorate 26(@entryPointOutput) Location 0
|
||||||
|
2: TypeVoid
|
||||||
|
3: TypeFunction 2
|
||||||
|
6: TypeFloat 32
|
||||||
|
7: TypeFunction 6(float)
|
||||||
|
10: TypeInt 32 1
|
||||||
|
11(N1): TypeStruct 10(int) 6(float)
|
||||||
|
12(N2): TypeStruct 11(N1) 11(N1)
|
||||||
|
13(N3): TypeStruct 12(N2) 11(N1) 12(N2)
|
||||||
|
14($Global): TypeStruct 13(N3)
|
||||||
|
15: TypePointer Uniform 14($Global)
|
||||||
|
16: 15(ptr) Variable Uniform
|
||||||
|
17: 10(int) Constant 0
|
||||||
|
18: 10(int) Constant 2
|
||||||
|
19: 10(int) Constant 1
|
||||||
|
20: TypePointer Uniform 6(float)
|
||||||
|
25: TypePointer Output 6(float)
|
||||||
|
26(@entryPointOutput): 25(ptr) Variable Output
|
||||||
|
4(main): 2 Function None 3
|
||||||
|
5: Label
|
||||||
|
27: 6(float) FunctionCall 8(@main()
|
||||||
|
Store 26(@entryPointOutput) 27
|
||||||
|
Return
|
||||||
|
FunctionEnd
|
||||||
|
8(@main(): 6(float) Function None 7
|
||||||
|
9: Label
|
||||||
|
21: 20(ptr) AccessChain 16 17 18 19 19
|
||||||
|
22: 6(float) Load 21
|
||||||
|
ReturnValue 22
|
||||||
|
FunctionEnd
|
24
Test/hlsl.typeGraphCopy.vert
Normal file
24
Test/hlsl.typeGraphCopy.vert
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
struct N1 {
|
||||||
|
int a;
|
||||||
|
float b;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct N2 {
|
||||||
|
N1 s1;
|
||||||
|
N1 s2;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct N3 {
|
||||||
|
N2 t1;
|
||||||
|
N1 t2;
|
||||||
|
N2 t3;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef N3 T3;
|
||||||
|
|
||||||
|
T3 foo;
|
||||||
|
|
||||||
|
float main()
|
||||||
|
{
|
||||||
|
return foo.t3.s2.b;
|
||||||
|
}
|
@ -1202,30 +1202,11 @@ public:
|
|||||||
typeName = copyOf.typeName;
|
typeName = copyOf.typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make complete copy of the whole type graph rooted at 'copyOf'.
|
||||||
void deepCopy(const TType& copyOf)
|
void deepCopy(const TType& copyOf)
|
||||||
{
|
{
|
||||||
shallowCopy(copyOf);
|
TUnorderedMap<TTypeList*,TTypeList*> copied; // to enable copying a type graph as a graph, not a tree
|
||||||
|
deepCopy(copyOf, copied);
|
||||||
if (copyOf.arraySizes) {
|
|
||||||
arraySizes = new TArraySizes;
|
|
||||||
*arraySizes = *copyOf.arraySizes;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copyOf.structure) {
|
|
||||||
structure = new TTypeList;
|
|
||||||
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
|
|
||||||
TTypeLoc typeLoc;
|
|
||||||
typeLoc.loc = (*copyOf.structure)[i].loc;
|
|
||||||
typeLoc.type = new TType();
|
|
||||||
typeLoc.type->deepCopy(*(*copyOf.structure)[i].type);
|
|
||||||
structure->push_back(typeLoc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copyOf.fieldName)
|
|
||||||
fieldName = NewPoolTString(copyOf.fieldName->c_str());
|
|
||||||
if (copyOf.typeName)
|
|
||||||
typeName = NewPoolTString(copyOf.typeName->c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively make temporary
|
// Recursively make temporary
|
||||||
@ -1830,6 +1811,42 @@ protected:
|
|||||||
TType(const TType& type);
|
TType(const TType& type);
|
||||||
TType& operator=(const TType& type);
|
TType& operator=(const TType& type);
|
||||||
|
|
||||||
|
// Recursively copy a type graph, while preserving the graph-like
|
||||||
|
// quality. That is, don't make more than one copy of a structure that
|
||||||
|
// gets reused multiple times in the type graph.
|
||||||
|
void deepCopy(const TType& copyOf, TUnorderedMap<TTypeList*,TTypeList*>& copiedMap)
|
||||||
|
{
|
||||||
|
shallowCopy(copyOf);
|
||||||
|
|
||||||
|
if (copyOf.arraySizes) {
|
||||||
|
arraySizes = new TArraySizes;
|
||||||
|
*arraySizes = *copyOf.arraySizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (copyOf.structure) {
|
||||||
|
auto prevCopy = copiedMap.find(copyOf.structure);
|
||||||
|
if (prevCopy != copiedMap.end())
|
||||||
|
structure = prevCopy->second;
|
||||||
|
else {
|
||||||
|
structure = new TTypeList;
|
||||||
|
copiedMap[copyOf.structure] = structure;
|
||||||
|
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
|
||||||
|
TTypeLoc typeLoc;
|
||||||
|
typeLoc.loc = (*copyOf.structure)[i].loc;
|
||||||
|
typeLoc.type = new TType();
|
||||||
|
typeLoc.type->deepCopy(*(*copyOf.structure)[i].type, copiedMap);
|
||||||
|
structure->push_back(typeLoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (copyOf.fieldName)
|
||||||
|
fieldName = NewPoolTString(copyOf.fieldName->c_str());
|
||||||
|
if (copyOf.typeName)
|
||||||
|
typeName = NewPoolTString(copyOf.typeName->c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void buildMangledName(TString&);
|
void buildMangledName(TString&);
|
||||||
|
|
||||||
TBasicType basicType : 8;
|
TBasicType basicType : 8;
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
// For the date, it uses the current date (when then script is run).
|
// For the date, it uses the current date (when then script is run).
|
||||||
|
|
||||||
#define GLSLANG_REVISION "Overload400-PrecQual.1780"
|
#define GLSLANG_REVISION "Overload400-PrecQual.1780"
|
||||||
#define GLSLANG_DATE "20-Jan-2017"
|
#define GLSLANG_DATE "01-Feb-2017"
|
||||||
|
@ -235,6 +235,7 @@ INSTANTIATE_TEST_CASE_P(
|
|||||||
{"hlsl.tx.bracket.frag", "main"},
|
{"hlsl.tx.bracket.frag", "main"},
|
||||||
{"hlsl.type.half.frag", "main"},
|
{"hlsl.type.half.frag", "main"},
|
||||||
{"hlsl.type.identifier.frag", "main"},
|
{"hlsl.type.identifier.frag", "main"},
|
||||||
|
{"hlsl.typeGraphCopy.vert", "main"},
|
||||||
{"hlsl.typedef.frag", "PixelShaderFunction"},
|
{"hlsl.typedef.frag", "PixelShaderFunction"},
|
||||||
{"hlsl.whileLoop.frag", "PixelShaderFunction"},
|
{"hlsl.whileLoop.frag", "PixelShaderFunction"},
|
||||||
{"hlsl.void.frag", "PixelShaderFunction"},
|
{"hlsl.void.frag", "PixelShaderFunction"},
|
||||||
|
Loading…
Reference in New Issue
Block a user