MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ff_vk_host_map_buffer

Function ff_vk_host_map_buffer

libavutil/vulkan.c:1391–1487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1389}
1390
1391int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst,
1392 uint8_t *src_data, const AVBufferRef *src_buf,
1393 VkBufferUsageFlags usage)
1394{
1395 int err;
1396 VkResult ret;
1397 FFVulkanFunctions *vk = &s->vkfn;
1398
1399 VkExternalMemoryBufferCreateInfo create_desc = {
1400 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
1401 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
1402 };
1403 VkMemoryAllocateFlagsInfo alloc_flags = {
1404 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO,
1405 .flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT,
1406 };
1407 VkImportMemoryHostPointerInfoEXT import_desc = {
1408 .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
1409 .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
1410 .pNext = usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT ? &alloc_flags : NULL,
1411 };
1412 VkMemoryHostPointerPropertiesEXT props;
1413
1414 AVBufferRef *ref;
1415 FFVkBuffer *vkb;
1416 size_t offs;
1417 size_t buffer_size;
1418
1419 *dst = NULL;
1420
1421 /* Get the previous point at which mapping was possible and use it */
1422 offs = (uintptr_t)src_data % s->hprops.minImportedHostPointerAlignment;
1423 import_desc.pHostPointer = src_data - offs;
1424
1425 props = (VkMemoryHostPointerPropertiesEXT) {
1426 VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT,
1427 };
1428 ret = vk->GetMemoryHostPointerPropertiesEXT(s->hwctx->act_dev,
1429 import_desc.handleType,
1430 import_desc.pHostPointer,
1431 &props);
1432 if (!(ret == VK_SUCCESS && props.memoryTypeBits))
1433 return AVERROR(EINVAL);
1434
1435 /* Ref the source buffer */
1436 ref = av_buffer_ref(src_buf);
1437 if (!ref)
1438 return AVERROR(ENOMEM);
1439
1440 /* Add the offset at the start, which gets ignored */
1441 const ptrdiff_t src_offset = src_data - src_buf->data;
1442 buffer_size = offs + (src_buf->size - src_offset);
1443 buffer_size = FFALIGN(buffer_size, s->props.properties.limits.minMemoryMapAlignment);
1444 buffer_size = FFALIGN(buffer_size, s->hprops.minImportedHostPointerAlignment);
1445
1446 /* Create a buffer struct */
1447 vkb = av_mallocz(sizeof(*vkb));
1448 if (!vkb) {

Callers 7

host_map_frameFunction · 0.85
vk_prores_start_frameFunction · 0.85
vk_ffv1_start_frameFunction · 0.85
get_packetFunction · 0.85
transfer_slicesFunction · 0.85
vk_dpx_start_frameFunction · 0.85

Calls 7

av_buffer_refFunction · 0.85
av_buffer_unrefFunction · 0.85
create_mapped_bufferFunction · 0.85
av_buffer_createFunction · 0.85
destroy_avvkbufFunction · 0.85
av_malloczFunction · 0.70
av_freeFunction · 0.70

Tested by

no test coverage detected