diff --git a/src/dawn/native/opengl/CommandBufferGL.cpp b/src/dawn/native/opengl/CommandBufferGL.cpp index f0ea75b641..884461544c 100644 --- a/src/dawn/native/opengl/CommandBufferGL.cpp +++ b/src/dawn/native/opengl/CommandBufferGL.cpp @@ -52,6 +52,10 @@ GLenum IndexFormatType(wgpu::IndexFormat format) { UNREACHABLE(); } +bool Is1DOr2D(wgpu::TextureDimension dimension) { + return dimension == wgpu::TextureDimension::e1D || dimension == wgpu::TextureDimension::e2D; +} + GLenum VertexFormatType(wgpu::VertexFormat format) { switch (format) { case wgpu::VertexFormat::Uint8x2: @@ -586,7 +590,6 @@ MaybeError CommandBuffer::Execute() { buffer->EnsureDataInitializedAsDestination(copy); - ASSERT(texture->GetDimension() != wgpu::TextureDimension::e1D); SubresourceRange subresources = GetSubresourcesAffectedByCopy(src, copy->copySize); texture->EnsureSubresourceContentInitialized(subresources); // The only way to move data from a texture to a buffer in GL is via @@ -631,6 +634,7 @@ MaybeError CommandBuffer::Execute() { uint8_t* offset = reinterpret_cast(static_cast(dst.offset)); switch (texture->GetDimension()) { + case wgpu::TextureDimension::e1D: case wgpu::TextureDimension::e2D: { if (texture->GetArrayLayers() == 1) { gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, glAttachment, target, @@ -656,9 +660,6 @@ MaybeError CommandBuffer::Execute() { } break; } - - case wgpu::TextureDimension::e1D: - UNREACHABLE(); } gl.PixelStorei(GL_PACK_ROW_LENGTH, 0); @@ -1227,7 +1228,6 @@ void DoTexSubImage(const OpenGLFunctions& gl, const TextureDataLayout& dataLayout, const Extent3D& copySize) { Texture* texture = ToBackend(destination.texture.Get()); - ASSERT(texture->GetDimension() != wgpu::TextureDimension::e1D); const GLFormat& format = texture->GetGLFormat(); GLenum target = texture->GetGLTarget(); @@ -1263,8 +1263,7 @@ void DoTexSubImage(const OpenGLFunctions& gl, gl.PixelStorei(GL_UNPACK_COMPRESSED_BLOCK_HEIGHT, blockInfo.height); gl.PixelStorei(GL_UNPACK_COMPRESSED_BLOCK_DEPTH, 1); - if (texture->GetArrayLayers() == 1 && - texture->GetDimension() == wgpu::TextureDimension::e2D) { + if (texture->GetArrayLayers() == 1 && Is1DOr2D(texture->GetDimension())) { gl.CompressedTexSubImage2D(target, destination.mipLevel, x, y, width, height, format.internalFormat, imageSize, data); } else { @@ -1281,8 +1280,7 @@ void DoTexSubImage(const OpenGLFunctions& gl, gl.PixelStorei(GL_UNPACK_COMPRESSED_BLOCK_HEIGHT, 0); gl.PixelStorei(GL_UNPACK_COMPRESSED_BLOCK_DEPTH, 0); } else { - if (texture->GetArrayLayers() == 1 && - texture->GetDimension() == wgpu::TextureDimension::e2D) { + if (texture->GetArrayLayers() == 1 && Is1DOr2D(texture->GetDimension())) { const uint8_t* d = static_cast(data); for (; y < destination.origin.y + copySize.height; y += blockInfo.height) { @@ -1315,8 +1313,7 @@ void DoTexSubImage(const OpenGLFunctions& gl, if (dataLayout.bytesPerRow % blockInfo.byteSize == 0) { gl.PixelStorei(GL_UNPACK_ROW_LENGTH, dataLayout.bytesPerRow / blockInfo.byteSize * blockInfo.width); - if (texture->GetArrayLayers() == 1 && - texture->GetDimension() == wgpu::TextureDimension::e2D) { + if (texture->GetArrayLayers() == 1 && Is1DOr2D(texture->GetDimension())) { gl.TexSubImage2D(target, destination.mipLevel, x, y, width, height, format.format, format.type, data); } else { @@ -1327,8 +1324,7 @@ void DoTexSubImage(const OpenGLFunctions& gl, } gl.PixelStorei(GL_UNPACK_ROW_LENGTH, 0); } else { - if (texture->GetArrayLayers() == 1 && - texture->GetDimension() == wgpu::TextureDimension::e2D) { + if (texture->GetArrayLayers() == 1 && Is1DOr2D(texture->GetDimension())) { const uint8_t* d = static_cast(data); for (; y < destination.origin.y + height; ++y) { gl.TexSubImage2D(target, destination.mipLevel, x, y, width, 1, format.format, diff --git a/src/dawn/native/opengl/TextureGL.cpp b/src/dawn/native/opengl/TextureGL.cpp index 6b47342071..1b4783d1ca 100644 --- a/src/dawn/native/opengl/TextureGL.cpp +++ b/src/dawn/native/opengl/TextureGL.cpp @@ -31,6 +31,7 @@ namespace { GLenum TargetForTexture(const TextureDescriptor* descriptor) { switch (descriptor->dimension) { + case wgpu::TextureDimension::e1D: case wgpu::TextureDimension::e2D: if (descriptor->size.depthOrArrayLayers > 1) { ASSERT(descriptor->sampleCount == 1); @@ -45,9 +46,6 @@ GLenum TargetForTexture(const TextureDescriptor* descriptor) { case wgpu::TextureDimension::e3D: ASSERT(descriptor->sampleCount == 1); return GL_TEXTURE_3D; - - case wgpu::TextureDimension::e1D: - break; } UNREACHABLE(); } @@ -56,6 +54,7 @@ GLenum TargetForTextureViewDimension(wgpu::TextureViewDimension dimension, uint32_t arrayLayerCount, uint32_t sampleCount) { switch (dimension) { + case wgpu::TextureViewDimension::e1D: case wgpu::TextureViewDimension::e2D: return (sampleCount > 1) ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; case wgpu::TextureViewDimension::e2DArray: @@ -76,7 +75,6 @@ GLenum TargetForTextureViewDimension(wgpu::TextureViewDimension dimension, case wgpu::TextureViewDimension::e3D: return GL_TEXTURE_3D; - case wgpu::TextureViewDimension::e1D: case wgpu::TextureViewDimension::Undefined: break; } @@ -289,6 +287,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { switch (GetDimension()) { + case wgpu::TextureDimension::e1D: case wgpu::TextureDimension::e2D: if (GetArrayLayers() == 1) { Aspect aspectsToClear = Aspect::None; @@ -305,7 +304,6 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, if (aspectsToClear == Aspect::None) { continue; } - gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GetGLTarget(), GetHandle(), static_cast(level)); DoClear(aspectsToClear); @@ -336,7 +334,6 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, } break; - case wgpu::TextureDimension::e1D: case wgpu::TextureDimension::e3D: UNREACHABLE(); } @@ -437,7 +434,6 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, if (GetArrayLayers() == 1) { switch (GetDimension()) { case wgpu::TextureDimension::e1D: - UNREACHABLE(); case wgpu::TextureDimension::e2D: gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GetGLTarget(), GetHandle(), level); diff --git a/src/dawn/tests/end2end/StorageTextureTests.cpp b/src/dawn/tests/end2end/StorageTextureTests.cpp index 4e1fb27144..bd61cc1a8e 100644 --- a/src/dawn/tests/end2end/StorageTextureTests.cpp +++ b/src/dawn/tests/end2end/StorageTextureTests.cpp @@ -765,9 +765,6 @@ TEST_P(StorageTextureTests, Writeonly2DArrayOr3DStorageTexture) { // Verify 1D write-only storage textures work correctly. TEST_P(StorageTextureTests, Writeonly1DStorageTexture) { - // TODO(crbug.com/dawn/547): implement 1D storage texture on OpenGL and OpenGLES. - DAWN_TEST_UNSUPPORTED_IF(IsOpenGL() || IsOpenGLES()); - constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::R32Uint; // Prepare the write-only storage texture. diff --git a/src/dawn/tests/end2end/TextureViewTests.cpp b/src/dawn/tests/end2end/TextureViewTests.cpp index 2955338e0b..e153b0c547 100644 --- a/src/dawn/tests/end2end/TextureViewTests.cpp +++ b/src/dawn/tests/end2end/TextureViewTests.cpp @@ -1113,4 +1113,9 @@ TEST_P(TextureView1DTest, Sampling) { EXPECT_PIXEL_RGBA8_EQ(data[3], rp.color, 3, 0); } -DAWN_INSTANTIATE_TEST(TextureView1DTest, D3D12Backend(), MetalBackend(), VulkanBackend()); +DAWN_INSTANTIATE_TEST(TextureView1DTest, + D3D12Backend(), + MetalBackend(), + VulkanBackend(), + OpenGLBackend(), + OpenGLESBackend());