diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2021-11-15 17:05:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-15 17:05:10 +0300 |
commit | 37dfb3f45f4fc47c841f81e618c602f6f3de0f17 (patch) | |
tree | 785fd59f4f63a8c9a964ffd61bed031c6ce2be00 /spirv_cross.cpp | |
parent | 7c3cb0b12c9965497b08403c82ac1b82846fa7be (diff) | |
parent | 5345051a8551b3fe6bc89bced15ec1a31fc4e60d (diff) |
Merge pull request #1794 from etra0/master
Add 64 bit support for OpSwitch
Diffstat (limited to 'spirv_cross.cpp')
-rw-r--r-- | spirv_cross.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/spirv_cross.cpp b/spirv_cross.cpp index 13e41357..dc836066 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -1659,6 +1659,39 @@ SPIRBlock::ContinueBlockType Compiler::continue_block_type(const SPIRBlock &bloc } } +const SmallVector<SPIRBlock::Case> &Compiler::get_case_list(const SPIRBlock &block) const +{ + uint32_t width = 0; + + // First we check if we can get the type directly from the block.condition + // since it can be a SPIRConstant or a SPIRVariable. + if (const auto *constant = maybe_get<SPIRConstant>(block.condition)) + { + const auto &type = get<SPIRType>(constant->constant_type); + width = type.width; + } + else if (const auto *var = maybe_get<SPIRVariable>(block.condition)) + { + const auto &type = get<SPIRType>(var->basetype); + width = type.width; + } + else + { + auto search = ir.load_type_width.find(block.condition); + if (search == ir.load_type_width.end()) + { + SPIRV_CROSS_THROW("Use of undeclared variable on a switch statement."); + } + + width = search->second; + } + + if (width > 32) + return block.cases_64bit; + + return block.cases_32bit; +} + bool Compiler::traverse_all_reachable_opcodes(const SPIRBlock &block, OpcodeHandler &handler) const { handler.set_current_block(block); @@ -3057,12 +3090,15 @@ void Compiler::AnalyzeVariableScopeAccessHandler::set_current_block(const SPIRBl break; case SPIRBlock::MultiSelect: + { notify_variable_access(block.condition, block.self); - for (auto &target : block.cases) + auto &cases = compiler.get_case_list(block); + for (auto &target : cases) test_phi(target.block); if (block.default_block) test_phi(block.default_block); break; + } default: break; |