summaryrefslogtreecommitdiff
path: root/libavfilter/vulkan.c
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2020-05-25 15:36:41 +0100
committerLynne <dev@lynne.ee>2020-05-26 10:52:11 +0100
commitfb49d5c0b18c7cdb2d6c324c3d92b5aaebd74ef6 (patch)
treeb4babe453bd8a1aaf2c2bbbd9c496c7e56570e27 /libavfilter/vulkan.c
parentbf056caf540e12d2ab3f9cc94e7ccc64cb13ca70 (diff)
downloadffmpeg-fb49d5c0b18c7cdb2d6c324c3d92b5aaebd74ef6.tar.gz
lavfi/vulkan: use dedicated allocation for buffers when necessary
Diffstat (limited to 'libavfilter/vulkan.c')
-rw-r--r--libavfilter/vulkan.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/libavfilter/vulkan.c b/libavfilter/vulkan.c
index 301ee4354f..c3badaee29 100644
--- a/libavfilter/vulkan.c
+++ b/libavfilter/vulkan.c
@@ -152,7 +152,7 @@ int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size,
{
int err;
VkResult ret;
- VkMemoryRequirements req;
+ int use_ded_mem;
VulkanFilterContext *s = avctx->priv;
VkBufferCreateInfo buf_spawn = {
@@ -164,6 +164,21 @@ int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size,
but should be ok */
};
+ VkBufferMemoryRequirementsInfo2 req_desc = {
+ .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
+ };
+ VkMemoryDedicatedAllocateInfo ded_alloc = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
+ .pNext = NULL,
+ };
+ VkMemoryDedicatedRequirements ded_req = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
+ };
+ VkMemoryRequirements2 req = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
+ .pNext = &ded_req,
+ };
+
ret = vkCreateBuffer(s->hwctx->act_dev, &buf_spawn, NULL, &buf->buf);
if (ret != VK_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "Failed to create buffer: %s\n",
@@ -171,9 +186,19 @@ int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size,
return AVERROR_EXTERNAL;
}
- vkGetBufferMemoryRequirements(s->hwctx->act_dev, buf->buf, &req);
+ req_desc.buffer = buf->buf;
+
+ vkGetBufferMemoryRequirements2(s->hwctx->act_dev, &req_desc, &req);
+
+ /* In case the implementation prefers/requires dedicated allocation */
+ use_ded_mem = ded_req.prefersDedicatedAllocation |
+ ded_req.requiresDedicatedAllocation;
+ if (use_ded_mem)
+ ded_alloc.buffer = buf->buf;
- err = vk_alloc_mem(avctx, &req, flags, NULL, &buf->flags, &buf->mem);
+ err = vk_alloc_mem(avctx, &req.memoryRequirements, flags,
+ use_ded_mem ? &ded_alloc : (void *)ded_alloc.pNext,
+ &buf->flags, &buf->mem);
if (err)
return err;