KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
2.02k stars 558 forks source link

Converting SPIR-V to MSL leads to use of undeclared variable #1033

Closed jiradeto closed 5 years ago

jiradeto commented 5 years ago

I was trying to convert SPIR-V to MSL using SPIRV-Cross and found that when a GLSL shader has variable declarations inside a switch statement like the following:


// GLSL:
switch(0)
 {
   case 0:
     int a = 1;   
   case 1:
     int b = 1;
   case 2:
     int c = 1;  
 }

SPIRV-Cross seems to move all declarations in each case into the first case of the switch statement leading to an invalid shader:

 // MSL:
 switch (0)
   {
       case 0:
       {
           int a = 1;
           int b = 1;
           int c = 1;
           break;
       }
       case 1:
       {
           b = 1; // error: use of undeclared identifier 'b'
           c = 1;
           break;
       }
       case 2:
       {
           c = 1;
           break;
       }
   }


Versions:


Steps to reproduce:

Note that before running SPIRV-Cross, I also used spirv-val to check that the SPIR-V produced by glslangValidator is valid.


This archive contains the original fragment shader, the associated SPIR-V, and MSL shader.


Issue found using GraphicsFuzz.

HansKristian-Work commented 5 years ago

Pretty sure this is due to lack of fall-through case handling in SPIRV-Cross, but I'll need to reproduce first.

HansKristian-Work commented 5 years ago

This was kind of fixed two weeks ago, but the code-gen is still duplicated, so that needs to be fixed.