mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-06 17:32:40 +00:00
amdgpu: Add missing specialization and move format mapping data to types
This commit is contained in:
parent
cb0650feb4
commit
548de01a04
@ -4,7 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "shader_recompiler/ir/ir_emitter.h"
|
#include "shader_recompiler/ir/ir_emitter.h"
|
||||||
#include "video_core/amdgpu/resource.h"
|
#include "video_core/amdgpu/types.h"
|
||||||
|
|
||||||
namespace Shader::IR {
|
namespace Shader::IR {
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ struct BufferSpecialization {
|
|||||||
struct TextureBufferSpecialization {
|
struct TextureBufferSpecialization {
|
||||||
bool is_integer = false;
|
bool is_integer = false;
|
||||||
AmdGpu::CompMapping dst_select{};
|
AmdGpu::CompMapping dst_select{};
|
||||||
|
AmdGpu::NumberConversion num_conversion{};
|
||||||
|
|
||||||
auto operator<=>(const TextureBufferSpecialization&) const = default;
|
auto operator<=>(const TextureBufferSpecialization&) const = default;
|
||||||
};
|
};
|
||||||
@ -41,6 +42,7 @@ struct ImageSpecialization {
|
|||||||
bool is_integer = false;
|
bool is_integer = false;
|
||||||
bool is_storage = false;
|
bool is_storage = false;
|
||||||
AmdGpu::CompMapping dst_select{};
|
AmdGpu::CompMapping dst_select{};
|
||||||
|
AmdGpu::NumberConversion num_conversion{};
|
||||||
|
|
||||||
auto operator<=>(const ImageSpecialization&) const = default;
|
auto operator<=>(const ImageSpecialization&) const = default;
|
||||||
};
|
};
|
||||||
@ -107,6 +109,7 @@ struct StageSpecialization {
|
|||||||
[](auto& spec, const auto& desc, AmdGpu::Buffer sharp) {
|
[](auto& spec, const auto& desc, AmdGpu::Buffer sharp) {
|
||||||
spec.is_integer = AmdGpu::IsInteger(sharp.GetNumberFmt());
|
spec.is_integer = AmdGpu::IsInteger(sharp.GetNumberFmt());
|
||||||
spec.dst_select = sharp.DstSelect();
|
spec.dst_select = sharp.DstSelect();
|
||||||
|
spec.num_conversion = sharp.GetNumberConversion();
|
||||||
});
|
});
|
||||||
ForEachSharp(binding, images, info->images,
|
ForEachSharp(binding, images, info->images,
|
||||||
[](auto& spec, const auto& desc, AmdGpu::Image sharp) {
|
[](auto& spec, const auto& desc, AmdGpu::Image sharp) {
|
||||||
@ -116,6 +119,7 @@ struct StageSpecialization {
|
|||||||
if (spec.is_storage) {
|
if (spec.is_storage) {
|
||||||
spec.dst_select = sharp.DstSelect();
|
spec.dst_select = sharp.DstSelect();
|
||||||
}
|
}
|
||||||
|
spec.num_conversion = sharp.GetNumberConversion();
|
||||||
});
|
});
|
||||||
ForEachSharp(binding, fmasks, info->fmasks,
|
ForEachSharp(binding, fmasks, info->fmasks,
|
||||||
[](auto& spec, const auto& desc, AmdGpu::Image sharp) {
|
[](auto& spec, const auto& desc, AmdGpu::Image sharp) {
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
#include "common/unique_function.h"
|
#include "common/unique_function.h"
|
||||||
#include "shader_recompiler/params.h"
|
#include "shader_recompiler/params.h"
|
||||||
#include "types.h"
|
|
||||||
#include "video_core/amdgpu/pixel_format.h"
|
#include "video_core/amdgpu/pixel_format.h"
|
||||||
#include "video_core/amdgpu/resource.h"
|
#include "video_core/amdgpu/resource.h"
|
||||||
|
#include "video_core/amdgpu/types.h"
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
class Rasterizer;
|
class Rasterizer;
|
||||||
@ -942,7 +942,7 @@ struct Liverpool {
|
|||||||
const auto swap_idx = static_cast<u32>(info.comp_swap.Value());
|
const auto swap_idx = static_cast<u32>(info.comp_swap.Value());
|
||||||
const auto components_idx = NumComponents(info.format) - 1;
|
const auto components_idx = NumComponents(info.format) - 1;
|
||||||
const auto mrt_swizzle = mrt_swizzles[swap_idx][components_idx];
|
const auto mrt_swizzle = mrt_swizzles[swap_idx][components_idx];
|
||||||
return RemapComponents(info.format, mrt_swizzle);
|
return RemapSwizzle(info.format, mrt_swizzle);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,125 +11,6 @@
|
|||||||
|
|
||||||
namespace AmdGpu {
|
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]
|
// Table 8.5 Buffer Resource Descriptor [Sea Islands Series Instruction Set Architecture]
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
u64 base_address : 44;
|
u64 base_address : 44;
|
||||||
@ -169,7 +50,7 @@ struct Buffer {
|
|||||||
.b = CompSwizzle(dst_sel_z),
|
.b = CompSwizzle(dst_sel_z),
|
||||||
.a = CompSwizzle(dst_sel_w),
|
.a = CompSwizzle(dst_sel_w),
|
||||||
};
|
};
|
||||||
return RemapComponents(DataFormat(data_format), dst_sel);
|
return RemapSwizzle(DataFormat(data_format), dst_sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberFormat GetNumberFmt() const noexcept {
|
NumberFormat GetNumberFmt() const noexcept {
|
||||||
@ -338,7 +219,7 @@ struct Image {
|
|||||||
.b = CompSwizzle(dst_sel_z),
|
.b = CompSwizzle(dst_sel_z),
|
||||||
.a = CompSwizzle(dst_sel_w),
|
.a = CompSwizzle(dst_sel_w),
|
||||||
};
|
};
|
||||||
return RemapComponents(DataFormat(data_format), dst_sel);
|
return RemapSwizzle(DataFormat(data_format), dst_sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Pitch() const {
|
u32 Pitch() const {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include "common/assert.h"
|
||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
|
|
||||||
namespace AmdGpu {
|
namespace AmdGpu {
|
||||||
@ -182,6 +183,125 @@ enum class NumberFormat : u32 {
|
|||||||
Ubscaled = 13,
|
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
|
} // namespace AmdGpu
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
Loading…
Reference in New Issue
Block a user