summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2018-02-04 23:17:20 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-02-05 02:49:03 -0800
commitf151ac57cb835408598e964beac17356e8c4f1cc (patch)
tree1daf96d3e9f9e0a3afd0f4137aa78c19b9024a7c
parentf92e45bb8c97287ced54e27e2a5ba66bcac66b19 (diff)
downloadmpv-f151ac57cb835408598e964beac17356e8c4f1cc.tar.bz2
mpv-f151ac57cb835408598e964beac17356e8c4f1cc.tar.xz
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.
-rw-r--r--video/out/vulkan/ra_vk.c18
1 files 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;
}