From 13d4a3d87db7790f7e26d587a76b4907c3bce064 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 18 Dec 2017 18:02:15 +0100 Subject: [PATCH] [dxbc] Fixed bug with constant vector operands --- src/dxbc/dxbc_compiler.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index f48596f8..7e679a13 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -1712,19 +1712,27 @@ namespace dxvk { result.type.ccount = 1; result.id = m_module.constu32(reg.imm.u32_1); } else if (reg.componentCount == DxbcComponentCount::Component4) { - // Create a four-component u32 vector - std::array indices = { - m_module.constu32(reg.imm.u32_4[0]), - m_module.constu32(reg.imm.u32_4[1]), - m_module.constu32(reg.imm.u32_4[2]), - m_module.constu32(reg.imm.u32_4[3]), - }; + // Create a u32 vector with as many components as needed + std::array indices; + uint32_t indexId = 0; + + for (uint32_t i = 0; i < indices.size(); i++) { + if (writeMask[i]) { + indices.at(indexId++) = + m_module.constu32(reg.imm.u32_4[i]); + } + } result.type.ctype = DxbcScalarType::Uint32; - result.type.ccount = 4; - result.id = m_module.constComposite( - getVectorTypeId(result.type), - indices.size(), indices.data()); + result.type.ccount = writeMask.setCount(); + result.id = indices.at(0); + + if (indexId > 1) { + result.id = m_module.constComposite( + getVectorTypeId(result.type), + result.type.ccount, indices.data()); + } + } else { // Something went horribly wrong in the decoder or the shader is broken throw DxvkError("DxbcCompiler: Invalid component count for immediate operand");