From 205c0158db5b15a6a1b27eacb9c25a8862c90561 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Thu, 31 Oct 2024 01:18:22 +0000 Subject: [PATCH] D3D12: Clear `mZeroBuffer` in the initialization of `Device` This patch clears `mZeroBuffer` to 0 in the initialization of `Device` instead of the function `ClearBufferToZero()` as the old test failures are all gone with current Dawn implementation. Bug: chromium:42242085 Test: dawn_end2end_tests Change-Id: I57b74361b09e6d6f338a77b2be814638d9d05426 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/212823 Reviewed-by: Loko Kung Commit-Queue: Jiawei Shao Reviewed-by: Corentin Wallez --- src/dawn/native/d3d12/DeviceD3D12.cpp | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index fecb72b37aa..79298423fa4 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -297,6 +297,21 @@ MaybeError Device::CreateZeroBuffer() { zeroBufferDescriptor.label = "ZeroBuffer_Internal"; DAWN_TRY_ASSIGN(mZeroBuffer, Buffer::Create(this, Unpack(&zeroBufferDescriptor))); + CommandRecordingContext* commandContext = + ToBackend(GetQueue())->GetPendingCommandContext(QueueBase::SubmitMode::Passive); + + DynamicUploader* uploader = GetDynamicUploader(); + UploadHandle uploadHandle; + DAWN_TRY_ASSIGN(uploadHandle, + uploader->Allocate(kZeroBufferSize, GetQueue()->GetPendingCommandSerial(), + kCopyBufferToBufferOffsetAlignment)); + + memset(uploadHandle.mappedBuffer, 0u, kZeroBufferSize); + + CopyFromStagingToBufferHelper(commandContext, uploadHandle.stagingBuffer, + uploadHandle.startOffset, mZeroBuffer.Get(), 0, kZeroBufferSize); + + mZeroBuffer->SetInitialized(true); return {}; } @@ -304,26 +319,6 @@ MaybeError Device::ClearBufferToZero(CommandRecordingContext* commandContext, BufferBase* destination, uint64_t offset, uint64_t size) { - // TODO(crbug.com/dawn/852): It would be ideal to clear the buffer in CreateZeroBuffer, but - // the allocation of the staging buffer causes various end2end tests that monitor heap usage - // to fail if it's done during device creation. Perhaps ClearUnorderedAccessView*() can be - // used to avoid that. - if (!mZeroBuffer->IsInitialized()) { - DynamicUploader* uploader = GetDynamicUploader(); - UploadHandle uploadHandle; - DAWN_TRY_ASSIGN(uploadHandle, - uploader->Allocate(kZeroBufferSize, GetQueue()->GetPendingCommandSerial(), - kCopyBufferToBufferOffsetAlignment)); - - memset(uploadHandle.mappedBuffer, 0u, kZeroBufferSize); - - CopyFromStagingToBufferHelper(commandContext, uploadHandle.stagingBuffer, - uploadHandle.startOffset, mZeroBuffer.Get(), 0, - kZeroBufferSize); - - mZeroBuffer->SetInitialized(true); - } - Buffer* dstBuffer = ToBackend(destination); // Necessary to ensure residency of the zero buffer.