mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 18:46:18 +00:00
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:
parent
85a897a0b5
commit
e035d060d1
|
@ -435,6 +435,19 @@ render_ensure_scratch_image(struct render_resources *r, VkExtent2D extent);
|
|||
bool
|
||||
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);
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -1357,3 +1357,41 @@ render_resources_get_timestamps(struct render_resources *r, uint64_t *out_gpu_st
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue