c/render: implement render_resources_get_duration

Useful for systems that don't support calibrated timestamps and caseas where only execution time measuring is needed.
This commit is contained in:
Fernando Velazquez Innella 2022-11-21 11:50:38 -05:00 committed by Korcan Hussein
parent 85a897a0b5
commit e035d060d1
2 changed files with 51 additions and 0 deletions

View file

@ -435,6 +435,19 @@ render_ensure_scratch_image(struct render_resources *r, VkExtent2D extent);
bool bool
render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_start_ns, uint64_t *out_gpu_end_ns); render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_start_ns, uint64_t *out_gpu_end_ns);
/*!
* Returns the duration for the latest GPU work that was submitted using
* @ref render_gfx or @ref render_compute cmd buf builders.
*
* Behaviour for this function is undefined if the GPU has not completed before
* calling this function, so make sure to call vkQueueWaitIdle or wait on the
* fence that the work was submitted with have fully completed.
*
* @public @memberof render_resources
*/
bool
render_resources_get_duration(struct render_resources *r, uint64_t *out_gpu_duration_ns);
/* /*
* *

View file

@ -1357,3 +1357,41 @@ render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_st
return true; return true;
} }
bool
render_resources_get_duration(struct render_resources *r, uint64_t *out_gpu_duration_ns)
{
struct vk_bundle *vk = r->vk;
VkResult ret = VK_SUCCESS;
/*
* Query how long things took.
*/
VkQueryResultFlags flags = VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT;
uint64_t timestamps[2] = {0};
ret = vk->vkGetQueryPoolResults( //
vk->device, // device
r->query_pool, // queryPool
0, // firstQuery
2, // queryCount
sizeof(uint64_t) * 2, // dataSize
timestamps, // pData
sizeof(uint64_t), // stride
flags); // flags
if (ret != VK_SUCCESS) {
return false;
}
/*
* Convert from ticks to nanoseconds
*/
double duration_ticks = (double)(timestamps[1] - timestamps[0]);
*out_gpu_duration_ns = (uint64_t)(duration_ticks * vk->features.timestamp_period);
return true;
}