Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ namespace NovelRT::Ecs::Graphics
private:
struct PerFrameResources
{
uint64_t frameNumber;
uint64_t FrameNumber;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this following our clang-format guidelines?

I thought that private members should be camelCased, not PascalCased

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang tidy/clang format was enforcing it on me and I was getting annoyed lol, but also in a struct they're public


std::shared_ptr<NovelRT::Graphics::GraphicsSwapchainImage<TGraphicsBackend>> frameImage;
std::shared_ptr<NovelRT::Graphics::GraphicsContext<TGraphicsBackend>> localContext;
std::shared_ptr<NovelRT::Graphics::GraphicsSwapchainImage<TGraphicsBackend>> FrameImage;
std::shared_ptr<NovelRT::Graphics::GraphicsContext<TGraphicsBackend>> LocalContext;

std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsRenderTarget<TGraphicsBackend>>> renderTargets{};
std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsDescriptorSet<TGraphicsBackend>>> descriptorSets{};
std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsCmdList<TGraphicsBackend>>> commandLists{};
std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsRenderTarget<TGraphicsBackend>>> RenderTargets{};
std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsDescriptorSet<TGraphicsBackend>>> DescriptorSets{};
std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsCmdList<TGraphicsBackend>>> CommandLists{};
};

std::shared_ptr<NovelRT::Graphics::GraphicsDevice<TGraphicsBackend>> _graphicsDevice;
Expand Down Expand Up @@ -77,10 +77,14 @@ namespace NovelRT::Ecs::Graphics
std::vector<EntityId>& inOrder)
{
if (view.HasComponent(graph.GetRawEntityId()))
{
inOrder.push_back(graph.GetRawEntityId());
}

if (!graph.HasChildren())
{
return;
}

for (const auto& child : graph.GetOriginalChildren())
{
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}
}

Expand All @@ -162,20 +172,15 @@ 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);
}

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;
};

Expand All @@ -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<NovelRT::Graphics::GraphicsRenderTarget<TGraphicsBackend>>(
_graphicsDevice, imageViewData, pass, static_cast<uint32_t>(surface->GetWidth()),
static_cast<uint32_t>(surface->GetHeight())));
Expand All @@ -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;
Expand All @@ -226,7 +233,7 @@ namespace NovelRT::Ecs::Graphics
waitSemaphores.reserve(trackedSemaphores.GetImmutableDataLength());

std::vector<std::pair<std::shared_ptr<NovelRT::Graphics::GraphicsSemaphore<TGraphicsBackend>>, 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)
Expand All @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions Graphics/Core/include/NovelRT/Graphics/GraphicsCmdList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ namespace NovelRT::Graphics

void CmdEndRenderPass();

void CmdBindDescriptorSet(
const std::shared_ptr<GraphicsDescriptorSet<TBackend>>&
set);
void CmdBindDescriptorSet(const std::shared_ptr<GraphicsDescriptorSet<TBackend>>& set);

void CmdBindDescriptorSets(
NovelRT::Utilities::Span<std::reference_wrapper<const std::shared_ptr<GraphicsDescriptorSet<TBackend>>>>
Expand Down Expand Up @@ -122,9 +120,6 @@ namespace NovelRT::Graphics
void CmdBeginTexturePipelineBarrierLegacyVersion(const std::shared_ptr<GraphicsTexture<TBackend>>& texture);
void CmdEndTexturePipelineBarrierLegacyVersion(const std::shared_ptr<GraphicsTexture<TBackend>>& texture);

void CmdInitialSwapchainImageBarrierLegacyVersion(
const std::shared_ptr<GraphicsSwapchainImage<TBackend>>& swapchainImage);

void CmdBindPipeline(const std::shared_ptr<GraphicsPipeline<TBackend>>& pipeline);

void CmdPushConstants(const std::shared_ptr<GraphicsPipelineSignature<TBackend>>& pipelineSignature,
Expand Down
35 changes: 0 additions & 35 deletions Graphics/Vulkan/VulkanGraphicsCmdList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,41 +551,6 @@ namespace NovelRT::Graphics
}
}

void GraphicsCmdList<Vulkan::VulkanGraphicsBackend>::CmdInitialSwapchainImageBarrierLegacyVersion(
const std::shared_ptr<GraphicsSwapchainImage<Vulkan::VulkanGraphicsBackend>>& 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<VulkanGraphicsPipeline>& pipeline)
{
if (_commandBuffer == VK_NULL_HANDLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ namespace NovelRT::Graphics
void CmdEndTexturePipelineBarrierLegacyVersion(
const std::shared_ptr<GraphicsTexture<Vulkan::VulkanGraphicsBackend>>& texture);

void CmdInitialSwapchainImageBarrierLegacyVersion(
const std::shared_ptr<GraphicsSwapchainImage<Vulkan::VulkanGraphicsBackend>>& swapchainImage);

void CmdBindPipeline(const std::shared_ptr<GraphicsPipeline<Vulkan::VulkanGraphicsBackend>>& pipeline);

void CmdPushConstants(
Expand Down
Loading