From 548de01a04271960ae3c39741282ee84ad6f7ca7 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sat, 4 Jan 2025 22:48:48 -0800 Subject: [PATCH] amdgpu: Add missing specialization and move format mapping data to types --- src/shader_recompiler/ir/reinterpret.h | 2 +- src/shader_recompiler/specialization.h | 4 + src/video_core/amdgpu/liverpool.h | 4 +- src/video_core/amdgpu/resource.h | 123 +------------------------ src/video_core/amdgpu/types.h | 120 ++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 124 deletions(-) diff --git a/src/shader_recompiler/ir/reinterpret.h b/src/shader_recompiler/ir/reinterpret.h index 74a7698db..29a1ba269 100644 --- a/src/shader_recompiler/ir/reinterpret.h +++ b/src/shader_recompiler/ir/reinterpret.h @@ -4,7 +4,7 @@ #pragma once #include "shader_recompiler/ir/ir_emitter.h" -#include "video_core/amdgpu/resource.h" +#include "video_core/amdgpu/types.h" namespace Shader::IR { diff --git a/src/shader_recompiler/specialization.h b/src/shader_recompiler/specialization.h index f8a86c63b..f58d2e2d3 100644 --- a/src/shader_recompiler/specialization.h +++ b/src/shader_recompiler/specialization.h @@ -32,6 +32,7 @@ struct BufferSpecialization { struct TextureBufferSpecialization { bool is_integer = false; AmdGpu::CompMapping dst_select{}; + AmdGpu::NumberConversion num_conversion{}; auto operator<=>(const TextureBufferSpecialization&) const = default; }; @@ -41,6 +42,7 @@ struct ImageSpecialization { bool is_integer = false; bool is_storage = false; AmdGpu::CompMapping dst_select{}; + AmdGpu::NumberConversion num_conversion{}; auto operator<=>(const ImageSpecialization&) const = default; }; @@ -107,6 +109,7 @@ struct StageSpecialization { [](auto& spec, const auto& desc, AmdGpu::Buffer sharp) { spec.is_integer = AmdGpu::IsInteger(sharp.GetNumberFmt()); spec.dst_select = sharp.DstSelect(); + spec.num_conversion = sharp.GetNumberConversion(); }); ForEachSharp(binding, images, info->images, [](auto& spec, const auto& desc, AmdGpu::Image sharp) { @@ -116,6 +119,7 @@ struct StageSpecialization { if (spec.is_storage) { spec.dst_select = sharp.DstSelect(); } + spec.num_conversion = sharp.GetNumberConversion(); }); ForEachSharp(binding, fmasks, info->fmasks, [](auto& spec, const auto& desc, AmdGpu::Image sharp) { diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index de72a41b2..837b73d89 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -20,9 +20,9 @@ #include "common/types.h" #include "common/unique_function.h" #include "shader_recompiler/params.h" -#include "types.h" #include "video_core/amdgpu/pixel_format.h" #include "video_core/amdgpu/resource.h" +#include "video_core/amdgpu/types.h" namespace Vulkan { class Rasterizer; @@ -942,7 +942,7 @@ struct Liverpool { const auto swap_idx = static_cast(info.comp_swap.Value()); const auto components_idx = NumComponents(info.format) - 1; const auto mrt_swizzle = mrt_swizzles[swap_idx][components_idx]; - return RemapComponents(info.format, mrt_swizzle); + return RemapSwizzle(info.format, mrt_swizzle); } }; diff --git a/src/video_core/amdgpu/resource.h b/src/video_core/amdgpu/resource.h index 43fa2d0cf..ffee7964a 100644 --- a/src/video_core/amdgpu/resource.h +++ b/src/video_core/amdgpu/resource.h @@ -11,125 +11,6 @@ namespace AmdGpu { -enum class CompSwizzle : u32 { - Zero = 0, - One = 1, - Red = 4, - Green = 5, - Blue = 6, - Alpha = 7, -}; - -struct CompMapping { - CompSwizzle r : 3; - CompSwizzle g : 3; - CompSwizzle b : 3; - CompSwizzle a : 3; - - auto operator<=>(const CompMapping& other) const = default; - - template - [[nodiscard]] std::array Apply(const std::array& data) const { - return { - ApplySingle(data, r), - ApplySingle(data, g), - ApplySingle(data, b), - ApplySingle(data, a), - }; - } - -private: - template - T ApplySingle(const std::array& data, const CompSwizzle swizzle) const { - switch (swizzle) { - case CompSwizzle::Zero: - return T(0); - case CompSwizzle::One: - return T(1); - case CompSwizzle::Red: - return data[0]; - case CompSwizzle::Green: - return data[1]; - case CompSwizzle::Blue: - return data[2]; - case CompSwizzle::Alpha: - return data[3]; - default: - UNREACHABLE(); - } - } -}; - -inline DataFormat RemapDataFormat(const DataFormat format) { - switch (format) { - case DataFormat::Format11_11_10: - return DataFormat::Format10_11_11; - case DataFormat::Format10_10_10_2: - return DataFormat::Format2_10_10_10; - case DataFormat::Format5_5_5_1: - return DataFormat::Format1_5_5_5; - default: - return format; - } -} - -inline NumberFormat RemapNumberFormat(const NumberFormat format) { - switch (format) { - case NumberFormat::Uscaled: - return NumberFormat::Uint; - case NumberFormat::Sscaled: - return NumberFormat::Sint; - case NumberFormat::Ubnorm: - return NumberFormat::Unorm; - default: - return format; - } -} - -inline CompMapping RemapComponents(const DataFormat format, const CompMapping components) { - switch (format) { - case DataFormat::Format11_11_10: { - CompMapping result; - result.r = components.b; - result.g = components.g; - result.b = components.r; - result.a = components.a; - return result; - } - case DataFormat::Format10_10_10_2: - case DataFormat::Format5_5_5_1: { - CompMapping result; - result.r = components.a; - result.g = components.b; - result.b = components.g; - result.a = components.r; - return result; - } - default: - return components; - } -} - -enum NumberConversion { - None, - UintToUscaled, - SintToSscaled, - UnormToUbnorm, -}; - -inline NumberConversion MapNumberConversion(const NumberFormat format) { - switch (format) { - case NumberFormat::Uscaled: - return UintToUscaled; - case NumberFormat::Sscaled: - return SintToSscaled; - case NumberFormat::Ubnorm: - return UnormToUbnorm; - default: - return None; - } -} - // Table 8.5 Buffer Resource Descriptor [Sea Islands Series Instruction Set Architecture] struct Buffer { u64 base_address : 44; @@ -169,7 +50,7 @@ struct Buffer { .b = CompSwizzle(dst_sel_z), .a = CompSwizzle(dst_sel_w), }; - return RemapComponents(DataFormat(data_format), dst_sel); + return RemapSwizzle(DataFormat(data_format), dst_sel); } NumberFormat GetNumberFmt() const noexcept { @@ -338,7 +219,7 @@ struct Image { .b = CompSwizzle(dst_sel_z), .a = CompSwizzle(dst_sel_w), }; - return RemapComponents(DataFormat(data_format), dst_sel); + return RemapSwizzle(DataFormat(data_format), dst_sel); } u32 Pitch() const { diff --git a/src/video_core/amdgpu/types.h b/src/video_core/amdgpu/types.h index 847730a72..a19e53256 100644 --- a/src/video_core/amdgpu/types.h +++ b/src/video_core/amdgpu/types.h @@ -5,6 +5,7 @@ #include #include +#include "common/assert.h" #include "common/types.h" namespace AmdGpu { @@ -182,6 +183,125 @@ enum class NumberFormat : u32 { Ubscaled = 13, }; +enum class CompSwizzle : u32 { + Zero = 0, + One = 1, + Red = 4, + Green = 5, + Blue = 6, + Alpha = 7, +}; + +enum class NumberConversion : u32 { + None, + UintToUscaled, + SintToSscaled, + UnormToUbnorm, +}; + +struct CompMapping { + CompSwizzle r : 3; + CompSwizzle g : 3; + CompSwizzle b : 3; + CompSwizzle a : 3; + + auto operator<=>(const CompMapping& other) const = default; + + template + [[nodiscard]] std::array Apply(const std::array& data) const { + return { + ApplySingle(data, r), + ApplySingle(data, g), + ApplySingle(data, b), + ApplySingle(data, a), + }; + } + +private: + template + T ApplySingle(const std::array& data, const CompSwizzle swizzle) const { + switch (swizzle) { + case CompSwizzle::Zero: + return T(0); + case CompSwizzle::One: + return T(1); + case CompSwizzle::Red: + return data[0]; + case CompSwizzle::Green: + return data[1]; + case CompSwizzle::Blue: + return data[2]; + case CompSwizzle::Alpha: + return data[3]; + default: + UNREACHABLE(); + } + } +}; + +inline DataFormat RemapDataFormat(const DataFormat format) { + switch (format) { + case DataFormat::Format11_11_10: + return DataFormat::Format10_11_11; + case DataFormat::Format10_10_10_2: + return DataFormat::Format2_10_10_10; + case DataFormat::Format5_5_5_1: + return DataFormat::Format1_5_5_5; + default: + return format; + } +} + +inline NumberFormat RemapNumberFormat(const NumberFormat format) { + switch (format) { + case NumberFormat::Uscaled: + return NumberFormat::Uint; + case NumberFormat::Sscaled: + return NumberFormat::Sint; + case NumberFormat::Ubnorm: + return NumberFormat::Unorm; + default: + return format; + } +} + +inline CompMapping RemapSwizzle(const DataFormat format, const CompMapping swizzle) { + switch (format) { + case DataFormat::Format11_11_10: { + CompMapping result; + result.r = swizzle.b; + result.g = swizzle.g; + result.b = swizzle.r; + result.a = swizzle.a; + return result; + } + case DataFormat::Format10_10_10_2: + case DataFormat::Format5_5_5_1: { + CompMapping result; + result.r = swizzle.a; + result.g = swizzle.b; + result.b = swizzle.g; + result.a = swizzle.r; + return result; + } + default: + return swizzle; + } +} + +inline NumberConversion MapNumberConversion(const NumberFormat format) { + switch (format) { + case NumberFormat::Uscaled: + return NumberConversion::UintToUscaled; + case NumberFormat::Sscaled: + return NumberConversion::SintToSscaled; + case NumberFormat::Ubnorm: + return NumberConversion::UnormToUbnorm; + default: + return NumberConversion::None; + } +} + } // namespace AmdGpu template <>