History

vulkan: do not reinvent a queue context struct

We recently introduced a public field which was a superset of the queue context we used to have. Switch to using it entirely. This also allows us to get rid of the NIH function which was valid only for video queues.

Lynne committed 1 year ago

Commit 2e06b841 parent 157cd8222 files · +157 −123Browse files

Unified · Split

22 files
  1. libavcodec/ffv1enc_vulkan.c +9 −9
  2. libavcodec/vulkan_decode.c +7 −9
  3. libavcodec/vulkan_decode.h +1 −1
  4. libavcodec/vulkan_encode.c +4 −6
  5. libavcodec/vulkan_encode.h +1 −1
  6. libavcodec/vulkan_video.c +0 −14
  7. libavcodec/vulkan_video.h +0 −6
  8. libavfilter/vf_avgblur_vulkan.c +9 −3
  9. libavfilter/vf_blend_vulkan.c +9 −3
  10. libavfilter/vf_bwdif_vulkan.c +9 −3
  11. libavfilter/vf_chromaber_vulkan.c +9 −3
  12. libavfilter/vf_flip_vulkan.c +9 −3
  13. libavfilter/vf_gblur_vulkan.c +9 −3
  14. libavfilter/vf_nlmeans_vulkan.c +9 −3
  15. libavfilter/vf_overlay_vulkan.c +9 −3
  16. libavfilter/vf_scale_vulkan.c +9 −3
  17. libavfilter/vf_transpose_vulkan.c +9 −3
  18. libavfilter/vf_xfade_vulkan.c +9 −3
  19. libavfilter/vsrc_testsrc_vulkan.c +9 −3
  20. libavutil/hwcontext_vulkan.c +10 −10
  21. libavutil/vulkan.c +12 −22
  22. libavutil/vulkan.h +5 −9
