2 #include "zink_context.h"
3 #include "zink_screen.h"
5 #include "util/u_memory.h"
6 #include "util/u_dump.h"
16 convert_query_type(unsigned query_type
, bool *use_64bit
, bool *precise
)
21 case PIPE_QUERY_OCCLUSION_COUNTER
:
24 case PIPE_QUERY_OCCLUSION_PREDICATE
:
25 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
26 return VK_QUERY_TYPE_OCCLUSION
;
27 case PIPE_QUERY_TIMESTAMP
:
29 return VK_QUERY_TYPE_TIMESTAMP
;
30 case PIPE_QUERY_PIPELINE_STATISTICS
:
31 return VK_QUERY_TYPE_PIPELINE_STATISTICS
;
33 debug_printf("unknown query: %s\n",
34 util_str_query_type(query_type
, true));
35 unreachable("zink: unknown query type");
39 static struct pipe_query
*
40 zink_create_query(struct pipe_context
*pctx
,
41 unsigned query_type
, unsigned index
)
43 struct zink_screen
*screen
= zink_screen(pctx
->screen
);
44 struct zink_query
*query
= CALLOC_STRUCT(zink_query
);
45 VkQueryPoolCreateInfo pool_create
= {};
50 query
->vkqtype
= convert_query_type(query_type
, &query
->use_64bit
, &query
->precise
);
51 if (query
->vkqtype
== -1)
54 pool_create
.sType
= VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
;
55 pool_create
.queryType
= query
->vkqtype
;
56 pool_create
.queryCount
= 1;
58 VkResult status
= vkCreateQueryPool(screen
->dev
, &pool_create
, NULL
, &query
->queryPool
);
59 if (status
!= VK_SUCCESS
) {
63 return (struct pipe_query
*)query
;
67 zink_destroy_query(struct pipe_context
*pctx
,
70 struct zink_screen
*screen
= zink_screen(pctx
->screen
);
71 struct zink_query
*query
= CALLOC_STRUCT(zink_query
);
73 vkDestroyQueryPool(screen
->dev
, query
->queryPool
, NULL
);
77 zink_begin_query(struct pipe_context
*pctx
,
80 struct zink_context
*ctx
= zink_context(pctx
);
81 struct zink_query
*query
= (struct zink_query
*)q
;
83 if (query
->vkqtype
== VK_QUERY_TYPE_TIMESTAMP
)
86 VkQueryControlFlags flags
= 0;
88 flags
|= VK_QUERY_CONTROL_PRECISE_BIT
;
90 struct zink_batch
*batch
= zink_curr_batch(ctx
);
91 vkCmdBeginQuery(batch
->cmdbuf
, query
->queryPool
, 0, flags
);
97 zink_end_query(struct pipe_context
*pctx
,
100 struct zink_context
*ctx
= zink_context(pctx
);
101 struct zink_query
*query
= (struct zink_query
*)q
;
103 struct zink_batch
*batch
= zink_curr_batch(ctx
);
104 if (query
->vkqtype
== VK_QUERY_TYPE_TIMESTAMP
)
105 vkCmdWriteTimestamp(batch
->cmdbuf
, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
,
106 query
->queryPool
, 0);
108 vkCmdEndQuery(batch
->cmdbuf
, query
->queryPool
, 0);
113 zink_get_query_result(struct pipe_context
*pctx
,
114 struct pipe_query
*q
,
116 union pipe_query_result
*result
)
118 struct zink_screen
*screen
= zink_screen(pctx
->screen
);
119 struct zink_query
*query
= (struct zink_query
*)q
;
120 VkQueryResultFlagBits flags
= 0;
122 pctx
->flush(pctx
, NULL
, 0);
125 flags
|= VK_QUERY_RESULT_WAIT_BIT
;
127 if (query
->use_64bit
)
128 flags
|= VK_QUERY_RESULT_64_BIT
;
130 VkResult status
= vkGetQueryPoolResults(screen
->dev
, query
->queryPool
,
131 0, 1, sizeof(*result
), result
,
133 return status
== VK_SUCCESS
;
137 zink_context_query_init(struct pipe_context
*pctx
)
139 pctx
->create_query
= zink_create_query
;
140 pctx
->destroy_query
= zink_destroy_query
;
141 pctx
->begin_query
= zink_begin_query
;
142 pctx
->end_query
= zink_end_query
;
143 pctx
->get_query_result
= zink_get_query_result
;