From f8a2442a165834d948cf3364a0e3816fcbc89ab9 Mon Sep 17 00:00:00 2001 From: Qingyuan Zheng Date: Tue, 14 Mar 2023 10:36:24 -0700 Subject: [PATCH] Improve line info for symbol access and assignment --- SPIRV/GlslangToSpv.cpp | 7 + Test/baseResults/spv.debugInfo.1.1.frag.out | 505 ++++++++++++------- Test/baseResults/spv.debugInfo.frag.out | 507 +++++++++++++------- Test/spv.debugInfo.frag | 31 ++ 4 files changed, 683 insertions(+), 367 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 713db67df..1a271e27c 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -2004,6 +2004,10 @@ void TGlslangToSpvTraverser::dumpSpv(std::vector& out) // void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol) { + // We update the line information even though no code might be generated here + // This is helpful to yield correct lines for control flow instructions + builder.setLine(symbol->getLoc().line, symbol->getLoc().getFilename()); + SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder); if (symbol->getType().isStruct()) glslangTypeToIdMap[symbol->getType().getStruct()] = symbol->getId(); @@ -2155,6 +2159,9 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T node->getRight()->traverse(this); spv::Id rValue = accessChainLoad(node->getRight()->getType()); + // reset line number for assignment + builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + if (node->getOp() != glslang::EOpAssign) { // the left is also an r-value builder.setAccessChain(lValue); diff --git a/Test/baseResults/spv.debugInfo.1.1.frag.out b/Test/baseResults/spv.debugInfo.1.1.frag.out index 67175de96..127267560 100644 --- a/Test/baseResults/spv.debugInfo.1.1.frag.out +++ b/Test/baseResults/spv.debugInfo.1.1.frag.out @@ -1,12 +1,12 @@ spv.debugInfo.frag // Module Version 10300 // Generated by (magic number): 8000b -// Id's are bound by 124 +// Id's are bound by 187 Capability Shader 2: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 5 "main" 24 52 + EntryPoint Fragment 5 "main" 30 104 ExecutionMode 5 OriginUpperLeft 1: String "spv.debugInfo.frag" Source GLSL 450 1 "#version 450 @@ -36,9 +36,40 @@ vec4 foo(S s) return r; } +float testBranch(float x, float y) +{ + float result = 0; + bool b = x > 0; + + // branch with load + if (b) { + result += 1; + } + else { + result -= 1; + } + + // branch with expression + if (x > y) { + result += x - y; + } + + // selection with load + result += b ? + 1 : -1; + + // selection with expression + result += x < y ? + y : + float(b); + + return result; +} + void main() { outv = foo(s); + outv += testBranch(inv.x, inv.y); outv += texture(s2d, vec2(0.5)); switch (s.a) { @@ -66,17 +97,24 @@ void main() MemberName 8(S) 0 "a" Name 14 "foo(struct-S-i11;" Name 13 "s" - Name 17 "r" - Name 24 "inv" - Name 52 "outv" - Name 53 "S" - MemberName 53(S) 0 "a" - Name 54 "ubuf" - MemberName 54(ubuf) 0 "s" - Name 56 "" - Name 57 "param" - Name 67 "s2d" - Name 97 "i" + Name 20 "testBranch(f1;f1;" + Name 18 "x" + Name 19 "y" + Name 23 "r" + Name 30 "inv" + Name 56 "result" + Name 59 "b" + Name 104 "outv" + Name 105 "S" + MemberName 105(S) 0 "a" + Name 106 "ubuf" + MemberName 106(ubuf) 0 "s" + Name 108 "" + Name 109 "param" + Name 116 "param" + Name 120 "param" + Name 131 "s2d" + Name 161 "i" ModuleProcessed "no-storage-format" ModuleProcessed "resource-set-binding 3" ModuleProcessed "auto-map-bindings" @@ -88,15 +126,15 @@ void main() ModuleProcessed "suppress-warnings" ModuleProcessed "hlsl-offsets" ModuleProcessed "entry-point main" - Decorate 24(inv) Location 0 - Decorate 52(outv) Location 0 - MemberDecorate 53(S) 0 Offset 0 - MemberDecorate 54(ubuf) 0 Offset 0 - Decorate 54(ubuf) Block - Decorate 56 DescriptorSet 3 - Decorate 56 Binding 0 - Decorate 67(s2d) DescriptorSet 3 - Decorate 67(s2d) Binding 1 + Decorate 30(inv) Location 0 + Decorate 104(outv) Location 0 + MemberDecorate 105(S) 0 Offset 0 + MemberDecorate 106(ubuf) 0 Offset 0 + Decorate 106(ubuf) Block + Decorate 108 DescriptorSet 3 + Decorate 108 Binding 0 + Decorate 131(s2d) DescriptorSet 3 + Decorate 131(s2d) Binding 1 3: TypeVoid 4: TypeFunction 3 7: TypeInt 32 1 @@ -105,179 +143,280 @@ void main() 10: TypeFloat 32 11: TypeVector 10(float) 4 12: TypeFunction 11(fvec4) 9(ptr) - 16: TypePointer Function 11(fvec4) - 18: 7(int) Constant 0 - 19: TypePointer Function 7(int) - 23: TypePointer Input 11(fvec4) - 24(inv): 23(ptr) Variable Input - 28: 10(float) Constant 1065353216 - 31: TypeInt 32 0 - 32: 31(int) Constant 0 - 33: TypePointer Function 10(float) - 36: 10(float) Constant 1077936128 - 37: TypeBool - 45: 10(float) Constant 1073741824 - 51: TypePointer Output 11(fvec4) - 52(outv): 51(ptr) Variable Output - 53(S): TypeStruct 7(int) - 54(ubuf): TypeStruct 53(S) - 55: TypePointer Uniform 54(ubuf) - 56: 55(ptr) Variable Uniform - 58: TypePointer Uniform 53(S) - 64: TypeImage 10(float) 2D sampled format:Unknown - 65: TypeSampledImage 64 - 66: TypePointer UniformConstant 65 - 67(s2d): 66(ptr) Variable UniformConstant - 69: TypeVector 10(float) 2 - 70: 10(float) Constant 1056964608 - 71: 69(fvec2) ConstantComposite 70 70 - 75: TypePointer Uniform 7(int) - 104: 7(int) Constant 10 - 109: 7(int) Constant 1 - 111: TypePointer Output 10(float) - 114: 10(float) Constant 1092616192 - Line 1 28 11 + 16: TypePointer Function 10(float) + 17: TypeFunction 10(float) 16(ptr) 16(ptr) + 22: TypePointer Function 11(fvec4) + 24: 7(int) Constant 0 + 25: TypePointer Function 7(int) + 29: TypePointer Input 11(fvec4) + 30(inv): 29(ptr) Variable Input + 34: 10(float) Constant 1065353216 + 37: TypeInt 32 0 + 38: 37(int) Constant 0 + 41: 10(float) Constant 1077936128 + 42: TypeBool + 50: 10(float) Constant 1073741824 + 57: 10(float) Constant 0 + 58: TypePointer Function 42(bool) + 81: 7(int) Constant 1 + 82: 7(int) Constant 4294967295 + 103: TypePointer Output 11(fvec4) + 104(outv): 103(ptr) Variable Output + 105(S): TypeStruct 7(int) + 106(ubuf): TypeStruct 105(S) + 107: TypePointer Uniform 106(ubuf) + 108: 107(ptr) Variable Uniform + 110: TypePointer Uniform 105(S) + 117: TypePointer Input 10(float) + 121: 37(int) Constant 1 + 128: TypeImage 10(float) 2D sampled format:Unknown + 129: TypeSampledImage 128 + 130: TypePointer UniformConstant 129 + 131(s2d): 130(ptr) Variable UniformConstant + 133: TypeVector 10(float) 2 + 134: 10(float) Constant 1056964608 + 135: 133(fvec2) ConstantComposite 134 134 + 139: TypePointer Uniform 7(int) + 168: 7(int) Constant 10 + 174: TypePointer Output 10(float) + 177: 10(float) Constant 1092616192 + Line 1 58 11 5(main): 3 Function None 4 6: Label - 57(param): 9(ptr) Variable Function - 97(i): 19(ptr) Variable Function - 116: 16(ptr) Variable Function - Line 1 30 0 - 59: 58(ptr) AccessChain 56 18 - 60: 53(S) Load 59 - 61: 7(int) CompositeExtract 60 0 - 62: 19(ptr) AccessChain 57(param) 18 - Store 62 61 - 63: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 57(param) - Store 52(outv) 63 - Line 1 31 0 - 68: 65 Load 67(s2d) - 72: 11(fvec4) ImageSampleImplicitLod 68 71 - 73: 11(fvec4) Load 52(outv) - 74: 11(fvec4) FAdd 73 72 - Store 52(outv) 74 - Line 1 33 0 - 76: 75(ptr) AccessChain 56 18 18 - 77: 7(int) Load 76 - SelectionMerge 81 None - Switch 77 80 - case 10: 78 - case 20: 79 - 80: Label - Line 1 42 0 - 92: 11(fvec4) Load 52(outv) - 93: 11(fvec4) CompositeConstruct 28 28 28 28 - 94: 11(fvec4) FSub 92 93 - Store 52(outv) 94 - Line 1 43 0 - Branch 81 - 78: Label - Line 1 35 0 - 82: 11(fvec4) Load 52(outv) - 83: 11(fvec4) CompositeConstruct 28 28 28 28 - 84: 11(fvec4) FAdd 82 83 - Store 52(outv) 84 - Line 1 36 0 - Branch 81 - 79: Label - Line 1 38 0 - 86: 11(fvec4) Load 52(outv) - 87: 11(fvec4) VectorTimesScalar 86 45 - Store 52(outv) 87 - Line 1 39 0 - 88: 11(fvec4) Load 52(outv) - 89: 11(fvec4) CompositeConstruct 28 28 28 28 - 90: 11(fvec4) FAdd 88 89 - Store 52(outv) 90 - Line 1 40 0 - Branch 81 - 81: Label - Line 1 46 0 - Store 97(i) 18 - Branch 98 - 98: Label - Line 1 46 0 - LoopMerge 100 101 None - Branch 102 - 102: Label - Line 1 46 0 - 103: 7(int) Load 97(i) - 105: 37(bool) SLessThan 103 104 - BranchConditional 105 99 100 - 99: Label - Line 1 47 0 - 106: 11(fvec4) Load 52(outv) - 107: 11(fvec4) VectorTimesScalar 106 36 - Store 52(outv) 107 - Branch 101 - 101: Label - Line 1 46 0 - 108: 7(int) Load 97(i) - 110: 7(int) IAdd 108 109 - Store 97(i) 110 - Branch 98 - 100: Label - Line 1 49 0 - 112: 111(ptr) AccessChain 52(outv) 32 - 113: 10(float) Load 112 - 115: 37(bool) FOrdLessThan 113 114 - SelectionMerge 118 None - BranchConditional 115 117 121 - 117: Label - Line 1 50 0 - 119: 11(fvec4) Load 52(outv) - 120: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 119 - Store 52(outv) 120 - Store 116 120 - Branch 118 - 121: Label - Line 1 51 0 - 122: 11(fvec4) Load 52(outv) - 123: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 122 - Store 52(outv) 123 - Store 116 123 - Branch 118 - 118: Label + 109(param): 9(ptr) Variable Function + 116(param): 16(ptr) Variable Function + 120(param): 16(ptr) Variable Function + 161(i): 25(ptr) Variable Function + 179: 22(ptr) Variable Function + Line 1 60 0 + 111: 110(ptr) AccessChain 108 24 + 112: 105(S) Load 111 + 113: 7(int) CompositeExtract 112 0 + 114: 25(ptr) AccessChain 109(param) 24 + Store 114 113 + 115: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 109(param) + Store 104(outv) 115 + Line 1 61 0 + 118: 117(ptr) AccessChain 30(inv) 38 + 119: 10(float) Load 118 + Store 116(param) 119 + 122: 117(ptr) AccessChain 30(inv) 121 + 123: 10(float) Load 122 + Store 120(param) 123 + 124: 10(float) FunctionCall 20(testBranch(f1;f1;) 116(param) 120(param) + 125: 11(fvec4) Load 104(outv) + 126: 11(fvec4) CompositeConstruct 124 124 124 124 + 127: 11(fvec4) FAdd 125 126 + Store 104(outv) 127 + Line 1 62 0 + 132: 129 Load 131(s2d) + 136: 11(fvec4) ImageSampleImplicitLod 132 135 + 137: 11(fvec4) Load 104(outv) + 138: 11(fvec4) FAdd 137 136 + Store 104(outv) 138 + Line 1 64 0 + 140: 139(ptr) AccessChain 108 24 24 + 141: 7(int) Load 140 + SelectionMerge 145 None + Switch 141 144 + case 10: 142 + case 20: 143 + 144: Label + Line 1 73 0 + 156: 11(fvec4) Load 104(outv) + 157: 11(fvec4) CompositeConstruct 34 34 34 34 + 158: 11(fvec4) FSub 156 157 + Store 104(outv) 158 + Line 1 74 0 + Branch 145 + 142: Label + Line 1 66 0 + 146: 11(fvec4) Load 104(outv) + 147: 11(fvec4) CompositeConstruct 34 34 34 34 + 148: 11(fvec4) FAdd 146 147 + Store 104(outv) 148 + Line 1 67 0 + Branch 145 + 143: Label + Line 1 69 0 + 150: 11(fvec4) Load 104(outv) + 151: 11(fvec4) VectorTimesScalar 150 50 + Store 104(outv) 151 + Line 1 70 0 + 152: 11(fvec4) Load 104(outv) + 153: 11(fvec4) CompositeConstruct 34 34 34 34 + 154: 11(fvec4) FAdd 152 153 + Store 104(outv) 154 + Line 1 71 0 + Branch 145 + 145: Label + Line 1 77 0 + Store 161(i) 24 + Branch 162 + 162: Label + Line 1 77 0 + LoopMerge 164 165 None + Branch 166 + 166: Label + Line 1 77 0 + 167: 7(int) Load 161(i) + 169: 42(bool) SLessThan 167 168 + BranchConditional 169 163 164 + 163: Label + Line 1 78 0 + 170: 11(fvec4) Load 104(outv) + 171: 11(fvec4) VectorTimesScalar 170 41 + Store 104(outv) 171 + Branch 165 + 165: Label + Line 1 77 0 + 172: 7(int) Load 161(i) + 173: 7(int) IAdd 172 81 + Store 161(i) 173 + Branch 162 + 164: Label + Line 1 80 0 + 175: 174(ptr) AccessChain 104(outv) 38 + 176: 10(float) Load 175 + 178: 42(bool) FOrdLessThan 176 177 + SelectionMerge 181 None + BranchConditional 178 180 184 + 180: Label + Line 1 81 0 + 182: 11(fvec4) Load 104(outv) + 183: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 182 + Store 104(outv) 183 + Store 179 183 + Branch 181 + 184: Label + Line 1 82 0 + 185: 11(fvec4) Load 104(outv) + 186: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 185 + Store 104(outv) 186 + Store 179 186 + Branch 181 + 181: Label Return FunctionEnd Line 1 16 13 14(foo(struct-S-i11;): 11(fvec4) Function None 12 13(s): 9(ptr) FunctionParameter 15: Label - 17(r): 16(ptr) Variable Function + 23(r): 22(ptr) Variable Function Line 1 18 0 - 20: 19(ptr) AccessChain 13(s) 18 - 21: 7(int) Load 20 - 22: 10(float) ConvertSToF 21 - 25: 11(fvec4) Load 24(inv) - 26: 11(fvec4) VectorTimesScalar 25 22 - Store 17(r) 26 + 26: 25(ptr) AccessChain 13(s) 24 + 27: 7(int) Load 26 + 28: 10(float) ConvertSToF 27 + 31: 11(fvec4) Load 30(inv) + 32: 11(fvec4) VectorTimesScalar 31 28 + Store 23(r) 32 Line 1 19 0 - 27: 11(fvec4) Load 17(r) - 29: 11(fvec4) CompositeConstruct 28 28 28 28 - 30: 11(fvec4) FAdd 27 29 - Store 17(r) 30 + 33: 11(fvec4) Load 23(r) + 35: 11(fvec4) CompositeConstruct 34 34 34 34 + 36: 11(fvec4) FAdd 33 35 + Store 23(r) 36 Line 1 20 0 - 34: 33(ptr) AccessChain 17(r) 32 - 35: 10(float) Load 34 - 38: 37(bool) FOrdGreaterThan 35 36 - SelectionMerge 40 None - BranchConditional 38 39 44 - 39: Label - Line 1 21 0 - 41: 11(fvec4) Load 17(r) - 42: 11(fvec4) CompositeConstruct 28 28 28 28 - 43: 11(fvec4) FSub 41 42 - Store 17(r) 43 - Branch 40 + 39: 16(ptr) AccessChain 23(r) 38 + 40: 10(float) Load 39 + 43: 42(bool) FOrdGreaterThan 40 41 + SelectionMerge 45 None + BranchConditional 43 44 49 44: Label + Line 1 21 0 + 46: 11(fvec4) Load 23(r) + 47: 11(fvec4) CompositeConstruct 34 34 34 34 + 48: 11(fvec4) FSub 46 47 + Store 23(r) 48 + Branch 45 + 49: Label Line 1 23 0 - 46: 11(fvec4) Load 17(r) - 47: 11(fvec4) VectorTimesScalar 46 45 - Store 17(r) 47 - Branch 40 - 40: Label + 51: 11(fvec4) Load 23(r) + 52: 11(fvec4) VectorTimesScalar 51 50 + Store 23(r) 52 + Branch 45 + 45: Label Line 1 25 0 - 48: 11(fvec4) Load 17(r) - ReturnValue 48 + 53: 11(fvec4) Load 23(r) + ReturnValue 53 + FunctionEnd + Line 1 28 34 +20(testBranch(f1;f1;): 10(float) Function None 17 + 18(x): 16(ptr) FunctionParameter + 19(y): 16(ptr) FunctionParameter + 21: Label + 56(result): 16(ptr) Variable Function + 59(b): 58(ptr) Variable Function + 90: 16(ptr) Variable Function + Line 1 30 0 + Store 56(result) 57 + Line 1 31 0 + 60: 10(float) Load 18(x) + 61: 42(bool) FOrdGreaterThan 60 57 + Store 59(b) 61 + Line 1 34 0 + 62: 42(bool) Load 59(b) + SelectionMerge 64 None + BranchConditional 62 63 67 + 63: Label + Line 1 35 0 + 65: 10(float) Load 56(result) + 66: 10(float) FAdd 65 34 + Store 56(result) 66 + Branch 64 + 67: Label + Line 1 38 0 + 68: 10(float) Load 56(result) + 69: 10(float) FSub 68 34 + Store 56(result) 69 + Branch 64 + 64: Label + Line 1 42 0 + 70: 10(float) Load 18(x) + 71: 10(float) Load 19(y) + 72: 42(bool) FOrdGreaterThan 70 71 + SelectionMerge 74 None + BranchConditional 72 73 74 + 73: Label + Line 1 43 0 + 75: 10(float) Load 18(x) + 76: 10(float) Load 19(y) + 77: 10(float) FSub 75 76 + 78: 10(float) Load 56(result) + 79: 10(float) FAdd 78 77 + Store 56(result) 79 + Branch 74 + 74: Label + Line 1 47 0 + 80: 42(bool) Load 59(b) + 83: 7(int) Select 80 81 82 + 84: 10(float) ConvertSToF 83 + 85: 10(float) Load 56(result) + 86: 10(float) FAdd 85 84 + Store 56(result) 86 + Line 1 51 0 + 87: 10(float) Load 18(x) + 88: 10(float) Load 19(y) + 89: 42(bool) FOrdLessThan 87 88 + SelectionMerge 92 None + BranchConditional 89 91 94 + 91: Label + Line 1 52 0 + 93: 10(float) Load 19(y) + Store 90 93 + Branch 92 + 94: Label + Line 1 53 0 + 95: 42(bool) Load 59(b) + 96: 10(float) Select 95 34 57 + Store 90 96 + Branch 92 + 92: Label + 97: 10(float) Load 90 + Line 1 51 0 + 98: 10(float) Load 56(result) + 99: 10(float) FAdd 98 97 + Store 56(result) 99 + Line 1 55 0 + 100: 10(float) Load 56(result) + ReturnValue 100 FunctionEnd diff --git a/Test/baseResults/spv.debugInfo.frag.out b/Test/baseResults/spv.debugInfo.frag.out index b9eb496a2..8bacd74d9 100644 --- a/Test/baseResults/spv.debugInfo.frag.out +++ b/Test/baseResults/spv.debugInfo.frag.out @@ -1,12 +1,12 @@ spv.debugInfo.frag // Module Version 10000 // Generated by (magic number): 8000b -// Id's are bound by 124 +// Id's are bound by 187 Capability Shader 2: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 5 "main" 24 52 + EntryPoint Fragment 5 "main" 30 104 ExecutionMode 5 OriginLowerLeft 1: String "spv.debugInfo.frag" Source GLSL 450 1 "// OpModuleProcessed no-storage-format @@ -47,9 +47,40 @@ vec4 foo(S s) return r; } +float testBranch(float x, float y) +{ + float result = 0; + bool b = x > 0; + + // branch with load + if (b) { + result += 1; + } + else { + result -= 1; + } + + // branch with expression + if (x > y) { + result += x - y; + } + + // selection with load + result += b ? + 1 : -1; + + // selection with expression + result += x < y ? + y : + float(b); + + return result; +} + void main() { outv = foo(s); + outv += testBranch(inv.x, inv.y); outv += texture(s2d, vec2(0.5)); switch (s.a) { @@ -77,27 +108,34 @@ void main() MemberName 8(S) 0 "a" Name 14 "foo(struct-S-i11;" Name 13 "s" - Name 17 "r" - Name 24 "inv" - Name 52 "outv" - Name 53 "S" - MemberName 53(S) 0 "a" - Name 54 "ubuf" - MemberName 54(ubuf) 0 "s" - Name 56 "" - Name 57 "param" - Name 67 "s2d" - Name 97 "i" - Decorate 24(inv) Location 0 - Decorate 52(outv) Location 0 - MemberDecorate 53(S) 0 Offset 0 - MemberDecorate 54(ubuf) 0 Offset 0 - Decorate 54(ubuf) Block - Decorate 56 DescriptorSet 3 - Decorate 56 Binding 0 - Decorate 67(s2d) Location 0 - Decorate 67(s2d) DescriptorSet 3 - Decorate 67(s2d) Binding 1 + Name 20 "testBranch(f1;f1;" + Name 18 "x" + Name 19 "y" + Name 23 "r" + Name 30 "inv" + Name 56 "result" + Name 59 "b" + Name 104 "outv" + Name 105 "S" + MemberName 105(S) 0 "a" + Name 106 "ubuf" + MemberName 106(ubuf) 0 "s" + Name 108 "" + Name 109 "param" + Name 116 "param" + Name 120 "param" + Name 131 "s2d" + Name 161 "i" + Decorate 30(inv) Location 0 + Decorate 104(outv) Location 0 + MemberDecorate 105(S) 0 Offset 0 + MemberDecorate 106(ubuf) 0 Offset 0 + Decorate 106(ubuf) Block + Decorate 108 DescriptorSet 3 + Decorate 108 Binding 0 + Decorate 131(s2d) Location 0 + Decorate 131(s2d) DescriptorSet 3 + Decorate 131(s2d) Binding 1 3: TypeVoid 4: TypeFunction 3 7: TypeInt 32 1 @@ -106,179 +144,280 @@ void main() 10: TypeFloat 32 11: TypeVector 10(float) 4 12: TypeFunction 11(fvec4) 9(ptr) - 16: TypePointer Function 11(fvec4) - 18: 7(int) Constant 0 - 19: TypePointer Function 7(int) - 23: TypePointer Input 11(fvec4) - 24(inv): 23(ptr) Variable Input - 28: 10(float) Constant 1065353216 - 31: TypeInt 32 0 - 32: 31(int) Constant 0 - 33: TypePointer Function 10(float) - 36: 10(float) Constant 1077936128 - 37: TypeBool - 45: 10(float) Constant 1073741824 - 51: TypePointer Output 11(fvec4) - 52(outv): 51(ptr) Variable Output - 53(S): TypeStruct 7(int) - 54(ubuf): TypeStruct 53(S) - 55: TypePointer Uniform 54(ubuf) - 56: 55(ptr) Variable Uniform - 58: TypePointer Uniform 53(S) - 64: TypeImage 10(float) 2D sampled format:Unknown - 65: TypeSampledImage 64 - 66: TypePointer UniformConstant 65 - 67(s2d): 66(ptr) Variable UniformConstant - 69: TypeVector 10(float) 2 - 70: 10(float) Constant 1056964608 - 71: 69(fvec2) ConstantComposite 70 70 - 75: TypePointer Uniform 7(int) - 104: 7(int) Constant 10 - 109: 7(int) Constant 1 - 111: TypePointer Output 10(float) - 114: 10(float) Constant 1092616192 - Line 1 28 11 + 16: TypePointer Function 10(float) + 17: TypeFunction 10(float) 16(ptr) 16(ptr) + 22: TypePointer Function 11(fvec4) + 24: 7(int) Constant 0 + 25: TypePointer Function 7(int) + 29: TypePointer Input 11(fvec4) + 30(inv): 29(ptr) Variable Input + 34: 10(float) Constant 1065353216 + 37: TypeInt 32 0 + 38: 37(int) Constant 0 + 41: 10(float) Constant 1077936128 + 42: TypeBool + 50: 10(float) Constant 1073741824 + 57: 10(float) Constant 0 + 58: TypePointer Function 42(bool) + 81: 7(int) Constant 1 + 82: 7(int) Constant 4294967295 + 103: TypePointer Output 11(fvec4) + 104(outv): 103(ptr) Variable Output + 105(S): TypeStruct 7(int) + 106(ubuf): TypeStruct 105(S) + 107: TypePointer Uniform 106(ubuf) + 108: 107(ptr) Variable Uniform + 110: TypePointer Uniform 105(S) + 117: TypePointer Input 10(float) + 121: 37(int) Constant 1 + 128: TypeImage 10(float) 2D sampled format:Unknown + 129: TypeSampledImage 128 + 130: TypePointer UniformConstant 129 + 131(s2d): 130(ptr) Variable UniformConstant + 133: TypeVector 10(float) 2 + 134: 10(float) Constant 1056964608 + 135: 133(fvec2) ConstantComposite 134 134 + 139: TypePointer Uniform 7(int) + 168: 7(int) Constant 10 + 174: TypePointer Output 10(float) + 177: 10(float) Constant 1092616192 + Line 1 58 11 5(main): 3 Function None 4 6: Label - 57(param): 9(ptr) Variable Function - 97(i): 19(ptr) Variable Function - 116: 16(ptr) Variable Function - Line 1 30 0 - 59: 58(ptr) AccessChain 56 18 - 60: 53(S) Load 59 - 61: 7(int) CompositeExtract 60 0 - 62: 19(ptr) AccessChain 57(param) 18 - Store 62 61 - 63: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 57(param) - Store 52(outv) 63 - Line 1 31 0 - 68: 65 Load 67(s2d) - 72: 11(fvec4) ImageSampleImplicitLod 68 71 - 73: 11(fvec4) Load 52(outv) - 74: 11(fvec4) FAdd 73 72 - Store 52(outv) 74 - Line 1 33 0 - 76: 75(ptr) AccessChain 56 18 18 - 77: 7(int) Load 76 - SelectionMerge 81 None - Switch 77 80 - case 10: 78 - case 20: 79 - 80: Label - Line 1 42 0 - 92: 11(fvec4) Load 52(outv) - 93: 11(fvec4) CompositeConstruct 28 28 28 28 - 94: 11(fvec4) FSub 92 93 - Store 52(outv) 94 - Line 1 43 0 - Branch 81 - 78: Label - Line 1 35 0 - 82: 11(fvec4) Load 52(outv) - 83: 11(fvec4) CompositeConstruct 28 28 28 28 - 84: 11(fvec4) FAdd 82 83 - Store 52(outv) 84 - Line 1 36 0 - Branch 81 - 79: Label - Line 1 38 0 - 86: 11(fvec4) Load 52(outv) - 87: 11(fvec4) VectorTimesScalar 86 45 - Store 52(outv) 87 - Line 1 39 0 - 88: 11(fvec4) Load 52(outv) - 89: 11(fvec4) CompositeConstruct 28 28 28 28 - 90: 11(fvec4) FAdd 88 89 - Store 52(outv) 90 - Line 1 40 0 - Branch 81 - 81: Label - Line 1 46 0 - Store 97(i) 18 - Branch 98 - 98: Label - Line 1 46 0 - LoopMerge 100 101 None - Branch 102 - 102: Label - Line 1 46 0 - 103: 7(int) Load 97(i) - 105: 37(bool) SLessThan 103 104 - BranchConditional 105 99 100 - 99: Label - Line 1 47 0 - 106: 11(fvec4) Load 52(outv) - 107: 11(fvec4) VectorTimesScalar 106 36 - Store 52(outv) 107 - Branch 101 - 101: Label - Line 1 46 0 - 108: 7(int) Load 97(i) - 110: 7(int) IAdd 108 109 - Store 97(i) 110 - Branch 98 - 100: Label - Line 1 49 0 - 112: 111(ptr) AccessChain 52(outv) 32 - 113: 10(float) Load 112 - 115: 37(bool) FOrdLessThan 113 114 - SelectionMerge 118 None - BranchConditional 115 117 121 - 117: Label - Line 1 50 0 - 119: 11(fvec4) Load 52(outv) - 120: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 119 - Store 52(outv) 120 - Store 116 120 - Branch 118 - 121: Label - Line 1 51 0 - 122: 11(fvec4) Load 52(outv) - 123: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 122 - Store 52(outv) 123 - Store 116 123 - Branch 118 - 118: Label + 109(param): 9(ptr) Variable Function + 116(param): 16(ptr) Variable Function + 120(param): 16(ptr) Variable Function + 161(i): 25(ptr) Variable Function + 179: 22(ptr) Variable Function + Line 1 60 0 + 111: 110(ptr) AccessChain 108 24 + 112: 105(S) Load 111 + 113: 7(int) CompositeExtract 112 0 + 114: 25(ptr) AccessChain 109(param) 24 + Store 114 113 + 115: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 109(param) + Store 104(outv) 115 + Line 1 61 0 + 118: 117(ptr) AccessChain 30(inv) 38 + 119: 10(float) Load 118 + Store 116(param) 119 + 122: 117(ptr) AccessChain 30(inv) 121 + 123: 10(float) Load 122 + Store 120(param) 123 + 124: 10(float) FunctionCall 20(testBranch(f1;f1;) 116(param) 120(param) + 125: 11(fvec4) Load 104(outv) + 126: 11(fvec4) CompositeConstruct 124 124 124 124 + 127: 11(fvec4) FAdd 125 126 + Store 104(outv) 127 + Line 1 62 0 + 132: 129 Load 131(s2d) + 136: 11(fvec4) ImageSampleImplicitLod 132 135 + 137: 11(fvec4) Load 104(outv) + 138: 11(fvec4) FAdd 137 136 + Store 104(outv) 138 + Line 1 64 0 + 140: 139(ptr) AccessChain 108 24 24 + 141: 7(int) Load 140 + SelectionMerge 145 None + Switch 141 144 + case 10: 142 + case 20: 143 + 144: Label + Line 1 73 0 + 156: 11(fvec4) Load 104(outv) + 157: 11(fvec4) CompositeConstruct 34 34 34 34 + 158: 11(fvec4) FSub 156 157 + Store 104(outv) 158 + Line 1 74 0 + Branch 145 + 142: Label + Line 1 66 0 + 146: 11(fvec4) Load 104(outv) + 147: 11(fvec4) CompositeConstruct 34 34 34 34 + 148: 11(fvec4) FAdd 146 147 + Store 104(outv) 148 + Line 1 67 0 + Branch 145 + 143: Label + Line 1 69 0 + 150: 11(fvec4) Load 104(outv) + 151: 11(fvec4) VectorTimesScalar 150 50 + Store 104(outv) 151 + Line 1 70 0 + 152: 11(fvec4) Load 104(outv) + 153: 11(fvec4) CompositeConstruct 34 34 34 34 + 154: 11(fvec4) FAdd 152 153 + Store 104(outv) 154 + Line 1 71 0 + Branch 145 + 145: Label + Line 1 77 0 + Store 161(i) 24 + Branch 162 + 162: Label + Line 1 77 0 + LoopMerge 164 165 None + Branch 166 + 166: Label + Line 1 77 0 + 167: 7(int) Load 161(i) + 169: 42(bool) SLessThan 167 168 + BranchConditional 169 163 164 + 163: Label + Line 1 78 0 + 170: 11(fvec4) Load 104(outv) + 171: 11(fvec4) VectorTimesScalar 170 41 + Store 104(outv) 171 + Branch 165 + 165: Label + Line 1 77 0 + 172: 7(int) Load 161(i) + 173: 7(int) IAdd 172 81 + Store 161(i) 173 + Branch 162 + 164: Label + Line 1 80 0 + 175: 174(ptr) AccessChain 104(outv) 38 + 176: 10(float) Load 175 + 178: 42(bool) FOrdLessThan 176 177 + SelectionMerge 181 None + BranchConditional 178 180 184 + 180: Label + Line 1 81 0 + 182: 11(fvec4) Load 104(outv) + 183: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 182 + Store 104(outv) 183 + Store 179 183 + Branch 181 + 184: Label + Line 1 82 0 + 185: 11(fvec4) Load 104(outv) + 186: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 185 + Store 104(outv) 186 + Store 179 186 + Branch 181 + 181: Label Return FunctionEnd Line 1 16 13 14(foo(struct-S-i11;): 11(fvec4) Function None 12 13(s): 9(ptr) FunctionParameter 15: Label - 17(r): 16(ptr) Variable Function + 23(r): 22(ptr) Variable Function Line 1 18 0 - 20: 19(ptr) AccessChain 13(s) 18 - 21: 7(int) Load 20 - 22: 10(float) ConvertSToF 21 - 25: 11(fvec4) Load 24(inv) - 26: 11(fvec4) VectorTimesScalar 25 22 - Store 17(r) 26 + 26: 25(ptr) AccessChain 13(s) 24 + 27: 7(int) Load 26 + 28: 10(float) ConvertSToF 27 + 31: 11(fvec4) Load 30(inv) + 32: 11(fvec4) VectorTimesScalar 31 28 + Store 23(r) 32 Line 1 19 0 - 27: 11(fvec4) Load 17(r) - 29: 11(fvec4) CompositeConstruct 28 28 28 28 - 30: 11(fvec4) FAdd 27 29 - Store 17(r) 30 + 33: 11(fvec4) Load 23(r) + 35: 11(fvec4) CompositeConstruct 34 34 34 34 + 36: 11(fvec4) FAdd 33 35 + Store 23(r) 36 Line 1 20 0 - 34: 33(ptr) AccessChain 17(r) 32 - 35: 10(float) Load 34 - 38: 37(bool) FOrdGreaterThan 35 36 - SelectionMerge 40 None - BranchConditional 38 39 44 - 39: Label - Line 1 21 0 - 41: 11(fvec4) Load 17(r) - 42: 11(fvec4) CompositeConstruct 28 28 28 28 - 43: 11(fvec4) FSub 41 42 - Store 17(r) 43 - Branch 40 + 39: 16(ptr) AccessChain 23(r) 38 + 40: 10(float) Load 39 + 43: 42(bool) FOrdGreaterThan 40 41 + SelectionMerge 45 None + BranchConditional 43 44 49 44: Label + Line 1 21 0 + 46: 11(fvec4) Load 23(r) + 47: 11(fvec4) CompositeConstruct 34 34 34 34 + 48: 11(fvec4) FSub 46 47 + Store 23(r) 48 + Branch 45 + 49: Label Line 1 23 0 - 46: 11(fvec4) Load 17(r) - 47: 11(fvec4) VectorTimesScalar 46 45 - Store 17(r) 47 - Branch 40 - 40: Label + 51: 11(fvec4) Load 23(r) + 52: 11(fvec4) VectorTimesScalar 51 50 + Store 23(r) 52 + Branch 45 + 45: Label Line 1 25 0 - 48: 11(fvec4) Load 17(r) - ReturnValue 48 + 53: 11(fvec4) Load 23(r) + ReturnValue 53 + FunctionEnd + Line 1 28 34 +20(testBranch(f1;f1;): 10(float) Function None 17 + 18(x): 16(ptr) FunctionParameter + 19(y): 16(ptr) FunctionParameter + 21: Label + 56(result): 16(ptr) Variable Function + 59(b): 58(ptr) Variable Function + 90: 16(ptr) Variable Function + Line 1 30 0 + Store 56(result) 57 + Line 1 31 0 + 60: 10(float) Load 18(x) + 61: 42(bool) FOrdGreaterThan 60 57 + Store 59(b) 61 + Line 1 34 0 + 62: 42(bool) Load 59(b) + SelectionMerge 64 None + BranchConditional 62 63 67 + 63: Label + Line 1 35 0 + 65: 10(float) Load 56(result) + 66: 10(float) FAdd 65 34 + Store 56(result) 66 + Branch 64 + 67: Label + Line 1 38 0 + 68: 10(float) Load 56(result) + 69: 10(float) FSub 68 34 + Store 56(result) 69 + Branch 64 + 64: Label + Line 1 42 0 + 70: 10(float) Load 18(x) + 71: 10(float) Load 19(y) + 72: 42(bool) FOrdGreaterThan 70 71 + SelectionMerge 74 None + BranchConditional 72 73 74 + 73: Label + Line 1 43 0 + 75: 10(float) Load 18(x) + 76: 10(float) Load 19(y) + 77: 10(float) FSub 75 76 + 78: 10(float) Load 56(result) + 79: 10(float) FAdd 78 77 + Store 56(result) 79 + Branch 74 + 74: Label + Line 1 47 0 + 80: 42(bool) Load 59(b) + 83: 7(int) Select 80 81 82 + 84: 10(float) ConvertSToF 83 + 85: 10(float) Load 56(result) + 86: 10(float) FAdd 85 84 + Store 56(result) 86 + Line 1 51 0 + 87: 10(float) Load 18(x) + 88: 10(float) Load 19(y) + 89: 42(bool) FOrdLessThan 87 88 + SelectionMerge 92 None + BranchConditional 89 91 94 + 91: Label + Line 1 52 0 + 93: 10(float) Load 19(y) + Store 90 93 + Branch 92 + 94: Label + Line 1 53 0 + 95: 42(bool) Load 59(b) + 96: 10(float) Select 95 34 57 + Store 90 96 + Branch 92 + 92: Label + 97: 10(float) Load 90 + Line 1 51 0 + 98: 10(float) Load 56(result) + 99: 10(float) FAdd 98 97 + Store 56(result) 99 + Line 1 55 0 + 100: 10(float) Load 56(result) + ReturnValue 100 FunctionEnd diff --git a/Test/spv.debugInfo.frag b/Test/spv.debugInfo.frag index 3b6cd27fe..31b63341d 100644 --- a/Test/spv.debugInfo.frag +++ b/Test/spv.debugInfo.frag @@ -25,9 +25,40 @@ vec4 foo(S s) return r; } +float testBranch(float x, float y) +{ + float result = 0; + bool b = x > 0; + + // branch with load + if (b) { + result += 1; + } + else { + result -= 1; + } + + // branch with expression + if (x > y) { + result += x - y; + } + + // selection with load + result += b ? + 1 : -1; + + // selection with expression + result += x < y ? + y : + float(b); + + return result; +} + void main() { outv = foo(s); + outv += testBranch(inv.x, inv.y); outv += texture(s2d, vec2(0.5)); switch (s.a) {