• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2023 Raspberry Pi Ltd
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include "v3dv_private.h"
25 
26 #include "common/v3d_performance_counters.h"
27 
28 VkResult
v3dX(enumerate_performance_query_counters)29 v3dX(enumerate_performance_query_counters)(uint32_t *pCounterCount,
30                                            VkPerformanceCounterKHR *pCounters,
31                                            VkPerformanceCounterDescriptionKHR *pCounterDescriptions)
32 {
33    uint32_t desc_count = *pCounterCount;
34 
35    VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterKHR,
36                           out, pCounters, pCounterCount);
37    VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterDescriptionKHR,
38                           out_desc, pCounterDescriptions, &desc_count);
39 
40    for (int i = 0; i < ARRAY_SIZE(v3d_performance_counters); i++) {
41       vk_outarray_append_typed(VkPerformanceCounterKHR, &out, counter) {
42          counter->unit = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR;
43          counter->scope = VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR;
44          counter->storage = VK_PERFORMANCE_COUNTER_STORAGE_UINT64_KHR;
45 
46          unsigned char sha1_result[20];
47          _mesa_sha1_compute(v3d_performance_counters[i][V3D_PERFCNT_NAME],
48                             strlen(v3d_performance_counters[i][V3D_PERFCNT_NAME]),
49                             sha1_result);
50 
51          memcpy(counter->uuid, sha1_result, sizeof(counter->uuid));
52       }
53 
54       vk_outarray_append_typed(VkPerformanceCounterDescriptionKHR,
55                                &out_desc, desc) {
56          desc->flags = 0;
57          snprintf(desc->name, sizeof(desc->name), "%s",
58             v3d_performance_counters[i][V3D_PERFCNT_NAME]);
59          snprintf(desc->category, sizeof(desc->category), "%s",
60             v3d_performance_counters[i][V3D_PERFCNT_CATEGORY]);
61          snprintf(desc->description, sizeof(desc->description), "%s",
62             v3d_performance_counters[i][V3D_PERFCNT_DESCRIPTION]);
63       }
64    }
65 
66    return vk_outarray_status(&out);
67 }
68