Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various sync fixes #102

Merged
merged 4 commits into from
Nov 16, 2024
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
3 changes: 1 addition & 2 deletions src/render/ForwardRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ void ForwardRenderer::recordDraw(

const size_t pipelineIndex = options.transparents ? 1 : 0;

const uint32_t dsIndex =
nextFrame * MAX_FRAMES_IN_FLIGHT * 2 + m_nextFrameRecord;
const uint32_t dsIndex = nextFrame * 2 * 2 + m_nextFrameRecord;
const vk::DescriptorSet ds = m_meshSets[dsIndex];

updateDescriptorSet(
Expand Down
13 changes: 5 additions & 8 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ void blitFinalComposite(
const StaticArray barriers{{
*gRenderResources.images->transitionBarrier(
finalComposite, ImageState::TransferSrc, true),
// https://github.com/KhronosGroup/Vulkan-Docs/wiki/Synchronization-Examples#combined-graphicspresent-queue
vk::ImageMemoryBarrier2{
// TODO:
// What's the tight stage for this? Synchronization validation
// complained about a hazard after color attachment write which
// seems like an oddly specific stage for present source access to
// happen in.
.srcStageMask = vk::PipelineStageFlagBits2::eBottomOfPipe,
.srcAccessMask = vk::AccessFlags2{},
.srcStageMask = vk::PipelineStageFlagBits2::eColorAttachmentOutput,
.srcAccessMask = vk::AccessFlagBits2::eNone,
.dstStageMask = vk::PipelineStageFlagBits2::eTransfer,
.dstAccessMask = vk::AccessFlagBits2::eTransferWrite,
.oldLayout = vk::ImageLayout::eUndefined,
Expand Down Expand Up @@ -106,10 +102,11 @@ void blitFinalComposite(
}

{
// https://github.com/KhronosGroup/Vulkan-Docs/wiki/Synchronization-Examples#combined-graphicspresent-queue
const vk::ImageMemoryBarrier2 barrier{
.srcStageMask = vk::PipelineStageFlagBits2::eTransfer,
.srcAccessMask = vk::AccessFlagBits2::eTransferWrite,
.dstStageMask = vk::PipelineStageFlagBits2::eNone,
.dstStageMask = vk::PipelineStageFlagBits2::eColorAttachmentOutput,
.dstAccessMask = vk::AccessFlagBits2::eNone,
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
.newLayout = vk::ImageLayout::ePresentSrcKHR,
Expand Down
21 changes: 19 additions & 2 deletions src/utils/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GpuFrameProfiler::Scope::Scope(
.pLabelName = name,
});
cb.writeTimestamp2(
vk::PipelineStageFlagBits2::eTopOfPipe, m_pools.timestamps,
vk::PipelineStageFlagBits2::eAllCommands, m_pools.timestamps,
m_queryIndex * 2);
if (m_hasStatistics)
cb.beginQuery(
Expand All @@ -51,7 +51,7 @@ GpuFrameProfiler::Scope::~Scope()
if (m_hasStatistics)
m_cb.endQuery(m_pools.statistics, m_queryIndex);
m_cb.writeTimestamp2(
vk::PipelineStageFlagBits2::eBottomOfPipe, m_pools.timestamps,
vk::PipelineStageFlagBits2::eAllCommands, m_pools.timestamps,
m_queryIndex * 2 + 1);
m_cb.endDebugUtilsLabelEXT();
}
Expand Down Expand Up @@ -161,6 +161,23 @@ void GpuFrameProfiler::startFrame()

void GpuFrameProfiler::endFrame(vk::CommandBuffer cb)
{
// Full pipeline barrier as a workaround for vk::QueryResultFlagBits::eWait
// causing a device lost.
// TODO:
// Why does wait misbehave?
const vk::MemoryBarrier2KHR memoryBarrier = {
.srcStageMask = vk::PipelineStageFlagBits2::eAllCommands,
.srcAccessMask = vk::AccessFlagBits2::eMemoryRead |
vk::AccessFlagBits2::eMemoryWrite,
.dstStageMask = vk::PipelineStageFlagBits2::eAllCommands,
.dstAccessMask = vk::AccessFlagBits2::eMemoryRead |
vk::AccessFlagBits2::eMemoryWrite,
};
cb.pipelineBarrier2(vk::DependencyInfo{
.memoryBarrierCount = 1,
.pMemoryBarriers = &memoryBarrier,
});

cb.copyQueryPoolResults(
m_pools.timestamps, 0,
asserted_cast<uint32_t>(m_queryScopeIndices.size() * 2),
Expand Down
Loading