diff options
| author | 2021-03-20 21:22:21 +0100 | |
|---|---|---|
| committer | 2021-07-22 21:51:23 -0400 | |
| commit | e802512d8e49cc4a92c0c09fe023576c2a2ab3db (patch) | |
| tree | 76c0e4b0a956307b7c00df422c93546267d95eeb | |
| parent | shader: Implement I2F (diff) | |
| download | yuzu-e802512d8e49cc4a92c0c09fe023576c2a2ab3db.tar.gz yuzu-e802512d8e49cc4a92c0c09fe023576c2a2ab3db.tar.xz yuzu-e802512d8e49cc4a92c0c09fe023576c2a2ab3db.zip | |
shader: Refactor half floating instructions
4 files changed, 84 insertions, 58 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index d0f0ec775..21c66ce13 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt | |||
| @@ -78,6 +78,8 @@ add_library(shader_recompiler STATIC | |||
| 78 | frontend/maxwell/translate/impl/floating_point_range_reduction.cpp | 78 | frontend/maxwell/translate/impl/floating_point_range_reduction.cpp |
| 79 | frontend/maxwell/translate/impl/floating_point_set_predicate.cpp | 79 | frontend/maxwell/translate/impl/floating_point_set_predicate.cpp |
| 80 | frontend/maxwell/translate/impl/half_floating_point_add.cpp | 80 | frontend/maxwell/translate/impl/half_floating_point_add.cpp |
| 81 | frontend/maxwell/translate/impl/half_floating_point_helper.cpp | ||
| 82 | frontend/maxwell/translate/impl/half_floating_point_helper.h | ||
| 81 | frontend/maxwell/translate/impl/impl.cpp | 83 | frontend/maxwell/translate/impl/impl.cpp |
| 82 | frontend/maxwell/translate/impl/impl.h | 84 | frontend/maxwell/translate/impl/impl.h |
| 83 | frontend/maxwell/translate/impl/integer_add.cpp | 85 | frontend/maxwell/translate/impl/integer_add.cpp |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_add.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_add.cpp index c292d5e87..19e3401ca 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_add.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_add.cpp | |||
| @@ -2,66 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | 5 | #include "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" |
| 6 | #include "shader_recompiler/exception.h" | ||
| 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/common_encoding.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | ||
| 9 | 6 | ||
| 10 | namespace Shader::Maxwell { | 7 | namespace Shader::Maxwell { |
| 11 | namespace { | 8 | namespace { |
| 12 | enum class Merge : u64 { | ||
| 13 | H1_H0, | ||
| 14 | F32, | ||
| 15 | MRG_H0, | ||
| 16 | MRG_H1, | ||
| 17 | }; | ||
| 18 | |||
| 19 | enum class Swizzle : u64 { | ||
| 20 | H1_H0, | ||
| 21 | F32, | ||
| 22 | H0_H0, | ||
| 23 | H1_H1, | ||
| 24 | }; | ||
| 25 | |||
| 26 | std::pair<IR::F16F32F64, IR::F16F32F64> Extract(IR::IREmitter& ir, IR::U32 value, Swizzle swizzle) { | ||
| 27 | switch (swizzle) { | ||
| 28 | case Swizzle::H1_H0: { | ||
| 29 | const IR::Value vector{ir.UnpackFloat2x16(value)}; | ||
| 30 | return {IR::F16{ir.CompositeExtract(vector, 0)}, IR::F16{ir.CompositeExtract(vector, 1)}}; | ||
| 31 | } | ||
| 32 | case Swizzle::H0_H0: { | ||
| 33 | const IR::F16 scalar{ir.CompositeExtract(ir.UnpackFloat2x16(value), 0)}; | ||
| 34 | return {scalar, scalar}; | ||
| 35 | } | ||
| 36 | case Swizzle::H1_H1: { | ||
| 37 | const IR::F16 scalar{ir.CompositeExtract(ir.UnpackFloat2x16(value), 1)}; | ||
| 38 | return {scalar, scalar}; | ||
| 39 | } | ||
| 40 | case Swizzle::F32: { | ||
| 41 | const IR::F32 scalar{ir.BitCast<IR::F32>(value)}; | ||
| 42 | return {scalar, scalar}; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | throw InvalidArgument("Invalid swizzle {}", swizzle); | ||
| 46 | } | ||
| 47 | |||
| 48 | IR::U32 MergeResult(IR::IREmitter& ir, IR::Reg dest, const IR::F16& lhs, const IR::F16& rhs, | ||
| 49 | Merge merge) { | ||
| 50 | switch (merge) { | ||
| 51 | case Merge::H1_H0: | ||
| 52 | return ir.PackFloat2x16(ir.CompositeConstruct(lhs, rhs)); | ||
| 53 | case Merge::F32: | ||
| 54 | return ir.BitCast<IR::U32, IR::F32>(ir.FPConvert(32, lhs)); | ||
| 55 | case Merge::MRG_H0: | ||
| 56 | case Merge::MRG_H1: { | ||
| 57 | const IR::Value vector{ir.UnpackFloat2x16(ir.GetReg(dest))}; | ||
| 58 | const bool h0{merge == Merge::MRG_H0}; | ||
| 59 | const IR::F16& insert{h0 ? lhs : rhs}; | ||
| 60 | return ir.PackFloat2x16(ir.CompositeInsert(vector, insert, h0 ? 0 : 1)); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | throw InvalidArgument("Invalid merge {}", merge); | ||
| 64 | } | ||
| 65 | 9 | ||
| 66 | void HADD2(TranslatorVisitor& v, u64 insn, Merge merge, bool ftz, bool sat, bool abs_a, bool neg_a, | 10 | void HADD2(TranslatorVisitor& v, u64 insn, Merge merge, bool ftz, bool sat, bool abs_a, bool neg_a, |
| 67 | Swizzle swizzle_a, bool abs_b, bool neg_b, Swizzle swizzle_b, const IR::U32& src_b) { | 11 | Swizzle swizzle_a, bool abs_b, bool neg_b, Swizzle swizzle_b, const IR::U32& src_b) { |
| @@ -122,7 +66,7 @@ void HADD2(TranslatorVisitor& v, u64 insn, bool sat, bool abs_b, bool neg_b, Swi | |||
| 122 | HADD2(v, insn, hadd2.merge, hadd2.ftz != 0, sat, hadd2.abs_a != 0, hadd2.neg_a != 0, | 66 | HADD2(v, insn, hadd2.merge, hadd2.ftz != 0, sat, hadd2.abs_a != 0, hadd2.neg_a != 0, |
| 123 | hadd2.swizzle_a, abs_b, neg_b, swizzle_b, src_b); | 67 | hadd2.swizzle_a, abs_b, neg_b, swizzle_b, src_b); |
| 124 | } | 68 | } |
| 125 | } // Anonymous namespace | 69 | } // namespace |
| 126 | 70 | ||
| 127 | void TranslatorVisitor::HADD2_reg(u64 insn) { | 71 | void TranslatorVisitor::HADD2_reg(u64 insn) { |
| 128 | union { | 72 | union { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp new file mode 100644 index 000000000..930822092 --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp | |||
| @@ -0,0 +1,49 @@ | |||
| 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 "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" | ||
| 6 | |||
| 7 | namespace Shader::Maxwell { | ||
| 8 | |||
| 9 | std::pair<IR::F16F32F64, IR::F16F32F64> Extract(IR::IREmitter& ir, IR::U32 value, Swizzle swizzle) { | ||
| 10 | switch (swizzle) { | ||
| 11 | case Swizzle::H1_H0: { | ||
| 12 | const IR::Value vector{ir.UnpackFloat2x16(value)}; | ||
| 13 | return {IR::F16{ir.CompositeExtract(vector, 0)}, IR::F16{ir.CompositeExtract(vector, 1)}}; | ||
| 14 | } | ||
| 15 | case Swizzle::H0_H0: { | ||
| 16 | const IR::F16 scalar{ir.CompositeExtract(ir.UnpackFloat2x16(value), 0)}; | ||
| 17 | return {scalar, scalar}; | ||
| 18 | } | ||
| 19 | case Swizzle::H1_H1: { | ||
| 20 | const IR::F16 scalar{ir.CompositeExtract(ir.UnpackFloat2x16(value), 1)}; | ||
| 21 | return {scalar, scalar}; | ||
| 22 | } | ||
| 23 | case Swizzle::F32: { | ||
| 24 | const IR::F32 scalar{ir.BitCast<IR::F32>(value)}; | ||
| 25 | return {scalar, scalar}; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | throw InvalidArgument("Invalid swizzle {}", swizzle); | ||
| 29 | } | ||
| 30 | |||
| 31 | IR::U32 MergeResult(IR::IREmitter& ir, IR::Reg dest, const IR::F16& lhs, const IR::F16& rhs, | ||
| 32 | Merge merge) { | ||
| 33 | switch (merge) { | ||
| 34 | case Merge::H1_H0: | ||
| 35 | return ir.PackFloat2x16(ir.CompositeConstruct(lhs, rhs)); | ||
| 36 | case Merge::F32: | ||
| 37 | return ir.BitCast<IR::U32, IR::F32>(ir.FPConvert(32, lhs)); | ||
| 38 | case Merge::MRG_H0: | ||
| 39 | case Merge::MRG_H1: { | ||
| 40 | const IR::Value vector{ir.UnpackFloat2x16(ir.GetReg(dest))}; | ||
| 41 | const bool h0{merge == Merge::MRG_H0}; | ||
| 42 | const IR::F16& insert{h0 ? lhs : rhs}; | ||
| 43 | return ir.PackFloat2x16(ir.CompositeInsert(vector, insert, h0 ? 0 : 1)); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | throw InvalidArgument("Invalid merge {}", merge); | ||
| 47 | } | ||
| 48 | |||
| 49 | } // namespace Shader::Maxwell | ||
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h new file mode 100644 index 000000000..0933b595e --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h | |||
| @@ -0,0 +1,31 @@ | |||
| 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/common_types.h" | ||
| 6 | #include "shader_recompiler/exception.h" | ||
| 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/common_encoding.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | ||
| 9 | |||
| 10 | namespace Shader::Maxwell { | ||
| 11 | |||
| 12 | enum class Merge : u64 { | ||
| 13 | H1_H0, | ||
| 14 | F32, | ||
| 15 | MRG_H0, | ||
| 16 | MRG_H1, | ||
| 17 | }; | ||
| 18 | |||
| 19 | enum class Swizzle : u64 { | ||
| 20 | H1_H0, | ||
| 21 | F32, | ||
| 22 | H0_H0, | ||
| 23 | H1_H1, | ||
| 24 | }; | ||
| 25 | |||
| 26 | std::pair<IR::F16F32F64, IR::F16F32F64> Extract(IR::IREmitter& ir, IR::U32 value, Swizzle swizzle); | ||
| 27 | |||
| 28 | IR::U32 MergeResult(IR::IREmitter& ir, IR::Reg dest, const IR::F16& lhs, const IR::F16& rhs, | ||
| 29 | Merge merge); | ||
| 30 | |||
| 31 | } // namespace Shader::Maxwell | ||