Bubble up potential errors during buffer.unmap().

Bug: dawn:1336
Change-Id: I715904874311349b4e996665dccc9d2d31959717
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122022
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung 2023-02-28 19:02:00 +00:00 committed by Dawn LUCI CQ
parent c2683a9459
commit f93f7ae8b1
5 changed files with 20 additions and 13 deletions

View File

@ -268,7 +268,7 @@ MaybeError BlitRG8ToDepth16Unorm(DeviceBase* device,
static_cast<uint32_t*>(paramsBuffer->GetMappedRange(0, bufferDesc.size));
params[0] = dst.origin.x;
params[1] = dst.origin.y;
paramsBuffer->Unmap();
DAWN_TRY(paramsBuffer->Unmap());
}
Ref<BindGroupBase> bindGroup;
@ -357,7 +357,7 @@ MaybeError BlitR8ToStencil(DeviceBase* device,
uint32_t* params = static_cast<uint32_t*>(paramsBuffer->GetMappedRange(0, bufferDesc.size));
params[0] = dst.origin.x;
params[1] = dst.origin.y;
paramsBuffer->Unmap();
DAWN_TRY(paramsBuffer->Unmap());
}
// For each layer, blit the stencil data.

View File

@ -506,29 +506,36 @@ void BufferBase::APIUnmap() {
if (GetDevice()->ConsumedError(ValidateUnmap(), "calling %s.Unmap().", this)) {
return;
}
Unmap();
}
void BufferBase::Unmap() {
if (mState == BufferState::Destroyed) {
if (GetDevice()->ConsumedError(Unmap(), "calling %s.Unmap().", this)) {
return;
}
}
MaybeError BufferBase::Unmap() {
if (mState == BufferState::Destroyed) {
return {};
}
// Make sure writes are now visibile to the GPU if we used a staging buffer.
if (mState == BufferState::MappedAtCreation && mStagingBuffer != nullptr) {
DAWN_TRY(CopyFromStagingBuffer());
}
UnmapInternal(WGPUBufferMapAsyncStatus_UnmappedBeforeCallback).Call();
return {};
}
BufferBase::PendingMappingCallback BufferBase::UnmapInternal(
WGPUBufferMapAsyncStatus callbackStatus) {
PendingMappingCallback toCall;
// Unmaps resources on the backend and returns the callback.
if (mState == BufferState::PendingMap) {
toCall = WillCallMappingCallback(mLastMapID, callbackStatus);
UnmapImpl();
} else if (mState == BufferState::Mapped) {
UnmapImpl();
} else if (mState == BufferState::MappedAtCreation) {
if (mStagingBuffer != nullptr) {
GetDevice()->ConsumedError(CopyFromStagingBuffer());
} else if (mSize != 0) {
if (!IsError() && mSize != 0 && IsCPUWritableAtCreation()) {
UnmapImpl();
}
}

View File

@ -77,7 +77,7 @@ class BufferBase : public ApiObjectBase {
virtual void* GetMappedPointer() = 0;
void* GetMappedRange(size_t offset, size_t size, bool writable = true);
void Unmap();
MaybeError Unmap();
// Dawn API
void APIMapAsync(wgpu::MapMode mode,

View File

@ -498,7 +498,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range,
// Fill the buffer with clear color
memset(srcBuffer->GetMappedRange(0, bufferSize), clearColor, bufferSize);
srcBuffer->Unmap();
DAWN_TRY(srcBuffer->Unmap());
gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER, srcBuffer->GetHandle());
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;

View File

@ -53,7 +53,7 @@ ResultOrError<Ref<BufferBase>> CreateBufferFromData(DeviceBase* device,
Ref<BufferBase> buffer;
DAWN_TRY_ASSIGN(buffer, device->CreateBuffer(&descriptor));
memcpy(buffer->GetMappedRange(0, size), data, size);
buffer->Unmap();
DAWN_TRY(buffer->Unmap());
return buffer;
}