Fix issues in end2end tests for enabling buffer lazy clear by default

This patch cleans up some issues in the end2end tests that will cause
test failures when we enable buffer lazy initialization by default.

This patch also skips a test that always fails with Vulkan validation
layer.

BUG=dawn:414
TEST=dawn_end2end_tests

Change-Id: I40f643615b3fec4e52c90d576285534a99950915
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/26960
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2020-08-23 06:08:05 +00:00 committed by Commit Bot service account
parent ce78ce2e28
commit ef74473347
6 changed files with 56 additions and 12 deletions

View File

@ -21,6 +21,18 @@ namespace dawn_native { namespace opengl {
// Buffer // Buffer
// static
ResultOrError<Ref<Buffer>> Buffer::CreateInternalBuffer(Device* device,
const BufferDescriptor* descriptor,
bool shouldLazyClear) {
Ref<Buffer> buffer = AcquireRef(new Buffer(device, descriptor, shouldLazyClear));
if (descriptor->mappedAtCreation) {
DAWN_TRY(buffer->MapAtCreation());
}
return std::move(buffer);
}
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor) Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
: BufferBase(device, descriptor) { : BufferBase(device, descriptor) {
// TODO(cwallez@chromium.org): Have a global "zero" buffer instead of creating a new 4-byte // TODO(cwallez@chromium.org): Have a global "zero" buffer instead of creating a new 4-byte
@ -38,6 +50,13 @@ namespace dawn_native { namespace opengl {
} }
} }
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor, bool shouldLazyClear)
: Buffer(device, descriptor) {
if (!shouldLazyClear) {
SetIsDataInitialized();
}
}
Buffer::~Buffer() { Buffer::~Buffer() {
DestroyInternal(); DestroyInternal();
} }

View File

@ -25,6 +25,10 @@ namespace dawn_native { namespace opengl {
class Buffer final : public BufferBase { class Buffer final : public BufferBase {
public: public:
static ResultOrError<Ref<Buffer>> CreateInternalBuffer(Device* device,
const BufferDescriptor* descriptor,
bool shouldLazyClear);
Buffer(Device* device, const BufferDescriptor* descriptor); Buffer(Device* device, const BufferDescriptor* descriptor);
GLuint GetHandle() const; GLuint GetHandle() const;
@ -34,6 +38,7 @@ namespace dawn_native { namespace opengl {
void EnsureDataInitializedAsDestination(const CopyTextureToBufferCmd* copy); void EnsureDataInitializedAsDestination(const CopyTextureToBufferCmd* copy);
private: private:
Buffer(Device* device, const BufferDescriptor* descriptor, bool shouldLazyClear);
~Buffer() override; ~Buffer() override;
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override; MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
void UnmapImpl() override; void UnmapImpl() override;

View File

@ -334,8 +334,10 @@ namespace dawn_native { namespace opengl {
return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate buffer."); return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate buffer.");
} }
// TODO(natlee@microsoft.com): use Dynamic Uplaoder here for temp buffer // We don't count the lazy clear of srcBuffer because it is an internal buffer.
Ref<Buffer> srcBuffer = AcquireRef(ToBackend(device->CreateBuffer(&descriptor))); // TODO(natlee@microsoft.com): use Dynamic Uploader here for temp buffer
Ref<Buffer> srcBuffer;
DAWN_TRY_ASSIGN(srcBuffer, Buffer::CreateInternalBuffer(device, &descriptor, false));
// Fill the buffer with clear color // Fill the buffer with clear color
memset(srcBuffer->GetMappedRange(0, descriptor.size), clearColor, descriptor.size); memset(srcBuffer->GetMappedRange(0, descriptor.size), clearColor, descriptor.size);

View File

@ -1011,13 +1011,15 @@ void DawnTestBase::FlushWire() {
DawnTestBase::ReadbackReservation DawnTestBase::ReserveReadback(uint64_t readbackSize) { DawnTestBase::ReadbackReservation DawnTestBase::ReserveReadback(uint64_t readbackSize) {
// For now create a new MapRead buffer for each readback // For now create a new MapRead buffer for each readback
// TODO(cwallez@chromium.org): eventually make bigger buffers and allocate linearly? // TODO(cwallez@chromium.org): eventually make bigger buffers and allocate linearly?
wgpu::BufferDescriptor descriptor;
descriptor.size = readbackSize;
descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
ReadbackSlot slot; ReadbackSlot slot;
slot.bufferSize = readbackSize; slot.bufferSize = readbackSize;
slot.buffer = device.CreateBuffer(&descriptor);
// Create and initialize the slot buffer so that it won't unexpectedly affect the count of
// resource lazy clear in the tests.
const std::vector<uint8_t> initialBufferData(readbackSize, 0u);
slot.buffer =
utils::CreateBufferFromData(device, initialBufferData.data(), readbackSize,
wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst);
ReadbackReservation reservation; ReadbackReservation reservation;
reservation.buffer = slot.buffer; reservation.buffer = slot.buffer;

View File

@ -167,6 +167,10 @@ TEST_P(TextureSubresourceTest, MipmapLevelsTest) {
// Test different array layers // Test different array layers
TEST_P(TextureSubresourceTest, ArrayLayersTest) { TEST_P(TextureSubresourceTest, ArrayLayersTest) {
// TODO(crbug.com/dawn/517): The Vulkan backend hits this validation rule.
// https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-vkCmdDraw-None-02687
DAWN_SKIP_TEST_IF(IsBackendValidationEnabled() && IsVulkan());
// Create a texture with 1 mipmap level and 2 layers // Create a texture with 1 mipmap level and 2 layers
wgpu::Texture texture = wgpu::Texture texture =
CreateTexture(1, 2, CreateTexture(1, 2,

View File

@ -1365,10 +1365,12 @@ TEST_P(TextureZeroInitTest, CopyTextureToBufferNonRenderableUnaligned) {
{ {
uint32_t bytesPerRow = Align(kUnalignedSize, kTextureBytesPerRowAlignment); uint32_t bytesPerRow = Align(kUnalignedSize, kTextureBytesPerRowAlignment);
wgpu::BufferDescriptor bufferDesc; // Create and initialize the destination buffer to ensure we only count the times of
bufferDesc.size = kUnalignedSize * bytesPerRow; // texture lazy initialization in this test.
bufferDesc.usage = wgpu::BufferUsage::CopyDst; const uint64_t bufferSize = kUnalignedSize * bytesPerRow;
wgpu::Buffer buffer = device.CreateBuffer(&bufferDesc); const std::vector<uint8_t> initialBufferData(bufferSize, 0u);
wgpu::Buffer buffer = utils::CreateBufferFromData(device, initialBufferData.data(),
bufferSize, wgpu::BufferUsage::CopyDst);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, {0, 0, 0});
wgpu::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
@ -1635,10 +1637,20 @@ 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"}),
VulkanBackend({"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"}));