Propagate more errors from reentrant calls

This CL propagates errors from reentrant WriteBuffer calls and makes
procy methods on BufferBase to show that it is safe to call
GetMappedRange and Unmap without handling errors.

Bug: dawn:723
Change-Id: I4ea43adc4844505314bf84e2357b2d928f1d1f8c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/46003
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Corentin Wallez 2021-03-31 11:24:42 +00:00 committed by Commit Bot service account
parent 348806be74
commit 79c9d125f2
7 changed files with 38 additions and 36 deletions

View File

@ -186,13 +186,11 @@ namespace dawn_native {
DeviceBase* device = GetDevice();
if (device->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
// TODO(dawn:723): propagate any errors from GetMappedRange.
memset(APIGetMappedRange(0, mSize), uint8_t(0u), mSize);
memset(GetMappedRange(0, mSize), uint8_t(0u), mSize);
SetIsDataInitialized();
device->IncrementLazyClearCountForTesting();
} else if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
// TODO(dawn:723): propagate any errors from GetMappedRange.
memset(APIGetMappedRange(0, mSize), uint8_t(1u), mSize);
memset(GetMappedRange(0, mSize), uint8_t(1u), mSize);
}
return {};
@ -294,14 +292,14 @@ namespace dawn_native {
}
void* BufferBase::APIGetMappedRange(size_t offset, size_t size) {
return GetMappedRangeInternal(true, offset, size);
return GetMappedRange(offset, size, true);
}
const void* BufferBase::APIGetConstMappedRange(size_t offset, size_t size) {
return GetMappedRangeInternal(false, offset, size);
return GetMappedRange(offset, size, false);
}
void* BufferBase::GetMappedRangeInternal(bool writable, size_t offset, size_t size) {
void* BufferBase::GetMappedRange(size_t offset, size_t size, bool writable) {
if (!CanGetMappedRange(writable, offset, size)) {
return nullptr;
}
@ -357,6 +355,10 @@ namespace dawn_native {
}
void BufferBase::APIUnmap() {
Unmap();
}
void BufferBase::Unmap() {
UnmapInternal(WGPUBufferMapAsyncStatus_UnmappedBeforeCallback);
}

View File

@ -61,6 +61,9 @@ namespace dawn_native {
bool IsDataInitialized() const;
void SetIsDataInitialized();
void* GetMappedRange(size_t offset, size_t size, bool writable = true);
void Unmap();
// Dawn API
void APIMapAsync(wgpu::MapMode mode,
size_t offset,
@ -91,7 +94,6 @@ namespace dawn_native {
virtual bool IsCPUWritableAtCreation() const = 0;
MaybeError CopyFromStagingBuffer();
void* GetMappedRangeInternal(bool writable, size_t offset, size_t size);
void CallMapCallback(MapRequestID mapID, WGPUBufferMapAsyncStatus status);
MaybeError ValidateMap(wgpu::BufferUsage requiredUsage,

View File

@ -399,7 +399,7 @@ namespace dawn_native {
return {};
}
void EncodeTimestampsToNanosecondsConversion(CommandEncoder* encoder,
MaybeError EncodeTimestampsToNanosecondsConversion(CommandEncoder* encoder,
QuerySetBase* querySet,
uint32_t queryCount,
BufferBase* destination,
@ -419,9 +419,9 @@ namespace dawn_native {
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
Ref<BufferBase> availabilityBuffer =
AcquireRef(device->APICreateBuffer(&availabilityDesc));
// TODO(dawn:723): propagate any errors from WriteBuffer.
device->GetQueue()->APIWriteBuffer(availabilityBuffer.Get(), 0, availability.data(),
availability.size() * sizeof(uint32_t));
DAWN_TRY(device->GetQueue()->WriteBuffer(availabilityBuffer.Get(), 0,
availability.data(),
availability.size() * sizeof(uint32_t)));
// Timestamp params uniform buffer
TimestampParams params = {queryCount, static_cast<uint32_t>(destinationOffset),
@ -431,11 +431,12 @@ namespace dawn_native {
parmsDesc.size = sizeof(params);
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
Ref<BufferBase> paramsBuffer = AcquireRef(device->APICreateBuffer(&parmsDesc));
// TODO(dawn:723): propagate any errors from WriteBuffer.
device->GetQueue()->APIWriteBuffer(paramsBuffer.Get(), 0, &params, sizeof(params));
DAWN_TRY(
device->GetQueue()->WriteBuffer(paramsBuffer.Get(), 0, &params, sizeof(params)));
EncodeConvertTimestampsToNanoseconds(encoder, destination, availabilityBuffer.Get(),
paramsBuffer.Get());
return {};
}
} // namespace
@ -869,8 +870,8 @@ namespace dawn_native {
// Encode internal compute pipeline for timestamp query
if (querySet->GetQueryType() == wgpu::QueryType::Timestamp &&
GetDevice()->IsToggleEnabled(Toggle::ConvertTimestampsToNanoseconds)) {
EncodeTimestampsToNanosecondsConversion(this, querySet, queryCount, destination,
destinationOffset);
DAWN_TRY(EncodeTimestampsToNanosecondsConversion(this, querySet, queryCount,
destination, destinationOffset));
}
return {};

View File

@ -273,9 +273,8 @@ namespace dawn_native {
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
Ref<BufferBase> uniformBuffer = AcquireRef(device->APICreateBuffer(&uniformDesc));
// TODO(dawn:723): propagate any errors from WriteBuffer.
device->GetQueue()->APIWriteBuffer(uniformBuffer.Get(), 0, uniformData,
sizeof(uniformData));
DAWN_TRY(device->GetQueue()->WriteBuffer(uniformBuffer.Get(), 0, uniformData,
sizeof(uniformData)));
// Prepare binding 1 resource: sampler
// Use default configuration, filterMode set to Nearest for min and mag.

View File

@ -266,10 +266,10 @@ namespace dawn_native {
uint64_t bufferOffset,
const void* data,
size_t size) {
GetDevice()->ConsumedError(WriteBufferInternal(buffer, bufferOffset, data, size));
GetDevice()->ConsumedError(WriteBuffer(buffer, bufferOffset, data, size));
}
MaybeError QueueBase::WriteBufferInternal(BufferBase* buffer,
MaybeError QueueBase::WriteBuffer(BufferBase* buffer,
uint64_t bufferOffset,
const void* data,
size_t size) {

View File

@ -57,6 +57,10 @@ namespace dawn_native {
const Extent3D* copySize,
const CopyTextureForBrowserOptions* options);
MaybeError WriteBuffer(BufferBase* buffer,
uint64_t bufferOffset,
const void* data,
size_t size);
void TrackTask(std::unique_ptr<TaskInFlight> task, ExecutionSerial serial);
void Tick(ExecutionSerial finishedSerial);
void HandleDeviceLoss();
@ -66,10 +70,6 @@ namespace dawn_native {
QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag);
private:
MaybeError WriteBufferInternal(BufferBase* buffer,
uint64_t bufferOffset,
const void* data,
size_t size);
MaybeError WriteTextureInternal(const ImageCopyTexture* destination,
const void* data,
size_t dataSize,

View File

@ -383,10 +383,8 @@ namespace dawn_native { namespace opengl {
DAWN_TRY_ASSIGN(srcBuffer, Buffer::CreateInternalBuffer(device, &descriptor, false));
// Fill the buffer with clear color
// TODO(dawn:723): propagate any errors from GetMappedRange.
memset(srcBuffer->APIGetMappedRange(0, descriptor.size), clearColor, descriptor.size);
// TODO(dawn:723): propagate any errors from Unmap.
srcBuffer->APIUnmap();
memset(srcBuffer->GetMappedRange(0, descriptor.size), clearColor, descriptor.size);
srcBuffer->Unmap();
// Bind buffer and texture, and make the buffer to texture copy
gl.PixelStorei(GL_UNPACK_ROW_LENGTH,