Advertisement

GPU timestamps with pre-recorded command buffers

Started by March 09, 2018 03:12 PM
6 comments, last by mark_braga 6 years, 10 months ago

I am working on reusing as many command buffers as I can by pre-recording them at load time. This gives a significant boost on CPU although now I cannot get the GPU timestamps since there is no way to read back. I Map the readback buffer before and Unmap it after reading is done. Does this mean I need a persistently mapped readback buffer?


void Init()
{
  beginCmd(cmd);
  cmdBeginQuery(cmd);
  // Do a bunch of stuff
  cmdEndQuery(cmd);
  endCmd(cmd);
}

void Draw()
{
  CommandBuffer* cmd = commands[frameIdx];
  submit(cmd);
}

The begin and end query do exactly what the names say.

Here's some Vulkan code...

at startup:

VkQueryPoolCreateInfo poolCI = {};
            poolCI.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
            poolCI.queryType = VK_QUERY_TYPE_TIMESTAMP;
            poolCI.queryCount = this->numTimers*2;

            VkResult err = vkCreateQueryPool (gpu->device, &poolCI, nullptr, &queryPool);

 

at prerecording:

vkCmdWriteTimestamp (cmd, pipelineStage, queryPool, idTaskStart);

vkCmdDispatchIndirect(...)

vkCmdWriteTimestamp (cmd, pipelineStage, queryPool, idTaskEnd);

 

no extra code when submitting cmds.

 

query results after the frame:

VkResult err = vkGetQueryPoolResults(gpu->device, queryPool, oldId, id-oldId,
                        sizeof(timestamps), (void*)&timestamps[oldId], sizeof(uint64_t), VK_QUERY_RESULT_64_BIT);

 

I don't care about memory for results at all, seems this is all done with the query pool under the hood.

 

 

 

 

Advertisement

That is a nice feature of Vulkan which DirectX12 does not have. Not many times you get a chance to say this. Thanks

58 minutes ago, mark_braga said:

although now I cannot get the GPU timestamps since there is no way to read back. I Map the readback buffer before and Unmap it after reading is done. Does this mean I need a persistently mapped readback buffer?

I don't entirely understand... why can't you include timestamp issuing in your pre-recorded command lists? What's the problem with reading back the results?

20 hours ago, SoldierOfLight said:

I don't entirely understand... why can't you include timestamp issuing in your pre-recorded command lists? What's the problem with reading back the results?

 

I have solved the problem. Seems like I was overthinking. Thanks

 

5 hours ago, mark_braga said:

I have solved the problem. Seems like I was overthinking. Thanks

 

Care to enlighten the rest of us? :)

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement

I do the map and unmap operations outside the command buffer recording so I can call them every frame

This topic is closed to new replies.

Advertisement