1 /*
2 * Copyright © 2022 Collabora, 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 "vk_query_pool.h"
25
26 #include "vk_alloc.h"
27 #include "vk_command_buffer.h"
28 #include "vk_common_entrypoints.h"
29 #include "vk_device.h"
30
31 void
vk_query_pool_init(struct vk_device * device,struct vk_query_pool * query_pool,const VkQueryPoolCreateInfo * pCreateInfo)32 vk_query_pool_init(struct vk_device *device,
33 struct vk_query_pool *query_pool,
34 const VkQueryPoolCreateInfo *pCreateInfo)
35 {
36 vk_object_base_init(device, &query_pool->base, VK_OBJECT_TYPE_QUERY_POOL);
37
38 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO);
39
40 query_pool->query_type = pCreateInfo->queryType;
41 query_pool->query_count = pCreateInfo->queryCount;
42 query_pool->pipeline_statistics =
43 pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS ?
44 pCreateInfo->pipelineStatistics : 0;
45 }
46
47 void *
vk_query_pool_create(struct vk_device * device,const VkQueryPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * alloc,size_t size)48 vk_query_pool_create(struct vk_device *device,
49 const VkQueryPoolCreateInfo *pCreateInfo,
50 const VkAllocationCallbacks *alloc,
51 size_t size)
52 {
53 struct vk_query_pool *query_pool =
54 vk_zalloc2(&device->alloc, alloc, size, 8,
55 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
56 if (query_pool == NULL)
57 return NULL;
58
59 vk_query_pool_init(device, query_pool, pCreateInfo);
60
61 return query_pool;
62 }
63
64 void
vk_query_pool_finish(struct vk_query_pool * query_pool)65 vk_query_pool_finish(struct vk_query_pool *query_pool)
66 {
67 vk_object_base_finish(&query_pool->base);
68 }
69
70 void
vk_query_pool_destroy(struct vk_device * device,const VkAllocationCallbacks * alloc,struct vk_query_pool * query_pool)71 vk_query_pool_destroy(struct vk_device *device,
72 const VkAllocationCallbacks *alloc,
73 struct vk_query_pool *query_pool)
74 {
75 vk_object_free(device, alloc, query_pool);
76 }
77
78 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdBeginQuery(VkCommandBuffer commandBuffer,VkQueryPool queryPool,uint32_t query,VkQueryControlFlags flags)79 vk_common_CmdBeginQuery(VkCommandBuffer commandBuffer,
80 VkQueryPool queryPool,
81 uint32_t query,
82 VkQueryControlFlags flags)
83 {
84 VK_FROM_HANDLE(vk_command_buffer, cmd_buffer, commandBuffer);
85 const struct vk_device_dispatch_table *disp =
86 &cmd_buffer->base.device->dispatch_table;
87
88 disp->CmdBeginQueryIndexedEXT(commandBuffer, queryPool, query, flags, 0);
89 }
90
91 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdEndQuery(VkCommandBuffer commandBuffer,VkQueryPool queryPool,uint32_t query)92 vk_common_CmdEndQuery(VkCommandBuffer commandBuffer,
93 VkQueryPool queryPool,
94 uint32_t query)
95 {
96 VK_FROM_HANDLE(vk_command_buffer, cmd_buffer, commandBuffer);
97 const struct vk_device_dispatch_table *disp =
98 &cmd_buffer->base.device->dispatch_table;
99
100 disp->CmdEndQueryIndexedEXT(commandBuffer, queryPool, query, 0);
101 }
102