History

hwcontext_vulkan: fix image copy

The patch was applied by mistake in an unfinished form. This fixes the build and lets the code run.

Lynne committed 1 year ago

Commit 3ac7d701 parent 9e931632 files · +28 −15Browse files

Unified · Split

2 files
  1. libavutil/hwcontext_vulkan.c +25 −14
  2. libavutil/vulkan.c +3 −1
libavutil/hwcontext_vulkan.c+25−14
@@ -2830,14 +2830,13 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) · 2829 unmodified lines
28302830
28312831 /* Image usage flags */
28322832 if (!hwctx->usage) {
2833− hwctx->usage = supported_usage & (VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
2834− VK_IMAGE_USAGE_STORAGE_BIT |
2833+ hwctx->usage = supported_usage & (VK_IMAGE_USAGE_TRANSFER_DST_BIT |
2834+ VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
2835+ VK_IMAGE_USAGE_STORAGE_BIT |
28352836 VK_IMAGE_USAGE_SAMPLED_BIT);
28362837
28372838 if (p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY)
28382839 hwctx->usage |= supported_usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT;
2839− else
2840− hwctx->usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
28412840
28422841 /* Enables encoding of images, if supported by format and extensions */
28432842 if ((supported_usage & VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR) &&
@@ -4160,8 +4159,9 @@ fail: · 1316 unmodified lines
41604159 static int vulkan_transfer_host(AVHWFramesContext *hwfc, AVFrame *hwf,
41614160 AVFrame *swf, int upload)
41624161 {
4162+ VulkanFramesPriv *fp = hwfc->hwctx;
4163+ AVVulkanFramesContext *hwfc_vk = &fp->p;
41634164 VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
4164− AVVulkanFramesContext *hwfc_vk = hwfc->hwctx;
41654165 AVVulkanDeviceContext *hwctx = &p->p;
41664166 FFVulkanFunctions *vk = &p->vkctx.vkfn;
41674167
@@ -4170,16 +4170,23 @@ static int vulkan_transfer_host(AVHWFramesContext *hwfc, AVFrame *hwf, · 2 unmodified lines
41704170 const int nb_images = ff_vk_count_images(hwf_vk);
41714171
41724172 VkSemaphoreWaitInfo sem_wait;
4173− VkHostImageLayoutTransitionInfo layout_ch_info[];
4173+ VkHostImageLayoutTransitionInfo layout_ch_info[AV_NUM_DATA_POINTERS];
41744174 int nb_layout_ch = 0;
41754175
41764176 hwfc_vk->lock_frame(hwfc, hwf_vk);
41774177
41784178 for (int i = 0; i < nb_images; i++) {
4179− if (hwf_vk->layout[i])
4179+ int compat = 0;
4180+ for (int j = 0; j < p->vkctx.host_image_props.copySrcLayoutCount; j++) {
4181+ if (hwf_vk->layout[i] == p->vkctx.host_image_props.pCopySrcLayouts[j]) {
4182+ compat = 1;
4183+ break;
4184+ }
4185+ }
4186+ if (compat)
41804187 continue;
41814188
4182− layout_ch_info[nb_layout_ch++] = (VkHostImageLayoutTransitionInfo) {
4189+ layout_ch_info[nb_layout_ch] = (VkHostImageLayoutTransitionInfo) {
41834190 .sType = VK_STRUCTURE_TYPE_HOST_IMAGE_LAYOUT_TRANSITION_INFO,
41844191 .image = hwf_vk->img[i],
41854192 .oldLayout = hwf_vk->layout[i],
@@ -4188,13 +4195,12 @@ static int vulkan_transfer_host(AVHWFramesContext *hwfc, AVFrame *hwf, · 2 unmodified lines
41884195 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
41894196 .levelCount = 1,
41904197 .layerCount = 1,
4191− };
4198+ },
41924199 };
4193− }
41944200
4195− if (nb_layout_ch)
4196− vk->TransitionImageLayoutEXT(hwctx->act_dev,
4197− nb_layout_ch, layout_ch_info);
4201+ hwf_vk->layout[i] = layout_ch_info[nb_layout_ch].newLayout;
4202+ nb_layout_ch++;
4203+ }
41984204
41994205 sem_wait = (VkSemaphoreWaitInfo) {
42004206 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO,
@@ -4205,6 +4211,10 @@ static int vulkan_transfer_host(AVHWFramesContext *hwfc, AVFrame *hwf, · 4 unmodified lines
42054211
42064212 vk->WaitSemaphores(hwctx->act_dev, &sem_wait, UINT64_MAX);
42074213
4214+ if (nb_layout_ch)
4215+ vk->TransitionImageLayoutEXT(hwctx->act_dev,
4216+ nb_layout_ch, layout_ch_info);
4217+
42084218 if (upload) {
42094219 VkMemoryToImageCopy region_info = {
42104220 .sType = VK_STRUCTURE_TYPE_MEMORY_TO_IMAGE_COPY,
@@ -4270,6 +4280,7 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc, · 59 unmodified lines
42704280 {
42714281 int err;
42724282 VulkanFramesPriv *fp = hwfc->hwctx;
4283+ AVVulkanFramesContext *hwctx = &fp->p;
42734284 VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
42744285 FFVulkanFunctions *vk = &p->vkctx.vkfn;
42754286
@@ -4300,7 +4311,7 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc, · 24 unmodified lines
43004311 if (swf->width > hwfc->width || swf->height > hwfc->height)
43014312 return AVERROR(EINVAL);
43024313
4303− if (p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY)
4314+ if (hwctx->usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT)
43044315 return vulkan_transfer_host(hwfc, hwf, swf, upload);
43054316
43064317 for (int i = 0; i < av_pix_fmt_count_planes(swf->format); i++) {
libavutil/vulkan.c+3−1
@@ -107,6 +107,8 @@ const char *ff_vk_ret2str(VkResult res) · 106 unmodified lines
107107 VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR); \
108108 MAP_TO(VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR, \
109109 VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR); \
110+ MAP_TO(VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT, \
111+ VK_IMAGE_USAGE_HOST_TRANSFER_BIT); \
110112 return dst; \
111113 }
112114
@@ -191,7 +193,7 @@ int ff_vk_load_props(FFVulkanContext *s) · 78 unmodified lines
191193 s->host_image_props.pCopySrcLayouts =
192194 s->host_image_props.pCopyDstLayouts = NULL;
193195 s->host_image_props.copySrcLayoutCount =
194− s->host_image_props.copyDstLayoutCount = NULL;
196+ s->host_image_props.copyDstLayoutCount = 0;
195197 vk->GetPhysicalDeviceProperties2(s->hwctx->phys_dev, &s->props);
196198
197199 new_size = s->host_image_props.copySrcLayoutCount +

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t