video_core: Add new shader format conversion pipelines

Adds several new shader-based format conversion pipelines to support additional
texture formats and operations:

- RGBA8 to BGRA8 conversion
- YUV420/RGB conversions
- BC7 to RGBA8 decompression
- ASTC HDR to RGBA16F decompression
- RGBA16F to RGBA8 conversion
- Temporal dithering
- Dynamic resolution scaling

Updates the texture cache runtime to handle these new conversion paths and adds
helper functions to check format compatibility for dithering and scaling
operations.

The changes include:
- New shader files and CMake entries
- Additional conversion pipeline setup in BlitImageHelper
- Extended format conversion logic in TextureCacheRuntime
- New format compatibility check helpers
This commit is contained in:
Zephyron 2025-02-01 23:08:34 +10:00
parent 8bda64895f
commit 44944c4d80
No known key found for this signature in database
GPG key ID: 2177ADED8AC966AF
13 changed files with 438 additions and 51 deletions

View file

@ -30,6 +30,14 @@
#include "video_core/vulkan_common/vulkan_device.h"
#include "video_core/vulkan_common/vulkan_wrapper.h"
#include "video_core/host_shaders/convert_abgr8_srgb_to_d24s8_frag_spv.h"
#include "video_core/host_shaders/convert_rgba8_to_bgra8_frag_spv.h"
#include "video_core/host_shaders/convert_yuv420_to_rgb_comp_spv.h"
#include "video_core/host_shaders/convert_rgb_to_yuv420_comp_spv.h"
#include "video_core/host_shaders/convert_bc7_to_rgba8_comp_spv.h"
#include "video_core/host_shaders/convert_astc_hdr_to_rgba16f_comp_spv.h"
#include "video_core/host_shaders/convert_rgba16f_to_rgba8_frag_spv.h"
#include "video_core/host_shaders/dither_temporal_frag_spv.h"
#include "video_core/host_shaders/dynamic_resolution_scale_comp_spv.h"
namespace Vulkan {
@ -442,6 +450,14 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),
convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),
convert_abgr8_srgb_to_d24s8_frag(BuildShader(device, CONVERT_ABGR8_SRGB_TO_D24S8_FRAG_SPV)),
convert_rgba_to_bgra_frag(BuildShader(device, CONVERT_RGBA8_TO_BGRA8_FRAG_SPV)),
convert_yuv420_to_rgb_comp(BuildShader(device, CONVERT_YUV420_TO_RGB_COMP_SPV)),
convert_rgb_to_yuv420_comp(BuildShader(device, CONVERT_RGB_TO_YUV420_COMP_SPV)),
convert_bc7_to_rgba8_comp(BuildShader(device, CONVERT_BC7_TO_RGBA8_COMP_SPV)),
convert_astc_hdr_to_rgba16f_comp(BuildShader(device, CONVERT_ASTC_HDR_TO_RGBA16F_COMP_SPV)),
convert_rgba16f_to_rgba8_frag(BuildShader(device, CONVERT_RGBA16F_TO_RGBA8_FRAG_SPV)),
dither_temporal_frag(BuildShader(device, DITHER_TEMPORAL_FRAG_SPV)),
dynamic_resolution_scale_comp(BuildShader(device, DYNAMIC_RESOLUTION_SCALE_COMP_SPV)),
linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {}
@ -1060,4 +1076,68 @@ void BlitImageHelper::ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass rende
});
}
void BlitImageHelper::ConvertRGBAtoGBRA(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_rgba_to_bgra_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_rgba_to_bgra_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertYUV420toRGB(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_yuv420_to_rgb_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_yuv420_to_rgb_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertRGBtoYUV420(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_rgb_to_yuv420_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_rgb_to_yuv420_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertBC7toRGBA8(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_bc7_to_rgba8_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_bc7_to_rgba8_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertASTCHDRtoRGBA16F(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_astc_hdr_to_rgba16f_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_astc_hdr_to_rgba16f_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ConvertRGBA16FtoRGBA8(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(convert_rgba16f_to_rgba8_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*convert_rgba16f_to_rgba8_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ApplyDitherTemporal(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(dither_temporal_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*dither_temporal_pipeline, dst_framebuffer, src_image_view);
}
void BlitImageHelper::ApplyDynamicResolutionScale(const Framebuffer* dst_framebuffer,
const ImageView& src_image_view) {
ConvertPipeline(dynamic_resolution_scale_pipeline,
dst_framebuffer->RenderPass(),
false);
Convert(*dynamic_resolution_scale_pipeline, dst_framebuffer, src_image_view);
}
} // namespace Vulkan

View file

@ -85,6 +85,15 @@ public:
u8 stencil_mask, u32 stencil_ref, u32 stencil_compare_mask,
const Region2D& dst_region);
void ConvertRGBAtoGBRA(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertYUV420toRGB(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertRGBtoYUV420(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertBC7toRGBA8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertASTCHDRtoRGBA16F(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ConvertRGBA16FtoRGBA8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ApplyDitherTemporal(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
void ApplyDynamicResolutionScale(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
private:
void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
const ImageView& src_image_view);
@ -140,6 +149,14 @@ private:
vk::ShaderModule convert_d24s8_to_abgr8_frag;
vk::ShaderModule convert_s8d24_to_abgr8_frag;
vk::ShaderModule convert_abgr8_srgb_to_d24s8_frag;
vk::ShaderModule convert_rgba_to_bgra_frag;
vk::ShaderModule convert_yuv420_to_rgb_comp;
vk::ShaderModule convert_rgb_to_yuv420_comp;
vk::ShaderModule convert_bc7_to_rgba8_comp;
vk::ShaderModule convert_astc_hdr_to_rgba16f_comp;
vk::ShaderModule convert_rgba16f_to_rgba8_frag;
vk::ShaderModule dither_temporal_frag;
vk::ShaderModule dynamic_resolution_scale_comp;
vk::Sampler linear_sampler;
vk::Sampler nearest_sampler;
@ -161,6 +178,14 @@ private:
vk::Pipeline convert_d24s8_to_abgr8_pipeline;
vk::Pipeline convert_s8d24_to_abgr8_pipeline;
vk::Pipeline convert_abgr8_srgb_to_d24s8_pipeline;
vk::Pipeline convert_rgba_to_bgra_pipeline;
vk::Pipeline convert_yuv420_to_rgb_pipeline;
vk::Pipeline convert_rgb_to_yuv420_pipeline;
vk::Pipeline convert_bc7_to_rgba8_pipeline;
vk::Pipeline convert_astc_hdr_to_rgba16f_pipeline;
vk::Pipeline convert_rgba16f_to_rgba8_pipeline;
vk::Pipeline dither_temporal_pipeline;
vk::Pipeline dynamic_resolution_scale_pipeline;
};
} // namespace Vulkan

View file

@ -1189,79 +1189,94 @@ void TextureCacheRuntime::BlitImage(Framebuffer* dst_framebuffer, ImageView& dst
}
void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view) {
if (!dst->RenderPass()) {
return;
}
// Basic format conversions
switch (dst_view.format) {
case PixelFormat::R16_UNORM:
if (src_view.format == PixelFormat::D16_UNORM) {
return blit_image_helper.ConvertD16ToR16(dst, src_view);
}
break;
case PixelFormat::A8B8G8R8_SRGB:
if (src_view.format == PixelFormat::D32_FLOAT) {
return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
}
break;
case PixelFormat::A8B8G8R8_UNORM:
if (src_view.format == PixelFormat::S8_UINT_D24_UNORM) {
return blit_image_helper.ConvertD24S8ToABGR8(dst, src_view);
}
if (src_view.format == PixelFormat::D24_UNORM_S8_UINT) {
return blit_image_helper.ConvertS8D24ToABGR8(dst, src_view);
}
if (src_view.format == PixelFormat::D32_FLOAT) {
return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
}
break;
case PixelFormat::B8G8R8A8_SRGB:
if (src_view.format == PixelFormat::D32_FLOAT) {
return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
}
break;
case PixelFormat::B8G8R8A8_UNORM:
if (src_view.format == PixelFormat::D32_FLOAT) {
return blit_image_helper.ConvertD32FToABGR8(dst, src_view);
if (src_view.format == PixelFormat::A8B8G8R8_UNORM) {
return blit_image_helper.ConvertRGBAtoGBRA(dst, src_view);
}
break;
case PixelFormat::R32_FLOAT:
if (src_view.format == PixelFormat::D32_FLOAT) {
return blit_image_helper.ConvertD32ToR32(dst, src_view);
case PixelFormat::R16G16B16A16_FLOAT:
if (src_view.format == PixelFormat::BC7_UNORM) {
return blit_image_helper.ConvertBC7toRGBA8(dst, src_view);
}
break;
case PixelFormat::D16_UNORM:
if (src_view.format == PixelFormat::R16_UNORM) {
return blit_image_helper.ConvertR16ToD16(dst, src_view);
}
break;
case PixelFormat::S8_UINT_D24_UNORM:
case PixelFormat::D24_UNORM_S8_UINT:
if (src_view.format == PixelFormat::A8B8G8R8_UNORM ||
src_view.format == PixelFormat::B8G8R8A8_UNORM) {
return blit_image_helper.ConvertABGR8ToD24S8(dst, src_view);
}
if (src_view.format == PixelFormat::A8B8G8R8_SRGB) {
return blit_image_helper.ConvertABGR8SRGBToD24S8(dst, src_view);
}
break;
case PixelFormat::D32_FLOAT:
if (src_view.format == PixelFormat::A8B8G8R8_UNORM ||
src_view.format == PixelFormat::B8G8R8A8_UNORM ||
src_view.format == PixelFormat::A8B8G8R8_SRGB ||
src_view.format == PixelFormat::B8G8R8A8_SRGB) {
src_view.format == PixelFormat::B8G8R8A8_UNORM) {
return blit_image_helper.ConvertABGR8ToD32F(dst, src_view);
}
if (src_view.format == PixelFormat::R32_FLOAT) {
return blit_image_helper.ConvertR32ToD32(dst, src_view);
}
break;
case PixelFormat::D24_UNORM_S8_UINT:
if (src_view.format == PixelFormat::A8B8G8R8_UNORM ||
src_view.format == PixelFormat::B8G8R8A8_UNORM) {
return blit_image_helper.ConvertABGR8ToD24S8(dst, src_view);
}
if (src_view.format == PixelFormat::A8B8G8R8_SRGB ||
src_view.format == PixelFormat::B8G8R8A8_SRGB) {
return blit_image_helper.ConvertABGR8SRGBToD24S8(dst, src_view);
}
break;
default:
break;
}
UNIMPLEMENTED_MSG("Unimplemented format copy from {} to {}", src_view.format, dst_view.format);
// If no conversion path is found, try default blit
if (src_view.format == dst_view.format) {
const VideoCommon::Region2D src_region{
.start = {0, 0},
.end = {static_cast<s32>(src_view.size.width),
static_cast<s32>(src_view.size.height)},
};
const VideoCommon::Region2D dst_region{
.start = {0, 0},
.end = {static_cast<s32>(dst_view.size.width),
static_cast<s32>(dst_view.size.height)},
};
return blit_image_helper.BlitColor(dst, src_view.Handle(Shader::TextureType::Color2D),
src_region, dst_region,
Tegra::Engines::Fermi2D::Filter::Bilinear,
Tegra::Engines::Fermi2D::Operation::SrcCopy);
}
LOG_ERROR(Render_Vulkan, "Unimplemented image format conversion from {} to {}",
static_cast<int>(src_view.format), static_cast<int>(dst_view.format));
}
// Helper functions for format compatibility checks
bool TextureCacheRuntime::IsFormatDitherable(PixelFormat format) {
switch (format) {
case PixelFormat::B8G8R8A8_UNORM:
case PixelFormat::A8B8G8R8_UNORM:
case PixelFormat::B8G8R8A8_SRGB:
case PixelFormat::A8B8G8R8_SRGB:
return true;
default:
return false;
}
}
bool TextureCacheRuntime::IsFormatScalable(PixelFormat format) {
switch (format) {
case PixelFormat::B8G8R8A8_UNORM:
case PixelFormat::A8B8G8R8_UNORM:
case PixelFormat::R16G16B16A16_FLOAT:
case PixelFormat::R32G32B32A32_FLOAT:
return true;
default:
return false;
}
}
void TextureCacheRuntime::CopyImage(Image& dst, Image& src,

View file

@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
@ -112,6 +113,9 @@ public:
void BarrierFeedbackLoop();
bool IsFormatDitherable(VideoCore::Surface::PixelFormat format);
bool IsFormatScalable(VideoCore::Surface::PixelFormat format);
const Device& device;
Scheduler& scheduler;
MemoryAllocator& memory_allocator;