gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.23k stars 898 forks source link

Surface with only texture usage `COPY_DST` attempts to create a `VkImageView` #5951

Open Pengiie opened 2 months ago

Pengiie commented 2 months ago

Description When creating a Surface with the only texture usage being COPY_DST with the vulkan backend, an image view is still attempted to be made with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT which causes a validation error.

Repro steps

surface.configure(&device, &wgpu::SurfaceConfiguration {
    usage: wgpu::TextureUsages::COPY_DST,
    view_formats: vec![],
    ...
});

Expected vs observed behavior When the surface textures are created with just COPY_DST, I expect a VkImageView not to be created since there is no reason to due to the only VkImageUsage being VK_IMAGE_USAGE_TRANSFER_DST_BIT.

What actually happens is the image view is attempted to be created with the VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT even though I didn't set wgpu::TextureUsages::RENDER_ATTACHMENT.

Extra materials Vulkan validation errors:

[2024-07-13T19:08:13Z ERROR wgpu_hal::vulkan::instance] VALIDATION [VUID-VkImageViewCreateInfo-image-04441 (0xb75da543)]
        Validation Error: [ VUID-VkImageViewCreateInfo-image-04441 ] Object 0: handle = 0xcfef35000000000a, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xb75da543 | vkCreateImageView(): pCreateInfo->image (VkImage 0xcfef35000000000a[]) was created with VK_IMAGE_USAGE_TRANSFER_DST_BIT but requires VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT|VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT|VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR|VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR|VK_IMAGE_USAGE_SAMPLE_WEIGHT_BIT_QCOM|VK_IMAGE_USAGE_SAMPLE_BLOCK_MATCH_BIT_QCOM. The Vulkan spec states: image must have been created with a usage value containing at least one of the usages defined in the valid image usage list for image views (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkImageViewCreateInfo-image-04441)
[2024-07-13T19:08:13Z ERROR wgpu_hal::vulkan::instance]     objects: (type: IMAGE, hndl: 0xcfef35000000000a, name: ?)
[2024-07-13T19:08:13Z ERROR wgpu_hal::vulkan::instance] VALIDATION [VUID-VkImageViewCreateInfo-pNext-02662 (0xfcaee507)]
        Validation Error: [ VUID-VkImageViewCreateInfo-pNext-02662 ] Object 0: handle = 0xcfef35000000000a, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xfcaee507 | vkCreateImageView(): pCreateInfo->pNext<VkImageViewUsageCreateInfo>.usage (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) must not include any bits that were not set in VkImageCreateInfo::usage (VK_IMAGE_USAGE_TRANSFER_DST_BIT) of the image. The Vulkan spec states: If the pNext chain includes a VkImageViewUsageCreateInfo structure, and image was not created with a VkImageStencilUsageCreateInfo structure included in the pNext chain of VkImageCreateInfo, its usage member must not include any bits that were not set in the usage member of the VkImageCreateInfo structure used to create image (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkImageViewCreateInfo-pNext-02662)
[2024-07-13T19:08:13Z ERROR wgpu_hal::vulkan::instance]     objects: (type: IMAGE, hndl: 0xcfef35000000000a, name: ?)

Platform wgpu v0.20.1 NixOS 24.05 using Vulkan Nvidia drivers 555.42.02

Pengiie commented 2 months ago

When I was searching around for if there was limitations for what usages surfaces can be made with I didn't check the docs (my bad), https://docs.rs/wgpu/latest/wgpu/type.SurfaceConfiguration.html. I see now that only RENDER_ATTACHMENT is supported.

cwfitzgerald commented 2 months ago

We should be validating this