GPUBuffer.unmap() shouldn't validate buffer state

WebGPU specification was updated that GPUBuffer.unmap()
shouldn't validate buffer state.

https://github.com/gpuweb/gpuweb/pull/3368

This commit reflects it to the Dawn implementation.

Bug: dawn:1528
Change-Id: Ie66f68214bd6896a4d674ed00addc3ffb539c235
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106264
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Takahiro <hogehoge@gachapin.jp>
This commit is contained in:
Takahiro 2022-11-04 00:08:27 +00:00 committed by Dawn LUCI CQ
parent 16b4cf87d0
commit e8cd0beb74
2 changed files with 16 additions and 28 deletions

View File

@ -539,19 +539,7 @@ bool BufferBase::CanGetMappedRange(bool writable, size_t offset, size_t size) co
MaybeError BufferBase::ValidateUnmap() const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
switch (mState) {
case BufferState::Mapped:
case BufferState::MappedAtCreation:
// A buffer may be in the Mapped state if it was created with mappedAtCreation
// even if it did not have a mappable usage.
return {};
case BufferState::Unmapped:
return DAWN_VALIDATION_ERROR("%s is unmapped.", this);
case BufferState::Destroyed:
return DAWN_VALIDATION_ERROR("%s is destroyed.", this);
}
UNREACHABLE();
return {};
}
void BufferBase::OnMapRequestCompleted(MapRequestID mapID, WGPUBufferMapAsyncStatus status) {

View File

@ -503,7 +503,7 @@ TEST_F(BufferValidationTest, DestroyDestroyedBuffer) {
buf.Destroy();
}
// Test that it is invalid to Unmap an error buffer
// Test that it is valid to Unmap an error buffer
TEST_F(BufferValidationTest, UnmapErrorBuffer) {
wgpu::BufferDescriptor desc;
desc.size = 4;
@ -511,20 +511,20 @@ TEST_F(BufferValidationTest, UnmapErrorBuffer) {
wgpu::Buffer buf;
ASSERT_DEVICE_ERROR(buf = device.CreateBuffer(&desc));
ASSERT_DEVICE_ERROR(buf.Unmap());
buf.Unmap();
}
// Test that it is invalid to Unmap a destroyed buffer
// Test that it is valid to Unmap a destroyed buffer
TEST_F(BufferValidationTest, UnmapDestroyedBuffer) {
{
wgpu::Buffer buf = CreateMapReadBuffer(4);
buf.Destroy();
ASSERT_DEVICE_ERROR(buf.Unmap());
buf.Unmap();
}
{
wgpu::Buffer buf = CreateMapWriteBuffer(4);
buf.Destroy();
ASSERT_DEVICE_ERROR(buf.Unmap());
buf.Unmap();
}
}
@ -626,35 +626,35 @@ TEST_F(BufferValidationTest, SubmitDestroyedBuffer) {
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
// Test that a map usage is required to call Unmap
// Test that a map usage is not required to call Unmap
TEST_F(BufferValidationTest, UnmapWithoutMapUsage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = wgpu::BufferUsage::CopyDst;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
ASSERT_DEVICE_ERROR(buf.Unmap());
buf.Unmap();
}
// Test that it is valid to call Unmap on a buffer that is not mapped
TEST_F(BufferValidationTest, UnmapUnmappedBuffer) {
{
wgpu::Buffer buf = CreateMapReadBuffer(4);
// Buffer starts unmapped. Unmap should fail.
ASSERT_DEVICE_ERROR(buf.Unmap());
// Buffer starts unmapped. Unmap shouldn't fail.
buf.Unmap();
buf.MapAsync(wgpu::MapMode::Read, 0, 4, nullptr, nullptr);
buf.Unmap();
// Unmapping a second time should fail.
ASSERT_DEVICE_ERROR(buf.Unmap());
// Unmapping a second time shouldn't fail.
buf.Unmap();
}
{
wgpu::Buffer buf = CreateMapWriteBuffer(4);
// Buffer starts unmapped. Unmap should fail.
ASSERT_DEVICE_ERROR(buf.Unmap());
// Buffer starts unmapped. Unmap shouldn't fail.
buf.Unmap();
buf.MapAsync(wgpu::MapMode::Write, 0, 4, nullptr, nullptr);
buf.Unmap();
// Unmapping a second time should fail.
ASSERT_DEVICE_ERROR(buf.Unmap());
// Unmapping a second time shouldn't fail.
buf.Unmap();
}
}