30 #include <drm_fourcc.h>
33 #include <va/va_drmcommon.h>
41 #define CHECK_CU(x) FF_CUDA_CHECK_DL(cuda_cu, cu, x)
65 VkPhysicalDeviceProperties2
props;
66 VkPhysicalDeviceMemoryProperties
mprops;
67 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
hprops;
107 #define GET_QUEUE_COUNT(hwctx, graph, comp, tx) ( \
108 graph ? hwctx->nb_graphics_queues : \
109 comp ? (hwctx->nb_comp_queues ? \
110 hwctx->nb_comp_queues : hwctx->nb_graphics_queues) : \
111 tx ? (hwctx->nb_tx_queues ? hwctx->nb_tx_queues : \
112 (hwctx->nb_comp_queues ? \
113 hwctx->nb_comp_queues : hwctx->nb_graphics_queues)) : \
117 #define VK_LOAD_PFN(inst, name) PFN_##name pfn_##name = (PFN_##name) \
118 vkGetInstanceProcAddr(inst, #name)
120 #define DEFAULT_USAGE_FLAGS (VK_IMAGE_USAGE_SAMPLED_BIT | \
121 VK_IMAGE_USAGE_STORAGE_BIT | \
122 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | \
123 VK_IMAGE_USAGE_TRANSFER_DST_BIT)
125 #define ADD_VAL_TO_LIST(list, count, val) \
127 list = av_realloc_array(list, sizeof(*list), ++count); \
129 err = AVERROR(ENOMEM); \
132 list[count - 1] = av_strdup(val); \
133 if (!list[count - 1]) { \
134 err = AVERROR(ENOMEM); \
139 static const struct {
157 {
AV_PIX_FMT_YUV420P, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
162 {
AV_PIX_FMT_YUV422P, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
167 {
AV_PIX_FMT_YUV444P, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
172 {
AV_PIX_FMT_YUVA420P, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
173 {
AV_PIX_FMT_YUVA420P10, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
175 {
AV_PIX_FMT_YUVA420P16, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
177 {
AV_PIX_FMT_YUVA422P, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
178 {
AV_PIX_FMT_YUVA422P10, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
179 {
AV_PIX_FMT_YUVA422P12, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
180 {
AV_PIX_FMT_YUVA422P16, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
182 {
AV_PIX_FMT_YUVA444P, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
183 {
AV_PIX_FMT_YUVA444P10, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
184 {
AV_PIX_FMT_YUVA444P12, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
185 {
AV_PIX_FMT_YUVA444P16, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
206 {
AV_PIX_FMT_GBRAP, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM } },
207 {
AV_PIX_FMT_GBRAP16, { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM } },
208 {
AV_PIX_FMT_GBRPF32, { VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT } },
209 {
AV_PIX_FMT_GBRAPF32, { VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT } },
230 VkFormatFeatureFlags
flags;
231 VkFormatProperties2 prop = {
232 .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
234 vkGetPhysicalDeviceFormatProperties2(hwctx->
phys_dev, fmt[
i], &prop);
235 flags =
linear ? prop.formatProperties.linearTilingFeatures :
236 prop.formatProperties.optimalTilingFeatures;
278 #define CASE(VAL) case VAL: return #VAL
284 CASE(VK_EVENT_RESET);
286 CASE(VK_ERROR_OUT_OF_HOST_MEMORY);
287 CASE(VK_ERROR_OUT_OF_DEVICE_MEMORY);
288 CASE(VK_ERROR_INITIALIZATION_FAILED);
289 CASE(VK_ERROR_DEVICE_LOST);
290 CASE(VK_ERROR_MEMORY_MAP_FAILED);
291 CASE(VK_ERROR_LAYER_NOT_PRESENT);
292 CASE(VK_ERROR_EXTENSION_NOT_PRESENT);
293 CASE(VK_ERROR_FEATURE_NOT_PRESENT);
294 CASE(VK_ERROR_INCOMPATIBLE_DRIVER);
295 CASE(VK_ERROR_TOO_MANY_OBJECTS);
296 CASE(VK_ERROR_FORMAT_NOT_SUPPORTED);
297 CASE(VK_ERROR_FRAGMENTED_POOL);
298 CASE(VK_ERROR_SURFACE_LOST_KHR);
299 CASE(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
300 CASE(VK_SUBOPTIMAL_KHR);
301 CASE(VK_ERROR_OUT_OF_DATE_KHR);
302 CASE(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR);
303 CASE(VK_ERROR_VALIDATION_FAILED_EXT);
304 CASE(VK_ERROR_INVALID_SHADER_NV);
305 CASE(VK_ERROR_OUT_OF_POOL_MEMORY);
306 CASE(VK_ERROR_INVALID_EXTERNAL_HANDLE);
307 CASE(VK_ERROR_NOT_PERMITTED_EXT);
308 CASE(VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT);
309 CASE(VK_ERROR_INVALID_DEVICE_ADDRESS_EXT);
310 CASE(VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT);
311 default:
return "Unknown error";
316 static VkBool32 VKAPI_CALL
vk_dbg_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
317 VkDebugUtilsMessageTypeFlagsEXT messageType,
318 const VkDebugUtilsMessengerCallbackDataEXT *
data,
325 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: l =
AV_LOG_VERBOSE;
break;
326 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: l =
AV_LOG_INFO;
break;
327 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: l =
AV_LOG_WARNING;
break;
328 case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: l =
AV_LOG_ERROR;
break;
333 for (
int i = 0;
i <
data->cmdBufLabelCount;
i++)
340 const char *
const **dst, uint32_t *num,
int debug)
343 const char **extension_names =
NULL;
346 int err = 0, found, extensions_found = 0;
349 int optional_exts_num;
350 uint32_t sup_ext_count;
351 char *user_exts_str =
NULL;
353 VkExtensionProperties *sup_ext;
363 if (!user_exts_str) {
368 vkEnumerateInstanceExtensionProperties(
NULL, &sup_ext_count,
NULL);
369 sup_ext =
av_malloc_array(sup_ext_count,
sizeof(VkExtensionProperties));
372 vkEnumerateInstanceExtensionProperties(
NULL, &sup_ext_count, sup_ext);
380 if (!user_exts_str) {
385 vkEnumerateDeviceExtensionProperties(hwctx->
phys_dev,
NULL,
386 &sup_ext_count,
NULL);
387 sup_ext =
av_malloc_array(sup_ext_count,
sizeof(VkExtensionProperties));
390 vkEnumerateDeviceExtensionProperties(hwctx->
phys_dev,
NULL,
391 &sup_ext_count, sup_ext);
394 for (
int i = 0;
i < optional_exts_num;
i++) {
395 tstr = optional_exts[
i].
name;
397 for (
int j = 0; j < sup_ext_count; j++) {
398 if (!strcmp(tstr, sup_ext[j].extensionName)) {
412 tstr = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
414 for (
int j = 0; j < sup_ext_count; j++) {
415 if (!strcmp(tstr, sup_ext[j].extensionName)) {
432 char *save, *token =
av_strtok(user_exts_str,
"+", &save);
435 for (
int j = 0; j < sup_ext_count; j++) {
436 if (!strcmp(token, sup_ext[j].extensionName)) {
452 *dst = extension_names;
453 *num = extensions_found;
461 for (
int i = 0;
i < extensions_found;
i++)
462 av_free((
void *)extension_names[
i]);
477 const int debug_mode = debug_opt && strtol(debug_opt->
value,
NULL, 10);
478 VkApplicationInfo application_info = {
479 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
480 .pEngineName =
"libavutil",
481 .apiVersion = VK_API_VERSION_1_1,
486 VkInstanceCreateInfo inst_props = {
487 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
488 .pApplicationInfo = &application_info,
493 &inst_props.enabledExtensionCount, debug_mode);
498 static const char *layers[] = {
"VK_LAYER_KHRONOS_validation" };
499 inst_props.ppEnabledLayerNames = layers;
504 ret = vkCreateInstance(&inst_props, hwctx->
alloc, &hwctx->
inst);
507 if (ret != VK_SUCCESS) {
510 for (
int i = 0;
i < inst_props.enabledExtensionCount;
i++)
511 av_free((
void *)inst_props.ppEnabledExtensionNames[
i]);
512 av_free((
void *)inst_props.ppEnabledExtensionNames);
517 VkDebugUtilsMessengerCreateInfoEXT dbg = {
518 .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
519 .messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
520 VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
521 VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
522 VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
523 .messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
524 VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
525 VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
531 pfn_vkCreateDebugUtilsMessengerEXT(hwctx->
inst, &dbg,
553 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
return "integrated";
554 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
return "discrete";
555 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
return "virtual";
556 case VK_PHYSICAL_DEVICE_TYPE_CPU:
return "software";
557 default:
return "unknown";
564 int err = 0, choice = -1;
567 VkPhysicalDevice *devices =
NULL;
568 VkPhysicalDeviceIDProperties *idp =
NULL;
569 VkPhysicalDeviceProperties2 *prop =
NULL;
572 ret = vkEnumeratePhysicalDevices(hwctx->
inst, &num,
NULL);
573 if (ret != VK_SUCCESS || !num) {
582 ret = vkEnumeratePhysicalDevices(hwctx->
inst, &num, devices);
583 if (ret != VK_SUCCESS) {
603 for (
int i = 0;
i < num;
i++) {
604 idp[
i].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
605 prop[
i].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
606 prop[
i].pNext = &idp[
i];
608 vkGetPhysicalDeviceProperties2(devices[
i], &prop[
i]);
610 prop[
i].properties.deviceName,
612 prop[
i].properties.deviceID);
616 for (
int i = 0;
i < num;
i++) {
617 if (!strncmp(idp[
i].deviceUUID, select->
uuid, VK_UUID_SIZE)) {
625 }
else if (select->
name) {
627 for (
int i = 0;
i < num;
i++) {
628 if (strstr(prop[
i].properties.deviceName, select->
name)) {
639 for (
int i = 0;
i < num;
i++) {
640 if (select->
pci_device == prop[
i].properties.deviceID) {
651 for (
int i = 0;
i < num;
i++) {
652 if (select->
vendor_id == prop[
i].properties.vendorID) {
662 if (select->
index < num) {
663 choice = select->
index;
687 VkQueueFamilyProperties *qs =
NULL;
689 int graph_index = -1, comp_index = -1, tx_index = -1;
690 VkDeviceQueueCreateInfo *pc = (VkDeviceQueueCreateInfo *)cd->pQueueCreateInfos;
693 vkGetPhysicalDeviceQueueFamilyProperties(hwctx->
phys_dev, &num,
NULL);
705 vkGetPhysicalDeviceQueueFamilyProperties(hwctx->
phys_dev, &num, qs);
707 #define SEARCH_FLAGS(expr, out) \
708 for (int i = 0; i < num; i++) { \
709 const VkQueueFlagBits flags = qs[i].queueFlags; \
722 (
i != comp_index), tx_index)
725 #define ADD_QUEUE(fidx, graph, comp, tx) \
726 av_log(ctx, AV_LOG_VERBOSE, "Using queue family %i (total queues: %i) for %s%s%s\n", \
727 fidx, qs[fidx].queueCount, graph ? "graphics " : "", \
728 comp ? "compute " : "", tx ? "transfers " : ""); \
729 av_log(ctx, AV_LOG_VERBOSE, " QF %i flags: %s%s%s%s\n", fidx, \
730 ((qs[fidx].queueFlags) & VK_QUEUE_GRAPHICS_BIT) ? "(graphics) " : "", \
731 ((qs[fidx].queueFlags) & VK_QUEUE_COMPUTE_BIT) ? "(compute) " : "", \
732 ((qs[fidx].queueFlags) & VK_QUEUE_TRANSFER_BIT) ? "(transfers) " : "", \
733 ((qs[fidx].queueFlags) & VK_QUEUE_SPARSE_BINDING_BIT) ? "(sparse) " : ""); \
734 pc[cd->queueCreateInfoCount].queueFamilyIndex = fidx; \
735 pc[cd->queueCreateInfoCount].queueCount = qs[fidx].queueCount; \
736 weights = av_malloc(qs[fidx].queueCount * sizeof(float)); \
737 pc[cd->queueCreateInfoCount].pQueuePriorities = weights; \
740 for (int i = 0; i < qs[fidx].queueCount; i++) \
742 cd->queueCreateInfoCount++;
744 ADD_QUEUE(graph_index, 1, comp_index < 0, tx_index < 0 && comp_index < 0)
750 if (comp_index != -1) {
751 ADD_QUEUE(comp_index, 0, 1, tx_index < 0)
757 if (tx_index != -1) {
778 int queue_family_index,
int num_queues)
784 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
785 .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
786 .queueFamilyIndex = queue_family_index,
788 VkCommandBufferAllocateInfo cbuf_create = {
789 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
790 .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
791 .commandBufferCount = num_queues,
799 if (ret != VK_SUCCESS) {
809 cbuf_create.commandPool = cmd->
pool;
812 ret = vkAllocateCommandBuffers(hwctx->
act_dev, &cbuf_create, cmd->
bufs);
813 if (ret != VK_SUCCESS) {
824 for (
int i = 0;
i < num_queues;
i++) {
826 vkGetDeviceQueue(hwctx->
act_dev, queue_family_index,
i, &q->
queue);
843 vkWaitForFences(hwctx->
act_dev, 1, &q->
fence, VK_TRUE, UINT64_MAX);
888 VkCommandBufferBeginInfo cmd_start = {
889 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
890 .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
895 VkFenceCreateInfo fence_spawn = {
896 .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
898 ret = vkCreateFence(hwctx->
act_dev, &fence_spawn, hwctx->
alloc,
900 if (ret != VK_SUCCESS) {
906 vkWaitForFences(hwctx->
act_dev, 1, &q->
fence, VK_TRUE, UINT64_MAX);
914 if (ret != VK_SUCCESS) {
929 if (!deps || !nb_deps)
939 for (
int i = 0;
i < nb_deps;
i++) {
954 VkSubmitInfo *s_info,
int synchronous)
960 if (ret != VK_SUCCESS) {
968 s_info->commandBufferCount = 1;
970 ret = vkQueueSubmit(q->
queue, 1, s_info, q->
fence);
971 if (ret != VK_SUCCESS) {
980 vkWaitForFences(hwctx->
act_dev, 1, &q->
fence, VK_TRUE, UINT64_MAX);
999 pfn_vkDestroyDebugUtilsMessengerEXT(hwctx->
inst, p->
debug_ctx,
1003 vkDestroyInstance(hwctx->
inst, hwctx->
alloc);
1023 VkPhysicalDeviceFeatures dev_features = { 0 };
1024 VkDeviceQueueCreateInfo queue_create_info[3] = {
1025 { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, },
1026 { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, },
1027 { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, },
1030 VkDeviceCreateInfo dev_info = {
1031 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
1033 .pQueueCreateInfos = queue_create_info,
1034 .queueCreateInfoCount = 0,
1037 hwctx->
device_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1048 vkGetPhysicalDeviceFeatures(hwctx->
phys_dev, &dev_features);
1049 #define COPY_FEATURE(DST, NAME) (DST).features.NAME = dev_features.NAME;
1063 &dev_info.enabledExtensionCount, 0))) {
1064 av_free((
void *)queue_create_info[0].pQueuePriorities);
1065 av_free((
void *)queue_create_info[1].pQueuePriorities);
1066 av_free((
void *)queue_create_info[2].pQueuePriorities);
1070 ret = vkCreateDevice(hwctx->
phys_dev, &dev_info, hwctx->
alloc,
1073 av_free((
void *)queue_create_info[0].pQueuePriorities);
1074 av_free((
void *)queue_create_info[1].pQueuePriorities);
1075 av_free((
void *)queue_create_info[2].pQueuePriorities);
1077 if (ret != VK_SUCCESS) {
1080 for (
int i = 0;
i < dev_info.enabledExtensionCount;
i++)
1081 av_free((
void *)dev_info.ppEnabledExtensionNames[
i]);
1082 av_free((
void *)dev_info.ppEnabledExtensionNames);
1118 p->
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
1120 p->
hprops.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT;
1124 p->
props.properties.deviceName);
1127 p->
props.properties.limits.optimalBufferCopyRowPitchAlignment);
1129 p->
props.properties.limits.minMemoryMapAlignment);
1132 p->
hprops.minImportedHostPointerAlignment);
1136 vkGetPhysicalDeviceQueueFamilyProperties(hwctx->
phys_dev, &queue_num,
NULL);
1142 #define CHECK_QUEUE(type, n) \
1143 if (n >= queue_num) { \
1144 av_log(ctx, AV_LOG_ERROR, "Invalid %s queue index %i (device has %i queues)!\n", \
1145 type, n, queue_num); \
1146 return AVERROR(EINVAL); \
1164 vkGetPhysicalDeviceMemoryProperties(hwctx->
phys_dev, &p->
mprops);
1173 if (device && device[0]) {
1175 dev_select.
index = strtol(device, &end, 10);
1176 if (end == device) {
1177 dev_select.
index = 0;
1178 dev_select.
name = device;
1194 switch(src_ctx->
type) {
1200 const char *vendor = vaQueryVendorString(src_hwctx->
display);
1206 if (strstr(vendor,
"Intel"))
1207 dev_select.vendor_id = 0x8086;
1208 if (strstr(vendor,
"AMD"))
1209 dev_select.vendor_id = 0x1002;
1217 drmDevice *drm_dev_info;
1218 int err = drmGetDevice(src_hwctx->
fd, &drm_dev_info);
1224 if (drm_dev_info->bustype == DRM_BUS_PCI)
1225 dev_select.pci_device = drm_dev_info->deviceinfo.pci->device_id;
1227 drmFreeDevice(&drm_dev_info);
1237 CudaFunctions *cu = cu_internal->
cuda_dl;
1239 int ret =
CHECK_CU(cu->cuDeviceGetUuid((CUuuid *)&dev_select.uuid,
1246 dev_select.has_uuid = 1;
1257 const void *hwconfig,
1290 constraints->
max_width = p->
props.properties.limits.maxImageDimension2D;
1291 constraints->
max_height = p->
props.properties.limits.maxImageDimension2D;
1304 VkMemoryPropertyFlagBits req_flags,
const void *alloc_extension,
1305 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
1311 VkMemoryAllocateInfo alloc_info = {
1312 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
1313 .pNext = alloc_extension,
1314 .allocationSize = req->size,
1319 for (
int i = 0;
i < p->
mprops.memoryTypeCount;
i++) {
1320 const VkMemoryType *
type = &p->
mprops.memoryTypes[
i];
1323 if (!(req->memoryTypeBits & (1 <<
i)))
1327 if ((
type->propertyFlags & req_flags) != req_flags)
1331 if (req->size > p->
mprops.memoryHeaps[
type->heapIndex].size)
1345 alloc_info.memoryTypeIndex =
index;
1347 ret = vkAllocateMemory(dev_hwctx->
act_dev, &alloc_info,
1348 dev_hwctx->
alloc, mem);
1349 if (ret != VK_SUCCESS) {
1355 *mem_flags |= p->
mprops.memoryTypes[
index].propertyFlags;
1366 if (internal->cuda_fc_ref) {
1372 CudaFunctions *cu = cu_internal->
cuda_dl;
1375 if (internal->cu_sem[
i])
1376 CHECK_CU(cu->cuDestroyExternalSemaphore(internal->cu_sem[
i]));
1377 if (internal->cu_mma[
i])
1378 CHECK_CU(cu->cuMipmappedArrayDestroy(internal->cu_mma[
i]));
1379 if (internal->ext_mem[
i])
1380 CHECK_CU(cu->cuDestroyExternalMemory(internal->ext_mem[
i]));
1409 void *alloc_pnext,
size_t alloc_pnext_stride)
1422 VkImageMemoryRequirementsInfo2 req_desc = {
1423 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
1426 VkMemoryDedicatedAllocateInfo ded_alloc = {
1427 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
1428 .pNext = (
void *)(((
uint8_t *)alloc_pnext) +
i*alloc_pnext_stride),
1430 VkMemoryDedicatedRequirements ded_req = {
1431 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
1433 VkMemoryRequirements2 req = {
1434 .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
1438 vkGetImageMemoryRequirements2(hwctx->
act_dev, &req_desc, &req);
1440 if (
f->tiling == VK_IMAGE_TILING_LINEAR)
1441 req.memoryRequirements.size =
FFALIGN(req.memoryRequirements.size,
1442 p->
props.properties.limits.minMemoryMapAlignment);
1445 use_ded_mem = ded_req.prefersDedicatedAllocation |
1446 ded_req.requiresDedicatedAllocation;
1448 ded_alloc.image =
f->img[
i];
1452 f->tiling == VK_IMAGE_TILING_LINEAR ?
1453 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT :
1454 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
1455 use_ded_mem ? &ded_alloc : (
void *)ded_alloc.pNext,
1456 &
f->flags, &
f->mem[
i])))
1459 f->size[
i] = req.memoryRequirements.size;
1460 bind_info[
i].sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
1461 bind_info[
i].image =
f->img[
i];
1462 bind_info[
i].memory =
f->mem[
i];
1466 ret = vkBindImageMemory2(hwctx->
act_dev,
planes, bind_info);
1467 if (ret != VK_SUCCESS) {
1487 VkImageLayout new_layout;
1488 VkAccessFlags new_access;
1493 VkSubmitInfo s_info = {
1494 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
1495 .pSignalSemaphores =
frame->sem,
1496 .signalSemaphoreCount =
planes,
1501 wait_st[
i] = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1505 new_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
1506 new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
1507 dst_qf = VK_QUEUE_FAMILY_IGNORED;
1510 new_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1511 new_access = VK_ACCESS_TRANSFER_READ_BIT;
1512 dst_qf = VK_QUEUE_FAMILY_IGNORED;
1515 new_layout = VK_IMAGE_LAYOUT_GENERAL;
1516 new_access = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
1517 dst_qf = VK_QUEUE_FAMILY_EXTERNAL_KHR;
1518 s_info.pWaitSemaphores =
frame->sem;
1519 s_info.pWaitDstStageMask = wait_st;
1520 s_info.waitSemaphoreCount =
planes;
1531 img_bar[
i].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
1532 img_bar[
i].srcAccessMask = 0x0;
1533 img_bar[
i].dstAccessMask = new_access;
1534 img_bar[
i].oldLayout =
frame->layout[
i];
1535 img_bar[
i].newLayout = new_layout;
1536 img_bar[
i].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1537 img_bar[
i].dstQueueFamilyIndex = dst_qf;
1538 img_bar[
i].image =
frame->img[
i];
1539 img_bar[
i].subresourceRange.levelCount = 1;
1540 img_bar[
i].subresourceRange.layerCount = 1;
1541 img_bar[
i].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1543 frame->layout[
i] = img_bar[
i].newLayout;
1544 frame->access[
i] = img_bar[
i].dstAccessMask;
1548 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1549 VK_PIPELINE_STAGE_TRANSFER_BIT,
1556 int frame_w,
int frame_h,
int plane)
1573 VkImageTiling tiling, VkImageUsageFlagBits
usage,
1585 VkExportSemaphoreCreateInfo ext_sem_info = {
1586 .sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO,
1587 .handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
1590 VkSemaphoreCreateInfo sem_spawn = {
1591 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
1603 VkImageCreateInfo create_info = {
1604 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1605 .pNext = create_pnext,
1606 .imageType = VK_IMAGE_TYPE_2D,
1607 .format = img_fmts[
i],
1611 .flags = VK_IMAGE_CREATE_ALIAS_BIT,
1613 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1615 .samples = VK_SAMPLE_COUNT_1_BIT,
1616 .pQueueFamilyIndices = p->
qfs,
1617 .queueFamilyIndexCount = p->
num_qfs,
1618 .sharingMode = p->
num_qfs > 1 ? VK_SHARING_MODE_CONCURRENT :
1619 VK_SHARING_MODE_EXCLUSIVE,
1622 get_plane_wh(&create_info.extent.width, &create_info.extent.height,
1625 ret = vkCreateImage(hwctx->
act_dev, &create_info,
1627 if (ret != VK_SUCCESS) {
1635 ret = vkCreateSemaphore(hwctx->
act_dev, &sem_spawn,
1637 if (ret != VK_SUCCESS) {
1643 f->layout[
i] = create_info.initialLayout;
1660 VkExternalMemoryHandleTypeFlags *comp_handle_types,
1661 VkExternalMemoryHandleTypeFlagBits *iexp,
1662 VkExternalMemoryHandleTypeFlagBits
exp)
1667 VkExternalImageFormatProperties eprops = {
1668 .sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR,
1670 VkImageFormatProperties2 props = {
1671 .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
1674 VkPhysicalDeviceExternalImageFormatInfo enext = {
1675 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO,
1678 VkPhysicalDeviceImageFormatInfo2 pinfo = {
1679 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
1680 .pNext = !
exp ?
NULL : &enext,
1682 .type = VK_IMAGE_TYPE_2D,
1684 .usage = hwctx->
usage,
1685 .flags = VK_IMAGE_CREATE_ALIAS_BIT,
1688 ret = vkGetPhysicalDeviceImageFormatProperties2(dev_hwctx->
phys_dev,
1690 if (ret == VK_SUCCESS) {
1692 *comp_handle_types |= eprops.externalMemoryProperties.compatibleHandleTypes;
1706 VkExternalMemoryHandleTypeFlags e = 0x0;
1708 VkExternalMemoryImageCreateInfo eiinfo = {
1709 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
1715 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT);
1719 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
1722 eminfo[
i].sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO;
1724 eminfo[
i].handleTypes = e;
1728 eiinfo.handleTypes ? &eiinfo :
NULL);
1772 VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
1857 !(
map->frame->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
1862 flush_ranges[
i].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
1863 flush_ranges[
i].memory =
map->frame->mem[
i];
1864 flush_ranges[
i].size = VK_WHOLE_SIZE;
1869 if (ret != VK_SUCCESS) {
1876 vkUnmapMemory(hwctx->
act_dev,
map->frame->mem[
i]);
1885 int err, mapped_mem_count = 0;
1901 if (!(
f->flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ||
1902 !(
f->tiling == VK_IMAGE_TILING_LINEAR)) {
1913 ret = vkMapMemory(hwctx->act_dev,
f->mem[
i], 0,
1914 VK_WHOLE_SIZE, 0, (
void **)&dst->
data[
i]);
1915 if (ret != VK_SUCCESS) {
1926 !(
f->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
1929 map_mem_ranges[
i].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
1930 map_mem_ranges[
i].size = VK_WHOLE_SIZE;
1931 map_mem_ranges[
i].memory =
f->mem[
i];
1934 ret = vkInvalidateMappedMemoryRanges(hwctx->act_dev,
planes,
1936 if (ret != VK_SUCCESS) {
1945 VkImageSubresource
sub = {
1946 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1948 VkSubresourceLayout
layout;
1949 vkGetImageSubresourceLayout(hwctx->act_dev,
f->img[
i], &
sub, &
layout);
1964 for (
int i = 0;
i < mapped_mem_count;
i++)
1965 vkUnmapMemory(hwctx->act_dev,
f->mem[
i]);
1988 static const struct {
1989 uint32_t drm_fourcc;
1991 } vulkan_drm_format_map[] = {
1992 { DRM_FORMAT_R8, VK_FORMAT_R8_UNORM },
1993 { DRM_FORMAT_R16, VK_FORMAT_R16_UNORM },
1994 { DRM_FORMAT_GR88, VK_FORMAT_R8G8_UNORM },
1995 { DRM_FORMAT_RG88, VK_FORMAT_R8G8_UNORM },
1996 { DRM_FORMAT_GR1616, VK_FORMAT_R16G16_UNORM },
1997 { DRM_FORMAT_RG1616, VK_FORMAT_R16G16_UNORM },
1998 { DRM_FORMAT_ARGB8888, VK_FORMAT_B8G8R8A8_UNORM },
1999 { DRM_FORMAT_XRGB8888, VK_FORMAT_B8G8R8A8_UNORM },
2000 { DRM_FORMAT_ABGR8888, VK_FORMAT_R8G8B8A8_UNORM },
2001 { DRM_FORMAT_XBGR8888, VK_FORMAT_R8G8B8A8_UNORM },
2004 static inline VkFormat drm_to_vulkan_fmt(uint32_t drm_fourcc)
2007 if (vulkan_drm_format_map[
i].drm_fourcc == drm_fourcc)
2008 return vulkan_drm_format_map[
i].vk_format;
2009 return VK_FORMAT_UNDEFINED;
2018 int bind_counts = 0;
2029 VkExternalMemoryHandleTypeFlagBits
htype = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
2033 for (
int i = 0;
i <
desc->nb_layers;
i++) {
2034 if (drm_to_vulkan_fmt(
desc->layers[
i].format) == VK_FORMAT_UNDEFINED) {
2036 desc->layers[
i].format);
2047 f->tiling = has_modifiers ? VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT :
2048 desc->objects[0].format_modifier == DRM_FORMAT_MOD_LINEAR ?
2049 VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
2051 for (
int i = 0;
i <
desc->nb_layers;
i++) {
2053 VkImageDrmFormatModifierExplicitCreateInfoEXT drm_info = {
2054 .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT,
2055 .drmFormatModifier =
desc->objects[0].format_modifier,
2056 .drmFormatModifierPlaneCount =
planes,
2057 .pPlaneLayouts = (
const VkSubresourceLayout *)&plane_data,
2060 VkExternalMemoryImageCreateInfo einfo = {
2061 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
2062 .pNext = has_modifiers ? &drm_info :
NULL,
2063 .handleTypes =
htype,
2066 VkSemaphoreCreateInfo sem_spawn = {
2067 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
2070 VkImageCreateInfo create_info = {
2071 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
2073 .imageType = VK_IMAGE_TYPE_2D,
2074 .format = drm_to_vulkan_fmt(
desc->layers[
i].format),
2078 .flags = VK_IMAGE_CREATE_ALIAS_BIT,
2079 .tiling =
f->tiling,
2080 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
2081 .usage = frames_hwctx->
usage,
2082 .samples = VK_SAMPLE_COUNT_1_BIT,
2083 .pQueueFamilyIndices = p->
qfs,
2084 .queueFamilyIndexCount = p->
num_qfs,
2085 .sharingMode = p->
num_qfs > 1 ? VK_SHARING_MODE_CONCURRENT :
2086 VK_SHARING_MODE_EXCLUSIVE,
2089 get_plane_wh(&create_info.extent.width, &create_info.extent.height,
2092 for (
int j = 0; j <
planes; j++) {
2093 plane_data[j].offset =
desc->layers[
i].planes[j].offset;
2094 plane_data[j].rowPitch =
desc->layers[
i].planes[j].pitch;
2095 plane_data[j].size = 0;
2096 plane_data[j].arrayPitch = 0;
2097 plane_data[j].depthPitch = 0;
2101 ret = vkCreateImage(hwctx->
act_dev, &create_info,
2103 if (ret != VK_SUCCESS) {
2110 ret = vkCreateSemaphore(hwctx->
act_dev, &sem_spawn,
2112 if (ret != VK_SUCCESS) {
2123 f->layout[
i] = create_info.initialLayout;
2127 for (
int i = 0;
i <
desc->nb_objects;
i++) {
2128 int use_ded_mem = 0;
2129 VkMemoryFdPropertiesKHR fdmp = {
2130 .sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR,
2132 VkMemoryRequirements req = {
2133 .size =
desc->objects[
i].size,
2135 VkImportMemoryFdInfoKHR idesc = {
2136 .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
2137 .handleType =
htype,
2138 .fd = dup(
desc->objects[
i].fd),
2140 VkMemoryDedicatedAllocateInfo ded_alloc = {
2141 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
2145 ret = pfn_vkGetMemoryFdPropertiesKHR(hwctx->
act_dev,
htype,
2147 if (ret != VK_SUCCESS) {
2155 req.memoryTypeBits = fdmp.memoryTypeBits;
2160 if (
desc->nb_layers ==
desc->nb_objects) {
2161 VkImageMemoryRequirementsInfo2 req_desc = {
2162 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
2165 VkMemoryDedicatedRequirements ded_req = {
2166 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
2168 VkMemoryRequirements2 req2 = {
2169 .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
2173 vkGetImageMemoryRequirements2(hwctx->
act_dev, &req_desc, &req2);
2175 use_ded_mem = ded_req.prefersDedicatedAllocation |
2176 ded_req.requiresDedicatedAllocation;
2178 ded_alloc.image =
f->img[
i];
2181 err =
alloc_mem(
ctx, &req, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2182 use_ded_mem ? &ded_alloc : ded_alloc.pNext,
2183 &
f->flags, &
f->mem[
i]);
2189 f->size[
i] =
desc->objects[
i].size;
2192 for (
int i = 0;
i <
desc->nb_layers;
i++) {
2194 const int signal_p = has_modifiers && (
planes > 1);
2195 for (
int j = 0; j <
planes; j++) {
2196 VkImageAspectFlagBits aspect = j == 0 ? VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT :
2197 j == 1 ? VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT :
2198 VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT;
2200 plane_info[bind_counts].sType = VK_STRUCTURE_TYPE_BIND_IMAGE_PLANE_MEMORY_INFO;
2201 plane_info[bind_counts].planeAspect = aspect;
2203 bind_info[bind_counts].sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
2204 bind_info[bind_counts].pNext = signal_p ? &
plane_info[bind_counts] :
NULL;
2205 bind_info[bind_counts].image =
f->img[
i];
2206 bind_info[bind_counts].memory =
f->mem[
desc->layers[
i].planes[j].object_index];
2207 bind_info[bind_counts].memoryOffset =
desc->layers[
i].planes[j].offset;
2213 ret = vkBindImageMemory2(hwctx->
act_dev, bind_counts, bind_info);
2214 if (ret != VK_SUCCESS) {
2232 for (
int i = 0;
i <
desc->nb_layers;
i++) {
2236 for (
int i = 0;
i <
desc->nb_objects;
i++)
2251 if ((err = vulkan_map_from_drm_frame_desc(hwfc, &
f,
src)))
2267 &vulkan_unmap_from,
map);
2290 VASurfaceID surface_id = (VASurfaceID)(uintptr_t)
src->data[3];
2296 vaSyncSurface(vaapi_ctx->display, surface_id);
2304 err = vulkan_map_from_drm(dst_fc, dst,
tmp,
flags);
2337 CudaFunctions *cu = cu_internal->
cuda_dl;
2338 CUarray_format cufmt =
desc->comp[0].depth > 8 ? CU_AD_FORMAT_UNSIGNED_INT16 :
2339 CU_AD_FORMAT_UNSIGNED_INT8;
2340 const int elem_size = 1 + (
desc->comp[0].depth > 8);
2345 if (!dst_int || !dst_int->cuda_fc_ref) {
2355 if (!dst_int->cuda_fc_ref) {
2361 CUDA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC tex_desc = {
2366 .NumChannels =
desc->comp[
i].step / elem_size,
2371 CUDA_EXTERNAL_MEMORY_HANDLE_DESC ext_desc = {
2372 .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD,
2373 .size = dst_f->
size[
i],
2375 VkMemoryGetFdInfoKHR export_info = {
2376 .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
2377 .memory = dst_f->
mem[
i],
2378 .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
2380 VkSemaphoreGetFdInfoKHR sem_export = {
2381 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR,
2382 .semaphore = dst_f->
sem[
i],
2383 .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
2385 CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC ext_sem_desc = {
2386 .type = CU_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD,
2392 tex_desc.arrayDesc.Width = p_w;
2393 tex_desc.arrayDesc.Height = p_h;
2395 ret = pfn_vkGetMemoryFdKHR(hwctx->
act_dev, &export_info,
2396 &ext_desc.handle.fd);
2397 if (ret != VK_SUCCESS) {
2403 ret =
CHECK_CU(cu->cuImportExternalMemory(&dst_int->ext_mem[
i], &ext_desc));
2409 ret =
CHECK_CU(cu->cuExternalMemoryGetMappedMipmappedArray(&dst_int->cu_mma[
i],
2410 dst_int->ext_mem[
i],
2417 ret =
CHECK_CU(cu->cuMipmappedArrayGetLevel(&dst_int->cu_array[
i],
2418 dst_int->cu_mma[
i], 0));
2424 ret = pfn_vkGetSemaphoreFdKHR(hwctx->
act_dev, &sem_export,
2425 &ext_sem_desc.handle.fd);
2426 if (ret != VK_SUCCESS) {
2433 ret =
CHECK_CU(cu->cuImportExternalSemaphore(&dst_int->cu_sem[
i],
2463 CudaFunctions *cu = cu_internal->
cuda_dl;
2467 ret =
CHECK_CU(cu->cuCtxPushCurrent(cuda_dev->cuda_ctx));
2473 ret = vulkan_export_to_cuda(hwfc,
src->hw_frames_ctx, dst);
2481 ret =
CHECK_CU(cu->cuWaitExternalSemaphoresAsync(dst_int->cu_sem, s_w_par,
2482 planes, cuda_dev->stream));
2489 CUDA_MEMCPY2D cpy = {
2490 .srcMemoryType = CU_MEMORYTYPE_DEVICE,
2491 .srcDevice = (CUdeviceptr)
src->data[
i],
2492 .srcPitch =
src->linesize[
i],
2495 .dstMemoryType = CU_MEMORYTYPE_ARRAY,
2496 .dstArray = dst_int->cu_array[
i],
2502 cpy.WidthInBytes = p_w *
desc->comp[
i].step;
2505 ret =
CHECK_CU(cu->cuMemcpy2DAsync(&cpy, cuda_dev->stream));
2512 ret =
CHECK_CU(cu->cuSignalExternalSemaphoresAsync(dst_int->cu_sem, s_s_par,
2513 planes, cuda_dev->stream));
2539 switch (
src->format) {
2544 return vulkan_map_from_vaapi(hwfc, dst,
src,
flags);
2548 return vulkan_map_from_drm(hwfc, dst,
src,
flags);
2556 typedef struct VulkanDRMMapping {
2571 static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt)
2574 if (vulkan_drm_format_map[
i].vk_format == vkfmt)
2575 return vulkan_drm_format_map[
i].drm_fourcc;
2576 return DRM_FORMAT_INVALID;
2590 VkImageDrmFormatModifierPropertiesEXT drm_mod = {
2591 .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
2593 int free_drm_desc_on_err = 1;
2608 free_drm_desc_on_err = 0;
2612 ret = pfn_vkGetImageDrmFormatModifierPropertiesEXT(hwctx->
act_dev,
f->img[0],
2614 if (ret != VK_SUCCESS) {
2621 for (
int i = 0; (
i <
planes) && (
f->mem[
i]);
i++) {
2622 VkMemoryGetFdInfoKHR export_info = {
2623 .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
2624 .memory =
f->mem[
i],
2625 .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
2628 ret = pfn_vkGetMemoryFdKHR(hwctx->
act_dev, &export_info,
2630 if (ret != VK_SUCCESS) {
2643 VkSubresourceLayout
layout;
2644 VkImageSubresource
sub = {
2646 VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT :
2647 VK_IMAGE_ASPECT_COLOR_BIT,
2651 drm_desc->
layers[
i].
format = vulkan_fmt_to_drm(plane_vkfmt);
2662 if (
f->tiling == VK_IMAGE_TILING_OPTIMAL)
2679 if (free_drm_desc_on_err)
2721 return vulkan_map_to_drm(hwfc, dst,
src,
flags);
2725 return vulkan_map_to_vaapi(hwfc, dst,
src,
flags);
2764 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags,
2765 size_t size, uint32_t req_memory_bits,
int host_mapped,
2766 void *create_pnext,
void *alloc_pnext)
2773 VkBufferCreateInfo buf_spawn = {
2774 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
2775 .pNext = create_pnext,
2778 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
2781 VkBufferMemoryRequirementsInfo2 req_desc = {
2782 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
2784 VkMemoryDedicatedAllocateInfo ded_alloc = {
2785 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
2786 .pNext = alloc_pnext,
2788 VkMemoryDedicatedRequirements ded_req = {
2789 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
2791 VkMemoryRequirements2 req = {
2792 .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
2802 ret = vkCreateBuffer(hwctx->
act_dev, &buf_spawn,
NULL, &vkbuf->
buf);
2803 if (ret != VK_SUCCESS) {
2810 req_desc.buffer = vkbuf->
buf;
2812 vkGetBufferMemoryRequirements2(hwctx->
act_dev, &req_desc, &req);
2815 use_ded_mem = ded_req.prefersDedicatedAllocation |
2816 ded_req.requiresDedicatedAllocation;
2818 ded_alloc.buffer = vkbuf->
buf;
2821 if (req_memory_bits)
2822 req.memoryRequirements.memoryTypeBits &= req_memory_bits;
2825 use_ded_mem ? &ded_alloc : (
void *)ded_alloc.pNext,
2830 ret = vkBindBufferMemory(hwctx->
act_dev, vkbuf->
buf, vkbuf->
mem, 0);
2831 if (ret != VK_SUCCESS) {
2853 int nb_buffers,
int invalidate)
2858 int invalidate_count = 0;
2860 for (
int i = 0;
i < nb_buffers;
i++) {
2865 ret = vkMapMemory(hwctx->
act_dev, vkbuf->
mem, 0,
2866 VK_WHOLE_SIZE, 0, (
void **)&mem[
i]);
2867 if (ret != VK_SUCCESS) {
2877 for (
int i = 0;
i < nb_buffers;
i++) {
2879 const VkMappedMemoryRange ival_buf = {
2880 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
2881 .memory = vkbuf->
mem,
2882 .size = VK_WHOLE_SIZE,
2891 if (vkbuf->
flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
2894 invalidate_ctx[invalidate_count++] = ival_buf;
2897 if (invalidate_count) {
2898 ret = vkInvalidateMappedMemoryRanges(hwctx->
act_dev, invalidate_count,
2900 if (ret != VK_SUCCESS)
2909 int nb_buffers,
int flush)
2915 int flush_count = 0;
2918 for (
int i = 0;
i < nb_buffers;
i++) {
2920 const VkMappedMemoryRange flush_buf = {
2921 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
2922 .memory = vkbuf->
mem,
2923 .size = VK_WHOLE_SIZE,
2926 if (vkbuf->
flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
2929 flush_ctx[flush_count++] = flush_buf;
2934 ret = vkFlushMappedMemoryRanges(hwctx->
act_dev, flush_count, flush_ctx);
2935 if (ret != VK_SUCCESS) {
2942 for (
int i = 0;
i < nb_buffers;
i++) {
2955 const int *buf_stride,
int w,
2972 VkSubmitInfo s_info = {
2973 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
2974 .pSignalSemaphores =
frame->sem,
2975 .pWaitSemaphores =
frame->sem,
2976 .pWaitDstStageMask = sem_wait_dst,
2977 .signalSemaphoreCount =
planes,
2978 .waitSemaphoreCount =
planes,
2986 VkImageLayout new_layout = to_buf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL :
2987 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
2988 VkAccessFlags new_access = to_buf ? VK_ACCESS_TRANSFER_READ_BIT :
2989 VK_ACCESS_TRANSFER_WRITE_BIT;
2991 sem_wait_dst[
i] = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
2994 if ((
frame->layout[
i] == new_layout) && (
frame->access[
i] & new_access))
2997 img_bar[bar_num].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
2998 img_bar[bar_num].srcAccessMask = 0x0;
2999 img_bar[bar_num].dstAccessMask = new_access;
3000 img_bar[bar_num].oldLayout =
frame->layout[
i];
3001 img_bar[bar_num].newLayout = new_layout;
3002 img_bar[bar_num].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
3003 img_bar[bar_num].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
3004 img_bar[bar_num].image =
frame->img[
i];
3005 img_bar[bar_num].subresourceRange.levelCount = 1;
3006 img_bar[bar_num].subresourceRange.layerCount = 1;
3007 img_bar[bar_num].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3009 frame->layout[
i] = img_bar[bar_num].newLayout;
3010 frame->access[
i] = img_bar[bar_num].dstAccessMask;
3016 vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
3017 VK_PIPELINE_STAGE_TRANSFER_BIT, 0,
3018 0,
NULL, 0,
NULL, bar_num, img_bar);
3023 VkBufferImageCopy buf_reg = {
3024 .bufferOffset = buf_offsets[
i],
3025 .bufferRowLength = buf_stride[
i] /
desc->comp[
i].step,
3026 .imageSubresource.layerCount = 1,
3027 .imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
3028 .imageOffset = { 0, 0, 0, },
3034 buf_reg.bufferImageHeight = p_h;
3035 buf_reg.imageExtent = (VkExtent3D){ p_w, p_h, 1, };
3038 vkCmdCopyImageToBuffer(cmd_buf,
frame->img[
i],
frame->layout[
i],
3039 vkbuf->
buf, 1, &buf_reg);
3041 vkCmdCopyBufferToImage(cmd_buf, vkbuf->
buf,
frame->img[
i],
3042 frame->layout[
i], 1, &buf_reg);
3095 if (swf->width > hwfc->
width || swf->height > hwfc->
height)
3102 if (bytewidth[
i] < 0)
3103 return bytewidth[
i];
3107 if (
f->tiling == VK_IMAGE_TILING_LINEAR &&
3108 f->flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
3112 map->format = swf->format;
3127 VkExternalMemoryBufferCreateInfo create_desc = {
3128 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
3129 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
3132 VkImportMemoryHostPointerInfoEXT import_desc = {
3133 .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
3134 .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
3137 VkMemoryHostPointerPropertiesEXT p_props = {
3138 .sType = VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT,
3141 get_plane_wh(&p_w, &p_h, swf->format, swf->width, swf->height,
i);
3146 if (map_host && swf->linesize[
i] > 0) {
3148 offs = (uintptr_t)swf->data[
i] % p->
hprops.minImportedHostPointerAlignment;
3149 import_desc.pHostPointer = swf->data[
i] - offs;
3154 p->
hprops.minImportedHostPointerAlignment);
3156 ret = pfn_vkGetMemoryHostPointerPropertiesEXT(hwctx->
act_dev,
3157 import_desc.handleType,
3158 import_desc.pHostPointer,
3161 if (ret == VK_SUCCESS) {
3163 buf_offsets[
i] = offs;
3167 if (!host_mapped[
i])
3171 from ? VK_BUFFER_USAGE_TRANSFER_DST_BIT :
3172 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
3173 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
3174 req_size, p_props.memoryTypeBits, host_mapped[
i],
3175 host_mapped[
i] ? &create_desc :
NULL,
3176 host_mapped[
i] ? &import_desc :
NULL);
3190 get_plane_wh(&p_w, &p_h, swf->format, swf->width, swf->height,
i);
3193 (
const uint8_t *)swf->data[
i], swf->linesize[
i],
3204 swf->width, swf->height, swf->format,
from);
3215 get_plane_wh(&p_w, &p_h, swf->format, swf->width, swf->height,
i);
3239 switch (
src->format) {
3244 return vulkan_transfer_data_from_cuda(hwfc, dst,
src);
3247 if (
src->hw_frames_ctx)
3270 CudaFunctions *cu = cu_internal->
cuda_dl;
3274 ret =
CHECK_CU(cu->cuCtxPushCurrent(cuda_dev->cuda_ctx));
3288 ret =
CHECK_CU(cu->cuWaitExternalSemaphoresAsync(dst_int->cu_sem, s_w_par,
3289 planes, cuda_dev->stream));
3296 CUDA_MEMCPY2D cpy = {
3297 .dstMemoryType = CU_MEMORYTYPE_DEVICE,
3298 .dstDevice = (CUdeviceptr)dst->
data[
i],
3302 .srcMemoryType = CU_MEMORYTYPE_ARRAY,
3303 .srcArray = dst_int->cu_array[
i],
3309 cpy.WidthInBytes =
w *
desc->comp[
i].step;
3312 ret =
CHECK_CU(cu->cuMemcpy2DAsync(&cpy, cuda_dev->stream));
3319 ret =
CHECK_CU(cu->cuSignalExternalSemaphoresAsync(dst_int->cu_sem, s_s_par,
3320 planes, cuda_dev->stream));
3351 return vulkan_transfer_data_to_cuda(hwfc, dst,
src);
static void flush(AVCodecContext *avctx)
static const char *const format[]
static cqueue * cqueue_create(int size, int max_size)
#define flags(name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static enum AVPixelFormat pix_fmt
static float sub(float src0, float src1)
#define AV_NUM_DATA_POINTERS
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVBufferPool * av_buffer_pool_init2(buffer_size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, buffer_size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_EXTERNAL
Generic error in an external library.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
char * av_strdup(const char *s)
Duplicate a string.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
#define LIBAVUTIL_VERSION_MINOR
#define LIBAVUTIL_VERSION_MAJOR
#define LIBAVUTIL_VERSION_MICRO
static const int weights[]
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
Replace the current hwmap of dst with the one from src, used for indirect mappings like VAAPI->(DRM)-...
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
AVHWFrameTransferDirection
@ AV_HWDEVICE_TYPE_VULKAN
FFmpeg internal API for CUDA.
API-specific header for AV_HWDEVICE_TYPE_DRM.
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
const VDPAUPixFmtMap * map
static int submit_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd, VkSubmitInfo *s_info, int synchronous)
static int wait_start_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd)
static int vulkan_frames_init(AVHWFramesContext *hwfc)
#define SEARCH_FLAGS(expr, out)
static VkBool32 VKAPI_CALL vk_dbg_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *data, void *priv)
static int alloc_mem(AVHWDeviceContext *ctx, VkMemoryRequirements *req, VkMemoryPropertyFlagBits req_flags, const void *alloc_extension, VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
static int vulkan_transfer_data(AVHWFramesContext *hwfc, const AVFrame *vkf, const AVFrame *swf, int from)
static int vulkan_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
static void free_buf(void *opaque, uint8_t *data)
static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
#define CHECK_QUEUE(type, n)
static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f, void *alloc_pnext, size_t alloc_pnext_stride)
static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts)
static void try_export_flags(AVHWFramesContext *hwfc, VkExternalMemoryHandleTypeFlags *comp_handle_types, VkExternalMemoryHandleTypeFlagBits *iexp, VkExternalMemoryHandleTypeFlagBits exp)
static int unmap_buffers(AVHWDeviceContext *ctx, AVBufferRef **bufs, int nb_buffers, int flush)
static VkCommandBuffer get_buf_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd)
static int transfer_image_buf(AVHWFramesContext *hwfc, const AVFrame *f, AVBufferRef **bufs, size_t *buf_offsets, const int *buf_stride, int w, int h, enum AVPixelFormat pix_fmt, int to_buf)
static void unref_exec_ctx_deps(AVHWFramesContext *hwfc, VulkanExecCtx *cmd)
static int create_buf(AVHWDeviceContext *ctx, AVBufferRef **buf, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags, size_t size, uint32_t req_memory_bits, int host_mapped, void *create_pnext, void *alloc_pnext)
static int find_device(AVHWDeviceContext *ctx, VulkanDeviceSelection *select)
#define ADD_VAL_TO_LIST(list, count, val)
static void vulkan_frame_free(void *opaque, uint8_t *data)
static int vulkan_device_create_internal(AVHWDeviceContext *ctx, VulkanDeviceSelection *dev_select, AVDictionary *opts, int flags)
static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts, const char *const **dst, uint32_t *num, int debug)
static size_t get_req_buffer_size(VulkanDevicePriv *p, int *stride, int height)
static int search_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static int vulkan_transfer_get_formats(AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static int vulkan_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
static int vulkan_device_init(AVHWDeviceContext *ctx)
static int vulkan_frames_derive_to(AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
static int vulkan_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static int vulkan_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
static int vulkan_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
static int create_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd, int queue_family_index, int num_queues)
AVVkFrame * av_vk_frame_alloc(void)
Allocates a single AVVkFrame and initializes everything as 0.
static int map_buffers(AVHWDeviceContext *ctx, AVBufferRef **bufs, uint8_t *mem[], int nb_buffers, int invalidate)
static void get_plane_wh(int *w, int *h, enum AVPixelFormat format, int frame_w, int frame_h, int plane)
static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx, AVVkFrame *frame, enum PrepMode pmode)
static AVBufferRef * vulkan_pool_alloc(void *opaque, buffer_size_t size)
static const char * vk_ret2str(VkResult res)
enum AVPixelFormat pixfmt
static const char * vk_dev_type(enum VkPhysicalDeviceType type)
static void vulkan_device_free(AVHWDeviceContext *ctx)
#define GET_QUEUE_COUNT(hwctx, graph, comp, tx)
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the format of each image up to the number of planes for a given sw_format.
#define ADD_QUEUE(fidx, graph, comp, tx)
#define VK_LOAD_PFN(inst, name)
#define COPY_FEATURE(DST, NAME)
static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
static int pixfmt_is_supported(AVVulkanDeviceContext *hwctx, enum AVPixelFormat p, int linear)
const HWContextType ff_hwcontext_type_vulkan
static int add_buf_dep_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd, AVBufferRef *const *deps, int nb_deps)
static const VulkanOptExtension optional_instance_exts[]
static void vulkan_free_internal(AVVkFrameInternal *internal)
@ EXT_EXTERNAL_HOST_MEMORY
@ EXT_EXTERNAL_DMABUF_MEMORY
static void vulkan_unmap_frame(AVHWFramesContext *hwfc, HWMapDescriptor *hwmap)
static const struct @311 vk_pixfmt_map[]
static int vulkan_get_buffer(AVHWFramesContext *hwfc, AVFrame *frame)
static const VulkanOptExtension optional_device_exts[]
static int create_frame(AVHWFramesContext *hwfc, AVVkFrame **frame, VkImageTiling tiling, VkImageUsageFlagBits usage, void *create_pnext)
@ PREP_MODE_EXTERNAL_EXPORT
static int vulkan_map_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
#define DEFAULT_USAGE_FLAGS
static void free_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd)
API-specific header for AV_HWDEVICE_TYPE_VULKAN.
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
static const struct @323 planes[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_X2RGB10
#define AV_PIX_FMT_GRAYF32
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_NV42
as above, but U and V bytes are swapped
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_DRM_PRIME
DRM-managed buffers exposed through PRIME buffer sharing.
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_BGR565
#define AV_PIX_FMT_RGB565
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_YUV444P10
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
AVCUDADeviceContextInternal * internal
int fd
File descriptor of DRM device.
AVDRMObjectDescriptor objects[AV_DRM_MAX_PLANES]
Array of objects making up the frame.
int nb_layers
Number of layers in the frame.
int nb_objects
Number of DRM objects making up this frame.
AVDRMLayerDescriptor layers[AV_DRM_MAX_PLANES]
Array of layers in the frame.
AVDRMPlaneDescriptor planes[AV_DRM_MAX_PLANES]
Array of planes in this layer.
int nb_planes
Number of planes in the layer.
uint32_t format
Format of the layer (DRM_FORMAT_*).
int fd
DRM PRIME fd for the object.
size_t size
Total size of the object.
uint64_t format_modifier
Format modifier applied to the object (DRM_FORMAT_MOD_*).
ptrdiff_t pitch
Pitch (linesize) of this plane.
int object_index
Index of the object containing this plane in the objects array of the enclosing frame descriptor.
ptrdiff_t offset
Offset within that object of this plane.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVHWDeviceInternal * internal
Private data used internally by libavutil.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int max_width
The maximum size of frames in this hw_frames_ctx.
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
int min_width
The minimum size of frames in this hw_frames_ctx.
This struct describes a set or pool of "hardware" frames (i.e.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVHWFramesInternal * internal
Private data used internally by libavutil.
int width
The allocated dimensions of the frames in this pool.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
AVBufferPool * pool_internal
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
VAAPI connection details.
VADisplay display
The VADisplay handle, to be filled by the user.
size_t size[AV_NUM_DATA_POINTERS]
VkSemaphore sem[AV_NUM_DATA_POINTERS]
Synchronization semaphores.
struct AVVkFrameInternal * internal
Internal data.
VkDeviceMemory mem[AV_NUM_DATA_POINTERS]
Memory backing the images.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkPhysicalDevice phys_dev
Physical device.
int queue_family_tx_index
Queue family index to use for transfer operations, and the amount of queues enabled.
int queue_family_index
Queue family index for graphics.
int nb_enabled_inst_extensions
const char *const * enabled_dev_extensions
Enabled device extensions.
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
VkDevice act_dev
Active device.
int queue_family_comp_index
Queue family index for compute ops, and the amount of queues enabled.
const char *const * enabled_inst_extensions
Enabled instance extensions.
VkInstance inst
Vulkan instance.
VkPhysicalDeviceFeatures2 device_features
This structure should be set to the set of features that present and enabled during device creation.
int nb_enabled_dev_extensions
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
void * create_pnext
Extension data for image creation.
VkImageTiling tiling
Controls the tiling of allocated frames.
void * alloc_pnext[AV_NUM_DATA_POINTERS]
Extension data for memory allocation.
VkImageUsageFlagBits usage
Defines extra usage of output frames.
void * priv
Hardware-specific private data associated with the mapping.
VkMemoryPropertyFlagBits flags
VkPhysicalDeviceMemoryProperties mprops
VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops
VkPhysicalDeviceProperties2 props
VkDebugUtilsMessengerEXT debug_ctx
uint8_t uuid[VK_UUID_SIZE]
VulkanExecCtx download_ctx
#define av_malloc_array(a, b)
static int ref[MAX_W *MAX_W]
static int mod(int a, int b)
Modulo operation with only positive remainders.