mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 05:38:49 +00:00
ir: Perform degamma in shader when sampler sets force_degamma (#3420)
* ir: Perform degamma in shader when sampler sets force_degamma * specialization: Add srgb if image is sampled Might fix cases where sampler force_degamma is used with srgb image
This commit is contained in:
@@ -312,6 +312,11 @@ constexpr NumberClass GetNumberClass(const NumberFormat nfmt) {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool IsRgb(CompSwizzle swizzle) {
|
||||
return swizzle == CompSwizzle::Red || swizzle == CompSwizzle::Green ||
|
||||
swizzle == CompSwizzle::Blue;
|
||||
}
|
||||
|
||||
constexpr bool IsInteger(const NumberFormat nfmt) {
|
||||
return nfmt == NumberFormat::Sint || nfmt == NumberFormat::Uint;
|
||||
}
|
||||
@@ -320,6 +325,10 @@ constexpr bool IsBlockCoded(DataFormat format) {
|
||||
return format >= DataFormat::FormatBc1 && format <= DataFormat::FormatBc7;
|
||||
}
|
||||
|
||||
constexpr bool IsFmask(DataFormat format) {
|
||||
return format >= DataFormat::FormatFmask8_1 && format <= DataFormat::FormatFmask64_8;
|
||||
}
|
||||
|
||||
std::string_view NameOf(DataFormat fmt);
|
||||
std::string_view NameOf(NumberFormat fmt);
|
||||
|
||||
|
||||
@@ -293,11 +293,6 @@ struct Image {
|
||||
return (((banks - 1) << 4) & base_address) >> 4;
|
||||
}
|
||||
|
||||
bool IsFmask() const noexcept {
|
||||
return GetDataFmt() >= DataFormat::FormatFmask8_1 &&
|
||||
GetDataFmt() <= DataFormat::FormatFmask64_8;
|
||||
}
|
||||
|
||||
ImageType GetBaseType() const noexcept {
|
||||
const auto base_type = GetType();
|
||||
if (base_type == ImageType::Color1DArray) {
|
||||
|
||||
@@ -11,32 +11,29 @@ namespace VideoCore {
|
||||
|
||||
Sampler::Sampler(const Vulkan::Instance& instance, const AmdGpu::Sampler& sampler,
|
||||
const AmdGpu::Liverpool::BorderColorBufferBase& border_color_base) {
|
||||
if (sampler.force_degamma) {
|
||||
LOG_WARNING(Render_Vulkan, "Texture requires gamma correction");
|
||||
}
|
||||
using namespace Vulkan;
|
||||
const bool anisotropyEnable = instance.IsAnisotropicFilteringSupported() &&
|
||||
(AmdGpu::IsAnisoFilter(sampler.xy_mag_filter) ||
|
||||
AmdGpu::IsAnisoFilter(sampler.xy_min_filter));
|
||||
const float maxAnisotropy =
|
||||
anisotropyEnable ? std::clamp(sampler.MaxAniso(), 1.0f, instance.MaxSamplerAnisotropy())
|
||||
: 1.0f;
|
||||
auto borderColor = LiverpoolToVK::BorderColor(sampler.border_color_type);
|
||||
const bool anisotropy_enable = instance.IsAnisotropicFilteringSupported() &&
|
||||
(AmdGpu::IsAnisoFilter(sampler.xy_mag_filter) ||
|
||||
AmdGpu::IsAnisoFilter(sampler.xy_min_filter));
|
||||
const float max_anisotropy =
|
||||
anisotropy_enable ? std::clamp(sampler.MaxAniso(), 1.0f, instance.MaxSamplerAnisotropy())
|
||||
: 1.0f;
|
||||
auto border_color = LiverpoolToVK::BorderColor(sampler.border_color_type);
|
||||
if (!instance.IsCustomBorderColorSupported()) {
|
||||
LOG_WARNING(Render_Vulkan, "Custom border color is not supported, falling back to black");
|
||||
borderColor = vk::BorderColor::eFloatOpaqueBlack;
|
||||
border_color = vk::BorderColor::eFloatOpaqueBlack;
|
||||
}
|
||||
|
||||
const auto customColor = [&]() -> std::optional<vk::SamplerCustomBorderColorCreateInfoEXT> {
|
||||
if (borderColor == vk::BorderColor::eFloatCustomEXT) {
|
||||
const auto borderColorIndex = sampler.border_color_ptr.Value();
|
||||
const auto borderColorBuffer = border_color_base.Address<std::array<float, 4>*>();
|
||||
const auto customBorderColorArray = borderColorBuffer[borderColorIndex];
|
||||
const auto custom_color = [&]() -> std::optional<vk::SamplerCustomBorderColorCreateInfoEXT> {
|
||||
if (border_color == vk::BorderColor::eFloatCustomEXT) {
|
||||
const auto border_color_index = sampler.border_color_ptr.Value();
|
||||
const auto border_color_buffer = border_color_base.Address<std::array<float, 4>*>();
|
||||
const auto custom_border_color_array = border_color_buffer[border_color_index];
|
||||
|
||||
const vk::SamplerCustomBorderColorCreateInfoEXT ret{
|
||||
.customBorderColor =
|
||||
vk::ClearColorValue{
|
||||
.float32 = customBorderColorArray,
|
||||
.float32 = custom_border_color_array,
|
||||
},
|
||||
.format = vk::Format::eR32G32B32A32Sfloat,
|
||||
};
|
||||
@@ -47,7 +44,7 @@ Sampler::Sampler(const Vulkan::Instance& instance, const AmdGpu::Sampler& sample
|
||||
}();
|
||||
|
||||
const vk::SamplerCreateInfo sampler_ci = {
|
||||
.pNext = customColor ? &*customColor : nullptr,
|
||||
.pNext = custom_color ? &*custom_color : nullptr,
|
||||
.magFilter = LiverpoolToVK::Filter(sampler.xy_mag_filter),
|
||||
.minFilter = LiverpoolToVK::Filter(sampler.xy_min_filter),
|
||||
.mipmapMode = LiverpoolToVK::MipFilter(sampler.mip_filter),
|
||||
@@ -55,13 +52,13 @@ Sampler::Sampler(const Vulkan::Instance& instance, const AmdGpu::Sampler& sample
|
||||
.addressModeV = LiverpoolToVK::ClampMode(sampler.clamp_y),
|
||||
.addressModeW = LiverpoolToVK::ClampMode(sampler.clamp_z),
|
||||
.mipLodBias = std::min(sampler.LodBias(), instance.MaxSamplerLodBias()),
|
||||
.anisotropyEnable = anisotropyEnable,
|
||||
.maxAnisotropy = maxAnisotropy,
|
||||
.anisotropyEnable = anisotropy_enable,
|
||||
.maxAnisotropy = max_anisotropy,
|
||||
.compareEnable = sampler.depth_compare_func != AmdGpu::DepthCompare::Never,
|
||||
.compareOp = LiverpoolToVK::DepthCompare(sampler.depth_compare_func),
|
||||
.minLod = sampler.MinLod(),
|
||||
.maxLod = sampler.MaxLod(),
|
||||
.borderColor = borderColor,
|
||||
.borderColor = border_color,
|
||||
.unnormalizedCoordinates = false, // Handled in shader due to Vulkan limitations.
|
||||
};
|
||||
auto [sampler_result, smplr] = instance.GetDevice().createSamplerUnique(sampler_ci);
|
||||
|
||||
Reference in New Issue
Block a user