diff options
Diffstat (limited to 'src/shader_recompiler')
15 files changed, 115 insertions, 16 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp index 2fc2a0ac6..5bfdecc09 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp | |||
| @@ -43,6 +43,10 @@ void EmitBitCastU64F64(EmitContext&, IR::Inst& inst, const IR::Value& value) { | |||
| 43 | Alias(inst, value); | 43 | Alias(inst, value); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | void EmitBitCastS32F32(EmitContext&, IR::Inst& inst, const IR::Value& value) { | ||
| 47 | Alias(inst, value); | ||
| 48 | } | ||
| 49 | |||
| 46 | void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) { | 50 | void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) { |
| 47 | Alias(inst, value); | 51 | Alias(inst, value); |
| 48 | } | 52 | } |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h index c08f48ed9..d645fd532 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h +++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h | |||
| @@ -196,6 +196,7 @@ void EmitSelectF64(EmitContext& ctx, ScalarS32 cond, Register true_value, Regist | |||
| 196 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 196 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 197 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 197 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 198 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 198 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 199 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | ||
| 199 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 200 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 200 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 201 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 201 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 202 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp index 1be4a0f59..8e5e6cf1f 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp | |||
| @@ -48,6 +48,10 @@ void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) | |||
| 48 | ctx.AddU64("{}=doubleBitsToUint64({});", inst, value); | 48 | ctx.AddU64("{}=doubleBitsToUint64({});", inst, value); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | ||
| 52 | ctx.AddF32("{}=ftoi({});", inst, value); | ||
| 53 | } | ||
| 54 | |||
| 51 | void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { | 55 | void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { |
| 52 | NotImplemented(); | 56 | NotImplemented(); |
| 53 | } | 57 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 3c8bcb7e9..96e683b5e 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -230,6 +230,7 @@ void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond, | |||
| 230 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst); | 230 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst); |
| 231 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 231 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 232 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 232 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 233 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | ||
| 233 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst); | 234 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst); |
| 234 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 235 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 235 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 236 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp index c4ca28d11..50daacd95 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp | |||
| @@ -18,6 +18,10 @@ void EmitBitCastU64F64(EmitContext&) { | |||
| 18 | throw NotImplementedException("SPIR-V Instruction"); | 18 | throw NotImplementedException("SPIR-V Instruction"); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | void EmitBitCastS32F32(EmitContext&) { | ||
| 22 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 23 | } | ||
| 24 | |||
| 21 | void EmitBitCastF16U16(EmitContext&) { | 25 | void EmitBitCastF16U16(EmitContext&) { |
| 22 | throw NotImplementedException("SPIR-V Instruction"); | 26 | throw NotImplementedException("SPIR-V Instruction"); |
| 23 | } | 27 | } |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index 86dd3c4f3..7070c8fda 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h | |||
| @@ -178,7 +178,8 @@ Id EmitSelectF64(EmitContext& ctx, Id cond, Id true_value, Id false_value); | |||
| 178 | void EmitBitCastU16F16(EmitContext& ctx); | 178 | void EmitBitCastU16F16(EmitContext& ctx); |
| 179 | Id EmitBitCastU32F32(EmitContext& ctx, Id value); | 179 | Id EmitBitCastU32F32(EmitContext& ctx, Id value); |
| 180 | void EmitBitCastU64F64(EmitContext& ctx); | 180 | void EmitBitCastU64F64(EmitContext& ctx); |
| 181 | void EmitBitCastF16U16(EmitContext& ctx); | 181 | void EmitBitCastS32F32(EmitContext& ctx); |
| 182 | void EmitBitCastF16U16(EmitContext&); | ||
| 182 | Id EmitBitCastF32U32(EmitContext& ctx, Id value); | 183 | Id EmitBitCastF32U32(EmitContext& ctx, Id value); |
| 183 | void EmitBitCastF64U64(EmitContext& ctx); | 184 | void EmitBitCastF64U64(EmitContext& ctx); |
| 184 | Id EmitPackUint2x32(EmitContext& ctx, Id value); | 185 | Id EmitPackUint2x32(EmitContext& ctx, Id value); |
diff --git a/src/shader_recompiler/environment.h b/src/shader_recompiler/environment.h index 980e0e54c..402f2664f 100644 --- a/src/shader_recompiler/environment.h +++ b/src/shader_recompiler/environment.h | |||
| @@ -22,6 +22,8 @@ public: | |||
| 22 | 22 | ||
| 23 | [[nodiscard]] virtual TextureType ReadTextureType(u32 raw_handle) = 0; | 23 | [[nodiscard]] virtual TextureType ReadTextureType(u32 raw_handle) = 0; |
| 24 | 24 | ||
| 25 | [[nodiscard]] virtual TexturePixelFormat ReadTexturePixelFormat(u32 raw_handle) = 0; | ||
| 26 | |||
| 25 | [[nodiscard]] virtual u32 ReadViewportTransformState() = 0; | 27 | [[nodiscard]] virtual u32 ReadViewportTransformState() = 0; |
| 26 | 28 | ||
| 27 | [[nodiscard]] virtual u32 TextureBoundBuffer() const = 0; | 29 | [[nodiscard]] virtual u32 TextureBoundBuffer() const = 0; |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index de1ce90a3..d4425f06d 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -692,6 +692,11 @@ IR::U32 IREmitter::BitCast<IR::U32, IR::F32>(const IR::F32& value) { | |||
| 692 | } | 692 | } |
| 693 | 693 | ||
| 694 | template <> | 694 | template <> |
| 695 | IR::S32 IREmitter::BitCast<IR::S32, IR::F32>(const IR::F32& value) { | ||
| 696 | return Inst<IR::S32>(Opcode::BitCastS32F32, value); | ||
| 697 | } | ||
| 698 | |||
| 699 | template <> | ||
| 695 | IR::F32 IREmitter::BitCast<IR::F32, IR::U32>(const IR::U32& value) { | 700 | IR::F32 IREmitter::BitCast<IR::F32, IR::U32>(const IR::U32& value) { |
| 696 | return Inst<IR::F32>(Opcode::BitCastF32U32, value); | 701 | return Inst<IR::F32>(Opcode::BitCastF32U32, value); |
| 697 | } | 702 | } |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.h b/src/shader_recompiler/frontend/ir/opcodes.h index 752879a18..e70d7745c 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.h +++ b/src/shader_recompiler/frontend/ir/opcodes.h | |||
| @@ -37,6 +37,7 @@ constexpr Type U8{Type::U8}; | |||
| 37 | constexpr Type U16{Type::U16}; | 37 | constexpr Type U16{Type::U16}; |
| 38 | constexpr Type U32{Type::U32}; | 38 | constexpr Type U32{Type::U32}; |
| 39 | constexpr Type U64{Type::U64}; | 39 | constexpr Type U64{Type::U64}; |
| 40 | constexpr Type S32{Type::S32}; | ||
| 40 | constexpr Type F16{Type::F16}; | 41 | constexpr Type F16{Type::F16}; |
| 41 | constexpr Type F32{Type::F32}; | 42 | constexpr Type F32{Type::F32}; |
| 42 | constexpr Type F64{Type::F64}; | 43 | constexpr Type F64{Type::F64}; |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index f3038f298..88aa077ee 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -174,6 +174,7 @@ OPCODE(SelectF64, F64, U1, | |||
| 174 | OPCODE(BitCastU16F16, U16, F16, ) | 174 | OPCODE(BitCastU16F16, U16, F16, ) |
| 175 | OPCODE(BitCastU32F32, U32, F32, ) | 175 | OPCODE(BitCastU32F32, U32, F32, ) |
| 176 | OPCODE(BitCastU64F64, U64, F64, ) | 176 | OPCODE(BitCastU64F64, U64, F64, ) |
| 177 | OPCODE(BitCastS32F32, S32, F32, ) | ||
| 177 | OPCODE(BitCastF16U16, F16, U16, ) | 178 | OPCODE(BitCastF16U16, F16, U16, ) |
| 178 | OPCODE(BitCastF32U32, F32, U32, ) | 179 | OPCODE(BitCastF32U32, F32, U32, ) |
| 179 | OPCODE(BitCastF64U64, F64, U64, ) | 180 | OPCODE(BitCastF64U64, F64, U64, ) |
diff --git a/src/shader_recompiler/frontend/ir/type.h b/src/shader_recompiler/frontend/ir/type.h index 04c8c4ddb..5a7c706ad 100644 --- a/src/shader_recompiler/frontend/ir/type.h +++ b/src/shader_recompiler/frontend/ir/type.h | |||
| @@ -24,21 +24,22 @@ enum class Type { | |||
| 24 | U16 = 1 << 7, | 24 | U16 = 1 << 7, |
| 25 | U32 = 1 << 8, | 25 | U32 = 1 << 8, |
| 26 | U64 = 1 << 9, | 26 | U64 = 1 << 9, |
| 27 | F16 = 1 << 10, | 27 | S32 = 1 << 10, |
| 28 | F32 = 1 << 11, | 28 | F16 = 1 << 11, |
| 29 | F64 = 1 << 12, | 29 | F32 = 1 << 12, |
| 30 | U32x2 = 1 << 13, | 30 | F64 = 1 << 13, |
| 31 | U32x3 = 1 << 14, | 31 | U32x2 = 1 << 14, |
| 32 | U32x4 = 1 << 15, | 32 | U32x3 = 1 << 15, |
| 33 | F16x2 = 1 << 16, | 33 | U32x4 = 1 << 16, |
| 34 | F16x3 = 1 << 17, | 34 | F16x2 = 1 << 17, |
| 35 | F16x4 = 1 << 18, | 35 | F16x3 = 1 << 18, |
| 36 | F32x2 = 1 << 19, | 36 | F16x4 = 1 << 19, |
| 37 | F32x3 = 1 << 20, | 37 | F32x2 = 1 << 20, |
| 38 | F32x4 = 1 << 21, | 38 | F32x3 = 1 << 21, |
| 39 | F64x2 = 1 << 22, | 39 | F32x4 = 1 << 22, |
| 40 | F64x3 = 1 << 23, | 40 | F64x2 = 1 << 23, |
| 41 | F64x4 = 1 << 24, | 41 | F64x3 = 1 << 24, |
| 42 | F64x4 = 1 << 25, | ||
| 42 | }; | 43 | }; |
| 43 | DECLARE_ENUM_FLAG_OPERATORS(Type) | 44 | DECLARE_ENUM_FLAG_OPERATORS(Type) |
| 44 | 45 | ||
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp index 346169328..30ba12316 100644 --- a/src/shader_recompiler/frontend/ir/value.cpp +++ b/src/shader_recompiler/frontend/ir/value.cpp | |||
| @@ -23,6 +23,8 @@ Value::Value(u16 value) noexcept : type{Type::U16}, imm_u16{value} {} | |||
| 23 | 23 | ||
| 24 | Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {} | 24 | Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {} |
| 25 | 25 | ||
| 26 | Value::Value(s32 value) noexcept : type{Type::S32}, imm_s32{value} {} | ||
| 27 | |||
| 26 | Value::Value(f32 value) noexcept : type{Type::F32}, imm_f32{value} {} | 28 | Value::Value(f32 value) noexcept : type{Type::F32}, imm_f32{value} {} |
| 27 | 29 | ||
| 28 | Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {} | 30 | Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {} |
| @@ -69,6 +71,7 @@ bool Value::operator==(const Value& other) const { | |||
| 69 | return imm_u16 == other.imm_u16; | 71 | return imm_u16 == other.imm_u16; |
| 70 | case Type::U32: | 72 | case Type::U32: |
| 71 | case Type::F32: | 73 | case Type::F32: |
| 74 | case Type::S32: | ||
| 72 | return imm_u32 == other.imm_u32; | 75 | return imm_u32 == other.imm_u32; |
| 73 | case Type::U64: | 76 | case Type::U64: |
| 74 | case Type::F64: | 77 | case Type::F64: |
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h index 6a673ca05..e8bbb93a5 100644 --- a/src/shader_recompiler/frontend/ir/value.h +++ b/src/shader_recompiler/frontend/ir/value.h | |||
| @@ -44,6 +44,7 @@ public: | |||
| 44 | explicit Value(u8 value) noexcept; | 44 | explicit Value(u8 value) noexcept; |
| 45 | explicit Value(u16 value) noexcept; | 45 | explicit Value(u16 value) noexcept; |
| 46 | explicit Value(u32 value) noexcept; | 46 | explicit Value(u32 value) noexcept; |
| 47 | explicit Value(s32 value) noexcept; | ||
| 47 | explicit Value(f32 value) noexcept; | 48 | explicit Value(f32 value) noexcept; |
| 48 | explicit Value(u64 value) noexcept; | 49 | explicit Value(u64 value) noexcept; |
| 49 | explicit Value(f64 value) noexcept; | 50 | explicit Value(f64 value) noexcept; |
| @@ -66,6 +67,7 @@ public: | |||
| 66 | [[nodiscard]] u8 U8() const; | 67 | [[nodiscard]] u8 U8() const; |
| 67 | [[nodiscard]] u16 U16() const; | 68 | [[nodiscard]] u16 U16() const; |
| 68 | [[nodiscard]] u32 U32() const; | 69 | [[nodiscard]] u32 U32() const; |
| 70 | [[nodiscard]] s32 S32() const; | ||
| 69 | [[nodiscard]] f32 F32() const; | 71 | [[nodiscard]] f32 F32() const; |
| 70 | [[nodiscard]] u64 U64() const; | 72 | [[nodiscard]] u64 U64() const; |
| 71 | [[nodiscard]] f64 F64() const; | 73 | [[nodiscard]] f64 F64() const; |
| @@ -85,6 +87,7 @@ private: | |||
| 85 | u8 imm_u8; | 87 | u8 imm_u8; |
| 86 | u16 imm_u16; | 88 | u16 imm_u16; |
| 87 | u32 imm_u32; | 89 | u32 imm_u32; |
| 90 | s32 imm_s32; | ||
| 88 | f32 imm_f32; | 91 | f32 imm_f32; |
| 89 | u64 imm_u64; | 92 | u64 imm_u64; |
| 90 | f64 imm_f64; | 93 | f64 imm_f64; |
| @@ -266,6 +269,7 @@ using U8 = TypedValue<Type::U8>; | |||
| 266 | using U16 = TypedValue<Type::U16>; | 269 | using U16 = TypedValue<Type::U16>; |
| 267 | using U32 = TypedValue<Type::U32>; | 270 | using U32 = TypedValue<Type::U32>; |
| 268 | using U64 = TypedValue<Type::U64>; | 271 | using U64 = TypedValue<Type::U64>; |
| 272 | using S32 = TypedValue<Type::S32>; | ||
| 269 | using F16 = TypedValue<Type::F16>; | 273 | using F16 = TypedValue<Type::F16>; |
| 270 | using F32 = TypedValue<Type::F32>; | 274 | using F32 = TypedValue<Type::F32>; |
| 271 | using F64 = TypedValue<Type::F64>; | 275 | using F64 = TypedValue<Type::F64>; |
| @@ -377,6 +381,14 @@ inline u32 Value::U32() const { | |||
| 377 | return imm_u32; | 381 | return imm_u32; |
| 378 | } | 382 | } |
| 379 | 383 | ||
| 384 | inline s32 Value::S32() const { | ||
| 385 | if (IsIdentity()) { | ||
| 386 | return inst->Arg(0).S32(); | ||
| 387 | } | ||
| 388 | DEBUG_ASSERT(type == Type::S32); | ||
| 389 | return imm_s32; | ||
| 390 | } | ||
| 391 | |||
| 380 | inline f32 Value::F32() const { | 392 | inline f32 Value::F32() const { |
| 381 | if (IsIdentity()) { | 393 | if (IsIdentity()) { |
| 382 | return inst->Arg(0).F32(); | 394 | return inst->Arg(0).F32(); |
diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp index e8be58357..9eff84a3d 100644 --- a/src/shader_recompiler/ir_opt/texture_pass.cpp +++ b/src/shader_recompiler/ir_opt/texture_pass.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include <boost/container/small_vector.hpp> | 8 | #include <boost/container/small_vector.hpp> |
| 9 | 9 | ||
| 10 | #include "common/settings.h" | ||
| 10 | #include "shader_recompiler/environment.h" | 11 | #include "shader_recompiler/environment.h" |
| 11 | #include "shader_recompiler/frontend/ir/basic_block.h" | 12 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 12 | #include "shader_recompiler/frontend/ir/breadth_first_search.h" | 13 | #include "shader_recompiler/frontend/ir/breadth_first_search.h" |
| @@ -363,6 +364,14 @@ TextureType ReadTextureType(Environment& env, const ConstBufferAddr& cbuf) { | |||
| 363 | return env.ReadTextureType(lhs_raw | rhs_raw); | 364 | return env.ReadTextureType(lhs_raw | rhs_raw); |
| 364 | } | 365 | } |
| 365 | 366 | ||
| 367 | TexturePixelFormat ReadTexturePixelFormat(Environment& env, const ConstBufferAddr& cbuf) { | ||
| 368 | const u32 secondary_index{cbuf.has_secondary ? cbuf.secondary_index : cbuf.index}; | ||
| 369 | const u32 secondary_offset{cbuf.has_secondary ? cbuf.secondary_offset : cbuf.offset}; | ||
| 370 | const u32 lhs_raw{env.ReadCbufValue(cbuf.index, cbuf.offset)}; | ||
| 371 | const u32 rhs_raw{env.ReadCbufValue(secondary_index, secondary_offset)}; | ||
| 372 | return env.ReadTexturePixelFormat(lhs_raw | rhs_raw); | ||
| 373 | } | ||
| 374 | |||
| 366 | class Descriptors { | 375 | class Descriptors { |
| 367 | public: | 376 | public: |
| 368 | explicit Descriptors(TextureBufferDescriptors& texture_buffer_descriptors_, | 377 | explicit Descriptors(TextureBufferDescriptors& texture_buffer_descriptors_, |
| @@ -451,6 +460,38 @@ void PatchImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { | |||
| 451 | ir.FPMul(IR::F32(ir.CompositeExtract(coord, 1)), | 460 | ir.FPMul(IR::F32(ir.CompositeExtract(coord, 1)), |
| 452 | ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 1)))))); | 461 | ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 1)))))); |
| 453 | } | 462 | } |
| 463 | |||
| 464 | void PathTexelFetch(IR::Block& block, IR::Inst& inst, TexturePixelFormat pixel_format) { | ||
| 465 | const auto it{IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 466 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 467 | auto get_max_value = [pixel_format]() -> float { | ||
| 468 | switch (pixel_format) { | ||
| 469 | case TexturePixelFormat::A8B8G8R8_SNORM: | ||
| 470 | case TexturePixelFormat::R8G8_SNORM: | ||
| 471 | case TexturePixelFormat::R8_SNORM: | ||
| 472 | return 1.f / std::numeric_limits<char>::max(); | ||
| 473 | case TexturePixelFormat::R16G16B16A16_SNORM: | ||
| 474 | case TexturePixelFormat::R16G16_SNORM: | ||
| 475 | case TexturePixelFormat::R16_SNORM: | ||
| 476 | return 1.f / std::numeric_limits<short>::max(); | ||
| 477 | default: | ||
| 478 | throw InvalidArgument("Invalid texture pixel format"); | ||
| 479 | } | ||
| 480 | }; | ||
| 481 | |||
| 482 | const IR::Value new_inst{&*block.PrependNewInst(it, inst)}; | ||
| 483 | const IR::F32 x(ir.CompositeExtract(new_inst, 0)); | ||
| 484 | const IR::F32 y(ir.CompositeExtract(new_inst, 1)); | ||
| 485 | const IR::F32 z(ir.CompositeExtract(new_inst, 2)); | ||
| 486 | const IR::F32 w(ir.CompositeExtract(new_inst, 3)); | ||
| 487 | const IR::F16F32F64 max_value(ir.Imm32(get_max_value())); | ||
| 488 | const IR::Value converted = | ||
| 489 | ir.CompositeConstruct(ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(x)), max_value), | ||
| 490 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(y)), max_value), | ||
| 491 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(z)), max_value), | ||
| 492 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(w)), max_value)); | ||
| 493 | inst.ReplaceUsesWith(converted); | ||
| 494 | } | ||
| 454 | } // Anonymous namespace | 495 | } // Anonymous namespace |
| 455 | 496 | ||
| 456 | void TexturePass(Environment& env, IR::Program& program) { | 497 | void TexturePass(Environment& env, IR::Program& program) { |
| @@ -597,6 +638,14 @@ void TexturePass(Environment& env, IR::Program& program) { | |||
| 597 | } else { | 638 | } else { |
| 598 | inst->SetArg(0, IR::Value{}); | 639 | inst->SetArg(0, IR::Value{}); |
| 599 | } | 640 | } |
| 641 | |||
| 642 | if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL && | ||
| 643 | inst->GetOpcode() == IR::Opcode::ImageFetch && flags.type == TextureType::Buffer) { | ||
| 644 | const auto pixel_format = ReadTexturePixelFormat(env, cbuf); | ||
| 645 | if (pixel_format != TexturePixelFormat::OTHER) { | ||
| 646 | PathTexelFetch(*texture_inst.block, *texture_inst.inst, pixel_format); | ||
| 647 | } | ||
| 648 | } | ||
| 600 | } | 649 | } |
| 601 | } | 650 | } |
| 602 | 651 | ||
diff --git a/src/shader_recompiler/shader_info.h b/src/shader_recompiler/shader_info.h index a479e105e..f31e1f821 100644 --- a/src/shader_recompiler/shader_info.h +++ b/src/shader_recompiler/shader_info.h | |||
| @@ -29,6 +29,16 @@ enum class TextureType : u32 { | |||
| 29 | }; | 29 | }; |
| 30 | constexpr u32 NUM_TEXTURE_TYPES = 9; | 30 | constexpr u32 NUM_TEXTURE_TYPES = 9; |
| 31 | 31 | ||
| 32 | enum class TexturePixelFormat : u32 { | ||
| 33 | A8B8G8R8_SNORM, | ||
| 34 | R8_SNORM, | ||
| 35 | R8G8_SNORM, | ||
| 36 | R16G16B16A16_SNORM, | ||
| 37 | R16G16_SNORM, | ||
| 38 | R16_SNORM, | ||
| 39 | OTHER | ||
| 40 | }; | ||
| 41 | |||
| 32 | enum class ImageFormat : u32 { | 42 | enum class ImageFormat : u32 { |
| 33 | Typeless, | 43 | Typeless, |
| 34 | R8_UINT, | 44 | R8_UINT, |