From 2acc4ea0028bc703be2d4e9bc8a4032d015d6516 Mon Sep 17 00:00:00 2001 From: Daniel Story Date: Mon, 23 Sep 2024 16:44:52 -0700 Subject: [PATCH] Add link-time cross stage optimization test --- .../link.crossStageOptimization.out | 232 ++++++++++++++++++ Test/link.crossStageOptimization.frag | 24 ++ Test/link.crossStageOptimization.vert | 41 ++++ Test/runtests | 7 + 4 files changed, 304 insertions(+) create mode 100644 Test/baseResults/link.crossStageOptimization.out create mode 100644 Test/link.crossStageOptimization.frag create mode 100644 Test/link.crossStageOptimization.vert diff --git a/Test/baseResults/link.crossStageOptimization.out b/Test/baseResults/link.crossStageOptimization.out new file mode 100644 index 00000000..1189c087 --- /dev/null +++ b/Test/baseResults/link.crossStageOptimization.out @@ -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 diff --git a/Test/link.crossStageOptimization.frag b/Test/link.crossStageOptimization.frag new file mode 100644 index 00000000..af7c2c4d --- /dev/null +++ b/Test/link.crossStageOptimization.frag @@ -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; +} diff --git a/Test/link.crossStageOptimization.vert b/Test/link.crossStageOptimization.vert new file mode 100644 index 00000000..159c1338 --- /dev/null +++ b/Test/link.crossStageOptimization.vert @@ -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); +} diff --git a/Test/runtests b/Test/runtests index 6b23cd44..cc4134fe 100755 --- a/Test/runtests +++ b/Test/runtests @@ -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 #