diff --git a/Ecs/Graphics/include/NovelRT/Ecs/Graphics/RenderOrchestratorSystem.hpp b/Ecs/Graphics/include/NovelRT/Ecs/Graphics/RenderOrchestratorSystem.hpp index 43014ee5e..0a8db2f5d 100644 --- a/Ecs/Graphics/include/NovelRT/Ecs/Graphics/RenderOrchestratorSystem.hpp +++ b/Ecs/Graphics/include/NovelRT/Ecs/Graphics/RenderOrchestratorSystem.hpp @@ -39,14 +39,14 @@ namespace NovelRT::Ecs::Graphics private: struct PerFrameResources { - uint64_t frameNumber; + uint64_t FrameNumber; - std::shared_ptr> frameImage; - std::shared_ptr> localContext; + std::shared_ptr> FrameImage; + std::shared_ptr> LocalContext; - std::vector>> renderTargets{}; - std::vector>> descriptorSets{}; - std::vector>> commandLists{}; + std::vector>> RenderTargets{}; + std::vector>> DescriptorSets{}; + std::vector>> CommandLists{}; }; std::shared_ptr> _graphicsDevice; @@ -77,10 +77,14 @@ namespace NovelRT::Ecs::Graphics std::vector& inOrder) { if (view.HasComponent(graph.GetRawEntityId())) + { inOrder.push_back(graph.GetRawEntityId()); + } if (!graph.HasChildren()) + { return; + } for (const auto& child : graph.GetOriginalChildren()) { @@ -108,12 +112,15 @@ namespace NovelRT::Ecs::Graphics { // 1. Clean up any resources that are no longer valid. auto lastRenderedFrame = _deletionSemaphore->GetValue(); + if (lastRenderedFrame > 0) + { lastRenderedFrame -= 1; // this is important to avoid underflow + } _frameResources.erase(std::remove_if(_frameResources.begin(), _frameResources.end(), [lastRenderedFrame](auto& it) - { return it.frameNumber < lastRenderedFrame; }), + { return it.FrameNumber < lastRenderedFrame; }), _frameResources.end()); // 2. Determine the order in which we should enumerate the entities based on their render pass @@ -134,8 +141,11 @@ namespace NovelRT::Ecs::Graphics { auto root = GetRoot(graph, catalogue, entity); auto [it, insertedTwo] = rootEntities.insert(root.GetRawEntityId()); + if (insertedTwo) + { roots.emplace_back(std::move(root)); + } } } @@ -162,11 +172,6 @@ namespace NovelRT::Ecs::Graphics cmdList->CmdTransitionSwapchainImageTo(image, NovelRT::Graphics::ImageLayout::DstTransfer, NovelRT::Graphics::ImageLayout::Present); - if (!passes.empty()) - { - cmdList->CmdInitialSwapchainImageBarrierLegacyVersion(image); - } - for (auto& root : roots) { EnumerateChildren(root, renderPasses, ordered); @@ -174,8 +179,8 @@ namespace NovelRT::Ecs::Graphics auto sorter = [&ordered](EntityId left, EntityId right) { - auto leftPos = std::distance(ordered.begin(), std::find(ordered.begin(), ordered.end(), left)); - auto rightPos = std::distance(ordered.begin(), std::find(ordered.begin(), ordered.end(), right)); + auto leftPos = std::distance(ordered.begin(), std::ranges::find(ordered, left)); + auto rightPos = std::distance(ordered.begin(), std::ranges::find(ordered, right)); return leftPos < rightPos; }; @@ -187,7 +192,7 @@ namespace NovelRT::Ecs::Graphics // 6. Prepare the render pass auto pass = _renderPassManager.GetRenderPass(passId); - auto target = frameResources.renderTargets.emplace_back( + auto target = frameResources.RenderTargets.emplace_back( std::make_shared>( _graphicsDevice, imageViewData, pass, static_cast(surface->GetWidth()), static_cast(surface->GetHeight()))); @@ -197,16 +202,18 @@ namespace NovelRT::Ecs::Graphics for (const auto entity : entities) { if (!commandLists.HasComponent(entity)) + { continue; + } auto* subCmdListPtr = commandLists.GetComponent(entity).commandList; - auto subCmdList = frameResources.commandLists.emplace_back(*subCmdListPtr); + auto subCmdList = frameResources.CommandLists.emplace_back(*subCmdListPtr); auto renderPassComponent = renderPasses.GetComponent(entity); auto* descriptorSetsPtr = renderPassComponent.descriptorSets; for (size_t i = 0; i < renderPassComponent.descriptorSetCount; i++) { - frameResources.descriptorSets.emplace_back(descriptorSetsPtr[i]); + frameResources.DescriptorSets.emplace_back(descriptorSetsPtr[i]); } delete subCmdListPtr; @@ -226,7 +233,7 @@ namespace NovelRT::Ecs::Graphics waitSemaphores.reserve(trackedSemaphores.GetImmutableDataLength()); std::vector>, uint64_t>> - signalSemaphores{std::make_pair(_deletionSemaphore, frameResources.frameNumber)}; + signalSemaphores{std::make_pair(_deletionSemaphore, frameResources.FrameNumber)}; signalSemaphores.reserve(trackedSemaphores.GetImmutableDataLength()); for (auto&& [entity, trackedSemaLocal] : trackedSemaphores) @@ -251,7 +258,7 @@ namespace NovelRT::Ecs::Graphics commandLists.RemoveAllComponents(); trackedSemaphores.RemoveAllComponents(); - frameResources.commandLists.emplace_back(cmdList); + frameResources.CommandLists.emplace_back(cmdList); // TODO: should this be in ECS? _graphicsDevice->EndFrame(); diff --git a/Graphics/Core/include/NovelRT/Graphics/GraphicsCmdList.hpp b/Graphics/Core/include/NovelRT/Graphics/GraphicsCmdList.hpp index fbcbd37f5..178c12f47 100644 --- a/Graphics/Core/include/NovelRT/Graphics/GraphicsCmdList.hpp +++ b/Graphics/Core/include/NovelRT/Graphics/GraphicsCmdList.hpp @@ -84,9 +84,7 @@ namespace NovelRT::Graphics void CmdEndRenderPass(); - void CmdBindDescriptorSet( - const std::shared_ptr>& - set); + void CmdBindDescriptorSet(const std::shared_ptr>& set); void CmdBindDescriptorSets( NovelRT::Utilities::Span>>> @@ -122,9 +120,6 @@ namespace NovelRT::Graphics void CmdBeginTexturePipelineBarrierLegacyVersion(const std::shared_ptr>& texture); void CmdEndTexturePipelineBarrierLegacyVersion(const std::shared_ptr>& texture); - void CmdInitialSwapchainImageBarrierLegacyVersion( - const std::shared_ptr>& swapchainImage); - void CmdBindPipeline(const std::shared_ptr>& pipeline); void CmdPushConstants(const std::shared_ptr>& pipelineSignature, diff --git a/Graphics/Vulkan/VulkanGraphicsCmdList.cpp b/Graphics/Vulkan/VulkanGraphicsCmdList.cpp index 30c168430..ca5aa9462 100644 --- a/Graphics/Vulkan/VulkanGraphicsCmdList.cpp +++ b/Graphics/Vulkan/VulkanGraphicsCmdList.cpp @@ -551,41 +551,6 @@ namespace NovelRT::Graphics } } - void GraphicsCmdList::CmdInitialSwapchainImageBarrierLegacyVersion( - const std::shared_ptr>& swapchainImage) - { - VkImageSubresourceRange subresourceRange{}; - subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - subresourceRange.levelCount = 1; - subresourceRange.layerCount = 1; - - VkImageMemoryBarrier barrier{}; - barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.srcAccessMask = 0; - barrier.dstAccessMask = 0; - barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; - barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; - barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - barrier.image = swapchainImage->GetVulkanImage(); - barrier.subresourceRange = subresourceRange; - - if (_commandBuffer == VK_NULL_HANDLE) - { - _replayData.emplace_back( - [barrier](VkCommandBuffer cmdBuffer) - { - vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); - }); - } - else - { - vkCmdPipelineBarrier(_commandBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, - VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier); - } - } - void VulkanGraphicsCmdList::CmdBindPipeline(const std::shared_ptr& pipeline) { if (_commandBuffer == VK_NULL_HANDLE) diff --git a/Graphics/Vulkan/include/NovelRT/Graphics/Vulkan/VulkanGraphicsCmdList.hpp b/Graphics/Vulkan/include/NovelRT/Graphics/Vulkan/VulkanGraphicsCmdList.hpp index fb09e8cf9..b04528643 100644 --- a/Graphics/Vulkan/include/NovelRT/Graphics/Vulkan/VulkanGraphicsCmdList.hpp +++ b/Graphics/Vulkan/include/NovelRT/Graphics/Vulkan/VulkanGraphicsCmdList.hpp @@ -100,9 +100,6 @@ namespace NovelRT::Graphics void CmdEndTexturePipelineBarrierLegacyVersion( const std::shared_ptr>& texture); - void CmdInitialSwapchainImageBarrierLegacyVersion( - const std::shared_ptr>& swapchainImage); - void CmdBindPipeline(const std::shared_ptr>& pipeline); void CmdPushConstants(