// Copyright 2023 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "dawn/native/EventManager.h" #include <algorithm> #include <functional> #include <utility> #include <vector> #include "dawn/common/Assert.h" #include "dawn/common/FutureUtils.h" #include "dawn/common/Log.h" #include "dawn/native/ChainUtils.h" #include "dawn/native/Device.h" #include "dawn/native/IntegerTypes.h" #include "dawn/native/Queue.h" #include "dawn/native/SystemEvent.h" #include "dawn/native/WaitAnySystemEvent.h" namespace dawn::native { namespace { // Ref<TrackedEvent> plus a few extra fields needed for some implementations. // Sometimes they'll be unused, but that's OK; it simplifies code reuse. struct TrackedFutureWaitInfo { … }; // Wrapper around an iterator to yield system event receiver and a pointer // to the ready bool. We pass this into WaitAnySystemEvent so it can extract // the receivers and get pointers to the ready status - without allocating // duplicate storage to store the receivers and ready bools. class SystemEventAndReadyStateIterator { … }; // Wait/poll the queue for futures in range [begin, end). `waitSerial` should be // the serial after which at least one future should be complete. All futures must // have completion data of type QueueAndSerial. // Returns true if at least one future is ready. If no futures are ready or the wait // timed out, returns false. bool WaitQueueSerialsImpl(DeviceBase* device, QueueBase* queue, ExecutionSerial waitSerial, std::vector<TrackedFutureWaitInfo>::iterator begin, std::vector<TrackedFutureWaitInfo>::iterator end, Nanoseconds timeout) { … } // We can replace the std::vector& when std::span is available via C++20. wgpu::WaitStatus WaitImpl(std::vector<TrackedFutureWaitInfo>& futures, Nanoseconds timeout) { … } // Reorder callbacks to enforce callback ordering required by the spec. // Returns an iterator just past the last ready callback. auto PrepareReadyCallbacks(std::vector<TrackedFutureWaitInfo>& futures) { … } } // namespace // EventManager EventManager::EventManager() { … } EventManager::~EventManager() { … } MaybeError EventManager::Initialize(const UnpackedPtr<InstanceDescriptor>& descriptor) { … } void EventManager::ShutDown() { … } bool EventManager::IsShutDown() const { … } FutureID EventManager::TrackEvent(Ref<TrackedEvent>&& event) { … } void EventManager::SetFutureReady(TrackedEvent* event) { … } bool EventManager::ProcessPollEvents() { … } wgpu::WaitStatus EventManager::WaitAny(size_t count, FutureWaitInfo* infos, Nanoseconds timeout) { … } // EventManager::TrackedEvent EventManager::TrackedEvent::TrackedEvent(wgpu::CallbackMode callbackMode, Ref<SystemEvent> completionEvent) : … { … } EventManager::TrackedEvent::TrackedEvent(wgpu::CallbackMode callbackMode, QueueBase* queue, ExecutionSerial completionSerial) : … { … } EventManager::TrackedEvent::TrackedEvent(wgpu::CallbackMode callbackMode, Completed tag) : … { … } EventManager::TrackedEvent::~TrackedEvent() { … } const EventManager::TrackedEvent::CompletionData& EventManager::TrackedEvent::GetCompletionData() const { … } void EventManager::TrackedEvent::EnsureComplete(EventCompletionType completionType) { … } } // namespace dawn::native