[Mesa-dev] [PATCH 04/12] i965: Replace open-coded gen6 queryobj offsets with simple helpers

Chris Wilson chris at chris-wilson.co.uk
Fri Aug 4 20:01:08 UTC 2017


Lots of places open-coded the assumed layout of the predicate/results
within the query object, replace those with simple helpers.

v2: Fix function decl style.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Kenneth Graunke <kenneth at whitecape.org>
Cc: Matt Turner <mattst88 at gmail.com>
---
 src/mesa/drivers/dri/i965/brw_conditional_render.c | 10 ++++++++--
 src/mesa/drivers/dri/i965/brw_context.h            | 15 +++++++++++++++
 src/mesa/drivers/dri/i965/gen6_queryobj.c          |  6 +++---
 src/mesa/drivers/dri/i965/hsw_queryobj.c           | 18 +++++++++---------
 4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_conditional_render.c b/src/mesa/drivers/dri/i965/brw_conditional_render.c
index e33e79fb6c..0177a7f80b 100644
--- a/src/mesa/drivers/dri/i965/brw_conditional_render.c
+++ b/src/mesa/drivers/dri/i965/brw_conditional_render.c
@@ -87,8 +87,14 @@ set_predicate_for_occlusion_query(struct brw_context *brw,
     */
    brw_emit_pipe_control_flush(brw, PIPE_CONTROL_FLUSH_ENABLE);
 
-   brw_load_register_mem64(brw, MI_PREDICATE_SRC0, query->bo, 0 /* offset */);
-   brw_load_register_mem64(brw, MI_PREDICATE_SRC1, query->bo, 8 /* offset */);
+   brw_load_register_mem64(brw,
+                           MI_PREDICATE_SRC0,
+                           query->bo,
+                           gen6_query_results_offset(query, 0));
+   brw_load_register_mem64(brw,
+                           MI_PREDICATE_SRC1,
+                           query->bo,
+                           gen6_query_results_offset(query, 1));
 }
 
 static void
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index d41e6aa7bd..d37e05bb47 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -428,6 +428,21 @@ struct brw_query_object {
    bool flushed;
 };
 
+#define GEN6_QUERY_PREDICATE (2)
+#define GEN6_QUERY_RESULTS (0)
+
+static inline unsigned
+gen6_query_predicate_offset(const struct brw_query_object *query)
+{
+   return GEN6_QUERY_PREDICATE * sizeof(uint64_t);
+}
+
+static inline unsigned
+gen6_query_results_offset(const struct brw_query_object *query, unsigned idx)
+{
+   return (GEN6_QUERY_RESULTS + idx) * sizeof(uint64_t);
+}
+
 enum brw_gpu_ring {
    UNKNOWN_RING,
    RENDER_RING,
diff --git a/src/mesa/drivers/dri/i965/gen6_queryobj.c b/src/mesa/drivers/dri/i965/gen6_queryobj.c
index 1ee3974198..a0b786f5d9 100644
--- a/src/mesa/drivers/dri/i965/gen6_queryobj.c
+++ b/src/mesa/drivers/dri/i965/gen6_queryobj.c
@@ -71,7 +71,7 @@ set_query_availability(struct brw_context *brw, struct brw_query_object *query,
       }
 
       brw_emit_pipe_control_write(brw, flags,
-                                  query->bo, 2 * sizeof(uint64_t),
+                                  query->bo, gen6_query_predicate_offset(query),
                                   available);
    }
 }
@@ -318,7 +318,7 @@ gen6_begin_query(struct gl_context *ctx, struct gl_query_object *q)
 {
    struct brw_context *brw = brw_context(ctx);
    struct brw_query_object *query = (struct brw_query_object *)q;
-   const int idx = 0;
+   const int idx = GEN6_QUERY_RESULTS;
 
    /* Since we're starting a new query, we need to throw away old results. */
    brw_bo_unreference(query->bo);
@@ -407,7 +407,7 @@ gen6_end_query(struct gl_context *ctx, struct gl_query_object *q)
 {
    struct brw_context *brw = brw_context(ctx);
    struct brw_query_object *query = (struct brw_query_object *)q;
-   const int idx = 1;
+   const int idx = GEN6_QUERY_RESULTS + 1;
 
    switch (query->Base.Target) {
    case GL_TIME_ELAPSED:
diff --git a/src/mesa/drivers/dri/i965/hsw_queryobj.c b/src/mesa/drivers/dri/i965/hsw_queryobj.c
index 9dc3b3de86..32b2e1f342 100644
--- a/src/mesa/drivers/dri/i965/hsw_queryobj.c
+++ b/src/mesa/drivers/dri/i965/hsw_queryobj.c
@@ -191,7 +191,7 @@ load_overflow_data_to_cs_gprs(struct brw_context *brw,
                               struct brw_query_object *query,
                               int idx)
 {
-   int offset = idx * sizeof(uint64_t) * 4;
+   int offset = gen6_query_results_offset(query, 0) + idx * sizeof(uint64_t) * 4;
 
    brw_load_register_mem64(brw, HSW_CS_GPR(1), query->bo, offset);
 
@@ -282,7 +282,7 @@ hsw_result_to_gpr0(struct gl_context *ctx, struct brw_query_object *query,
       brw_load_register_mem64(brw,
                               HSW_CS_GPR(0),
                               query->bo,
-                              2 * sizeof(uint64_t));
+                              gen6_query_predicate_offset(query));
       return;
    }
 
@@ -299,7 +299,7 @@ hsw_result_to_gpr0(struct gl_context *ctx, struct brw_query_object *query,
       brw_load_register_mem64(brw,
                               HSW_CS_GPR(0),
                               query->bo,
-                              0 * sizeof(uint64_t));
+                              gen6_query_results_offset(query, 0));
    } else if (query->Base.Target == GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
               || query->Base.Target == GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB) {
       /* Don't do anything in advance here, since the math for this is a little
@@ -309,11 +309,11 @@ hsw_result_to_gpr0(struct gl_context *ctx, struct brw_query_object *query,
       brw_load_register_mem64(brw,
                               HSW_CS_GPR(1),
                               query->bo,
-                              0 * sizeof(uint64_t));
+                              gen6_query_results_offset(query, 0));
       brw_load_register_mem64(brw,
                               HSW_CS_GPR(2),
                               query->bo,
-                              1 * sizeof(uint64_t));
+                              gen6_query_results_offset(query, 1));
 
       BEGIN_BATCH(5);
       OUT_BATCH(HSW_MI_MATH | (5 - 2));
@@ -383,13 +383,13 @@ store_query_result_imm(struct brw_context *brw, struct brw_bo *bo,
 }
 
 static void
-set_predicate(struct brw_context *brw, struct brw_bo *query_bo)
+set_predicate(struct brw_context *brw, struct brw_query_object *query)
 {
    brw_load_register_imm64(brw, MI_PREDICATE_SRC1, 0ull);
 
    /* Load query availability into SRC0 */
-   brw_load_register_mem64(brw, MI_PREDICATE_SRC0, query_bo,
-                           2 * sizeof(uint64_t));
+   brw_load_register_mem64(brw, MI_PREDICATE_SRC0, query->bo,
+                           gen6_query_predicate_offset(query));
 
    /* predicate = !(query_availability == 0); */
    BEGIN_BATCH(1);
@@ -454,7 +454,7 @@ hsw_store_query_result(struct gl_context *ctx, struct gl_query_object *q,
        */
       hsw_result_to_gpr0(ctx, query, buf, offset, pname, ptype);
       if (pipelined)
-         set_predicate(brw, query->bo);
+         set_predicate(brw, query);
       store_query_result_reg(brw, bo->buffer, offset, ptype, HSW_CS_GPR(0),
                              pipelined);
    } else {
-- 
2.13.3



More information about the mesa-dev mailing list