From 9227a2b86844b98b810ab02dd483c7fba5b7a688 Mon Sep 17 00:00:00 2001 From: psucien Date: Thu, 30 May 2024 11:21:26 +0200 Subject: [PATCH] video_core: multiple color attachments support --- src/video_core/amdgpu/liverpool.h | 4 +++ .../renderer_vulkan/vk_pipeline_cache.cpp | 5 ++-- .../renderer_vulkan/vk_rasterizer.cpp | 25 ++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index ac507667..442a66f2 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -631,6 +631,10 @@ struct Liverpool { u32 clear_word1; INSERT_PADDING_WORDS(2); + operator bool() const { + return info.format != DataFormat::FormatInvalid; + } + u32 Pitch() const { return (pitch.tile_max + 1) << 3; } diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 9b4e6856..d4a38308 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -101,9 +101,8 @@ void PipelineCache::RefreshGraphicsKey() { : vk::Format::eUndefined; for (u32 i = 0; i < Liverpool::NumColorBuffers; i++) { const auto& cb = regs.color_buffers[i]; - key.color_formats[i] = cb.base_address - ? LiverpoolToVK::SurfaceFormat(cb.info.format, cb.NumFormat()) - : vk::Format::eUndefined; + key.color_formats[i] = cb ? LiverpoolToVK::SurfaceFormat(cb.info.format, cb.NumFormat()) + : vk::Format::eUndefined; } for (u32 i = 0; i < MaxShaderStages; i++) { diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index ded491c4..5bdb443d 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -39,14 +39,21 @@ void Rasterizer::Draw(bool is_indexed) { const GraphicsPipeline* pipeline = pipeline_cache.GetGraphicsPipeline(); pipeline->BindResources(memory, vertex_index_buffer, texture_cache); - const auto& image_view = texture_cache.RenderTarget(regs.color_buffers[0]); + boost::container::static_vector + color_attachments{}; + for (const auto& col_buf : regs.color_buffers) { + if (!col_buf) { + continue; + } + const auto& image_view = texture_cache.RenderTarget(col_buf); - const vk::RenderingAttachmentInfo color_info = { - .imageView = *image_view.image_view, - .imageLayout = vk::ImageLayout::eGeneral, - .loadOp = vk::AttachmentLoadOp::eLoad, - .storeOp = vk::AttachmentStoreOp::eStore, - }; + color_attachments.push_back({ + .imageView = *image_view.image_view, + .imageLayout = vk::ImageLayout::eGeneral, + .loadOp = vk::AttachmentLoadOp::eLoad, + .storeOp = vk::AttachmentStoreOp::eStore, + }); + } // TODO: Don't restart renderpass every draw const auto& scissor = regs.screen_scissor; @@ -57,8 +64,8 @@ void Rasterizer::Draw(bool is_indexed) { .extent = {scissor.GetWidth(), scissor.GetHeight()}, }, .layerCount = 1, - .colorAttachmentCount = 1, - .pColorAttachments = &color_info, + .colorAttachmentCount = static_cast(color_attachments.size()), + .pColorAttachments = color_attachments.data(), }; UpdateDynamicState();