I’m trying to use a simple timestamp query, but I’ve once again ran into a bit of trouble.
Here’s my test-code which I used in the cube-demo from the SDK at the top of the ‘demo_draw’-function (Executed every frame):
static void demo_draw(struct demo *demo) {
static VkQueryPool queryPool = NULL;
const uint32_t queryId = 0;
if(queryPool == NULL)
{
VkQueryPoolCreateInfo info;
info.flags = 0;
info.pipelineStatistics = 0;
info.pNext = NULL;
info.queryCount = 1;
info.queryType = VK_QUERY_TYPE_TIMESTAMP;
info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
VkResult r = vkCreateQueryPool(demo->device,&info,NULL,&queryPool);
assert(!r);
vkCmdResetQueryPool(demo->buffers[demo->current_buffer].cmd,queryPool,queryId,1); // "As with other queries, the query must be reset using vkCmdResetQueryPool before requesting the timestamp value be written to it."
vkCmdWriteTimestamp(demo->buffers[demo->current_buffer].cmd,VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,queryPool,queryId); // Tried it with different pipeline stages; Same result regardless
}
// From the specs: "The first query’s result is written starting at the first byte requested by the command, and each subsequent query’s result begins stride bytes later."
// "If VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is used, the final element of each query’s result is an integer indicating whether the query’s result is available, with any non-zero value indicating that it is available."
uint32_t resultData[2] = {0,0}; // resultData[0] = Query result; resultData[1] = Availability
VkResult r = vkGetQueryPoolResults(demo->device,queryPool,queryId,1,sizeof(uint32_t) *2,resultData,sizeof(uint32_t) *2,VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
assert(!r);
if(resultData[1] != 0)
printf("Result available
");
else
printf("Result not available
");
[...] // Rest of the rendering code as usual
}
resultData[1] is always 0, so the result is never available.
Something that strikes me as odd is this part from the specs:
So, if I understand this correctly, since I only have one query in this case, if the query is unavailable, resultData[1] should be set to 0 and the return value should be VK_NOT_READY, correct?
Well, resultData[1] is being set to 0 (I’ve checked), however the return value is always VK_SUCCESS. So… The query is in the available state, but at the same time it’s not?
Are there any examples around anywhere on how to use timestamp queries properly?