2 * Copyright © 2015 Intel Corporation
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
30 #include "anv_private.h"
32 VkResult
anv_CreateQueryPool(
34 const VkQueryPoolCreateInfo
* pCreateInfo
,
35 VkQueryPool
* pQueryPool
)
37 ANV_FROM_HANDLE(anv_device
, device
, _device
);
38 struct anv_query_pool
*pool
;
42 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
);
44 switch (pCreateInfo
->queryType
) {
45 case VK_QUERY_TYPE_OCCLUSION
:
47 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
48 return VK_UNSUPPORTED
;
53 pool
= anv_device_alloc(device
, sizeof(*pool
), 8,
54 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
56 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
58 size
= pCreateInfo
->slots
* sizeof(struct anv_query_pool_slot
);
59 result
= anv_bo_init_new(&pool
->bo
, device
, size
);
60 if (result
!= VK_SUCCESS
)
63 pool
->bo
.map
= anv_gem_mmap(device
, pool
->bo
.gem_handle
, 0, size
);
65 *pQueryPool
= anv_query_pool_to_handle(pool
);
70 anv_device_free(device
, pool
);
75 void anv_DestroyQueryPool(
79 ANV_FROM_HANDLE(anv_device
, device
, _device
);
80 ANV_FROM_HANDLE(anv_query_pool
, pool
, _pool
);
82 anv_gem_munmap(pool
->bo
.map
, pool
->bo
.size
);
83 anv_gem_close(device
, pool
->bo
.gem_handle
);
84 anv_device_free(device
, pool
);
87 VkResult
anv_GetQueryPoolResults(
89 VkQueryPool queryPool
,
94 VkQueryResultFlags flags
)
96 ANV_FROM_HANDLE(anv_device
, device
, _device
);
97 ANV_FROM_HANDLE(anv_query_pool
, pool
, queryPool
);
98 struct anv_query_pool_slot
*slot
= pool
->bo
.map
;
99 int64_t timeout
= INT64_MAX
;
100 uint32_t *dst32
= pData
;
101 uint64_t *dst64
= pData
;
105 if (flags
& VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
) {
106 /* Where is the availabilty info supposed to go? */
107 anv_finishme("VK_QUERY_RESULT_WITH_AVAILABILITY_BIT");
108 return VK_UNSUPPORTED
;
111 assert(pool
->type
== VK_QUERY_TYPE_OCCLUSION
);
113 if (flags
& VK_QUERY_RESULT_64_BIT
)
114 *pDataSize
= queryCount
* sizeof(uint64_t);
116 *pDataSize
= queryCount
* sizeof(uint32_t);
121 if (flags
& VK_QUERY_RESULT_WAIT_BIT
) {
122 ret
= anv_gem_wait(device
, pool
->bo
.gem_handle
, &timeout
);
124 /* We don't know the real error. */
125 return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY
,
126 "gem_wait failed %m");
130 for (uint32_t i
= 0; i
< queryCount
; i
++) {
131 result
= slot
[startQuery
+ i
].end
- slot
[startQuery
+ i
].begin
;
132 if (flags
& VK_QUERY_RESULT_64_BIT
) {
135 if (result
> UINT32_MAX
)
144 void anv_CmdResetQueryPool(
145 VkCmdBuffer cmdBuffer
,
146 VkQueryPool queryPool
,