Remove Toggle LazyClearBufferOnFirstUse
This patch removes the Toggle LazyClearBufferOnFirstUse and uses
the Toggle::LazyClearResourceOnFirstUse, which means buffer lazy
initialization has been enabled by default in Dawn.
BUG=dawn:414
TEST=dawn_end2end_tests
Change-Id: I6b247d9442b57b6bb3cb5a2208467036fef6b293
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/27820
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp
index 49a7717..65c21b0 100644
--- a/src/dawn_native/Buffer.cpp
+++ b/src/dawn_native/Buffer.cpp
@@ -163,10 +163,8 @@
MaybeError BufferBase::MapAtCreation() {
DAWN_TRY(MapAtCreationInternal());
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse instead when
- // buffer lazy initialization is completely supported.
DeviceBase* device = GetDevice();
- if (device->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ if (device->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
memset(GetMappedRange(0, mSize), uint8_t(0u), mSize);
SetIsDataInitialized();
device->IncrementLazyClearCountForTesting();
diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp
index d54dc09..290e413 100644
--- a/src/dawn_native/Toggles.cpp
+++ b/src/dawn_native/Toggles.cpp
@@ -133,12 +133,6 @@
"https://crbug.com/dawn/402"}},
{Toggle::DisableRobustness,
{"disable_robustness", "Disable robust buffer access", "https://crbug.com/dawn/480"}},
- {Toggle::LazyClearBufferOnFirstUse,
- {"lazy_clear_buffer_on_first_use",
- "Clear buffers on their first use. This is a temporary toggle only for the "
- "development of buffer lazy initialization and will be removed after buffer lazy "
- "initialization is completely implemented.",
- "https://crbug.com/dawn/414"}},
{Toggle::MetalEnableVertexPulling,
{"metal_enable_vertex_pulling",
"Uses vertex pulling to protect out-of-bounds reads on Metal",
diff --git a/src/dawn_native/Toggles.h b/src/dawn_native/Toggles.h
index 5186cb5..e4dd479 100644
--- a/src/dawn_native/Toggles.h
+++ b/src/dawn_native/Toggles.h
@@ -43,7 +43,6 @@
UseD3D12SmallShaderVisibleHeapForTesting,
UseDXC,
DisableRobustness,
- LazyClearBufferOnFirstUse,
MetalEnableVertexPulling,
EnumCount,
diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp
index 7501a50..da4be7a 100644
--- a/src/dawn_native/d3d12/BufferD3D12.cpp
+++ b/src/dawn_native/d3d12/BufferD3D12.cpp
@@ -353,10 +353,8 @@
}
MaybeError Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return {};
}
@@ -368,10 +366,8 @@
MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
uint64_t offset,
uint64_t size) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return {};
}
@@ -386,10 +382,8 @@
MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
const CopyTextureToBufferCmd* copy) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return {};
}
@@ -403,7 +397,7 @@
}
MaybeError Buffer::InitializeToZero(CommandRecordingContext* commandContext) {
- ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse));
+ ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized());
// TODO(jiawei.shao@intel.com): skip initializing the buffer when it is created on a heap
diff --git a/src/dawn_native/metal/BufferMTL.mm b/src/dawn_native/metal/BufferMTL.mm
index 757e7c0..14f6c42 100644
--- a/src/dawn_native/metal/BufferMTL.mm
+++ b/src/dawn_native/metal/BufferMTL.mm
@@ -141,10 +141,8 @@
}
void Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -154,10 +152,8 @@
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
uint64_t offset,
uint64_t size) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -170,10 +166,8 @@
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
const CopyTextureToBufferCmd* copy) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -185,7 +179,7 @@
}
void Buffer::InitializeToZero(CommandRecordingContext* commandContext) {
- ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse));
+ ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized());
ClearBuffer(commandContext, uint8_t(0u));
@@ -196,6 +190,12 @@
void Buffer::ClearBuffer(CommandRecordingContext* commandContext, uint8_t clearValue) {
ASSERT(commandContext != nullptr);
+
+ // Metal validation layer doesn't allow the length of the range in fillBuffer() to be 0.
+ if (GetSize() == 0u) {
+ return;
+ }
+
[commandContext->EnsureBlit() fillBuffer:mMtlBuffer
range:NSMakeRange(0, GetSize())
value:clearValue];
diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp
index f765ca4..7b86964a 100644
--- a/src/dawn_native/null/DeviceNull.cpp
+++ b/src/dawn_native/null/DeviceNull.cpp
@@ -197,7 +197,7 @@
BufferBase* destination,
uint64_t destinationOffset,
uint64_t size) {
- if (IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ if (IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
destination->SetIsDataInitialized();
}
diff --git a/src/dawn_native/opengl/BufferGL.cpp b/src/dawn_native/opengl/BufferGL.cpp
index 5de6ed7..82602ee 100644
--- a/src/dawn_native/opengl/BufferGL.cpp
+++ b/src/dawn_native/opengl/BufferGL.cpp
@@ -75,10 +75,8 @@
}
void Buffer::EnsureDataInitialized() {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -86,10 +84,8 @@
}
void Buffer::EnsureDataInitializedAsDestination(uint64_t offset, uint64_t size) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -101,10 +97,8 @@
}
void Buffer::EnsureDataInitializedAsDestination(const CopyTextureToBufferCmd* copy) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -116,7 +110,7 @@
}
void Buffer::InitializeToZero() {
- ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse));
+ ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized());
const uint64_t size = GetAppliedSize();
diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp
index 689bfdf..f8e0acd 100644
--- a/src/dawn_native/vulkan/BufferVk.cpp
+++ b/src/dawn_native/vulkan/BufferVk.cpp
@@ -284,10 +284,8 @@
}
void Buffer::EnsureDataInitialized(CommandRecordingContext* recordingContext) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -297,10 +295,8 @@
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* recordingContext,
uint64_t offset,
uint64_t size) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -313,10 +309,8 @@
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* recordingContext,
const CopyTextureToBufferCmd* copy) {
- // TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
- // instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() ||
- !GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) {
+ !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return;
}
@@ -328,7 +322,7 @@
}
void Buffer::InitializeToZero(CommandRecordingContext* recordingContext) {
- ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse));
+ ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized());
ClearBuffer(recordingContext, 0u);
@@ -339,6 +333,11 @@
void Buffer::ClearBuffer(CommandRecordingContext* recordingContext, uint32_t clearValue) {
ASSERT(recordingContext != nullptr);
+ // Vulkan validation layer doesn't allow the `size` in vkCmdFillBuffer() to be 0.
+ if (GetSize() == 0u) {
+ return;
+ }
+
TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst);
Device* device = ToBackend(GetDevice());
diff --git a/src/tests/end2end/BufferTests.cpp b/src/tests/end2end/BufferTests.cpp
index e56c3c2..5d80624 100644
--- a/src/tests/end2end/BufferTests.cpp
+++ b/src/tests/end2end/BufferTests.cpp
@@ -683,20 +683,12 @@
buffer.Unmap();
}
-// TODO(jiawei.shao@intel.com): remove "lazy_clear_buffer_on_first_use" when we complete the
-// support of buffer lazy initialization.
DAWN_INSTANTIATE_TEST(BufferMappedAtCreationTests,
D3D12Backend(),
D3D12Backend({}, {"use_d3d12_resource_heap_tier2"}),
- D3D12Backend({"lazy_clear_buffer_on_first_use"}),
- D3D12Backend({"lazy_clear_buffer_on_first_use"},
- {"use_d3d12_resource_heap_tier2"}),
MetalBackend(),
- MetalBackend({"lazy_clear_buffer_on_first_use"}),
OpenGLBackend(),
- OpenGLBackend({"lazy_clear_buffer_on_first_use"}),
- VulkanBackend(),
- VulkanBackend({"lazy_clear_buffer_on_first_use"}));
+ VulkanBackend());
class BufferTests : public DawnTest {};
diff --git a/src/tests/end2end/BufferZeroInitTests.cpp b/src/tests/end2end/BufferZeroInitTests.cpp
index eb46afd..46d8e87 100644
--- a/src/tests/end2end/BufferZeroInitTests.cpp
+++ b/src/tests/end2end/BufferZeroInitTests.cpp
@@ -1177,11 +1177,7 @@
}
DAWN_INSTANTIATE_TEST(BufferZeroInitTest,
- D3D12Backend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}),
- MetalBackend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}),
- OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}),
- VulkanBackend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}));
+ D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}),
+ MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}),
+ OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
+ VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));
diff --git a/src/tests/end2end/NonzeroBufferCreationTests.cpp b/src/tests/end2end/NonzeroBufferCreationTests.cpp
index 9a8c684..25e84b6 100644
--- a/src/tests/end2end/NonzeroBufferCreationTests.cpp
+++ b/src/tests/end2end/NonzeroBufferCreationTests.cpp
@@ -129,7 +129,11 @@
}
DAWN_INSTANTIATE_TEST(NonzeroBufferCreationTests,
- D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}),
- MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));
+ D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
+ {"lazy_clear_resource_on_first_use"}),
+ MetalBackend({"nonzero_clear_resources_on_creation_for_testing"},
+ {"lazy_clear_resource_on_first_use"}),
+ OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"},
+ {"lazy_clear_resource_on_first_use"}),
+ VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"},
+ {"lazy_clear_resource_on_first_use"}));
diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp
index 07967b7..7f065d7 100644
--- a/src/tests/end2end/TextureZeroInitTests.cpp
+++ b/src/tests/end2end/TextureZeroInitTests.cpp
@@ -1637,20 +1637,10 @@
kMipLevel, 0);
}
-// TODO(jiawei.shao@intel.com): remove "lazy_clear_buffer_on_first_use" when we complete the
-// support of buffer lazy initialization.
DAWN_INSTANTIATE_TEST(TextureZeroInitTest,
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}),
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
{"use_d3d12_render_pass"}),
- D3D12Backend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}),
OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}),
MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- MetalBackend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}),
- VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- VulkanBackend({"nonzero_clear_resources_on_creation_for_testing",
- "lazy_clear_buffer_on_first_use"}));
+ VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));