Skip to content

Commit 1485048

Browse files
Fix ShaderDebugInfo having invalid line numbers in 1.0
1 parent 09c541e commit 1485048

27 files changed

+53
-218
lines changed

SPIRV/GlslangToSpv.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,20 +1679,32 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
16791679
}
16801680
builder.setDebugMainSourceFile(glslangIntermediate->getSourceFile());
16811681

1682-
// Set the source shader's text. If for SPV version 1.0, include
1682+
// Set the source shader's text
1683+
std::string text;
1684+
1685+
// If for SPV version 1.0, include
16831686
// a preamble in comments stating the OpModuleProcessed instructions.
16841687
// Otherwise, emit those as actual instructions.
1685-
std::string text;
1688+
//
1689+
// ...Except when using ShaderDebugInfo we DON'T want these as it will mess up the line
1690+
// number, instead the user has opt'ed in for ShaderDebugInfo instead, so they will want
1691+
// to parse those instead
1692+
// https://github.com/KhronosGroup/glslang/issues/3863
1693+
const bool add_comments =
1694+
glslangIntermediate->getSpv().spv < glslang::EShTargetSpv_1_1 && !options.emitNonSemanticShaderDebugSource;
1695+
16861696
const std::vector<std::string>& processes = glslangIntermediate->getProcesses();
16871697
for (int p = 0; p < (int)processes.size(); ++p) {
1688-
if (glslangIntermediate->getSpv().spv < glslang::EShTargetSpv_1_1) {
1698+
if (add_comments) {
16891699
text.append("// OpModuleProcessed ");
16901700
text.append(processes[p]);
16911701
text.append("\n");
1692-
} else
1702+
} else if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_1) {
1703+
// OpModuleProcessed added in SPIR-V 1.1
16931704
builder.addModuleProcessed(processes[p]);
1705+
}
16941706
}
1695-
if (glslangIntermediate->getSpv().spv < glslang::EShTargetSpv_1_1 && (int)processes.size() > 0)
1707+
if (add_comments && (int)processes.size() > 0)
16961708
text.append("#line 1\n");
16971709
text.append(glslangIntermediate->getSourceText());
16981710
builder.setSourceText(text);

Test/baseResults/spv.debuginfo.bufferref.glsl.frag.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ spv.debuginfo.bufferref.glsl.frag
1717
2: String "spv.debuginfo.bufferref.glsl.frag"
1818
8: String "uint"
1919
16: String "main"
20-
19: String "// OpModuleProcessed auto-map-locations
21-
// OpModuleProcessed auto-map-bindings
22-
// OpModuleProcessed client vulkan100
23-
// OpModuleProcessed target-env vulkan1.0
24-
// OpModuleProcessed keep-uncalled
25-
// OpModuleProcessed entry-point main
26-
#line 1
27-
#version 450 core
20+
19: String "#version 450 core
2821
#extension GL_EXT_buffer_reference : enable
2922

