diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp index c0f6f428d9..87db6ac7c0 100644 --- a/src/dawn/native/Buffer.cpp +++ b/src/dawn/native/Buffer.cpp @@ -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) { diff --git a/src/dawn/tests/unittests/validation/BufferValidationTests.cpp b/src/dawn/tests/unittests/validation/BufferValidationTests.cpp index 7c5fcbb034..c943c4e820 100644 --- a/src/dawn/tests/unittests/validation/BufferValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/BufferValidationTests.cpp @@ -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(); } }