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:
parent
2d988ce095
commit
7d6abb70b2
|
@ -196,6 +196,24 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) {
|
|||
ASSERT(mD3d11NonConstantBuffer || mD3d11ConstantBuffer);
|
||||
|
||||
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 {};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,53 +27,51 @@
|
|||
|
||||
namespace dawn::native::d3d11 {
|
||||
|
||||
MaybeError CommandRecordingContext::Open(Device* device) {
|
||||
MaybeError CommandRecordingContext::Intialize(Device* device) {
|
||||
ASSERT(!IsOpen());
|
||||
ASSERT(device);
|
||||
mDevice = device;
|
||||
|
||||
if (!mD3D11DeviceContext4) {
|
||||
ID3D11Device* d3d11Device = device->GetD3D11Device();
|
||||
|
||||
ComPtr<ID3D11DeviceContext> d3d11DeviceContext;
|
||||
device->GetD3D11Device()->GetImmediateContext(&d3d11DeviceContext);
|
||||
|
||||
ComPtr<ID3D11DeviceContext4> d3d11DeviceContext4;
|
||||
DAWN_TRY(
|
||||
CheckHRESULT(d3d11DeviceContext.As(&d3d11DeviceContext4),
|
||||
"D3D11 querying immediate context for ID3D11DeviceContext4 interface"));
|
||||
|
||||
DAWN_TRY(CheckHRESULT(
|
||||
d3d11DeviceContext4.As(&mD3D11UserDefinedAnnotation),
|
||||
"D3D11 querying immediate context for ID3DUserDefinedAnnotation interface"));
|
||||
|
||||
// Create a uniform buffer for built in variables.
|
||||
BufferDescriptor descriptor;
|
||||
// The maximum number of builtin elements is 4 (vec4). It must be multiple of 4.
|
||||
constexpr size_t kMaxNumBuiltinElements = 4;
|
||||
descriptor.size = sizeof(uint32_t) * kMaxNumBuiltinElements;
|
||||
descriptor.usage = wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst;
|
||||
descriptor.mappedAtCreation = false;
|
||||
descriptor.label = "builtin uniform buffer";
|
||||
Ref<BufferBase> uniformBuffer;
|
||||
DAWN_TRY_ASSIGN(uniformBuffer, device->CreateBuffer(&descriptor));
|
||||
|
||||
mD3D11Device = d3d11Device;
|
||||
mD3D11DeviceContext4 = std::move(d3d11DeviceContext4);
|
||||
mUniformBuffer = ToBackend(std::move(uniformBuffer));
|
||||
|
||||
// Always bind the uniform buffer to the reserved slot for all pipelines.
|
||||
// This buffer will be updated with the correct values before each draw or dispatch call.
|
||||
ID3D11Buffer* bufferPtr = mUniformBuffer->GetD3D11ConstantBuffer();
|
||||
mD3D11DeviceContext4->VSSetConstantBuffers(PipelineLayout::kReservedConstantBufferSlot, 1,
|
||||
&bufferPtr);
|
||||
mD3D11DeviceContext4->CSSetConstantBuffers(PipelineLayout::kReservedConstantBufferSlot, 1,
|
||||
&bufferPtr);
|
||||
}
|
||||
|
||||
mIsOpen = true;
|
||||
mNeedsSubmit = false;
|
||||
|
||||
ID3D11Device* d3d11Device = device->GetD3D11Device();
|
||||
|
||||
ComPtr<ID3D11DeviceContext> d3d11DeviceContext;
|
||||
device->GetD3D11Device()->GetImmediateContext(&d3d11DeviceContext);
|
||||
|
||||
ComPtr<ID3D11DeviceContext4> d3d11DeviceContext4;
|
||||
DAWN_TRY(CheckHRESULT(d3d11DeviceContext.As(&d3d11DeviceContext4),
|
||||
"D3D11 querying immediate context for ID3D11DeviceContext4 interface"));
|
||||
|
||||
DAWN_TRY(
|
||||
CheckHRESULT(d3d11DeviceContext4.As(&mD3D11UserDefinedAnnotation),
|
||||
"D3D11 querying immediate context for ID3DUserDefinedAnnotation interface"));
|
||||
|
||||
mD3D11Device = d3d11Device;
|
||||
mD3D11DeviceContext4 = std::move(d3d11DeviceContext4);
|
||||
mIsOpen = true;
|
||||
|
||||
// Create a uniform buffer for built in variables.
|
||||
BufferDescriptor descriptor;
|
||||
// The maximum number of builtin elements is 4 (vec4). It must be multiple of 4.
|
||||
constexpr size_t kMaxNumBuiltinElements = 4;
|
||||
descriptor.size = sizeof(uint32_t) * kMaxNumBuiltinElements;
|
||||
descriptor.usage = wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst;
|
||||
descriptor.mappedAtCreation = false;
|
||||
descriptor.label = "builtin uniform buffer";
|
||||
|
||||
Ref<BufferBase> uniformBuffer;
|
||||
DAWN_TRY_ASSIGN(uniformBuffer, device->CreateBuffer(&descriptor));
|
||||
|
||||
mUniformBuffer = ToBackend(std::move(uniformBuffer));
|
||||
|
||||
// Always bind the uniform buffer to the reserved slot for all pipelines.
|
||||
// This buffer will be updated with the correct values before each draw or dispatch call.
|
||||
ID3D11Buffer* bufferPtr = mUniformBuffer->GetD3D11ConstantBuffer();
|
||||
mD3D11DeviceContext4->VSSetConstantBuffers(PipelineLayout::kReservedConstantBufferSlot, 1,
|
||||
&bufferPtr);
|
||||
mD3D11DeviceContext4->CSSetConstantBuffers(PipelineLayout::kReservedConstantBufferSlot, 1,
|
||||
&bufferPtr);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class Device;
|
|||
|
||||
class CommandRecordingContext {
|
||||
public:
|
||||
MaybeError Open(Device* device);
|
||||
MaybeError Intialize(Device* device);
|
||||
|
||||
void Release();
|
||||
bool IsOpen() const;
|
||||
|
|
|
@ -121,7 +121,7 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
|
|||
// Create the fence event.
|
||||
mFenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
|
||||
DAWN_TRY(PreparePendingCommandContext());
|
||||
DAWN_TRY(mPendingCommands.Intialize(this));
|
||||
|
||||
SetLabelImpl();
|
||||
|
||||
|
@ -149,13 +149,6 @@ CommandRecordingContext* Device::GetPendingCommandContext(Device::SubmitMode sub
|
|||
return &mPendingCommands;
|
||||
}
|
||||
|
||||
MaybeError Device::PreparePendingCommandContext() {
|
||||
if (!mPendingCommands.IsOpen()) {
|
||||
DAWN_TRY(mPendingCommands.Open(this));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError Device::TickImpl() {
|
||||
// Perform cleanup operations to free unused objects
|
||||
[[maybe_unused]] ExecutionSerial completedSerial = GetCompletedCommandSerial();
|
||||
|
|
|
@ -42,7 +42,6 @@ class Device final : public d3d::Device {
|
|||
ID3D11Device5* GetD3D11Device5() const;
|
||||
|
||||
CommandRecordingContext* GetPendingCommandContext(SubmitMode submitMode = SubmitMode::Normal);
|
||||
MaybeError PreparePendingCommandContext();
|
||||
|
||||
const DeviceInfo& GetDeviceInfo() const;
|
||||
|
||||
|
|
|
@ -129,6 +129,8 @@ TEST_P(NonzeroBufferCreationTests, BufferCreationWithMappedAtCreation) {
|
|||
}
|
||||
|
||||
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"},
|
||||
{"lazy_clear_resource_on_first_use"}),
|
||||
MetalBackend({"nonzero_clear_resources_on_creation_for_testing"},
|
||||
|
|
Loading…
Reference in New Issue