From 2008d15326a7249d783b616fe52d9f75f6bcf285 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 30 Jun 2020 11:05:44 +0000 Subject: [PATCH] Buffer: Always use MappedAtCreation state when applicable. In a follow-up CL we need to know if the buffer is in the MappedAtCreation state for validation of GetMappedRange. Having the state not 100% reflect the state in the spec meant that validation if GetMappedRange would fail for buffers mapped at creation for which IsMapWritable is true. Bug: dawn:445 Change-Id: I4a64335a708b838526da8d65f907b21c782816e0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23981 Commit-Queue: Corentin Wallez Reviewed-by: Kai Ninomiya --- src/dawn_native/Buffer.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp index 3c97655fba..21a5e43037 100644 --- a/src/dawn_native/Buffer.cpp +++ b/src/dawn_native/Buffer.cpp @@ -163,16 +163,15 @@ namespace dawn_native { ASSERT(!IsError()); ASSERT(mappedPointer != nullptr); + mState = BufferState::MappedAtCreation; + // Mappable buffers don't use a staging buffer and are just as if mapped through MapAsync. if (IsMapWritable()) { DAWN_TRY(MapAtCreationImpl(mappedPointer)); - mState = BufferState::Mapped; ASSERT(*mappedPointer != nullptr); return {}; } - mState = BufferState::MappedAtCreation; - // 0-sized buffers are not supposed to be written to, Return back any non-null pointer. if (mSize == 0) { *mappedPointer = reinterpret_cast(intptr_t(0xCAFED00D)); @@ -322,8 +321,9 @@ namespace dawn_native { } else if (mState == BufferState::MappedAtCreation) { if (mStagingBuffer != nullptr) { mStagingBuffer.reset(); - } else { - ASSERT(mSize == 0); + } else if (mSize != 0) { + ASSERT(IsMapWritable()); + Unmap(); } } @@ -371,8 +371,9 @@ namespace dawn_native { } else if (mState == BufferState::MappedAtCreation) { if (mStagingBuffer != nullptr) { GetDevice()->ConsumedError(CopyFromStagingBuffer()); - } else { - ASSERT(mSize == 0); + } else if (mSize != 0) { + ASSERT(IsMapWritable()); + UnmapImpl(); } }