From f151ac57cb835408598e964beac17356e8c4f1cc Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sun, 4 Feb 2018 23:17:20 +0100 Subject: vo_gpu: vulkan: don't issue queries for unused timers The vulkan validation layers warn you if you try requesting a query result from a timer that hasn't even been started yet, so we have to do some extra bit of work to keep track of which indices we've seen so far, and avoid the queries on them. --- video/out/vulkan/ra_vk.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/video/out/vulkan/ra_vk.c b/video/out/vulkan/ra_vk.c index 9ba815bbc8..a4b6f3e6ad 100644 --- a/video/out/vulkan/ra_vk.c +++ b/video/out/vulkan/ra_vk.c @@ -1765,6 +1765,7 @@ static int vk_desc_namespace(enum ra_vartype type) struct vk_timer { VkQueryPool pool; + int index_seen; // keeps track of which indices have been used at least once int index; uint64_t result; }; @@ -1789,6 +1790,7 @@ static ra_timer *vk_timer_create(struct ra *ra) struct mpvk_ctx *vk = ra_vk_get(ra); struct vk_timer *timer = talloc_zero(NULL, struct vk_timer); + timer->index_seen = -1; struct VkQueryPoolCreateInfo qinfo = { .sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, @@ -1820,12 +1822,15 @@ static void vk_timer_start(struct ra *ra, ra_timer *ratimer) struct mpvk_ctx *vk = ra_vk_get(ra); struct vk_timer *timer = ratimer; - timer->index = (timer->index + 2) % VK_QUERY_POOL_SIZE; - + VkResult res = VK_NOT_READY; uint64_t out[2]; - VkResult res = vkGetQueryPoolResults(vk->dev, timer->pool, timer->index, 2, - sizeof(out), &out[0], sizeof(uint64_t), - VK_QUERY_RESULT_64_BIT); + + if (timer->index <= timer->index_seen) { + res = vkGetQueryPoolResults(vk->dev, timer->pool, timer->index, 2, + sizeof(out), &out[0], sizeof(uint64_t), + VK_QUERY_RESULT_64_BIT); + } + switch (res) { case VK_SUCCESS: timer->result = (out[1] - out[0]) * vk->limits.timestampPeriod; @@ -1848,6 +1853,9 @@ static uint64_t vk_timer_stop(struct ra *ra, ra_timer *ratimer) vk_timer_record(ra, timer->pool, timer->index + 1, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT); + timer->index_seen = MPMAX(timer->index_seen, timer->index); + timer->index = (timer->index + 2) % VK_QUERY_POOL_SIZE; + return timer->result; } -- cgit v1.2.3