Open Bug 2008705 Opened 10 months ago Updated 7 days ago

WebGPU: external textures missing on Linux

Categories

(Core :: Graphics: WebGPU, defect, P1)

defect

Tracking

()

ASSIGNED

People

(Reporter: jnicol, Assigned: aleiserson)

References

(Blocks 2 open bugs)

Details

This will require:

  • a wgpu implementation for external textures on Vulkan/SPV
  • Implementing a new function ExternalTextureHostSource::CreateFromDMABufTextureHost() called from here.
    • Which will call in to wgpu_bindings rust code to create a wgpu::Texture from a DMABuf. We should see if this implementation can be shared with the Vulkan swapchain implementation.
  • Updating the blocklist here
See Also: → 2008706

Seems S3 level, please update if incorrect.

Severity: -- → S3
Summary: Implement WebGPU external textures for Linux → WebGPU: external textures missing on Linux

This is a follow-up to a concern I raised in https://phabricator.services.mozilla.com/D324573#inline-1735437.

The Vulkan backend translates wgt::TextureUses::UNINITIALIZED => vk::ImageLayout::UNDEFINED.

Vulkan says:

VUID-VkImageCreateInfo-pNext-01443
If the pNext chain includes a VkExternalMemoryImageCreateInfo or VkExternalMemoryImageCreateInfoNV structure whose handleTypes member is not 0, initialLayout must be VK_IMAGE_LAYOUT_UNDEFINED

from https://docs.vulkan.org/refpages/latest/refpages/source/VkImageCreateInfo.html#VUID-VkImageCreateInfo-pNext-01443

VK_IMAGE_LAYOUT_UNDEFINED specifies that the layout is unknown. Image memory cannot be transitioned into this layout. This layout can be used as the initialLayout member of VkImageCreateInfo. This layout can be used in place of the current image layout in a layout transition, but doing so will cause the contents of the image’s memory to be undefined.

from https://docs.vulkan.org/refpages/latest/refpages/source/VkImageLayout.html#_description

  1. Are new image layouts or metadata required to specify image layouts and layout transitions compatible with non-Vulkan APIs, or with other instances of the same Vulkan driver?

RESOLVED: Separate instances of the same Vulkan driver running on the same GPU should have identical internal layout semantics, so applications have the tools they need to ensure views of images are consistent between the two instances. Other APIs will fall into two categories: Those that are Vulkan- compatible, and those that are Vulkan-incompatible. Vulkan-incompatible APIs will require the image to be in the GENERAL layout whenever they are accessing them.

from https://docs.vulkan.org/refpages/latest/refpages/source/VK_KHR_external_memory.html

Relevant threads:

So I think we need to:

  • set initialLayout to ImageLayout::UNDEFINED when creating the image
  • set oldLayout to VK_IMAGE_LAYOUT_GENERAL & srcQueueFamilyIndex to VK_QUEUE_FAMILY_FOREIGN_EXT when encoding the first barrier
  • check & enable VK_EXT_queue_family_foreign

I think we should also emit a barrier with dstQueueFamilyIndex set to VK_QUEUE_FAMILY_FOREIGN_EXT and newLayout set to VK_IMAGE_LAYOUT_GENERAL in our zero-readback presentation path. I will open a new bug for this.

See Also: → 2074667

I opened Bug 2074667 for the zero-readback presentation issue. It also includes more references as to why a queue family ownership transfer is needed at all (which also applies to the import path).

It seems worth checking how Dawn handled this.

Assignee: nobody → aleiserson
Status: NEW → ASSIGNED

I have external textures working on Linux on my local dev branches.

Depends on: 2081416
Priority: -- → P1

Deltas from last update in italics.

Since the last update, I have also worked on cleaning up the SPIR-V external texture support, passing external textures to functions, and on two fixes to multi-planar textures that are import wgpu correctness issues as we expose multi-planar textures more widely, but aren't absolutely required in order to support external textures: #10684 fix(core): Check that clear_texture targets all aspects and #10710 fix(core): Correctly clear multi-planar textures when using render passes

See Also: → 2086850

Deltas from last update in italics.

Other progress: #10776 Multi-planar texture copy validation

You need to log in before you can comment on or make changes to this bug.