• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016-2022 The Khronos Group Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5include::{generated}/meta/{refprefix}VK_KHR_external_memory.adoc[]
6
7=== Other Extension Metadata
8
9*Last Modified Date*::
10    2016-10-20
11*IP Status*::
12    No known IP claims.
13*Interactions and External Dependencies*::
14  - Interacts with `apiext:VK_KHR_dedicated_allocation`.
15  - Interacts with `apiext:VK_NV_dedicated_allocation`.
16  - Promoted to Vulkan 1.1 Core
17*Contributors*::
18  - Jason Ekstrand, Intel
19  - Ian Elliott, Google
20  - Jesse Hall, Google
21  - Tobias Hector, Imagination Technologies
22  - James Jones, NVIDIA
23  - Jeff Juliano, NVIDIA
24  - Matthew Netsch, Qualcomm Technologies, Inc.
25  - Daniel Rakos, AMD
26  - Carsten Rohde, NVIDIA
27  - Ray Smith, ARM
28  - Chad Versace, Google
29
30=== Description
31
32An application may wish to reference device memory in multiple Vulkan
33logical devices or instances, in multiple processes, and/or in multiple
34APIs.
35This extension enables an application to export non-Vulkan handles from
36Vulkan memory objects such that the underlying resources can be referenced
37outside the scope of the Vulkan logical device that created them.
38
39=== Promotion to Vulkan 1.1
40
41All functionality in this extension is included in core Vulkan 1.1, with the
42KHR suffix omitted.
43The original type, enum and command names are still available as aliases of
44the core functionality.
45
46include::{generated}/interfaces/VK_KHR_external_memory.adoc[]
47
48=== Issues
49
501) How do applications correlate two physical devices across process or
51Vulkan instance boundaries?
52
53*RESOLVED*: New device ID fields have been introduced by
54`apiext:VK_KHR_external_memory_capabilities`.
55These fields, combined with the existing
56slink:VkPhysicalDeviceProperties::pname:driverVersion field can be used to
57identify compatible devices across processes, drivers, and APIs.
58slink:VkPhysicalDeviceProperties::pname:pipelineCacheUUID is not sufficient
59for this purpose because despite its description in the specification, it
60need only identify a unique pipeline cache format in practice.
61Multiple devices may be able to use the same pipeline cache data, and hence
62it would be desirable for all of them to have the same pipeline cache UUID.
63However, only the same concrete physical device can be used when sharing
64memory, so an actual unique device ID was introduced.
65Further, the pipeline cache UUID was specific to Vulkan, but correlation
66with other, non-extensible APIs is required to enable interoperation with
67those APIs.
68
692) If memory objects are shared between processes and APIs, is this
70considered aliasing according to the rules outlined in the
71<<resources-memory-aliasing,Memory Aliasing>> section?
72
73*RESOLVED*: Yes.
74Applications must take care to obey all restrictions imposed on aliased
75resources when using memory across multiple Vulkan instances or other APIs.
76
773) Are new image layouts or metadata required to specify image layouts and
78layout transitions compatible with non-Vulkan APIs, or with other instances
79of the same Vulkan driver?
80
81*RESOLVED*: Separate instances of the same Vulkan driver running on the same
82GPU should have identical internal layout semantics, so applications have
83the tools they need to ensure views of images are consistent between the two
84instances.
85Other APIs will fall into two categories: Those that are Vulkan- compatible,
86and those that are Vulkan-incompatible.
87Vulkan-incompatible APIs will require the image to be in the GENERAL layout
88whenever they are accessing them.
89
90Note this does not attempt to address cross-device transitions, nor
91transitions to engines on the same device which are not visible within the
92Vulkan API.
93Both of these are beyond the scope of this extension.
94
954) Is a new barrier flag or operation of some type needed to prepare
96external memory for handoff to another Vulkan instance or API and/or receive
97it from another instance or API?
98
99*RESOLVED*: Yes.
100Some implementations need to perform additional cache management when
101transitioning memory between address spaces and other APIs, instances, or
102processes which may operate in a separate address space.
103Options for defining this transition include:
104
105  * A new structure that can be added to the pname:pNext list in
106    slink:VkMemoryBarrier, slink:VkBufferMemoryBarrier, and
107    slink:VkImageMemoryBarrier.
108  * A new bit in tlink:VkAccessFlags that can be set to indicate an
109    "`external`" access.
110  * A new bit in tlink:VkDependencyFlags
111  * A new special queue family that represents an "`external`" queue.
112
113A new structure has the advantage that the type of external transition can
114be described in as much detail as necessary.
115However, there is not currently a known need for anything beyond
116differentiating between external and internal accesses, so this is likely an
117over-engineered solution.
118The access flag bit has the advantage that it can be applied at buffer,
119image, or global granularity, and semantically it maps pretty well to the
120operation being described.
121Additionally, the API already includes ename:VK_ACCESS_MEMORY_READ_BIT and
122ename:VK_ACCESS_MEMORY_WRITE_BIT which appear to be intended for this
123purpose.
124However, there is no obvious pipeline stage that would correspond to an
125external access, and therefore no clear way to use
126ename:VK_ACCESS_MEMORY_READ_BIT or ename:VK_ACCESS_MEMORY_WRITE_BIT.
127tlink:VkDependencyFlags and tlink:VkPipelineStageFlags operate at command
128granularity rather than image or buffer granularity, which would make an
129entire pipeline barrier an internal->external or external->internal barrier.
130This may not be a problem in practice, but seems like the wrong scope.
131Another downside of tlink:VkDependencyFlags is that it lacks inherent
132directionality: there are no ptext:src and ptext:dst variants of it in the
133barrier or dependency description semantics, so two bits might need to be
134added to describe both internal->external and external->internal
135transitions.
136Transitioning a resource to a special queue family corresponds well with the
137operation of transitioning to a separate Vulkan instance, in that both
138operations ideally include scheduling a barrier on both sides of the
139transition: Both the releasing and the acquiring queue or process.
140Using a special queue family requires adding an additional reserved queue
141family index.
142Re-using ename:VK_QUEUE_FAMILY_IGNORED would have left it unclear how to
143transition a concurrent usage resource from one process to another, since
144the semantics would have likely been equivalent to the currently-ignored
145transition of
146ename:VK_QUEUE_FAMILY_IGNORED{nbsp}->{nbsp}ename:VK_QUEUE_FAMILY_IGNORED.
147Fortunately, creating a new reserved queue family index is not invasive.
148
149Based on the above analysis, the approach of transitioning to a special
150"`external`" queue family was chosen.
151
1525) Do internal driver memory arrangements and/or other internal driver image
153properties need to be exported and imported when sharing images across
154processes or APIs.
155
156*RESOLVED*: Some vendors claim this is necessary on their implementations,
157but it was determined that the security risks of allowing opaque metadata to
158be passed from applications to the driver were too high.
159Therefore, implementations which require metadata will need to associate it
160with the objects represented by the external handles, and rely on the
161dedicated allocation mechanism to associate the exported and imported memory
162objects with a single image or buffer.
163
1646) Most prior interoperation and cross-process sharing APIs have been based
165on image-level sharing.
166Should Vulkan sharing be based on memory-object sharing or image sharing?
167
168*RESOLVED*: These extensions have assumed memory-level sharing is the
169correct granularity.
170Vulkan is a lower-level API than most prior APIs, and as such attempts to
171closely align with to the underlying primitives of the hardware and
172system-level drivers it abstracts.
173In general, the resource that holds the backing store for both images and
174buffers of various types is memory.
175Images and buffers are merely metadata containing brief descriptions of the
176layout of bits within that memory.
177
178Because memory object-based sharing is aligned with the overall Vulkan API
179design, it enables the full range of Vulkan capabilities with external
180objects.
181External memory can be used as backing for sparse images, for example,
182whereas such usage would be awkward at best with a sharing mechanism based
183on higher-level primitives such as images.
184Further, aligning the mechanism with the API in this way provides some hope
185of trivial compatibility with future API enhancements.
186If new objects backed by memory objects are added to the API, they too can
187be used across processes with minimal additions to the base external memory
188APIs.
189
190Earlier APIs implemented interop at a higher level, and this necessitated
191entirely separate sharing APIs for images and buffers.
192To co-exist and interoperate with those APIs, the Vulkan external sharing
193mechanism must accommodate their model.
194However, if it can be agreed that memory-based sharing is the more desirable
195and forward-looking design, legacy interoperation constraints can be
196considered another reason to favor memory-based sharing: while native and
197legacy driver primitives that may be used to implement sharing may not be as
198low-level as the API here suggests, raw memory is still the least common
199denominator among the types.
200Image-based sharing can be cleanly derived from a set of base memory- object
201sharing APIs with minimal effort, whereas image-based sharing does not
202generalize well to buffer or raw-memory sharing.
203Therefore, following the general Vulkan design principle of minimalism, it
204is better to expose interopability with image-based native and external
205primitives via the memory sharing API, and place sufficient limits on their
206usage to ensure they can be used only as backing for equivalent Vulkan
207images.
208This provides a consistent API for applications regardless of which platform
209or external API they are targeting, which makes development of multi-API and
210multi-platform applications simpler.
211
2127) Should Vulkan define a common external handle type and provide Vulkan
213functions to facilitate cross-process sharing of such handles rather than
214relying on native handles to define the external objects?
215
216*RESOLVED*: No.
217Cross-process sharing of resources is best left to native platforms.
218There are myriad security and extensibility issues with such a mechanism,
219and attempting to re-solve all those issues within Vulkan does not align
220with Vulkan's purpose as a graphics API.
221If desired, such a mechanism could be built as a layer or helper library on
222top of the opaque native handle defined in this family of extensions.
223
2248) Must implementations provide additional guarantees about state implicitly
225included in memory objects for those memory objects that may be exported?
226
227*RESOLVED*: Implementations must ensure that sharing memory objects does not
228transfer any information between the exporting and importing instances and
229APIs other than that required to share the data contained in the memory
230objects explicitly shared.
231As specific examples, data from previously freed memory objects that used
232the same underlying physical memory, and data from memory obects using
233adjacent physical memory must not be visible to applications importing an
234exported memory object.
235
2369) Must implementations validate external handles the application provides
237as inputs to memory import operations?
238
239*RESOLVED*: Implementations must return an error to the application if the
240provided memory handle cannot be used to complete the requested import
241operation.
242However, implementations need not validate handles are of the exact type
243specified by the application.
244
245=== Version History
246
247  * Revision 1, 2016-10-20 (James Jones)
248  ** Initial version
249