Browse Source
shader: Implement FSET and FSETP
shader: Implement FSET and FSETP
Also fix oversight with adding SignedZeroInfNanPreserve execution mode.pull/15/merge
9 changed files with 204 additions and 94 deletions
-
2src/shader_recompiler/CMakeLists.txt
-
6src/shader_recompiler/backend/spirv/emit_spirv.cpp
-
48src/shader_recompiler/frontend/maxwell/translate/impl/common_funcs.cpp
-
6src/shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h
-
68src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_compare.cpp
-
65src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_compare_and_set.cpp
-
60src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_set_predicate.cpp
-
19src/shader_recompiler/frontend/maxwell/translate/impl/impl.h
-
24src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
@ -0,0 +1,65 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include "common/bit_field.h"
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
|
||||
|
|
||||
|
namespace Shader::Maxwell { |
||||
|
namespace { |
||||
|
void FSET(TranslatorVisitor& v, u64 insn, const IR::F32& src_b) { |
||||
|
union { |
||||
|
u64 insn; |
||||
|
BitField<0, 8, IR::Reg> dest_reg; |
||||
|
BitField<8, 8, IR::Reg> src_a_reg; |
||||
|
BitField<39, 3, IR::Pred> pred; |
||||
|
BitField<42, 1, u64> neg_pred; |
||||
|
BitField<43, 1, u64> negate_a; |
||||
|
BitField<44, 1, u64> abs_b; |
||||
|
BitField<45, 2, BooleanOp> bop; |
||||
|
BitField<48, 4, FPCompareOp> compare_op; |
||||
|
BitField<52, 1, u64> bf; |
||||
|
BitField<53, 1, u64> negate_b; |
||||
|
BitField<54, 1, u64> abs_a; |
||||
|
BitField<55, 1, u64> ftz; |
||||
|
} const fset{insn}; |
||||
|
|
||||
|
const IR::F32 op_a{v.ir.FPAbsNeg(v.F(fset.src_a_reg), fset.abs_a != 0, fset.negate_a != 0)}; |
||||
|
const IR::F32 op_b = v.ir.FPAbsNeg(src_b, fset.abs_b != 0, fset.negate_b != 0); |
||||
|
const IR::FpControl control{ |
||||
|
.no_contraction{false}, |
||||
|
.rounding{IR::FpRounding::DontCare}, |
||||
|
.fmz_mode{fset.ftz != 0 ? IR::FmzMode::FTZ : IR::FmzMode::None}, |
||||
|
}; |
||||
|
|
||||
|
IR::U1 pred{v.ir.GetPred(fset.pred)}; |
||||
|
if (fset.neg_pred != 0) { |
||||
|
pred = v.ir.LogicalNot(pred); |
||||
|
} |
||||
|
const IR::U1 cmp_result{FloatingPointCompare(v.ir, op_a, op_b, fset.compare_op, control)}; |
||||
|
const IR::U1 bop_result{PredicateCombine(v.ir, cmp_result, pred, fset.bop)}; |
||||
|
|
||||
|
const IR::U32 one_mask{v.ir.Imm32(-1)}; |
||||
|
const IR::U32 fp_one{v.ir.Imm32(0x3f800000)}; |
||||
|
const IR::U32 fail_result{v.ir.Imm32(0)}; |
||||
|
const IR::U32 pass_result{fset.bf == 0 ? one_mask : fp_one}; |
||||
|
|
||||
|
v.X(fset.dest_reg, IR::U32{v.ir.Select(bop_result, pass_result, fail_result)}); |
||||
|
} |
||||
|
} // Anonymous namespace
|
||||
|
|
||||
|
void TranslatorVisitor::FSET_reg(u64 insn) { |
||||
|
FSET(*this, insn, GetFloatReg20(insn)); |
||||
|
} |
||||
|
|
||||
|
void TranslatorVisitor::FSET_cbuf(u64 insn) { |
||||
|
FSET(*this, insn, GetFloatCbuf(insn)); |
||||
|
} |
||||
|
|
||||
|
void TranslatorVisitor::FSET_imm(u64 insn) { |
||||
|
FSET(*this, insn, GetFloatImm20(insn)); |
||||
|
} |
||||
|
|
||||
|
} // namespace Shader::Maxwell
|
||||
@ -0,0 +1,60 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include "common/bit_field.h"
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/translate/impl/common_funcs.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
|
||||
|
|
||||
|
namespace Shader::Maxwell { |
||||
|
namespace { |
||||
|
void FSETP(TranslatorVisitor& v, u64 insn, const IR::F32& src_b) { |
||||
|
union { |
||||
|
u64 insn; |
||||
|
BitField<0, 3, IR::Pred> dest_pred_b; |
||||
|
BitField<3, 3, IR::Pred> dest_pred_a; |
||||
|
BitField<6, 1, u64> negate_b; |
||||
|
BitField<7, 1, u64> abs_a; |
||||
|
BitField<8, 8, IR::Reg> src_a_reg; |
||||
|
BitField<39, 3, IR::Pred> bop_pred; |
||||
|
BitField<42, 1, u64> neg_bop_pred; |
||||
|
BitField<43, 1, u64> negate_a; |
||||
|
BitField<44, 1, u64> abs_b; |
||||
|
BitField<45, 2, BooleanOp> bop; |
||||
|
BitField<47, 1, u64> ftz; |
||||
|
BitField<48, 4, FPCompareOp> compare_op; |
||||
|
} const fsetp{insn}; |
||||
|
|
||||
|
const IR::F32 op_a{v.ir.FPAbsNeg(v.F(fsetp.src_a_reg), fsetp.abs_a != 0, fsetp.negate_a != 0)}; |
||||
|
const IR::F32 op_b = v.ir.FPAbsNeg(src_b, fsetp.abs_b != 0, fsetp.negate_b != 0); |
||||
|
const IR::FpControl control{ |
||||
|
.no_contraction{false}, |
||||
|
.rounding{IR::FpRounding::DontCare}, |
||||
|
.fmz_mode{fsetp.ftz != 0 ? IR::FmzMode::FTZ : IR::FmzMode::None}, |
||||
|
}; |
||||
|
|
||||
|
const BooleanOp bop{fsetp.bop}; |
||||
|
const FPCompareOp compare_op{fsetp.compare_op}; |
||||
|
const IR::U1 comparison{FloatingPointCompare(v.ir, op_a, op_b, compare_op, control)}; |
||||
|
const IR::U1 bop_pred{v.ir.GetPred(fsetp.bop_pred, fsetp.neg_bop_pred != 0)}; |
||||
|
const IR::U1 result_a{PredicateCombine(v.ir, comparison, bop_pred, bop)}; |
||||
|
const IR::U1 result_b{PredicateCombine(v.ir, v.ir.LogicalNot(comparison), bop_pred, bop)}; |
||||
|
v.ir.SetPred(fsetp.dest_pred_a, result_a); |
||||
|
v.ir.SetPred(fsetp.dest_pred_b, result_b); |
||||
|
} |
||||
|
} // Anonymous namespace
|
||||
|
|
||||
|
void TranslatorVisitor::FSETP_reg(u64 insn) { |
||||
|
FSETP(*this, insn, GetFloatReg20(insn)); |
||||
|
} |
||||
|
|
||||
|
void TranslatorVisitor::FSETP_cbuf(u64 insn) { |
||||
|
FSETP(*this, insn, GetFloatCbuf(insn)); |
||||
|
} |
||||
|
|
||||
|
void TranslatorVisitor::FSETP_imm(u64 insn) { |
||||
|
FSETP(*this, insn, GetFloatImm20(insn)); |
||||
|
} |
||||
|
|
||||
|
} // namespace Shader::Maxwell
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue