From 2d1f5e3dcb3d3f32acd69429aa38e2ecac93956c Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Fri, 17 Sep 2021 18:53:02 -0700 Subject: [PATCH] d3d12: Don't accumulate timestamp queries If an app re-issues a timestamp query a lot, but doesn't ever ask for the results, we could end up running off the end of our query heap. But we don't actually need to advance/accumulate, so just use a single entry in the heap. Reviewed By: Bill Kristiansen Part-of: --- src/gallium/drivers/d3d12/d3d12_query.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/d3d12/d3d12_query.cpp b/src/gallium/drivers/d3d12/d3d12_query.cpp index 0463d13f856..8cc8b723b2c 100644 --- a/src/gallium/drivers/d3d12/d3d12_query.cpp +++ b/src/gallium/drivers/d3d12/d3d12_query.cpp @@ -117,9 +117,12 @@ d3d12_create_query(struct pipe_context *pctx, query->num_queries = 16; /* With timer queries we want a few more queries, especially since we need two slots - * per query for TIME_ELAPSED queries */ - if (unlikely(query->d3d12qtype == D3D12_QUERY_TYPE_TIMESTAMP)) + * per query for TIME_ELAPSED queries + * For TIMESTAMP, we don't need more than one slot, since there's nothing to accumulate */ + if (unlikely(query_type == PIPE_QUERY_TIME_ELAPSED)) query->num_queries = 64; + else if (query_type == PIPE_QUERY_TIMESTAMP) + query->num_queries = 1; query->curr_query = 0; @@ -357,6 +360,10 @@ end_query(struct d3d12_context *ctx, struct d3d12_query *q) if (q->subquery) end_query(ctx, q->subquery); + /* For TIMESTAMP, there's only one slot */ + if (q->type == PIPE_QUERY_TIMESTAMP) + q->curr_query = 0; + /* With QUERY_TIME_ELAPSED we have recorded one value at * (2 * q->curr_query), and now we record a value at (2 * q->curr_query + 1) * and when resolving the query we subtract the latter from the former */