Skip to content

Commit

Permalink
Add link-time cross stage optimization test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-story authored and arcady-lunarg committed Oct 8, 2024
1 parent 05559a2 commit 2acc4ea
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 0 deletions.
232 changes: 232 additions & 0 deletions Test/baseResults/link.crossStageOptimization.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
link.crossStageOptimization.vert
link.crossStageOptimization.frag
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 88

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 9 60 84
Source GLSL 440
Name 4 "main"
Name 9 "a0"
Name 10 "AccessedUniformBlock"
MemberName 10(AccessedUniformBlock) 0 "a"
MemberName 10(AccessedUniformBlock) 1 "b"
Name 12 ""
Name 21 "AccessedStorageBlock"
MemberName 21(AccessedStorageBlock) 0 "e"
Name 23 ""
Name 32 "uSampler0"
Name 41 "a1"
Name 42 "NotAccessedUniformBlock"
MemberName 42(NotAccessedUniformBlock) 0 "c"
MemberName 42(NotAccessedUniformBlock) 1 "d"
Name 44 ""
Name 48 "NotAccessedStorageBlock"
MemberName 48(NotAccessedStorageBlock) 0 "f"
Name 50 ""
Name 56 "uSampler1"
Name 60 "a2"
Name 70 "a3"
Name 82 "gl_PerVertex"
MemberName 82(gl_PerVertex) 0 "gl_Position"
MemberName 82(gl_PerVertex) 1 "gl_PointSize"
MemberName 82(gl_PerVertex) 2 "gl_ClipDistance"
Name 84 ""
Decorate 9(a0) Location 0
Decorate 10(AccessedUniformBlock) Block
MemberDecorate 10(AccessedUniformBlock) 0 Offset 0
MemberDecorate 10(AccessedUniformBlock) 1 Offset 16
Decorate 12 Binding 0
Decorate 12 DescriptorSet 0
Decorate 20 ArrayStride 4
Decorate 21(AccessedStorageBlock) BufferBlock
MemberDecorate 21(AccessedStorageBlock) 0 Offset 0
Decorate 23 Binding 2
Decorate 23 DescriptorSet 0
Decorate 32(uSampler0) Binding 4
Decorate 32(uSampler0) DescriptorSet 0
Decorate 42(NotAccessedUniformBlock) Block
MemberDecorate 42(NotAccessedUniformBlock) 0 Offset 0
MemberDecorate 42(NotAccessedUniformBlock) 1 Offset 16
Decorate 44 Binding 1
Decorate 44 DescriptorSet 0
Decorate 47 ArrayStride 4
Decorate 48(NotAccessedStorageBlock) BufferBlock
MemberDecorate 48(NotAccessedStorageBlock) 0 Offset 0
Decorate 50 Binding 3
Decorate 50 DescriptorSet 0
Decorate 56(uSampler1) Binding 5
Decorate 56(uSampler1) DescriptorSet 0
Decorate 60(a2) Location 2
Decorate 82(gl_PerVertex) Block
MemberDecorate 82(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 82(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 82(gl_PerVertex) 2 BuiltIn ClipDistance
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(a0): 8(ptr) Variable Output
10(AccessedUniformBlock): TypeStruct 7(fvec4) 7(fvec4)
11: TypePointer Uniform 10(AccessedUniformBlock)
12: 11(ptr) Variable Uniform
13: TypeInt 32 1
14: 13(int) Constant 0
15: TypePointer Uniform 7(fvec4)
18: TypeInt 32 0
19: 18(int) Constant 512
20: TypeArray 6(float) 19
21(AccessedStorageBlock): TypeStruct 20
22: TypePointer Uniform 21(AccessedStorageBlock)
23: 22(ptr) Variable Uniform
24: TypePointer Uniform 6(float)
29: TypeImage 6(float) 2D sampled format:Unknown
30: TypeSampledImage 29
31: TypePointer UniformConstant 30
32(uSampler0): 31(ptr) Variable UniformConstant
34: TypeVector 6(float) 2
35: 6(float) Constant 1056964608
36: 34(fvec2) ConstantComposite 35 35
37: 6(float) Constant 0
40: TypePointer Private 7(fvec4)
41(a1): 40(ptr) Variable Private
42(NotAccessedUniformBlock): TypeStruct 7(fvec4) 7(fvec4)
43: TypePointer Uniform 42(NotAccessedUniformBlock)
44: 43(ptr) Variable Uniform
47: TypeArray 6(float) 19
48(NotAccessedStorageBlock): TypeStruct 47
49: TypePointer Uniform 48(NotAccessedStorageBlock)
50: 49(ptr) Variable Uniform
51: 13(int) Constant 1
56(uSampler1): 31(ptr) Variable UniformConstant
60(a2): 8(ptr) Variable Output
70(a3): 40(ptr) Variable Private
80: 18(int) Constant 1
81: TypeArray 6(float) 80
82(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 81
83: TypePointer Output 82(gl_PerVertex)
84: 83(ptr) Variable Output
85: 6(float) Constant 1065353216
86: 7(fvec4) ConstantComposite 85 85 85 85
4(main): 2 Function None 3
5: Label
16: 15(ptr) AccessChain 12 14
17: 7(fvec4) Load 16
25: 24(ptr) AccessChain 23 14 14
26: 6(float) Load 25
27: 7(fvec4) CompositeConstruct 26 26 26 26
28: 7(fvec4) FAdd 17 27
33: 30 Load 32(uSampler0)
38: 7(fvec4) ImageSampleExplicitLod 33 36 Lod 37
39: 7(fvec4) FAdd 28 38
Store 9(a0) 39
45: 15(ptr) AccessChain 44 14
46: 7(fvec4) Load 45
52: 24(ptr) AccessChain 50 14 51
53: 6(float) Load 52
54: 7(fvec4) CompositeConstruct 53 53 53 53
55: 7(fvec4) FAdd 46 54
57: 30 Load 56(uSampler1)
58: 7(fvec4) ImageSampleExplicitLod 57 36 Lod 37
59: 7(fvec4) FAdd 55 58
Store 41(a1) 59
61: 15(ptr) AccessChain 12 51
62: 7(fvec4) Load 61
63: 24(ptr) AccessChain 23 14 14
64: 6(float) Load 63
65: 7(fvec4) CompositeConstruct 64 64 64 64
66: 7(fvec4) FAdd 62 65
67: 30 Load 32(uSampler0)
68: 7(fvec4) ImageSampleExplicitLod 67 36 Lod 37
69: 7(fvec4) FAdd 66 68
Store 60(a2) 69
71: 15(ptr) AccessChain 44 51
72: 7(fvec4) Load 71
73: 24(ptr) AccessChain 50 14 51
74: 6(float) Load 73
75: 7(fvec4) CompositeConstruct 74 74 74 74
76: 7(fvec4) FAdd 72 75
77: 30 Load 56(uSampler1)
78: 7(fvec4) ImageSampleExplicitLod 77 36 Lod 37
79: 7(fvec4) FAdd 76 78
Store 70(a3) 79
87: 8(ptr) AccessChain 84 14
Store 87 86
Return
FunctionEnd
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 40

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 17 21 38
ExecutionMode 4 OriginUpperLeft
Source GLSL 440
Name 4 "main"
Name 9 "temp"
Name 17 "a0"
Name 21 "a2"
Name 29 "a1"
Name 33 "a3"
Name 38 "oColor"
Decorate 17(a0) Location 0
Decorate 21(a2) Location 2
Decorate 38(oColor) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
10: 6(float) Constant 1065353216
11: 7(fvec4) ConstantComposite 10 10 10 10
12: TypeBool
13: 12(bool) ConstantTrue
16: TypePointer Input 7(fvec4)
17(a0): 16(ptr) Variable Input
21(a2): 16(ptr) Variable Input
25: 12(bool) ConstantFalse
28: TypePointer Private 7(fvec4)
29(a1): 28(ptr) Variable Private
33(a3): 28(ptr) Variable Private
37: TypePointer Output 7(fvec4)
38(oColor): 37(ptr) Variable Output
4(main): 2 Function None 3
5: Label
9(temp): 8(ptr) Variable Function
Store 9(temp) 11
SelectionMerge 15 None
BranchConditional 13 14 15
14: Label
18: 7(fvec4) Load 17(a0)
19: 7(fvec4) Load 9(temp)
20: 7(fvec4) FMul 19 18
Store 9(temp) 20
22: 7(fvec4) Load 21(a2)
23: 7(fvec4) Load 9(temp)
24: 7(fvec4) FMul 23 22
Store 9(temp) 24
Branch 15
15: Label
SelectionMerge 27 None
BranchConditional 25 26 27
26: Label
30: 7(fvec4) Load 29(a1)
31: 7(fvec4) Load 9(temp)
32: 7(fvec4) FMul 31 30
Store 9(temp) 32
34: 7(fvec4) Load 33(a3)
35: 7(fvec4) Load 9(temp)
36: 7(fvec4) FMul 35 34
Store 9(temp) 36
Branch 27
27: Label
39: 7(fvec4) Load 9(temp)
Store 38(oColor) 39
Return
FunctionEnd
24 changes: 24 additions & 0 deletions Test/link.crossStageOptimization.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#version 440

layout(location = 0) in vec4 a0; // accessed
layout(location = 1) in vec4 a1; // not accessed
layout(location = 2) in vec4 a2; // accessed
layout(location = 3) in vec4 a3; // not accessed

layout(location = 0) out vec4 oColor;

void main()
{
vec4 temp = vec4(1.0);
if (true)
{
temp *= a0;
temp *= a2;
}
if (false)
{
temp *= a1;
temp *= a3;
}
oColor = temp;
}
41 changes: 41 additions & 0 deletions Test/link.crossStageOptimization.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#version 440

layout(std140) uniform AccessedUniformBlock
{
vec4 a;
vec4 b;
};

layout(std140) uniform NotAccessedUniformBlock
{
vec4 c;
vec4 d;
};

layout(std430) buffer AccessedStorageBlock
{
float e[512];
};

layout(std430) buffer NotAccessedStorageBlock
{
float f[512];
};

uniform sampler2D uSampler0; // accessed
uniform sampler2D uSampler1; // not accessed

layout(location = 0) out vec4 a0; // accessed
layout(location = 1) out vec4 a1; // not accessed
layout(location = 2) out vec4 a2; // accessed
layout(location = 3) out vec4 a3; // not accessed

void main()
{
a0 = a + vec4(e[0]) + texture(uSampler0, vec2(0.5, 0.5));
a1 = c + vec4(f[1]) + texture(uSampler1, vec2(0.5, 0.5));
a2 = b + vec4(e[0]) + texture(uSampler0, vec2(0.5, 0.5));
a3 = d + vec4(f[1]) + texture(uSampler1, vec2(0.5, 0.5));

gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
}
7 changes: 7 additions & 0 deletions Test/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ echo "Testing UTF8BOM"
run --glsl-version 410 -V -S vert UTF8BOM.vert > $TARGETDIR/UTF8BOM.vert.out
diff -b $BASEDIR/UTF8BOM.vert.out $TARGETDIR/UTF8BOM.vert.out || HASERROR=1

#
# Test LTO
#
echo "Testing link-time optimization"
run -V -H --amb --aml -l --lto link.crossStageOptimization.vert link.crossStageOptimization.frag > "$TARGETDIR/link.crossStageOptimization.out"
diff -b $BASEDIR/link.crossStageOptimization.out "$TARGETDIR/link.crossStageOptimization.out" || HASERROR=1

#
# Final checking
#
Expand Down

0 comments on commit 2acc4ea

Please sign in to comment.