Fixes multiplane support on Nvidia. Also, remove the ENCODE usage, even if the driver signals it as supported. Currently, it's not used, and when it is used, it'll be gated behind two extension checks.
Unified · Split
| @@ -42,18 +42,23 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s, · 41 unmodified lines | ||
| 42 | 42 | vk_frames = frames_ctx->hwctx; |
| 43 | 43 | vk_dev = device_ctx->hwctx; |
| 44 | 44 | |
| 45 | − /* Basic format validation */ | |
| 45 | + /* Width and height mismatch */ | |
| 46 | 46 | if (width != frames_ctx->width || |
| 47 | − height != frames_ctx->height || | |
| 48 | − sw_format != frames_ctx->sw_format || | |
| 49 | − (vk_frames->tiling != VK_IMAGE_TILING_LINEAR && | |
| 50 | − vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL) || | |
| 51 | − !(vk_frames->usage & VK_IMAGE_USAGE_SAMPLED_BIT)) { | |
| 47 | + height != frames_ctx->height) | |
| 48 | + goto skip; | |
| 49 | + | |
| 50 | + /* Format mismatch */ | |
| 51 | + if (sw_format != frames_ctx->sw_format) | |
| 52 | 52 | goto skip; |
| 53 | − } | |
| 54 | 53 | |
| 55 | − if (vk_frames->usage & VK_IMAGE_USAGE_STORAGE_BIT) | |
| 56 | − goto accept; | |
| 54 | + /* Unusual tiling mismatch. Don't let linear through either. */ | |
| 55 | + if (vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL) | |
| 56 | + goto skip; | |
| 57 | + | |
| 58 | + /* Usage mismatch */ | |
| 59 | + if ((vk_frames->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) != | |
| 60 | + (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) | |
| 61 | + goto skip; | |
| 57 | 62 | |
| 58 | 63 | s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions, |
| 59 | 64 | vk_dev->nb_enabled_dev_extensions); |
| @@ -110,6 +115,7 @@ accept: · 50 unmodified lines | ||
| 110 | 115 | vk_frames = frames_ctx->hwctx; |
| 111 | 116 | vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL; |
| 112 | 117 | vk_frames->usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 118 | + VK_IMAGE_USAGE_STORAGE_BIT | | |
| 113 | 119 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 114 | 120 | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 115 | 121 | |
| @@ -282,9 +282,11 @@ FN_MAP_TO(VkImageUsageFlags, usage, VkFormatFeatureFlagBits2, feats) · 281 unmodified lines | ||
| 282 | 282 | |
| 283 | 283 | static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, |
| 284 | 284 | VkImageTiling tiling, |
| 285 | − VkFormat fmts[AV_NUM_DATA_POINTERS], | |
| 286 | − int *nb_images, VkImageAspectFlags *aspect, | |
| 287 | − VkImageUsageFlags *supported_usage, int disable_multiplane) | |
| 285 | + VkFormat fmts[AV_NUM_DATA_POINTERS], /* Output format list */ | |
| 286 | + int *nb_images, /* Output number of images */ | |
| 287 | + VkImageAspectFlags *aspect, /* Output aspect */ | |
| 288 | + VkImageUsageFlags *supported_usage, /* Output supported usage */ | |
| 289 | + int disable_multiplane, int need_storage) | |
| 288 | 290 | { |
| 289 | 291 | AVVulkanDeviceContext *hwctx = dev_ctx->hwctx; |
| 290 | 292 | VulkanDevicePriv *priv = dev_ctx->internal->priv; |
| @@ -301,6 +303,7 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, · 10 unmodified lines | ||
| 301 | 303 | }; |
| 302 | 304 | VkFormatFeatureFlagBits2 feats_primary, feats_secondary; |
| 303 | 305 | int basics_primary = 0, basics_secondary = 0; |
| 306 | + int storage_primary = 0, storage_secondary = 0; | |
| 304 | 307 | |
| 305 | 308 | vk->GetPhysicalDeviceFormatProperties2(hwctx->phys_dev, |
| 306 | 309 | vk_formats_list[i].vkf, |
| @@ -310,6 +313,7 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, · 3 unmodified lines | ||
| 310 | 313 | prop.formatProperties.linearTilingFeatures : |
| 311 | 314 | prop.formatProperties.optimalTilingFeatures; |
| 312 | 315 | basics_primary = (feats_primary & basic_flags) == basic_flags; |
| 316 | + storage_primary = !!(feats_primary & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT); | |
| 313 | 317 | |
| 314 | 318 | if (vk_formats_list[i].vkf != vk_formats_list[i].fallback[0]) { |
| 315 | 319 | vk->GetPhysicalDeviceFormatProperties2(hwctx->phys_dev, |
| @@ -319,11 +323,15 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, · 3 unmodified lines | ||
| 319 | 323 | prop.formatProperties.linearTilingFeatures : |
| 320 | 324 | prop.formatProperties.optimalTilingFeatures; |
| 321 | 325 | basics_secondary = (feats_secondary & basic_flags) == basic_flags; |
| 326 | + storage_secondary = !!(feats_secondary & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT); | |
| 322 | 327 | } else { |
| 323 | 328 | basics_secondary = basics_primary; |
| 329 | + storage_secondary = storage_primary; | |
| 324 | 330 | } |
| 325 | 331 | |
| 326 | − if (basics_primary && !(disable_multiplane && vk_formats_list[i].vk_planes > 1)) { | |
| 332 | + if (basics_primary && | |
| 333 | + !(disable_multiplane && vk_formats_list[i].vk_planes > 1) && | |
| 334 | + (!need_storage || (need_storage && (storage_primary | storage_secondary)))) { | |
| 327 | 335 | if (fmts) |
| 328 | 336 | fmts[0] = vk_formats_list[i].vkf; |
| 329 | 337 | if (nb_images) |
| @@ -331,9 +339,12 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, · 1 unmodified line | ||
| 331 | 339 | if (aspect) |
| 332 | 340 | *aspect = vk_formats_list[i].aspect; |
| 333 | 341 | if (supported_usage) |
| 334 | − *supported_usage = map_feats_to_usage(feats_primary); | |
| 342 | + *supported_usage = map_feats_to_usage(feats_primary) | | |
| 343 | + ((need_storage && (storage_primary | storage_secondary)) ? | |
| 344 | + VK_IMAGE_USAGE_STORAGE_BIT : 0); | |
| 335 | 345 | return 0; |
| 336 | − } else if (basics_secondary) { | |
| 346 | + } else if (basics_secondary && | |
| 347 | + (!need_storage || (need_storage && storage_secondary))) { | |
| 337 | 348 | if (fmts) { |
| 338 | 349 | for (int j = 0; j < vk_formats_list[i].nb_images_fallback; j++) |
| 339 | 350 | fmts[j] = vk_formats_list[i].fallback[j]; |
| @@ -1640,7 +1651,7 @@ static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx, · 1300 unmodified lines | ||
| 1640 | 1651 | count += vkfmt_from_pixfmt2(ctx, vk_formats_list[i].pixfmt, |
| 1641 | 1652 | p->use_linear_images ? VK_IMAGE_TILING_LINEAR : |
| 1642 | 1653 | VK_IMAGE_TILING_OPTIMAL, |
| 1643 | − NULL, NULL, NULL, NULL, 0) >= 0; | |
| 1654 | + NULL, NULL, NULL, NULL, 0, 0) >= 0; | |
| 1644 | 1655 | } |
| 1645 | 1656 | |
| 1646 | 1657 | #if CONFIG_CUDA |
| @@ -1658,7 +1669,7 @@ static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx, · 11 unmodified lines | ||
| 1658 | 1669 | if (vkfmt_from_pixfmt2(ctx, vk_formats_list[i].pixfmt, |
| 1659 | 1670 | p->use_linear_images ? VK_IMAGE_TILING_LINEAR : |
| 1660 | 1671 | VK_IMAGE_TILING_OPTIMAL, |
| 1661 | − NULL, NULL, NULL, NULL, 0) >= 0) { | |
| 1672 | + NULL, NULL, NULL, NULL, 0, 0) >= 0) { | |
| 1662 | 1673 | constraints->valid_sw_formats[count++] = vk_formats_list[i].pixfmt; |
| 1663 | 1674 | } |
| 1664 | 1675 | } |
| @@ -2294,7 +2305,8 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) · 629 unmodified lines | ||
| 2294 | 2305 | /* Check if the sw_format itself is supported */ |
| 2295 | 2306 | err = vkfmt_from_pixfmt2(hwfc->device_ctx, hwfc->sw_format, |
| 2296 | 2307 | hwctx->tiling, NULL, |
| 2297 | − NULL, NULL, &supported_usage, 0); | |
| 2308 | + NULL, NULL, &supported_usage, 0, | |
| 2309 | + hwctx->usage & VK_IMAGE_USAGE_STORAGE_BIT); | |
| 2298 | 2310 | if (err < 0) { |
| 2299 | 2311 | av_log(hwfc, AV_LOG_ERROR, "Unsupported sw format: %s!\n", |
| 2300 | 2312 | av_get_pix_fmt_name(hwfc->sw_format)); |
| @@ -2304,7 +2316,8 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) · 3 unmodified lines | ||
| 2304 | 2316 | err = vkfmt_from_pixfmt2(hwfc->device_ctx, hwfc->sw_format, |
| 2305 | 2317 | hwctx->tiling, hwctx->format, NULL, |
| 2306 | 2318 | NULL, &supported_usage, |
| 2307 | − disable_multiplane); | |
| 2319 | + disable_multiplane, | |
| 2320 | + hwctx->usage & VK_IMAGE_USAGE_STORAGE_BIT); | |
| 2308 | 2321 | if (err < 0) |
| 2309 | 2322 | return err; |
| 2310 | 2323 | } |
| @@ -2314,8 +2327,7 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) · 3 unmodified lines | ||
| 2314 | 2327 | hwctx->usage = supported_usage & (VK_BUFFER_USAGE_TRANSFER_DST_BIT | |
| 2315 | 2328 | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | |
| 2316 | 2329 | VK_IMAGE_USAGE_STORAGE_BIT | |
| 2317 | − VK_IMAGE_USAGE_SAMPLED_BIT | | |
| 2318 | − VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR); | |
| 2330 | + VK_IMAGE_USAGE_SAMPLED_BIT); | |
| 2319 | 2331 | } |
| 2320 | 2332 | |
| 2321 | 2333 | /* Image creation flags. |