diff options
| author | 2021-03-25 11:31:37 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:24 -0400 | |
| commit | 32c5483beb2f79f5d55eb2906f2bfdfa1698bca3 (patch) | |
| tree | bca00dad85f6823746aee66f43dc0cbe2f337481 /src/shader_recompiler/frontend | |
| parent | shader: Track first bindless argument instead of the instruction itself (diff) | |
| download | yuzu-32c5483beb2f79f5d55eb2906f2bfdfa1698bca3.tar.gz yuzu-32c5483beb2f79f5d55eb2906f2bfdfa1698bca3.tar.xz yuzu-32c5483beb2f79f5d55eb2906f2bfdfa1698bca3.zip | |
shader: Implement SHFL
Diffstat (limited to '')
8 files changed, 124 insertions, 8 deletions
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index 6280c08f6..418b7f5ac 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -374,6 +374,10 @@ U1 IREmitter::GetSparseFromOp(const Value& op) { | |||
| 374 | return Inst<U1>(Opcode::GetSparseFromOp, op); | 374 | return Inst<U1>(Opcode::GetSparseFromOp, op); |
| 375 | } | 375 | } |
| 376 | 376 | ||
| 377 | U1 IREmitter::GetInBoundsFromOp(const Value& op) { | ||
| 378 | return Inst<U1>(Opcode::GetInBoundsFromOp, op); | ||
| 379 | } | ||
| 380 | |||
| 377 | F16F32F64 IREmitter::FPAdd(const F16F32F64& a, const F16F32F64& b, FpControl control) { | 381 | F16F32F64 IREmitter::FPAdd(const F16F32F64& a, const F16F32F64& b, FpControl control) { |
| 378 | if (a.Type() != b.Type()) { | 382 | if (a.Type() != b.Type()) { |
| 379 | throw InvalidArgument("Mismatching types {} and {}", a.Type(), b.Type()); | 383 | throw InvalidArgument("Mismatching types {} and {}", a.Type(), b.Type()); |
| @@ -1486,4 +1490,23 @@ U32 IREmitter::SubgroupBallot(const U1& value) { | |||
| 1486 | return Inst<U32>(Opcode::SubgroupBallot, value); | 1490 | return Inst<U32>(Opcode::SubgroupBallot, value); |
| 1487 | } | 1491 | } |
| 1488 | 1492 | ||
| 1493 | U32 IREmitter::ShuffleIndex(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 1494 | const IR::U32& seg_mask) { | ||
| 1495 | return Inst<U32>(Opcode::ShuffleIndex, value, index, clamp, seg_mask); | ||
| 1496 | } | ||
| 1497 | |||
| 1498 | U32 IREmitter::ShuffleUp(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 1499 | const IR::U32& seg_mask) { | ||
| 1500 | return Inst<U32>(Opcode::ShuffleUp, value, index, clamp, seg_mask); | ||
| 1501 | } | ||
| 1502 | |||
| 1503 | U32 IREmitter::ShuffleDown(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 1504 | const IR::U32& seg_mask) { | ||
| 1505 | return Inst<U32>(Opcode::ShuffleDown, value, index, clamp, seg_mask); | ||
| 1506 | } | ||
| 1507 | |||
| 1508 | U32 IREmitter::ShuffleButterfly(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 1509 | const IR::U32& seg_mask) { | ||
| 1510 | return Inst<U32>(Opcode::ShuffleButterfly, value, index, clamp, seg_mask); | ||
| 1511 | } | ||
| 1489 | } // namespace Shader::IR | 1512 | } // namespace Shader::IR |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index ebbda78a9..64738735e 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h | |||
| @@ -104,6 +104,7 @@ public: | |||
| 104 | [[nodiscard]] U1 GetCarryFromOp(const Value& op); | 104 | [[nodiscard]] U1 GetCarryFromOp(const Value& op); |
| 105 | [[nodiscard]] U1 GetOverflowFromOp(const Value& op); | 105 | [[nodiscard]] U1 GetOverflowFromOp(const Value& op); |
| 106 | [[nodiscard]] U1 GetSparseFromOp(const Value& op); | 106 | [[nodiscard]] U1 GetSparseFromOp(const Value& op); |
| 107 | [[nodiscard]] U1 GetInBoundsFromOp(const Value& op); | ||
| 107 | 108 | ||
| 108 | [[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2); | 109 | [[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2); |
| 109 | [[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2, const Value& e3); | 110 | [[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2, const Value& e3); |
| @@ -147,7 +148,8 @@ public: | |||
| 147 | [[nodiscard]] F32F64 FPRecipSqrt(const F32F64& value); | 148 | [[nodiscard]] F32F64 FPRecipSqrt(const F32F64& value); |
| 148 | [[nodiscard]] F32 FPSqrt(const F32& value); | 149 | [[nodiscard]] F32 FPSqrt(const F32& value); |
| 149 | [[nodiscard]] F16F32F64 FPSaturate(const F16F32F64& value); | 150 | [[nodiscard]] F16F32F64 FPSaturate(const F16F32F64& value); |
| 150 | [[nodiscard]] F16F32F64 FPClamp(const F16F32F64& value, const F16F32F64& min_value, const F16F32F64& max_value); | 151 | [[nodiscard]] F16F32F64 FPClamp(const F16F32F64& value, const F16F32F64& min_value, |
| 152 | const F16F32F64& max_value); | ||
| 151 | [[nodiscard]] F16F32F64 FPRoundEven(const F16F32F64& value, FpControl control = {}); | 153 | [[nodiscard]] F16F32F64 FPRoundEven(const F16F32F64& value, FpControl control = {}); |
| 152 | [[nodiscard]] F16F32F64 FPFloor(const F16F32F64& value, FpControl control = {}); | 154 | [[nodiscard]] F16F32F64 FPFloor(const F16F32F64& value, FpControl control = {}); |
| 153 | [[nodiscard]] F16F32F64 FPCeil(const F16F32F64& value, FpControl control = {}); | 155 | [[nodiscard]] F16F32F64 FPCeil(const F16F32F64& value, FpControl control = {}); |
| @@ -242,6 +244,14 @@ public: | |||
| 242 | [[nodiscard]] U1 VoteAny(const U1& value); | 244 | [[nodiscard]] U1 VoteAny(const U1& value); |
| 243 | [[nodiscard]] U1 VoteEqual(const U1& value); | 245 | [[nodiscard]] U1 VoteEqual(const U1& value); |
| 244 | [[nodiscard]] U32 SubgroupBallot(const U1& value); | 246 | [[nodiscard]] U32 SubgroupBallot(const U1& value); |
| 247 | [[nodiscard]] U32 ShuffleIndex(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 248 | const IR::U32& seg_mask); | ||
| 249 | [[nodiscard]] U32 ShuffleUp(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 250 | const IR::U32& seg_mask); | ||
| 251 | [[nodiscard]] U32 ShuffleDown(const IR::U32& value, const IR::U32& index, const IR::U32& clamp, | ||
| 252 | const IR::U32& seg_mask); | ||
| 253 | [[nodiscard]] U32 ShuffleButterfly(const IR::U32& value, const IR::U32& index, | ||
| 254 | const IR::U32& clamp, const IR::U32& seg_mask); | ||
| 245 | 255 | ||
| 246 | private: | 256 | private: |
| 247 | IR::Block::iterator insertion_point; | 257 | IR::Block::iterator insertion_point; |
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp index ba3968056..be8eb4d4c 100644 --- a/src/shader_recompiler/frontend/ir/microinstruction.cpp +++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp | |||
| @@ -89,6 +89,7 @@ bool Inst::IsPseudoInstruction() const noexcept { | |||
| 89 | case Opcode::GetCarryFromOp: | 89 | case Opcode::GetCarryFromOp: |
| 90 | case Opcode::GetOverflowFromOp: | 90 | case Opcode::GetOverflowFromOp: |
| 91 | case Opcode::GetSparseFromOp: | 91 | case Opcode::GetSparseFromOp: |
| 92 | case Opcode::GetInBoundsFromOp: | ||
| 92 | return true; | 93 | return true; |
| 93 | default: | 94 | default: |
| 94 | return false; | 95 | return false; |
| @@ -123,6 +124,9 @@ Inst* Inst::GetAssociatedPseudoOperation(IR::Opcode opcode) { | |||
| 123 | case Opcode::GetSparseFromOp: | 124 | case Opcode::GetSparseFromOp: |
| 124 | CheckPseudoInstruction(associated_insts->sparse_inst, Opcode::GetSparseFromOp); | 125 | CheckPseudoInstruction(associated_insts->sparse_inst, Opcode::GetSparseFromOp); |
| 125 | return associated_insts->sparse_inst; | 126 | return associated_insts->sparse_inst; |
| 127 | case Opcode::GetInBoundsFromOp: | ||
| 128 | CheckPseudoInstruction(associated_insts->in_bounds_inst, Opcode::GetInBoundsFromOp); | ||
| 129 | return associated_insts->in_bounds_inst; | ||
| 126 | default: | 130 | default: |
| 127 | throw InvalidArgument("{} is not a pseudo-instruction", opcode); | 131 | throw InvalidArgument("{} is not a pseudo-instruction", opcode); |
| 128 | } | 132 | } |
| @@ -262,6 +266,10 @@ void Inst::Use(const Value& value) { | |||
| 262 | AllocAssociatedInsts(assoc_inst); | 266 | AllocAssociatedInsts(assoc_inst); |
| 263 | SetPseudoInstruction(assoc_inst->sparse_inst, this); | 267 | SetPseudoInstruction(assoc_inst->sparse_inst, this); |
| 264 | break; | 268 | break; |
| 269 | case Opcode::GetInBoundsFromOp: | ||
| 270 | AllocAssociatedInsts(assoc_inst); | ||
| 271 | SetPseudoInstruction(assoc_inst->in_bounds_inst, this); | ||
| 272 | break; | ||
| 265 | default: | 273 | default: |
| 266 | break; | 274 | break; |
| 267 | } | 275 | } |
| @@ -289,6 +297,10 @@ void Inst::UndoUse(const Value& value) { | |||
| 289 | AllocAssociatedInsts(assoc_inst); | 297 | AllocAssociatedInsts(assoc_inst); |
| 290 | RemovePseudoInstruction(assoc_inst->overflow_inst, Opcode::GetOverflowFromOp); | 298 | RemovePseudoInstruction(assoc_inst->overflow_inst, Opcode::GetOverflowFromOp); |
| 291 | break; | 299 | break; |
| 300 | case Opcode::GetInBoundsFromOp: | ||
| 301 | AllocAssociatedInsts(assoc_inst); | ||
| 302 | RemovePseudoInstruction(assoc_inst->in_bounds_inst, Opcode::GetInBoundsFromOp); | ||
| 303 | break; | ||
| 292 | default: | 304 | default: |
| 293 | break; | 305 | break; |
| 294 | } | 306 | } |
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.h b/src/shader_recompiler/frontend/ir/microinstruction.h index d5336c438..770bbd550 100644 --- a/src/shader_recompiler/frontend/ir/microinstruction.h +++ b/src/shader_recompiler/frontend/ir/microinstruction.h | |||
| @@ -134,6 +134,7 @@ static_assert(sizeof(Inst) <= 128, "Inst size unintentionally increased"); | |||
| 134 | 134 | ||
| 135 | struct AssociatedInsts { | 135 | struct AssociatedInsts { |
| 136 | union { | 136 | union { |
| 137 | Inst* in_bounds_inst; | ||
| 137 | Inst* sparse_inst; | 138 | Inst* sparse_inst; |
| 138 | Inst* zero_inst{}; | 139 | Inst* zero_inst{}; |
| 139 | }; | 140 | }; |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index dd17212a1..a2479c46a 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -159,6 +159,7 @@ OPCODE(GetSignFromOp, U1, Opaq | |||
| 159 | OPCODE(GetCarryFromOp, U1, Opaque, ) | 159 | OPCODE(GetCarryFromOp, U1, Opaque, ) |
| 160 | OPCODE(GetOverflowFromOp, U1, Opaque, ) | 160 | OPCODE(GetOverflowFromOp, U1, Opaque, ) |
| 161 | OPCODE(GetSparseFromOp, U1, Opaque, ) | 161 | OPCODE(GetSparseFromOp, U1, Opaque, ) |
| 162 | OPCODE(GetInBoundsFromOp, U1, Opaque, ) | ||
| 162 | 163 | ||
| 163 | // Floating-point operations | 164 | // Floating-point operations |
| 164 | OPCODE(FPAbs16, F16, F16, ) | 165 | OPCODE(FPAbs16, F16, F16, ) |
| @@ -363,8 +364,12 @@ OPCODE(ImageSampleExplicitLod, F32x4, U32, | |||
| 363 | OPCODE(ImageSampleDrefImplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, ) | 364 | OPCODE(ImageSampleDrefImplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, ) |
| 364 | OPCODE(ImageSampleDrefExplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, ) | 365 | OPCODE(ImageSampleDrefExplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, ) |
| 365 | 366 | ||
| 366 | // Vote operations | 367 | // Warp operations |
| 367 | OPCODE(VoteAll, U1, U1, ) | 368 | OPCODE(VoteAll, U1, U1, ) |
| 368 | OPCODE(VoteAny, U1, U1, ) | 369 | OPCODE(VoteAny, U1, U1, ) |
| 369 | OPCODE(VoteEqual, U1, U1, ) | 370 | OPCODE(VoteEqual, U1, U1, ) |
| 370 | OPCODE(SubgroupBallot, U32, U1, ) | 371 | OPCODE(SubgroupBallot, U32, U1, ) |
| 372 | OPCODE(ShuffleIndex, U32, U32, U32, U32, U32, ) | ||
| 373 | OPCODE(ShuffleUp, U32, U32, U32, U32, U32, ) | ||
| 374 | OPCODE(ShuffleDown, U32, U32, U32, U32, U32, ) | ||
| 375 | OPCODE(ShuffleButterfly, U32, U32, U32, U32, U32, ) | ||
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_scaled_add.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_scaled_add.cpp index 5469e445a..42fd42bb1 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_scaled_add.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_scaled_add.cpp | |||
| @@ -53,8 +53,8 @@ void TranslatorVisitor::ISCADD_reg(u64 insn) { | |||
| 53 | ISCADD(*this, insn, GetReg20(insn)); | 53 | ISCADD(*this, insn, GetReg20(insn)); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | void TranslatorVisitor::ISCADD_cbuf(u64) { | 56 | void TranslatorVisitor::ISCADD_cbuf(u64 insn) { |
| 57 | throw NotImplementedException("ISCADD (cbuf)"); | 57 | ISCADD(*this, insn, GetCbuf(insn)); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | void TranslatorVisitor::ISCADD_imm(u64 insn) { | 60 | void TranslatorVisitor::ISCADD_imm(u64 insn) { |
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 c0e36a7e2..3ccd7b925 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp | |||
| @@ -301,10 +301,6 @@ void TranslatorVisitor::SETLMEMBASE(u64) { | |||
| 301 | ThrowNotImplemented(Opcode::SETLMEMBASE); | 301 | ThrowNotImplemented(Opcode::SETLMEMBASE); |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | void TranslatorVisitor::SHFL(u64) { | ||
| 305 | ThrowNotImplemented(Opcode::SHFL); | ||
| 306 | } | ||
| 307 | |||
| 308 | void TranslatorVisitor::SSY() { | 304 | void TranslatorVisitor::SSY() { |
| 309 | // SSY is a no-op | 305 | // SSY is a no-op |
| 310 | } | 306 | } |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp new file mode 100644 index 000000000..550fed55c --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/warp_shuffle.cpp | |||
| @@ -0,0 +1,69 @@ | |||
| 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 <optional> | ||
| 6 | |||
| 7 | #include "common/bit_field.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | ||
| 10 | |||
| 11 | namespace Shader::Maxwell { | ||
| 12 | namespace { | ||
| 13 | enum class ShuffleMode : u64 { | ||
| 14 | IDX, | ||
| 15 | UP, | ||
| 16 | DOWN, | ||
| 17 | BFLY, | ||
| 18 | }; | ||
| 19 | |||
| 20 | [[nodiscard]] IR::U32 ShuffleOperation(IR::IREmitter& ir, const IR::U32& value, | ||
| 21 | const IR::U32& index, const IR::U32& mask, | ||
| 22 | ShuffleMode shfl_op) { | ||
| 23 | const IR::U32 clamp{ir.BitFieldExtract(mask, ir.Imm32(0), ir.Imm32(5))}; | ||
| 24 | const IR::U32 seg_mask{ir.BitFieldExtract(mask, ir.Imm32(8), ir.Imm32(5))}; | ||
| 25 | switch (shfl_op) { | ||
| 26 | case ShuffleMode::IDX: | ||
| 27 | return ir.ShuffleIndex(value, index, clamp, seg_mask); | ||
| 28 | case ShuffleMode::UP: | ||
| 29 | return ir.ShuffleUp(value, index, clamp, seg_mask); | ||
| 30 | case ShuffleMode::DOWN: | ||
| 31 | return ir.ShuffleDown(value, index, clamp, seg_mask); | ||
| 32 | case ShuffleMode::BFLY: | ||
| 33 | return ir.ShuffleButterfly(value, index, clamp, seg_mask); | ||
| 34 | default: | ||
| 35 | throw NotImplementedException("Invalid SHFL op {}", shfl_op); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | void Shuffle(TranslatorVisitor& v, u64 insn, const IR::U32& index, const IR::U32& mask) { | ||
| 40 | union { | ||
| 41 | u64 insn; | ||
| 42 | BitField<0, 8, IR::Reg> dest_reg; | ||
| 43 | BitField<8, 8, IR::Reg> src_reg; | ||
| 44 | BitField<30, 2, ShuffleMode> mode; | ||
| 45 | BitField<48, 3, IR::Pred> pred; | ||
| 46 | } const shfl{insn}; | ||
| 47 | |||
| 48 | const IR::U32 result{ShuffleOperation(v.ir, v.X(shfl.src_reg), index, mask, shfl.mode)}; | ||
| 49 | v.ir.SetPred(shfl.pred, v.ir.GetInBoundsFromOp(result)); | ||
| 50 | v.X(shfl.dest_reg, result); | ||
| 51 | } | ||
| 52 | } // Anonymous namespace | ||
| 53 | |||
| 54 | void TranslatorVisitor::SHFL(u64 insn) { | ||
| 55 | union { | ||
| 56 | u64 insn; | ||
| 57 | BitField<20, 5, u64> src_a_imm; | ||
| 58 | BitField<28, 1, u64> src_a_flag; | ||
| 59 | BitField<29, 1, u64> src_b_flag; | ||
| 60 | BitField<34, 13, u64> src_b_imm; | ||
| 61 | } const flags{insn}; | ||
| 62 | const IR::U32 src_a{flags.src_a_flag != 0 ? ir.Imm32(static_cast<u32>(flags.src_a_imm)) | ||
| 63 | : GetReg20(insn)}; | ||
| 64 | const IR::U32 src_b{flags.src_b_flag != 0 ? ir.Imm32(static_cast<u32>(flags.src_b_imm)) | ||
| 65 | : GetReg39(insn)}; | ||
| 66 | Shuffle(*this, insn, src_a, src_b); | ||
| 67 | } | ||
| 68 | |||
| 69 | } // namespace Shader::Maxwell | ||