From 6e5b08054755dc92f1559b46620d4a9635205c0a Mon Sep 17 00:00:00 2001 From: Li Hao Date: Tue, 27 Jul 2021 01:22:29 +0000 Subject: [PATCH] Improve buffer zero-initialization in resolveQuerySet on Vulkan Simplify the buffer clear logic, and tolerate clear twice when resolving unavailable queries if the destination buffer is not initialized and not fully written. Bug: dawn:973 Change-Id: Iaaf16acfd789787cb2f3eb18cd324c60d5f720b1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/59680 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Hao Li --- src/dawn_native/vulkan/CommandBufferVk.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index 64090795ca..0d6dcda580 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -732,27 +732,23 @@ namespace dawn_native { namespace vulkan { QuerySet* querySet = ToBackend(cmd->querySet.Get()); Buffer* destination = ToBackend(cmd->destination.Get()); + destination->EnsureDataInitializedAsDestination( + recordingContext, cmd->destinationOffset, + cmd->queryCount * sizeof(uint64_t)); + // vkCmdCopyQueryPoolResults only can retrieve available queries because - // VK_QUERY_RESULT_WAIT_BIT is set, for these unavailable queries, we need to - // clear the resolving region of the buffer to 0s if the buffer has been - // initialized or fully used. + // VK_QUERY_RESULT_WAIT_BIT is set. In order to resolve the unavailable queries + // as 0s, we need to clear the resolving region of the destination buffer to 0s. auto startIt = querySet->GetQueryAvailability().begin() + cmd->firstQuery; auto endIt = querySet->GetQueryAvailability().begin() + cmd->firstQuery + cmd->queryCount; bool hasUnavailableQueries = std::find(startIt, endIt, false) != endIt; - if (hasUnavailableQueries && - (destination->IsDataInitialized() || - destination->IsFullBufferRange(cmd->destinationOffset, - cmd->queryCount * sizeof(uint64_t)))) { + if (hasUnavailableQueries) { destination->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst); device->fn.CmdFillBuffer(commands, destination->GetHandle(), cmd->destinationOffset, cmd->queryCount * sizeof(uint64_t), 0u); - } else { - destination->EnsureDataInitializedAsDestination( - recordingContext, cmd->destinationOffset, - cmd->queryCount * sizeof(uint64_t)); } destination->TransitionUsageNow(recordingContext,