| 415 | } |
| 416 | |
| 417 | StatsProvider::Counters VulkanStatsProvider::sample(float delta_time) |
| 418 | { |
| 419 | Counters out; |
| 420 | if (!query_pool || queries_ready == 0) |
| 421 | { |
| 422 | return out; |
| 423 | } |
| 424 | |
| 425 | uint32_t active_frame_idx = render_context.get_active_frame_index(); |
| 426 | |
| 427 | VkDeviceSize stride = sizeof(VkPerformanceCounterResultKHR) * counter_indices.size(); |
| 428 | |
| 429 | std::vector<VkPerformanceCounterResultKHR> results(counter_indices.size()); |
| 430 | |
| 431 | VkResult r = query_pool->get_results(active_frame_idx, 1, |
| 432 | results.size() * sizeof(VkPerformanceCounterResultKHR), |
| 433 | results.data(), stride, VK_QUERY_RESULT_WAIT_BIT); |
| 434 | if (r != VK_SUCCESS) |
| 435 | { |
| 436 | return out; |
| 437 | } |
| 438 | |
| 439 | // Use timestamps to get a more accurate delta if available |
| 440 | delta_time = get_best_delta_time(delta_time); |
| 441 | |
| 442 | // Parse the results - they are in the order we gave in counter_indices |
| 443 | for (const auto &s : stat_data) |
| 444 | { |
| 445 | StatIndex si = s.first; |
| 446 | |
| 447 | bool need_divisor = (stat_data[si].scaling == StatScaling::ByCounter); |
| 448 | double divisor_value = 1.0; |
| 449 | double value = 0.0; |
| 450 | bool found_ctr = false, found_div = !need_divisor; |
| 451 | |
| 452 | for (uint32_t i = 0; !(found_ctr && found_div) && i < counter_indices.size(); i++) |
| 453 | { |
| 454 | if (s.second.counter_index == counter_indices[i]) |
| 455 | { |
| 456 | value = get_counter_value(results[i], stat_data[si].storage); |
| 457 | found_ctr = true; |
| 458 | } |
| 459 | if (need_divisor && s.second.divisor_counter_index == counter_indices[i]) |
| 460 | { |
| 461 | divisor_value = get_counter_value(results[i], stat_data[si].divisor_storage); |
| 462 | found_div = true; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | if (found_ctr && found_div) |
| 467 | { |
| 468 | if (stat_data[si].scaling == StatScaling::ByDeltaTime && delta_time != 0.0) |
| 469 | { |
| 470 | value /= delta_time; |
| 471 | } |
| 472 | else if (stat_data[si].scaling == StatScaling::ByCounter && divisor_value != 0.0) |
| 473 | { |
| 474 | value /= divisor_value; |
no test coverage detected