3 # Copyright (c) 2015-2025 The Khronos Group Inc.
4 # Copyright (c) 2015-2025 Valve Corporation
5 # Copyright (c) 2015-2025 LunarG, Inc.
6 # Copyright (c) 2015-2025 Google Inc.
7 # Copyright (c) 2023-2025 RasterGrid Kft.
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 # Author: Tobin Ehlis <tobine@google.com>
23 # This script generates a Mock ICD that intercepts almost all Vulkan
24 # functions. That layer is not intended to be useful or even compilable
25 # in its initial state. Rather it's intended to be a starting point that
26 # can be copied and customized to assist in creation of a new layer.
29 from generator
import *
30 from common_codegen
import *
32 CUSTOM_C_INTERCEPTS
= {
33 'vkCreateInstance': '''
34 // TODO: If loader ver <=4 ICD must fail with VK_ERROR_INCOMPATIBLE_DRIVER for all vkCreateInstance calls with
35 // apiVersion set to > Vulkan 1.0 because the loader is still at interface version <= 4. Otherwise, the
36 // ICD should behave as normal.
37 if (loader_interface_version <= 4) {
38 return VK_ERROR_INCOMPATIBLE_DRIVER;
40 *pInstance = (VkInstance)CreateDispObjHandle();
41 for (auto& physical_device : physical_device_map[*pInstance])
42 physical_device = (VkPhysicalDevice)CreateDispObjHandle();
43 // TODO: If emulating specific device caps, will need to add intelligence here
46 'vkDestroyInstance': '''
48 for (const auto physical_device : physical_device_map.at(instance)) {
49 display_map.erase(physical_device);
50 DestroyDispObjHandle((void*)physical_device);
52 physical_device_map.erase(instance);
53 DestroyDispObjHandle((void*)instance);
56 'vkAllocateCommandBuffers': '''
57 unique_lock_t lock(global_lock);
58 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; ++i) {
59 pCommandBuffers[i] = (VkCommandBuffer)CreateDispObjHandle();
60 command_pool_buffer_map[pAllocateInfo->commandPool].push_back(pCommandBuffers[i]);
64 'vkFreeCommandBuffers': '''
65 unique_lock_t lock(global_lock);
66 for (auto i = 0u; i < commandBufferCount; ++i) {
67 if (!pCommandBuffers[i]) {
71 for (auto& pair : command_pool_buffer_map) {
72 auto& cbs = pair.second;
73 auto it = std::find(cbs.begin(), cbs.end(), pCommandBuffers[i]);
74 if (it != cbs.end()) {
79 DestroyDispObjHandle((void*) pCommandBuffers[i]);
82 'vkCreateCommandPool': '''
83 unique_lock_t lock(global_lock);
84 *pCommandPool = (VkCommandPool)global_unique_handle++;
85 command_pool_map[device].insert(*pCommandPool);
88 'vkDestroyCommandPool': '''
89 // destroy command buffers for this pool
90 unique_lock_t lock(global_lock);
91 auto it = command_pool_buffer_map.find(commandPool);
92 if (it != command_pool_buffer_map.end()) {
93 for (auto& cb : it->second) {
94 DestroyDispObjHandle((void*) cb);
96 command_pool_buffer_map.erase(it);
98 command_pool_map[device].erase(commandPool);
100 'vkEnumeratePhysicalDevices': '''
101 VkResult result_code = VK_SUCCESS;
102 if (pPhysicalDevices) {
103 const auto return_count = (std::min)(*pPhysicalDeviceCount, icd_physical_device_count);
104 for (uint32_t i = 0; i < return_count; ++i) pPhysicalDevices[i] = physical_device_map.at(instance)[i];
105 if (return_count < icd_physical_device_count) result_code = VK_INCOMPLETE;
106 *pPhysicalDeviceCount = return_count;
108 *pPhysicalDeviceCount = icd_physical_device_count;
112 'vkCreateDevice': '''
113 *pDevice = (VkDevice)CreateDispObjHandle();
114 // TODO: If emulating specific device caps, will need to add intelligence here
117 'vkDestroyDevice': '''
118 unique_lock_t lock(global_lock);
119 // First destroy sub-device objects
121 for (auto queue_family_map_pair : queue_map[device]) {
122 for (auto index_queue_pair : queue_map[device][queue_family_map_pair.first]) {
123 DestroyDispObjHandle((void*)index_queue_pair.second);
127 for (auto& cp : command_pool_map[device]) {
128 for (auto& cb : command_pool_buffer_map[cp]) {
129 DestroyDispObjHandle((void*) cb);
131 command_pool_buffer_map.erase(cp);
133 command_pool_map[device].clear();
135 queue_map.erase(device);
136 buffer_map.erase(device);
137 image_memory_size_map.erase(device);
138 // Now destroy device
139 DestroyDispObjHandle((void*)device);
140 // TODO: If emulating specific device caps, will need to add intelligence here
142 'vkGetDeviceQueue': '''
143 unique_lock_t lock(global_lock);
144 auto queue = queue_map[device][queueFamilyIndex][queueIndex];
148 *pQueue = queue_map[device][queueFamilyIndex][queueIndex] = (VkQueue)CreateDispObjHandle();
150 // TODO: If emulating specific device caps, will need to add intelligence here
153 'vkGetDeviceQueue2': '''
154 GetDeviceQueue(device, pQueueInfo->queueFamilyIndex, pQueueInfo->queueIndex, pQueue);
155 // TODO: Add further support for GetDeviceQueue2 features
157 'vkEnumerateInstanceLayerProperties': '''
160 'vkEnumerateInstanceVersion': '''
161 *pApiVersion = VK_HEADER_VERSION_COMPLETE;
164 'vkEnumerateDeviceLayerProperties': '''
167 'vkEnumerateInstanceExtensionProperties': '''
168 // If requesting number of extensions, return that
171 *pPropertyCount = (uint32_t)instance_extension_map.size();
174 for (const auto &name_ver_pair : instance_extension_map) {
175 if (i == *pPropertyCount) {
178 std::strncpy(pProperties[i].extensionName, name_ver_pair.first.c_str(), sizeof(pProperties[i].extensionName));
179 pProperties[i].extensionName[sizeof(pProperties[i].extensionName) - 1] = 0;
180 pProperties[i].specVersion = name_ver_pair.second;
183 if (i != instance_extension_map.size()) {
184 return VK_INCOMPLETE;
188 // If requesting extension properties, fill in data struct for number of extensions
191 'vkEnumerateDeviceExtensionProperties': '''
192 // If requesting number of extensions, return that
195 *pPropertyCount = (uint32_t)device_extension_map.size();
198 for (const auto &name_ver_pair : device_extension_map) {
199 if (i == *pPropertyCount) {
202 std::strncpy(pProperties[i].extensionName, name_ver_pair.first.c_str(), sizeof(pProperties[i].extensionName));
203 pProperties[i].extensionName[sizeof(pProperties[i].extensionName) - 1] = 0;
204 pProperties[i].specVersion = name_ver_pair.second;
207 if (i != device_extension_map.size()) {
208 return VK_INCOMPLETE;
212 // If requesting extension properties, fill in data struct for number of extensions
215 'vkGetPhysicalDeviceSurfacePresentModesKHR': '''
216 // Currently always say that all present modes are supported
217 if (!pPresentModes) {
218 *pPresentModeCount = 6;
220 if (*pPresentModeCount >= 6) pPresentModes[5] = VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR;
221 if (*pPresentModeCount >= 5) pPresentModes[4] = VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR;
222 if (*pPresentModeCount >= 4) pPresentModes[3] = VK_PRESENT_MODE_FIFO_RELAXED_KHR;
223 if (*pPresentModeCount >= 3) pPresentModes[2] = VK_PRESENT_MODE_FIFO_KHR;
224 if (*pPresentModeCount >= 2) pPresentModes[1] = VK_PRESENT_MODE_MAILBOX_KHR;
225 if (*pPresentModeCount >= 1) pPresentModes[0] = VK_PRESENT_MODE_IMMEDIATE_KHR;
229 'vkGetPhysicalDeviceSurfaceFormatsKHR': '''
230 // Currently always say that RGBA8 & BGRA8 are supported
231 if (!pSurfaceFormats) {
232 *pSurfaceFormatCount = 2;
234 if (*pSurfaceFormatCount >= 2) {
235 pSurfaceFormats[1].format = VK_FORMAT_R8G8B8A8_UNORM;
236 pSurfaceFormats[1].colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
238 if (*pSurfaceFormatCount >= 1) {
239 pSurfaceFormats[0].format = VK_FORMAT_B8G8R8A8_UNORM;
240 pSurfaceFormats[0].colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
245 'vkGetPhysicalDeviceSurfaceFormats2KHR': '''
246 // Currently always say that RGBA8 & BGRA8 are supported
247 if (!pSurfaceFormats) {
248 *pSurfaceFormatCount = 2;
250 if (*pSurfaceFormatCount >= 2) {
251 pSurfaceFormats[1].pNext = nullptr;
252 pSurfaceFormats[1].surfaceFormat.format = VK_FORMAT_R8G8B8A8_UNORM;
253 pSurfaceFormats[1].surfaceFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
255 if (*pSurfaceFormatCount >= 1) {
256 pSurfaceFormats[1].pNext = nullptr;
257 pSurfaceFormats[0].surfaceFormat.format = VK_FORMAT_B8G8R8A8_UNORM;
258 pSurfaceFormats[0].surfaceFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
263 'vkGetPhysicalDeviceSurfaceSupportKHR': '''
264 // Currently say that all surface/queue combos are supported
265 *pSupported = VK_TRUE;
268 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR': '''
269 // In general just say max supported is available for requested surface
270 pSurfaceCapabilities->minImageCount = 1;
271 pSurfaceCapabilities->maxImageCount = 0;
272 pSurfaceCapabilities->currentExtent.width = 0xFFFFFFFF;
273 pSurfaceCapabilities->currentExtent.height = 0xFFFFFFFF;
274 pSurfaceCapabilities->minImageExtent.width = 1;
275 pSurfaceCapabilities->minImageExtent.height = 1;
276 pSurfaceCapabilities->maxImageExtent.width = 0xFFFF;
277 pSurfaceCapabilities->maxImageExtent.height = 0xFFFF;
278 pSurfaceCapabilities->maxImageArrayLayers = 128;
279 pSurfaceCapabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR |
280 VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR |
281 VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR |
282 VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR |
283 VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR |
284 VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR |
285 VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR |
286 VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR |
287 VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR;
288 pSurfaceCapabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
289 pSurfaceCapabilities->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR |
290 VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR |
291 VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR |
292 VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
293 pSurfaceCapabilities->supportedUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
294 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
295 VK_IMAGE_USAGE_SAMPLED_BIT |
296 VK_IMAGE_USAGE_STORAGE_BIT |
297 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
298 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
299 VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT |
300 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
303 'vkGetPhysicalDeviceSurfaceCapabilities2KHR': '''
304 GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, pSurfaceInfo->surface, &pSurfaceCapabilities->surfaceCapabilities);
306 auto *present_mode_compatibility = lvl_find_mod_in_chain<VkSurfacePresentModeCompatibilityEXT>(pSurfaceCapabilities->pNext);
307 if (present_mode_compatibility) {
308 if (!present_mode_compatibility->pPresentModes) {
309 present_mode_compatibility->presentModeCount = 3;
312 present_mode_compatibility->pPresentModes[0] = VK_PRESENT_MODE_IMMEDIATE_KHR;
313 present_mode_compatibility->pPresentModes[1] = VK_PRESENT_MODE_FIFO_KHR;
314 present_mode_compatibility->pPresentModes[2] = VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR;
319 'vkGetInstanceProcAddr': '''
320 if (!negotiate_loader_icd_interface_called) {
321 loader_interface_version = 0;
323 const auto &item = name_to_funcptr_map.find(pName);
324 if (item != name_to_funcptr_map.end()) {
325 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
327 // Mock should intercept all functions so if we get here just return null
330 'vkGetDeviceProcAddr': '''
331 return GetInstanceProcAddr(nullptr, pName);
333 'vkGetPhysicalDeviceMemoryProperties': '''
334 pMemoryProperties->memoryTypeCount = 6;
335 // Host visible Coherent
336 pMemoryProperties->memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
337 pMemoryProperties->memoryTypes[0].heapIndex = 0;
338 // Host visible Cached
339 pMemoryProperties->memoryTypes[1].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
340 pMemoryProperties->memoryTypes[1].heapIndex = 0;
341 // Device local and Host visible
342 pMemoryProperties->memoryTypes[2].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
343 pMemoryProperties->memoryTypes[2].heapIndex = 1;
344 // Device local lazily
345 pMemoryProperties->memoryTypes[3].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
346 pMemoryProperties->memoryTypes[3].heapIndex = 1;
347 // Device local protected
348 pMemoryProperties->memoryTypes[4].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_PROTECTED_BIT;
349 pMemoryProperties->memoryTypes[4].heapIndex = 1;
351 pMemoryProperties->memoryTypes[5].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
352 pMemoryProperties->memoryTypes[5].heapIndex = 1;
353 pMemoryProperties->memoryHeapCount = 2;
354 pMemoryProperties->memoryHeaps[0].flags = VK_MEMORY_HEAP_MULTI_INSTANCE_BIT;
355 pMemoryProperties->memoryHeaps[0].size = 8000000000;
356 pMemoryProperties->memoryHeaps[1].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
357 pMemoryProperties->memoryHeaps[1].size = 8000000000;
359 'vkGetPhysicalDeviceMemoryProperties2KHR': '''
360 GetPhysicalDeviceMemoryProperties(physicalDevice, &pMemoryProperties->memoryProperties);
362 'vkGetPhysicalDeviceQueueFamilyProperties': '''
363 if (pQueueFamilyProperties) {
364 std::vector<VkQueueFamilyProperties2KHR> props2(*pQueueFamilyPropertyCount, {
365 VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR});
366 GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, props2.data());
367 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) {
368 pQueueFamilyProperties[i] = props2[i].queueFamilyProperties;
371 GetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, nullptr);
374 'vkGetPhysicalDeviceQueueFamilyProperties2KHR': '''
375 if (pQueueFamilyProperties) {
376 if (*pQueueFamilyPropertyCount >= 1) {
377 auto props = &pQueueFamilyProperties[0].queueFamilyProperties;
378 props->queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT
379 | VK_QUEUE_SPARSE_BINDING_BIT | VK_QUEUE_PROTECTED_BIT;
380 props->queueCount = 1;
381 props->timestampValidBits = 16;
382 props->minImageTransferGranularity = {1,1,1};
384 if (*pQueueFamilyPropertyCount >= 2) {
385 auto props = &pQueueFamilyProperties[1].queueFamilyProperties;
386 props->queueFlags = VK_QUEUE_TRANSFER_BIT | VK_QUEUE_PROTECTED_BIT | VK_QUEUE_VIDEO_DECODE_BIT_KHR;
387 props->queueCount = 1;
388 props->timestampValidBits = 16;
389 props->minImageTransferGranularity = {1,1,1};
391 auto status_query_props = lvl_find_mod_in_chain<VkQueueFamilyQueryResultStatusPropertiesKHR>(pQueueFamilyProperties[1].pNext);
392 if (status_query_props) {
393 status_query_props->queryResultStatusSupport = VK_TRUE;
395 auto video_props = lvl_find_mod_in_chain<VkQueueFamilyVideoPropertiesKHR>(pQueueFamilyProperties[1].pNext);
397 video_props->videoCodecOperations = VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR
398 | VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR
399 | VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR;
402 if (*pQueueFamilyPropertyCount >= 3) {
403 auto props = &pQueueFamilyProperties[2].queueFamilyProperties;
404 props->queueFlags = VK_QUEUE_TRANSFER_BIT | VK_QUEUE_PROTECTED_BIT | VK_QUEUE_VIDEO_ENCODE_BIT_KHR;
405 props->queueCount = 1;
406 props->timestampValidBits = 16;
407 props->minImageTransferGranularity = {1,1,1};
409 auto status_query_props = lvl_find_mod_in_chain<VkQueueFamilyQueryResultStatusPropertiesKHR>(pQueueFamilyProperties[2].pNext);
410 if (status_query_props) {
411 status_query_props->queryResultStatusSupport = VK_TRUE;
413 auto video_props = lvl_find_mod_in_chain<VkQueueFamilyVideoPropertiesKHR>(pQueueFamilyProperties[2].pNext);
415 video_props->videoCodecOperations = VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR
416 | VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR
417 | VK_VIDEO_CODEC_OPERATION_ENCODE_AV1_BIT_KHR;
420 if (*pQueueFamilyPropertyCount > 3) {
421 *pQueueFamilyPropertyCount = 3;
424 *pQueueFamilyPropertyCount = 3;
427 'vkGetPhysicalDeviceFeatures': '''
428 uint32_t num_bools = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
429 VkBool32 *bool_array = &pFeatures->robustBufferAccess;
430 SetBoolArrayTrue(bool_array, num_bools);
432 'vkGetPhysicalDeviceFeatures2KHR': '''
433 GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
434 uint32_t num_bools = 0; // Count number of VkBool32s in extension structs
435 VkBool32* feat_bools = nullptr;
436 auto vk_1_1_features = lvl_find_mod_in_chain<VkPhysicalDeviceVulkan11Features>(pFeatures->pNext);
437 if (vk_1_1_features) {
438 vk_1_1_features->protectedMemory = VK_TRUE;
440 auto vk_1_3_features = lvl_find_mod_in_chain<VkPhysicalDeviceVulkan13Features>(pFeatures->pNext);
441 if (vk_1_3_features) {
442 vk_1_3_features->synchronization2 = VK_TRUE;
444 auto prot_features = lvl_find_mod_in_chain<VkPhysicalDeviceProtectedMemoryFeatures>(pFeatures->pNext);
446 prot_features->protectedMemory = VK_TRUE;
448 auto sync2_features = lvl_find_mod_in_chain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pFeatures->pNext);
449 if (sync2_features) {
450 sync2_features->synchronization2 = VK_TRUE;
452 auto video_maintenance1_features = lvl_find_mod_in_chain<VkPhysicalDeviceVideoMaintenance1FeaturesKHR>(pFeatures->pNext);
453 if (video_maintenance1_features) {
454 video_maintenance1_features->videoMaintenance1 = VK_TRUE;
456 const auto *desc_idx_features = lvl_find_in_chain<VkPhysicalDeviceDescriptorIndexingFeaturesEXT>(pFeatures->pNext);
457 if (desc_idx_features) {
458 const auto bool_size = sizeof(VkPhysicalDeviceDescriptorIndexingFeaturesEXT) - offsetof(VkPhysicalDeviceDescriptorIndexingFeaturesEXT, shaderInputAttachmentArrayDynamicIndexing);
459 num_bools = bool_size/sizeof(VkBool32);
460 feat_bools = (VkBool32*)&desc_idx_features->shaderInputAttachmentArrayDynamicIndexing;
461 SetBoolArrayTrue(feat_bools, num_bools);
463 const auto *blendop_features = lvl_find_in_chain<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT>(pFeatures->pNext);
464 if (blendop_features) {
465 const auto bool_size = sizeof(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT) - offsetof(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT, advancedBlendCoherentOperations);
466 num_bools = bool_size/sizeof(VkBool32);
467 feat_bools = (VkBool32*)&blendop_features->advancedBlendCoherentOperations;
468 SetBoolArrayTrue(feat_bools, num_bools);
470 const auto *host_image_copy_features = lvl_find_in_chain<VkPhysicalDeviceHostImageCopyFeaturesEXT>(pFeatures->pNext);
471 if (host_image_copy_features) {
472 feat_bools = (VkBool32*)&host_image_copy_features->hostImageCopy;
473 SetBoolArrayTrue(feat_bools, 1);
476 'vkGetPhysicalDeviceFormatProperties': '''
477 if (VK_FORMAT_UNDEFINED == format) {
478 *pFormatProperties = { 0x0, 0x0, 0x0 };
480 // Default to a color format, skip DS bit
481 *pFormatProperties = { 0x00FFFDFF, 0x00FFFDFF, 0x00FFFDFF };
483 case VK_FORMAT_D16_UNORM:
484 case VK_FORMAT_X8_D24_UNORM_PACK32:
485 case VK_FORMAT_D32_SFLOAT:
486 case VK_FORMAT_S8_UINT:
487 case VK_FORMAT_D16_UNORM_S8_UINT:
488 case VK_FORMAT_D24_UNORM_S8_UINT:
489 case VK_FORMAT_D32_SFLOAT_S8_UINT:
490 // Don't set color bits for DS formats
491 *pFormatProperties = { 0x00FFFE7F, 0x00FFFE7F, 0x00FFFE7F };
493 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
494 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
495 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
496 case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16:
497 case VK_FORMAT_G8_B8R8_2PLANE_444_UNORM:
498 // Set decode/encode bits for these formats
499 *pFormatProperties = { 0x1EFFFDFF, 0x1EFFFDFF, 0x00FFFDFF };
506 'vkGetPhysicalDeviceFormatProperties2KHR': '''
507 GetPhysicalDeviceFormatProperties(physicalDevice, format, &pFormatProperties->formatProperties);
508 VkFormatProperties3KHR *props_3 = lvl_find_mod_in_chain<VkFormatProperties3KHR>(pFormatProperties->pNext);
510 props_3->linearTilingFeatures = pFormatProperties->formatProperties.linearTilingFeatures;
511 props_3->optimalTilingFeatures = pFormatProperties->formatProperties.optimalTilingFeatures;
512 props_3->bufferFeatures = pFormatProperties->formatProperties.bufferFeatures;
513 props_3->optimalTilingFeatures |= VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT;
516 'vkGetPhysicalDeviceImageFormatProperties': '''
517 // A hardcoded unsupported format
518 if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) {
519 return VK_ERROR_FORMAT_NOT_SUPPORTED;
522 // TODO: Just hard-coding some values for now
523 // TODO: If tiling is linear, limit the mips, levels, & sample count
524 if (VK_IMAGE_TILING_LINEAR == tiling) {
525 *pImageFormatProperties = { { 4096, 4096, 256 }, 1, 1, VK_SAMPLE_COUNT_1_BIT, 4294967296 };
527 // We hard-code support for all sample counts except 64 bits.
528 *pImageFormatProperties = { { 4096, 4096, 256 }, 12, 256, 0x7F & ~VK_SAMPLE_COUNT_64_BIT, 4294967296 };
532 'vkGetPhysicalDeviceImageFormatProperties2KHR': '''
533 auto *external_image_prop = lvl_find_mod_in_chain<VkExternalImageFormatProperties>(pImageFormatProperties->pNext);
534 auto *external_image_format = lvl_find_in_chain<VkPhysicalDeviceExternalImageFormatInfo>(pImageFormatInfo->pNext);
535 if (external_image_prop && external_image_format) {
536 external_image_prop->externalMemoryProperties.externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
537 external_image_prop->externalMemoryProperties.compatibleHandleTypes = external_image_format->handleType;
540 GetPhysicalDeviceImageFormatProperties(physicalDevice, pImageFormatInfo->format, pImageFormatInfo->type, pImageFormatInfo->tiling, pImageFormatInfo->usage, pImageFormatInfo->flags, &pImageFormatProperties->imageFormatProperties);
543 'vkGetPhysicalDeviceSparseImageFormatProperties': '''
548 pProperties->imageGranularity = {4, 4, 4};
549 pProperties->flags = VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT;
551 case VK_FORMAT_D16_UNORM:
552 case VK_FORMAT_D32_SFLOAT:
553 pProperties->aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
555 case VK_FORMAT_S8_UINT:
556 pProperties->aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
558 case VK_FORMAT_X8_D24_UNORM_PACK32:
559 case VK_FORMAT_D16_UNORM_S8_UINT:
560 case VK_FORMAT_D24_UNORM_S8_UINT:
561 case VK_FORMAT_D32_SFLOAT_S8_UINT:
562 pProperties->aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
565 pProperties->aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
570 'vkGetPhysicalDeviceSparseImageFormatProperties2KHR': '''
571 if (pPropertyCount && pProperties) {
572 GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, pFormatInfo->format, pFormatInfo->type, pFormatInfo->samples, pFormatInfo->usage, pFormatInfo->tiling, pPropertyCount, &pProperties->properties);
574 GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, pFormatInfo->format, pFormatInfo->type, pFormatInfo->samples, pFormatInfo->usage, pFormatInfo->tiling, pPropertyCount, nullptr);
577 'vkGetPhysicalDeviceProperties': '''
578 pProperties->apiVersion = VK_HEADER_VERSION_COMPLETE;
579 pProperties->driverVersion = 1;
580 pProperties->vendorID = 0xba5eba11;
581 pProperties->deviceID = 0xf005ba11;
582 pProperties->deviceType = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
583 //std::string devName = "Vulkan Mock Device";
584 strcpy(pProperties->deviceName, "Vulkan Mock Device");
585 pProperties->pipelineCacheUUID[0] = 18;
586 pProperties->limits = SetLimits(&pProperties->limits);
587 pProperties->sparseProperties = { VK_TRUE, VK_TRUE, VK_TRUE, VK_TRUE, VK_TRUE };
589 'vkGetPhysicalDeviceProperties2KHR': '''
590 // The only value that need to be set are those the Profile layer can't set
591 // see https://github.com/KhronosGroup/Vulkan-Profiles/issues/352
592 // All values set are arbitrary
593 GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
595 auto *props_11 = lvl_find_mod_in_chain<VkPhysicalDeviceVulkan11Properties>(pProperties->pNext);
597 props_11->protectedNoFault = VK_FALSE;
600 auto *props_12 = lvl_find_mod_in_chain<VkPhysicalDeviceVulkan12Properties>(pProperties->pNext);
602 props_12->denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL;
603 props_12->roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL;
606 auto *props_13 = lvl_find_mod_in_chain<VkPhysicalDeviceVulkan13Properties>(pProperties->pNext);
608 props_13->storageTexelBufferOffsetSingleTexelAlignment = VK_TRUE;
609 props_13->uniformTexelBufferOffsetSingleTexelAlignment = VK_TRUE;
610 props_13->storageTexelBufferOffsetAlignmentBytes = 16;
611 props_13->uniformTexelBufferOffsetAlignmentBytes = 16;
614 auto *protected_memory_props = lvl_find_mod_in_chain<VkPhysicalDeviceProtectedMemoryProperties>(pProperties->pNext);
615 if (protected_memory_props) {
616 protected_memory_props->protectedNoFault = VK_FALSE;
619 auto *float_controls_props = lvl_find_mod_in_chain<VkPhysicalDeviceFloatControlsProperties>(pProperties->pNext);
620 if (float_controls_props) {
621 float_controls_props->denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL;
622 float_controls_props->roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL;
625 auto *conservative_raster_props = lvl_find_mod_in_chain<VkPhysicalDeviceConservativeRasterizationPropertiesEXT>(pProperties->pNext);
626 if (conservative_raster_props) {
627 conservative_raster_props->primitiveOverestimationSize = 0.00195313f;
628 conservative_raster_props->conservativePointAndLineRasterization = VK_TRUE;
629 conservative_raster_props->degenerateTrianglesRasterized = VK_TRUE;
630 conservative_raster_props->degenerateLinesRasterized = VK_TRUE;
633 auto *rt_pipeline_props = lvl_find_mod_in_chain<VkPhysicalDeviceRayTracingPipelinePropertiesKHR>(pProperties->pNext);
634 if (rt_pipeline_props) {
635 rt_pipeline_props->shaderGroupHandleSize = 32;
636 rt_pipeline_props->shaderGroupBaseAlignment = 64;
637 rt_pipeline_props->shaderGroupHandleCaptureReplaySize = 32;
640 auto *rt_pipeline_nv_props = lvl_find_mod_in_chain<VkPhysicalDeviceRayTracingPropertiesNV>(pProperties->pNext);
641 if (rt_pipeline_nv_props) {
642 rt_pipeline_nv_props->shaderGroupHandleSize = 32;
643 rt_pipeline_nv_props->shaderGroupBaseAlignment = 64;
646 auto *texel_buffer_props = lvl_find_mod_in_chain<VkPhysicalDeviceTexelBufferAlignmentProperties>(pProperties->pNext);
647 if (texel_buffer_props) {
648 texel_buffer_props->storageTexelBufferOffsetSingleTexelAlignment = VK_TRUE;
649 texel_buffer_props->uniformTexelBufferOffsetSingleTexelAlignment = VK_TRUE;
650 texel_buffer_props->storageTexelBufferOffsetAlignmentBytes = 16;
651 texel_buffer_props->uniformTexelBufferOffsetAlignmentBytes = 16;
654 auto *descriptor_buffer_props = lvl_find_mod_in_chain<VkPhysicalDeviceDescriptorBufferPropertiesEXT>(pProperties->pNext);
655 if (descriptor_buffer_props) {
656 descriptor_buffer_props->combinedImageSamplerDescriptorSingleArray = VK_TRUE;
657 descriptor_buffer_props->bufferlessPushDescriptors = VK_TRUE;
658 descriptor_buffer_props->allowSamplerImageViewPostSubmitCreation = VK_TRUE;
659 descriptor_buffer_props->descriptorBufferOffsetAlignment = 4;
662 auto *mesh_shader_props = lvl_find_mod_in_chain<VkPhysicalDeviceMeshShaderPropertiesEXT>(pProperties->pNext);
663 if (mesh_shader_props) {
664 mesh_shader_props->meshOutputPerVertexGranularity = 32;
665 mesh_shader_props->meshOutputPerPrimitiveGranularity = 32;
666 mesh_shader_props->prefersLocalInvocationVertexOutput = VK_TRUE;
667 mesh_shader_props->prefersLocalInvocationPrimitiveOutput = VK_TRUE;
668 mesh_shader_props->prefersCompactVertexOutput = VK_TRUE;
669 mesh_shader_props->prefersCompactPrimitiveOutput = VK_TRUE;
672 auto *fragment_density_map2_props = lvl_find_mod_in_chain<VkPhysicalDeviceFragmentDensityMap2PropertiesEXT>(pProperties->pNext);
673 if (fragment_density_map2_props) {
674 fragment_density_map2_props->subsampledLoads = VK_FALSE;
675 fragment_density_map2_props->subsampledCoarseReconstructionEarlyAccess = VK_FALSE;
676 fragment_density_map2_props->maxSubsampledArrayLayers = 2;
677 fragment_density_map2_props->maxDescriptorSetSubsampledSamplers = 1;
680 auto *maintenance3_props = lvl_find_mod_in_chain<VkPhysicalDeviceMaintenance3Properties>(pProperties->pNext);
681 if (maintenance3_props) {
682 maintenance3_props->maxMemoryAllocationSize = 1073741824;
683 maintenance3_props->maxPerSetDescriptors = 1024;
686 const uint32_t num_copy_layouts = 5;
687 const VkImageLayout HostCopyLayouts[]{
688 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
689 VK_IMAGE_LAYOUT_GENERAL,
690 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
691 VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL,
692 VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
695 auto *host_image_copy_props = lvl_find_mod_in_chain<VkPhysicalDeviceHostImageCopyPropertiesEXT>(pProperties->pNext);
696 if (host_image_copy_props){
697 if (host_image_copy_props->pCopyDstLayouts == nullptr) host_image_copy_props->copyDstLayoutCount = num_copy_layouts;
699 uint32_t num_layouts = (std::min)(host_image_copy_props->copyDstLayoutCount, num_copy_layouts);
700 for (uint32_t i = 0; i < num_layouts; i++) {
701 host_image_copy_props->pCopyDstLayouts[i] = HostCopyLayouts[i];
704 if (host_image_copy_props->pCopySrcLayouts == nullptr) host_image_copy_props->copySrcLayoutCount = num_copy_layouts;
706 uint32_t num_layouts = (std::min)(host_image_copy_props->copySrcLayoutCount, num_copy_layouts);
707 for (uint32_t i = 0; i < num_layouts; i++) {
708 host_image_copy_props->pCopySrcLayouts[i] = HostCopyLayouts[i];
713 auto *driver_properties = lvl_find_mod_in_chain<VkPhysicalDeviceDriverProperties>(pProperties->pNext);
714 if (driver_properties) {
715 std::strncpy(driver_properties->driverName, "Vulkan Mock Device", VK_MAX_DRIVER_NAME_SIZE);
716 #if defined(GIT_BRANCH_NAME) && defined(GIT_TAG_INFO)
717 std::strncpy(driver_properties->driverInfo, "Branch: " GIT_BRANCH_NAME " Tag Info: " GIT_TAG_INFO, VK_MAX_DRIVER_INFO_SIZE);
719 std::strncpy(driver_properties->driverInfo, "Branch: --unknown-- Tag Info: --unknown--", VK_MAX_DRIVER_INFO_SIZE);
723 'vkGetPhysicalDeviceExternalSemaphoreProperties':'''
724 // Hard code support for all handle types and features
725 pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0x1F;
726 pExternalSemaphoreProperties->compatibleHandleTypes = 0x1F;
727 pExternalSemaphoreProperties->externalSemaphoreFeatures = 0x3;
729 'vkGetPhysicalDeviceExternalSemaphorePropertiesKHR':'''
730 GetPhysicalDeviceExternalSemaphoreProperties(physicalDevice, pExternalSemaphoreInfo, pExternalSemaphoreProperties);
732 'vkGetPhysicalDeviceExternalFenceProperties':'''
733 // Hard-code support for all handle types and features
734 pExternalFenceProperties->exportFromImportedHandleTypes = 0xF;
735 pExternalFenceProperties->compatibleHandleTypes = 0xF;
736 pExternalFenceProperties->externalFenceFeatures = 0x3;
738 'vkGetPhysicalDeviceExternalFencePropertiesKHR':'''
739 GetPhysicalDeviceExternalFenceProperties(physicalDevice, pExternalFenceInfo, pExternalFenceProperties);
741 'vkGetPhysicalDeviceExternalBufferProperties':'''
742 constexpr VkExternalMemoryHandleTypeFlags supported_flags = 0x1FF;
743 if (pExternalBufferInfo->handleType & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) {
744 // Can't have dedicated memory with AHB
745 pExternalBufferProperties->externalMemoryProperties.externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
746 pExternalBufferProperties->externalMemoryProperties.exportFromImportedHandleTypes = pExternalBufferInfo->handleType;
747 pExternalBufferProperties->externalMemoryProperties.compatibleHandleTypes = pExternalBufferInfo->handleType;
748 } else if (pExternalBufferInfo->handleType & supported_flags) {
749 pExternalBufferProperties->externalMemoryProperties.externalMemoryFeatures = 0x7;
750 pExternalBufferProperties->externalMemoryProperties.exportFromImportedHandleTypes = supported_flags;
751 pExternalBufferProperties->externalMemoryProperties.compatibleHandleTypes = supported_flags;
753 pExternalBufferProperties->externalMemoryProperties.externalMemoryFeatures = 0;
754 pExternalBufferProperties->externalMemoryProperties.exportFromImportedHandleTypes = 0;
755 // According to spec, handle type is always compatible with itself. Even if export/import
756 // not supported, it's important to properly implement self-compatibility property since
757 // application's control flow can rely on this.
758 pExternalBufferProperties->externalMemoryProperties.compatibleHandleTypes = pExternalBufferInfo->handleType;
761 'vkGetPhysicalDeviceExternalBufferPropertiesKHR':'''
762 GetPhysicalDeviceExternalBufferProperties(physicalDevice, pExternalBufferInfo, pExternalBufferProperties);
764 'vkGetBufferMemoryRequirements': '''
765 // TODO: Just hard-coding reqs for now
766 pMemoryRequirements->size = 4096;
767 pMemoryRequirements->alignment = 1;
768 pMemoryRequirements->memoryTypeBits = 0xFFFF;
769 // Return a better size based on the buffer size from the create info.
770 unique_lock_t lock(global_lock);
771 auto d_iter = buffer_map.find(device);
772 if (d_iter != buffer_map.end()) {
773 auto iter = d_iter->second.find(buffer);
774 if (iter != d_iter->second.end()) {
775 pMemoryRequirements->size = ((iter->second.size + 4095) / 4096) * 4096;
779 'vkGetBufferMemoryRequirements2KHR': '''
780 GetBufferMemoryRequirements(device, pInfo->buffer, &pMemoryRequirements->memoryRequirements);
782 'vkGetDeviceBufferMemoryRequirements': '''
783 // TODO: Just hard-coding reqs for now
784 pMemoryRequirements->memoryRequirements.alignment = 1;
785 pMemoryRequirements->memoryRequirements.memoryTypeBits = 0xFFFF;
787 // Return a size based on the buffer size from the create info.
788 pMemoryRequirements->memoryRequirements.size = ((pInfo->pCreateInfo->size + 4095) / 4096) * 4096;
790 'vkGetDeviceBufferMemoryRequirementsKHR': '''
791 GetDeviceBufferMemoryRequirements(device, pInfo, pMemoryRequirements);
793 'vkGetImageMemoryRequirements': '''
794 pMemoryRequirements->size = 0;
795 pMemoryRequirements->alignment = 1;
797 unique_lock_t lock(global_lock);
798 auto d_iter = image_memory_size_map.find(device);
799 if(d_iter != image_memory_size_map.end()){
800 auto iter = d_iter->second.find(image);
801 if (iter != d_iter->second.end()) {
802 pMemoryRequirements->size = iter->second;
805 // Here we hard-code that the memory type at index 3 doesn't support this image.
806 pMemoryRequirements->memoryTypeBits = 0xFFFF & ~(0x1 << 3);
808 'vkGetImageMemoryRequirements2KHR': '''
809 GetImageMemoryRequirements(device, pInfo->image, &pMemoryRequirements->memoryRequirements);
811 'vkGetDeviceImageMemoryRequirements': '''
812 pMemoryRequirements->memoryRequirements.size = GetImageSizeFromCreateInfo(pInfo->pCreateInfo);
813 pMemoryRequirements->memoryRequirements.alignment = 1;
814 // Here we hard-code that the memory type at index 3 doesn't support this image.
815 pMemoryRequirements->memoryRequirements.memoryTypeBits = 0xFFFF & ~(0x1 << 3);
817 'vkGetDeviceImageMemoryRequirementsKHR': '''
818 GetDeviceImageMemoryRequirements(device, pInfo, pMemoryRequirements);
821 unique_lock_t lock(global_lock);
822 if (VK_WHOLE_SIZE == size) {
823 if (allocated_memory_size_map.count(memory) != 0)
824 size = allocated_memory_size_map[memory] - offset;
828 void* map_addr = malloc((size_t)size);
829 mapped_memory_map[memory].push_back(map_addr);
833 'vkMapMemory2KHR': '''
834 return MapMemory(device, pMemoryMapInfo->memory, pMemoryMapInfo->offset, pMemoryMapInfo->size, pMemoryMapInfo->flags, ppData);
837 unique_lock_t lock(global_lock);
838 for (auto map_addr : mapped_memory_map[memory]) {
841 mapped_memory_map.erase(memory);
843 'vkUnmapMemory2KHR': '''
844 UnmapMemory(device, pMemoryUnmapInfo->memory);
847 'vkGetImageSubresourceLayout': '''
848 // Need safe values. Callers are computing memory offsets from pLayout, with no return code to flag failure.
849 *pLayout = VkSubresourceLayout(); // Default constructor zero values.
851 'vkCreateSwapchainKHR': '''
852 unique_lock_t lock(global_lock);
853 *pSwapchain = (VkSwapchainKHR)global_unique_handle++;
854 for(uint32_t i = 0; i < icd_swapchain_image_count; ++i){
855 swapchain_image_map[*pSwapchain][i] = (VkImage)global_unique_handle++;
859 'vkDestroySwapchainKHR': '''
860 unique_lock_t lock(global_lock);
861 swapchain_image_map.clear();
863 'vkGetSwapchainImagesKHR': '''
864 if (!pSwapchainImages) {
865 *pSwapchainImageCount = icd_swapchain_image_count;
867 unique_lock_t lock(global_lock);
868 for (uint32_t img_i = 0; img_i < (std::min)(*pSwapchainImageCount, icd_swapchain_image_count); ++img_i){
869 pSwapchainImages[img_i] = swapchain_image_map.at(swapchain)[img_i];
872 if (*pSwapchainImageCount < icd_swapchain_image_count) return VK_INCOMPLETE;
873 else if (*pSwapchainImageCount > icd_swapchain_image_count) *pSwapchainImageCount = icd_swapchain_image_count;
877 'vkAcquireNextImageKHR': '''
881 'vkAcquireNextImage2KHR': '''
885 'vkCreateBuffer': '''
886 unique_lock_t lock(global_lock);
887 *pBuffer = (VkBuffer)global_unique_handle++;
888 buffer_map[device][*pBuffer] = {
890 current_available_address
892 current_available_address += pCreateInfo->size;
893 // Always align to next 64-bit pointer
894 const uint64_t alignment = current_available_address % 64;
895 if (alignment != 0) {
896 current_available_address += (64 - alignment);
900 'vkDestroyBuffer': '''
901 unique_lock_t lock(global_lock);
902 buffer_map[device].erase(buffer);
905 unique_lock_t lock(global_lock);
906 *pImage = (VkImage)global_unique_handle++;
907 image_memory_size_map[device][*pImage] = GetImageSizeFromCreateInfo(pCreateInfo);
910 'vkDestroyImage': '''
911 unique_lock_t lock(global_lock);
912 image_memory_size_map[device].erase(image);
914 'vkEnumeratePhysicalDeviceGroupsKHR': '''
915 if (!pPhysicalDeviceGroupProperties) {
916 *pPhysicalDeviceGroupCount = 1;
919 pPhysicalDeviceGroupProperties->physicalDeviceCount = 1;
920 pPhysicalDeviceGroupProperties->physicalDevices[0] = physical_device_map.at(instance)[0];
921 pPhysicalDeviceGroupProperties->subsetAllocation = VK_FALSE;
925 'vkGetPhysicalDeviceMultisamplePropertiesEXT': '''
926 if (pMultisampleProperties) {
928 pMultisampleProperties->maxSampleLocationGridSize = {32, 32};
931 'vkGetPhysicalDeviceFragmentShadingRatesKHR': '''
932 if (!pFragmentShadingRates) {
933 *pFragmentShadingRateCount = 1;
936 pFragmentShadingRates->sampleCounts = VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT;
937 pFragmentShadingRates->fragmentSize = {8, 8};
941 'vkGetPhysicalDeviceCalibrateableTimeDomainsEXT': '''
943 *pTimeDomainCount = 1;
946 *pTimeDomains = VK_TIME_DOMAIN_DEVICE_EXT;
950 'vkGetPhysicalDeviceCalibrateableTimeDomainsKHR': '''
952 *pTimeDomainCount = 1;
955 *pTimeDomains = VK_TIME_DOMAIN_DEVICE_KHR;
959 'vkGetFenceWin32HandleKHR': '''
960 *pHandle = (HANDLE)0x12345678;
963 'vkGetFenceFdKHR': '''
967 'vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR': '''
971 if (*pCounterCount == 0){
972 return VK_INCOMPLETE;
975 pCounters[0].unit = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR;
976 pCounters[0].scope = VK_QUERY_SCOPE_COMMAND_BUFFER_KHR;
977 pCounters[0].storage = VK_PERFORMANCE_COUNTER_STORAGE_INT32_KHR;
978 pCounters[0].uuid[0] = 0x01;
979 if (*pCounterCount == 1){
980 return VK_INCOMPLETE;
982 pCounters[1].unit = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR;
983 pCounters[1].scope = VK_QUERY_SCOPE_RENDER_PASS_KHR;
984 pCounters[1].storage = VK_PERFORMANCE_COUNTER_STORAGE_INT32_KHR;
985 pCounters[1].uuid[0] = 0x02;
986 if (*pCounterCount == 2){
987 return VK_INCOMPLETE;
989 pCounters[2].unit = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR;
990 pCounters[2].scope = VK_QUERY_SCOPE_COMMAND_KHR;
991 pCounters[2].storage = VK_PERFORMANCE_COUNTER_STORAGE_INT32_KHR;
992 pCounters[2].uuid[0] = 0x03;
997 'vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR': '''
1003 'vkGetShaderModuleIdentifierEXT': '''
1006 pIdentifier->identifierSize = 1;
1007 pIdentifier->identifier[0] = 0x01;
1010 'vkGetImageSparseMemoryRequirements': '''
1011 if (!pSparseMemoryRequirements) {
1012 *pSparseMemoryRequirementCount = 1;
1015 pSparseMemoryRequirements->imageMipTailFirstLod = 0;
1016 pSparseMemoryRequirements->imageMipTailSize = 8;
1017 pSparseMemoryRequirements->imageMipTailOffset = 0;
1018 pSparseMemoryRequirements->imageMipTailStride = 4;
1019 pSparseMemoryRequirements->formatProperties.imageGranularity = {4, 4, 4};
1020 pSparseMemoryRequirements->formatProperties.flags = VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT;
1021 // Would need to track the VkImage to know format for better value here
1022 pSparseMemoryRequirements->formatProperties.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT;
1026 'vkGetImageSparseMemoryRequirements2KHR': '''
1027 if (pSparseMemoryRequirementCount && pSparseMemoryRequirements) {
1028 GetImageSparseMemoryRequirements(device, pInfo->image, pSparseMemoryRequirementCount, &pSparseMemoryRequirements->memoryRequirements);
1030 GetImageSparseMemoryRequirements(device, pInfo->image, pSparseMemoryRequirementCount, nullptr);
1033 'vkGetBufferDeviceAddress': '''
1034 VkDeviceAddress address = 0;
1035 auto d_iter = buffer_map.find(device);
1036 if (d_iter != buffer_map.end()) {
1037 auto iter = d_iter->second.find(pInfo->buffer);
1038 if (iter != d_iter->second.end()) {
1039 address = iter->second.address;
1044 'vkGetBufferDeviceAddressKHR': '''
1045 return GetBufferDeviceAddress(device, pInfo);
1047 'vkGetBufferDeviceAddressEXT': '''
1048 return GetBufferDeviceAddress(device, pInfo);
1050 'vkGetDescriptorSetLayoutSizeEXT': '''
1051 // Need to give something non-zero
1052 *pLayoutSizeInBytes = 4;
1054 'vkGetAccelerationStructureBuildSizesKHR': '''
1056 pSizeInfo->accelerationStructureSize = 4;
1057 pSizeInfo->updateScratchSize = 4;
1058 pSizeInfo->buildScratchSize = 4;
1060 'vkGetAccelerationStructureMemoryRequirementsNV': '''
1062 pMemoryRequirements->memoryRequirements.size = 4096;
1063 pMemoryRequirements->memoryRequirements.alignment = 1;
1064 pMemoryRequirements->memoryRequirements.memoryTypeBits = 0xFFFF;
1066 'vkGetAccelerationStructureDeviceAddressKHR': '''
1067 // arbitrary - need to be aligned to 256 bytes
1070 'vkGetVideoSessionMemoryRequirementsKHR': '''
1071 if (!pMemoryRequirements) {
1072 *pMemoryRequirementsCount = 1;
1075 pMemoryRequirements[0].memoryBindIndex = 0;
1076 pMemoryRequirements[0].memoryRequirements.size = 4096;
1077 pMemoryRequirements[0].memoryRequirements.alignment = 1;
1078 pMemoryRequirements[0].memoryRequirements.memoryTypeBits = 0xFFFF;
1082 'vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR': '''
1084 *pPropertyCount = 2;
1087 pProperties[0].MSize = 16;
1088 pProperties[0].NSize = 16;
1089 pProperties[0].KSize = 16;
1090 pProperties[0].AType = VK_COMPONENT_TYPE_UINT32_KHR;
1091 pProperties[0].BType = VK_COMPONENT_TYPE_UINT32_KHR;
1092 pProperties[0].CType = VK_COMPONENT_TYPE_UINT32_KHR;
1093 pProperties[0].ResultType = VK_COMPONENT_TYPE_UINT32_KHR;
1094 pProperties[0].saturatingAccumulation = VK_FALSE;
1095 pProperties[0].scope = VK_SCOPE_SUBGROUP_KHR;
1097 pProperties[1] = pProperties[0];
1098 pProperties[1].scope = VK_SCOPE_DEVICE_KHR;
1102 'vkGetPhysicalDeviceVideoCapabilitiesKHR': '''
1103 // We include some reasonable set of capability combinations to cover a wide range of use cases
1104 auto caps = pCapabilities;
1105 auto caps_decode = lvl_find_mod_in_chain<VkVideoDecodeCapabilitiesKHR>(pCapabilities->pNext);
1106 auto caps_decode_h264 = lvl_find_mod_in_chain<VkVideoDecodeH264CapabilitiesKHR>(pCapabilities->pNext);
1107 auto caps_decode_h265 = lvl_find_mod_in_chain<VkVideoDecodeH265CapabilitiesKHR>(pCapabilities->pNext);
1108 auto caps_decode_av1 = lvl_find_mod_in_chain<VkVideoDecodeAV1CapabilitiesKHR>(pCapabilities->pNext);
1109 auto caps_encode = lvl_find_mod_in_chain<VkVideoEncodeCapabilitiesKHR>(pCapabilities->pNext);
1110 auto caps_encode_quantization_map =
1111 lvl_find_mod_in_chain<VkVideoEncodeQuantizationMapCapabilitiesKHR>(pCapabilities->pNext);
1112 auto caps_encode_h264_quantization_map =
1113 lvl_find_mod_in_chain<VkVideoEncodeH264QuantizationMapCapabilitiesKHR>(pCapabilities->pNext);
1114 auto caps_encode_h265_quantization_map =
1115 lvl_find_mod_in_chain<VkVideoEncodeH265QuantizationMapCapabilitiesKHR>(pCapabilities->pNext);
1116 auto caps_encode_av1_quantization_map =
1117 lvl_find_mod_in_chain<VkVideoEncodeAV1QuantizationMapCapabilitiesKHR>(pCapabilities->pNext);
1118 auto caps_encode_h264 = lvl_find_mod_in_chain<VkVideoEncodeH264CapabilitiesKHR>(pCapabilities->pNext);
1119 auto caps_encode_h265 = lvl_find_mod_in_chain<VkVideoEncodeH265CapabilitiesKHR>(pCapabilities->pNext);
1120 auto caps_encode_av1 = lvl_find_mod_in_chain<VkVideoEncodeAV1CapabilitiesKHR>(pCapabilities->pNext);
1122 switch (pVideoProfile->videoCodecOperation) {
1123 case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR: {
1124 auto profile = lvl_find_in_chain<VkVideoDecodeH264ProfileInfoKHR>(pVideoProfile->pNext);
1125 if (profile->stdProfileIdc != STD_VIDEO_H264_PROFILE_IDC_BASELINE &&
1126 profile->stdProfileIdc != STD_VIDEO_H264_PROFILE_IDC_MAIN) {
1127 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1130 caps->flags = VK_VIDEO_CAPABILITY_PROTECTED_CONTENT_BIT_KHR;
1131 caps->minBitstreamBufferOffsetAlignment = 256;
1132 caps->minBitstreamBufferSizeAlignment = 256;
1133 caps->pictureAccessGranularity = {16,16};
1134 caps->minCodedExtent = {16,16};
1135 caps->maxCodedExtent = {1920,1080};
1136 caps->maxDpbSlots = 33;
1137 caps->maxActiveReferencePictures = 32;
1138 std::strncpy(caps->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME,
1139 sizeof(caps->stdHeaderVersion.extensionName));
1140 caps->stdHeaderVersion.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION;
1142 switch (pVideoProfile->chromaSubsampling) {
1143 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1144 if (profile->pictureLayout != VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_PROGRESSIVE_KHR) {
1145 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1147 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR;
1148 caps_decode_h264->maxLevelIdc = STD_VIDEO_H264_LEVEL_IDC_6_2;
1149 caps_decode_h264->fieldOffsetGranularity = {0,0};
1151 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1152 if (profile->pictureLayout != VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_PROGRESSIVE_KHR &&
1153 profile->pictureLayout != VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_INTERLACED_SEPARATE_PLANES_BIT_KHR) {
1154 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1156 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
1157 caps_decode_h264->maxLevelIdc = STD_VIDEO_H264_LEVEL_IDC_5_0;
1158 caps_decode_h264->fieldOffsetGranularity = {0,16};
1160 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1161 if (profile->pictureLayout != VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_PROGRESSIVE_KHR &&
1162 profile->pictureLayout != VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_INTERLACED_INTERLEAVED_LINES_BIT_KHR) {
1163 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1165 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR
1166 | VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
1167 caps_decode_h264->maxLevelIdc = STD_VIDEO_H264_LEVEL_IDC_3_2;
1168 caps_decode_h264->fieldOffsetGranularity = {0,1};
1171 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1175 case VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR: {
1176 auto profile = lvl_find_in_chain<VkVideoDecodeH265ProfileInfoKHR>(pVideoProfile->pNext);
1177 if (profile->stdProfileIdc != STD_VIDEO_H265_PROFILE_IDC_MAIN) {
1178 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1181 caps->flags = VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR;
1182 caps->minBitstreamBufferOffsetAlignment = 64;
1183 caps->minBitstreamBufferSizeAlignment = 64;
1184 caps->pictureAccessGranularity = {32,32};
1185 caps->minCodedExtent = {48,48};
1186 caps->maxCodedExtent = {3840,2160};
1187 caps->maxDpbSlots = 16;
1188 caps->maxActiveReferencePictures = 15;
1189 std::strncpy(caps->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME,
1190 sizeof(caps->stdHeaderVersion.extensionName));
1191 caps->stdHeaderVersion.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION;
1193 switch (pVideoProfile->chromaSubsampling) {
1194 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1195 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR;
1196 caps_decode_h265->maxLevelIdc = STD_VIDEO_H265_LEVEL_IDC_6_0;
1198 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1199 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
1200 caps_decode_h265->maxLevelIdc = STD_VIDEO_H265_LEVEL_IDC_5_2;
1202 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1203 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR
1204 | VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
1205 caps_decode_h265->maxLevelIdc = STD_VIDEO_H265_LEVEL_IDC_4_1;
1208 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1212 case VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR: {
1213 auto profile = lvl_find_in_chain<VkVideoDecodeAV1ProfileInfoKHR>(pVideoProfile->pNext);
1214 if (profile->stdProfile != STD_VIDEO_AV1_PROFILE_MAIN) {
1215 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1218 caps->flags = VK_VIDEO_CAPABILITY_PROTECTED_CONTENT_BIT_KHR;
1219 caps->minBitstreamBufferOffsetAlignment = 256;
1220 caps->minBitstreamBufferSizeAlignment = 256;
1221 caps->pictureAccessGranularity = {16,16};
1222 caps->minCodedExtent = {16,16};
1223 caps->maxCodedExtent = {1920,1080};
1224 caps->maxDpbSlots = 8;
1225 caps->maxActiveReferencePictures = 7;
1226 std::strncpy(caps->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
1227 sizeof(caps->stdHeaderVersion.extensionName));
1228 caps->stdHeaderVersion.specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION;
1230 switch (pVideoProfile->chromaSubsampling) {
1231 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1232 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR;
1233 caps_decode_av1->maxLevel = STD_VIDEO_AV1_LEVEL_6_2;
1235 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1236 if (profile->filmGrainSupport) {
1237 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1239 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
1240 caps_decode_av1->maxLevel = STD_VIDEO_AV1_LEVEL_5_0;
1242 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1243 caps_decode->flags = VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR
1244 | VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_DISTINCT_BIT_KHR;
1245 caps_decode_av1->maxLevel = STD_VIDEO_AV1_LEVEL_3_2;
1248 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1252 case VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR: {
1253 auto profile = lvl_find_in_chain<VkVideoEncodeH264ProfileInfoKHR>(pVideoProfile->pNext);
1254 if (profile->stdProfileIdc != STD_VIDEO_H264_PROFILE_IDC_BASELINE) {
1255 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1258 caps->flags = VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR;
1259 caps->minBitstreamBufferOffsetAlignment = 4096;
1260 caps->minBitstreamBufferSizeAlignment = 4096;
1261 caps->pictureAccessGranularity = {16,16};
1262 caps->minCodedExtent = {160,128};
1263 caps->maxCodedExtent = {1920,1080};
1264 caps->maxDpbSlots = 10;
1265 caps->maxActiveReferencePictures = 4;
1266 std::strncpy(caps->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_EXTENSION_NAME,
1267 sizeof(caps->stdHeaderVersion.extensionName));
1268 caps->stdHeaderVersion.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_SPEC_VERSION;
1270 switch (pVideoProfile->chromaSubsampling) {
1271 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1272 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_PRECEDING_EXTERNALLY_ENCODED_BYTES_BIT_KHR
1273 | VK_VIDEO_ENCODE_CAPABILITY_QUANTIZATION_DELTA_MAP_BIT_KHR
1274 | VK_VIDEO_ENCODE_CAPABILITY_EMPHASIS_MAP_BIT_KHR;
1275 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR
1276 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR
1277 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_VBR_BIT_KHR;
1278 caps_encode->maxRateControlLayers = 4;
1279 caps_encode->maxBitrate = 800000000;
1280 caps_encode->maxQualityLevels = 4;
1281 caps_encode->encodeInputPictureGranularity = {16,16};
1282 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1283 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR
1284 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_HAS_OVERRIDES_BIT_KHR;
1285 caps_encode_h264->flags = VK_VIDEO_ENCODE_H264_CAPABILITY_HRD_COMPLIANCE_BIT_KHR
1286 | VK_VIDEO_ENCODE_H264_CAPABILITY_PREDICTION_WEIGHT_TABLE_GENERATED_BIT_KHR
1287 | VK_VIDEO_ENCODE_H264_CAPABILITY_ROW_UNALIGNED_SLICE_BIT_KHR
1288 | VK_VIDEO_ENCODE_H264_CAPABILITY_B_FRAME_IN_L0_LIST_BIT_KHR
1289 | VK_VIDEO_ENCODE_H264_CAPABILITY_PER_PICTURE_TYPE_MIN_MAX_QP_BIT_KHR
1290 | VK_VIDEO_ENCODE_H264_CAPABILITY_GENERATE_PREFIX_NALU_BIT_KHR;
1291 caps_encode_h264->maxLevelIdc = STD_VIDEO_H264_LEVEL_IDC_6_2;
1292 caps_encode_h264->maxSliceCount = 8;
1293 caps_encode_h264->maxPPictureL0ReferenceCount = 4;
1294 caps_encode_h264->maxBPictureL0ReferenceCount = 3;
1295 caps_encode_h264->maxL1ReferenceCount = 2;
1296 caps_encode_h264->maxTemporalLayerCount = 4;
1297 caps_encode_h264->expectDyadicTemporalLayerPattern = VK_FALSE;
1298 caps_encode_h264->minQp = 0;
1299 caps_encode_h264->maxQp = 51;
1300 caps_encode_h264->prefersGopRemainingFrames = VK_FALSE;
1301 caps_encode_h264->requiresGopRemainingFrames = VK_FALSE;
1303 if (caps_encode_quantization_map) {
1304 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 15) / 16,
1305 (caps->maxCodedExtent.height + 15) / 16};
1308 if (caps_encode_h264_quantization_map) {
1309 caps_encode_h264_quantization_map->minQpDelta = -26;
1310 caps_encode_h264_quantization_map->maxQpDelta = +25;
1313 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1314 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_PRECEDING_EXTERNALLY_ENCODED_BYTES_BIT_KHR
1315 | VK_VIDEO_ENCODE_CAPABILITY_EMPHASIS_MAP_BIT_KHR;
1316 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR
1317 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_VBR_BIT_KHR;
1318 caps_encode->maxRateControlLayers = 1;
1319 caps_encode->maxBitrate = 480000000;
1320 caps_encode->maxQualityLevels = 3;
1321 caps_encode->encodeInputPictureGranularity = {32,32};
1322 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1323 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
1324 caps_encode_h264->flags = VK_VIDEO_ENCODE_H264_CAPABILITY_DIFFERENT_SLICE_TYPE_BIT_KHR
1325 | VK_VIDEO_ENCODE_H264_CAPABILITY_PER_SLICE_CONSTANT_QP_BIT_KHR
1326 | VK_VIDEO_ENCODE_H264_CAPABILITY_GENERATE_PREFIX_NALU_BIT_KHR;
1327 caps_encode_h264->maxLevelIdc = STD_VIDEO_H264_LEVEL_IDC_6_1;
1328 caps_encode_h264->maxSliceCount = 4;
1329 caps_encode_h264->maxPPictureL0ReferenceCount = 4;
1330 caps_encode_h264->maxBPictureL0ReferenceCount = 0;
1331 caps_encode_h264->maxL1ReferenceCount = 0;
1332 caps_encode_h264->maxTemporalLayerCount = 4;
1333 caps_encode_h264->expectDyadicTemporalLayerPattern = VK_TRUE;
1334 caps_encode_h264->minQp = 0;
1335 caps_encode_h264->maxQp = 30;
1336 caps_encode_h264->prefersGopRemainingFrames = VK_TRUE;
1337 caps_encode_h264->requiresGopRemainingFrames = VK_FALSE;
1339 if (caps_encode_quantization_map) {
1340 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 15) / 16,
1341 (caps->maxCodedExtent.height + 15) / 16};
1344 if (caps_encode_h264_quantization_map) {
1345 caps_encode_h264_quantization_map->minQpDelta = 0;
1346 caps_encode_h264_quantization_map->maxQpDelta = 0;
1349 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1350 caps_encode->flags = 0;
1351 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR;
1352 caps_encode->maxRateControlLayers = 1;
1353 caps_encode->maxBitrate = 240000000;
1354 caps_encode->maxQualityLevels = 1;
1355 caps_encode->encodeInputPictureGranularity = {1,1};
1356 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1357 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
1358 caps_encode_h264->flags = VK_VIDEO_ENCODE_H264_CAPABILITY_ROW_UNALIGNED_SLICE_BIT_KHR
1359 | VK_VIDEO_ENCODE_H264_CAPABILITY_B_FRAME_IN_L1_LIST_BIT_KHR
1360 | VK_VIDEO_ENCODE_H264_CAPABILITY_PER_PICTURE_TYPE_MIN_MAX_QP_BIT_KHR;
1361 caps_encode_h264->maxLevelIdc = STD_VIDEO_H264_LEVEL_IDC_5_1;
1362 caps_encode_h264->maxSliceCount = 1;
1363 caps_encode_h264->maxPPictureL0ReferenceCount = 0;
1364 caps_encode_h264->maxBPictureL0ReferenceCount = 2;
1365 caps_encode_h264->maxL1ReferenceCount = 2;
1366 caps_encode_h264->maxTemporalLayerCount = 1;
1367 caps_encode_h264->expectDyadicTemporalLayerPattern = VK_FALSE;
1368 caps_encode_h264->minQp = 5;
1369 caps_encode_h264->maxQp = 40;
1370 caps_encode_h264->prefersGopRemainingFrames = VK_TRUE;
1371 caps_encode_h264->requiresGopRemainingFrames = VK_TRUE;
1373 if (caps_encode_quantization_map) {
1374 caps_encode_quantization_map->maxQuantizationMapExtent = {0, 0};
1377 if (caps_encode_h264_quantization_map) {
1378 caps_encode_h264_quantization_map->minQpDelta = 0;
1379 caps_encode_h264_quantization_map->maxQpDelta = 0;
1383 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1387 case VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR: {
1388 auto profile = lvl_find_in_chain<VkVideoEncodeH265ProfileInfoKHR>(pVideoProfile->pNext);
1389 if (profile->stdProfileIdc != STD_VIDEO_H265_PROFILE_IDC_MAIN) {
1390 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1393 caps->flags = VK_VIDEO_CAPABILITY_PROTECTED_CONTENT_BIT_KHR;
1394 caps->minBitstreamBufferOffsetAlignment = 1;
1395 caps->minBitstreamBufferSizeAlignment = 1;
1396 caps->pictureAccessGranularity = {8,8};
1397 caps->minCodedExtent = {64,48};
1398 caps->maxCodedExtent = {4096,2560};
1399 caps->maxDpbSlots = 8;
1400 caps->maxActiveReferencePictures = 2;
1401 std::strncpy(caps->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_EXTENSION_NAME, sizeof(caps->stdHeaderVersion.extensionName));
1402 caps->stdHeaderVersion.specVersion = VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_SPEC_VERSION;
1404 switch (pVideoProfile->chromaSubsampling) {
1405 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1406 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_EMPHASIS_MAP_BIT_KHR;
1407 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR;
1408 caps_encode->maxRateControlLayers = 1;
1409 caps_encode->maxBitrate = 800000000;
1410 caps_encode->maxQualityLevels = 1;
1411 caps_encode->encodeInputPictureGranularity = {64,64};
1412 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1413 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
1414 caps_encode_h265->flags = VK_VIDEO_ENCODE_H265_CAPABILITY_HRD_COMPLIANCE_BIT_KHR
1415 | VK_VIDEO_ENCODE_H265_CAPABILITY_PREDICTION_WEIGHT_TABLE_GENERATED_BIT_KHR
1416 | VK_VIDEO_ENCODE_H265_CAPABILITY_ROW_UNALIGNED_SLICE_SEGMENT_BIT_KHR
1417 | VK_VIDEO_ENCODE_H265_CAPABILITY_B_FRAME_IN_L0_LIST_BIT_KHR
1418 | VK_VIDEO_ENCODE_H265_CAPABILITY_PER_SLICE_SEGMENT_CONSTANT_QP_BIT_KHR
1419 | VK_VIDEO_ENCODE_H265_CAPABILITY_MULTIPLE_SLICE_SEGMENTS_PER_TILE_BIT_KHR;
1420 caps_encode_h265->maxLevelIdc = STD_VIDEO_H265_LEVEL_IDC_6_2;
1421 caps_encode_h265->maxSliceSegmentCount = 8;
1422 caps_encode_h265->maxTiles = {1,1};
1423 caps_encode_h265->ctbSizes = VK_VIDEO_ENCODE_H265_CTB_SIZE_32_BIT_KHR
1424 | VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR;
1425 caps_encode_h265->transformBlockSizes = VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_4_BIT_KHR
1426 | VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_8_BIT_KHR
1427 | VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_32_BIT_KHR;
1428 caps_encode_h265->maxPPictureL0ReferenceCount = 4;
1429 caps_encode_h265->maxBPictureL0ReferenceCount = 3;
1430 caps_encode_h265->maxL1ReferenceCount = 2;
1431 caps_encode_h265->maxSubLayerCount = 1;
1432 caps_encode_h265->expectDyadicTemporalSubLayerPattern = VK_FALSE;
1433 caps_encode_h265->minQp = 16;
1434 caps_encode_h265->maxQp = 32;
1435 caps_encode_h265->prefersGopRemainingFrames = VK_FALSE;
1436 caps_encode_h265->requiresGopRemainingFrames = VK_FALSE;
1438 if (caps_encode_quantization_map) {
1439 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 3) / 4,
1440 (caps->maxCodedExtent.height + 3) / 4};
1443 if (caps_encode_h265_quantization_map) {
1444 caps_encode_h265_quantization_map->minQpDelta = -16;
1445 caps_encode_h265_quantization_map->maxQpDelta = +15;
1448 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1449 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_QUANTIZATION_DELTA_MAP_BIT_KHR;
1450 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR;
1451 caps_encode->maxRateControlLayers = 0;
1452 caps_encode->maxBitrate = 480000000;
1453 caps_encode->maxQualityLevels = 2;
1454 caps_encode->encodeInputPictureGranularity = {32,32};
1455 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1456 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
1457 caps_encode_h265->flags = VK_VIDEO_ENCODE_H265_CAPABILITY_DIFFERENT_SLICE_SEGMENT_TYPE_BIT_KHR;
1458 caps_encode_h265->maxLevelIdc = STD_VIDEO_H265_LEVEL_IDC_6_1;
1459 caps_encode_h265->maxSliceSegmentCount = 4;
1460 caps_encode_h265->maxTiles = {2,2};
1461 caps_encode_h265->ctbSizes = VK_VIDEO_ENCODE_H265_CTB_SIZE_16_BIT_KHR
1462 | VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR;
1463 caps_encode_h265->transformBlockSizes = VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_8_BIT_KHR
1464 | VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_16_BIT_KHR
1465 | VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_32_BIT_KHR;
1466 caps_encode_h265->maxPPictureL0ReferenceCount = 4;
1467 caps_encode_h265->maxBPictureL0ReferenceCount = 0;
1468 caps_encode_h265->maxL1ReferenceCount = 0;
1469 caps_encode_h265->maxSubLayerCount = 1;
1470 caps_encode_h265->expectDyadicTemporalSubLayerPattern = VK_FALSE;
1471 caps_encode_h265->minQp = 0;
1472 caps_encode_h265->maxQp = 51;
1473 caps_encode_h265->prefersGopRemainingFrames = VK_TRUE;
1474 caps_encode_h265->requiresGopRemainingFrames = VK_FALSE;
1476 if (caps_encode_quantization_map) {
1477 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 31) / 32,
1478 (caps->maxCodedExtent.height + 31) / 32};
1481 if (caps_encode_h265_quantization_map) {
1482 caps_encode_h265_quantization_map->minQpDelta = 0;
1483 caps_encode_h265_quantization_map->maxQpDelta = 0;
1486 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1487 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_PRECEDING_EXTERNALLY_ENCODED_BYTES_BIT_KHR;
1488 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR
1489 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR
1490 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_VBR_BIT_KHR;
1491 caps_encode->maxRateControlLayers = 2;
1492 caps_encode->maxBitrate = 240000000;
1493 caps_encode->maxQualityLevels = 3;
1494 caps_encode->encodeInputPictureGranularity = {16,16};
1495 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1496 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR
1497 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_HAS_OVERRIDES_BIT_KHR;
1498 caps_encode_h265->flags = VK_VIDEO_ENCODE_H265_CAPABILITY_B_FRAME_IN_L1_LIST_BIT_KHR
1499 | VK_VIDEO_ENCODE_H265_CAPABILITY_PER_PICTURE_TYPE_MIN_MAX_QP_BIT_KHR
1500 | VK_VIDEO_ENCODE_H265_CAPABILITY_MULTIPLE_TILES_PER_SLICE_SEGMENT_BIT_KHR;
1501 caps_encode_h265->maxLevelIdc = STD_VIDEO_H265_LEVEL_IDC_5_1;
1502 caps_encode_h265->maxSliceSegmentCount = 1;
1503 caps_encode_h265->maxTiles = {2,2};
1504 caps_encode_h265->ctbSizes = VK_VIDEO_ENCODE_H265_CTB_SIZE_32_BIT_KHR;
1505 caps_encode_h265->transformBlockSizes = VK_VIDEO_ENCODE_H265_TRANSFORM_BLOCK_SIZE_32_BIT_KHR;
1506 caps_encode_h265->maxPPictureL0ReferenceCount = 0;
1507 caps_encode_h265->maxBPictureL0ReferenceCount = 2;
1508 caps_encode_h265->maxL1ReferenceCount = 2;
1509 caps_encode_h265->maxSubLayerCount = 4;
1510 caps_encode_h265->expectDyadicTemporalSubLayerPattern = VK_TRUE;
1511 caps_encode_h265->minQp = 16;
1512 caps_encode_h265->maxQp = 51;
1513 caps_encode_h265->prefersGopRemainingFrames = VK_TRUE;
1514 caps_encode_h265->requiresGopRemainingFrames = VK_TRUE;
1516 if (caps_encode_quantization_map) {
1517 caps_encode_quantization_map->maxQuantizationMapExtent = {0, 0};
1520 if (caps_encode_h265_quantization_map) {
1521 caps_encode_h265_quantization_map->minQpDelta = 0;
1522 caps_encode_h265_quantization_map->maxQpDelta = 0;
1526 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1530 case VK_VIDEO_CODEC_OPERATION_ENCODE_AV1_BIT_KHR: {
1531 auto profile = lvl_find_in_chain<VkVideoEncodeAV1ProfileInfoKHR>(pVideoProfile->pNext);
1532 if (profile->stdProfile != STD_VIDEO_AV1_PROFILE_MAIN) {
1533 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1536 caps->flags = VK_VIDEO_CAPABILITY_PROTECTED_CONTENT_BIT_KHR;
1537 caps->minBitstreamBufferOffsetAlignment = 1;
1538 caps->minBitstreamBufferSizeAlignment = 1;
1539 caps->pictureAccessGranularity = {8,8};
1540 caps->minCodedExtent = {192,128};
1541 caps->maxCodedExtent = {4096,2560};
1542 caps->maxDpbSlots = 8;
1543 caps->maxActiveReferencePictures = 2;
1544 std::strncpy(caps->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_AV1_ENCODE_EXTENSION_NAME, sizeof(caps->stdHeaderVersion.extensionName));
1545 caps->stdHeaderVersion.specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_ENCODE_SPEC_VERSION;
1547 switch (pVideoProfile->chromaSubsampling) {
1548 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1549 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_QUANTIZATION_DELTA_MAP_BIT_KHR
1550 | VK_VIDEO_ENCODE_CAPABILITY_EMPHASIS_MAP_BIT_KHR;
1551 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR;
1552 caps_encode->maxRateControlLayers = 1;
1553 caps_encode->maxBitrate = 800000000;
1554 caps_encode->maxQualityLevels = 1;
1555 caps_encode->encodeInputPictureGranularity = {64,64};
1556 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1557 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
1558 caps_encode_av1->flags = VK_VIDEO_ENCODE_AV1_CAPABILITY_PRIMARY_REFERENCE_CDF_ONLY_BIT_KHR;
1559 caps_encode_av1->maxLevel = STD_VIDEO_AV1_LEVEL_6_2;
1560 caps_encode_av1->maxTiles = {1,1};
1561 caps_encode_av1->minTileSize = {64,64};
1562 caps_encode_av1->maxTileSize = {4096,2560};
1563 caps_encode_av1->superblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_64_BIT_KHR;
1564 caps_encode_av1->maxSingleReferenceCount = 1;
1565 caps_encode_av1->singleReferenceNameMask = 0x7B;
1566 caps_encode_av1->maxUnidirectionalCompoundReferenceCount = 0;
1567 caps_encode_av1->maxUnidirectionalCompoundGroup1ReferenceCount = 0;
1568 caps_encode_av1->unidirectionalCompoundReferenceNameMask = 0x00;
1569 caps_encode_av1->maxBidirectionalCompoundReferenceCount = 0;
1570 caps_encode_av1->maxBidirectionalCompoundGroup1ReferenceCount = 0;
1571 caps_encode_av1->maxBidirectionalCompoundGroup2ReferenceCount = 0;
1572 caps_encode_av1->bidirectionalCompoundReferenceNameMask = 0x00;
1573 caps_encode_av1->maxTemporalLayerCount = 1;
1574 caps_encode_av1->maxSpatialLayerCount = 1;
1575 caps_encode_av1->maxOperatingPoints = 1;
1576 caps_encode_av1->minQIndex = 32;
1577 caps_encode_av1->maxQIndex = 128;
1578 caps_encode_av1->prefersGopRemainingFrames = VK_FALSE;
1579 caps_encode_av1->requiresGopRemainingFrames = VK_FALSE;
1581 if (caps_encode_quantization_map) {
1582 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 7) / 8,
1583 (caps->maxCodedExtent.height + 7) / 8};
1586 if (caps_encode_av1_quantization_map) {
1587 caps_encode_av1_quantization_map->minQIndexDelta = -64;
1588 caps_encode_av1_quantization_map->maxQIndexDelta = +64;
1591 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1592 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_QUANTIZATION_DELTA_MAP_BIT_KHR;
1593 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR;
1594 caps_encode->maxRateControlLayers = 0;
1595 caps_encode->maxBitrate = 480000000;
1596 caps_encode->maxQualityLevels = 2;
1597 caps_encode->encodeInputPictureGranularity = {32,32};
1598 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1599 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
1600 caps_encode_av1->flags = VK_VIDEO_ENCODE_AV1_CAPABILITY_PRIMARY_REFERENCE_CDF_ONLY_BIT_KHR
1601 | VK_VIDEO_ENCODE_AV1_CAPABILITY_GENERATE_OBU_EXTENSION_HEADER_BIT_KHR
1602 | VK_VIDEO_ENCODE_AV1_CAPABILITY_FRAME_SIZE_OVERRIDE_BIT_KHR;
1603 caps_encode_av1->maxLevel = STD_VIDEO_AV1_LEVEL_6_1;
1604 caps_encode_av1->maxTiles = {2,2};
1605 caps_encode_av1->minTileSize = {128,128};
1606 caps_encode_av1->maxTileSize = {4096,2048};
1607 caps_encode_av1->superblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_64_BIT_KHR
1608 | VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_128_BIT_KHR;
1609 caps_encode_av1->maxSingleReferenceCount = 0;
1610 caps_encode_av1->singleReferenceNameMask = 0x00;
1611 caps_encode_av1->maxUnidirectionalCompoundReferenceCount = 2;
1612 caps_encode_av1->maxUnidirectionalCompoundGroup1ReferenceCount = 2;
1613 caps_encode_av1->unidirectionalCompoundReferenceNameMask = 0x5F;
1614 caps_encode_av1->maxBidirectionalCompoundReferenceCount = 2;
1615 caps_encode_av1->maxBidirectionalCompoundGroup1ReferenceCount = 2;
1616 caps_encode_av1->maxBidirectionalCompoundGroup2ReferenceCount = 2;
1617 caps_encode_av1->bidirectionalCompoundReferenceNameMask = 0x5F;
1618 caps_encode_av1->maxTemporalLayerCount = 4;
1619 caps_encode_av1->maxSpatialLayerCount = 1;
1620 caps_encode_av1->maxOperatingPoints = 4;
1621 caps_encode_av1->minQIndex = 0;
1622 caps_encode_av1->maxQIndex = 255;
1623 caps_encode_av1->prefersGopRemainingFrames = VK_TRUE;
1624 caps_encode_av1->requiresGopRemainingFrames = VK_FALSE;
1626 if (caps_encode_quantization_map) {
1627 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 63) / 64,
1628 (caps->maxCodedExtent.height + 63) / 64};
1631 if (caps_encode_av1_quantization_map) {
1632 caps_encode_av1_quantization_map->minQIndexDelta = -255;
1633 caps_encode_av1_quantization_map->maxQIndexDelta = +255;
1636 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1637 caps_encode->flags = VK_VIDEO_ENCODE_CAPABILITY_PRECEDING_EXTERNALLY_ENCODED_BYTES_BIT_KHR
1638 | VK_VIDEO_ENCODE_CAPABILITY_EMPHASIS_MAP_BIT_KHR;
1639 caps_encode->rateControlModes = VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR
1640 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR
1641 | VK_VIDEO_ENCODE_RATE_CONTROL_MODE_VBR_BIT_KHR;
1642 caps_encode->maxRateControlLayers = 2;
1643 caps_encode->maxBitrate = 240000000;
1644 caps_encode->maxQualityLevels = 3;
1645 caps_encode->encodeInputPictureGranularity = {16,16};
1646 caps_encode->supportedEncodeFeedbackFlags = VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR
1647 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR
1648 | VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_HAS_OVERRIDES_BIT_KHR;
1649 caps_encode_av1->flags = VK_VIDEO_ENCODE_AV1_CAPABILITY_PER_RATE_CONTROL_GROUP_MIN_MAX_Q_INDEX_BIT_KHR
1650 | VK_VIDEO_ENCODE_AV1_CAPABILITY_FRAME_SIZE_OVERRIDE_BIT_KHR
1651 | VK_VIDEO_ENCODE_AV1_CAPABILITY_MOTION_VECTOR_SCALING_BIT_KHR;
1652 caps_encode_av1->maxLevel = STD_VIDEO_AV1_LEVEL_5_1;
1653 caps_encode_av1->maxTiles = {4,4};
1654 caps_encode_av1->minTileSize = {128,128};
1655 caps_encode_av1->maxTileSize = {2048,2048};
1656 caps_encode_av1->superblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_128_BIT_KHR;
1657 caps_encode_av1->maxSingleReferenceCount = 1;
1658 caps_encode_av1->singleReferenceNameMask = 0x5F;
1659 caps_encode_av1->maxUnidirectionalCompoundReferenceCount = 4;
1660 caps_encode_av1->maxUnidirectionalCompoundGroup1ReferenceCount = 4;
1661 caps_encode_av1->unidirectionalCompoundReferenceNameMask = 0x5B;
1662 caps_encode_av1->maxBidirectionalCompoundReferenceCount = 0;
1663 caps_encode_av1->maxBidirectionalCompoundGroup1ReferenceCount = 0;
1664 caps_encode_av1->maxBidirectionalCompoundGroup2ReferenceCount = 0;
1665 caps_encode_av1->bidirectionalCompoundReferenceNameMask = 0x00;
1666 caps_encode_av1->maxTemporalLayerCount = 4;
1667 caps_encode_av1->maxSpatialLayerCount = 2;
1668 caps_encode_av1->maxOperatingPoints = 2;
1669 caps_encode_av1->minQIndex = 16;
1670 caps_encode_av1->maxQIndex = 96;
1671 caps_encode_av1->prefersGopRemainingFrames = VK_TRUE;
1672 caps_encode_av1->requiresGopRemainingFrames = VK_TRUE;
1674 if (caps_encode_quantization_map) {
1675 caps_encode_quantization_map->maxQuantizationMapExtent = {(caps->maxCodedExtent.width + 127) / 128,
1676 (caps->maxCodedExtent.height + 127) / 128};
1679 if (caps_encode_av1_quantization_map) {
1680 caps_encode_av1_quantization_map->minQIndexDelta = -64;
1681 caps_encode_av1_quantization_map->maxQIndexDelta = +63;
1685 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1694 'vkGetPhysicalDeviceVideoFormatPropertiesKHR': '''
1695 // We include some reasonable set of format combinations to cover a wide range of use cases
1696 auto profile_list = lvl_find_in_chain<VkVideoProfileListInfoKHR>(pVideoFormatInfo->pNext);
1697 if (profile_list->profileCount != 1) {
1698 return VK_ERROR_VIDEO_PROFILE_FORMAT_NOT_SUPPORTED_KHR;
1701 struct VideoFormatProperties {
1702 VkVideoFormatPropertiesKHR props;
1703 VkVideoFormatQuantizationMapPropertiesKHR props_quantization_map;
1704 VkVideoFormatH265QuantizationMapPropertiesKHR props_h265_quantization_map;
1705 VkVideoFormatAV1QuantizationMapPropertiesKHR props_av1_quantization_map;
1708 std::vector<VideoFormatProperties> format_props{};
1710 VideoFormatProperties fmt = {};
1711 fmt.props.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_PROPERTIES_KHR;
1712 fmt.props.imageCreateFlags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_ALIAS_BIT |
1713 VK_IMAGE_CREATE_EXTENDED_USAGE_BIT | VK_IMAGE_CREATE_PROTECTED_BIT | VK_IMAGE_CREATE_DISJOINT_BIT;
1714 fmt.props.imageType = VK_IMAGE_TYPE_2D;
1715 fmt.props.imageTiling = VK_IMAGE_TILING_OPTIMAL;
1716 fmt.props_quantization_map.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_QUANTIZATION_MAP_PROPERTIES_KHR;
1717 fmt.props_h265_quantization_map.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_H265_QUANTIZATION_MAP_PROPERTIES_KHR;
1718 fmt.props_av1_quantization_map.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_AV1_QUANTIZATION_MAP_PROPERTIES_KHR;
1720 // Populate DPB and input/output formats
1721 switch (profile_list->pProfiles[0].videoCodecOperation) {
1722 case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR:
1723 case VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR:
1724 case VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR:
1725 switch (profile_list->pProfiles[0].chromaSubsampling) {
1726 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1727 fmt.props.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
1728 fmt.props.imageUsageFlags =
1729 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
1730 format_props.push_back(fmt);
1731 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1732 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
1733 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |
1734 VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
1735 format_props.push_back(fmt);
1736 fmt.props.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
1737 format_props.push_back(fmt);
1739 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1740 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
1741 fmt.props.format = VK_FORMAT_G8_B8R8_2PLANE_422_UNORM;
1742 format_props.push_back(fmt);
1743 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1744 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
1745 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
1746 format_props.push_back(fmt);
1747 fmt.props.format = VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16;
1748 format_props.push_back(fmt);
1750 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1751 fmt.props.format = VK_FORMAT_G8_B8R8_2PLANE_444_UNORM;
1752 fmt.props.imageUsageFlags =
1753 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
1754 format_props.push_back(fmt);
1755 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1756 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
1757 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR |
1758 VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
1759 format_props.push_back(fmt);
1762 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1765 case VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR:
1766 case VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR:
1767 case VK_VIDEO_CODEC_OPERATION_ENCODE_AV1_BIT_KHR:
1768 switch (profile_list->pProfiles[0].chromaSubsampling) {
1769 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1770 fmt.props.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
1771 fmt.props.imageUsageFlags =
1772 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR;
1773 format_props.push_back(fmt);
1774 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1775 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
1776 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
1777 format_props.push_back(fmt);
1778 fmt.props.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
1779 format_props.push_back(fmt);
1781 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1782 fmt.props.format = VK_FORMAT_G8_B8R8_2PLANE_422_UNORM;
1783 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR;
1784 format_props.push_back(fmt);
1785 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1786 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
1787 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
1788 format_props.push_back(fmt);
1789 fmt.props.format = VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16;
1790 format_props.push_back(fmt);
1792 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1793 fmt.props.format = VK_FORMAT_G8_B8R8_2PLANE_444_UNORM;
1794 fmt.props.imageUsageFlags =
1795 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR;
1796 format_props.push_back(fmt);
1797 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1798 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
1799 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
1800 format_props.push_back(fmt);
1803 return VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR;
1811 // Populate quantization map formats
1812 fmt.props.imageCreateFlags = VK_IMAGE_CREATE_PROTECTED_BIT;
1813 fmt.props.imageTiling = VK_IMAGE_TILING_LINEAR;
1814 switch (profile_list->pProfiles[0].videoCodecOperation) {
1815 case VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR:
1816 switch (profile_list->pProfiles[0].chromaSubsampling) {
1817 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1818 fmt.props.format = VK_FORMAT_R32_SINT;
1819 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1820 VK_IMAGE_USAGE_VIDEO_ENCODE_QUANTIZATION_DELTA_MAP_BIT_KHR;
1821 fmt.props_quantization_map.quantizationMapTexelSize = {16, 16};
1822 format_props.push_back(fmt);
1823 fmt.props.format = VK_FORMAT_R8_UNORM;
1824 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1825 VK_IMAGE_USAGE_VIDEO_ENCODE_EMPHASIS_MAP_BIT_KHR;
1826 format_props.push_back(fmt);
1828 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1829 fmt.props.format = VK_FORMAT_R8_UNORM;
1830 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1831 VK_IMAGE_USAGE_VIDEO_ENCODE_EMPHASIS_MAP_BIT_KHR;
1832 fmt.props_quantization_map.quantizationMapTexelSize = {16, 16};
1833 format_props.push_back(fmt);
1835 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1841 case VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR:
1842 switch (profile_list->pProfiles[0].chromaSubsampling) {
1843 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1844 fmt.props.format = VK_FORMAT_R8_UNORM;
1845 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1846 VK_IMAGE_USAGE_VIDEO_ENCODE_EMPHASIS_MAP_BIT_KHR;
1847 fmt.props_quantization_map.quantizationMapTexelSize = {4, 4};
1848 fmt.props_h265_quantization_map.compatibleCtbSizes =
1849 VK_VIDEO_ENCODE_H265_CTB_SIZE_32_BIT_KHR | VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR;
1850 format_props.push_back(fmt);
1851 fmt.props_quantization_map.quantizationMapTexelSize = {8, 8};
1852 format_props.push_back(fmt);
1853 fmt.props_quantization_map.quantizationMapTexelSize = {32, 32};
1854 format_props.push_back(fmt);
1855 fmt.props_quantization_map.quantizationMapTexelSize = {64, 64};
1856 fmt.props_h265_quantization_map.compatibleCtbSizes = VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR;
1857 format_props.push_back(fmt);
1859 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1860 fmt.props.format = VK_FORMAT_R32_SINT;
1861 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1862 VK_IMAGE_USAGE_VIDEO_ENCODE_QUANTIZATION_DELTA_MAP_BIT_KHR;
1863 fmt.props_quantization_map.quantizationMapTexelSize = {32, 32};
1864 fmt.props_h265_quantization_map.compatibleCtbSizes =
1865 VK_VIDEO_ENCODE_H265_CTB_SIZE_32_BIT_KHR | VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR;
1866 format_props.push_back(fmt);
1867 fmt.props_quantization_map.quantizationMapTexelSize = {64, 64};
1868 fmt.props_h265_quantization_map.compatibleCtbSizes = VK_VIDEO_ENCODE_H265_CTB_SIZE_64_BIT_KHR;
1869 format_props.push_back(fmt);
1871 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1877 case VK_VIDEO_CODEC_OPERATION_ENCODE_AV1_BIT_KHR:
1878 switch (profile_list->pProfiles[0].chromaSubsampling) {
1879 case VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR:
1880 fmt.props.format = VK_FORMAT_R32_SINT;
1881 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1882 VK_IMAGE_USAGE_VIDEO_ENCODE_QUANTIZATION_DELTA_MAP_BIT_KHR;
1883 fmt.props_quantization_map.quantizationMapTexelSize = {8, 8};
1884 fmt.props_av1_quantization_map.compatibleSuperblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_64_BIT_KHR;
1885 format_props.push_back(fmt);
1886 fmt.props.format = VK_FORMAT_R8_UNORM;
1887 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1888 VK_IMAGE_USAGE_VIDEO_ENCODE_EMPHASIS_MAP_BIT_KHR;
1889 fmt.props_quantization_map.quantizationMapTexelSize = {64, 64};
1890 fmt.props_av1_quantization_map.compatibleSuperblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_64_BIT_KHR;
1891 format_props.push_back(fmt);
1893 case VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR:
1894 fmt.props.format = VK_FORMAT_R32_SINT;
1895 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1896 VK_IMAGE_USAGE_VIDEO_ENCODE_QUANTIZATION_DELTA_MAP_BIT_KHR;
1897 fmt.props_quantization_map.quantizationMapTexelSize = {64, 64};
1898 fmt.props_av1_quantization_map.compatibleSuperblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_64_BIT_KHR;
1899 format_props.push_back(fmt);
1900 fmt.props_quantization_map.quantizationMapTexelSize = {128, 128};
1901 fmt.props_av1_quantization_map.compatibleSuperblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_128_BIT_KHR;
1902 format_props.push_back(fmt);
1904 case VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR:
1905 fmt.props.format = VK_FORMAT_R8_UNORM;
1906 fmt.props.imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1907 VK_IMAGE_USAGE_VIDEO_ENCODE_EMPHASIS_MAP_BIT_KHR;
1908 fmt.props_quantization_map.quantizationMapTexelSize = {128, 128};
1909 fmt.props_av1_quantization_map.compatibleSuperblockSizes = VK_VIDEO_ENCODE_AV1_SUPERBLOCK_SIZE_128_BIT_KHR;
1910 format_props.push_back(fmt);
1921 std::vector<VideoFormatProperties> filtered;
1922 for (const auto& format : format_props) {
1923 if ((pVideoFormatInfo->imageUsage & format.props.imageUsageFlags) == pVideoFormatInfo->imageUsage) {
1924 filtered.push_back(format);
1928 if (pVideoFormatProperties != nullptr) {
1929 for (uint32_t i = 0; i < (std::min)(*pVideoFormatPropertyCount, (uint32_t)filtered.size()); ++i) {
1930 void* saved_pNext = pVideoFormatProperties[i].pNext;
1931 pVideoFormatProperties[i] = filtered[i].props;
1932 pVideoFormatProperties[i].pNext = saved_pNext;
1934 auto* props_quantization_map = lvl_find_mod_in_chain<VkVideoFormatQuantizationMapPropertiesKHR>(saved_pNext);
1935 auto* props_h265_quantization_map = lvl_find_mod_in_chain<VkVideoFormatH265QuantizationMapPropertiesKHR>(saved_pNext);
1936 auto* props_av1_quantization_map = lvl_find_mod_in_chain<VkVideoFormatAV1QuantizationMapPropertiesKHR>(saved_pNext);
1938 if (props_quantization_map != nullptr) {
1939 saved_pNext = props_quantization_map->pNext;
1940 *props_quantization_map = filtered[i].props_quantization_map;
1941 props_quantization_map->pNext = saved_pNext;
1944 if (props_h265_quantization_map != nullptr) {
1945 saved_pNext = props_h265_quantization_map->pNext;
1946 *props_h265_quantization_map = filtered[i].props_h265_quantization_map;
1947 props_h265_quantization_map->pNext = saved_pNext;
1950 if (props_av1_quantization_map != nullptr) {
1951 saved_pNext = props_av1_quantization_map->pNext;
1952 *props_av1_quantization_map = filtered[i].props_av1_quantization_map;
1953 props_av1_quantization_map->pNext = saved_pNext;
1957 *pVideoFormatPropertyCount = (uint32_t)filtered.size();
1960 'vkGetDescriptorSetLayoutSupport':'''
1962 pSupport->supported = VK_TRUE;
1965 'vkGetDescriptorSetLayoutSupportKHR':'''
1966 GetDescriptorSetLayoutSupport(device, pCreateInfo, pSupport);
1968 'vkGetRenderAreaGranularity': '''
1969 pGranularity->width = 1;
1970 pGranularity->height = 1;
1972 'vkGetMemoryFdKHR': '''
1976 'vkGetMemoryHostPointerPropertiesEXT': '''
1977 pMemoryHostPointerProperties->memoryTypeBits = 1 << 5; // DEVICE_LOCAL only type
1980 'vkGetAndroidHardwareBufferPropertiesANDROID': '''
1981 pProperties->allocationSize = 65536;
1982 pProperties->memoryTypeBits = 1 << 5; // DEVICE_LOCAL only type
1984 auto *format_prop = lvl_find_mod_in_chain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
1986 // Likley using this format
1987 format_prop->format = VK_FORMAT_R8G8B8A8_UNORM;
1988 format_prop->externalFormat = 37;
1991 auto *format_resolve_prop = lvl_find_mod_in_chain<VkAndroidHardwareBufferFormatResolvePropertiesANDROID>(pProperties->pNext);
1992 if (format_resolve_prop) {
1993 format_resolve_prop->colorAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
1997 'vkGetPhysicalDeviceDisplayPropertiesKHR': '''
1999 *pPropertyCount = 1;
2001 unique_lock_t lock(global_lock);
2002 pProperties[0].display = (VkDisplayKHR)global_unique_handle++;
2003 display_map[physicalDevice].insert(pProperties[0].display);
2007 'vkRegisterDisplayEventEXT': '''
2008 unique_lock_t lock(global_lock);
2009 *pFence = (VkFence)global_unique_handle++;
2012 'vkQueueSubmit': '''
2013 // Special way to cause DEVICE_LOST
2014 // Picked VkExportFenceCreateInfo because needed some struct that wouldn't get cleared by validation Safe Struct
2015 // ... TODO - It would be MUCH nicer to have a layer or other setting control when this occured
2016 // For now this is used to allow Validation Layers test reacting to device losts
2017 if (submitCount > 0 && pSubmits) {
2018 auto pNext = reinterpret_cast<const VkBaseInStructure *>(pSubmits[0].pNext);
2019 if (pNext && pNext->sType == VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO && pNext->pNext == nullptr) {
2020 return VK_ERROR_DEVICE_LOST;
2025 'vkGetMemoryWin32HandlePropertiesKHR': '''
2026 pMemoryWin32HandleProperties->memoryTypeBits = 0xFFFF;
2029 'vkCreatePipelineBinariesKHR': '''
2030 unique_lock_t lock(global_lock);
2031 for (uint32_t i = 0; i < pBinaries->pipelineBinaryCount; ++i) {
2032 pBinaries->pPipelineBinaries[i] = (VkPipelineBinaryKHR)global_unique_handle++;
2038 # MockICDGeneratorOptions - subclass of GeneratorOptions.
2040 # Adds options used by MockICDOutputGenerator objects during Mock
2043 # Additional members
2044 # prefixText - list of strings to prefix generated header with
2045 # (usually a copyright statement + calling convention macros).
2046 # protectFile - True if multiple inclusion protection should be
2047 # generated (based on the filename) around the entire header.
2048 # protectFeature - True if #ifndef..#endif protection should be
2049 # generated around a feature interface in the header file.
2050 # genFuncPointers - True if function pointer typedefs should be
2052 # protectProto - If conditional protection should be generated
2053 # around prototype declarations, set to either '#ifdef'
2054 # to require opt-in (#ifdef protectProtoStr) or '#ifndef'
2055 # to require opt-out (#ifndef protectProtoStr). Otherwise
2057 # protectProtoStr - #ifdef/#ifndef symbol to use around prototype
2058 # declarations, if protectProto is set
2059 # apicall - string to use for the function declaration prefix,
2060 # such as APICALL on Windows.
2061 # apientry - string to use for the calling convention macro,
2062 # in typedefs, such as APIENTRY.
2063 # apientryp - string to use for the calling convention macro
2064 # in function pointer typedefs, such as APIENTRYP.
2065 # indentFuncProto - True if prototype declarations should put each
2066 # parameter on a separate line
2067 # indentFuncPointer - True if typedefed function pointers should put each
2068 # parameter on a separate line
2069 # alignFuncParam - if nonzero and parameters are being put on a
2070 # separate line, align parameter names at the specified column
2071 class MockICDGeneratorOptions(GeneratorOptions
):
2080 emitversions
= '.*',
2081 defaultExtensions
= None,
2082 addExtensions
= None,
2083 removeExtensions
= None,
2084 emitExtensions
= None,
2085 sortProcedure
= regSortFeatures
,
2087 genFuncPointers
= True,
2089 protectFeature
= True,
2090 protectProto
= None,
2091 protectProtoStr
= None,
2095 indentFuncProto
= True,
2096 indentFuncPointer
= False,
2098 expandEnumerants
= True,
2099 helper_file_type
= ''):
2100 GeneratorOptions
.__init
__(self
,
2101 conventions
= conventions
,
2102 filename
= filename
,
2103 directory
= directory
,
2107 versions
= versions
,
2108 emitversions
= emitversions
,
2109 defaultExtensions
= defaultExtensions
,
2110 addExtensions
= addExtensions
,
2111 removeExtensions
= removeExtensions
,
2112 emitExtensions
= emitExtensions
,
2113 sortProcedure
= sortProcedure
)
2114 self
.prefixText
= prefixText
2115 self
.genFuncPointers
= genFuncPointers
2116 self
.protectFile
= protectFile
2117 self
.protectFeature
= protectFeature
2118 self
.protectProto
= protectProto
2119 self
.protectProtoStr
= protectProtoStr
2120 self
.apicall
= apicall
2121 self
.apientry
= apientry
2122 self
.apientryp
= apientryp
2123 self
.indentFuncProto
= indentFuncProto
2124 self
.indentFuncPointer
= indentFuncPointer
2125 self
.alignFuncParam
= alignFuncParam
2127 # MockICDOutputGenerator - subclass of OutputGenerator.
2128 # Generates a mock vulkan ICD.
2129 # This is intended to be a minimal replacement for a vulkan device in order
2130 # to enable Vulkan Validation testing.
2133 # MockOutputGenerator(errFile, warnFile, diagFile) - args as for
2134 # OutputGenerator. Defines additional internal state.
2135 # ---- methods overriding base class ----
2136 # beginFile(genOpts)
2138 # beginFeature(interface, emit)
2140 # genType(typeinfo,name)
2141 # genStruct(typeinfo,name)
2142 # genGroup(groupinfo,name)
2143 # genEnum(enuminfo, name)
2145 class MockICDOutputGenerator(OutputGenerator
):
2146 """Generate specified API interfaces in a specific style, such as a C header"""
2147 # This is an ordered list of sections in the header file.
2148 TYPE_SECTIONS
= ['include', 'define', 'basetype', 'handle', 'enum',
2149 'group', 'bitmask', 'funcpointer', 'struct']
2150 ALL_SECTIONS
= TYPE_SECTIONS
+ ['command']
2152 errFile
= sys
.stderr
,
2153 warnFile
= sys
.stderr
,
2154 diagFile
= sys
.stdout
):
2155 OutputGenerator
.__init
__(self
, errFile
, warnFile
, diagFile
)
2156 # Internal state - accumulators for different inner block text
2157 self
.sections
= dict([(section
, []) for section
in self
.ALL_SECTIONS
])
2158 self
.intercepts
= []
2159 self
.function_declarations
= False
2161 # Check if the parameter passed in is a pointer to an array
2162 def paramIsArray(self
, param
):
2163 return param
.attrib
.get('len') is not None
2165 # Check if the parameter passed in is a pointer
2166 def paramIsPointer(self
, param
):
2169 if ((elem
.tag
!= 'type') and (elem
.tail
is not None)) and '*' in elem
.tail
:
2173 # Check if an object is a non-dispatchable handle
2174 def isHandleTypeNonDispatchable(self
, handletype
):
2175 handle
= self
.registry
.tree
.find("types/type/[name='" + handletype
+ "'][@category='handle']")
2176 if handle
is not None and handle
.find('type').text
== 'VK_DEFINE_NON_DISPATCHABLE_HANDLE':
2181 # Check if an object is a dispatchable handle
2182 def isHandleTypeDispatchable(self
, handletype
):
2183 handle
= self
.registry
.tree
.find("types/type/[name='" + handletype
+ "'][@category='handle']")
2184 if handle
is not None and handle
.find('type').text
== 'VK_DEFINE_HANDLE':
2189 # Check that the target API is in the supported list for the extension
2190 def checkExtensionAPISupport(self
, supported
):
2191 return self
.genOpts
.apiname
in supported
.split(',')
2193 def beginFile(self
, genOpts
):
2194 OutputGenerator
.beginFile(self
, genOpts
)
2197 # Multiple inclusion protection & C++ namespace.
2198 if (genOpts
.protectFile
and self
.genOpts
.filename
== "function_declarations.h"):
2199 self
.function_declarations
= True
2201 # User-supplied prefix text, if any (list of strings)
2202 if (genOpts
.prefixText
):
2203 for s
in genOpts
.prefixText
:
2204 write(s
, file=self
.outFile
)
2206 if self
.function_declarations
:
2208 # Include all of the extensions in ICD except specific ignored ones
2211 # Ignore extensions that ICDs should not implement or are not safe to report
2212 ignore_exts
= ['VK_EXT_validation_cache', 'VK_KHR_portability_subset']
2213 for ext
in self
.registry
.tree
.findall("extensions/extension"):
2214 if self
.checkExtensionAPISupport(ext
.attrib
['supported']): # Only include API-relevant extensions
2215 if (ext
.attrib
['name'] not in ignore_exts
):
2216 # Search for extension version enum
2217 for enum
in ext
.findall('require/enum'):
2218 if enum
.get('name', '').endswith('_SPEC_VERSION'):
2219 ext_version
= enum
.get('value')
2220 if (ext
.attrib
.get('type') == 'instance'):
2221 instance_exts
.append(' {"%s", %s},' % (ext
.attrib
['name'], ext_version
))
2223 device_exts
.append(' {"%s", %s},' % (ext
.attrib
['name'], ext_version
))
2225 write('#pragma once\n',file=self
.outFile
)
2226 write('#include <stdint.h>',file=self
.outFile
)
2227 write('#include <cstring>',file=self
.outFile
)
2228 write('#include <string>',file=self
.outFile
)
2229 write('#include <unordered_map>',file=self
.outFile
)
2230 write('#include <vulkan/vulkan.h>',file=self
.outFile
)
2232 write('namespace vkmock {\n', file=self
.outFile
)
2233 write('// Map of instance extension name to version', file=self
.outFile
)
2234 write('static const std::unordered_map<std::string, uint32_t> instance_extension_map = {', file=self
.outFile
)
2235 write('\n'.join(instance_exts
), file=self
.outFile
)
2236 write('};', file=self
.outFile
)
2237 write('// Map of device extension name to version', file=self
.outFile
)
2238 write('static const std::unordered_map<std::string, uint32_t> device_extension_map = {', file=self
.outFile
)
2239 write('\n'.join(device_exts
), file=self
.outFile
)
2240 write('};', file=self
.outFile
)
2242 write('#pragma once\n',file=self
.outFile
)
2243 write('#include "mock_icd.h"',file=self
.outFile
)
2244 write('#include "function_declarations.h"\n',file=self
.outFile
)
2245 write('namespace vkmock {', file=self
.outFile
)
2250 # Finish C++ namespace
2252 if self
.function_declarations
:
2253 # record intercepted procedures
2254 write('// Map of all APIs to be intercepted by this layer', file=self
.outFile
)
2255 write('static const std::unordered_map<std::string, void*> name_to_funcptr_map = {', file=self
.outFile
)
2256 write('\n'.join(self
.intercepts
), file=self
.outFile
)
2257 write('};\n', file=self
.outFile
)
2258 write('} // namespace vkmock', file=self
.outFile
)
2261 # Finish processing in superclass
2262 OutputGenerator
.endFile(self
)
2263 def beginFeature(self
, interface
, emit
):
2264 #write('// starting beginFeature', file=self.outFile)
2265 # Start processing in superclass
2266 OutputGenerator
.beginFeature(self
, interface
, emit
)
2267 self
.featureExtraProtect
= GetFeatureProtect(interface
)
2269 # Accumulate includes, defines, types, enums, function pointer typedefs,
2270 # end function prototypes separately for this feature. They're only
2271 # printed in endFeature().
2272 self
.sections
= dict([(section
, []) for section
in self
.ALL_SECTIONS
])
2273 #write('// ending beginFeature', file=self.outFile)
2274 def endFeature(self
):
2276 # Actually write the interface to the output file.
2277 #write('// starting endFeature', file=self.outFile)
2280 if (self
.genOpts
.protectFeature
):
2281 write('#ifndef', self
.featureName
, file=self
.outFile
)
2282 # If type declarations are needed by other features based on
2283 # this one, it may be necessary to suppress the ExtraProtect,
2284 # or move it below the 'for section...' loop.
2285 #write('// endFeature looking at self.featureExtraProtect', file=self.outFile)
2286 if (self
.featureExtraProtect
!= None):
2287 write('#ifdef', self
.featureExtraProtect
, file=self
.outFile
)
2288 #write('#define', self.featureName, '1', file=self.outFile)
2289 for section
in self
.TYPE_SECTIONS
:
2290 #write('// endFeature writing section'+section, file=self.outFile)
2291 contents
= self
.sections
[section
]
2293 write('\n'.join(contents
), file=self
.outFile
)
2295 #write('// endFeature looking at self.sections[command]', file=self.outFile)
2296 if (self
.sections
['command']):
2297 write('\n'.join(self
.sections
['command']), end
=u
'', file=self
.outFile
)
2299 if (self
.featureExtraProtect
!= None):
2300 write('#endif /*', self
.featureExtraProtect
, '*/', file=self
.outFile
)
2301 if (self
.genOpts
.protectFeature
):
2302 write('#endif /*', self
.featureName
, '*/', file=self
.outFile
)
2303 # Finish processing in superclass
2304 OutputGenerator
.endFeature(self
)
2305 #write('// ending endFeature', file=self.outFile)
2307 # Append a definition to the specified section
2308 def appendSection(self
, section
, text
):
2309 # self.sections[section].append('SECTION: ' + section + '\n')
2310 self
.sections
[section
].append(text
)
2313 def genType(self
, typeinfo
, name
, alias
):
2316 # Struct (e.g. C "struct" type) generation.
2317 # This is a special case of the <type> tag where the contents are
2318 # interpreted as a set of <member> tags instead of freeform C
2319 # C type declarations. The <member> tags are just like <param>
2320 # tags - they are a declaration of a struct or union member.
2321 # Only simple member declarations are supported (no nested
2323 def genStruct(self
, typeinfo
, typeName
, alias
):
2324 OutputGenerator
.genStruct(self
, typeinfo
, typeName
, alias
)
2325 body
= 'typedef ' + typeinfo
.elem
.get('category') + ' ' + typeName
+ ' {\n'
2326 # paramdecl = self.makeCParamDecl(typeinfo.elem, self.genOpts.alignFuncParam)
2327 for member
in typeinfo
.elem
.findall('.//member'):
2328 body
+= self
.makeCParamDecl(member
, self
.genOpts
.alignFuncParam
)
2330 body
+= '} ' + typeName
+ ';\n'
2331 self
.appendSection('struct', body
)
2333 # Group (e.g. C "enum" type) generation.
2334 # These are concatenated together with other types.
2335 def genGroup(self
, groupinfo
, groupName
, alias
):
2337 # Enumerant generation
2338 # <enum> tags may specify their values in several ways, but are usually
2340 def genEnum(self
, enuminfo
, name
, alias
):
2343 # Command generation
2344 def genCmd(self
, cmdinfo
, name
, alias
):
2345 decls
= self
.makeCDecls(cmdinfo
.elem
)
2346 if self
.function_declarations
: # In the header declare all intercepts
2347 self
.appendSection('command', '')
2348 self
.appendSection('command', 'static %s' % (decls
[0]))
2349 if (self
.featureExtraProtect
!= None):
2350 self
.intercepts
+= [ '#ifdef %s' % self
.featureExtraProtect
]
2351 self
.intercepts
+= [ ' {"%s", (void*)%s},' % (name
,name
[2:]) ]
2352 if (self
.featureExtraProtect
!= None):
2353 self
.intercepts
+= [ '#endif' ]
2356 manual_functions
= [
2357 # Include functions here to be intercepted w/ manually implemented function bodies
2358 'vkGetDeviceProcAddr',
2359 'vkGetInstanceProcAddr',
2363 'vkDestroyInstance',
2364 'vkFreeCommandBuffers',
2365 'vkAllocateCommandBuffers',
2366 'vkDestroyCommandPool',
2367 #'vkCreateDebugReportCallbackEXT',
2368 #'vkDestroyDebugReportCallbackEXT',
2369 'vkEnumerateInstanceLayerProperties',
2370 'vkEnumerateInstanceVersion',
2371 'vkEnumerateInstanceExtensionProperties',
2372 'vkEnumerateDeviceLayerProperties',
2373 'vkEnumerateDeviceExtensionProperties',
2375 if name
in manual_functions
:
2376 self
.appendSection('command', '')
2377 if name
not in CUSTOM_C_INTERCEPTS
:
2378 self
.appendSection('command', '// declare only')
2379 self
.appendSection('command', 'static %s' % (decls
[0]))
2380 self
.appendSection('command', '// TODO: Implement custom intercept body')
2382 self
.appendSection('command', 'static %s' % (decls
[0][:-1]))
2383 self
.appendSection('command', '{\n%s}' % (CUSTOM_C_INTERCEPTS
[name
]))
2384 self
.intercepts
+= [ ' {"%s", (void*)%s},' % (name
,name
[2:]) ]
2386 # record that the function will be intercepted
2387 if (self
.featureExtraProtect
!= None):
2388 self
.intercepts
+= [ '#ifdef %s' % self
.featureExtraProtect
]
2389 self
.intercepts
+= [ ' {"%s", (void*)%s},' % (name
,name
[2:]) ]
2390 if (self
.featureExtraProtect
!= None):
2391 self
.intercepts
+= [ '#endif' ]
2393 OutputGenerator
.genCmd(self
, cmdinfo
, name
, alias
)
2395 self
.appendSection('command', '')
2396 self
.appendSection('command', 'static %s' % (decls
[0][:-1]))
2397 if name
in CUSTOM_C_INTERCEPTS
:
2398 self
.appendSection('command', '{%s}' % (CUSTOM_C_INTERCEPTS
[name
]))
2401 # Declare result variable, if any.
2402 resulttype
= cmdinfo
.elem
.find('proto/type')
2403 if (resulttype
!= None and resulttype
.text
== 'void'):
2405 # if the name w/ KHR postfix is in the CUSTOM_C_INTERCEPTS
2406 # Call the KHR custom version instead of generating separate code
2407 khr_name
= name
+ "KHR"
2408 if khr_name
in CUSTOM_C_INTERCEPTS
:
2410 if resulttype
!= None:
2411 return_string
= 'return '
2412 params
= cmdinfo
.elem
.findall('param/name')
2414 for param
in params
:
2415 param_names
.append(param
.text
)
2416 self
.appendSection('command', '{\n %s%s(%s);\n}' % (return_string
, khr_name
[2:], ", ".join(param_names
)))
2418 self
.appendSection('command', '{')
2420 api_function_name
= cmdinfo
.elem
.attrib
.get('name')
2421 # GET THE TYPE OF FUNCTION
2422 if any(api_function_name
.startswith(ftxt
) for ftxt
in ('vkCreate', 'vkAllocate')):
2424 last_param
= cmdinfo
.elem
.findall('param')[-1]
2425 lp_txt
= last_param
.find('name').text
2427 if ('len' in last_param
.attrib
):
2428 lp_len
= last_param
.attrib
['len']
2429 lp_len
= lp_len
.replace('::', '->')
2430 lp_type
= last_param
.find('type').text
2431 handle_type
= 'dispatchable'
2432 allocator_txt
= 'CreateDispObjHandle()';
2433 if (self
.isHandleTypeNonDispatchable(lp_type
)):
2434 handle_type
= 'non-' + handle_type
2435 allocator_txt
= 'global_unique_handle++';
2436 # Need to lock in both cases
2437 self
.appendSection('command', ' unique_lock_t lock(global_lock);')
2438 if (lp_len
!= None):
2439 #print("%s last params (%s) has len %s" % (handle_type, lp_txt, lp_len))
2440 self
.appendSection('command', ' for (uint32_t i = 0; i < %s; ++i) {' % (lp_len
))
2441 self
.appendSection('command', ' %s[i] = (%s)%s;' % (lp_txt
, lp_type
, allocator_txt
))
2442 self
.appendSection('command', ' }')
2444 #print("Single %s last param is '%s' w/ type '%s'" % (handle_type, lp_txt, lp_type))
2445 if 'AllocateMemory' in api_function_name
:
2446 # Store allocation size in case it's mapped
2447 self
.appendSection('command', ' allocated_memory_size_map[(VkDeviceMemory)global_unique_handle] = pAllocateInfo->allocationSize;')
2448 self
.appendSection('command', ' *%s = (%s)%s;' % (lp_txt
, lp_type
, allocator_txt
))
2449 elif True in [ftxt
in api_function_name
for ftxt
in ['Destroy', 'Free']]:
2450 self
.appendSection('command', '//Destroy object')
2451 if 'FreeMemory' in api_function_name
:
2452 # If the memory is mapped, unmap it
2453 self
.appendSection('command', ' UnmapMemory(device, memory);')
2454 # Remove from allocation map
2455 self
.appendSection('command', ' unique_lock_t lock(global_lock);')
2456 self
.appendSection('command', ' allocated_memory_size_map.erase(memory);')
2458 self
.appendSection('command', '//Not a CREATE or DESTROY function')
2460 # Return result variable, if any.
2461 if (resulttype
!= None):
2462 if api_function_name
== 'vkGetEventStatus':
2463 self
.appendSection('command', ' return VK_EVENT_SET;')
2465 self
.appendSection('command', ' return VK_SUCCESS;')
2466 self
.appendSection('command', '}')
2468 # override makeProtoName to drop the "vk" prefix
2469 def makeProtoName(self
, name
, tail
):
2470 return self
.genOpts
.apientry
+ name
[2:] + tail