History

vulkan(_decode): fix, simplify and improve queries

The old query code never worked properly, and did some hideous heuristics to read the status bit, and work that into a return code. This is all best left to callers to do, which simplifies our code a lot. This also fixes minor validation errors regarding calling queries which are not in their active state.

Lynne committed 2 years ago

Commit 5e9845f1 parent 3415e053 files · +25 −44Browse files

Unified · Split

3 files
  1. libavcodec/vulkan_decode.c +14 −7
  2. libavutil/vulkan.c +8 −35
  3. libavutil/vulkan.h +3 −2
libavcodec/vulkan_decode.c+14−7
@@ -294,6 +294,7 @@ void ff_vk_decode_flush(AVCodecContext *avctx) · 293 unmodified lines
294294
295295 VkCommandBuffer cmd_buf;
296296 FFVkExecContext *exec = ff_vk_exec_get(&dec->exec_pool);
297+ int had_submission = exec->had_submission;
297298 ff_vk_exec_start(&ctx->s, exec);
298299 cmd_buf = exec->buf;
299300
@@ -301,6 +302,11 @@ void ff_vk_decode_flush(AVCodecContext *avctx) · 1 unmodified line
301302 vk->CmdControlVideoCodingKHR(cmd_buf, &decode_ctrl);
302303 vk->CmdEndVideoCodingKHR(cmd_buf, &decode_end);
303304 ff_vk_exec_submit(&ctx->s, exec);
305+
306+ /* If this is the very first time this context is used, then remove the
307+ * had_submission flag to indicate that no query result is available,
308+ * as no decode command was issued. */
309+ exec->had_submission = had_submission;
304310 }
305311
306312 int ff_vk_decode_frame(AVCodecContext *avctx,
@@ -348,19 +354,20 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 41 unmodified lines
348354 cur_vk_ref[0].slotIndex = -1;
349355 decode_start.referenceSlotCount++;
350356
351− if (dec->exec_pool.nb_queries) {
352− int64_t prev_sub_res = 0;
353− ff_vk_exec_wait(&ctx->s, exec);
354− ret = ff_vk_exec_get_query(&ctx->s, exec, NULL, &prev_sub_res);
357+ if (dec->exec_pool.nb_queries && exec->had_submission) {
358+ uint32_t *result;
359+ ret = ff_vk_exec_get_query(&ctx->s, exec, (void **)&result,
360+ VK_QUERY_RESULT_WAIT_BIT);
355361 if (ret != VK_NOT_READY && ret != VK_SUCCESS) {
356362 av_log(avctx, AV_LOG_ERROR, "Unable to perform query: %s!\n",
357363 ff_vk_ret2str(ret));
358364 return AVERROR_EXTERNAL;
359365 }
360366
361− if (ret == VK_SUCCESS)
362− av_log(avctx, prev_sub_res < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
363− "Result of previous frame decoding: %"PRId64"\n", prev_sub_res);
367+ av_log(avctx,
368+ result[0] != VK_QUERY_RESULT_STATUS_COMPLETE_KHR ?
369+ AV_LOG_ERROR : AV_LOG_DEBUG,
370+ "Result of previous frame decoding: %u\n", result[0]);
364371 }
365372
366373 sd_buf = (FFVkBuffer *)vp->slices_buf->data;
libavutil/vulkan.c+8−35
@@ -433,19 +433,12 @@ fail: · 432 unmodified lines
433433 }
434434
435435 VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e,
436− void **data, int64_t *status)
436+ void **data, VkQueryResultFlagBits flags)
437437 {
438− VkResult ret;
439438 FFVulkanFunctions *vk = &s->vkfn;
440439 const FFVkExecPool *pool = e->parent;
441−
442− int32_t *res32 = e->query_data;
443− int64_t *res64 = e->query_data;
444− int64_t res = 0;
445− VkQueryResultFlags qf = 0;
446−
447− if (!e->had_submission)
448− return VK_INCOMPLETE;
440+ VkQueryResultFlags qf = flags & ~(VK_QUERY_RESULT_64_BIT |
441+ VK_QUERY_RESULT_WITH_STATUS_BIT_KHR);
449442
450443 if (!e->query_data) {
451444 av_log(s, AV_LOG_ERROR, "Requested a query with a NULL query_data pointer!\n");
@@ -457,34 +450,14 @@ VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, · 5 unmodified lines
457450 qf |= pool->query_statuses ?
458451 VK_QUERY_RESULT_WITH_STATUS_BIT_KHR : 0x0;
459452
460− ret = vk->GetQueryPoolResults(s->hwctx->act_dev, pool->query_pool,
461− e->query_idx,
462− pool->nb_queries,
463− pool->qd_size, e->query_data,
464− pool->qd_size, qf);
465− if (ret != VK_SUCCESS)
466− return ret;
467−
468− if (pool->query_statuses && pool->query_64bit) {
469− for (int i = 0; i < pool->query_statuses; i++) {
470− res = (res64[i] < res) || (res >= 0 && res64[i] > res) ?
471− res64[i] : res;
472− res64 += pool->query_status_stride;
473− }
474− } else if (pool->query_statuses) {
475− for (int i = 0; i < pool->query_statuses; i++) {
476− res = (res32[i] < res) || (res >= 0 && res32[i] > res) ?
477− res32[i] : res;
478− res32 += pool->query_status_stride;
479− }
480− }
481−
482453 if (data)
483454 *data = e->query_data;
484− if (status)
485− *status = res;
486455
487− return VK_SUCCESS;
456+ return vk->GetQueryPoolResults(s->hwctx->act_dev, pool->query_pool,
457+ e->query_idx,
458+ pool->nb_queries,
459+ pool->qd_size, e->query_data,
460+ pool->qd_size, qf);
488461 }
489462
490463 FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool)
libavutil/vulkan.h+3−2
@@ -357,10 +357,11 @@ FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool); · 356 unmodified lines
357357
358358 /**
359359 * Performs nb_queries queries and returns their results and statuses.
360− * Execution must have been waited on to produce valid results.
360+ * 64_BIT and WITH_STATUS flags are ignored as 64_BIT must be specified via
361+ * query_64bit in ff_vk_exec_pool_init() and WITH_STATUS is always enabled.
361362 */
362363 VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e,
363− void **data, int64_t *status);
364+ void **data, VkQueryResultFlagBits flags);
364365
365366 /**
366367 * Start/submit/wait an execution.

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