Commit 41aa1995 by John Kessenich

HLSL: Partially flatten hierarchies, instead of all or nothing.

Fixes #1092. Allows arrays of opaques to keep arrayness, unless needed by uniform array flattening. Can handle assignments of mixed amounts of flattening.
parent 60e91611
hlsl.partialFlattenMixed.vert
WARNING: AST will form illegal SPIR-V; need to transform to legalize
Shader version: 500
0:? Sequence
0:10 Function Definition: @main(vf4; ( temp 4-component vector of float)
0:10 Function Parameters:
0:10 'pos' ( in 4-component vector of float)
0:? Sequence
0:13 Sequence
0:13 move second child to first child ( temp texture2D)
0:13 direct index ( temp texture2D)
0:? 'packed.membTex' ( temp 2-element array of texture2D)
0:13 Constant:
0:13 0 (const int)
0:? 'tex[0]' ( uniform texture2D)
0:13 move second child to first child ( temp texture2D)
0:13 direct index ( temp texture2D)
0:? 'packed.membTex' ( temp 2-element array of texture2D)
0:13 Constant:
0:13 1 (const int)
0:? 'tex[1]' ( uniform texture2D)
0:15 Branch: Return with expression
0:15 'pos' ( in 4-component vector of float)
0:10 Function Definition: main( ( temp void)
0:10 Function Parameters:
0:? Sequence
0:10 move second child to first child ( temp 4-component vector of float)
0:? 'pos' ( temp 4-component vector of float)
0:? 'pos' (layout( location=0) in 4-component vector of float)
0:10 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' ( out 4-component vector of float Position)
0:10 Function Call: @main(vf4; ( temp 4-component vector of float)
0:? 'pos' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'tex[0]' ( uniform texture2D)
0:? 'tex[1]' ( uniform texture2D)
0:? '@entryPointOutput' ( out 4-component vector of float Position)
0:? 'pos' (layout( location=0) in 4-component vector of float)
Linked vertex stage:
Shader version: 500
0:? Sequence
0:10 Function Definition: @main(vf4; ( temp 4-component vector of float)
0:10 Function Parameters:
0:10 'pos' ( in 4-component vector of float)
0:? Sequence
0:13 Sequence
0:13 move second child to first child ( temp texture2D)
0:13 direct index ( temp texture2D)
0:? 'packed.membTex' ( temp 2-element array of texture2D)
0:13 Constant:
0:13 0 (const int)
0:? 'tex[0]' ( uniform texture2D)
0:13 move second child to first child ( temp texture2D)
0:13 direct index ( temp texture2D)
0:? 'packed.membTex' ( temp 2-element array of texture2D)
0:13 Constant:
0:13 1 (const int)
0:? 'tex[1]' ( uniform texture2D)
0:15 Branch: Return with expression
0:15 'pos' ( in 4-component vector of float)
0:10 Function Definition: main( ( temp void)
0:10 Function Parameters:
0:? Sequence
0:10 move second child to first child ( temp 4-component vector of float)
0:? 'pos' ( temp 4-component vector of float)
0:? 'pos' (layout( location=0) in 4-component vector of float)
0:10 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' ( out 4-component vector of float Position)
0:10 Function Call: @main(vf4; ( temp 4-component vector of float)
0:? 'pos' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'tex[0]' ( uniform texture2D)
0:? 'tex[1]' ( uniform texture2D)
0:? '@entryPointOutput' ( out 4-component vector of float Position)
0:? 'pos' (layout( location=0) in 4-component vector of float)
// Module Version 10000
// Generated by (magic number): 80002
// Id's are bound by 42
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 35 38
Source HLSL 500
Name 4 "main"
Name 11 "@main(vf4;"
Name 10 "pos"
Name 18 "packed.membTex"
Name 22 "tex[0]"
Name 27 "tex[1]"
Name 33 "pos"
Name 35 "pos"
Name 38 "@entryPointOutput"
Name 39 "param"
Decorate 22(tex[0]) DescriptorSet 0
Decorate 27(tex[1]) DescriptorSet 0
Decorate 35(pos) Location 0
Decorate 38(@entryPointOutput) BuiltIn Position
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
9: TypeFunction 7(fvec4) 8(ptr)
13: TypeImage 6(float) 2D sampled format:Unknown
14: TypeInt 32 0
15: 14(int) Constant 2
16: TypeArray 13 15
17: TypePointer Function 16
19: TypeInt 32 1
20: 19(int) Constant 0
21: TypePointer UniformConstant 13
22(tex[0]): 21(ptr) Variable UniformConstant
24: TypePointer Function 13
26: 19(int) Constant 1
27(tex[1]): 21(ptr) Variable UniformConstant
34: TypePointer Input 7(fvec4)
35(pos): 34(ptr) Variable Input
37: TypePointer Output 7(fvec4)
38(@entryPointOutput): 37(ptr) Variable Output
4(main): 2 Function None 3
5: Label
33(pos): 8(ptr) Variable Function
39(param): 8(ptr) Variable Function
36: 7(fvec4) Load 35(pos)
Store 33(pos) 36
40: 7(fvec4) Load 33(pos)
Store 39(param) 40
41: 7(fvec4) FunctionCall 11(@main(vf4;) 39(param)
Store 38(@entryPointOutput) 41
Return
FunctionEnd
11(@main(vf4;): 7(fvec4) Function None 9
10(pos): 8(ptr) FunctionParameter
12: Label
18(packed.membTex): 17(ptr) Variable Function
23: 13 Load 22(tex[0])
25: 24(ptr) AccessChain 18(packed.membTex) 20
Store 25 23
28: 13 Load 27(tex[1])
29: 24(ptr) AccessChain 18(packed.membTex) 26
Store 29 28
30: 7(fvec4) Load 10(pos)
ReturnValue 30
FunctionEnd
Texture2D tex;
struct Packed {
Texture2D tex;
float3 pos[3];
float2 uv[2];
float x;
int n;
};
float4 main(float4 pos : POSITION) : SV_POSITION
{
Packed packed;
packed.tex = tex;
packed.pos[0] = float3(0, 0, 0);
packed.uv[0] = float2(0, 1);
packed.x = 1.0;
packed.n = 3;
for (int i = 0; i < 1; ++i) {
packed.pos[i].xy += packed.uv[i];
}
Packed packed2 = packed;
return pos + float4(packed2.pos[0], 0);
}
\ No newline at end of file
Texture2D tex[2];
struct Packed {
int a;
Texture2D membTex[2];
int b;
};
float4 main(float4 pos : POSITION) : SV_POSITION
{
Packed packed;
packed.membTex = tex;
return pos;
}
\ No newline at end of file
...@@ -247,6 +247,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -247,6 +247,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.params.default.frag", "main"}, {"hlsl.params.default.frag", "main"},
{"hlsl.params.default.negative.frag", "main"}, {"hlsl.params.default.negative.frag", "main"},
{"hlsl.partialInit.frag", "PixelShaderFunction"}, {"hlsl.partialInit.frag", "PixelShaderFunction"},
{"hlsl.partialFlattenLocal.vert", "main"},
{"hlsl.pp.vert", "main"}, {"hlsl.pp.vert", "main"},
{"hlsl.pp.line.frag", "main"}, {"hlsl.pp.line.frag", "main"},
{"hlsl.precise.frag", "main"}, {"hlsl.precise.frag", "main"},
...@@ -367,6 +368,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -367,6 +368,7 @@ INSTANTIATE_TEST_CASE_P(
ToSpirv, HlslCompileAndFlattenTest, ToSpirv, HlslCompileAndFlattenTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{ ::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.array.flatten.frag", "main"}, {"hlsl.array.flatten.frag", "main"},
{"hlsl.partialFlattenMixed.vert", "main"},
}), }),
FileNameAsCustomTestSuffix FileNameAsCustomTestSuffix
); );
......
...@@ -244,15 +244,14 @@ protected: ...@@ -244,15 +244,14 @@ protected:
// Array and struct flattening // Array and struct flattening
TIntermTyped* flattenAccess(TIntermTyped* base, int member); TIntermTyped* flattenAccess(TIntermTyped* base, int member);
TIntermTyped* flattenAccess(int uniqueId, int member, const TType&, int subset = -1); TIntermTyped* flattenAccess(int uniqueId, int member, TStorageQualifier outerStorage, const TType&, int subset = -1);
int findSubtreeOffset(const TIntermNode&) const; int findSubtreeOffset(const TIntermNode&) const;
int findSubtreeOffset(const TType&, int subset, const TVector<int>& offsets) const; int findSubtreeOffset(const TType&, int subset, const TVector<int>& offsets) const;
bool shouldFlatten(const TType&) const; bool shouldFlatten(const TType&, TStorageQualifier, bool topLevel) const;
bool wasFlattened(const TIntermTyped* node) const; bool wasFlattened(const TIntermTyped* node) const;
bool wasFlattened(int id) const { return flattenMap.find(id) != flattenMap.end(); } bool wasFlattened(int id) const { return flattenMap.find(id) != flattenMap.end(); }
int addFlattenedMember(const TVariable&, const TType&, TFlattenData&, const TString& name, bool linkage, int addFlattenedMember(const TVariable&, const TType&, TFlattenData&, const TString& name, bool linkage,
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes); const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
bool isFinalFlattening(const TType& type) const { return !(type.isStruct() || type.isArray()); }
// Structure splitting (splits interstage built-in types into its own struct) // Structure splitting (splits interstage built-in types into its own struct)
void split(const TVariable&); void split(const TVariable&);
......
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