Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 27c89d2

Browse files
ShabbyXCommit Bot
authored andcommitted
Vulkan: fix BufferVk::map() synchronization
4398b2b made finishToSerial() in BufferVk::map() conditional to whether the serial is in use to work around a performance regression. Notes: - Prior to 087f138, finishToSerial already did that, but that check was inadvertently removed. - finishToSerial waits for the smallest serial that's bigger than or equal to the requested serial. - The flush() call in BufferVk::map() was conditional to whether the serial is in use, but it really meant to check whether the buffer has pending commands in the graph. The end result is that there was an unnecessary flush in BufferVk::map() if we had to wait for a previous serial to finish. This change makes the flush conditional to whether the buffer has pending commands in the graph, and the finishToSerial call to whether the serial is not yet finished. Bug: angleproject:3994 Change-Id: Idca436ef2439bcc8c59396a07b2591c1dfadd669 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1932341 Reviewed-by: Brandon Schade <[email protected]> Reviewed-by: Shahbaz Youssefi <[email protected]> Commit-Queue: Shahbaz Youssefi <[email protected]>
1 parent 36ab960 commit 27c89d2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/libANGLE/renderer/vulkan/BufferVk.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,14 @@ angle::Result BufferVk::mapRangeImpl(ContextVk *contextVk,
222222
if ((access & GL_MAP_UNSYNCHRONIZED_BIT) == 0)
223223
{
224224
// If there are pending commands for the buffer, flush them.
225-
if (mBuffer.isResourceInUse(contextVk))
225+
if (mBuffer.isCurrentlyInGraph())
226226
{
227227
ANGLE_TRY(contextVk->flushImpl(nullptr));
228+
}
228229

229-
// Make sure the GPU is done with the buffer.
230+
// Make sure the GPU is done with the buffer.
231+
if (contextVk->isSerialInUse(mBuffer.getLatestSerial()))
232+
{
230233
ANGLE_TRY(contextVk->finishToSerial(mBuffer.getLatestSerial()));
231234
}
232235

src/libANGLE/renderer/vulkan/ContextVk.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ angle::Result CommandQueue::finishToSerial(vk::Context *context, Serial serial,
416416

417417
// Find the first batch with serial equal to or bigger than given serial (note that
418418
// the batch serials are unique, otherwise upper-bound would have been necessary).
419+
//
420+
// Note: we don't check for the exact serial, because it may belong to another context. For
421+
// example, imagine the following submissions:
422+
//
423+
// - Context 1: Serial 1, Serial 3, Serial 5
424+
// - Context 2: Serial 2, Serial 4, Serial 6
425+
//
426+
// And imagine none of the submissions have finished yet. Now if Context 2 asks for
427+
// finishToSerial(3), it will have no choice but to finish until Serial 4 instead.
419428
size_t batchIndex = mInFlightCommands.size() - 1;
420429
for (size_t i = 0; i < mInFlightCommands.size(); ++i)
421430
{

0 commit comments

Comments
 (0)