2 * Copyright © 2019 Red Hat.
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:
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
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
24 #include "val_private.h"
25 #include "pipe/p_context.h"
27 VkResult
val_CreateQueryPool(
29 const VkQueryPoolCreateInfo
* pCreateInfo
,
30 const VkAllocationCallbacks
* pAllocator
,
31 VkQueryPool
* pQueryPool
)
33 VAL_FROM_HANDLE(val_device
, device
, _device
);
35 enum pipe_query_type pipeq
;
36 switch (pCreateInfo
->queryType
) {
37 case VK_QUERY_TYPE_OCCLUSION
:
38 pipeq
= PIPE_QUERY_OCCLUSION_COUNTER
;
40 case VK_QUERY_TYPE_TIMESTAMP
:
41 pipeq
= PIPE_QUERY_TIMESTAMP
;
44 return VK_ERROR_FEATURE_NOT_PRESENT
;
46 struct val_query_pool
*pool
;
47 uint32_t pool_size
= sizeof(*pool
) + pCreateInfo
->queryCount
* sizeof(struct pipe_query
*);
49 pool
= vk_zalloc2(&device
->alloc
, pAllocator
,
51 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
53 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
55 vk_object_base_init(&device
->vk
, &pool
->base
,
56 VK_OBJECT_TYPE_QUERY_POOL
);
57 pool
->type
= pCreateInfo
->queryType
;
58 pool
->count
= pCreateInfo
->queryCount
;
59 pool
->base_type
= pipeq
;
61 *pQueryPool
= val_query_pool_to_handle(pool
);
65 void val_DestroyQueryPool(
68 const VkAllocationCallbacks
* pAllocator
)
70 VAL_FROM_HANDLE(val_device
, device
, _device
);
71 VAL_FROM_HANDLE(val_query_pool
, pool
, _pool
);
76 for (unsigned i
= 0; i
< pool
->count
; i
++)
78 device
->queue
.ctx
->destroy_query(device
->queue
.ctx
, pool
->queries
[i
]);
79 vk_object_base_finish(&pool
->base
);
80 vk_free2(&device
->alloc
, pAllocator
, pool
);
83 VkResult
val_GetQueryPoolResults(
85 VkQueryPool queryPool
,
91 VkQueryResultFlags flags
)
93 VAL_FROM_HANDLE(val_device
, device
, _device
);
94 VAL_FROM_HANDLE(val_query_pool
, pool
, queryPool
);
95 VkResult vk_result
= VK_SUCCESS
;
97 val_DeviceWaitIdle(_device
);
99 for (unsigned i
= firstQuery
; i
< firstQuery
+ queryCount
; i
++) {
100 uint8_t *dptr
= (uint8_t *)((char *)pData
+ (stride
* (i
- firstQuery
)));
101 union pipe_query_result result
;
103 if (pool
->queries
[i
]) {
104 ready
= device
->queue
.ctx
->get_query_result(device
->queue
.ctx
,
106 (flags
& VK_QUERY_RESULT_WAIT_BIT
),
112 if (!ready
&& !(flags
& VK_QUERY_RESULT_PARTIAL_BIT
))
113 vk_result
= VK_NOT_READY
;
114 if (flags
& VK_QUERY_RESULT_64_BIT
) {
115 if (ready
|| (flags
& VK_QUERY_RESULT_PARTIAL_BIT
))
116 *(uint64_t *)dptr
= result
.u64
;
119 if (ready
|| (flags
& VK_QUERY_RESULT_PARTIAL_BIT
)) {
120 if (result
.u64
> UINT32_MAX
)
121 *(uint32_t *)dptr
= UINT32_MAX
;
123 *(uint32_t *)dptr
= result
.u32
;
128 if (flags
& VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
) {
129 if (flags
& VK_QUERY_RESULT_64_BIT
)
130 *(uint64_t *)dptr
= ready
;
132 *(uint32_t *)dptr
= ready
;