Skip to content

Commit

Permalink
D3D12: Clear mZeroBuffer in the initialization of Device
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Jiawei Shao <[email protected]>
Reviewed-by: Corentin Wallez <[email protected]>
  • Loading branch information
Jiawei-Shao authored and Dawn LUCI CQ committed Oct 31, 2024
1 parent 1f22d41 commit 205c015
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/dawn/native/d3d12/DeviceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,33 +297,28 @@ 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 {};
}

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.
Expand Down

0 comments on commit 205c015

Please sign in to comment.