D3D12: Simplify the mapping logic. This also removes the reliance on BufferBase::IsMapped to know whether to unmap on destroy. This call was confusing because it was used by the D3D12 backend to know if its own storage was mapped, but semantically seemed to check for Buffer::State::Mapped (and not MappedAtCreation). Bug: dawn:445 Change-Id: I3d6fde1d2996798d53264d5643545f0efb90551a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24060 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Brandon Jones <brandon1.jones@intel.com>
diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp index 92c2cea..f4dc904 100644 --- a/src/dawn_native/Buffer.cpp +++ b/src/dawn_native/Buffer.cpp
@@ -165,6 +165,13 @@ mState = BufferState::MappedAtCreation; + // 0-sized buffers are not supposed to be written to, Return back any non-null pointer. + // Handle 0-sized buffers first so we don't try to map them in the backend. + if (mSize == 0) { + *mappedPointer = reinterpret_cast<uint8_t*>(intptr_t(0xCAFED00D)); + return {}; + } + // Mappable buffers don't use a staging buffer and are just as if mapped through MapAsync. if (IsMapWritable()) { DAWN_TRY(MapAtCreationImpl(mappedPointer)); @@ -172,12 +179,6 @@ return {}; } - // 0-sized buffers are not supposed to be written to, Return back any non-null pointer. - if (mSize == 0) { - *mappedPointer = reinterpret_cast<uint8_t*>(intptr_t(0xCAFED00D)); - return {}; - } - // If any of these fail, the buffer will be deleted and replaced with an // error buffer. // TODO(enga): Suballocate and reuse memory from a larger staging buffer so we don't create @@ -483,10 +484,6 @@ mState = BufferState::Destroyed; } - bool BufferBase::IsMapped() const { - return mState == BufferState::Mapped; - } - void BufferBase::OnMapCommandSerialFinished(uint32_t mapSerial, bool isWrite) { void* data = GetMappedPointerImpl(); if (isWrite) {