From 2a7b631482d8cb167d5651be130b08549b4dedc8 Mon Sep 17 00:00:00 2001 From: Natasha Lee Date: Mon, 20 May 2019 21:00:17 +0000 Subject: [PATCH] Add nonzero_clear_resources_on_creation_for_testing toggle to opengl Forces texture to clear to nonzero on creation to test the logic of lazy clearing. Bug: dawn:145 Change-Id: Ib1f6e8f961927008e3c09960ad0219f975d86cc6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7240 Commit-Queue: Natasha Lee Reviewed-by: Corentin Wallez --- src/dawn_native/opengl/DeviceGL.cpp | 3 +++ src/dawn_native/opengl/TextureGL.cpp | 12 ++++++++++++ src/tests/end2end/NonzeroTextureCreationTests.cpp | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index a287f48409..df45d5cf29 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -33,6 +33,9 @@ namespace dawn_native { namespace opengl { Device::Device(AdapterBase* adapter, const DeviceDescriptor* descriptor) : DeviceBase(adapter, descriptor) { + if (descriptor != nullptr) { + ApplyToggleOverrides(descriptor); + } } Device::~Device() { diff --git a/src/dawn_native/opengl/TextureGL.cpp b/src/dawn_native/opengl/TextureGL.cpp index 34fa9f3af8..03203d25b3 100644 --- a/src/dawn_native/opengl/TextureGL.cpp +++ b/src/dawn_native/opengl/TextureGL.cpp @@ -166,6 +166,18 @@ namespace dawn_native { namespace opengl { // The texture is not complete if it uses mipmapping and not all levels up to // MAX_LEVEL have been defined. glTexParameteri(mTarget, GL_TEXTURE_MAX_LEVEL, levels - 1); + + if (GetDevice()->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) { + static constexpr uint32_t MAX_TEXEL_SIZE = 16; + ASSERT(TextureFormatPixelSize(GetFormat()) <= MAX_TEXEL_SIZE); + GLubyte clearColor[MAX_TEXEL_SIZE]; + std::fill(clearColor, clearColor + MAX_TEXEL_SIZE, 255); + + // TODO(natlee@microsoft.com): clear all subresources + for (uint32_t i = 0; i < GL_TEXTURE_MAX_LEVEL; i++) { + glClearTexImage(mHandle, i, formatInfo.format, formatInfo.type, clearColor); + } + } } Texture::Texture(Device* device, diff --git a/src/tests/end2end/NonzeroTextureCreationTests.cpp b/src/tests/end2end/NonzeroTextureCreationTests.cpp index 28a9b4d992..3053d135ca 100644 --- a/src/tests/end2end/NonzeroTextureCreationTests.cpp +++ b/src/tests/end2end/NonzeroTextureCreationTests.cpp @@ -95,5 +95,7 @@ TEST_P(NonzeroTextureCreationTests, ArrayLayerClears) { } DAWN_INSTANTIATE_TEST(NonzeroTextureCreationTests, + ForceWorkaround(OpenGLBackend, + "nonzero_clear_resources_on_creation_for_testing"), ForceWorkaround(VulkanBackend, "nonzero_clear_resources_on_creation_for_testing"));