Use typed integers for the Fence FenceAPISerial

This will prevent mixing it up with other serial types in the future.

Bug: dawn:442
Change-Id: I1cdb35ee01be3c771183003bc357c84d46aa5745
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28922
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2020-09-28 15:11:04 +00:00 committed by Commit Bot service account
parent 53cdbead78
commit 306fc502cf
7 changed files with 30 additions and 19 deletions

View File

@ -60,12 +60,14 @@ namespace dawn_native {
if (IsError()) { if (IsError()) {
return 0; return 0;
} }
return mCompletedValue; return uint64_t(mCompletedValue);
} }
void Fence::OnCompletion(uint64_t value, void Fence::OnCompletion(uint64_t apiValue,
wgpu::FenceOnCompletionCallback callback, wgpu::FenceOnCompletionCallback callback,
void* userdata) { void* userdata) {
FenceAPISerial value(apiValue);
WGPUFenceCompletionStatus status; WGPUFenceCompletionStatus status;
if (GetDevice()->ConsumedError(ValidateOnCompletion(value, &status))) { if (GetDevice()->ConsumedError(ValidateOnCompletion(value, &status))) {
callback(status, userdata); callback(status, userdata);
@ -84,7 +86,7 @@ namespace dawn_native {
mRequests.Enqueue(std::move(request), value); mRequests.Enqueue(std::move(request), value);
} }
uint64_t Fence::GetSignaledValue() const { FenceAPISerial Fence::GetSignaledValue() const {
ASSERT(!IsError()); ASSERT(!IsError());
return mSignalValue; return mSignalValue;
} }
@ -94,13 +96,13 @@ namespace dawn_native {
return mQueue.Get(); return mQueue.Get();
} }
void Fence::SetSignaledValue(uint64_t signalValue) { void Fence::SetSignaledValue(FenceAPISerial signalValue) {
ASSERT(!IsError()); ASSERT(!IsError());
ASSERT(signalValue > mSignalValue); ASSERT(signalValue > mSignalValue);
mSignalValue = signalValue; mSignalValue = signalValue;
} }
void Fence::SetCompletedValue(uint64_t completedValue) { void Fence::SetCompletedValue(FenceAPISerial completedValue) {
ASSERT(!IsError()); ASSERT(!IsError());
ASSERT(completedValue <= mSignalValue); ASSERT(completedValue <= mSignalValue);
ASSERT(completedValue > mCompletedValue); ASSERT(completedValue > mCompletedValue);
@ -116,7 +118,7 @@ namespace dawn_native {
mRequests.ClearUpTo(mCompletedValue); mRequests.ClearUpTo(mCompletedValue);
} }
MaybeError Fence::ValidateOnCompletion(uint64_t value, MaybeError Fence::ValidateOnCompletion(FenceAPISerial value,
WGPUFenceCompletionStatus* status) const { WGPUFenceCompletionStatus* status) const {
*status = WGPUFenceCompletionStatus_DeviceLost; *status = WGPUFenceCompletionStatus_DeviceLost;
DAWN_TRY(GetDevice()->ValidateIsAlive()); DAWN_TRY(GetDevice()->ValidateIsAlive());

View File

@ -18,6 +18,7 @@
#include "common/SerialMap.h" #include "common/SerialMap.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/IntegerTypes.h"
#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -34,7 +35,7 @@ namespace dawn_native {
static Fence* MakeError(DeviceBase* device); static Fence* MakeError(DeviceBase* device);
uint64_t GetSignaledValue() const; FenceAPISerial GetSignaledValue() const;
const QueueBase* GetQueue() const; const QueueBase* GetQueue() const;
// Dawn API // Dawn API
@ -44,24 +45,25 @@ namespace dawn_native {
protected: protected:
friend class QueueBase; friend class QueueBase;
friend class FenceSignalTracker; friend class FenceSignalTracker;
void SetSignaledValue(uint64_t signalValue); void SetSignaledValue(FenceAPISerial signalValue);
void SetCompletedValue(uint64_t completedValue); void SetCompletedValue(FenceAPISerial completedValue);
private: private:
Fence(DeviceBase* device, ObjectBase::ErrorTag tag); Fence(DeviceBase* device, ObjectBase::ErrorTag tag);
~Fence() override; ~Fence() override;
MaybeError ValidateOnCompletion(uint64_t value, WGPUFenceCompletionStatus* status) const; MaybeError ValidateOnCompletion(FenceAPISerial value,
WGPUFenceCompletionStatus* status) const;
struct OnCompletionData { struct OnCompletionData {
wgpu::FenceOnCompletionCallback completionCallback = nullptr; wgpu::FenceOnCompletionCallback completionCallback = nullptr;
void* userdata = nullptr; void* userdata = nullptr;
}; };
uint64_t mSignalValue; FenceAPISerial mSignalValue;
uint64_t mCompletedValue; FenceAPISerial mCompletedValue;
Ref<QueueBase> mQueue; Ref<QueueBase> mQueue;
SerialMap<Serial, OnCompletionData> mRequests; SerialMap<FenceAPISerial, OnCompletionData> mRequests;
}; };
} // namespace dawn_native } // namespace dawn_native

View File

@ -26,7 +26,7 @@ namespace dawn_native {
ASSERT(mFencesInFlight.Empty()); 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 // Because we currently only have a single queue, we can simply update
// the fence completed value once the last submitted serial has passed. // the fence completed value once the last submitted serial has passed.
mFencesInFlight.Enqueue(FenceInFlight{fence, value}, mFencesInFlight.Enqueue(FenceInFlight{fence, value},

View File

@ -17,6 +17,7 @@
#include "common/RefCounted.h" #include "common/RefCounted.h"
#include "common/SerialQueue.h" #include "common/SerialQueue.h"
#include "dawn_native/IntegerTypes.h"
namespace dawn_native { namespace dawn_native {
@ -26,14 +27,14 @@ namespace dawn_native {
class FenceSignalTracker { class FenceSignalTracker {
struct FenceInFlight { struct FenceInFlight {
Ref<Fence> fence; Ref<Fence> fence;
uint64_t value; FenceAPISerial value;
}; };
public: public:
FenceSignalTracker(DeviceBase* device); FenceSignalTracker(DeviceBase* device);
~FenceSignalTracker(); ~FenceSignalTracker();
void UpdateFenceOnComplete(Fence* fence, uint64_t value); void UpdateFenceOnComplete(Fence* fence, FenceAPISerial value);
void Tick(Serial finishedSerial); void Tick(Serial finishedSerial);

View File

@ -54,6 +54,9 @@ namespace dawn_native {
// that was sent. // that was sent.
using MapRequestID = TypedInteger<struct MapRequestIDT, uint64_t>; using MapRequestID = TypedInteger<struct MapRequestIDT, uint64_t>;
// The type for the WebGPU API fence serial values.
using FenceAPISerial = TypedInteger<struct FenceAPISerialT, uint64_t>;
} // namespace dawn_native } // namespace dawn_native
#endif // DAWNNATIVE_INTEGERTYPES_H_ #endif // DAWNNATIVE_INTEGERTYPES_H_

View File

@ -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(); DeviceBase* device = GetDevice();
if (device->ConsumedError(ValidateSignal(fence, signalValue))) { if (device->ConsumedError(ValidateSignal(fence, signalValue))) {
return; return;
@ -312,7 +314,7 @@ namespace dawn_native {
return {}; 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()->ValidateIsAlive());
DAWN_TRY(GetDevice()->ValidateObject(this)); DAWN_TRY(GetDevice()->ValidateObject(this));
DAWN_TRY(GetDevice()->ValidateObject(fence)); DAWN_TRY(GetDevice()->ValidateObject(fence));

View File

@ -17,6 +17,7 @@
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/IntegerTypes.h"
#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -65,7 +66,7 @@ namespace dawn_native {
const Extent3D& writeSize); const Extent3D& writeSize);
MaybeError ValidateSubmit(uint32_t commandCount, CommandBufferBase* const* commands) const; 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 ValidateCreateFence(const FenceDescriptor* descriptor) const;
MaybeError ValidateWriteBuffer(const BufferBase* buffer, MaybeError ValidateWriteBuffer(const BufferBase* buffer,
uint64_t bufferOffset, uint64_t bufferOffset,