2 * Copyrigh 2016 Red Hat Inc.
4 * Copyright © 2015 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 #include "tu_private.h"
34 #include "nir/nir_builder.h"
36 /* It seems like sample counts need to be copied over to 16-byte aligned
38 struct PACKED slot_value
{
43 struct PACKED occlusion_query_slot
{
44 struct slot_value available
; /* 0 when unavailable, 1 when available */
45 struct slot_value begin
;
46 struct slot_value end
;
47 struct slot_value result
;
51 tu_CreateQueryPool(VkDevice _device
,
52 const VkQueryPoolCreateInfo
*pCreateInfo
,
53 const VkAllocationCallbacks
*pAllocator
,
54 VkQueryPool
*pQueryPool
)
56 TU_FROM_HANDLE(tu_device
, device
, _device
);
57 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
);
58 assert(pCreateInfo
->queryCount
> 0);
61 switch (pCreateInfo
->queryType
) {
62 case VK_QUERY_TYPE_OCCLUSION
:
63 slot_size
= sizeof(struct occlusion_query_slot
);
65 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
66 case VK_QUERY_TYPE_TIMESTAMP
:
67 unreachable("Unimplemented query type");
69 assert(!"Invalid query type");
72 struct tu_query_pool
*pool
=
73 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pool
), 8,
74 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
77 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
79 VkResult result
= tu_bo_init_new(device
, &pool
->bo
,
80 pCreateInfo
->queryCount
* slot_size
);
81 if (result
!= VK_SUCCESS
) {
82 vk_free2(&device
->alloc
, pAllocator
, pool
);
86 result
= tu_bo_map(device
, &pool
->bo
);
87 if (result
!= VK_SUCCESS
) {
88 tu_bo_finish(device
, &pool
->bo
);
89 vk_free2(&device
->alloc
, pAllocator
, pool
);
93 /* Initialize all query statuses to unavailable */
94 memset(pool
->bo
.map
, 0, pool
->bo
.size
);
96 pool
->type
= pCreateInfo
->queryType
;
97 pool
->stride
= slot_size
;
98 pool
->size
= pCreateInfo
->queryCount
;
99 pool
->pipeline_statistics
= pCreateInfo
->pipelineStatistics
;
100 *pQueryPool
= tu_query_pool_to_handle(pool
);
106 tu_DestroyQueryPool(VkDevice _device
,
108 const VkAllocationCallbacks
*pAllocator
)
110 TU_FROM_HANDLE(tu_device
, device
, _device
);
111 TU_FROM_HANDLE(tu_query_pool
, pool
, _pool
);
116 tu_bo_finish(device
, &pool
->bo
);
117 vk_free2(&device
->alloc
, pAllocator
, pool
);
121 tu_GetQueryPoolResults(VkDevice _device
,
122 VkQueryPool queryPool
,
128 VkQueryResultFlags flags
)
134 tu_CmdCopyQueryPoolResults(VkCommandBuffer commandBuffer
,
135 VkQueryPool queryPool
,
139 VkDeviceSize dstOffset
,
141 VkQueryResultFlags flags
)
146 tu_CmdResetQueryPool(VkCommandBuffer commandBuffer
,
147 VkQueryPool queryPool
,
154 tu_CmdBeginQuery(VkCommandBuffer commandBuffer
,
155 VkQueryPool queryPool
,
157 VkQueryControlFlags flags
)
162 tu_CmdEndQuery(VkCommandBuffer commandBuffer
,
163 VkQueryPool queryPool
,
169 tu_CmdWriteTimestamp(VkCommandBuffer commandBuffer
,
170 VkPipelineStageFlagBits pipelineStage
,
171 VkQueryPool queryPool
,