3023
layout(buffer_reference, std430) buffer MeshVertexPositions {

Test/baseResults/spv.debuginfo.const_params.glsl.comp.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ spv.debuginfo.const_params.glsl.comp
1414
8: String "uint"
1515
17: String "float"
1616
35: String "function"
17-
38: String "// OpModuleProcessed auto-map-locations
18-
// OpModuleProcessed auto-map-bindings
19-
// OpModuleProcessed client vulkan100
20-
// OpModuleProcessed target-env vulkan1.0
21-
// OpModuleProcessed keep-uncalled
22-
// OpModuleProcessed entry-point main
23-
#line 1
24-
#version 450
17+
38: String "#version 450
2518

2619
void function(
2720
const float f,

Test/baseResults/spv.debuginfo.const_variables.glsl.frag.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ spv.debuginfo.const_variables.glsl.frag
1313
2: String "spv.debuginfo.const_variables.glsl.frag"
1414
8: String "uint"
1515
16: String "main"
16-
19: String "// OpModuleProcessed auto-map-locations
17-
// OpModuleProcessed auto-map-bindings
18-
// OpModuleProcessed client vulkan100
19-
// OpModuleProcessed target-env vulkan1.0
20-
// OpModuleProcessed keep-uncalled
21-
// OpModuleProcessed entry-point main
22-
#line 1
23-
#version 460
16+
19: String "#version 460
2417

2518
const vec4 constGlobal = vec4(1.0, 0.0, 0.0, 1.0);
2619

Test/baseResults/spv.debuginfo.continued.glsl.vert.out

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ spv.debuginfo.continued.glsl.vert
1212
2: String "spv.debuginfo.continued.glsl.vert"
1313
8: String "uint"
1414
16: String "main"
15-
19: String "// OpModuleProcessed auto-map-locations
16-
// OpModuleProcessed auto-map-bindings
17-
// OpModuleProcessed client vulkan100
18-
// OpModuleProcessed target-env vulkan1.0
19-
// OpModuleProcessed keep-uncalled
20-
// OpModuleProcessed entry-point main
21-
#line 1
22-
#version 460
15+
19: String "#version 460
2316

2417
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
2518
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
@@ -1904,10 +1897,10 @@ spv.debuginfo.continued.glsl.vert
19041897
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
19051898
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
19061899
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
1907-
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceCont"
1908-
20: String "inued.
19091900
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
19101901
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
1902+
// This is filler text to cause the source length to exceed the maximum length of DebugSource "
1903+
20: String "and require the use of DebugSourceContinued.
19111904
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
19121905
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
19131906
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
@@ -3791,8 +3784,10 @@ spv.debuginfo.continued.glsl.vert
37913784
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
37923785
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
37933786
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
3794-
// This is filler text to cause the source length to exceed the maximum length of DebugSource and req"
3795-
22: String "uire the use of DebugSourceContinued.
3787+
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
3788+
// This is filler text to cause the source length to exceed the maximum length of DebugSource and require the use of DebugSourceContinued.
3789+
// This is filler text to cause the source length to exceed the"
3790+
22: String " maximum length of DebugSource and require the use of DebugSourceContinued.
37963791

37973792
void main()
37983793
{
@@ -3831,7 +3826,7 @@ void main()
38313826
18: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 35(DebugSource) 2 19
38323827
21: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 102(DebugSourceContinued) 20
38333828
23: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 102(DebugSourceContinued) 22
3834-
24: 7(int) Constant 3774
3829+
24: 7(int) Constant 3776
38353830
26: 7(int) Constant 1
38363831
27: 7(int) Constant 4
38373832
28: 7(int) Constant 2
@@ -3852,7 +3847,7 @@ void main()
38523847
46: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 11(DebugTypeMember) 47 38 18 26 48 12 12 13
38533848
51: 7(int) Constant 85
38543849
49: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 11(DebugTypeMember) 50 38 18 26 51 12 12 13
3855-
54: 7(int) Constant 3776
3850+
54: 7(int) Constant 3778
38563851
52: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 10(DebugTypeComposite) 53 26 18 54 12 25 53 12 13 40 43 46 49
38573852
55: TypePointer Output 39(gl_PerVertex)
38583853
56: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 3(DebugTypePointer) 52 13 12
@@ -3866,7 +3861,7 @@ void main()
38663861
66: 35(fvec4) ConstantComposite 65 65 65 65
38673862
67: TypePointer Output 35(fvec4)
38683863
68: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 3(DebugTypePointer) 36 13 12
3869-
72: 7(int) Constant 3777
3864+
72: 7(int) Constant 3779
38703865
14(main): 4 Function None 5
38713866
15: Label
38723867
30: 4 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 17

Test/baseResults/spv.debuginfo.declaration.glsl.frag.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ spv.debuginfo.declaration.glsl.frag
1313
2: String "spv.debuginfo.declaration.glsl.frag"
1414
8: String "uint"
1515
16: String "main"
16-
19: String "// OpModuleProcessed auto-map-locations
17-
// OpModuleProcessed auto-map-bindings
18-
// OpModuleProcessed client vulkan100
19-
// OpModuleProcessed target-env vulkan1.0
20-
// OpModuleProcessed keep-uncalled
21-
// OpModuleProcessed entry-point main
22-
#line 1
23-
#version 460
16+
19: String "#version 460
2417

2518
uniform UBO {
2619
int x;

Test/baseResults/spv.debuginfo.glsl.comp.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ spv.debuginfo.glsl.comp
1414
8: String "uint"
1515
17: String "float"
1616
33: String "springForce"
17-
36: String "// OpModuleProcessed auto-map-locations
18-
// OpModuleProcessed auto-map-bindings
19-
// OpModuleProcessed client vulkan100
20-
// OpModuleProcessed target-env vulkan1.0
21-
// OpModuleProcessed keep-uncalled
22-
// OpModuleProcessed entry-point main
23-
#line 1
24-
/*
17+
36: String "/*
2518
The MIT License (MIT)
2619

2720
Copyright (c) 2022 Sascha Willems

Test/baseResults/spv.debuginfo.glsl.frag.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ spv.debuginfo.glsl.frag
1515
8: String "uint"
1616
17: String "float"
1717
39: String "textureProj"
18-
42: String "// OpModuleProcessed auto-map-locations
19-
// OpModuleProcessed auto-map-bindings
20-
// OpModuleProcessed client vulkan100
21-
// OpModuleProcessed target-env vulkan1.0
22-
// OpModuleProcessed keep-uncalled
23-
// OpModuleProcessed entry-point main
24-
#line 1
25-
/*
18+
42: String "/*
2619
The MIT License (MIT)
2720

2821
Copyright (c) 2022 Sascha Willems

Test/baseResults/spv.debuginfo.glsl.geom.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ spv.debuginfo.glsl.geom
1717
2: String "spv.debuginfo.glsl.geom"
1818
8: String "uint"
1919
16: String "main"
20-
19: String "// OpModuleProcessed auto-map-locations
21-
// OpModuleProcessed auto-map-bindings
22-
// OpModuleProcessed client vulkan100
23-
// OpModuleProcessed target-env vulkan1.0
24-
// OpModuleProcessed keep-uncalled
25-
// OpModuleProcessed entry-point main
26-
#line 1
27-
/*
20+
19: String "/*
2821
The MIT License (MIT)
2922

3023
Copyright (c) 2022 Sascha Willems

Test/baseResults/spv.debuginfo.glsl.tesc.out

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ spv.debuginfo.glsl.tesc
1414
8: String "uint"
1515
17: String "float"
1616
31: String "screenSpaceTessFactor"
17-
34: String "// OpModuleProcessed auto-map-locations
18-
// OpModuleProcessed auto-map-bindings
19-
// OpModuleProcessed client vulkan100
20-
// OpModuleProcessed target-env vulkan1.0
21-
// OpModuleProcessed keep-uncalled
22-
// OpModuleProcessed entry-point main
23-
#line 1
24-
/*
17+
34: String "/*
2518
The MIT License (MIT)
2619

2720
Copyright (c) 2022 Sascha Willems

0 commit comments

Comments
 (0)