diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-07-19 13:50:29 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-07-19 13:58:19 +0300 |
commit | 134af81463af53e6c996e1b86d01ca7feda14318 (patch) | |
tree | 6790da8d7660303e41417fd51771fd41b82c8165 /dxil_converter.cpp | |
parent | 8f5f0228f203899da301e5b1addf95bf2ba25ea8 (diff) |
Resolve bitcasted metadata references.
Fixes some DXR shaders where local root signatures fail.
Also fixes offset bugs where we didn't correctly deduce the
use of lib variables which changes the rules on how resources are
indexed, sigh ...
Diffstat (limited to 'dxil_converter.cpp')
-rw-r--r-- | dxil_converter.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/dxil_converter.cpp b/dxil_converter.cpp index 1cf2e91..2974149 100644 --- a/dxil_converter.cpp +++ b/dxil_converter.cpp @@ -640,10 +640,26 @@ Converter::Impl::ResourceVariableMeta Converter::Impl::get_resource_variable_met if (const auto *variable = llvm::dyn_cast<llvm::ConstantAsMetadata>(resource->getOperand(1))) { - if (const auto *var = llvm::dyn_cast<llvm::GlobalVariable>(variable->getValue())) + const llvm::Value *val = variable->getValue(); + const auto *global = llvm::dyn_cast<llvm::GlobalVariable>(val); + + // It's possible that the variable is a constexpr bitcast, so resolve those ... + while (!global && val) + { + auto *constexpr_op = llvm::dyn_cast<llvm::ConstantExpr>(val); + val = nullptr; + + if (constexpr_op && constexpr_op->getOpcode() == llvm::UnaryOperator::BitCast) + { + val = constexpr_op->getOperand(0); + global = llvm::dyn_cast<llvm::GlobalVariable>(val); + } + } + + if (global) { meta.is_lib_variable = true; - meta.is_active = llvm_active_global_resource_variables.count(var) != 0; + meta.is_active = llvm_active_global_resource_variables.count(global) != 0; return meta; } } |