| 25 | namespace vkb |
| 26 | { |
| 27 | VulkanStatsProvider::VulkanStatsProvider(std::set<StatIndex> &requested_stats, |
| 28 | const CounterSamplingConfig &sampling_config, |
| 29 | vkb::rendering::RenderContextC &render_context) : |
| 30 | render_context(render_context) |
| 31 | { |
| 32 | // Check all the Vulkan capabilities we require are present |
| 33 | if (!is_supported(sampling_config)) |
| 34 | { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | vkb::core::DeviceC &device = render_context.get_device(); |
| 39 | vkb::core::PhysicalDeviceC const &gpu = device.get_gpu(); |
| 40 | |
| 41 | has_timestamps = gpu.get_properties().limits.timestampComputeAndGraphics; |
| 42 | timestamp_period = gpu.get_properties().limits.timestampPeriod; |
| 43 | |
| 44 | // Interrogate device for supported stats |
| 45 | uint32_t queue_family_index = vkb::get_queue_family_index(gpu.get_queue_family_properties(), VK_QUEUE_GRAPHICS_BIT); |
| 46 | |
| 47 | std::vector<VkPerformanceCounterKHR> counters; |
| 48 | std::vector<VkPerformanceCounterDescriptionKHR> descs; |
| 49 | std::tie(counters, descs) = gpu.enumerate_queue_family_performance_query_counters(queue_family_index); |
| 50 | assert(counters.size() == descs.size()); |
| 51 | if (counters.size() == 0 || descs.size() == 0) |
| 52 | { |
| 53 | return; // No counters available |
| 54 | } |
| 55 | |
| 56 | // Every vendor has a different set of performance counters each |
| 57 | // with different names. Match them to the stats we want, where available. |
| 58 | if (!fill_vendor_data()) |
| 59 | { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | bool performance_impact = false; |
| 64 | |
| 65 | // Now build stat_data by matching vendor_data to Vulkan counter data |
| 66 | for (auto &s : vendor_data) |
| 67 | { |
| 68 | StatIndex index = s.first; |
| 69 | |
| 70 | if (requested_stats.find(index) == requested_stats.end()) |
| 71 | { |
| 72 | continue; // We weren't asked for this stat |
| 73 | } |
| 74 | |
| 75 | VendorStat &init = s.second; |
| 76 | bool found_ctr = false; |
| 77 | bool found_div = (init.divisor_name == ""); |
| 78 | uint32_t ctr_idx, div_idx; |
| 79 | |
| 80 | std::regex name_regex(init.name); |
| 81 | std::regex div_regex(init.divisor_name); |
| 82 | |
| 83 | for (uint32_t i = 0; !(found_ctr && found_div) && i < descs.size(); i++) |
| 84 | { |
nothing calls this directly
no test coverage detected