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