From e612e881ac2bd3112c38dc0660771447e5e62218 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:10:40 -0800 Subject: [PATCH] renderer_vulkan: Bind null color attachments when target is masked out. (#1740) * renderer_vulkan: Bind null color attachments when target is masked out. * Simplify setting null color attachment --- src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 5 +++-- src/video_core/renderer_vulkan/vk_rasterizer.cpp | 11 ++++++++--- src/video_core/renderer_vulkan/vk_scheduler.h | 2 -- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 276e4ef2..b9f318f7 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -279,7 +279,7 @@ bool PipelineCache::RefreshGraphicsKey() { // recompiler. for (auto cb = 0u, remapped_cb = 0u; cb < Liverpool::NumColorBuffers; ++cb) { auto const& col_buf = regs.color_buffers[cb]; - if (skip_cb_binding || !col_buf) { + if (skip_cb_binding || !col_buf || !regs.color_target_mask.GetMask(cb)) { continue; } const auto base_format = @@ -385,7 +385,8 @@ bool PipelineCache::RefreshGraphicsKey() { // Second pass to fill remain CB pipeline key data for (auto cb = 0u, remapped_cb = 0u; cb < Liverpool::NumColorBuffers; ++cb) { auto const& col_buf = regs.color_buffers[cb]; - if (skip_cb_binding || !col_buf || (key.mrt_mask & (1u << cb)) == 0) { + if (skip_cb_binding || !col_buf || !regs.color_target_mask.GetMask(cb) || + (key.mrt_mask & (1u << cb)) == 0) { key.color_formats[cb] = vk::Format::eUndefined; key.mrt_swizzles[cb] = Liverpool::ColorBuffer::SwapMode::Standard; continue; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 33358b85..496ea516 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -103,6 +103,14 @@ RenderState Rasterizer::PrepareRenderState(u32 mrt_mask) { continue; } + // If the color buffer is still bound but rendering to it is disabled by the target + // mask, we need to prevent the render area from being affected by unbound render target + // extents. + if (!regs.color_target_mask.GetMask(col_buf_id)) { + state.color_attachments[state.num_color_attachments++].imageView = VK_NULL_HANDLE; + continue; + } + const auto& hint = liverpool->last_cb_extent[col_buf_id]; auto& [image_id, desc] = cb_descs.emplace_back(std::piecewise_construct, std::tuple{}, std::tuple{col_buf, hint}); @@ -118,7 +126,6 @@ RenderState Rasterizer::PrepareRenderState(u32 mrt_mask) { const auto mip = image_view.info.range.base.level; state.width = std::min(state.width, std::max(image.info.size.width >> mip, 1u)); state.height = std::min(state.height, std::max(image.info.size.height >> mip, 1u)); - state.color_images[state.num_color_attachments] = image.image; state.color_attachments[state.num_color_attachments++] = { .imageView = *image_view.image_view, .imageLayout = vk::ImageLayout::eUndefined, @@ -153,7 +160,6 @@ RenderState Rasterizer::PrepareRenderState(u32 mrt_mask) { state.width = std::min(state.width, image.info.size.width); state.height = std::min(state.height, image.info.size.height); - state.depth_image = image.image; state.depth_attachment = { .imageView = *image_view.image_view, .imageLayout = vk::ImageLayout::eUndefined, @@ -716,7 +722,6 @@ void Rasterizer::BeginRendering(const GraphicsPipeline& pipeline, RenderState& s auto& image = texture_cache.GetImage(view.image_id); state.color_attachments[cb_index].imageView = *view.image_view; state.color_attachments[cb_index].imageLayout = image.last_state.layout; - state.color_images[cb_index] = image.image; const auto mip = view.info.range.base.level; state.width = std::min(state.width, std::max(image.info.size.width >> mip, 1u)); diff --git a/src/video_core/renderer_vulkan/vk_scheduler.h b/src/video_core/renderer_vulkan/vk_scheduler.h index 45a9228c..cdd33745 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.h +++ b/src/video_core/renderer_vulkan/vk_scheduler.h @@ -20,9 +20,7 @@ class Instance; struct RenderState { std::array color_attachments{}; - std::array color_images{}; vk::RenderingAttachmentInfo depth_attachment{}; - vk::Image depth_image{}; u32 num_color_attachments{}; bool has_depth{}; bool has_stencil{};