Skip to content

Commit

Permalink
amdgpu: Add missing specialization and move format mapping data to types
Browse files Browse the repository at this point in the history
  • Loading branch information
squidbus committed Jan 5, 2025
1 parent 43da807 commit 8bb5af7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 123 deletions.
4 changes: 4 additions & 0 deletions src/shader_recompiler/specialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/video_core/amdgpu/liverpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -942,7 +942,7 @@ struct Liverpool {
const auto swap_idx = static_cast<u32>(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);
}
};

Expand Down
123 changes: 2 additions & 121 deletions src/video_core/amdgpu/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
[[nodiscard]] std::array<T, 4> Apply(const std::array<T, 4>& data) const {
return {
ApplySingle(data, r),
ApplySingle(data, g),
ApplySingle(data, b),
ApplySingle(data, a),
};
}

private:
template <typename T>
T ApplySingle(const std::array<T, 4>& 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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
120 changes: 120 additions & 0 deletions src/video_core/amdgpu/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string_view>
#include <fmt/format.h>
#include "common/assert.h"
#include "common/types.h"

namespace AmdGpu {
Expand Down Expand Up @@ -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 <typename T>
[[nodiscard]] std::array<T, 4> Apply(const std::array<T, 4>& data) const {
return {
ApplySingle(data, r),
ApplySingle(data, g),
ApplySingle(data, b),
ApplySingle(data, a),
};
}

private:
template <typename T>
T ApplySingle(const std::array<T, 4>& 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 <>
Expand Down

0 comments on commit 8bb5af7

Please sign in to comment.