From 8d64d44c3fd5f1fec98f04501e93b17c6f32e540 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 12 Jun 2015 22:34:37 +0000 Subject: [PATCH] glslang -> SPV: fix degenerate switch topologies (bug 14118). git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31485 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- SPIRV/GlslangToSpv.cpp | 3 ++- Test/baseResults/spv.switch.frag.out | 19 ++++++++++++++++++- Test/spv.switch.frag | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index bb72e31f..b8a2e0f7 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1109,7 +1109,8 @@ bool TGlslangToSpvTraverser::visitSwitch(glslang::TVisit /* visit */, glslang::T // handle the case where the last code segment is missing, due to no code // statements between the last case and the end of the switch statement - if ((int)codeSegments.size() == valueIndexToSegment[caseValues.size() - 1]) + if ((caseValues.size() && (int)codeSegments.size() == valueIndexToSegment[caseValues.size() - 1]) || + (int)codeSegments.size() == defaultSegment) codeSegments.push_back(nullptr); // make the switch statement diff --git a/Test/baseResults/spv.switch.frag.out b/Test/baseResults/spv.switch.frag.out index 10a7705c..cc527af2 100644 --- a/Test/baseResults/spv.switch.frag.out +++ b/Test/baseResults/spv.switch.frag.out @@ -1,5 +1,7 @@ spv.switch.frag WARNING: 0:121: 'switch' : last case/default label not followed by statements +WARNING: 0:134: 'switch' : last case/default label not followed by statements +WARNING: 0:139: 'switch' : last case/default label not followed by statements @@ -9,7 +11,7 @@ Linked fragment stage: // Module Version 99 // Generated by (magic number): 51a00bb -// Id's are bound by 249 +// Id's are bound by 261 Source ESSL 300 1: ExtInstImport "GLSL.std.450" @@ -322,6 +324,21 @@ Linked fragment stage: 247: 7(float) Load 222(color) 248: 7(float) FAdd 247 246 Store 222(color) 248 + 249: 10(int) Load 61(c) + SelectionMerge 252 None + Switch 249 251 + case 0: 250 + 250: Label + Branch 252 + 251: Label + Branch 252 + 252: Label + 256: 10(int) Load 61(c) + SelectionMerge 258 None + Switch 256 257 + 257: Label + Branch 258 + 258: Label Branch 6 6: Label Return diff --git a/Test/spv.switch.frag b/Test/spv.switch.frag index 88b4b981..c131c91a 100644 --- a/Test/spv.switch.frag +++ b/Test/spv.switch.frag @@ -130,4 +130,13 @@ void main() color += foo1(v,v,c).y; color += foo2(v,v,c).z; + + switch (c) { + case 0: break; + default: + } + + switch (c) { + default: + } }