d3d11: Fix the failing BufferMapping cases.

This adds buffer usage tracking and corrects the usage of pending
command context.

Bug: dawn:1705
Change-Id: If327169429d4e0909bbcaa87a14bac9ef01ac2ad
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128180
Reviewed-by: Peng Huang <penghuang@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
jchen10 2023-04-22 02:33:45 +00:00 committed by Dawn LUCI CQ
parent 9b726858ff
commit 2fd411f7fe
6 changed files with 13 additions and 17 deletions

View File

@ -407,6 +407,7 @@ MaybeError Buffer::Write(CommandRecordingContext* commandContext,
return {};
}
MarkUsedInPendingCommands();
// Map the buffer if it is possible, so EnsureDataInitializedAsDestination() and WriteInternal()
// can write the mapped memory directly.
ScopedMap scopedMap;

View File

@ -296,6 +296,8 @@ MaybeError CommandBuffer::Execute() {
// Buffer::Copy() will ensure the source and destination buffers are initialized.
DAWN_TRY(Buffer::Copy(commandContext, source, copy->sourceOffset, copy->size,
destination, copy->destinationOffset));
source->MarkUsedInPendingCommands();
destination->MarkUsedInPendingCommands();
break;
}
@ -326,6 +328,7 @@ MaybeError CommandBuffer::Execute() {
DAWN_TRY(texture->Write(commandContext, subresources, copy->destination.origin,
copy->copySize, data, copy->source.bytesPerRow,
copy->source.rowsPerImage));
buffer->MarkUsedInPendingCommands();
break;
}
@ -423,6 +426,7 @@ MaybeError CommandBuffer::Execute() {
d3d11DeviceContext1->Unmap(stagingTexture.Get(), z);
}
dst.buffer->MarkUsedInPendingCommands();
break;
}
@ -446,6 +450,7 @@ MaybeError CommandBuffer::Execute() {
}
Buffer* buffer = ToBackend(cmd->buffer.Get());
DAWN_TRY(buffer->Clear(commandContext, 0, cmd->offset, cmd->size));
buffer->MarkUsedInPendingCommands();
break;
}
@ -467,6 +472,7 @@ MaybeError CommandBuffer::Execute() {
Buffer* dstBuffer = ToBackend(cmd->buffer.Get());
uint8_t* data = mCommands.NextData<uint8_t>(cmd->size);
DAWN_TRY(dstBuffer->Write(commandContext, cmd->offset, data, cmd->size));
dstBuffer->MarkUsedInPendingCommands();
break;
}

View File

@ -76,6 +76,7 @@ MaybeError CommandRecordingContext::Open(Device* device) {
MaybeError CommandRecordingContext::ExecuteCommandList(Device* device) {
// Consider using deferred DeviceContext.
mNeedsSubmit = false;
return {};
}

View File

@ -183,7 +183,8 @@ MaybeError Device::NextSerial() {
TRACE_EVENT1(GetPlatform(), General, "D3D11Device::SignalFence", "serial",
uint64_t(GetLastSubmittedCommandSerial()));
CommandRecordingContext* commandContext = GetPendingCommandContext();
CommandRecordingContext* commandContext =
GetPendingCommandContext(DeviceBase::SubmitMode::Passive);
DAWN_TRY(CheckHRESULT(commandContext->GetD3D11DeviceContext4()->Signal(
mFence.Get(), uint64_t(GetLastSubmittedCommandSerial())),
"D3D11 command queue signal fence"));
@ -228,14 +229,10 @@ bool Device::HasPendingCommands() const {
return mPendingCommands.NeedsSubmit();
}
void Device::ForceEventualFlushOfCommands() {
if (mPendingCommands.IsOpen()) {
mPendingCommands.SetNeedsSubmit();
}
}
void Device::ForceEventualFlushOfCommands() {}
MaybeError Device::ExecutePendingCommandContext() {
return {};
return mPendingCommands.ExecuteCommandList(this);
}
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(

View File

@ -38,6 +38,7 @@ MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* co
for (uint32_t i = 0; i < commandCount; ++i) {
DAWN_TRY(ToBackend(commands[i])->Execute());
}
DAWN_TRY(device->ExecutePendingCommandContext());
TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferD3D11::Execute");
DAWN_TRY(device->NextSerial());

View File

@ -634,11 +634,6 @@ TEST_P(BufferMappingCallbackTests, EmptySubmissionAndThenMap) {
}
TEST_P(BufferMappingCallbackTests, UseTheBufferAndThenMap) {
// TODO(dawn:1705): enable this test for D3D11. D3D11 MapAsync() calls
// ID3D11DeviceContext::Map() which will synchronize with GPU. so the callback will always be
// called earlier comparing to other backends.
DAWN_SUPPRESS_TEST_IF(IsD3D11());
wgpu::Buffer buffer = CreateMapWriteBuffer(4);
MapAsyncAndWait(buffer, wgpu::MapMode::Write, 0, wgpu::kWholeMapSize);
buffer.Unmap();
@ -678,11 +673,6 @@ TEST_P(BufferMappingCallbackTests, UseTheBufferAndThenMap) {
}
TEST_P(BufferMappingCallbackTests, EmptySubmissionWriteAndThenMap) {
// TODO(dawn:1705): enable this test for D3D11. D3D11 MapAsync() calls
// ID3D11DeviceContext::Map() which will synchronize with GPU. so the callback will always be
// called earlier comparing to other backends.
DAWN_SUPPRESS_TEST_IF(IsD3D11());
wgpu::Buffer buffer = CreateMapReadBuffer(4);
MapAsyncAndWait(buffer, wgpu::MapMode::Read, 0, wgpu::kWholeMapSize);
buffer.Unmap();