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.
Unified · Split
| @@ -294,6 +294,7 @@ void ff_vk_decode_flush(AVCodecContext *avctx) · 293 unmodified lines | ||
| 294 | 294 | |
| 295 | 295 | VkCommandBuffer cmd_buf; |
| 296 | 296 | FFVkExecContext *exec = ff_vk_exec_get(&dec->exec_pool); |
| 297 | + int had_submission = exec->had_submission; | |
| 297 | 298 | ff_vk_exec_start(&ctx->s, exec); |
| 298 | 299 | cmd_buf = exec->buf; |
| 299 | 300 | |
| @@ -301,6 +302,11 @@ void ff_vk_decode_flush(AVCodecContext *avctx) · 1 unmodified line | ||
| 301 | 302 | vk->CmdControlVideoCodingKHR(cmd_buf, &decode_ctrl); |
| 302 | 303 | vk->CmdEndVideoCodingKHR(cmd_buf, &decode_end); |
| 303 | 304 | 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; | |
| 304 | 310 | } |
| 305 | 311 | |
| 306 | 312 | int ff_vk_decode_frame(AVCodecContext *avctx, |
| @@ -348,19 +354,20 @@ int ff_vk_decode_frame(AVCodecContext *avctx, · 41 unmodified lines | ||
| 348 | 354 | cur_vk_ref[0].slotIndex = -1; |
| 349 | 355 | decode_start.referenceSlotCount++; |
| 350 | 356 | |
| 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); | |
| 355 | 361 | if (ret != VK_NOT_READY && ret != VK_SUCCESS) { |
| 356 | 362 | av_log(avctx, AV_LOG_ERROR, "Unable to perform query: %s!\n", |
| 357 | 363 | ff_vk_ret2str(ret)); |
| 358 | 364 | return AVERROR_EXTERNAL; |
| 359 | 365 | } |
| 360 | 366 | |
| 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]); | |
| 364 | 371 | } |
| 365 | 372 | |
| 366 | 373 | sd_buf = (FFVkBuffer *)vp->slices_buf->data; |
| @@ -433,19 +433,12 @@ fail: · 432 unmodified lines | ||
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, |
| 436 | − void **data, int64_t *status) | |
| 436 | + void **data, VkQueryResultFlagBits flags) | |
| 437 | 437 | { |
| 438 | − VkResult ret; | |
| 439 | 438 | FFVulkanFunctions *vk = &s->vkfn; |
| 440 | 439 | 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); | |
| 449 | 442 | |
| 450 | 443 | if (!e->query_data) { |
| 451 | 444 | 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 | ||
| 457 | 450 | qf |= pool->query_statuses ? |
| 458 | 451 | VK_QUERY_RESULT_WITH_STATUS_BIT_KHR : 0x0; |
| 459 | 452 | |
| 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 | − | |
| 482 | 453 | if (data) |
| 483 | 454 | *data = e->query_data; |
| 484 | − if (status) | |
| 485 | − *status = res; | |
| 486 | 455 | |
| 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); | |
| 488 | 461 | } |
| 489 | 462 | |
| 490 | 463 | FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool) |
| @@ -357,10 +357,11 @@ FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool); · 356 unmodified lines | ||
| 357 | 357 | |
| 358 | 358 | /** |
| 359 | 359 | * 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. | |
| 361 | 362 | */ |
| 362 | 363 | VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, |
| 363 | − void **data, int64_t *status); | |
| 364 | + void **data, VkQueryResultFlagBits flags); | |
| 364 | 365 | |
| 365 | 366 | /** |
| 366 | 367 | * Start/submit/wait an execution. |