diff options
Diffstat (limited to 'src')
8 files changed, 88 insertions, 15 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index ddd34e915..cc38b28ed 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt | |||
| @@ -94,6 +94,7 @@ add_library(shader_recompiler STATIC | |||
| 94 | frontend/maxwell/translate/impl/logic_operation_three_input.cpp | 94 | frontend/maxwell/translate/impl/logic_operation_three_input.cpp |
| 95 | frontend/maxwell/translate/impl/move_predicate_to_register.cpp | 95 | frontend/maxwell/translate/impl/move_predicate_to_register.cpp |
| 96 | frontend/maxwell/translate/impl/move_register.cpp | 96 | frontend/maxwell/translate/impl/move_register.cpp |
| 97 | frontend/maxwell/translate/impl/move_register_to_predicate.cpp | ||
| 97 | frontend/maxwell/translate/impl/move_special_register.cpp | 98 | frontend/maxwell/translate/impl/move_special_register.cpp |
| 98 | frontend/maxwell/translate/impl/not_implemented.cpp | 99 | frontend/maxwell/translate/impl/not_implemented.cpp |
| 99 | frontend/maxwell/translate/impl/predicate_set_predicate.cpp | 100 | frontend/maxwell/translate/impl/predicate_set_predicate.cpp |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index bf1b5ace6..92387ca28 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -120,6 +120,7 @@ void EmitCompositeExtractF64x4(EmitContext& ctx); | |||
| 120 | Id EmitCompositeInsertF64x2(EmitContext& ctx, Id composite, Id object, u32 index); | 120 | Id EmitCompositeInsertF64x2(EmitContext& ctx, Id composite, Id object, u32 index); |
| 121 | Id EmitCompositeInsertF64x3(EmitContext& ctx, Id composite, Id object, u32 index); | 121 | Id EmitCompositeInsertF64x3(EmitContext& ctx, Id composite, Id object, u32 index); |
| 122 | Id EmitCompositeInsertF64x4(EmitContext& ctx, Id composite, Id object, u32 index); | 122 | Id EmitCompositeInsertF64x4(EmitContext& ctx, Id composite, Id object, u32 index); |
| 123 | Id EmitSelectU1(EmitContext& ctx, Id cond, Id true_value, Id false_value); | ||
| 123 | Id EmitSelectU8(EmitContext& ctx, Id cond, Id true_value, Id false_value); | 124 | Id EmitSelectU8(EmitContext& ctx, Id cond, Id true_value, Id false_value); |
| 124 | Id EmitSelectU16(EmitContext& ctx, Id cond, Id true_value, Id false_value); | 125 | Id EmitSelectU16(EmitContext& ctx, Id cond, Id true_value, Id false_value); |
| 125 | Id EmitSelectU32(EmitContext& ctx, Id cond, Id true_value, Id false_value); | 126 | Id EmitSelectU32(EmitContext& ctx, Id cond, Id true_value, Id false_value); |
| @@ -242,7 +243,7 @@ Id EmitBitwiseOr32(EmitContext& ctx, Id a, Id b); | |||
| 242 | Id EmitBitwiseXor32(EmitContext& ctx, Id a, Id b); | 243 | Id EmitBitwiseXor32(EmitContext& ctx, Id a, Id b); |
| 243 | Id EmitBitFieldInsert(EmitContext& ctx, Id base, Id insert, Id offset, Id count); | 244 | Id EmitBitFieldInsert(EmitContext& ctx, Id base, Id insert, Id offset, Id count); |
| 244 | Id EmitBitFieldSExtract(EmitContext& ctx, Id base, Id offset, Id count); | 245 | Id EmitBitFieldSExtract(EmitContext& ctx, Id base, Id offset, Id count); |
| 245 | Id EmitBitFieldUExtract(EmitContext& ctx, Id base, Id offset, Id count); | 246 | Id EmitBitFieldUExtract(EmitContext& ctx, IR::Inst* inst, Id base, Id offset, Id count); |
| 246 | Id EmitBitReverse32(EmitContext& ctx, Id value); | 247 | Id EmitBitReverse32(EmitContext& ctx, Id value); |
| 247 | Id EmitBitCount32(EmitContext& ctx, Id value); | 248 | Id EmitBitCount32(EmitContext& ctx, Id value); |
| 248 | Id EmitBitwiseNot32(EmitContext& ctx, Id value); | 249 | Id EmitBitwiseNot32(EmitContext& ctx, Id value); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp index 5ab3b5e86..c9de204b0 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp | |||
| @@ -114,8 +114,13 @@ Id EmitBitFieldSExtract(EmitContext& ctx, Id base, Id offset, Id count) { | |||
| 114 | return ctx.OpBitFieldSExtract(ctx.U32[1], base, offset, count); | 114 | return ctx.OpBitFieldSExtract(ctx.U32[1], base, offset, count); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | Id EmitBitFieldUExtract(EmitContext& ctx, Id base, Id offset, Id count) { | 117 | Id EmitBitFieldUExtract(EmitContext& ctx, IR::Inst* inst, Id base, Id offset, Id count) { |
| 118 | return ctx.OpBitFieldUExtract(ctx.U32[1], base, offset, count); | 118 | const Id result{ctx.OpBitFieldUExtract(ctx.U32[1], base, offset, count)}; |
| 119 | if (IR::Inst* const zero{inst->GetAssociatedPseudoOperation(IR::Opcode::GetZeroFromOp)}) { | ||
| 120 | zero->SetDefinition(ctx.OpIEqual(ctx.U1, result, ctx.u32_zero_value)); | ||
| 121 | zero->Invalidate(); | ||
| 122 | } | ||
| 123 | return result; | ||
| 119 | } | 124 | } |
| 120 | 125 | ||
| 121 | Id EmitBitReverse32(EmitContext& ctx, Id value) { | 126 | Id EmitBitReverse32(EmitContext& ctx, Id value) { |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp index 21cca4455..0ae127d50 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_select.cpp | |||
| @@ -6,6 +6,10 @@ | |||
| 6 | 6 | ||
| 7 | namespace Shader::Backend::SPIRV { | 7 | namespace Shader::Backend::SPIRV { |
| 8 | 8 | ||
| 9 | Id EmitSelectU1(EmitContext& ctx, Id cond, Id true_value, Id false_value) { | ||
| 10 | return ctx.OpSelect(ctx.U1, cond, true_value, false_value); | ||
| 11 | } | ||
| 12 | |||
| 9 | Id EmitSelectU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Id cond, | 13 | Id EmitSelectU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Id cond, |
| 10 | [[maybe_unused]] Id true_value, [[maybe_unused]] Id false_value) { | 14 | [[maybe_unused]] Id true_value, [[maybe_unused]] Id false_value) { |
| 11 | throw NotImplementedException("SPIR-V Instruction"); | 15 | throw NotImplementedException("SPIR-V Instruction"); |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index 1659b7f3b..f38b46bac 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -412,6 +412,8 @@ Value IREmitter::Select(const U1& condition, const Value& true_value, const Valu | |||
| 412 | throw InvalidArgument("Mismatching types {} and {}", true_value.Type(), false_value.Type()); | 412 | throw InvalidArgument("Mismatching types {} and {}", true_value.Type(), false_value.Type()); |
| 413 | } | 413 | } |
| 414 | switch (true_value.Type()) { | 414 | switch (true_value.Type()) { |
| 415 | case Type::U1: | ||
| 416 | return Inst(Opcode::SelectU1, condition, true_value, false_value); | ||
| 415 | case Type::U8: | 417 | case Type::U8: |
| 416 | return Inst(Opcode::SelectU8, condition, true_value, false_value); | 418 | return Inst(Opcode::SelectU8, condition, true_value, false_value); |
| 417 | case Type::U16: | 419 | case Type::U16: |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index 75f09ebfc..c4e72c84d 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -115,6 +115,7 @@ OPCODE(CompositeInsertF64x3, F64x3, F64x | |||
| 115 | OPCODE(CompositeInsertF64x4, F64x4, F64x4, F64, U32, ) | 115 | OPCODE(CompositeInsertF64x4, F64x4, F64x4, F64, U32, ) |
| 116 | 116 | ||
| 117 | // Select operations | 117 | // Select operations |
| 118 | OPCODE(SelectU1, U1, U1, U1, U1, ) | ||
| 118 | OPCODE(SelectU8, U8, U1, U8, U8, ) | 119 | OPCODE(SelectU8, U8, U1, U8, U8, ) |
| 119 | OPCODE(SelectU16, U16, U1, U16, U16, ) | 120 | OPCODE(SelectU16, U16, U1, U16, U16, ) |
| 120 | OPCODE(SelectU32, U32, U1, U32, U32, ) | 121 | OPCODE(SelectU32, U32, U1, U32, U32, ) |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/move_register_to_predicate.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/move_register_to_predicate.cpp new file mode 100644 index 000000000..eda5f177b --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/move_register_to_predicate.cpp | |||
| @@ -0,0 +1,71 @@ | |||
| 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 "shader_recompiler/exception.h" | ||
| 7 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | ||
| 8 | |||
| 9 | namespace Shader::Maxwell { | ||
| 10 | namespace { | ||
| 11 | enum class Mode : u64 { | ||
| 12 | PR, | ||
| 13 | CC, | ||
| 14 | }; | ||
| 15 | |||
| 16 | void SetFlag(IR::IREmitter& ir, const IR::U1& inv_mask_bit, const IR::U1& src_bit, u32 index) { | ||
| 17 | switch (index) { | ||
| 18 | case 0: | ||
| 19 | return ir.SetZFlag(IR::U1{ir.Select(inv_mask_bit, ir.GetZFlag(), src_bit)}); | ||
| 20 | case 1: | ||
| 21 | return ir.SetSFlag(IR::U1{ir.Select(inv_mask_bit, ir.GetSFlag(), src_bit)}); | ||
| 22 | case 2: | ||
| 23 | return ir.SetCFlag(IR::U1{ir.Select(inv_mask_bit, ir.GetCFlag(), src_bit)}); | ||
| 24 | case 3: | ||
| 25 | return ir.SetOFlag(IR::U1{ir.Select(inv_mask_bit, ir.GetOFlag(), src_bit)}); | ||
| 26 | default: | ||
| 27 | throw LogicError("Unreachable R2P index"); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | void R2P(TranslatorVisitor& v, u64 insn, const IR::U32& mask) { | ||
| 32 | union { | ||
| 33 | u64 raw; | ||
| 34 | BitField<8, 8, IR::Reg> src_reg; | ||
| 35 | BitField<40, 1, Mode> mode; | ||
| 36 | BitField<41, 2, u64> byte_selector; | ||
| 37 | } const r2p{insn}; | ||
| 38 | const IR::U32 src{v.X(r2p.src_reg)}; | ||
| 39 | const IR::U32 count{v.ir.Imm32(1)}; | ||
| 40 | const bool pr_mode{r2p.mode == Mode::PR}; | ||
| 41 | const u32 num_items{pr_mode ? 7U : 4U}; | ||
| 42 | const u32 offset_base{static_cast<u32>(r2p.byte_selector) * 8}; | ||
| 43 | for (u32 index = 0; index < num_items; ++index) { | ||
| 44 | const IR::U32 offset{v.ir.Imm32(offset_base + index)}; | ||
| 45 | const IR::U1 src_zero{v.ir.GetZeroFromOp(v.ir.BitFieldExtract(src, offset, count, false))}; | ||
| 46 | const IR::U1 src_bit{v.ir.LogicalNot(src_zero)}; | ||
| 47 | const IR::U32 mask_bfe{v.ir.BitFieldExtract(mask, v.ir.Imm32(index), count, false)}; | ||
| 48 | const IR::U1 inv_mask_bit{v.ir.GetZeroFromOp(mask_bfe)}; | ||
| 49 | if (pr_mode) { | ||
| 50 | const IR::Pred pred{index}; | ||
| 51 | v.ir.SetPred(pred, IR::U1{v.ir.Select(inv_mask_bit, v.ir.GetPred(pred), src_bit)}); | ||
| 52 | } else { | ||
| 53 | SetFlag(v.ir, inv_mask_bit, src_bit, index); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } // Anonymous namespace | ||
| 58 | |||
| 59 | void TranslatorVisitor::R2P_reg(u64 insn) { | ||
| 60 | R2P(*this, insn, GetReg20(insn)); | ||
| 61 | } | ||
| 62 | |||
| 63 | void TranslatorVisitor::R2P_cbuf(u64 insn) { | ||
| 64 | R2P(*this, insn, GetCbuf(insn)); | ||
| 65 | } | ||
| 66 | |||
| 67 | void TranslatorVisitor::R2P_imm(u64 insn) { | ||
| 68 | R2P(*this, insn, GetImm20(insn)); | ||
| 69 | } | ||
| 70 | |||
| 71 | } // 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 2ab90d1bf..fc6030e04 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp | |||
| @@ -513,18 +513,6 @@ void TranslatorVisitor::R2B(u64) { | |||
| 513 | ThrowNotImplemented(Opcode::R2B); | 513 | ThrowNotImplemented(Opcode::R2B); |
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | void TranslatorVisitor::R2P_reg(u64) { | ||
| 517 | ThrowNotImplemented(Opcode::R2P_reg); | ||
| 518 | } | ||
| 519 | |||
| 520 | void TranslatorVisitor::R2P_cbuf(u64) { | ||
| 521 | ThrowNotImplemented(Opcode::R2P_cbuf); | ||
| 522 | } | ||
| 523 | |||
| 524 | void TranslatorVisitor::R2P_imm(u64) { | ||
| 525 | ThrowNotImplemented(Opcode::R2P_imm); | ||
| 526 | } | ||
| 527 | |||
| 528 | void TranslatorVisitor::RAM(u64) { | 516 | void TranslatorVisitor::RAM(u64) { |
| 529 | ThrowNotImplemented(Opcode::RAM); | 517 | ThrowNotImplemented(Opcode::RAM); |
| 530 | } | 518 | } |