Skip to content

Commit 3a139d6

Browse files
committed
sync: Cleanup ApplyWait functionality
1 parent 23f2b61 commit 3a139d6

File tree

6 files changed

+67
-76
lines changed

6 files changed

+67
-76
lines changed

layers/sync/sync_access_state.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -873,38 +873,6 @@ void AccessState::ApplySemaphore(const SemaphoreScope &signal, const SemaphoreSc
873873
if (last_write.has_value()) last_write->dependency_chain = read_execution_barriers;
874874
}
875875

876-
// Read access predicate for queue wait
877-
bool AccessState::WaitQueueTagPredicate::operator()(const ReadState &read_access) const {
878-
return (read_access.queue == queue) && (read_access.tag <= tag) &&
879-
(read_access.stage != VK_PIPELINE_STAGE_2_PRESENT_ENGINE_BIT_SYNCVAL);
880-
}
881-
bool AccessState::WaitQueueTagPredicate::operator()(const AccessState &access) const {
882-
if (!access.last_write.has_value()) return false;
883-
const auto &write_state = *access.last_write;
884-
return write_state.queue == queue && (write_state.tag <= tag) &&
885-
write_state.access_index != SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_PRESENTED_SYNCVAL;
886-
}
887-
888-
// Read access predicate for queue wait
889-
bool AccessState::WaitTagPredicate::operator()(const ReadState &read_access) const {
890-
return (read_access.tag <= tag) && (read_access.stage != VK_PIPELINE_STAGE_2_PRESENT_ENGINE_BIT_SYNCVAL);
891-
}
892-
bool AccessState::WaitTagPredicate::operator()(const AccessState &access) const {
893-
if (!access.last_write.has_value()) return false;
894-
const auto &write_state = *access.last_write;
895-
return (write_state.tag <= tag) && write_state.access_index != SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_PRESENTED_SYNCVAL;
896-
}
897-
898-
// Present operations only matching only the *exactly* tagged present and acquire operations
899-
bool AccessState::WaitAcquirePredicate::operator()(const ReadState &read_access) const {
900-
return (read_access.tag == acquire_tag) && (read_access.stage == VK_PIPELINE_STAGE_2_PRESENT_ENGINE_BIT_SYNCVAL);
901-
}
902-
bool AccessState::WaitAcquirePredicate::operator()(const AccessState &access) const {
903-
if (!access.last_write.has_value()) return false;
904-
const auto &write_state = *access.last_write;
905-
return (write_state.tag == present_tag) && write_state.access_index == SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_PRESENTED_SYNCVAL;
906-
}
907-
908876
ResourceUsageRange AccessState::GetFirstAccessRange() const {
909877
if (first_accesses_.empty()) {
910878
return {};

layers/sync/sync_access_state.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -366,29 +366,6 @@ class AccessState {
366366

367367
void ApplySemaphore(const SemaphoreScope &signal, const SemaphoreScope &wait);
368368

369-
struct WaitQueueTagPredicate {
370-
QueueId queue;
371-
ResourceUsageTag tag;
372-
bool operator()(const ReadState &read_access) const; // Read access predicate
373-
bool operator()(const AccessState &access) const; // Write access predicate
374-
};
375-
friend WaitQueueTagPredicate;
376-
377-
struct WaitTagPredicate {
378-
ResourceUsageTag tag;
379-
bool operator()(const ReadState &read_access) const; // Read access predicate
380-
bool operator()(const AccessState &access) const; // Write access predicate
381-
};
382-
friend WaitTagPredicate;
383-
384-
struct WaitAcquirePredicate {
385-
ResourceUsageTag present_tag;
386-
ResourceUsageTag acquire_tag;
387-
bool operator()(const ReadState &read_access) const; // Read access predicate
388-
bool operator()(const AccessState &access) const; // Write access predicate
389-
};
390-
friend WaitAcquirePredicate;
391-
392369
// Clear read/write accesses that satisfy the predicate
393370
// (predicate says which accesses should be considered synchronized).
394371
// Return true if all accesses were cleared and access state is empty

layers/sync/sync_common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2019-2025 Valve Corporation
3-
* Copyright (c) 2019-2025 LunarG, Inc.
2+
* Copyright (c) 2019-2026 Valve Corporation
3+
* Copyright (c) 2019-2026 LunarG, Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ using ImageRangeGen = subresource_adapter::ImageRangeGenerator;
3232
// The resource tag index is relative to the command buffer or queue in which it's found
3333
using QueueId = uint32_t;
3434
constexpr static QueueId kQueueIdInvalid = QueueId(vvl::kNoIndex32);
35-
constexpr static QueueId kQueueAny = kQueueIdInvalid - 1;
3635

3736
using ResourceUsageTag = size_t;
3837

layers/sync/sync_submit.cpp

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -335,29 +335,76 @@ void QueueBatchContext::ApplyPredicatedWait(Predicate& predicate, const LastSync
335335
});
336336
}
337337

338+
struct WaitQueueTagPredicate {
339+
QueueId queue;
340+
ResourceUsageTag tag;
341+
342+
bool operator()(const ReadState& read_access) const {
343+
return read_access.queue == queue && read_access.tag <= tag &&
344+
read_access.stage != VK_PIPELINE_STAGE_2_PRESENT_ENGINE_BIT_SYNCVAL;
345+
}
346+
bool operator()(const AccessState& access) const {
347+
if (!access.HasWriteOp()) {
348+
return false;
349+
}
350+
const WriteState& write_state = access.LastWrite();
351+
return write_state.queue == queue && write_state.tag <= tag &&
352+
write_state.access_index != SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_PRESENTED_SYNCVAL;
353+
}
354+
};
355+
356+
struct DeviceWaitPredicate {
357+
bool operator()(const ReadState& read_access) const {
358+
return read_access.stage != VK_PIPELINE_STAGE_2_PRESENT_ENGINE_BIT_SYNCVAL;
359+
}
360+
bool operator()(const AccessState& access) const {
361+
if (!access.HasWriteOp()) {
362+
return false;
363+
}
364+
return access.LastWrite().access_index != SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_PRESENTED_SYNCVAL;
365+
}
366+
};
367+
368+
// Present operations matching only the *exactly* tagged present and acquire operations
369+
struct WaitAcquirePredicate {
370+
ResourceUsageTag present_tag;
371+
ResourceUsageTag acquire_tag;
372+
373+
bool operator()(const ReadState& read_access) const {
374+
return read_access.tag == acquire_tag && read_access.stage == VK_PIPELINE_STAGE_2_PRESENT_ENGINE_BIT_SYNCVAL;
375+
}
376+
bool operator()(const AccessState& access) const {
377+
if (!access.HasWriteOp()) {
378+
return false;
379+
}
380+
const WriteState& write_state = access.LastWrite();
381+
return write_state.tag == present_tag && write_state.access_index == SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_PRESENTED_SYNCVAL;
382+
}
383+
};
384+
338385
void QueueBatchContext::ApplyTaggedWait(QueueId queue_id, ResourceUsageTag tag,
339386
const LastSynchronizedPresent& last_synchronized_present) {
340-
const bool any_queue = (queue_id == kQueueAny);
341-
342-
if (any_queue) {
343-
// This isn't just avoid an unneeded test, but to allow *all* queues to to be waited in a single pass
344-
// (and it does avoid doing the same test for every access, as well as avoiding the need for the predicate
345-
// to grok Queue/Device/Wait differences.
346-
AccessState::WaitTagPredicate predicate{tag};
347-
ApplyPredicatedWait(predicate, last_synchronized_present);
348-
} else {
349-
AccessState::WaitQueueTagPredicate predicate{queue_id, tag};
350-
ApplyPredicatedWait(predicate, last_synchronized_present);
351-
}
387+
WaitQueueTagPredicate predicate{queue_id, tag};
388+
ApplyPredicatedWait(predicate, last_synchronized_present);
352389

353-
// SwapChain acquire QBC's have no queue, but also, events are always empty.
354-
if (queue_state_ && (queue_id == GetQueueId() || any_queue)) {
390+
// SwapChain acquire batch contexts have no queue
391+
if (queue_state_ && queue_id == GetQueueId()) {
355392
events_context_.ApplyTaggedWait(queue_state_->GetQueueFlags(), tag);
356393
}
357394
}
358395

396+
void QueueBatchContext::ApplyDeviceWait(const LastSynchronizedPresent& last_synchronized_present) {
397+
DeviceWaitPredicate predicate;
398+
ApplyPredicatedWait(predicate, last_synchronized_present);
399+
400+
// SwapChain acquire batch contexts have no queue
401+
if (queue_state_) {
402+
events_context_.ApplyTaggedWait(queue_state_->GetQueueFlags(), ResourceUsageRecord::kMaxIndex);
403+
}
404+
}
405+
359406
void QueueBatchContext::ApplyAcquireWait(const AcquiredImage& acquired) {
360-
AccessState::WaitAcquirePredicate predicate{acquired.present_tag, acquired.acquire_tag};
407+
WaitAcquirePredicate predicate{acquired.present_tag, acquired.acquire_tag};
361408
ApplyPredicatedWait(predicate, {});
362409
}
363410

layers/sync/sync_submit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class QueueBatchContext : public CommandExecutionContext, public std::enable_sha
360360
template <typename Predicate>
361361
void ApplyPredicatedWait(Predicate &predicate, const LastSynchronizedPresent &last_synchronized_present);
362362
void ApplyTaggedWait(QueueId queue_id, ResourceUsageTag tag, const LastSynchronizedPresent &last_synchronized_present);
363+
void ApplyDeviceWait(const LastSynchronizedPresent &last_synchronized_present);
363364
void ApplyAcquireWait(const AcquiredImage &acquired);
364365
void OnResourceDestroyed(const AccessRange &resource_range);
365366

layers/sync/sync_validation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,10 +2394,9 @@ void SyncValidator::PostCallRecordDeviceWaitIdle(VkDevice device, const RecordOb
23942394
global_last_synchronized_present.Merge(batch->last_synchronized_present);
23952395
}
23962396

2397-
// DeviceWaitIdle is equivalent to waiting on the fence on all queues.
2398-
// Tagged wait will preserve unsynchronized present operations.
2397+
// Device wait will preserve unsynchronized present operations.
23992398
for (const auto &batch : batches) {
2400-
batch->ApplyTaggedWait(kQueueAny, ResourceUsageRecord::kMaxIndex, global_last_synchronized_present);
2399+
batch->ApplyDeviceWait(global_last_synchronized_present);
24012400
}
24022401

24032402
// For each timeline keep only the last signal per queue.

0 commit comments

Comments
 (0)