Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dxso] Implement bem instruction #3511

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/dxso/dxso_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<uint32_t, 2> 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<uint32_t, 4> 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 });
Expand Down