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>
This commit is contained in:
Jiawei Shao 2020-09-02 00:21:08 +00:00 committed by Commit Bot service account
parent f114a68b8f
commit 8800135793
12 changed files with 43 additions and 83 deletions

View File

@ -163,10 +163,8 @@ namespace dawn_native {
MaybeError BufferBase::MapAtCreation() { MaybeError BufferBase::MapAtCreation() {
DAWN_TRY(MapAtCreationInternal()); DAWN_TRY(MapAtCreationInternal());
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse instead when
// buffer lazy initialization is completely supported.
DeviceBase* device = GetDevice(); DeviceBase* device = GetDevice();
if (device->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { if (device->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
memset(GetMappedRange(0, mSize), uint8_t(0u), mSize); memset(GetMappedRange(0, mSize), uint8_t(0u), mSize);
SetIsDataInitialized(); SetIsDataInitialized();
device->IncrementLazyClearCountForTesting(); device->IncrementLazyClearCountForTesting();

View File

@ -133,12 +133,6 @@ namespace dawn_native {
"https://crbug.com/dawn/402"}}, "https://crbug.com/dawn/402"}},
{Toggle::DisableRobustness, {Toggle::DisableRobustness,
{"disable_robustness", "Disable robust buffer access", "https://crbug.com/dawn/480"}}, {"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, {Toggle::MetalEnableVertexPulling,
{"metal_enable_vertex_pulling", {"metal_enable_vertex_pulling",
"Uses vertex pulling to protect out-of-bounds reads on Metal", "Uses vertex pulling to protect out-of-bounds reads on Metal",

View File

@ -43,7 +43,6 @@ namespace dawn_native {
UseD3D12SmallShaderVisibleHeapForTesting, UseD3D12SmallShaderVisibleHeapForTesting,
UseDXC, UseDXC,
DisableRobustness, DisableRobustness,
LazyClearBufferOnFirstUse,
MetalEnableVertexPulling, MetalEnableVertexPulling,
EnumCount, EnumCount,

View File

@ -353,10 +353,8 @@ namespace dawn_native { namespace d3d12 {
} }
MaybeError Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) { MaybeError Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return {}; return {};
} }
@ -368,10 +366,8 @@ namespace dawn_native { namespace d3d12 {
MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext, MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
uint64_t offset, uint64_t offset,
uint64_t size) { uint64_t size) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return {}; return {};
} }
@ -386,10 +382,8 @@ namespace dawn_native { namespace d3d12 {
MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext, MaybeError Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
const CopyTextureToBufferCmd* copy) { const CopyTextureToBufferCmd* copy) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return {}; return {};
} }
@ -403,7 +397,7 @@ namespace dawn_native { namespace d3d12 {
} }
MaybeError Buffer::InitializeToZero(CommandRecordingContext* commandContext) { MaybeError Buffer::InitializeToZero(CommandRecordingContext* commandContext) {
ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)); ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized()); ASSERT(!IsDataInitialized());
// TODO(jiawei.shao@intel.com): skip initializing the buffer when it is created on a heap // TODO(jiawei.shao@intel.com): skip initializing the buffer when it is created on a heap

View File

@ -141,10 +141,8 @@ namespace dawn_native { namespace metal {
} }
void Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) { void Buffer::EnsureDataInitialized(CommandRecordingContext* commandContext) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -154,10 +152,8 @@ namespace dawn_native { namespace metal {
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext, void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
uint64_t offset, uint64_t offset,
uint64_t size) { uint64_t size) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -170,10 +166,8 @@ namespace dawn_native { namespace metal {
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext, void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* commandContext,
const CopyTextureToBufferCmd* copy) { const CopyTextureToBufferCmd* copy) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -185,7 +179,7 @@ namespace dawn_native { namespace metal {
} }
void Buffer::InitializeToZero(CommandRecordingContext* commandContext) { void Buffer::InitializeToZero(CommandRecordingContext* commandContext) {
ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)); ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized()); ASSERT(!IsDataInitialized());
ClearBuffer(commandContext, uint8_t(0u)); ClearBuffer(commandContext, uint8_t(0u));
@ -196,6 +190,12 @@ namespace dawn_native { namespace metal {
void Buffer::ClearBuffer(CommandRecordingContext* commandContext, uint8_t clearValue) { void Buffer::ClearBuffer(CommandRecordingContext* commandContext, uint8_t clearValue) {
ASSERT(commandContext != nullptr); 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 [commandContext->EnsureBlit() fillBuffer:mMtlBuffer
range:NSMakeRange(0, GetSize()) range:NSMakeRange(0, GetSize())
value:clearValue]; value:clearValue];

View File

@ -197,7 +197,7 @@ namespace dawn_native { namespace null {
BufferBase* destination, BufferBase* destination,
uint64_t destinationOffset, uint64_t destinationOffset,
uint64_t size) { uint64_t size) {
if (IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { if (IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
destination->SetIsDataInitialized(); destination->SetIsDataInitialized();
} }

View File

@ -75,10 +75,8 @@ namespace dawn_native { namespace opengl {
} }
void Buffer::EnsureDataInitialized() { void Buffer::EnsureDataInitialized() {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -86,10 +84,8 @@ namespace dawn_native { namespace opengl {
} }
void Buffer::EnsureDataInitializedAsDestination(uint64_t offset, uint64_t size) { 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() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -101,10 +97,8 @@ namespace dawn_native { namespace opengl {
} }
void Buffer::EnsureDataInitializedAsDestination(const CopyTextureToBufferCmd* copy) { void Buffer::EnsureDataInitializedAsDestination(const CopyTextureToBufferCmd* copy) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -116,7 +110,7 @@ namespace dawn_native { namespace opengl {
} }
void Buffer::InitializeToZero() { void Buffer::InitializeToZero() {
ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)); ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized()); ASSERT(!IsDataInitialized());
const uint64_t size = GetAppliedSize(); const uint64_t size = GetAppliedSize();

View File

@ -284,10 +284,8 @@ namespace dawn_native { namespace vulkan {
} }
void Buffer::EnsureDataInitialized(CommandRecordingContext* recordingContext) { void Buffer::EnsureDataInitialized(CommandRecordingContext* recordingContext) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -297,10 +295,8 @@ namespace dawn_native { namespace vulkan {
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* recordingContext, void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* recordingContext,
uint64_t offset, uint64_t offset,
uint64_t size) { uint64_t size) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -313,10 +309,8 @@ namespace dawn_native { namespace vulkan {
void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* recordingContext, void Buffer::EnsureDataInitializedAsDestination(CommandRecordingContext* recordingContext,
const CopyTextureToBufferCmd* copy) { const CopyTextureToBufferCmd* copy) {
// TODO(jiawei.shao@intel.com): check Toggle::LazyClearResourceOnFirstUse
// instead when buffer lazy initialization is completely supported.
if (IsDataInitialized() || if (IsDataInitialized() ||
!GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)) { !GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
return; return;
} }
@ -328,7 +322,7 @@ namespace dawn_native { namespace vulkan {
} }
void Buffer::InitializeToZero(CommandRecordingContext* recordingContext) { void Buffer::InitializeToZero(CommandRecordingContext* recordingContext) {
ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearBufferOnFirstUse)); ASSERT(GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse));
ASSERT(!IsDataInitialized()); ASSERT(!IsDataInitialized());
ClearBuffer(recordingContext, 0u); ClearBuffer(recordingContext, 0u);
@ -339,6 +333,11 @@ namespace dawn_native { namespace vulkan {
void Buffer::ClearBuffer(CommandRecordingContext* recordingContext, uint32_t clearValue) { void Buffer::ClearBuffer(CommandRecordingContext* recordingContext, uint32_t clearValue) {
ASSERT(recordingContext != nullptr); 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); TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst);
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());

View File

@ -683,20 +683,12 @@ TEST_P(BufferMappedAtCreationTests, GetMappedRangeZeroSized) {
buffer.Unmap(); 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, DAWN_INSTANTIATE_TEST(BufferMappedAtCreationTests,
D3D12Backend(), D3D12Backend(),
D3D12Backend({}, {"use_d3d12_resource_heap_tier2"}), 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(),
MetalBackend({"lazy_clear_buffer_on_first_use"}),
OpenGLBackend(), OpenGLBackend(),
OpenGLBackend({"lazy_clear_buffer_on_first_use"}), VulkanBackend());
VulkanBackend(),
VulkanBackend({"lazy_clear_buffer_on_first_use"}));
class BufferTests : public DawnTest {}; class BufferTests : public DawnTest {};

View File

@ -1177,11 +1177,7 @@ TEST_P(BufferZeroInitTest, IndirectBufferForDispatchIndirect) {
} }
DAWN_INSTANTIATE_TEST(BufferZeroInitTest, DAWN_INSTANTIATE_TEST(BufferZeroInitTest,
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing", D3D12Backend({"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", OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
"lazy_clear_buffer_on_first_use"}), VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));
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"}));

View File

@ -129,7 +129,11 @@ TEST_P(NonzeroBufferCreationTests, BufferCreationWithMappedAtCreation) {
} }
DAWN_INSTANTIATE_TEST(NonzeroBufferCreationTests, DAWN_INSTANTIATE_TEST(NonzeroBufferCreationTests,
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}), D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}), {"lazy_clear_resource_on_first_use"}),
OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}), MetalBackend({"nonzero_clear_resources_on_creation_for_testing"},
VulkanBackend({"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"}));

View File

@ -1637,20 +1637,10 @@ TEST_P(TextureZeroInitTest, WriteTextureHalfAtMipLevel) {
kMipLevel, 0); 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, DAWN_INSTANTIATE_TEST(TextureZeroInitTest,
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}), D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}),
D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}, D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
{"use_d3d12_render_pass"}), {"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"}),
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"}),
MetalBackend({"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"}),
VulkanBackend({"nonzero_clear_resources_on_creation_for_testing",
"lazy_clear_buffer_on_first_use"}));