summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-03-04 07:02:44 +0100
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:23 +0200
commit81f72471e831a0bc4205df6df61e5b510a5c25ac (patch)
tree529ce1f6999c0c2ec7d55255b6c8c62be57f4370 /src/shader_recompiler
parentshader: Implement HADD2 (diff)
downloadyuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.tar
yuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.tar.gz
yuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.tar.bz2
yuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.tar.lz
yuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.tar.xz
yuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.tar.zst
yuzu-81f72471e831a0bc4205df6df61e5b510a5c25ac.zip
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/CMakeLists.txt1
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp99
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp12
3 files changed, 100 insertions, 12 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt
index cb73e03fb..51c245a63 100644
--- a/src/shader_recompiler/CMakeLists.txt
+++ b/src/shader_recompiler/CMakeLists.txt
@@ -85,6 +85,7 @@ add_library(shader_recompiler STATIC
frontend/maxwell/translate/impl/integer_shift_left.cpp
frontend/maxwell/translate/impl/integer_shift_right.cpp
frontend/maxwell/translate/impl/integer_short_multiply_add.cpp
+ frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp
frontend/maxwell/translate/impl/load_store_attribute.cpp
frontend/maxwell/translate/impl/load_store_memory.cpp
frontend/maxwell/translate/impl/logic_operation.cpp
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp
new file mode 100644
index 000000000..ca28c6dd9
--- /dev/null
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp
@@ -0,0 +1,99 @@
+// 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/impl.h"
+
+namespace Shader::Maxwell {
+namespace {
+enum class IntegerWidth : u64 {
+ Byte,
+ Short,
+ Word,
+};
+
+[[nodiscard]] IR::U32 WidthSize(IR::IREmitter& ir, IntegerWidth width) {
+ switch (width) {
+ case IntegerWidth::Byte:
+ return ir.Imm32(8);
+ case IntegerWidth::Short:
+ return ir.Imm32(16);
+ case IntegerWidth::Word:
+ return ir.Imm32(32);
+ default:
+ throw NotImplementedException("Invalid width {}", width);
+ }
+}
+
+[[nodiscard]] IR::U32 ConvertInteger(IR::IREmitter& ir, const IR::U32& src,
+ IntegerWidth dst_width) {
+ const IR::U32 zero{ir.Imm32(0)};
+ switch (dst_width) {
+ case IntegerWidth::Byte:
+ return ir.BitFieldExtract(src, zero, ir.Imm32(8), false);
+ case IntegerWidth::Short:
+ return ir.BitFieldExtract(src, zero, ir.Imm32(16), false);
+ case IntegerWidth::Word:
+ return ir.BitFieldExtract(src, zero, ir.Imm32(32), false);
+ default:
+ throw NotImplementedException("Invalid width {}", dst_width);
+ }
+}
+
+void I2I(TranslatorVisitor& v, u64 insn, const IR::U32& src_a) {
+ union {
+ u64 insn;
+ BitField<0, 8, IR::Reg> dest_reg;
+ BitField<8, 2, IntegerWidth> dst_fmt;
+ BitField<12, 1, u64> dst_fmt_sign;
+ BitField<10, 2, IntegerWidth> src_fmt;
+ BitField<13, 1, u64> src_fmt_sign;
+ BitField<41, 3, u64> selector;
+ BitField<45, 1, u64> neg;
+ BitField<49, 1, u64> abs;
+ BitField<50, 1, u64> sat;
+ } const i2i{insn};
+
+ if (i2i.sat != 0) {
+ throw NotImplementedException("I2I SAT");
+ }
+ if (i2i.src_fmt == IntegerWidth::Short && (i2i.selector == 1 || i2i.selector == 3)) {
+ throw NotImplementedException("16-bit source format incompatible with selector {}",
+ i2i.selector);
+ }
+ if (i2i.src_fmt == IntegerWidth::Word && i2i.selector != 0) {
+ throw NotImplementedException("32-bit source format incompatible with selector {}",
+ i2i.selector);
+ }
+
+ const s32 selector{static_cast<s32>(i2i.selector)};
+ const IR::U32 offset{v.ir.Imm32(selector * 8)};
+ const IR::U32 count{WidthSize(v.ir, i2i.src_fmt)};
+ IR::U32 src_values{v.ir.BitFieldExtract(src_a, offset, count, i2i.src_fmt_sign != 0)};
+ if (i2i.abs) {
+ src_values = v.ir.IAbs(src_values);
+ }
+ if (i2i.neg) {
+ src_values = v.ir.INeg(src_values);
+ }
+
+ const IR::U32 result{ConvertInteger(v.ir, src_values, i2i.dst_fmt)};
+ v.X(i2i.dest_reg, result);
+}
+} // Anonymous namespace
+
+void TranslatorVisitor::I2I_reg(u64 insn) {
+ I2I(*this, insn, GetReg20(insn));
+}
+
+void TranslatorVisitor::I2I_cbuf(u64 insn) {
+ I2I(*this, insn, GetCbuf(insn));
+}
+
+void TranslatorVisitor::I2I_imm(u64 insn) {
+ I2I(*this, insn, GetImm20(insn));
+}
+
+} // 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 c24f29ff7..bd7a7a8b7 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
@@ -337,18 +337,6 @@ void TranslatorVisitor::I2F_imm(u64) {
ThrowNotImplemented(Opcode::I2F_imm);
}
-void TranslatorVisitor::I2I_reg(u64) {
- ThrowNotImplemented(Opcode::I2I_reg);
-}
-
-void TranslatorVisitor::I2I_cbuf(u64) {
- ThrowNotImplemented(Opcode::I2I_cbuf);
-}
-
-void TranslatorVisitor::I2I_imm(u64) {
- ThrowNotImplemented(Opcode::I2I_imm);
-}
-
void TranslatorVisitor::IDE(u64) {
ThrowNotImplemented(Opcode::IDE);
}