From 404c984f9c42dc1e946921b1fd14bef8128ab56c Mon Sep 17 00:00:00 2001 From: Alpyne Date: Thu, 27 Apr 2023 18:01:46 -0700 Subject: [PATCH] [dxso] Implement bem instruction --- src/dxso/dxso_compiler.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/dxso/dxso_compiler.cpp b/src/dxso/dxso_compiler.cpp index be0344e0..4cc8a3dd 100644 --- a/src/dxso/dxso_compiler.cpp +++ b/src/dxso/dxso_compiler.cpp @@ -128,6 +128,7 @@ namespace dxvk { case DxsoOpcode::Lrp: case DxsoOpcode::Frc: case DxsoOpcode::Cmp: + case DxsoOpcode::Bem: case DxsoOpcode::Cnd: case DxsoOpcode::Dp2Add: case DxsoOpcode::DsX: @@ -2196,6 +2197,41 @@ namespace dxvk { emitRegisterLoad(src[2], mask).id); break; } + case DxsoOpcode::Bem: { + DxsoRegisterValue src0 = emitRegisterLoad(src[0], mask); + DxsoRegisterValue src1 = emitRegisterLoad(src[1], mask); + + // dst.x = src0.x + [bm00(m) * src1.x + bm10(m) * src1.y] + // dst.y = src0.y + [bm01(m) * src1.x + bm11(m) * src1.y] + + // But we flipped the bm indices so we can use dot here... + + // dst.x = src0.x + dot(bm0, src1) + // dst.y = src0.y + dot(bm1, src1) + + std::array values = { m_module.constf32(0.0f), m_module.constf32(0.0f) }; + + for (uint32_t i = 0; i < 2; i++) { + uint32_t fl_t = getScalarTypeId(DxsoScalarType::Float32); + uint32_t vec2_t = getVectorTypeId({ DxsoScalarType::Float32, 2 }); + std::array indices = { 0, 1, 2, 3 }; + + uint32_t tc_m_n = m_module.opCompositeExtract(fl_t, src0.id, 1, &i); + + uint32_t offset = m_module.constu32(D3D9SharedPSStages_Count * ctx.dst.id.num + D3D9SharedPSStages_BumpEnvMat0 + i); + uint32_t bm = m_module.opAccessChain(m_module.defPointerType(vec2_t, spv::StorageClassUniform), + m_ps.sharedState, 1, &offset); + bm = m_module.opLoad(vec2_t, bm); + + uint32_t t = m_module.opVectorShuffle(vec2_t, src1.id, src1.id, 2, indices.data()); + + uint32_t dot = m_module.opDot(fl_t, bm, t); + + values[i] = m_module.opFAdd(fl_t, tc_m_n, dot); + } + result.id = m_module.opCompositeConstruct(typeId, values.size(), values.data()); + break; + } case DxsoOpcode::Cnd: { const uint32_t boolTypeId = getVectorTypeId({ DxsoScalarType::Bool, result.type.ccount });