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"));