diff options
Diffstat (limited to 'src/video_core/renderer_vulkan')
| -rw-r--r-- | src/video_core/renderer_vulkan/blit_image.cpp | 80 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/blit_image.h | 25 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 117 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.h | 4 |
4 files changed, 175 insertions, 51 deletions
diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp index 1eeed165f..cf8c5454c 100644 --- a/src/video_core/renderer_vulkan/blit_image.cpp +++ b/src/video_core/renderer_vulkan/blit_image.cpp @@ -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 diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.h index d5e79db5e..b7bc95263 100644 --- a/src/video_core/renderer_vulkan/blit_image.h +++ b/src/video_core/renderer_vulkan/blit_image.h @@ -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 diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 1bbe76ebf..364b73545 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -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); - } - break; - case PixelFormat::D16_UNORM: - if (src_view.format == PixelFormat::R16_UNORM) { - return blit_image_helper.ConvertR16ToD16(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::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, diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 4161d7ff9..41663e1c5 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h @@ -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 @@ -111,6 +112,9 @@ public: void BarrierFeedbackLoop(); + bool IsFormatDitherable(VideoCore::Surface::PixelFormat format); + bool IsFormatScalable(VideoCore::Surface::PixelFormat format); + const Device& device; Scheduler& scheduler; MemoryAllocator& memory_allocator; |
