diff --git a/src/dawn_native/Fence.cpp b/src/dawn_native/Fence.cpp index f16274e9d3..5c2a64fe14 100644 --- a/src/dawn_native/Fence.cpp +++ b/src/dawn_native/Fence.cpp @@ -60,12 +60,14 @@ namespace dawn_native { if (IsError()) { return 0; } - return mCompletedValue; + return uint64_t(mCompletedValue); } - void Fence::OnCompletion(uint64_t value, + void Fence::OnCompletion(uint64_t apiValue, wgpu::FenceOnCompletionCallback callback, void* userdata) { + FenceAPISerial value(apiValue); + WGPUFenceCompletionStatus status; if (GetDevice()->ConsumedError(ValidateOnCompletion(value, &status))) { callback(status, userdata); @@ -84,7 +86,7 @@ namespace dawn_native { mRequests.Enqueue(std::move(request), value); } - uint64_t Fence::GetSignaledValue() const { + FenceAPISerial Fence::GetSignaledValue() const { ASSERT(!IsError()); return mSignalValue; } @@ -94,13 +96,13 @@ namespace dawn_native { return mQueue.Get(); } - void Fence::SetSignaledValue(uint64_t signalValue) { + void Fence::SetSignaledValue(FenceAPISerial signalValue) { ASSERT(!IsError()); ASSERT(signalValue > mSignalValue); mSignalValue = signalValue; } - void Fence::SetCompletedValue(uint64_t completedValue) { + void Fence::SetCompletedValue(FenceAPISerial completedValue) { ASSERT(!IsError()); ASSERT(completedValue <= mSignalValue); ASSERT(completedValue > mCompletedValue); @@ -116,7 +118,7 @@ namespace dawn_native { mRequests.ClearUpTo(mCompletedValue); } - MaybeError Fence::ValidateOnCompletion(uint64_t value, + MaybeError Fence::ValidateOnCompletion(FenceAPISerial value, WGPUFenceCompletionStatus* status) const { *status = WGPUFenceCompletionStatus_DeviceLost; DAWN_TRY(GetDevice()->ValidateIsAlive()); diff --git a/src/dawn_native/Fence.h b/src/dawn_native/Fence.h index b4fb821412..f5f4be6e34 100644 --- a/src/dawn_native/Fence.h +++ b/src/dawn_native/Fence.h @@ -18,6 +18,7 @@ #include "common/SerialMap.h" #include "dawn_native/Error.h" #include "dawn_native/Forward.h" +#include "dawn_native/IntegerTypes.h" #include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -34,7 +35,7 @@ namespace dawn_native { static Fence* MakeError(DeviceBase* device); - uint64_t GetSignaledValue() const; + FenceAPISerial GetSignaledValue() const; const QueueBase* GetQueue() const; // Dawn API @@ -44,24 +45,25 @@ namespace dawn_native { protected: friend class QueueBase; friend class FenceSignalTracker; - void SetSignaledValue(uint64_t signalValue); - void SetCompletedValue(uint64_t completedValue); + void SetSignaledValue(FenceAPISerial signalValue); + void SetCompletedValue(FenceAPISerial completedValue); private: Fence(DeviceBase* device, ObjectBase::ErrorTag tag); ~Fence() override; - MaybeError ValidateOnCompletion(uint64_t value, WGPUFenceCompletionStatus* status) const; + MaybeError ValidateOnCompletion(FenceAPISerial value, + WGPUFenceCompletionStatus* status) const; struct OnCompletionData { wgpu::FenceOnCompletionCallback completionCallback = nullptr; void* userdata = nullptr; }; - uint64_t mSignalValue; - uint64_t mCompletedValue; + FenceAPISerial mSignalValue; + FenceAPISerial mCompletedValue; Ref mQueue; - SerialMap mRequests; + SerialMap mRequests; }; } // namespace dawn_native diff --git a/src/dawn_native/FenceSignalTracker.cpp b/src/dawn_native/FenceSignalTracker.cpp index b8243a256c..2147ea6552 100644 --- a/src/dawn_native/FenceSignalTracker.cpp +++ b/src/dawn_native/FenceSignalTracker.cpp @@ -26,7 +26,7 @@ namespace dawn_native { ASSERT(mFencesInFlight.Empty()); } - void FenceSignalTracker::UpdateFenceOnComplete(Fence* fence, uint64_t value) { + void FenceSignalTracker::UpdateFenceOnComplete(Fence* fence, FenceAPISerial value) { // Because we currently only have a single queue, we can simply update // the fence completed value once the last submitted serial has passed. mFencesInFlight.Enqueue(FenceInFlight{fence, value}, diff --git a/src/dawn_native/FenceSignalTracker.h b/src/dawn_native/FenceSignalTracker.h index 623140f316..f1ea883012 100644 --- a/src/dawn_native/FenceSignalTracker.h +++ b/src/dawn_native/FenceSignalTracker.h @@ -17,6 +17,7 @@ #include "common/RefCounted.h" #include "common/SerialQueue.h" +#include "dawn_native/IntegerTypes.h" namespace dawn_native { @@ -26,14 +27,14 @@ namespace dawn_native { class FenceSignalTracker { struct FenceInFlight { Ref fence; - uint64_t value; + FenceAPISerial value; }; public: FenceSignalTracker(DeviceBase* device); ~FenceSignalTracker(); - void UpdateFenceOnComplete(Fence* fence, uint64_t value); + void UpdateFenceOnComplete(Fence* fence, FenceAPISerial value); void Tick(Serial finishedSerial); diff --git a/src/dawn_native/IntegerTypes.h b/src/dawn_native/IntegerTypes.h index 3b72722502..f7e97abe28 100644 --- a/src/dawn_native/IntegerTypes.h +++ b/src/dawn_native/IntegerTypes.h @@ -54,6 +54,9 @@ namespace dawn_native { // that was sent. using MapRequestID = TypedInteger; + // The type for the WebGPU API fence serial values. + using FenceAPISerial = TypedInteger; + } // namespace dawn_native #endif // DAWNNATIVE_INTEGERTYPES_H_ diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp index 3b7376eff9..c655139d4b 100644 --- a/src/dawn_native/Queue.cpp +++ b/src/dawn_native/Queue.cpp @@ -155,7 +155,9 @@ namespace dawn_native { } } - void QueueBase::Signal(Fence* fence, uint64_t signalValue) { + void QueueBase::Signal(Fence* fence, uint64_t apiSignalValue) { + FenceAPISerial signalValue(apiSignalValue); + DeviceBase* device = GetDevice(); if (device->ConsumedError(ValidateSignal(fence, signalValue))) { return; @@ -312,7 +314,7 @@ namespace dawn_native { return {}; } - MaybeError QueueBase::ValidateSignal(const Fence* fence, uint64_t signalValue) const { + MaybeError QueueBase::ValidateSignal(const Fence* fence, FenceAPISerial signalValue) const { DAWN_TRY(GetDevice()->ValidateIsAlive()); DAWN_TRY(GetDevice()->ValidateObject(this)); DAWN_TRY(GetDevice()->ValidateObject(fence)); diff --git a/src/dawn_native/Queue.h b/src/dawn_native/Queue.h index 2a0f7fc4d0..cf1d384082 100644 --- a/src/dawn_native/Queue.h +++ b/src/dawn_native/Queue.h @@ -17,6 +17,7 @@ #include "dawn_native/Error.h" #include "dawn_native/Forward.h" +#include "dawn_native/IntegerTypes.h" #include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -65,7 +66,7 @@ namespace dawn_native { const Extent3D& writeSize); MaybeError ValidateSubmit(uint32_t commandCount, CommandBufferBase* const* commands) const; - MaybeError ValidateSignal(const Fence* fence, uint64_t signalValue) const; + MaybeError ValidateSignal(const Fence* fence, FenceAPISerial signalValue) const; MaybeError ValidateCreateFence(const FenceDescriptor* descriptor) const; MaybeError ValidateWriteBuffer(const BufferBase* buffer, uint64_t bufferOffset,