From 5b3cdc66fd62ea10f36d053f4ebca5f60b534acb Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 2 Jun 2020 18:39:59 +0000 Subject: [PATCH] Skip creating the VkImageView if the texture usage is only Copy Bug: dawn:399 Change-Id: Iedd097dc96b248499fefd0c259b13fb55fc39f0d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22380 Reviewed-by: Corentin Wallez Reviewed-by: Jiawei Shao Reviewed-by: Austin Eng Commit-Queue: Austin Eng --- src/dawn_native/vulkan/TextureVk.cpp | 8 ++++++++ src/tests/end2end/TextureViewTests.cpp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/dawn_native/vulkan/TextureVk.cpp b/src/dawn_native/vulkan/TextureVk.cpp index fa3c20b774..c9ad0eb653 100644 --- a/src/dawn_native/vulkan/TextureVk.cpp +++ b/src/dawn_native/vulkan/TextureVk.cpp @@ -946,6 +946,14 @@ namespace dawn_native { namespace vulkan { } MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { + if ((GetTexture()->GetUsage() & + ~(wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst)) == 0) { + // If the texture view has no other usage than CopySrc and CopyDst, then it can't + // actually be used as a render pass attachment or sampled/storage texture. The Vulkan + // validation errors warn if you create such a vkImageView, so return early. + return {}; + } + Device* device = ToBackend(GetTexture()->GetDevice()); VkImageViewCreateInfo createInfo; diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp index 9f51d2e6fa..0deb1120b4 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -614,3 +614,23 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALayerOf2DArrayTextureAsCol DAWN_INSTANTIATE_TEST(TextureViewSamplingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend()); DAWN_INSTANTIATE_TEST(TextureViewRenderingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend()); + +class TextureViewTest : public DawnTest {}; + +// This is a regression test for crbug.com/dawn/399 where creating a texture view with only copy +// usage would cause the Vulkan validation layers to warn +TEST_P(TextureViewTest, OnlyCopySrcDst) { + wgpu::TextureDescriptor descriptor; + descriptor.size = {4, 4, 1}; + descriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst; + descriptor.format = wgpu::TextureFormat::RGBA8Unorm; + + wgpu::Texture texture = device.CreateTexture(&descriptor); + wgpu::TextureView view = texture.CreateView(); +} + +DAWN_INSTANTIATE_TEST(TextureViewTest, + D3D12Backend(), + MetalBackend(), + OpenGLBackend(), + VulkanBackend());