diff options
| author | 2021-03-01 15:58:16 -0500 | |
|---|---|---|
| committer | 2021-07-22 21:51:23 -0400 | |
| commit | 103b9da4f7115ff47eee52d0dbd31b5b7a18b257 (patch) | |
| tree | 52e00b1766326559fad61cefa460b6666d2792c9 /src | |
| parent | shader: Implement ISET, add common_funcs (diff) | |
| download | yuzu-103b9da4f7115ff47eee52d0dbd31b5b7a18b257.tar.gz yuzu-103b9da4f7115ff47eee52d0dbd31b5b7a18b257.tar.xz yuzu-103b9da4f7115ff47eee52d0dbd31b5b7a18b257.zip | |
shader: Implement FLO
Diffstat (limited to 'src')
8 files changed, 75 insertions, 18 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index 89fc24f62..035fd34e2 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt | |||
| @@ -64,6 +64,7 @@ add_library(shader_recompiler STATIC | |||
| 64 | frontend/maxwell/translate/impl/common_encoding.h | 64 | frontend/maxwell/translate/impl/common_encoding.h |
| 65 | frontend/maxwell/translate/impl/common_funcs.cpp | 65 | frontend/maxwell/translate/impl/common_funcs.cpp |
| 66 | frontend/maxwell/translate/impl/common_funcs.h | 66 | frontend/maxwell/translate/impl/common_funcs.h |
| 67 | frontend/maxwell/translate/impl/find_leading_one.cpp | ||
| 67 | frontend/maxwell/translate/impl/floating_point_add.cpp | 68 | frontend/maxwell/translate/impl/floating_point_add.cpp |
| 68 | frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp | 69 | frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp |
| 69 | frontend/maxwell/translate/impl/floating_point_fused_multiply_add.cpp | 70 | frontend/maxwell/translate/impl/floating_point_fused_multiply_add.cpp |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index 4d00b235d..5446d6ab6 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -229,7 +229,9 @@ Id EmitBitFieldSExtract(EmitContext& ctx, Id base, Id offset, Id count); | |||
| 229 | Id EmitBitFieldUExtract(EmitContext& ctx, Id base, Id offset, Id count); | 229 | Id EmitBitFieldUExtract(EmitContext& ctx, Id base, Id offset, Id count); |
| 230 | Id EmitBitReverse32(EmitContext& ctx, Id value); | 230 | Id EmitBitReverse32(EmitContext& ctx, Id value); |
| 231 | Id EmitBitCount32(EmitContext& ctx, Id value); | 231 | Id EmitBitCount32(EmitContext& ctx, Id value); |
| 232 | Id EmitBitwiseNot32(EmitContext& ctx, Id a); | 232 | Id EmitBitwiseNot32(EmitContext& ctx, Id value); |
| 233 | Id EmitFindSMsb32(EmitContext& ctx, Id value); | ||
| 234 | Id EmitFindUMsb32(EmitContext& ctx, Id value); | ||
| 233 | Id EmitSMin32(EmitContext& ctx, Id a, Id b); | 235 | Id EmitSMin32(EmitContext& ctx, Id a, Id b); |
| 234 | Id EmitUMin32(EmitContext& ctx, Id a, Id b); | 236 | Id EmitUMin32(EmitContext& ctx, Id a, Id b); |
| 235 | Id EmitSMax32(EmitContext& ctx, Id a, Id b); | 237 | Id EmitSMax32(EmitContext& ctx, Id a, Id b); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp index 5bdd943a4..162fb6a91 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp | |||
| @@ -110,8 +110,16 @@ Id EmitBitCount32(EmitContext& ctx, Id value) { | |||
| 110 | return ctx.OpBitCount(ctx.U32[1], value); | 110 | return ctx.OpBitCount(ctx.U32[1], value); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | Id EmitBitwiseNot32(EmitContext& ctx, Id a) { | 113 | Id EmitBitwiseNot32(EmitContext& ctx, Id value) { |
| 114 | return ctx.OpNot(ctx.U32[1], a); | 114 | return ctx.OpNot(ctx.U32[1], value); |
| 115 | } | ||
| 116 | |||
| 117 | Id EmitFindSMsb32(EmitContext& ctx, Id value) { | ||
| 118 | return ctx.OpFindSMsb(ctx.U32[1], value); | ||
| 119 | } | ||
| 120 | |||
| 121 | Id EmitFindUMsb32(EmitContext& ctx, Id value) { | ||
| 122 | return ctx.OpFindUMsb(ctx.U32[1], value); | ||
| 115 | } | 123 | } |
| 116 | 124 | ||
| 117 | Id EmitSMin32(EmitContext& ctx, Id a, Id b) { | 125 | Id EmitSMin32(EmitContext& ctx, Id a, Id b) { |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index 04edcdfd8..0f1cab57a 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -812,8 +812,16 @@ U32 IREmitter::BitCount(const U32& value) { | |||
| 812 | return Inst<U32>(Opcode::BitCount32, value); | 812 | return Inst<U32>(Opcode::BitCount32, value); |
| 813 | } | 813 | } |
| 814 | 814 | ||
| 815 | U32 IREmitter::BitwiseNot(const U32& a) { | 815 | U32 IREmitter::BitwiseNot(const U32& value) { |
| 816 | return Inst<U32>(Opcode::BitwiseNot32, a); | 816 | return Inst<U32>(Opcode::BitwiseNot32, value); |
| 817 | } | ||
| 818 | |||
| 819 | U32 IREmitter::FindSMsb(const U32& value) { | ||
| 820 | return Inst<U32>(Opcode::FindSMsb32, value); | ||
| 821 | } | ||
| 822 | |||
| 823 | U32 IREmitter::FindUMsb(const U32& value) { | ||
| 824 | return Inst<U32>(Opcode::FindUMsb32, value); | ||
| 817 | } | 825 | } |
| 818 | 826 | ||
| 819 | U32 IREmitter::SMin(const U32& a, const U32& b) { | 827 | U32 IREmitter::SMin(const U32& a, const U32& b) { |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index 00ba2e4cd..03a67985f 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h | |||
| @@ -161,8 +161,10 @@ public: | |||
| 161 | bool is_signed); | 161 | bool is_signed); |
| 162 | [[nodiscard]] U32 BitReverse(const U32& value); | 162 | [[nodiscard]] U32 BitReverse(const U32& value); |
| 163 | [[nodiscard]] U32 BitCount(const U32& value); | 163 | [[nodiscard]] U32 BitCount(const U32& value); |
| 164 | [[nodiscard]] U32 BitwiseNot(const U32& a); | 164 | [[nodiscard]] U32 BitwiseNot(const U32& value); |
| 165 | 165 | ||
| 166 | [[nodiscard]] U32 FindSMsb(const U32& value); | ||
| 167 | [[nodiscard]] U32 FindUMsb(const U32& value); | ||
| 166 | [[nodiscard]] U32 SMin(const U32& a, const U32& b); | 168 | [[nodiscard]] U32 SMin(const U32& a, const U32& b); |
| 167 | [[nodiscard]] U32 UMin(const U32& a, const U32& b); | 169 | [[nodiscard]] U32 UMin(const U32& a, const U32& b); |
| 168 | [[nodiscard]] U32 SMax(const U32& a, const U32& b); | 170 | [[nodiscard]] U32 SMax(const U32& a, const U32& b); |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index 2c4a997dc..aedbc5c3e 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -235,6 +235,8 @@ OPCODE(BitReverse32, U32, U32, | |||
| 235 | OPCODE(BitCount32, U32, U32, ) | 235 | OPCODE(BitCount32, U32, U32, ) |
| 236 | OPCODE(BitwiseNot32, U32, U32, ) | 236 | OPCODE(BitwiseNot32, U32, U32, ) |
| 237 | 237 | ||
| 238 | OPCODE(FindSMsb32, U32, U32, ) | ||
| 239 | OPCODE(FindUMsb32, U32, U32, ) | ||
| 238 | OPCODE(SMin32, U32, U32, U32, ) | 240 | OPCODE(SMin32, U32, U32, U32, ) |
| 239 | OPCODE(UMin32, U32, U32, U32, ) | 241 | OPCODE(UMin32, U32, U32, U32, ) |
| 240 | OPCODE(SMax32, U32, U32, U32, ) | 242 | OPCODE(SMax32, U32, U32, U32, ) |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/find_leading_one.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/find_leading_one.cpp new file mode 100644 index 000000000..d5361bec5 --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/find_leading_one.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/bit_field.h" | ||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | ||
| 8 | |||
| 9 | namespace Shader::Maxwell { | ||
| 10 | namespace { | ||
| 11 | void FLO(TranslatorVisitor& v, u64 insn, const IR::U32& src) { | ||
| 12 | union { | ||
| 13 | u64 insn; | ||
| 14 | BitField<0, 8, IR::Reg> dest_reg; | ||
| 15 | BitField<40, 1, u64> tilde; | ||
| 16 | BitField<41, 1, u64> shift; | ||
| 17 | BitField<48, 1, u64> is_signed; | ||
| 18 | } const flo{insn}; | ||
| 19 | |||
| 20 | const bool invert{flo.tilde != 0}; | ||
| 21 | const bool is_signed{flo.is_signed != 0}; | ||
| 22 | const bool shift_op{flo.shift != 0}; | ||
| 23 | |||
| 24 | const IR::U32 operand{invert ? v.ir.BitwiseNot(src) : src}; | ||
| 25 | const IR::U32 find_result{is_signed ? v.ir.FindSMsb(operand) : v.ir.FindUMsb(operand)}; | ||
| 26 | const IR::U1 find_fail{v.ir.IEqual(find_result, v.ir.Imm32(-1))}; | ||
| 27 | const IR::U32 offset{v.ir.Imm32(31)}; | ||
| 28 | const IR::U32 success_result{shift_op ? IR::U32{v.ir.ISub(offset, find_result)} : find_result}; | ||
| 29 | |||
| 30 | const IR::U32 result{v.ir.Select(find_fail, find_result, success_result)}; | ||
| 31 | v.X(flo.dest_reg, result); | ||
| 32 | } | ||
| 33 | } // Anonymous namespace | ||
| 34 | |||
| 35 | void TranslatorVisitor::FLO_reg(u64 insn) { | ||
| 36 | FLO(*this, insn, GetReg20(insn)); | ||
| 37 | } | ||
| 38 | |||
| 39 | void TranslatorVisitor::FLO_cbuf(u64 insn) { | ||
| 40 | FLO(*this, insn, GetCbuf(insn)); | ||
| 41 | } | ||
| 42 | |||
| 43 | void TranslatorVisitor::FLO_imm(u64 insn) { | ||
| 44 | FLO(*this, insn, GetImm20(insn)); | ||
| 45 | } | ||
| 46 | } // namespace Shader::Maxwell | ||
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp index f327e6fa5..2da0b87c4 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp | |||
| @@ -217,18 +217,6 @@ void TranslatorVisitor::FCMP_imm(u64) { | |||
| 217 | ThrowNotImplemented(Opcode::FCMP_imm); | 217 | ThrowNotImplemented(Opcode::FCMP_imm); |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | void TranslatorVisitor::FLO_reg(u64) { | ||
| 221 | ThrowNotImplemented(Opcode::FLO_reg); | ||
| 222 | } | ||
| 223 | |||
| 224 | void TranslatorVisitor::FLO_cbuf(u64) { | ||
| 225 | ThrowNotImplemented(Opcode::FLO_cbuf); | ||
| 226 | } | ||
| 227 | |||
| 228 | void TranslatorVisitor::FLO_imm(u64) { | ||
| 229 | ThrowNotImplemented(Opcode::FLO_imm); | ||
| 230 | } | ||
| 231 | |||
| 232 | void TranslatorVisitor::FMNMX_reg(u64) { | 220 | void TranslatorVisitor::FMNMX_reg(u64) { |
| 233 | ThrowNotImplemented(Opcode::FMNMX_reg); | 221 | ThrowNotImplemented(Opcode::FMNMX_reg); |
| 234 | } | 222 | } |