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