• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2023-2024 The Khronos Group Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5= VK_KHR_video_maintenance1
6:toc: left
7:refpage: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/
8:sectnums:
9
10This proposal details and addresses the issues solved by the `VK_KHR_video_maintenance1` extension.
11
12== Problem Statement
13
14Over time, a collection of minor features, none of which would warrant an entire extension of their own, and some of which have been identified after the final version of the first set of video coding extensions were released, justified the creation of a video maintenance extension:
15
16The following is a list of issues considered in this proposal:
17
18  * Relax the requirement for the application having to specify video profiles when creating buffer or image resources with video usage
19  * Simplify how queries work in video coding
20
21
22== Solution Space
23
24=== Relaxed video profile compatibility
25
26For buffers and images used in video coding, it is currently required that applications have to specify all video profiles which these resources will be used with. In case of video decoding, this requirement is not too limiting. However, in transcoding use cases it is very common for the application to not have a full list up-front of all possible video encode profiles the resources will be intended to be used with which may limit the application's ability to reuse the decode output picture resources directly as the encode input picture resources.
27
28The motivation behind requiring the specification of all video profiles the created resources are planned to be used with is that knowing that information up-front enables implementations to use the optimal representation option when multiple choices may be available. In particular, image resources may be optimized both from memory usage and memory layout perspective specifically for that explicit list of video profiles, while not having that information available may result in representations that require worst case memory storage that may also suffer from suboptimal access performance.
29
30The following two main options have been considered to address this issue:
31
32  1. Allow opting in to exclude certain subsets of video profile parameters from the video profile compatibility criteria
33  2. Allow creating resources in an entirely video profile independent fashion
34
35Option 1 is problematic, because one would either have to draw an arbitrary line between parameters affecting the video profile compatibility criteria vs those which do not, or there would be a need to introduce multiple options and complex compatibility rules to allow more flexibility.
36
37In practice, most of the benefits of knowing the video profiles up-front are only important for DPB images, which are not expected to be shared between video sessions using different video profiles anyway, hence this extension follows option 2 with the restriction that image resources with only DPB video usage cannot be created as video profile independent resources.
38
39Nonetheless, while this extension enables creating video profile independent buffers with video usage, and creating video profile independent images with video decode output or video encode input usage, applications that do know the set of video profiles up-front should still prefer specifying those instead of creating video profile independent resources, as that may still provide some performance or memory usage benefits on certain implementations.
40
41=== Simplified video queries
42
43Currently, queries performed in video coding scopes use the same scoped `vkCmdBegin/EndQuery` commands, as the ones used in the vast majority of the cases across the Vulkan API, with the notable exception timestamp queries and some ray tracing related queries.
44
45This poses some problems in the context of video coding for the following reasons:
46
47  * Query slots are consumed and query results are produced on a per video coding operation basis. While a scoped query is a good fit for queries that collect statistics over multiple commands (like occlusion queries and pipeline statistics queries), scoped queries are not a good fit for video coding operations as they allow for command sequences that are invalid (like recording multiple video coding operations within the scope of a query) or simply useless (like recording a `vkCmdBegin/EndQuery` command pair without issuing any video coding operations in between)
48  * This would only get more complicated if future video coding functionality would introduce the ability to issue multiple video coding operations through the recording of a single video coding command, and thus would need to consume more than a single query slot, as there are no variants of the `vkCmdBegin/EndQuery` commands that allow running more than one query within a scope (excluding the awkward corner case of query behavior with multiview rendering)
49  * In addition, as in practice the scope of video queries will only ever span a single video coding command, the additional overhead of calling the `vkCmdBegin/EndQuery` commands before/after the video coding command which the query will apply to is simply wasteful
50
51The straightforward answer to these problems is to provide the query information directly to the video coding command it applies to. Considering that some ray tracing related queries already follow this model, such an API change would not create a new precedence either.
52
53The following options have been considered to define the interaction between `vkCmdBegin/EndQuery`-style scoped queries and the newly introduced inline queries:
54
55  1. Only allow inline queries when the features of this extension are enabled
56  2. Allow mixing scoped queries and inline queries
57  3. Make the use of scoped queries and inline queries mutually exclusive within a video coding scope
58  4. Make the use of scoped queries and inline queries mutually exclusive on a per video session basis
59
60The problem with option 1 is that it could cause backward-compatibility issues for any legacy content that may automatically enable all features available on the implementation.
61
62Option 2 is the most flexible, but it would add a lot of unnecessary complexity to implementations.
63
64Between option 3 and 4, the only difference is the granularity at which the application has to choose between the use of scoped queries and inline queries. However, as in practice it is highly unlikely for an application to mix the two forms of queries, option 4 is preferred due to its simplicity.
65
66Going forward, applications should prefer to use inline queries, when available, as support for using scoped video queries is unlikely to be extended to be compatible with any future video coding functionalities that may require the use of multiple query slots.
67
68
69== Proposal
70
71Items introduced by this extension are:
72
73=== Video profile independent buffer creation
74
75The new `VK_BUFFER_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR` buffer creation flag enables creating buffers that can be used in video coding operations, independent of the used video profile.
76
77=== Video profile independent image creation
78
79The new `VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR` image creation flag enables creating images (except for DPB-only video usage) that can be used in video coding operations, independent of the used video profile.
80
81=== Inline video queries
82
83When creating a video session with the new `VK_VIDEO_SESSION_CREATE_INLINE_QUERIES_BIT_KHR` flag, instead of using the `vkCmdBegin/EndQuery` commands, applications can issue queries inline with the video coding commands themselves by chaining the following new structure to the `pNext` chain of the corresponding video coding command's input parameter structure (e.g. to `VkVideoDecodeInfoKHR` or `VkVideoEncodeInfoKHR`):
84
85[source,c]
86----
87typedef struct VkVideoInlineQueryInfoKHR {
88    VkStructureType    sType;
89    const void*        pNext;
90    VkQueryPool        queryPool;
91    uint32_t           firstQuery;
92    uint32_t           queryCount;
93} VkVideoInlineQueryInfoKHR;
94----
95
96== Examples
97
98=== Create video profile independent bitstream buffer
99
100[source,c]
101----
102VkBuffer buffer = VK_NULL_HANDLE;
103
104VkBufferCreateInfo createInfo = {
105    .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
106    .pNext = NULL, // No need to specify video profile list
107    .flags = VK_BUFFER_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR,
108    ... // buffer creation parameters including one or more video-specific usage flags
109};
110
111vkCreateBuffer(device, &createInfo, NULL, &buffer);
112----
113
114
115=== Create video profile independent image backing video picture resources
116
117[source,c]
118----
119VkImage image = VK_NULL_HANDLE;
120
121VkImageCreateInfo imageCreateInfo = {
122    .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
123    .pNext = NULL, // No need to specify video profile list
124    .flags = VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR,
125    ... // image creation parameters including one or more video-specific usage flags
126    // NOTE: usage must not contain DPB use as the only video-specific usage flag
127};
128
129vkCreateImage(device, &imageCreateInfo, NULL, &image);
130----
131
132
133=== Using inline queries with a video session
134
135[source,c]
136----
137// Create video session with inline query support
138VkVideoSessionKHR videoSession = VK_NULL_HANDLE;
139
140VkVideoSessionCreateInfoKHR createInfo = {
141    .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_CREATE_INFO_KHR,
142    .pNext = NULL,
143    .queueFamilyIndex = ... // index of queue family that supports the video codec operation
144    .flags = VK_VIDEO_SESSION_CREATE_INLINE_QUERIES_BIT_KHR, // opt-in to use inline queries
145    ...
146};
147
148vkCreateVideoSessionKHR(device, &createInfo, NULL, &videoSession);
149
150// Create query pool as usual
151VkQueryPool queryPool = VK_NULL_HANDLE;
152
153VkVideoProfileInfoKHR profileInfo = {
154    ...
155};
156
157VkQueryPoolCreateInfo createInfo = {
158    .sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,
159    .pNext = &profileInfo,
160    ...
161};
162
163vkCreateQueryPool(device, &createInfo, NULL, &queryPool);
164
165...
166vkBeginCommandBuffer(commandBuffer, ...);
167...
168vkCmdBeginVideoCodingKHR(commandBuffer, ...);
169...
170
171// Execute single query inline with a video codec operation
172VkVideoInlineQueryInfoKHR inlineQueryInfo = {
173    .sType = VK_STRUCTURE_TYPE_VIDEO_INLINE_QUERY_INFO_KHR,
174    .pNext = NULL,
175    .queryPool = queryPool,
176    .firstQuery = 0,
177    .queryCount = 1
178};
179
180// Include inlineQueryInfo in the pNext chain of the video codec command parameters
181// (e.g. VkVideoDecodeInfoKHR or VkVideoEncodeInfoKHR).
182
183// Issue video coding operation
184
185...
186vkCmdEndVideoCodingKHR(commandBuffer, ...);
187...
188vkEndCommandBuffer(commandBuffer);
189...
190----
191
192
193== Issues
194
195None.
196
197
198== Further Functionality
199
200None.
201