video_core: added support for alternate CB channels order

This commit is contained in:
psucien 2024-06-15 22:18:21 +02:00
parent b9602afc82
commit b2b45bf480
7 changed files with 29 additions and 8 deletions

View File

@ -276,7 +276,13 @@ vk::BorderColor BorderColor(AmdGpu::BorderColor color) {
} }
} }
vk::Format SurfaceFormat(AmdGpu::DataFormat data_format, AmdGpu::NumberFormat num_format) { vk::Format SurfaceFormat(
AmdGpu::DataFormat data_format, AmdGpu::NumberFormat num_format,
Liverpool::ColorBuffer::SwapMode comp_swap /*= Liverpool::ColorBuffer::SwapMode::Standard*/) {
ASSERT_MSG(comp_swap == Liverpool::ColorBuffer::SwapMode::Standard ||
comp_swap == Liverpool::ColorBuffer::SwapMode::Alternate,
"Unsupported component swap mode {}", static_cast<u32>(comp_swap));
if (data_format == AmdGpu::DataFormat::Format32_32_32_32 && if (data_format == AmdGpu::DataFormat::Format32_32_32_32 &&
num_format == AmdGpu::NumberFormat::Float) { num_format == AmdGpu::NumberFormat::Float) {
return vk::Format::eR32G32B32A32Sfloat; return vk::Format::eR32G32B32A32Sfloat;
@ -287,11 +293,14 @@ vk::Format SurfaceFormat(AmdGpu::DataFormat data_format, AmdGpu::NumberFormat nu
} }
if (data_format == AmdGpu::DataFormat::Format8_8_8_8 && if (data_format == AmdGpu::DataFormat::Format8_8_8_8 &&
num_format == AmdGpu::NumberFormat::Unorm) { num_format == AmdGpu::NumberFormat::Unorm) {
return vk::Format::eR8G8B8A8Unorm; return comp_swap == Liverpool::ColorBuffer::SwapMode::Alternate
? vk::Format::eB8G8R8A8Unorm
: vk::Format::eR8G8B8A8Unorm;
} }
if (data_format == AmdGpu::DataFormat::Format8_8_8_8 && if (data_format == AmdGpu::DataFormat::Format8_8_8_8 &&
num_format == AmdGpu::NumberFormat::Srgb) { num_format == AmdGpu::NumberFormat::Srgb) {
return vk::Format::eB8G8R8A8Srgb; return comp_swap == Liverpool::ColorBuffer::SwapMode::Alternate ? vk::Format::eB8G8R8A8Srgb
: vk::Format::eR8G8B8A8Srgb;
} }
if (data_format == AmdGpu::DataFormat::Format32_32_32 && if (data_format == AmdGpu::DataFormat::Format32_32_32 &&
num_format == AmdGpu::NumberFormat::Float) { num_format == AmdGpu::NumberFormat::Float) {

View File

@ -38,7 +38,9 @@ vk::SamplerMipmapMode MipFilter(AmdGpu::MipFilter filter);
vk::BorderColor BorderColor(AmdGpu::BorderColor color); vk::BorderColor BorderColor(AmdGpu::BorderColor color);
vk::Format SurfaceFormat(AmdGpu::DataFormat data_format, AmdGpu::NumberFormat num_format); vk::Format SurfaceFormat(
AmdGpu::DataFormat data_format, AmdGpu::NumberFormat num_format,
Liverpool::ColorBuffer::SwapMode comp_swap = Liverpool::ColorBuffer::SwapMode::Standard);
vk::Format DepthFormat(Liverpool::DepthBuffer::ZFormat z_format, vk::Format DepthFormat(Liverpool::DepthBuffer::ZFormat z_format,
Liverpool::DepthBuffer::StencilFormat stencil_format); Liverpool::DepthBuffer::StencilFormat stencil_format);

View File

@ -129,8 +129,8 @@ void PipelineCache::RefreshGraphicsKey() {
if (!col_buf) { if (!col_buf) {
continue; continue;
} }
key.color_formats[remapped_cb] = key.color_formats[remapped_cb] = LiverpoolToVK::SurfaceFormat(
LiverpoolToVK::SurfaceFormat(col_buf.info.format, col_buf.NumFormat()); col_buf.info.format, col_buf.NumFormat(), col_buf.info.comp_swap.Value());
key.blend_controls[remapped_cb] = regs.blend_control[cb]; key.blend_controls[remapped_cb] = regs.blend_control[cb];
key.blend_controls[remapped_cb].enable.Assign(key.blend_controls[remapped_cb].enable && key.blend_controls[remapped_cb].enable.Assign(key.blend_controls[remapped_cb].enable &&
!col_buf.info.blend_bypass); !col_buf.info.blend_bypass);

View File

@ -62,6 +62,11 @@ ImageViewInfo::ImageViewInfo(const AmdGpu::Image& image, bool is_storage) noexce
} }
} }
ImageViewInfo::ImageViewInfo(const AmdGpu::Liverpool::ColorBuffer& col_buffer) noexcept {
format = Vulkan::LiverpoolToVK::SurfaceFormat(col_buffer.info.format, col_buffer.NumFormat(),
col_buffer.info.comp_swap.Value());
}
ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info_, Image& image, ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info_, Image& image,
std::optional<vk::ImageUsageFlags> usage_override /*= {}*/) std::optional<vk::ImageUsageFlags> usage_override /*= {}*/)
: info{info_} { : info{info_} {

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "video_core/amdgpu/liverpool.h"
#include "video_core/amdgpu/resource.h" #include "video_core/amdgpu/resource.h"
#include "video_core/renderer_vulkan/vk_common.h" #include "video_core/renderer_vulkan/vk_common.h"
#include "video_core/texture_cache/types.h" #include "video_core/texture_cache/types.h"
@ -19,6 +20,7 @@ namespace VideoCore {
struct ImageViewInfo { struct ImageViewInfo {
explicit ImageViewInfo() = default; explicit ImageViewInfo() = default;
explicit ImageViewInfo(const AmdGpu::Image& image, bool is_storage) noexcept; explicit ImageViewInfo(const AmdGpu::Image& image, bool is_storage) noexcept;
explicit ImageViewInfo(const AmdGpu::Liverpool::ColorBuffer& col_buffer) noexcept;
vk::ImageViewType type = vk::ImageViewType::e2D; vk::ImageViewType type = vk::ImageViewType::e2D;
vk::Format format = vk::Format::eR8G8B8A8Unorm; vk::Format format = vk::Format::eR8G8B8A8Unorm;

View File

@ -183,8 +183,7 @@ ImageView& TextureCache::RenderTarget(const AmdGpu::Liverpool::ColorBuffer& buff
vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentWrite |
vk::AccessFlagBits::eColorAttachmentRead); vk::AccessFlagBits::eColorAttachmentRead);
ImageViewInfo view_info; ImageViewInfo view_info{buffer};
view_info.format = info.pixel_format;
return RegisterImageView(image, view_info); return RegisterImageView(image, view_info);
} }

View File

@ -178,8 +178,12 @@ vk::Format DemoteImageFormatForDetiling(vk::Format format) {
switch (format) { switch (format) {
case vk::Format::eR8Unorm: case vk::Format::eR8Unorm:
return vk::Format::eR8Uint; return vk::Format::eR8Uint;
case vk::Format::eR8G8B8A8Srgb:
[[fallthrough]];
case vk::Format::eB8G8R8A8Srgb: case vk::Format::eB8G8R8A8Srgb:
[[fallthrough]]; [[fallthrough]];
case vk::Format::eB8G8R8A8Unorm:
[[fallthrough]];
case vk::Format::eR8G8B8A8Unorm: case vk::Format::eR8G8B8A8Unorm:
return vk::Format::eR32Uint; return vk::Format::eR32Uint;
case vk::Format::eBc1RgbaUnormBlock: case vk::Format::eBc1RgbaUnormBlock: