From b0cd2e8cbe040bc23c0014b4da0c5ad5da0168a3 Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Thu, 4 Dec 2025 05:08:07 -0400 Subject: [PATCH] [vk] Adjusted Texel Block View for Depth/Stencil attachment images --- .../renderer_vulkan/vk_texture_cache.cpp | 42 ++++++++++++++----- .../renderer_vulkan/vk_texture_cache.h | 5 +++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 4e3f657cb5..130392754b 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -44,6 +44,8 @@ using VideoCommon::ImageInfo; using VideoCommon::ImageType; using VideoCommon::SubresourceRange; using VideoCore::Surface::BytesPerBlock; +using VideoCore::Surface::DefaultBlockHeight; +using VideoCore::Surface::DefaultBlockWidth; using VideoCore::Surface::HasAlpha; using VideoCore::Surface::IsPixelFormatASTC; using VideoCore::Surface::IsPixelFormatInteger; @@ -191,7 +193,8 @@ constexpr VkBorderColor ConvertBorderColor(const std::array& color) { } [[nodiscard]] vk::Image MakeImage(const Device& device, const MemoryAllocator& allocator, - const ImageInfo& info, std::span view_formats) { + const ImageInfo& info, std::span view_formats, + bool needs_block_compatible_views) { if (info.type == ImageType::Buffer) { return vk::Image{}; } @@ -204,6 +207,9 @@ constexpr VkBorderColor ConvertBorderColor(const std::array& color) { }; if (view_formats.size() > 1) { image_ci.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; + if (needs_block_compatible_views) { + image_ci.flags |= VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT; + } if (device.IsKhrImageFormatListSupported()) { image_ci.pNext = &image_format_list; } @@ -880,17 +886,30 @@ TextureCacheRuntime::TextureCacheRuntime(const Device& device_, Scheduler& sched } for (size_t index_a = 0; index_a < VideoCore::Surface::MaxPixelFormat; index_a++) { const auto image_format = static_cast(index_a); + const auto image_block_width = DefaultBlockWidth(image_format); + const auto image_block_height = DefaultBlockHeight(image_format); + const auto image_bytes_per_block = BytesPerBlock(image_format); + bool needs_block_view = false; if (IsPixelFormatASTC(image_format) && !device.IsOptimalAstcSupported()) { view_formats[index_a].push_back(VK_FORMAT_A8B8G8R8_UNORM_PACK32); + needs_block_view = true; } for (size_t index_b = 0; index_b < VideoCore::Surface::MaxPixelFormat; index_b++) { const auto view_format = static_cast(index_b); - if (VideoCore::Surface::IsViewCompatible(image_format, view_format, false, true)) { - const auto view_info = - MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true, view_format); - view_formats[index_a].push_back(view_info.format); + if (!VideoCore::Surface::IsViewCompatible(image_format, view_format, false, true)) { + continue; + } + const auto view_info = + MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true, view_format); + view_formats[index_a].push_back(view_info.format); + if (!needs_block_view) { + const bool different_block = image_bytes_per_block != BytesPerBlock(view_format) || + image_block_width != DefaultBlockWidth(view_format) || + image_block_height != DefaultBlockHeight(view_format); + needs_block_view = different_block; } } + requires_block_view_formats[index_a] = needs_block_view; } } @@ -1675,9 +1694,11 @@ void TextureCacheRuntime::TickFrame() {} Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_, VAddr cpu_addr_) - : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler}, - runtime{&runtime_}, original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info, - runtime->ViewFormats(info.format))), + : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler}, + runtime{&runtime_}, + original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info, + runtime_.ViewFormats(info.format), + runtime_.RequiresBlockCompatibleViewFormats(info.format))), aspect_mask(ImageAspectMask(info.format)) { if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { switch (Settings::values.accelerate_astc.GetValue()) { @@ -2054,7 +2075,8 @@ bool Image::ScaleUp(bool ignore) { scaled_info.size.width = scaled_width; scaled_info.size.height = scaled_height; scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info, - runtime->ViewFormats(info.format)); + runtime->ViewFormats(info.format), + runtime->RequiresBlockCompatibleViewFormats(info.format)); ignore = false; } current_image = &Image::scaled_image; @@ -2305,7 +2327,7 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::NullImageV ImageInfo info{}; info.format = PixelFormat::A8B8G8R8_UNORM; - null_image = MakeImage(*device, runtime.memory_allocator, info, {}); + null_image = MakeImage(*device, runtime.memory_allocator, info, {}, false); image_handle = *null_image; for (u32 i = 0; i < Shader::NUM_TEXTURE_TYPES; i++) { image_views[i] = MakeView(VK_FORMAT_A8B8G8R8_UNORM_PACK32, VK_IMAGE_ASPECT_COLOR_BIT); diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 0c62924070..12e0802912 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h @@ -116,6 +116,10 @@ public: return view_formats[static_cast(format)]; } + bool RequiresBlockCompatibleViewFormats(PixelFormat format) const noexcept { + return requires_block_view_formats[static_cast(format)]; + } + void BarrierFeedbackLoop(); bool IsFormatDitherable(VideoCore::Surface::PixelFormat format); @@ -134,6 +138,7 @@ public: std::unique_ptr msaa_copy_pass; const Settings::ResolutionScalingInfo& resolution; std::array, VideoCore::Surface::MaxPixelFormat> view_formats; + std::array requires_block_view_formats{}; static constexpr size_t indexing_slots = 8 * sizeof(size_t); std::array buffers{};