diff options
author | lat9nq <lat9nq@gmail.com> | 2021-07-25 21:31:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-25 21:31:33 +0200 |
commit | 09d6cc99435322c5f480eaa2b0967e33f4966ba6 (patch) | |
tree | 72cdf06f6b7d77fdf5826104fea691f3ea450f54 /src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp | |
parent | configuration: Use combobox apply template where possible (diff) | |
parent | Merge pull request #6575 from FernandoS27/new_settings (diff) | |
download | yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.tar yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.tar.gz yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.tar.bz2 yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.tar.lz yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.tar.xz yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.tar.zst yuzu-09d6cc99435322c5f480eaa2b0967e33f4966ba6.zip |
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp')
-rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
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..0dbeb7f56 --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.cpp @@ -0,0 +1,62 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "shader_recompiler/frontend/maxwell/translate/impl/half_floating_point_helper.h" + +namespace Shader::Maxwell { + +IR::FmzMode HalfPrecision2FmzMode(HalfPrecision precision) { + switch (precision) { + case HalfPrecision::None: + return IR::FmzMode::None; + case HalfPrecision::FTZ: + return IR::FmzMode::FTZ; + case HalfPrecision::FMZ: + return IR::FmzMode::FMZ; + default: + return IR::FmzMode::DontCare; + } +} + +std::pair<IR::F16F32F64, IR::F16F32F64> Extract(IR::IREmitter& ir, IR::U32 value, Swizzle swizzle) { + switch (swizzle) { + case Swizzle::H1_H0: { + const IR::Value vector{ir.UnpackFloat2x16(value)}; + return {IR::F16{ir.CompositeExtract(vector, 0)}, IR::F16{ir.CompositeExtract(vector, 1)}}; + } + case Swizzle::H0_H0: { + const IR::F16 scalar{ir.CompositeExtract(ir.UnpackFloat2x16(value), 0)}; + return {scalar, scalar}; + } + case Swizzle::H1_H1: { + const IR::F16 scalar{ir.CompositeExtract(ir.UnpackFloat2x16(value), 1)}; + return {scalar, scalar}; + } + case Swizzle::F32: { + const IR::F32 scalar{ir.BitCast<IR::F32>(value)}; + return {scalar, scalar}; + } + } + throw InvalidArgument("Invalid swizzle {}", swizzle); +} + +IR::U32 MergeResult(IR::IREmitter& ir, IR::Reg dest, const IR::F16& lhs, const IR::F16& rhs, + Merge merge) { + switch (merge) { + case Merge::H1_H0: + return ir.PackFloat2x16(ir.CompositeConstruct(lhs, rhs)); + case Merge::F32: + return ir.BitCast<IR::U32, IR::F32>(ir.FPConvert(32, lhs)); + case Merge::MRG_H0: + case Merge::MRG_H1: { + const IR::Value vector{ir.UnpackFloat2x16(ir.GetReg(dest))}; + const bool is_h0{merge == Merge::MRG_H0}; + const IR::F16 insert{ir.FPConvert(16, is_h0 ? lhs : rhs)}; + return ir.PackFloat2x16(ir.CompositeInsert(vector, insert, is_h0 ? 0 : 1)); + } + } + throw InvalidArgument("Invalid merge {}", merge); +} + +} // namespace Shader::Maxwell |