Foreign queue transfers are hard to use correctly

未关闭
#2,829 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@r-potter 已经在做这个了。

开始于 2026年10月21日。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
markdown
领域
documentation

调研方向

Start by reading the synchronization and image-layout-transition specification sections linked in the issue, especially the rules for foreign queue transfers. The issue describes two proposed specification changes but does not identify files or tests; first determine where those rules are documented and how changes are validated in Vulkan-Docs. Done means the spec clearly resolves foreign-queue layout transitions and their synchronization requirements.

由索引模型根据 Issue 内容生成。

描述

The foreign queue is designed to work across vulkan drivers and to additionally allow interop between vulkan and non-vulkan APIs.

The special queue family index VK_QUEUE_FAMILY_FOREIGN_EXT represents any queue external to the resource’s current Vulkan instance, regardless of the queue’s underlying physical device or driver version. This includes, for example, queues for fixed-function image processing devices, media codec devices, and display devices, as well as all queues that use the same underlying device group or physical device, and the same driver version as the resource’s VkDevice.

When a queue transfer barrier also contains an image layout transition, the spec requires that both release and acquire operations use the same values in oldLayout and newLayout. The spec says that the transition will be executed only once, and it is unspecified if the transition is executed by the release operation or the acquire operation:

If the transfer is via an image memory barrier, and an image layout transition is desired, then the values of oldLayout and newLayout in the release operation's memory barrier must be equal to values of oldLayout and newLayout in the acquire operation's memory barrier. Although the image layout transition is submitted twice, it will only be executed once.

However, this is impossible with the foreign queue, for two reasons:

  1. If the other half is a non-vulkan API, then there are no oldLayout/newLayout parameters.
  2. Even if the other half is only a different driver version (let alone completely different drivers), the driver versions might disagree which half executes the layout transition.

Therefore, it seems that you cannot combine a queue transfer involving the foreign queue with an image layout transition in a single barrier. The "solution" I have been using is to use two barriers. For the release operation:

  1. An image layout transition to GENERAL with no queue transfer.
  2. A queue transfer with oldLayout = newLayout = GENERAL.

And the inverse for the acquire operation.

However, this is more tricky than it might initially appear. You cannot submit both barriers with a single vkCmdPipelineBarrier2. The synchronization scopes of vkCmdPipelineBarrier2 only contain commands submitted previously/afterwards. There is no ordering between barriers within a single vkCmdPipelineBarrier2. Submitting both barriers in a single vkCmdPipelineBarrier2 would therefore effect two unordered memory operations on the image.

You must instead submit barrier 1 in one vkCmdPipelineBarrier2 and then barrier 2 in a separate vkCmdPipelineBarrier2.

Furthermore, you must ensure that both barriers form an execution dependency chain. I'm not sure if there is a way to do this while strictly following the spec, but I've been "doing" it by setting the dstStageMask of barrier 1 and srcStageMask of barrier 2 to the same value.

The reason I believe it cannot be done within the spec is that such a chain requires the intersection of the second synchronization scope of the first barrier and the first synchronization scope of the second barrier to be non-empty. But there are no commands between the two barriers, so the intersection is empty.

This all seems unnecessarily complicated and I wonder if it could be simplified. I see a few possibilities:

  1. Having a dedicated cmd that can be used to acquire/release foreign memory.
  2. Specifying that the layout transition is executed by the release side when transitioning to the foreign queue and removing the requirement that both sides agree on the parameters. And the same for the acquire side.
主要语言
JavaScript
星标
3.4k
派生
555
平均合并
3 天 10 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

KhronosGroup/Vulkan-Docs 的其他 Issue

查看 KhronosGroup/Vulkan-Docs 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。