From 8063e27c08f68cbcb324c44a0b8263f611bf61fe Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 14 Sep 2021 15:27:27 +0200 Subject: [PATCH] [dxso] Handle multiplication by zero in cross product --- src/dxso/dxso_compiler.cpp | 38 +++++++++++++++++++++++++++++++++----- src/dxso/dxso_compiler.h | 4 ++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/dxso/dxso_compiler.cpp b/src/dxso/dxso_compiler.cpp index 87f9ca9b..14622e29 100644 --- a/src/dxso/dxso_compiler.cpp +++ b/src/dxso/dxso_compiler.cpp @@ -1495,6 +1495,36 @@ namespace dxvk { } + DxsoRegisterValue DxsoCompiler::emitCross( + DxsoRegisterValue a, + DxsoRegisterValue b) { + const std::array shiftIndices = { 1, 2, 0, 1 }; + + DxsoRegisterValue result; + result.type = { DxsoScalarType::Float32, 3 }; + + uint32_t typeId = getVectorTypeId(result.type); + std::array products; + + for (uint32_t i = 0; i < 2; i++) { + DxsoRegisterValue ashift; + ashift.type = result.type; + ashift.id = m_module.opVectorShuffle(typeId, + a.id, a.id, 3, &shiftIndices[i]); + + DxsoRegisterValue bshift; + bshift.type = result.type; + bshift.id = m_module.opVectorShuffle(typeId, + b.id, b.id, 3, &shiftIndices[1 - i]); + + products[i] = emitMul(ashift, bshift); + } + + result.id = m_module.opFSub(typeId, products[0].id, products[1].id); + return result; + } + + DxsoRegisterValue DxsoCompiler::emitRegisterInsert( DxsoRegisterValue dstValue, DxsoRegisterValue srcValue, @@ -2036,11 +2066,9 @@ namespace dxvk { case DxsoOpcode::Crs: { DxsoRegMask vec3Mask(true, true, true, false); - DxsoRegisterValue crossValue; - crossValue.type = { DxsoScalarType::Float32, 3 }; - crossValue.id = m_module.opCross(getVectorTypeId(crossValue.type), - emitRegisterLoad(src[0], vec3Mask).id, - emitRegisterLoad(src[1], vec3Mask).id); + DxsoRegisterValue crossValue = emitCross( + emitRegisterLoad(src[0], vec3Mask), + emitRegisterLoad(src[1], vec3Mask)); std::array indices = { 0, 0, 0 }; diff --git a/src/dxso/dxso_compiler.h b/src/dxso/dxso_compiler.h index 0a1ce589..a25fcd2e 100644 --- a/src/dxso/dxso_compiler.h +++ b/src/dxso/dxso_compiler.h @@ -562,6 +562,10 @@ namespace dxvk { DxsoRegisterValue a, DxsoRegisterValue b); + DxsoRegisterValue emitCross( + DxsoRegisterValue a, + DxsoRegisterValue b); + DxsoRegisterValue emitRegisterInsert( DxsoRegisterValue dstValue, DxsoRegisterValue srcValue,