@@ -489,19 +489,19 @@ ze_result_t MetricQueryImp::appendBegin(CommandList &commandList) {
489489
490490 switch (pool.description .flags ) {
491491 case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE:
492- return writeMetricQuery (commandList, nullptr , true );
492+ return writeMetricQuery (commandList, nullptr , 0 , nullptr , true );
493493
494494 default :
495495 DEBUG_BREAK_IF (true );
496496 return ZE_RESULT_ERROR_INVALID_ARGUMENT;
497497 }
498498}
499499
500- ze_result_t MetricQueryImp::appendEnd (CommandList &commandList,
501- ze_event_handle_t hCompletionEvent ) {
500+ ze_result_t MetricQueryImp::appendEnd (CommandList &commandList, ze_event_handle_t hSignalEvent,
501+ uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents ) {
502502 switch (pool.description .flags ) {
503503 case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE:
504- return writeMetricQuery (commandList, hCompletionEvent , false );
504+ return writeMetricQuery (commandList, hSignalEvent, numWaitEvents, phWaitEvents , false );
505505
506506 default :
507507 DEBUG_BREAK_IF (true );
@@ -529,8 +529,13 @@ ze_result_t MetricQueryImp::destroy() {
529529 return ZE_RESULT_SUCCESS;
530530}
531531
532- ze_result_t MetricQueryImp::writeMetricQuery (CommandList &commandList,
533- ze_event_handle_t hCompletionEvent, const bool begin) {
532+ ze_result_t MetricQueryImp::writeMetricQuery (CommandList &commandList, ze_event_handle_t hSignalEvent,
533+ uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents,
534+ const bool begin) {
535+
536+ bool writeCompletionEvent = hSignalEvent && !begin;
537+ bool result = false ;
538+
534539 // Make gpu allocation visible.
535540 commandList.commandContainer .addToResidencyContainer (pool.pAllocation );
536541
@@ -546,12 +551,18 @@ ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList,
546551 ? GpuCommandBufferType::Compute
547552 : GpuCommandBufferType::Render;
548553
549- bool writeCompletionEvent = hCompletionEvent && !begin;
550- bool result = metricsLibrary.getGpuCommands (commandList, commandBuffer);
554+ // Wait for events before executing query.
555+ result = zeCommandListAppendWaitOnEvents (commandList.toHandle (), numWaitEvents, phWaitEvents) ==
556+ ZE_RESULT_SUCCESS;
557+
558+ // Get query commands.
559+ if (result) {
560+ result = metricsLibrary.getGpuCommands (commandList, commandBuffer);
561+ }
551562
552563 // Write completion event.
553564 if (result && writeCompletionEvent) {
554- result = zeCommandListAppendSignalEvent (commandList.toHandle (), hCompletionEvent ) ==
565+ result = zeCommandListAppendSignalEvent (commandList.toHandle (), hSignalEvent ) ==
555566 ZE_RESULT_SUCCESS;
556567 }
557568
0 commit comments