diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp index dd67467d0a..71b6b400e5 100644 --- a/src/dawn_native/d3d12/BufferD3D12.cpp +++ b/src/dawn_native/d3d12/BufferD3D12.cpp @@ -169,6 +169,7 @@ namespace dawn_native { namespace d3d12 { } void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) { + mWrittenMappedRange = {}; D3D12_RANGE readRange = {start, start + count}; char* data = nullptr; ASSERT_SUCCESS(mResource->Map(0, &readRange, reinterpret_cast(&data))); @@ -180,9 +181,9 @@ namespace dawn_native { namespace d3d12 { } void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) { - D3D12_RANGE readRange = {start, start + count}; + mWrittenMappedRange = {start, start + count}; char* data = nullptr; - ASSERT_SUCCESS(mResource->Map(0, &readRange, reinterpret_cast(&data))); + ASSERT_SUCCESS(mResource->Map(0, &mWrittenMappedRange, reinterpret_cast(&data))); // There is no need to transition the resource to a new state: D3D12 seems to make the CPU // writes available on queue submission. @@ -191,11 +192,9 @@ namespace dawn_native { namespace d3d12 { } void Buffer::UnmapImpl() { - // TODO(enga@google.com): When MapWrite is implemented, this should state the range that was - // modified - D3D12_RANGE writeRange = {}; - mResource->Unmap(0, &writeRange); + mResource->Unmap(0, &mWrittenMappedRange); ToBackend(GetDevice())->GetResourceAllocator()->Release(mResource); + mWrittenMappedRange = {}; } BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { diff --git a/src/dawn_native/d3d12/BufferD3D12.h b/src/dawn_native/d3d12/BufferD3D12.h index 4ff93ba4b1..9965d49e77 100644 --- a/src/dawn_native/d3d12/BufferD3D12.h +++ b/src/dawn_native/d3d12/BufferD3D12.h @@ -47,6 +47,7 @@ namespace dawn_native { namespace d3d12 { ComPtr mResource; bool mFixedResourceState = false; dawn::BufferUsageBit mLastUsage = dawn::BufferUsageBit::None; + D3D12_RANGE mWrittenMappedRange; }; class BufferView : public BufferViewBase {