From 934130b3e61510d223879f8ed58b4ea8994fceeb Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Tue, 11 Jan 2022 19:25:53 +0530 Subject: [PATCH] Remove Implicit Command Executor Resource Attachment Any usage of a resource in a command now requires attaching that resource externally and will not be implicitly attached on usage, this makes attaching of resources consistent and allows for more lax locking requirements on resources as they can be locked while attaching and don't need to be for any commands, it also avoids redundantly attaching a resource in certain cases. --- .../skyline/gpu/interconnect/command_executor.cpp | 14 ++------------ .../skyline/gpu/interconnect/command_executor.h | 9 ++++----- .../skyline/gpu/interconnect/graphics_context.h | 5 +++-- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp index 49c159bd..39085795 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp @@ -30,9 +30,9 @@ namespace skyline::gpu::interconnect { if (!syncTextures.contains(texture)) { texture->WaitOnFence(); texture->cycle = cycle; - cycle->AttachObject(view->shared_from_this()); syncTextures.emplace(texture); } + cycle->AttachObject(view->shared_from_this()); } void CommandExecutor::AttachBuffer(BufferView *view) { @@ -45,17 +45,11 @@ namespace skyline::gpu::interconnect { } } - void CommandExecutor::AttachDependency(std::shared_ptr dependency) { + void CommandExecutor::AttachDependency(const std::shared_ptr &dependency) { cycle->AttachObject(dependency); } void CommandExecutor::AddSubpass(std::function &, GPU &, vk::RenderPass, u32)> &&function, vk::Rect2D renderArea, span inputAttachments, span colorAttachments, TextureView *depthStencilAttachment) { - for (const auto &attachments : {inputAttachments, colorAttachments}) - for (const auto &attachment : attachments) - AttachTexture(attachment); - if (depthStencilAttachment) - AttachTexture(depthStencilAttachment); - bool newRenderPass{CreateRenderPass(renderArea)}; renderPass->AddSubpass(inputAttachments, colorAttachments, depthStencilAttachment ? &*depthStencilAttachment : nullptr); if (newRenderPass) @@ -65,8 +59,6 @@ namespace skyline::gpu::interconnect { } void CommandExecutor::AddClearColorSubpass(TextureView *attachment, const vk::ClearColorValue &value) { - AttachTexture(attachment); - bool newRenderPass{CreateRenderPass(vk::Rect2D{ .extent = attachment->texture->dimensions, })}; @@ -96,8 +88,6 @@ namespace skyline::gpu::interconnect { } void CommandExecutor::AddClearDepthStencilSubpass(TextureView *attachment, const vk::ClearDepthStencilValue &value) { - AttachTexture(attachment); - bool newRenderPass{CreateRenderPass(vk::Rect2D{ .extent = attachment->texture->dimensions, })}; diff --git a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h index 3bdd3aba..6295d369 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h @@ -49,24 +49,23 @@ namespace skyline::gpu::interconnect { /** * @brief Attach the lifetime of the fence cycle dependency to the command buffer */ - void AttachDependency(std::shared_ptr dependency); + void AttachDependency(const std::shared_ptr &dependency); /** * @brief Adds a command that needs to be executed inside a subpass configured with certain attachments - * @note Any texture supplied to this **must** be locked by the calling thread, it should also undergo no persistent layout transitions till execution - * @note All attachments will automatically be attached and aren't required to be attached prior + * @note Any supplied texture should be attached prior and not undergo any persistent layout transitions till execution */ void AddSubpass(std::function &, GPU &, vk::RenderPass, u32)> &&function, vk::Rect2D renderArea, span inputAttachments = {}, span colorAttachments = {}, TextureView *depthStencilAttachment = {}); /** * @brief Adds a subpass that clears the entirety of the specified attachment with a color value, it may utilize VK_ATTACHMENT_LOAD_OP_CLEAR for a more efficient clear when possible - * @note Any texture supplied to this **must** be locked by the calling thread, it should also undergo no persistent layout transitions till execution + * @note Any supplied texture should be attached prior and not undergo any persistent layout transitions till execution */ void AddClearColorSubpass(TextureView *attachment, const vk::ClearColorValue &value); /** * @brief Adds a subpass that clears the entirety of the specified attachment with a depth/stencil value, it may utilize VK_ATTACHMENT_LOAD_OP_CLEAR for a more efficient clear when possible - * @note Any texture supplied to this **must** be locked by the calling thread, it should also undergo no persistent layout transitions till execution + * @note Any supplied texture should be attached prior and not undergo any persistent layout transitions till execution */ void AddClearDepthStencilSubpass(TextureView *attachment, const vk::ClearDepthStencilValue &value); diff --git a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h index 40728238..5e3cf842 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h @@ -442,6 +442,7 @@ namespace skyline::gpu::interconnect { void ClearColorRt(TextureView *renderTarget, vk::Rect2D scissor, u32 layerIndex) { std::lock_guard lock(*renderTarget); + executor.AttachTexture(renderTarget); scissor.extent.width = static_cast(std::min(static_cast(renderTarget->texture->dimensions.width) - scissor.offset.x, static_cast(scissor.extent.width))); @@ -473,6 +474,7 @@ namespace skyline::gpu::interconnect { void ClearDepthStencilRt(TextureView *renderTarget, vk::ImageAspectFlags aspect, u32 layerIndex) { std::lock_guard lock(*renderTarget); + executor.AttachTexture(renderTarget); if (renderTarget->range.layerCount == 1 && layerIndex == 0) { executor.AddClearDepthStencilSubpass(renderTarget, clearDepthValue); @@ -2112,7 +2114,6 @@ namespace skyline::gpu::interconnect { depthTargetLock.emplace(*depthRenderTargetView); // Vertex Buffer Setup - boost::container::static_vector, maxwell3d::VertexBufferCount> vertexBufferLocks; std::array vertexBufferHandles{}; std::array vertexBufferOffsets{}; @@ -2126,7 +2127,7 @@ namespace skyline::gpu::interconnect { vertexBindingDescriptions.push_back(vertexBuffer.bindingDescription); vertexBindingDivisorsDescriptions.push_back(vertexBuffer.bindingDivisorDescription); - vertexBufferLocks.emplace_back(*vertexBufferView); + std::scoped_lock vertexBufferLock(*vertexBufferView); executor.AttachBuffer(vertexBufferView); vertexBufferHandles[index] = vertexBufferView->buffer->GetBacking(); vertexBufferOffsets[index] = vertexBufferView->offset;