diff options
Diffstat (limited to 'src/shader_recompiler/frontend')
8 files changed, 52 insertions, 19 deletions
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index b365a8a6e..f49c30484 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -398,15 +398,16 @@ Value IREmitter::CompositeConstruct(const Value& e1, const Value& e2) { | |||
| 398 | if (e1.Type() != e2.Type()) { | 398 | if (e1.Type() != e2.Type()) { |
| 399 | throw InvalidArgument("Mismatching types {} and {}", e1.Type(), e2.Type()); | 399 | throw InvalidArgument("Mismatching types {} and {}", e1.Type(), e2.Type()); |
| 400 | } | 400 | } |
| 401 | CompositeDecoration decor{}; | ||
| 401 | switch (e1.Type()) { | 402 | switch (e1.Type()) { |
| 402 | case Type::U32: | 403 | case Type::U32: |
| 403 | return Inst(Opcode::CompositeConstructU32x2, e1, e2); | 404 | return Inst(Opcode::CompositeConstructU32x2, Flags{decor}, e1, e2); |
| 404 | case Type::F16: | 405 | case Type::F16: |
| 405 | return Inst(Opcode::CompositeConstructF16x2, e1, e2); | 406 | return Inst(Opcode::CompositeConstructF16x2, Flags{decor}, e1, e2); |
| 406 | case Type::F32: | 407 | case Type::F32: |
| 407 | return Inst(Opcode::CompositeConstructF32x2, e1, e2); | 408 | return Inst(Opcode::CompositeConstructF32x2, Flags{decor}, e1, e2); |
| 408 | case Type::F64: | 409 | case Type::F64: |
| 409 | return Inst(Opcode::CompositeConstructF64x2, e1, e2); | 410 | return Inst(Opcode::CompositeConstructF64x2, Flags{decor}, e1, e2); |
| 410 | default: | 411 | default: |
| 411 | ThrowInvalidType(e1.Type()); | 412 | ThrowInvalidType(e1.Type()); |
| 412 | } | 413 | } |
| @@ -436,6 +437,7 @@ Value IREmitter::CompositeConstruct(const Value& e1, const Value& e2, const Valu | |||
| 436 | throw InvalidArgument("Mismatching types {}, {}, {}, and {}", e1.Type(), e2.Type(), | 437 | throw InvalidArgument("Mismatching types {}, {}, {}, and {}", e1.Type(), e2.Type(), |
| 437 | e3.Type(), e4.Type()); | 438 | e3.Type(), e4.Type()); |
| 438 | } | 439 | } |
| 440 | CompositeDecoration decor{}; | ||
| 439 | switch (e1.Type()) { | 441 | switch (e1.Type()) { |
| 440 | case Type::U32: | 442 | case Type::U32: |
| 441 | return Inst(Opcode::CompositeConstructU32x4, e1, e2, e3, e4); | 443 | return Inst(Opcode::CompositeConstructU32x4, e1, e2, e3, e4); |
| @@ -445,6 +447,8 @@ Value IREmitter::CompositeConstruct(const Value& e1, const Value& e2, const Valu | |||
| 445 | return Inst(Opcode::CompositeConstructF32x4, e1, e2, e3, e4); | 447 | return Inst(Opcode::CompositeConstructF32x4, e1, e2, e3, e4); |
| 446 | case Type::F64: | 448 | case Type::F64: |
| 447 | return Inst(Opcode::CompositeConstructF64x4, e1, e2, e3, e4); | 449 | return Inst(Opcode::CompositeConstructF64x4, e1, e2, e3, e4); |
| 450 | case Type::U32x2: | ||
| 451 | return Inst(Opcode::CompositeConstructArrayU32x2, Flags{decor}, e1, e2, e3, e4); | ||
| 448 | default: | 452 | default: |
| 449 | ThrowInvalidType(e1.Type()); | 453 | ThrowInvalidType(e1.Type()); |
| 450 | } | 454 | } |
| @@ -1481,7 +1485,7 @@ Value IREmitter::ImageGather(const Value& handle, const Value& coords, const Val | |||
| 1481 | } | 1485 | } |
| 1482 | 1486 | ||
| 1483 | Value IREmitter::ImageGatherDref(const Value& handle, const Value& coords, const Value& offset, | 1487 | Value IREmitter::ImageGatherDref(const Value& handle, const Value& coords, const Value& offset, |
| 1484 | const Value& offset2, const F32& dref, TextureInstInfo info) { | 1488 | const Value& offset2, const F32& dref, TextureInstInfo info) { |
| 1485 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageGatherDref | 1489 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageGatherDref |
| 1486 | : Opcode::BindlessImageGatherDref}; | 1490 | : Opcode::BindlessImageGatherDref}; |
| 1487 | return Inst(op, Flags{info}, handle, coords, offset, offset2, dref); | 1491 | return Inst(op, Flags{info}, handle, coords, offset, offset2, dref); |
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.h b/src/shader_recompiler/frontend/ir/microinstruction.h index 770bbd550..77296cfa4 100644 --- a/src/shader_recompiler/frontend/ir/microinstruction.h +++ b/src/shader_recompiler/frontend/ir/microinstruction.h | |||
| @@ -99,6 +99,12 @@ public: | |||
| 99 | return ret; | 99 | return ret; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | template <typename FlagsType> | ||
| 103 | requires(sizeof(FlagsType) <= sizeof(u32) && std::is_trivially_copyable_v<FlagsType>) | ||
| 104 | [[nodiscard]] void SetFlags(FlagsType& new_val) noexcept { | ||
| 105 | std::memcpy(&flags, &new_val, sizeof(new_val)); | ||
| 106 | } | ||
| 107 | |||
| 102 | /// Intrusively store the host definition of this instruction. | 108 | /// Intrusively store the host definition of this instruction. |
| 103 | template <typename DefinitionType> | 109 | template <typename DefinitionType> |
| 104 | void SetDefinition(DefinitionType def) { | 110 | void SetDefinition(DefinitionType def) { |
diff --git a/src/shader_recompiler/frontend/ir/modifiers.h b/src/shader_recompiler/frontend/ir/modifiers.h index 4f09a4b39..20fb14fea 100644 --- a/src/shader_recompiler/frontend/ir/modifiers.h +++ b/src/shader_recompiler/frontend/ir/modifiers.h | |||
| @@ -32,6 +32,11 @@ struct FpControl { | |||
| 32 | }; | 32 | }; |
| 33 | static_assert(sizeof(FpControl) <= sizeof(u32)); | 33 | static_assert(sizeof(FpControl) <= sizeof(u32)); |
| 34 | 34 | ||
| 35 | struct CompositeDecoration { | ||
| 36 | bool is_constant{false}; | ||
| 37 | }; | ||
| 38 | static_assert(sizeof(CompositeDecoration) <= sizeof(u32)); | ||
| 39 | |||
| 35 | union TextureInstInfo { | 40 | union TextureInstInfo { |
| 36 | u32 raw; | 41 | u32 raw; |
| 37 | BitField<0, 8, TextureType> type; | 42 | BitField<0, 8, TextureType> type; |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index 60a0bc980..0dc0aabdf 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -126,6 +126,7 @@ OPCODE(CompositeExtractF64x4, F64, F64x | |||
| 126 | OPCODE(CompositeInsertF64x2, F64x2, F64x2, F64, U32, ) | 126 | OPCODE(CompositeInsertF64x2, F64x2, F64x2, F64, U32, ) |
| 127 | OPCODE(CompositeInsertF64x3, F64x3, F64x3, F64, U32, ) | 127 | OPCODE(CompositeInsertF64x3, F64x3, F64x3, F64, U32, ) |
| 128 | OPCODE(CompositeInsertF64x4, F64x4, F64x4, F64, U32, ) | 128 | OPCODE(CompositeInsertF64x4, F64x4, F64x4, F64, U32, ) |
| 129 | OPCODE(CompositeConstructArrayU32x2, Opaque, U32x2, U32x2, U32x2, U32x2, ) | ||
| 129 | 130 | ||
| 130 | // Select operations | 131 | // Select operations |
| 131 | OPCODE(SelectU1, U1, U1, U1, U1, ) | 132 | OPCODE(SelectU1, U1, U1, U1, U1, ) |
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp index e8e4662e7..7671fc3d8 100644 --- a/src/shader_recompiler/frontend/ir/value.cpp +++ b/src/shader_recompiler/frontend/ir/value.cpp | |||
| @@ -44,6 +44,20 @@ bool Value::IsEmpty() const noexcept { | |||
| 44 | return type == Type::Void; | 44 | return type == Type::Void; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | bool Value::IsConstantContainer() const { | ||
| 48 | if (IsImmediate()) { | ||
| 49 | return true; | ||
| 50 | } | ||
| 51 | ValidateAccess(Type::Opaque); | ||
| 52 | auto num_args = inst->NumArgs(); | ||
| 53 | for (size_t i = 0; i < num_args; i++) { | ||
| 54 | if (!inst->Arg(i).IsConstantContainer()) { | ||
| 55 | return false; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | |||
| 47 | bool Value::IsImmediate() const noexcept { | 61 | bool Value::IsImmediate() const noexcept { |
| 48 | if (IsIdentity()) { | 62 | if (IsIdentity()) { |
| 49 | return inst->Arg(0).IsImmediate(); | 63 | return inst->Arg(0).IsImmediate(); |
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h index b27601e70..5d6e74c14 100644 --- a/src/shader_recompiler/frontend/ir/value.h +++ b/src/shader_recompiler/frontend/ir/value.h | |||
| @@ -38,6 +38,7 @@ public: | |||
| 38 | [[nodiscard]] bool IsImmediate() const noexcept; | 38 | [[nodiscard]] bool IsImmediate() const noexcept; |
| 39 | [[nodiscard]] bool IsLabel() const noexcept; | 39 | [[nodiscard]] bool IsLabel() const noexcept; |
| 40 | [[nodiscard]] IR::Type Type() const noexcept; | 40 | [[nodiscard]] IR::Type Type() const noexcept; |
| 41 | [[nodiscard]] bool IsConstantContainer() const; | ||
| 41 | 42 | ||
| 42 | [[nodiscard]] IR::Inst* Inst() const; | 43 | [[nodiscard]] IR::Inst* Inst() const; |
| 43 | [[nodiscard]] IR::Block* Label() const; | 44 | [[nodiscard]] IR::Block* Label() const; |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch.cpp index 1f1689c43..b2da079f9 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch.cpp | |||
| @@ -101,16 +101,18 @@ IR::Value MakeOffset(TranslatorVisitor& v, IR::Reg& reg, TextureType type) { | |||
| 101 | switch (type) { | 101 | switch (type) { |
| 102 | case TextureType::_1D: | 102 | case TextureType::_1D: |
| 103 | case TextureType::ARRAY_1D: | 103 | case TextureType::ARRAY_1D: |
| 104 | return v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(4)); | 104 | return v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(4), true); |
| 105 | case TextureType::_2D: | 105 | case TextureType::_2D: |
| 106 | case TextureType::ARRAY_2D: | 106 | case TextureType::ARRAY_2D: |
| 107 | return v.ir.CompositeConstruct(v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(4)), | 107 | return v.ir.CompositeConstruct( |
| 108 | v.ir.BitFieldExtract(value, v.ir.Imm32(4), v.ir.Imm32(4))); | 108 | v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(4), true), |
| 109 | v.ir.BitFieldExtract(value, v.ir.Imm32(4), v.ir.Imm32(4), true)); | ||
| 109 | case TextureType::_3D: | 110 | case TextureType::_3D: |
| 110 | case TextureType::ARRAY_3D: | 111 | case TextureType::ARRAY_3D: |
| 111 | return v.ir.CompositeConstruct(v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(4)), | 112 | return v.ir.CompositeConstruct( |
| 112 | v.ir.BitFieldExtract(value, v.ir.Imm32(4), v.ir.Imm32(4)), | 113 | v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(4), true), |
| 113 | v.ir.BitFieldExtract(value, v.ir.Imm32(8), v.ir.Imm32(4))); | 114 | v.ir.BitFieldExtract(value, v.ir.Imm32(4), v.ir.Imm32(4), true), |
| 115 | v.ir.BitFieldExtract(value, v.ir.Imm32(8), v.ir.Imm32(4), true)); | ||
| 114 | case TextureType::CUBE: | 116 | case TextureType::CUBE: |
| 115 | case TextureType::ARRAY_CUBE: | 117 | case TextureType::ARRAY_CUBE: |
| 116 | throw NotImplementedException("Illegal offset on CUBE sample"); | 118 | throw NotImplementedException("Illegal offset on CUBE sample"); |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp index 8c6384040..cdf5cb5c4 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gather.cpp | |||
| @@ -106,17 +106,17 @@ IR::Value MakeOffset(TranslatorVisitor& v, IR::Reg& reg, TextureType type) { | |||
| 106 | throw NotImplementedException("Invalid texture type {}", type); | 106 | throw NotImplementedException("Invalid texture type {}", type); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | std::pair<IR::Value, IR::Value> MakeOffsetPTP(TranslatorVisitor& v, IR::Reg& reg) { | 109 | IR::Value MakeOffsetPTP(TranslatorVisitor& v, IR::Reg& reg) { |
| 110 | const IR::U32 value1{v.X(reg++)}; | 110 | const IR::U32 value1{v.X(reg++)}; |
| 111 | const IR::U32 value2{v.X(reg++)}; | 111 | const IR::U32 value2{v.X(reg++)}; |
| 112 | const auto getVector = ([&v](const IR::U32& value) { | 112 | const IR::U32 bitsize = v.ir.Imm32(6); |
| 113 | const auto getVector = ([&v, &bitsize](const IR::U32& value, u32 base) { | ||
| 113 | return v.ir.CompositeConstruct( | 114 | return v.ir.CompositeConstruct( |
| 114 | v.ir.BitFieldExtract(value, v.ir.Imm32(0), v.ir.Imm32(6), true), | 115 | v.ir.BitFieldExtract(value, v.ir.Imm32(base + 0), bitsize, true), |
| 115 | v.ir.BitFieldExtract(value, v.ir.Imm32(8), v.ir.Imm32(6), true), | 116 | v.ir.BitFieldExtract(value, v.ir.Imm32(base + 8), bitsize, true)); |
| 116 | v.ir.BitFieldExtract(value, v.ir.Imm32(16), v.ir.Imm32(6), true), | ||
| 117 | v.ir.BitFieldExtract(value, v.ir.Imm32(24), v.ir.Imm32(6), true)); | ||
| 118 | }); | 117 | }); |
| 119 | return {getVector(value1), getVector(value2)}; | 118 | return v.ir.CompositeConstruct(getVector(value1, 0), getVector(value1, 16), |
| 119 | getVector(value2, 0), getVector(value2, 16)); | ||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | void Impl(TranslatorVisitor& v, u64 insn, ComponentType component_type, OffsetType offset_type, | 122 | void Impl(TranslatorVisitor& v, u64 insn, ComponentType component_type, OffsetType offset_type, |
| @@ -155,7 +155,7 @@ void Impl(TranslatorVisitor& v, u64 insn, ComponentType component_type, OffsetTy | |||
| 155 | break; | 155 | break; |
| 156 | } | 156 | } |
| 157 | case OffsetType::PTP: { | 157 | case OffsetType::PTP: { |
| 158 | std::tie(offset, offset2) = MakeOffsetPTP(v, meta_reg); | 158 | offset2 = MakeOffsetPTP(v, meta_reg); |
| 159 | break; | 159 | break; |
| 160 | } | 160 | } |
| 161 | default: | 161 | default: |