d3d11: enable NonzeroBufferCreationTests

Bug: dawn:1705
Change-Id: I5c6f77a9728fd47593716a1ce2ea69a8960178ef
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133964
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Peng Huang <penghuang@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
jchen10 2023-05-26 00:23:47 +00:00 committed by Dawn LUCI CQ
parent 2d988ce095
commit 7d6abb70b2
6 changed files with 62 additions and 52 deletions

View File

@ -196,6 +196,24 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) {
ASSERT(mD3d11NonConstantBuffer || mD3d11ConstantBuffer); ASSERT(mD3d11NonConstantBuffer || mD3d11ConstantBuffer);
SetLabelImpl(); SetLabelImpl();
if (!mappedAtCreation) {
if (GetDevice()->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
DAWN_TRY(ClearInternal(ToBackend(GetDevice())->GetPendingCommandContext(), 1u));
}
// Initialize the padding bytes to zero.
if (GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
uint32_t paddingBytes = GetAllocatedSize() - GetSize();
if (paddingBytes > 0) {
uint32_t clearSize = paddingBytes;
uint64_t clearOffset = GetSize();
DAWN_TRY(ClearInternal(ToBackend(GetDevice())->GetPendingCommandContext(), 0,
clearOffset, clearSize));
}
}
}
return {}; return {};
} }

View File

@ -27,26 +27,29 @@
namespace dawn::native::d3d11 { namespace dawn::native::d3d11 {
MaybeError CommandRecordingContext::Open(Device* device) { MaybeError CommandRecordingContext::Intialize(Device* device) {
ASSERT(!IsOpen()); ASSERT(!IsOpen());
ASSERT(device); ASSERT(device);
mDevice = device; mDevice = device;
mNeedsSubmit = false;
if (!mD3D11DeviceContext4) {
ID3D11Device* d3d11Device = device->GetD3D11Device(); ID3D11Device* d3d11Device = device->GetD3D11Device();
ComPtr<ID3D11DeviceContext> d3d11DeviceContext; ComPtr<ID3D11DeviceContext> d3d11DeviceContext;
device->GetD3D11Device()->GetImmediateContext(&d3d11DeviceContext); device->GetD3D11Device()->GetImmediateContext(&d3d11DeviceContext);
ComPtr<ID3D11DeviceContext4> d3d11DeviceContext4; ComPtr<ID3D11DeviceContext4> d3d11DeviceContext4;
DAWN_TRY( DAWN_TRY(CheckHRESULT(d3d11DeviceContext.As(&d3d11DeviceContext4),
CheckHRESULT(d3d11DeviceContext.As(&d3d11DeviceContext4),
"D3D11 querying immediate context for ID3D11DeviceContext4 interface")); "D3D11 querying immediate context for ID3D11DeviceContext4 interface"));
DAWN_TRY(CheckHRESULT( DAWN_TRY(
d3d11DeviceContext4.As(&mD3D11UserDefinedAnnotation), CheckHRESULT(d3d11DeviceContext4.As(&mD3D11UserDefinedAnnotation),
"D3D11 querying immediate context for ID3DUserDefinedAnnotation interface")); "D3D11 querying immediate context for ID3DUserDefinedAnnotation interface"));
mD3D11Device = d3d11Device;
mD3D11DeviceContext4 = std::move(d3d11DeviceContext4);
mIsOpen = true;
// Create a uniform buffer for built in variables. // Create a uniform buffer for built in variables.
BufferDescriptor descriptor; BufferDescriptor descriptor;
// The maximum number of builtin elements is 4 (vec4). It must be multiple of 4. // The maximum number of builtin elements is 4 (vec4). It must be multiple of 4.
@ -55,11 +58,10 @@ MaybeError CommandRecordingContext::Open(Device* device) {
descriptor.usage = wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst;
descriptor.mappedAtCreation = false; descriptor.mappedAtCreation = false;
descriptor.label = "builtin uniform buffer"; descriptor.label = "builtin uniform buffer";
Ref<BufferBase> uniformBuffer; Ref<BufferBase> uniformBuffer;
DAWN_TRY_ASSIGN(uniformBuffer, device->CreateBuffer(&descriptor)); DAWN_TRY_ASSIGN(uniformBuffer, device->CreateBuffer(&descriptor));
mD3D11Device = d3d11Device;
mD3D11DeviceContext4 = std::move(d3d11DeviceContext4);
mUniformBuffer = ToBackend(std::move(uniformBuffer)); mUniformBuffer = ToBackend(std::move(uniformBuffer));
// Always bind the uniform buffer to the reserved slot for all pipelines. // Always bind the uniform buffer to the reserved slot for all pipelines.
@ -69,10 +71,6 @@ MaybeError CommandRecordingContext::Open(Device* device) {
&bufferPtr); &bufferPtr);
mD3D11DeviceContext4->CSSetConstantBuffers(PipelineLayout::kReservedConstantBufferSlot, 1, mD3D11DeviceContext4->CSSetConstantBuffers(PipelineLayout::kReservedConstantBufferSlot, 1,
&bufferPtr); &bufferPtr);
}
mIsOpen = true;
mNeedsSubmit = false;
return {}; return {};
} }

View File

@ -26,7 +26,7 @@ class Device;
class CommandRecordingContext { class CommandRecordingContext {
public: public:
MaybeError Open(Device* device); MaybeError Intialize(Device* device);
void Release(); void Release();
bool IsOpen() const; bool IsOpen() const;

View File

@ -121,7 +121,7 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
// Create the fence event. // Create the fence event.
mFenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); mFenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
DAWN_TRY(PreparePendingCommandContext()); DAWN_TRY(mPendingCommands.Intialize(this));
SetLabelImpl(); SetLabelImpl();
@ -149,13 +149,6 @@ CommandRecordingContext* Device::GetPendingCommandContext(Device::SubmitMode sub
return &mPendingCommands; return &mPendingCommands;
} }
MaybeError Device::PreparePendingCommandContext() {
if (!mPendingCommands.IsOpen()) {
DAWN_TRY(mPendingCommands.Open(this));
}
return {};
}
MaybeError Device::TickImpl() { MaybeError Device::TickImpl() {
// Perform cleanup operations to free unused objects // Perform cleanup operations to free unused objects
[[maybe_unused]] ExecutionSerial completedSerial = GetCompletedCommandSerial(); [[maybe_unused]] ExecutionSerial completedSerial = GetCompletedCommandSerial();

View File

@ -42,7 +42,6 @@ class Device final : public d3d::Device {
ID3D11Device5* GetD3D11Device5() const; ID3D11Device5* GetD3D11Device5() const;
CommandRecordingContext* GetPendingCommandContext(SubmitMode submitMode = SubmitMode::Normal); CommandRecordingContext* GetPendingCommandContext(SubmitMode submitMode = SubmitMode::Normal);
MaybeError PreparePendingCommandContext();
const DeviceInfo& GetDeviceInfo() const; const DeviceInfo& GetDeviceInfo() const;

View File

@ -129,6 +129,8 @@ TEST_P(NonzeroBufferCreationTests, BufferCreationWithMappedAtCreation) {
} }
DAWN_INSTANTIATE_TEST(NonzeroBufferCreationTests, DAWN_INSTANTIATE_TEST(NonzeroBufferCreationTests,
D3D11Backend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"}),
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}, D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"}), {"lazy_clear_resource_on_first_use"}),
MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}, MetalBackend({"nonzero_clear_resources_on_creation_for_testing"},