libavcodec/ffv1enc_vulkan.c+9−9
@@ -58,10 +58,10 @@ typedef struct VulkanEncodeFFv1Context { · 57 unmodified lines
5858 AVFrame *frame;
5959
6060 FFVulkanContext s;
61− FFVkQueueFamilyCtx qf;
61+ AVVulkanDeviceQueueFamily *qf;
6262 FFVkExecPool exec_pool;
6363
64− FFVkQueueFamilyCtx transfer_qf;
64+ AVVulkanDeviceQueueFamily *transfer_qf;
6565 FFVkExecPool transfer_exec_pool;
6666
6767 VkBufferCopy *buf_regions;
@@ -1586,8 +1586,8 @@ static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx) · 1518 unmodified lines
15861586 if (err < 0)
15871587 return err;
15881588
1589− err = ff_vk_qf_init(&fv->s, &fv->qf, VK_QUEUE_COMPUTE_BIT);
1590− if (err < 0) {
1589+ fv->qf = ff_vk_qf_find(&fv->s, VK_QUEUE_COMPUTE_BIT, 0);
1590+ if (!fv->qf) {
15911591 av_log(avctx, AV_LOG_ERROR, "Device has no compute queues!\n");
15921592 return err;
15931593 }
@@ -1626,7 +1626,7 @@ static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx) · 32 unmodified lines
16261626 }
16271627
16281628 if (!fv->async_depth) {
1629− fv->async_depth = FFMIN(fv->qf.nb_queues, FFMAX(max_heap_size / maxsize, 1));
1629+ fv->async_depth = FFMIN(fv->qf->num, FFMAX(max_heap_size / maxsize, 1));
16301630 fv->async_depth = FFMAX(fv->async_depth, 1);
16311631 }
16321632
@@ -1635,19 +1635,19 @@ static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx) · 2 unmodified lines
16351635 (fv->async_depth * maxsize) / (1024*1024),
16361636 fv->async_depth);
16371637
1638− err = ff_vk_exec_pool_init(&fv->s, &fv->qf, &fv->exec_pool,
1638+ err = ff_vk_exec_pool_init(&fv->s, fv->qf, &fv->exec_pool,
16391639 fv->async_depth,
16401640 0, 0, 0, NULL);
16411641 if (err < 0)
16421642 return err;
16431643
1644− err = ff_vk_qf_init(&fv->s, &fv->transfer_qf, VK_QUEUE_TRANSFER_BIT);
1645− if (err < 0) {
1644+ fv->transfer_qf = ff_vk_qf_find(&fv->s, VK_QUEUE_TRANSFER_BIT, 0);
1645+ if (!fv->transfer_qf) {
16461646 av_log(avctx, AV_LOG_ERROR, "Device has no transfer queues!\n");
16471647 return err;
16481648 }
16491649
1650− err = ff_vk_exec_pool_init(&fv->s, &fv->transfer_qf, &fv->transfer_exec_pool,
1650+ err = ff_vk_exec_pool_init(&fv->s, fv->transfer_qf, &fv->transfer_exec_pool,
16511651 1,
16521652 0, 0, 0, NULL);
16531653 if (err < 0)
libavcodec/vulkan_decode.c+7−9
@@ -1116,21 +1116,19 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 1115 unmodified lines
11161116
11171117 /* Create queue context */
11181118 vk_desc = get_codecdesc(avctx->codec_id);
1119− err = ff_vk_video_qf_init(s, &ctx->qf,
1120− VK_QUEUE_VIDEO_DECODE_BIT_KHR,
1121− vk_desc->decode_op);
1122− if (err < 0) {
1119+ ctx->qf = ff_vk_qf_find(s, VK_QUEUE_VIDEO_DECODE_BIT_KHR, vk_desc->decode_op);
1120+ if (!ctx->qf) {
11231121 av_log(avctx, AV_LOG_ERROR, "Decoding of %s is not supported by this device\n",
11241122 avcodec_get_name(avctx->codec_id));
11251123 return err;
11261124 }
11271125
1128− /* Enable queries if supported */
1129− if (s->query_props[ctx->qf.queue_family].queryResultStatusSupport)
1126+ /* Enable queries if supported and usable */
1127+ if (s->query_props[ctx->qf->idx].queryResultStatusSupport)
11301128 nb_q = 1;
11311129
11321130 session_create.flags = 0x0;
1133− session_create.queueFamilyIndex = ctx->qf.queue_family;
1131+ session_create.queueFamilyIndex = ctx->qf->idx;
11341132 session_create.maxCodedExtent = ctx->caps.maxCodedExtent;
11351133 session_create.maxDpbSlots = ctx->caps.maxDpbSlots;
11361134 session_create.maxActiveReferencePictures = ctx->caps.maxActiveReferencePictures;
@@ -1142,8 +1140,8 @@ int ff_vk_decode_init(AVCodecContext *avctx) · 5 unmodified lines
11421140 /* Create decode exec context for this specific main thread.
11431141 * 2 async contexts per thread was experimentally determined to be optimal
11441142 * for a majority of streams. */
1145− err = ff_vk_exec_pool_init(s, &ctx->qf, &ctx->exec_pool,
1146− FFMAX(2*ctx->qf.nb_queues, avctx->thread_count),
1143+ err = ff_vk_exec_pool_init(s, ctx->qf, &ctx->exec_pool,
1144+ FFMAX(2*ctx->qf->num, avctx->thread_count),
11471145 nb_q, VK_QUERY_TYPE_RESULT_STATUS_ONLY_KHR, 0,
11481146 profile);
11491147 if (err < 0)
libavcodec/vulkan_decode.h+1−1
@@ -46,7 +46,7 @@ typedef struct FFVulkanDecodeProfileData { · 45 unmodified lines
4646 typedef struct FFVulkanDecodeShared {
4747 FFVulkanContext s;
4848 FFVkVideoCommon common;
49− FFVkQueueFamilyCtx qf;
49+ AVVulkanDeviceQueueFamily *qf;
5050 FFVkExecPool exec_pool;
5151
5252 AVBufferPool *buf_pool;
libavcodec/vulkan_encode.c+4−6
@@ -769,10 +769,8 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, FFVulkanEncodeContext * · 768 unmodified lines
769769 return err;
770770
771771 /* Create queue context */
772− err = ff_vk_video_qf_init(s, &ctx->qf_enc,
773− VK_QUEUE_VIDEO_ENCODE_BIT_KHR,
774− vk_desc->encode_op);
775− if (err < 0) {
772+ ctx->qf_enc = ff_vk_qf_find(s, VK_QUEUE_VIDEO_ENCODE_BIT_KHR, vk_desc->encode_op);
773+ if (!ctx->qf_enc) {
776774 av_log(avctx, AV_LOG_ERROR, "Encoding of %s is not supported by this device\n",
777775 avcodec_get_name(avctx->codec_id));
778776 return err;
@@ -846,7 +844,7 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, FFVulkanEncodeContext * · 67 unmodified lines
846844 .encodeFeedbackFlags = ctx->enc_caps.supportedEncodeFeedbackFlags &
847845 (~VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_HAS_OVERRIDES_BIT_KHR),
848846 };
849− err = ff_vk_exec_pool_init(s, &ctx->qf_enc, &ctx->enc_pool, base_ctx->async_depth,
847+ err = ff_vk_exec_pool_init(s, ctx->qf_enc, &ctx->enc_pool, base_ctx->async_depth,
850848 1, VK_QUERY_TYPE_VIDEO_ENCODE_FEEDBACK_KHR, 0,
851849 &query_create);
852850 if (err < 0)
@@ -994,7 +992,7 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, FFVulkanEncodeContext * · 141 unmodified lines
994992 /* Create session */
995993 session_create.pVideoProfile = &ctx->profile;
996994 session_create.flags = 0x0;
997− session_create.queueFamilyIndex = ctx->qf_enc.queue_family;
995+ session_create.queueFamilyIndex = ctx->qf_enc->idx;
998996 session_create.maxCodedExtent = ctx->caps.maxCodedExtent;
999997 session_create.maxDpbSlots = ctx->caps.maxDpbSlots;
1000998 session_create.maxActiveReferencePictures = ctx->caps.maxActiveReferencePictures;
libavcodec/vulkan_encode.h+1−1
@@ -188,7 +188,7 @@ typedef struct FFVulkanEncodeContext { · 187 unmodified lines
188188 VkVideoEncodeCapabilitiesKHR enc_caps;
189189 VkVideoEncodeUsageInfoKHR usage_info;
190190
191− FFVkQueueFamilyCtx qf_enc;
191+ AVVulkanDeviceQueueFamily *qf_enc;
192192 FFVkExecPool enc_pool;
193193
194194 FFHWBaseEncodePicture *slots[32];
libavcodec/vulkan_video.c+0−14
@@ -268,20 +268,6 @@ int ff_vk_h265_profile_to_av(StdVideoH264ProfileIdc profile) · 267 unmodified lines
268268 }
269269 }
270270
271−int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
272− VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps)
273−{
274− for (int i = 0; i < s->hwctx->nb_qf; i++) {
275− if ((s->hwctx->qf[i].flags & family) &&
276− (s->hwctx->qf[i].video_caps & caps)) {
277− qf->queue_family = s->hwctx->qf[i].idx;
278− qf->nb_queues = s->hwctx->qf[i].num;
279− return 0;
280− }
281− }
282− return AVERROR(ENOTSUP);
283−}
284−
285271 int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common,
286272 VkImageView *view, VkImageAspectFlags *aspect,
287273 AVVkFrame *src, VkFormat vkf, int is_dpb)
libavcodec/vulkan_video.h+0−6
@@ -63,12 +63,6 @@ VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFm · 62 unmodified lines
6363 */
6464 VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
6565
66−/**
67− * Chooses a QF and loads it into a context.
68− */
69−int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
70− VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps);
71−
7266 /**
7367 * Convert level from Vulkan to AV.
7468 */
libavfilter/vf_avgblur_vulkan.c+9−3
@@ -31,7 +31,7 @@ typedef struct AvgBlurVulkanContext { · 30 unmodified lines
3131
3232 int initialized;
3333 FFVkExecPool e;
34− FFVkQueueFamilyCtx qf;
34+ AVVulkanDeviceQueueFamily *qf;
3535 VkSampler sampler;
3636 FFVulkanShader shd;
3737
@@ -77,8 +77,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 39 unmodified lines
7777 return AVERROR_EXTERNAL;
7878 }
7979
80− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
81− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
80+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
81+ if (!s->qf) {
82+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
83+ err = AVERROR(ENOTSUP);
84+ goto fail;
85+ }
86+
87+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
8288 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_LINEAR));
8389 RET(ff_vk_shader_init(vkctx, &s->shd, "avgblur",
8490 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_blend_vulkan.c+9−3
@@ -47,7 +47,7 @@ typedef struct BlendVulkanContext { · 46 unmodified lines
4747
4848 int initialized;
4949 FFVkExecPool e;
50− FFVkQueueFamilyCtx qf;
50+ AVVulkanDeviceQueueFamily *qf;
5151 FFVulkanShader shd;
5252 VkSampler sampler;
5353
@@ -141,8 +141,14 @@ static av_cold int init_filter(AVFilterContext *avctx) · 87 unmodified lines
141141 return AVERROR_EXTERNAL;
142142 }
143143
144− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
145− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
144+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
145+ if (!s->qf) {
146+ av_log(avctx, AV_LOG_ERROR, "Device has no compute queues\n");
147+ err = AVERROR(ENOTSUP);
148+ goto fail;
149+ }
150+
151+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
146152 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
147153 RET(ff_vk_shader_init(vkctx, &s->shd, "blend",
148154 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_bwdif_vulkan.c+9−3
@@ -33,7 +33,7 @@ typedef struct BWDIFVulkanContext { · 32 unmodified lines
3333
3434 int initialized;
3535 FFVkExecPool e;
36− FFVkQueueFamilyCtx qf;
36+ AVVulkanDeviceQueueFamily *qf;
3737 VkSampler sampler;
3838 FFVulkanShader shd;
3939 } BWDIFVulkanContext;
@@ -65,8 +65,14 @@ static av_cold int init_filter(AVFilterContext *ctx) · 25 unmodified lines
6565 return AVERROR_EXTERNAL;
6666 }
6767
68− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
69− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
68+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
69+ if (!s->qf) {
70+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
71+ err = AVERROR(ENOTSUP);
72+ goto fail;
73+ }
74+
75+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
7076 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
7177
7278 RET(ff_vk_shader_init(vkctx, &s->shd, "bwdif",
libavfilter/vf_chromaber_vulkan.c+9−3
@@ -31,7 +31,7 @@ typedef struct ChromaticAberrationVulkanContext { · 30 unmodified lines
3131
3232 int initialized;
3333 FFVkExecPool e;
34− FFVkQueueFamilyCtx qf;
34+ AVVulkanDeviceQueueFamily *qf;
3535 FFVulkanShader shd;
3636 VkSampler sampler;
3737
@@ -88,8 +88,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 50 unmodified lines
8888 return AVERROR_EXTERNAL;
8989 }
9090
91− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
92− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
91+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
92+ if (!s->qf) {
93+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
94+ err = AVERROR(ENOTSUP);
95+ goto fail;
96+ }
97+
98+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
9399 RET(ff_vk_init_sampler(vkctx, &s->sampler, 0, VK_FILTER_LINEAR));
94100 RET(ff_vk_shader_init(vkctx, &s->shd, "chromatic_abberation",
95101 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_flip_vulkan.c+9−3
@@ -38,7 +38,7 @@ typedef struct FlipVulkanContext { · 37 unmodified lines
3838
3939 int initialized;
4040 FFVkExecPool e;
41− FFVkQueueFamilyCtx qf;
41+ AVVulkanDeviceQueueFamily *qf;
4242 FFVulkanShader shd;
4343 VkSampler sampler;
4444 } FlipVulkanContext;
@@ -62,8 +62,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in, enum FlipType · 17 unmodified lines
6262 return AVERROR_EXTERNAL;
6363 }
6464
65− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
66− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
65+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
66+ if (!s->qf) {
67+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
68+ err = AVERROR(ENOTSUP);
69+ goto fail;
70+ }
71+
72+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
6773 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_LINEAR));
6874 RET(ff_vk_shader_init(vkctx, &s->shd, "flip",
6975 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_gblur_vulkan.c+9−3
@@ -36,7 +36,7 @@ typedef struct GBlurVulkanContext { · 35 unmodified lines
3636
3737 int initialized;
3838 FFVkExecPool e;
39− FFVkQueueFamilyCtx qf;
39+ AVVulkanDeviceQueueFamily *qf;
4040 VkSampler sampler;
4141 FFVulkanShader shd_hor;
4242 FFVkBuffer params_hor;
@@ -212,8 +212,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 169 unmodified lines
212212 return AVERROR_EXTERNAL;
213213 }
214214
215− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
216− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
215+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
216+ if (!s->qf) {
217+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
218+ err = AVERROR(ENOTSUP);
219+ goto fail;
220+ }
221+
222+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
217223 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_LINEAR));
218224
219225 desc = (FFVulkanDescriptorSetBinding []) {
libavfilter/vf_nlmeans_vulkan.c+9−3
@@ -36,7 +36,7 @@ typedef struct NLMeansVulkanContext { · 35 unmodified lines
3636
3737 int initialized;
3838 FFVkExecPool e;
39− FFVkQueueFamilyCtx qf;
39+ AVVulkanDeviceQueueFamily *qf;
4040 VkSampler sampler;
4141
4242 AVBufferPool *integral_buf_pool;
@@ -652,8 +652,14 @@ static av_cold int init_filter(AVFilterContext *ctx) · 609 unmodified lines
652652 return AVERROR_EXTERNAL;
653653 }
654654
655− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
656− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, 1, 0, 0, 0, NULL));
655+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
656+ if (!s->qf) {
657+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
658+ err = AVERROR(ENOTSUP);
659+ goto fail;
660+ }
661+
662+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, 1, 0, 0, 0, NULL));
657663 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
658664
659665 RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights, s->sampler,
libavfilter/vf_overlay_vulkan.c+9−3
@@ -33,7 +33,7 @@ typedef struct OverlayVulkanContext { · 32 unmodified lines
3333
3434 int initialized;
3535 FFVkExecPool e;
36− FFVkQueueFamilyCtx qf;
36+ AVVulkanDeviceQueueFamily *qf;
3737 FFVulkanShader shd;
3838 VkSampler sampler;
3939
@@ -101,8 +101,14 @@ static av_cold int init_filter(AVFilterContext *ctx) · 61 unmodified lines
101101 return AVERROR_EXTERNAL;
102102 }
103103
104− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
105− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
104+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
105+ if (!s->qf) {
106+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
107+ err = AVERROR(ENOTSUP);
108+ goto fail;
109+ }
110+
111+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
106112 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
107113 RET(ff_vk_shader_init(vkctx, &s->shd, "overlay",
108114 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_scale_vulkan.c+9−3
@@ -39,7 +39,7 @@ typedef struct ScaleVulkanContext { · 38 unmodified lines
3939
4040 int initialized;
4141 FFVkExecPool e;
42− FFVkQueueFamilyCtx qf;
42+ AVVulkanDeviceQueueFamily *qf;
4343 FFVulkanShader shd;
4444 VkSampler sampler;
4545
@@ -142,8 +142,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 96 unmodified lines
142142 return AVERROR_EXTERNAL;
143143 }
144144
145− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
146− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
145+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
146+ if (!s->qf) {
147+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
148+ err = AVERROR(ENOTSUP);
149+ goto fail;
150+ }
151+
152+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
147153 RET(ff_vk_init_sampler(vkctx, &s->sampler, 0, sampler_mode));
148154 RET(ff_vk_shader_init(vkctx, &s->shd, "scale",
149155 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_transpose_vulkan.c+9−3
@@ -33,7 +33,7 @@ typedef struct TransposeVulkanContext { · 32 unmodified lines
3333
3434 int initialized;
3535 FFVkExecPool e;
36− FFVkQueueFamilyCtx qf;
36+ AVVulkanDeviceQueueFamily *qf;
3737 FFVulkanShader shd;
3838 VkSampler sampler;
3939
@@ -61,8 +61,14 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 21 unmodified lines
6161 return AVERROR_EXTERNAL;
6262 }
6363
64− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
65− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
64+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
65+ if (!s->qf) {
66+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
67+ err = AVERROR(ENOTSUP);
68+ goto fail;
69+ }
70+
71+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
6672 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_LINEAR));
6773 RET(ff_vk_shader_init(vkctx, &s->shd, "transpose",
6874 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vf_xfade_vulkan.c+9−3
@@ -41,7 +41,7 @@ typedef struct XFadeVulkanContext { · 40 unmodified lines
4141
4242 int initialized;
4343 FFVkExecPool e;
44− FFVkQueueFamilyCtx qf;
44+ AVVulkanDeviceQueueFamily *qf;
4545 FFVulkanShader shd;
4646 VkSampler sampler;
4747
@@ -335,8 +335,14 @@ static av_cold int init_vulkan(AVFilterContext *avctx) · 287 unmodified lines
335335 return AVERROR_EXTERNAL;
336336 }
337337
338− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
339− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
338+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
339+ if (!s->qf) {
340+ av_log(avctx, AV_LOG_ERROR, "Device has no compute queues\n");
341+ err = AVERROR(ENOTSUP);
342+ goto fail;
343+ }
344+
345+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
340346 RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
341347 RET(ff_vk_shader_init(vkctx, &s->shd, "xfade",
342348 VK_SHADER_STAGE_COMPUTE_BIT,
libavfilter/vsrc_testsrc_vulkan.c+9−3
@@ -40,7 +40,7 @@ typedef struct TestSrcVulkanContext { · 39 unmodified lines
4040
4141 int initialized;
4242 FFVkExecPool e;
43− FFVkQueueFamilyCtx qf;
43+ AVVulkanDeviceQueueFamily *qf;
4444 FFVulkanShader shd;
4545
4646 /* Only used by color_vulkan */
@@ -82,8 +82,14 @@ static av_cold int init_filter(AVFilterContext *ctx, enum TestSrcVulkanMode mode · 35 unmodified lines
8282 return AVERROR_EXTERNAL;
8383 }
8484
85− ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
86− RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
85+ s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
86+ if (!s->qf) {
87+ av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
88+ err = AVERROR(ENOTSUP);
89+ goto fail;
90+ }
91+
92+ RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
8793 RET(ff_vk_shader_init(vkctx, &s->shd, "scale",
8894 VK_SHADER_STAGE_COMPUTE_BIT,
8995 NULL, 0,
libavutil/hwcontext_vulkan.c+10−10
@@ -104,8 +104,8 @@ typedef struct VulkanDevicePriv { · 103 unmodified lines
104104 void *libvulkan;
105105
106106 FFVulkanContext vkctx;
107− FFVkQueueFamilyCtx compute_qf;
108− FFVkQueueFamilyCtx transfer_qf;
107+ AVVulkanDeviceQueueFamily *compute_qf;
108+ AVVulkanDeviceQueueFamily *transfer_qf;
109109
110110 /* Properties */
111111 VkPhysicalDeviceProperties2 props;
@@ -1904,8 +1904,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1792 unmodified lines
19041904 p->vkctx.hwctx = hwctx;
19051905
19061906 ff_vk_load_props(&p->vkctx);
1907− ff_vk_qf_init(&p->vkctx, &p->compute_qf, VK_QUEUE_COMPUTE_BIT);
1908− ff_vk_qf_init(&p->vkctx, &p->transfer_qf, VK_QUEUE_TRANSFER_BIT);
1907+ p->compute_qf = ff_vk_qf_find(&p->vkctx, VK_QUEUE_COMPUTE_BIT, 0);
1908+ p->transfer_qf = ff_vk_qf_find(&p->vkctx, VK_QUEUE_TRANSFER_BIT, 0);
19091909
19101910 end:
19111911 av_free(qf_vid);
@@ -2789,18 +2789,18 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) · 877 unmodified lines
27892789 if (!hwctx->unlock_frame)
27902790 hwctx->unlock_frame = unlock_frame;
27912791
2792− err = ff_vk_exec_pool_init(&p->vkctx, &p->compute_qf, &fp->compute_exec,
2793− p->compute_qf.nb_queues, 0, 0, 0, NULL);
2792+ err = ff_vk_exec_pool_init(&p->vkctx, p->compute_qf, &fp->compute_exec,
2793+ p->compute_qf->num, 0, 0, 0, NULL);
27942794 if (err)
27952795 return err;
27962796
2797− err = ff_vk_exec_pool_init(&p->vkctx, &p->transfer_qf, &fp->upload_exec,
2798− p->transfer_qf.nb_queues*2, 0, 0, 0, NULL);
2797+ err = ff_vk_exec_pool_init(&p->vkctx, p->transfer_qf, &fp->upload_exec,
2798+ p->transfer_qf->num*2, 0, 0, 0, NULL);
27992799 if (err)
28002800 return err;
28012801
2802− err = ff_vk_exec_pool_init(&p->vkctx, &p->transfer_qf, &fp->download_exec,
2803− p->transfer_qf.nb_queues, 0, 0, 0, NULL);
2802+ err = ff_vk_exec_pool_init(&p->vkctx, p->transfer_qf, &fp->download_exec,
2803+ p->transfer_qf->num, 0, 0, 0, NULL);
28042804 if (err)
28052805 return err;
28062806
libavutil/vulkan.c+12−22
@@ -217,26 +217,17 @@ int ff_vk_load_props(FFVulkanContext *s) · 216 unmodified lines
217217 return 0;
218218 }
219219
220−static int vk_qf_get_index(FFVulkanContext *s, VkQueueFlagBits dev_family, int *nb)
220+AVVulkanDeviceQueueFamily *ff_vk_qf_find(FFVulkanContext *s,
221+ VkQueueFlagBits dev_family,
222+ VkVideoCodecOperationFlagBitsKHR vid_ops)
221223 {
222224 for (int i = 0; i < s->hwctx->nb_qf; i++) {
223− if (s->hwctx->qf[i].flags & dev_family) {
224− *nb = s->hwctx->qf[i].num;
225− return s->hwctx->qf[i].idx;
225+ if ((s->hwctx->qf[i].flags & dev_family) &&
226+ (s->hwctx->qf[i].video_caps & vid_ops) == vid_ops) {
227+ return &s->hwctx->qf[i];
226228 }
227229 }
228−
229− av_assert0(0); /* Should never happen */
230−}
231−
232−int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
233− VkQueueFlagBits dev_family)
234−{
235− /* Fill in queue families from context if not done yet */
236− if (!s->nb_qfs)
237− load_enabled_qfs(s);
238−
239− return (qf->queue_family = vk_qf_get_index(s, dev_family, &qf->nb_queues));
230+ return NULL;
240231 }
241232
242233 void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
@@ -302,7 +293,7 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool) · 59 unmodified lines
302293 av_free(pool->contexts);
303294 }
304295
305−int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
296+int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf,
306297 FFVkExecPool *pool, int nb_contexts,
307298 int nb_queries, VkQueryType query_type, int query_64bit,
308299 const void *query_create_pnext)
@@ -330,7 +321,7 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 21 unmodified lines
330321 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
331322 .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT |
332323 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
333− .queueFamilyIndex = qf->queue_family,
324+ .queueFamilyIndex = qf->idx,
334325 };
335326 ret = vk->CreateCommandPool(s->hwctx->act_dev, &cqueue_create,
336327 s->hwctx->alloc, &pool->cmd_buf_pool);
@@ -443,10 +434,9 @@ int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 106 unmodified lines
443434 e->buf = pool->cmd_bufs[i];
444435
445436 /* Queue index distribution */
446− e->qi = i % qf->nb_queues;
447− e->qf = qf->queue_family;
448− vk->GetDeviceQueue(s->hwctx->act_dev, qf->queue_family,
449− e->qi, &e->queue);
437+ e->qi = i % qf->num;
438+ e->qf = qf->idx;
439+ vk->GetDeviceQueue(s->hwctx->act_dev, qf->idx, e->qi, &e->queue);
450440 }
451441
452442 return 0;
libavutil/vulkan.h+5−9
@@ -99,11 +99,6 @@ typedef struct FFVkBuffer { · 98 unmodified lines
9999 uint8_t *mapped_mem;
100100 } FFVkBuffer;
101101
102−typedef struct FFVkQueueFamilyCtx {
103− int queue_family;
104− int nb_queues;
105−} FFVkQueueFamilyCtx;
106−
107102 typedef struct FFVkExecContext {
108103 uint32_t idx;
109104 const struct FFVkExecPool *parent;
@@ -393,10 +388,11 @@ const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, · 283 unmodified lines
393388 int ff_vk_load_props(FFVulkanContext *s);
394389
395390 /**
396− * Chooses a QF and loads it into a context.
391+ * Chooses an appropriate QF.
397392 */
398−int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
399− VkQueueFlagBits dev_family);
393+AVVulkanDeviceQueueFamily *ff_vk_qf_find(FFVulkanContext *s,
394+ VkQueueFlagBits dev_family,
395+ VkVideoCodecOperationFlagBitsKHR vid_ops);
400396
401397 /**
402398 * Allocates/frees an execution pool.
@@ -405,7 +401,7 @@ int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, · 2 unmodified lines
405401 * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add()
406402 * has been called.
407403 */
408−int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
404+int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf,
409405 FFVkExecPool *pool, int nb_contexts,
410406 int nb_queries, VkQueryType query_type, int query_64bit,
411407 const void *query_create_pnext);

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