Handle SpecConstantOp used as switch case.

This commit is contained in:
Hans-Kristian Arntzen 2024-08-23 10:53:01 +02:00
parent d33a39045d
commit b49acb11ca
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#version 450
#ifndef SPIRV_CROSS_CONSTANT_ID_0
#define SPIRV_CROSS_CONSTANT_ID_0 4
#endif
const int FOO = SPIRV_CROSS_CONSTANT_ID_0;
const int _9 = (FOO + 4);
layout(location = 0) out vec4 FragColor;
void main()
{
switch (_9)
{
case 4:
{
FragColor = vec4(10.0);
break;
}
case 6:
{
FragColor = vec4(20.0);
break;
}
default:
{
FragColor = vec4(0.0);
break;
}
}
}

View File

@ -0,0 +1,23 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 Attr;
layout(constant_id = 0) const int FOO = 4;
void main()
{
switch (FOO + 4)
{
case 4:
FragColor = vec4(10.0);
break;
case 6:
FragColor = vec4(20.0);
break;
default:
FragColor = vec4(0.0);
break;
}
}

View File

@ -1850,6 +1850,11 @@ const SmallVector<SPIRBlock::Case> &Compiler::get_case_list(const SPIRBlock &blo
const auto &type = get<SPIRType>(constant->constant_type); const auto &type = get<SPIRType>(constant->constant_type);
width = type.width; width = type.width;
} }
else if (const auto *op = maybe_get<SPIRConstantOp>(block.condition))
{
const auto &type = get<SPIRType>(op->basetype);
width = type.width;
}
else if (const auto *var = maybe_get<SPIRVariable>(block.condition)) else if (const auto *var = maybe_get<SPIRVariable>(block.condition))
{ {
const auto &type = get<SPIRType>(var->basetype); const auto &type = get<SPIRType>(var->basetype);