28 .r = VK_COMPONENT_SWIZZLE_IDENTITY,
29 .g = VK_COMPONENT_SWIZZLE_IDENTITY,
30 .b = VK_COMPONENT_SWIZZLE_IDENTITY,
31 .a = VK_COMPONENT_SWIZZLE_IDENTITY,
37 #define CASE(VAL) case VAL: return #VAL
45 CASE(VK_ERROR_OUT_OF_HOST_MEMORY);
46 CASE(VK_ERROR_OUT_OF_DEVICE_MEMORY);
47 CASE(VK_ERROR_INITIALIZATION_FAILED);
48 CASE(VK_ERROR_DEVICE_LOST);
49 CASE(VK_ERROR_MEMORY_MAP_FAILED);
50 CASE(VK_ERROR_LAYER_NOT_PRESENT);
51 CASE(VK_ERROR_EXTENSION_NOT_PRESENT);
52 CASE(VK_ERROR_FEATURE_NOT_PRESENT);
53 CASE(VK_ERROR_INCOMPATIBLE_DRIVER);
54 CASE(VK_ERROR_TOO_MANY_OBJECTS);
55 CASE(VK_ERROR_FORMAT_NOT_SUPPORTED);
56 CASE(VK_ERROR_FRAGMENTED_POOL);
57 CASE(VK_ERROR_UNKNOWN);
58 CASE(VK_ERROR_OUT_OF_POOL_MEMORY);
59 CASE(VK_ERROR_INVALID_EXTERNAL_HANDLE);
60 CASE(VK_ERROR_FRAGMENTATION);
61 CASE(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS);
62 CASE(VK_PIPELINE_COMPILE_REQUIRED);
63 CASE(VK_ERROR_SURFACE_LOST_KHR);
64 CASE(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
65 CASE(VK_SUBOPTIMAL_KHR);
66 CASE(VK_ERROR_OUT_OF_DATE_KHR);
67 CASE(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR);
68 CASE(VK_ERROR_VALIDATION_FAILED_EXT);
69 CASE(VK_ERROR_INVALID_SHADER_NV);
70 CASE(VK_ERROR_VIDEO_PICTURE_LAYOUT_NOT_SUPPORTED_KHR);
71 CASE(VK_ERROR_VIDEO_PROFILE_OPERATION_NOT_SUPPORTED_KHR);
72 CASE(VK_ERROR_VIDEO_PROFILE_FORMAT_NOT_SUPPORTED_KHR);
73 CASE(VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR);
74 CASE(VK_ERROR_VIDEO_STD_VERSION_NOT_SUPPORTED_KHR);
75 CASE(VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT);
76 CASE(VK_ERROR_NOT_PERMITTED_KHR);
77 CASE(VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT);
78 CASE(VK_THREAD_IDLE_KHR);
79 CASE(VK_THREAD_DONE_KHR);
80 CASE(VK_OPERATION_DEFERRED_KHR);
81 CASE(VK_OPERATION_NOT_DEFERRED_KHR);
82 default:
return "Unknown error";
90 for (
int i = 0;
i <
s->hwctx->nb_qf;
i++) {
93 for (
int j = 0; j <
s->nb_qfs; j++) {
94 if (
s->qfs[j] ==
s->hwctx->qf[
i].idx) {
102 s->qfs[
s->nb_qfs++] =
s->hwctx->qf[
i].idx;
110 s->hprops = (VkPhysicalDeviceExternalMemoryHostPropertiesEXT) {
111 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT,
113 s->optical_flow_props = (VkPhysicalDeviceOpticalFlowPropertiesNV) {
114 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPTICAL_FLOW_PROPERTIES_NV,
117 s->coop_matrix_props = (VkPhysicalDeviceCooperativeMatrixPropertiesKHR) {
118 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_PROPERTIES_KHR,
119 .pNext = &
s->optical_flow_props,
121 s->subgroup_props = (VkPhysicalDeviceSubgroupSizeControlProperties) {
122 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES,
123 .pNext = &
s->coop_matrix_props,
125 s->desc_buf_props = (VkPhysicalDeviceDescriptorBufferPropertiesEXT) {
126 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_PROPERTIES_EXT,
127 .pNext = &
s->subgroup_props,
129 s->driver_props = (VkPhysicalDeviceDriverProperties) {
130 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES,
131 .pNext = &
s->desc_buf_props,
133 s->props_11 = (VkPhysicalDeviceVulkan11Properties) {
134 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES,
135 .pNext = &
s->driver_props,
137 s->props = (VkPhysicalDeviceProperties2) {
138 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
139 .pNext = &
s->props_11,
142 s->atomic_float_feats = (VkPhysicalDeviceShaderAtomicFloatFeaturesEXT) {
143 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT,
145 s->feats_12 = (VkPhysicalDeviceVulkan12Features) {
146 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
147 .pNext = &
s->atomic_float_feats,
149 s->feats = (VkPhysicalDeviceFeatures2) {
150 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
151 .pNext = &
s->feats_12,
154 vk->GetPhysicalDeviceProperties2(
s->hwctx->phys_dev, &
s->props);
155 vk->GetPhysicalDeviceMemoryProperties(
s->hwctx->phys_dev, &
s->mprops);
156 vk->GetPhysicalDeviceFeatures2(
s->hwctx->phys_dev, &
s->feats);
163 vk->GetPhysicalDeviceQueueFamilyProperties2(
s->hwctx->phys_dev, &
s->tot_nb_qfs,
NULL);
165 s->qf_props =
av_calloc(
s->tot_nb_qfs,
sizeof(*
s->qf_props));
169 s->query_props =
av_calloc(
s->tot_nb_qfs,
sizeof(*
s->query_props));
175 s->video_props =
av_calloc(
s->tot_nb_qfs,
sizeof(*
s->video_props));
176 if (!
s->video_props) {
182 for (uint32_t
i = 0;
i <
s->tot_nb_qfs;
i++) {
183 s->query_props[
i] = (VkQueueFamilyQueryResultStatusPropertiesKHR) {
184 .sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_QUERY_RESULT_STATUS_PROPERTIES_KHR,
186 s->video_props[
i] = (VkQueueFamilyVideoPropertiesKHR) {
187 .sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_VIDEO_PROPERTIES_KHR,
188 .pNext = &
s->query_props[
i],
190 s->qf_props[
i] = (VkQueueFamilyProperties2) {
191 .sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2,
196 vk->GetPhysicalDeviceQueueFamilyProperties2(
s->hwctx->phys_dev, &
s->tot_nb_qfs,
s->qf_props);
199 vk->GetPhysicalDeviceCooperativeMatrixPropertiesKHR(
s->hwctx->phys_dev,
200 &
s->coop_mat_props_nb,
NULL);
202 if (
s->coop_mat_props_nb) {
204 sizeof(VkCooperativeMatrixPropertiesKHR));
205 for (
int i = 0;
i <
s->coop_mat_props_nb;
i++) {
206 s->coop_mat_props[
i] = (VkCooperativeMatrixPropertiesKHR) {
207 .sType = VK_STRUCTURE_TYPE_COOPERATIVE_MATRIX_PROPERTIES_KHR,
211 vk->GetPhysicalDeviceCooperativeMatrixPropertiesKHR(
s->hwctx->phys_dev,
212 &
s->coop_mat_props_nb,
221 VkQueueFlagBits dev_family,
222 VkVideoCodecOperationFlagBitsKHR vid_ops)
224 for (
int i = 0;
i <
s->hwctx->nb_qf;
i++) {
225 if ((
s->hwctx->qf[
i].flags & dev_family) &&
226 (
s->hwctx->qf[
i].video_caps & vid_ops) == vid_ops) {
227 return &
s->hwctx->qf[
i];
242 vk->WaitForFences(
s->hwctx->act_dev, 1, &e->
fence, VK_TRUE, UINT64_MAX);
243 vk->DestroyFence(
s->hwctx->act_dev, e->
fence,
s->hwctx->alloc);
275 vk->DestroyDescriptorPool(
s->hwctx->act_dev, sd->
desc_pool,
284 vk->FreeCommandBuffers(
s->hwctx->act_dev, pool->
cmd_buf_pool,
287 vk->DestroyCommandPool(
s->hwctx->act_dev, pool->
cmd_buf_pool,
s->hwctx->alloc);
289 vk->DestroyQueryPool(
s->hwctx->act_dev, pool->
query_pool,
s->hwctx->alloc);
298 int nb_queries, VkQueryType query_type,
int query_64bit,
299 const void *query_create_pnext)
306 VkCommandBufferAllocateInfo cbuf_create;
308 const VkQueryPoolVideoEncodeFeedbackCreateInfoKHR *ef =
NULL;
312 if (query_type == VK_QUERY_TYPE_VIDEO_ENCODE_FEEDBACK_KHR) {
314 VK_STRUCTURE_TYPE_QUERY_POOL_VIDEO_ENCODE_FEEDBACK_CREATE_INFO_KHR);
321 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
322 .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT |
323 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
324 .queueFamilyIndex = qf->
idx,
328 if (
ret != VK_SUCCESS) {
343 cbuf_create = (VkCommandBufferAllocateInfo) {
344 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
345 .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
347 .commandBufferCount = nb_contexts,
349 ret = vk->AllocateCommandBuffers(
s->hwctx->act_dev, &cbuf_create,
351 if (
ret != VK_SUCCESS) {
360 VkQueryPoolCreateInfo query_pool_info = {
361 .sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,
362 .pNext = query_create_pnext,
363 .queryType = query_type,
364 .queryCount = nb_queries*nb_contexts,
366 ret = vk->CreateQueryPool(
s->hwctx->act_dev, &query_pool_info,
368 if (
ret != VK_SUCCESS) {
381 if (query_type == VK_QUERY_TYPE_VIDEO_ENCODE_FEEDBACK_KHR) {
382 int nb_results =
av_popcount(ef->encodeFeedbackFlags);
385 }
else if (query_type == VK_QUERY_TYPE_RESULT_STATUS_ONLY_KHR) {
412 VkFenceCreateInfo fence_create = {
413 .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
414 .flags = VK_FENCE_CREATE_SIGNALED_BIT,
418 ret = vk->CreateFence(
s->hwctx->act_dev, &fence_create,
s->hwctx->alloc,
420 if (
ret != VK_SUCCESS) {
439 vk->GetDeviceQueue(
s->hwctx->act_dev, qf->
idx, e->
qi, &e->
queue);
450 void **
data, VkQueryResultFlagBits
flags)
454 VkQueryResultFlags qf =
flags & ~(VK_QUERY_RESULT_64_BIT |
455 VK_QUERY_RESULT_WITH_STATUS_BIT_KHR);
459 return VK_INCOMPLETE;
463 VK_QUERY_RESULT_64_BIT : 0x0;
465 VK_QUERY_RESULT_WITH_STATUS_BIT_KHR : 0x0;
470 return vk->GetQueryPoolResults(
s->hwctx->act_dev, pool->
query_pool,
485 vk->WaitForFences(
s->hwctx->act_dev, 1, &e->
fence, VK_TRUE, UINT64_MAX);
495 VkCommandBufferBeginInfo cmd_start = {
496 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
497 .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
501 vk->WaitForFences(
s->hwctx->act_dev, 1, &e->
fence, VK_TRUE, UINT64_MAX);
502 vk->ResetFences(
s->hwctx->act_dev, 1, &e->
fence);
507 ret = vk->BeginCommandBuffer(e->
buf, &cmd_start);
508 if (
ret != VK_SUCCESS) {
537 vkfc->unlock_frame(hwfc, vkf);
561 for (
int i = 0;
i < nb_deps;
i++) {
599 #define ARR_REALLOC(str, arr, alloc_s, cnt) \
601 arr = av_fast_realloc(str->arr, alloc_s, (cnt + 1)*sizeof(*arr)); \
603 ff_vk_exec_discard_deps(s, e); \
604 return AVERROR(ENOMEM); \
621 vk->DestroySemaphore(
s->hwctx->act_dev, ts->
sem[
i],
s->hwctx->alloc);
627 VkSemaphore sem, uint64_t
val,
628 VkPipelineStageFlagBits2 stage)
634 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
644 VkSemaphore *sem,
int nb,
645 VkPipelineStageFlagBits2 stage,
657 for (
int i = 0;
i < nb;
i++) {
658 VkSemaphoreSubmitInfo *sem_sig;
662 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
671 buf_size =
sizeof(*ts) +
sizeof(VkSemaphore)*nb;
678 memcpy(ts->sem, sem, nb*
sizeof(*sem));
694 for (
int i = 0;
i < nb;
i++) {
703 for (
int i = 0;
i < nb;
i++)
704 vk->DestroySemaphore(
s->hwctx->act_dev, sem[
i],
s->hwctx->alloc);
710 VkPipelineStageFlagBits2 wait_stage,
711 VkPipelineStageFlagBits2 signal_stage)
713 uint8_t *frame_locked;
714 uint8_t *frame_update;
717 VkImageLayout *layout_dst;
718 uint32_t *queue_family_dst;
719 VkAccessFlagBits *access_dst;
754 vkfc->lock_frame(hwfc, vkf);
759 for (
int i = 0;
i < nb_images;
i++) {
761 VkSemaphoreSubmitInfo *sem_sig;
762 uint64_t **sem_sig_val_dst;
769 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
770 .semaphore = vkf->sem[
i],
771 .value = vkf->sem_value[
i],
772 .stageMask = wait_stage,
776 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
777 .semaphore = vkf->sem[
i],
778 .value = vkf->sem_value[
i] + 1,
779 .stageMask = signal_stage,
790 VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar)
809 VkSemaphore *
dst, uint64_t *dst_val,
812 uint64_t **sem_sig_val_dst;
838 VkCommandBufferSubmitInfo cmd_buf_info = (VkCommandBufferSubmitInfo) {
839 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO,
840 .commandBuffer = e->
buf,
842 VkSubmitInfo2 submit_info = (VkSubmitInfo2) {
843 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2,
844 .pCommandBufferInfos = &cmd_buf_info,
845 .commandBufferInfoCount = 1,
848 .pSignalSemaphoreInfos = e->
sem_sig,
852 ret = vk->EndCommandBuffer(e->
buf);
853 if (
ret != VK_SUCCESS) {
860 s->hwctx->lock_queue(
s->device, e->
qf, e->
qi);
862 s->hwctx->unlock_queue(
s->device, e->
qf, e->
qi);
864 if (
ret != VK_SUCCESS) {
884 for (
int i = 0;
i < nb_images;
i++) {
890 vkfc->unlock_frame(hwfc, vkf);
901 VkMemoryPropertyFlagBits req_flags,
void *alloc_extension,
902 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
908 VkMemoryAllocateInfo alloc_info = {
909 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
910 .pNext = alloc_extension,
913 alloc_info.allocationSize = req->size;
917 for (
int i = 0;
i <
s->mprops.memoryTypeCount;
i++) {
919 if (!(req->memoryTypeBits & (1 <<
i)))
923 if ((req_flags != UINT32_MAX) &&
924 ((
s->mprops.memoryTypes[
i].propertyFlags & req_flags) != req_flags))
938 alloc_info.memoryTypeIndex =
index;
940 ret = vk->AllocateMemory(
s->hwctx->act_dev, &alloc_info,
941 s->hwctx->alloc, mem);
942 if (
ret != VK_SUCCESS)
946 *mem_flags |=
s->mprops.memoryTypes[
index].propertyFlags;
952 void *pNext,
void *alloc_pNext,
953 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags)
960 VkBufferCreateInfo buf_spawn = {
961 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
964 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
965 .size =
flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ?
966 FFALIGN(
size,
s->props.properties.limits.minMemoryMapAlignment) :
970 VkMemoryAllocateFlagsInfo alloc_flags = {
971 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO,
972 .flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT,
974 VkBufferMemoryRequirementsInfo2 req_desc = {
975 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
977 VkMemoryDedicatedAllocateInfo ded_alloc = {
978 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
979 .pNext = alloc_pNext,
981 VkMemoryDedicatedRequirements ded_req = {
982 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
984 VkMemoryRequirements2 req = {
985 .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
990 "usage: 0x%x, flags: 0x%x\n",
993 ret = vk->CreateBuffer(
s->hwctx->act_dev, &buf_spawn,
s->hwctx->alloc, &buf->
buf);
994 if (
ret != VK_SUCCESS) {
1000 req_desc.buffer = buf->
buf;
1002 vk->GetBufferMemoryRequirements2(
s->hwctx->act_dev, &req_desc, &req);
1005 use_ded_mem = ded_req.prefersDedicatedAllocation |
1006 ded_req.requiresDedicatedAllocation;
1008 ded_alloc.buffer = buf->
buf;
1009 ded_alloc.pNext = alloc_pNext;
1010 alloc_pNext = &ded_alloc;
1013 if (
usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) {
1014 alloc_flags.pNext = alloc_pNext;
1015 alloc_pNext = &alloc_flags;
1023 ret = vk->BindBufferMemory(
s->hwctx->act_dev, buf->
buf, buf->
mem, 0);
1024 if (
ret != VK_SUCCESS) {
1030 if (
usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) {
1031 VkBufferDeviceAddressInfo address_info = {
1032 .sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
1035 buf->
address = vk->GetBufferDeviceAddress(
s->hwctx->act_dev, &address_info);
1044 int nb_buffers,
int invalidate)
1048 VkMappedMemoryRange inval_list[64];
1049 int inval_count = 0;
1051 for (
int i = 0;
i < nb_buffers;
i++) {
1053 ret = vk->MapMemory(
s->hwctx->act_dev, buf[
i]->
mem, 0,
1054 VK_WHOLE_SIZE, 0, &
dst);
1055 if (
ret != VK_SUCCESS) {
1066 for (
int i = 0;
i < nb_buffers;
i++) {
1067 const VkMappedMemoryRange ival_buf = {
1068 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
1069 .memory = buf[
i]->
mem,
1070 .size = VK_WHOLE_SIZE,
1072 if (buf[
i]->
flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
1074 inval_list[inval_count++] = ival_buf;
1078 ret = vk->InvalidateMappedMemoryRanges(
s->hwctx->act_dev, inval_count,
1080 if (
ret != VK_SUCCESS) {
1096 VkMappedMemoryRange flush_list[64];
1097 int flush_count = 0;
1100 for (
int i = 0;
i < nb_buffers;
i++) {
1101 const VkMappedMemoryRange flush_buf = {
1102 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
1103 .memory = buf[
i]->
mem,
1104 .size = VK_WHOLE_SIZE,
1108 if (buf[
i]->
flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
1110 flush_list[flush_count++] = flush_buf;
1115 ret = vk->FlushMappedMemoryRanges(
s->hwctx->act_dev, flush_count,
1117 if (
ret != VK_SUCCESS) {
1124 for (
int i = 0;
i < nb_buffers;
i++) {
1125 vk->UnmapMemory(
s->hwctx->act_dev, buf[
i]->
mem);
1136 if (!buf || !
s->hwctx)
1141 if (buf->
buf != VK_NULL_HANDLE)
1142 vk->DestroyBuffer(
s->hwctx->act_dev, buf->
buf,
s->hwctx->alloc);
1143 if (buf->
mem != VK_NULL_HANDLE)
1144 vk->FreeMemory(
s->hwctx->act_dev, buf->
mem,
s->hwctx->alloc);
1148 buf->
buf = VK_NULL_HANDLE;
1149 buf->
mem = VK_NULL_HANDLE;
1176 void *create_pNext,
size_t size,
1177 VkMemoryPropertyFlagBits mem_props)
1197 data->stage = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
1198 data->access = VK_ACCESS_2_NONE;
1215 if (mem_props & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
1230 VkExternalMemoryBufferCreateInfo *create_desc,
1231 VkImportMemoryHostPointerInfoEXT *import_desc,
1232 VkMemoryHostPointerPropertiesEXT props)
1238 VkBufferCreateInfo buf_spawn = {
1239 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
1240 .pNext = create_desc,
1242 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
1245 VkMemoryRequirements req = {
1247 .alignment =
s->hprops.minImportedHostPointerAlignment,
1248 .memoryTypeBits = props.memoryTypeBits,
1252 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1253 import_desc, &vkb->
flags, &vkb->
mem);
1257 ret = vk->CreateBuffer(
s->hwctx->act_dev, &buf_spawn,
s->hwctx->alloc, &vkb->
buf);
1258 if (
ret != VK_SUCCESS) {
1259 vk->FreeMemory(
s->hwctx->act_dev, vkb->
mem,
s->hwctx->alloc);
1263 ret = vk->BindBufferMemory(
s->hwctx->act_dev, vkb->
buf, vkb->
mem, 0);
1264 if (
ret != VK_SUCCESS) {
1265 vk->FreeMemory(
s->hwctx->act_dev, vkb->
mem,
s->hwctx->alloc);
1266 vk->DestroyBuffer(
s->hwctx->act_dev, vkb->
buf,
s->hwctx->alloc);
1283 VkBufferUsageFlags
usage)
1289 VkExternalMemoryBufferCreateInfo create_desc = {
1290 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
1291 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
1293 VkMemoryAllocateFlagsInfo alloc_flags = {
1294 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO,
1295 .flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT,
1297 VkImportMemoryHostPointerInfoEXT import_desc = {
1298 .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
1299 .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
1300 .pNext =
usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT ? &alloc_flags :
NULL,
1302 VkMemoryHostPointerPropertiesEXT props;
1312 offs = (uintptr_t)src_data %
s->hprops.minImportedHostPointerAlignment;
1313 import_desc.pHostPointer = src_data - offs;
1315 props = (VkMemoryHostPointerPropertiesEXT) {
1316 VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT,
1318 ret = vk->GetMemoryHostPointerPropertiesEXT(
s->hwctx->act_dev,
1319 import_desc.handleType,
1320 import_desc.pHostPointer,
1322 if (!(
ret == VK_SUCCESS && props.memoryTypeBits))
1331 buffer_size = offs + src_buf->
size;
1332 buffer_size =
FFALIGN(buffer_size,
s->props.properties.limits.minMemoryMapAlignment);
1333 buffer_size =
FFALIGN(buffer_size,
s->hprops.minImportedHostPointerAlignment);
1343 buffer_size, &create_desc, &import_desc,
1351 if (
usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) {
1352 VkBufferDeviceAddressInfo address_info = {
1353 .sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
1356 vkb->
address = vk->GetBufferDeviceAddress(
s->hwctx->act_dev, &address_info);
1363 vkb->
size = buffer_size - offs;
1364 vkb->
flags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
1379 VkShaderStageFlagBits stage)
1381 VkPushConstantRange *pc;
1390 memset(pc, 0,
sizeof(*pc));
1392 pc->stageFlags = stage;
1400 int unnorm_coords, VkFilter
filt)
1405 VkSamplerCreateInfo sampler_info = {
1406 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
1408 .minFilter = sampler_info.magFilter,
1409 .mipmapMode = unnorm_coords ? VK_SAMPLER_MIPMAP_MODE_NEAREST :
1410 VK_SAMPLER_MIPMAP_MODE_LINEAR,
1411 .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
1412 .addressModeV = sampler_info.addressModeU,
1413 .addressModeW = sampler_info.addressModeU,
1414 .anisotropyEnable = VK_FALSE,
1415 .compareOp = VK_COMPARE_OP_NEVER,
1416 .borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
1417 .unnormalizedCoordinates = unnorm_coords,
1420 ret = vk->CreateSampler(
s->hwctx->act_dev, &sampler_info,
1421 s->hwctx->alloc, sampler);
1422 if (
ret != VK_SUCCESS) {
1438 static const VkImageAspectFlags plane_aspect[] = { VK_IMAGE_ASPECT_PLANE_0_BIT,
1439 VK_IMAGE_ASPECT_PLANE_1_BIT,
1440 VK_IMAGE_ASPECT_PLANE_2_BIT, };
1443 return VK_IMAGE_ASPECT_COLOR_BIT;
1445 return plane_aspect[p];
1508 int lut_tmp[4] = { lut[0], lut[1], lut[2], lut[3] };
1509 for (
int i = 0;
i < 4;
i++)
1510 lut[lut_tmp[
i]] =
i;
1531 const char *rep_tab[] = {
1537 return rep_tab[rep_fmt];
1543 const char *rep_tab[] = {
1549 return rep_tab[rep_fmt];
1557 const char *rep_tab[] = {
1563 return rep_tab[rep_fmt];
1567 const char *rep_tab[] = {
1573 return rep_tab[rep_fmt];
1577 const char *rep_tab[] = {
1583 return rep_tab[rep_fmt];
1590 const char *rep_tab[] = {
1596 return rep_tab[rep_fmt];
1619 const char *rep_tab[] = {
1625 return rep_tab[rep_fmt];
1631 const char *rep_tab[] = {
1637 return rep_tab[rep_fmt];
1640 const char *rep_tab[] = {
1646 return rep_tab[rep_fmt];
1651 const char *rep_tab[] = {
1657 return rep_tab[rep_fmt];
1662 const char *rep_tab[] = {
1668 return rep_tab[rep_fmt];
1676 const char *rep_tab[] = {
1682 return rep_tab[rep_fmt];
1701 vk->DestroyImageView(
s->hwctx->act_dev, iv->
views[
i],
s->hwctx->alloc);
1708 #define REPS_FMT(fmt) \
1709 [FF_VK_REP_NATIVE] = fmt ## _UINT, \
1710 [FF_VK_REP_FLOAT] = fmt ## _UNORM, \
1711 [FF_VK_REP_INT] = fmt ## _SINT, \
1712 [FF_VK_REP_UINT] = fmt ## _UINT,
1714 #define REPS_FMT_PACK(fmt, num) \
1715 [FF_VK_REP_NATIVE] = fmt ## _UINT_PACK ## num, \
1716 [FF_VK_REP_FLOAT] = fmt ## _UNORM_PACK ## num, \
1717 [FF_VK_REP_INT] = fmt ## _SINT_PACK ## num, \
1718 [FF_VK_REP_UINT] = fmt ## _UINT_PACK ## num,
1724 VK_FORMAT_B5G6R5_UNORM_PACK16,
1725 VK_FORMAT_B5G6R5_UNORM_PACK16,
1726 VK_FORMAT_UNDEFINED,
1727 VK_FORMAT_UNDEFINED,
1730 VK_FORMAT_R5G6B5_UNORM_PACK16,
1731 VK_FORMAT_R5G6B5_UNORM_PACK16,
1732 VK_FORMAT_UNDEFINED,
1733 VK_FORMAT_UNDEFINED,
1744 {
REPS_FMT(VK_FORMAT_R16G16B16A16) },
1747 VK_FORMAT_R32_SFLOAT,
1752 VK_FORMAT_R32G32B32_SFLOAT,
1753 VK_FORMAT_R32G32B32_SFLOAT,
1754 VK_FORMAT_UNDEFINED,
1755 VK_FORMAT_UNDEFINED,
1758 VK_FORMAT_R32G32B32A32_SFLOAT,
1759 VK_FORMAT_R32G32B32A32_SFLOAT,
1760 VK_FORMAT_UNDEFINED,
1761 VK_FORMAT_UNDEFINED,
1764 VK_FORMAT_R32G32B32_UINT,
1765 VK_FORMAT_UNDEFINED,
1766 VK_FORMAT_R32G32B32_SINT,
1767 VK_FORMAT_R32G32B32_UINT,
1770 VK_FORMAT_R32G32B32A32_UINT,
1771 VK_FORMAT_UNDEFINED,
1772 VK_FORMAT_R32G32B32A32_SINT,
1773 VK_FORMAT_R32G32B32A32_UINT,
1776 #undef REPS_FMT_PACK
1779 if (fmt == VK_FORMAT_UNDEFINED)
1780 return VK_FORMAT_UNDEFINED;
1787 return fmts_map[
i][rep_fmt];
1790 return VK_FORMAT_UNDEFINED;
1794 VkImageViewCreateInfo *ci)
1796 if (!(vkfc->
usage & VK_IMAGE_USAGE_STORAGE_BIT))
1798 switch (ci->format) {
1799 #define REMAP(src, dst) \
1803 REMAP(VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM)
1804 REMAP(VK_FORMAT_B8G8R8A8_SINT, VK_FORMAT_R8G8B8A8_SINT)
1805 REMAP(VK_FORMAT_B8G8R8A8_UINT, VK_FORMAT_R8G8B8A8_UINT)
1806 REMAP(VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM)
1807 REMAP(VK_FORMAT_B8G8R8_SINT, VK_FORMAT_R8G8B8_SINT)
1808 REMAP(VK_FORMAT_B8G8R8_UINT, VK_FORMAT_R8G8B8_UINT)
1809 REMAP(VK_FORMAT_A2B10G10R10_UNORM_PACK32, VK_FORMAT_A2R10G10B10_UNORM_PACK32)
1817 VkImageView *img_view, VkImageAspectFlags *aspect,
1828 VkImageViewUsageCreateInfo view_usage_info = {
1829 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO,
1830 .usage = vkfc->usage &
1831 (~(VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR |
1832 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)),
1834 VkImageViewCreateInfo view_create_info = {
1835 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1836 .pNext = &view_usage_info,
1837 .image = vkf->
img[
FFMIN(plane, nb_images - 1)],
1838 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1841 .subresourceRange = {
1848 if (view_create_info.format == VK_FORMAT_UNDEFINED) {
1850 "of format %i and mode %i\n",
1851 rep_fmts[plane], rep_fmt);
1855 ret = vk->CreateImageView(
s->hwctx->act_dev, &view_create_info,
1856 s->hwctx->alloc, img_view);
1857 if (
ret != VK_SUCCESS) {
1863 *aspect = view_create_info.subresourceRange.aspectMask;
1884 const size_t buf_size =
sizeof(*iv) + nb_planes*
sizeof(VkImageView);
1889 for (
int i = 0;
i < nb_planes;
i++) {
1890 VkImageViewUsageCreateInfo view_usage_info = {
1891 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO,
1892 .usage = vkfc->usage &
1893 (~(VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR |
1894 VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)),
1896 VkImageViewCreateInfo view_create_info = {
1897 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1898 .pNext = &view_usage_info,
1899 .image = vkf->
img[
FFMIN(
i, nb_images - 1)],
1900 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1903 .subresourceRange = {
1910 if (view_create_info.format == VK_FORMAT_UNDEFINED) {
1912 "of format %i and mode %i\n",
1913 rep_fmts[
i], rep_fmt);
1918 ret = vk->CreateImageView(
s->hwctx->act_dev, &view_create_info,
1919 s->hwctx->alloc, &iv->views[
i]);
1920 if (
ret != VK_SUCCESS) {
1941 memcpy(views, iv->views, nb_planes*
sizeof(*views));
1946 for (
int i = 0;
i < iv->nb_views;
i++)
1947 vk->DestroyImageView(
s->hwctx->act_dev, iv->views[
i],
s->hwctx->alloc);
1953 AVFrame *pic, VkImageMemoryBarrier2 *bar,
int *nb_bar,
1954 VkPipelineStageFlags src_stage,
1955 VkPipelineStageFlags dst_stage,
1956 VkAccessFlagBits new_access,
1957 VkImageLayout new_layout,
1970 for (
int i = 0;
i < nb_images;
i++) {
1971 bar[*nb_bar] = (VkImageMemoryBarrier2) {
1972 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
1974 .srcStageMask = src_stage,
1975 .dstStageMask = dst_stage,
1977 .dstAccessMask = new_access,
1979 .newLayout = new_layout,
1981 .dstQueueFamilyIndex = new_qf,
1982 .image = vkf->
img[
i],
1983 .subresourceRange = (VkImageSubresourceRange) {
1984 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1996 VkPipelineStageFlags stage,
1997 const char *extensions[],
int nb_extensions,
1998 int lg_x,
int lg_y,
int lg_z,
1999 uint32_t required_subgroup_size)
2009 switch (shd->
stage) {
2010 case VK_SHADER_STAGE_ANY_HIT_BIT_KHR:
2011 case VK_SHADER_STAGE_CALLABLE_BIT_KHR:
2012 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
2013 case VK_SHADER_STAGE_INTERSECTION_BIT_KHR:
2014 case VK_SHADER_STAGE_MISS_BIT_KHR:
2015 case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
2016 shd->
bind_point = VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR;
2018 case VK_SHADER_STAGE_COMPUTE_BIT:
2019 shd->
bind_point = VK_PIPELINE_BIND_POINT_COMPUTE;
2022 shd->
bind_point = VK_PIPELINE_BIND_POINT_GRAPHICS;
2026 if (required_subgroup_size) {
2027 shd->
subgroup_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO;
2028 shd->
subgroup_info.requiredSubgroupSize = required_subgroup_size;
2032 (stage == VK_SHADER_STAGE_TASK_BIT_EXT ||
2033 stage == VK_SHADER_STAGE_MESH_BIT_EXT) ?
2035 (shd->
bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) ?
2037 (shd->
bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) ?
2038 "Compute" :
"Graphics",
2044 GLSLC(0, #define IS_WITHIN(v1, v2) ((v1.x < v2.x) && (v1.y < v2.y)) );
2046 GLSLC(0, #extension GL_EXT_scalar_block_layout : require );
2047 GLSLC(0, #extension GL_EXT_shader_explicit_arithmetic_types : require );
2048 GLSLC(0, #extension GL_EXT_control_flow_attributes : require );
2051 GLSLC(0, #extension GL_EXT_debug_printf : require );
2055 if (stage == VK_SHADER_STAGE_TASK_BIT_EXT ||
2056 stage == VK_SHADER_STAGE_MESH_BIT_EXT)
2057 GLSLC(0, #extension GL_EXT_mesh_shader : require );
2059 for (
int i = 0;
i < nb_extensions;
i++)
2060 GLSLF(0, #extension %
s : %
s ,extensions[
i],
"require");
2063 GLSLF(0,
layout (local_size_x = %
i, local_size_y = %
i, local_size_z = %
i) in;
2073 const char *p = shd->
src.str;
2074 const char *start = p;
2075 const size_t len = strlen(p);
2080 for (
int i = 0;
i <
len;
i++) {
2096 VkPipelineLayoutCreateInfo pipeline_layout_info;
2099 pipeline_layout_info = (VkPipelineLayoutCreateInfo) {
2100 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
2107 ret = vk->CreatePipelineLayout(
s->hwctx->act_dev, &pipeline_layout_info,
2109 if (
ret != VK_SUCCESS) {
2119 VkShaderModule *
mod,
2120 uint8_t *spirv,
size_t spirv_len)
2125 VkShaderModuleCreateInfo shader_module_info = {
2126 .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
2129 .pCode = (
void *)spirv,
2130 .codeSize = spirv_len,
2133 ret = vk->CreateShaderModule(
s->hwctx->act_dev, &shader_module_info,
2134 s->hwctx->alloc,
mod);
2135 if (
ret != VK_SUCCESS) {
2145 VkShaderModule
mod,
const char *entrypoint)
2150 VkComputePipelineCreateInfo pipeline_create_info = {
2151 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
2153 VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT : 0x0,
2155 .stage = (VkPipelineShaderStageCreateInfo) {
2156 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
2159 .pName = entrypoint,
2161 VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT : 0x0,
2162 .stage = shd->
stage,
2167 ret = vk->CreateComputePipelines(
s->hwctx->act_dev, VK_NULL_HANDLE, 1,
2168 &pipeline_create_info,
2170 if (
ret != VK_SUCCESS) {
2180 uint8_t *spirv,
size_t spirv_len,
2181 const char *entrypoint)
2185 size_t shader_size = 0;
2187 VkShaderCreateInfoEXT shader_obj_create = {
2188 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT,
2190 VK_SHADER_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT : 0x0,
2191 .stage = shd->
stage,
2193 .codeType = VK_SHADER_CODE_TYPE_SPIRV_EXT,
2195 .codeSize = spirv_len,
2196 .pName = entrypoint,
2201 .pSpecializationInfo =
NULL,
2204 ret = vk->CreateShadersEXT(
s->hwctx->act_dev, 1, &shader_obj_create,
2205 s->hwctx->alloc, &shd->
object);
2206 if (
ret != VK_SUCCESS) {
2212 if (vk->GetShaderBinaryDataEXT(
s->hwctx->act_dev, shd->
object,
2213 &shader_size,
NULL) == VK_SUCCESS)
2215 shd->
name, shader_size, spirv_len);
2231 int has_singular = 0;
2245 VkDescriptorSetLayoutCreateInfo desc_layout_create = {
2246 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
2247 .bindingCount =
set->nb_bindings,
2248 .pBindings =
set->binding,
2250 VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT :
2252 VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR :
2256 ret = vk->CreateDescriptorSetLayout(
s->hwctx->act_dev,
2257 &desc_layout_create,
2260 if (
ret != VK_SUCCESS) {
2267 vk->GetDescriptorSetLayoutSizeEXT(
s->hwctx->act_dev, shd->
desc_layout[
i],
2271 s->desc_buf_props.descriptorBufferOffsetAlignment);
2273 for (
int j = 0; j <
set->nb_bindings; j++)
2274 vk->GetDescriptorSetLayoutBindingOffsetEXT(
s->hwctx->act_dev,
2277 &
set->binding_offset[j]);
2285 uint8_t *spirv,
size_t spirv_len,
2286 const char *entrypoint)
2320 case VK_PIPELINE_BIND_POINT_COMPUTE:
2330 vk->DestroyShaderModule(
s->hwctx->act_dev,
mod,
s->hwctx->alloc);
2346 [VK_DESCRIPTOR_TYPE_SAMPLER] = {
sizeof(VkDescriptorImageInfo),
"sampler", 1, 0, 0, 0, },
2347 [VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE] = {
sizeof(VkDescriptorImageInfo),
"texture", 1, 0, 1, 0, },
2348 [VK_DESCRIPTOR_TYPE_STORAGE_IMAGE] = {
sizeof(VkDescriptorImageInfo),
"image", 1, 1, 1, 0, },
2349 [VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT] = {
sizeof(VkDescriptorImageInfo),
"subpassInput", 1, 0, 0, 0, },
2350 [VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER] = {
sizeof(VkDescriptorImageInfo),
"sampler", 1, 0, 1, 0, },
2351 [VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER] = {
sizeof(VkDescriptorBufferInfo),
NULL, 1, 0, 0, 1, },
2352 [VK_DESCRIPTOR_TYPE_STORAGE_BUFFER] = {
sizeof(VkDescriptorBufferInfo),
"buffer", 0, 1, 0, 1, },
2353 [VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] = {
sizeof(VkDescriptorBufferInfo),
NULL, 1, 0, 0, 1, },
2354 [VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] = {
sizeof(VkDescriptorBufferInfo),
"buffer", 0, 1, 0, 1, },
2355 [VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER] = {
sizeof(VkBufferView),
"samplerBuffer", 1, 0, 0, 0, },
2356 [VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER] = {
sizeof(VkBufferView),
"imageBuffer", 1, 0, 0, 0, },
2361 int singular,
int print_to_shader_only)
2363 int has_sampler = 0;
2366 if (print_to_shader_only)
2378 memset(
set, 0,
sizeof(*
set));
2385 if (!
set->binding_offset) {
2390 for (
int i = 0;
i < nb;
i++) {
2391 set->binding[
i].binding =
i;
2392 set->binding[
i].descriptorType =
desc[
i].type;
2394 set->binding[
i].stageFlags =
desc[
i].stages;
2395 set->binding[
i].pImmutableSamplers =
desc[
i].samplers;
2397 if (
desc[
i].
type == VK_DESCRIPTOR_TYPE_SAMPLER ||
2398 desc[
i].
type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
2402 set->usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT |
2403 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
2405 set->usage |= VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT;
2408 for (
int i = 0;
i < nb;
i++) {
2410 VkDescriptorPoolSize *desc_pool_size;
2416 sizeof(*desc_pool_size),
2418 if (!desc_pool_size)
2423 memset(&desc_pool_size[j], 0,
sizeof(VkDescriptorPoolSize));
2430 set->singular = singular;
2431 set->nb_bindings = nb;
2436 for (
int i = 0;
i < nb;
i++) {
2440 if (
desc[
i].mem_layout)
2452 if (
desc[
i].
type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
2453 if (
desc[
i].mem_layout) {
2454 int len = strlen(
desc[
i].mem_layout);
2455 if (
desc[
i].mem_layout[
len - 1] ==
'i' &&
2456 desc[
i].mem_layout[
len - 2] ==
'u') {
2458 }
else if (
desc[
i].mem_layout[
len - 1] ==
'i') {
2473 if (
desc[
i].buf_elems) {
2480 }
else if (
desc[
i].elems > 0) {
2509 memset(sd, 0,
sizeof(*sd));
2529 set->aligned_size*nb,
2531 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2532 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
2533 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
2541 sd->
desc_bind[
i] = (VkDescriptorBufferBindingInfoEXT) {
2542 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT,
2543 .usage =
set->usage,
2550 VkDescriptorSetLayout *tmp_layouts;
2551 VkDescriptorSetAllocateInfo set_alloc_info;
2552 VkDescriptorPoolCreateInfo pool_create_info;
2557 pool_create_info = (VkDescriptorPoolCreateInfo) {
2558 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
2565 ret = vk->CreateDescriptorPool(
s->hwctx->act_dev, &pool_create_info,
2567 if (
ret != VK_SUCCESS) {
2573 tmp_layouts =
av_malloc_array(pool_create_info.maxSets,
sizeof(*tmp_layouts));
2582 set_alloc_info = (VkDescriptorSetAllocateInfo) {
2583 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
2585 .pSetLayouts = tmp_layouts,
2586 .descriptorSetCount = pool_create_info.maxSets,
2590 sizeof(*tmp_layouts));
2595 ret = vk->AllocateDescriptorSets(
s->hwctx->act_dev, &set_alloc_info,
2598 if (
ret != VK_SUCCESS) {
2620 int bind_idx,
int array_idx,
2621 VkDescriptorGetInfoEXT *desc_get_info,
2632 array_idx*desc_size;
2634 vk->GetDescriptorEXT(
s->hwctx->act_dev, desc_get_info, desc_size,
desc);
2639 VkWriteDescriptorSet *write_info)
2648 vk->UpdateDescriptorSets(
s->hwctx->act_dev, 1, write_info, 0,
NULL);
2652 vk->CmdPushDescriptorSetKHR(e->
buf,
2659 vk->UpdateDescriptorSets(
s->hwctx->act_dev, 1, write_info, 0,
NULL);
2666 VkImageView view, VkImageLayout
layout,
2672 VkDescriptorGetInfoEXT desc_get_info = {
2673 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT,
2674 .type = desc_set->
binding[bind].descriptorType,
2676 VkDescriptorImageInfo desc_img_info = {
2683 switch (desc_get_info.type) {
2684 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2685 desc_get_info.
data.pSampledImage = &desc_img_info;
2686 desc_size =
s->desc_buf_props.sampledImageDescriptorSize;
2688 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2689 desc_get_info.data.pStorageImage = &desc_img_info;
2690 desc_size =
s->desc_buf_props.storageImageDescriptorSize;
2692 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
2693 desc_get_info.data.pInputAttachmentImage = &desc_img_info;
2694 desc_size =
s->desc_buf_props.inputAttachmentDescriptorSize;
2696 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2697 desc_get_info.data.pCombinedImageSampler = &desc_img_info;
2698 desc_size =
s->desc_buf_props.combinedImageSamplerDescriptorSize;
2702 set, bind, desc_get_info.type);
2708 &desc_get_info, desc_size);
2710 VkDescriptorImageInfo desc_pool_write_info_img = {
2715 VkWriteDescriptorSet desc_pool_write_info = {
2716 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2718 .descriptorCount = 1,
2719 .dstArrayElement = offs,
2720 .descriptorType = desc_set->
binding[bind].descriptorType,
2721 .pImageInfo = &desc_pool_write_info_img,
2731 VkImageView *views,
int set,
int binding,
2732 VkImageLayout
layout, VkSampler sampler)
2737 for (
int i = 0;
i < nb_planes;
i++)
2744 int set,
int bind,
int elem,
2751 VkDescriptorGetInfoEXT desc_get_info = {
2752 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT,
2753 .type = desc_set->
binding[bind].descriptorType,
2755 VkDescriptorAddressInfoEXT desc_buf_info = {
2756 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT,
2763 switch (desc_get_info.type) {
2764 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2765 desc_get_info.data.pUniformBuffer = &desc_buf_info;
2766 desc_size =
s->desc_buf_props.uniformBufferDescriptorSize;
2768 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2769 desc_get_info.data.pStorageBuffer = &desc_buf_info;
2770 desc_size =
s->desc_buf_props.storageBufferDescriptorSize;
2772 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2773 desc_get_info.data.pUniformTexelBuffer = &desc_buf_info;
2774 desc_size =
s->desc_buf_props.uniformTexelBufferDescriptorSize;
2776 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2777 desc_get_info.data.pStorageTexelBuffer = &desc_buf_info;
2778 desc_size =
s->desc_buf_props.storageTexelBufferDescriptorSize;
2782 set, bind, desc_get_info.type);
2789 VkDescriptorBufferInfo desc_pool_write_info_buf = {
2794 VkWriteDescriptorSet desc_pool_write_info = {
2795 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2797 .descriptorCount = 1,
2798 .dstArrayElement = elem,
2799 .descriptorType = desc_set->
binding[bind].descriptorType,
2800 .pBufferInfo = &desc_pool_write_info_buf,
2810 VkShaderStageFlagBits stage,
2826 VkShaderStageFlagBits stages = shd->
stage;
2827 vk->CmdBindShadersEXT(e->
buf, 1, &stages, &shd->
object);
2859 if (shd->shader.module)
2860 vk->DestroyShaderModule(
s->hwctx->act_dev, shd->shader.module,
2865 vk->DestroyShaderEXT(
s->hwctx->act_dev, shd->
object,
s->hwctx->alloc);
2867 vk->DestroyPipeline(
s->hwctx->act_dev, shd->
pipeline,
s->hwctx->alloc);
2881 vk->DestroyDescriptorSetLayout(
s->hwctx->act_dev, shd->
desc_layout[
i],
2909 static const AVClass vulkan_context_class = {
2915 memset(
s, 0,
sizeof(*
s));
2916 s->log_parent = log_parent;
2917 s->class = &vulkan_context_class;
2925 s->hwfc =
s->frames->hwctx;
2927 device_ref =
s->frames->device_ref;
2931 if (!
s->device_ref) {
2937 s->hwctx =
s->device->hwctx;
2940 s->hwctx->nb_enabled_dev_extensions);
2942 s->hwctx->nb_enabled_inst_extensions);