[Mesa-dev] [PATCH 26/51] i965: Refactor batch buffer dumping

Chris Wilson chris at chris-wilson.co.uk
Tue Jan 10 21:23:49 UTC 2017


Move the computation of the state offset into a smaller helper to reduce
churn later.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 src/mesa/drivers/dri/i965/brw_state_dump.c | 62 ++++++++++++++++--------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_state_dump.c b/src/mesa/drivers/dri/i965/brw_state_dump.c
index c5885650a6..d8e37f9bff 100644
--- a/src/mesa/drivers/dri/i965/brw_state_dump.c
+++ b/src/mesa/drivers/dri/i965/brw_state_dump.c
@@ -68,6 +68,11 @@ static const char *surface_tiling[] = {
    "Y-tiled"
 };
 
+static void *batch_in(struct brw_context *brw, unsigned offset)
+{
+   return (void *)brw->batch.bo->virtual + offset;
+}
+
 static void
 batch_out(struct brw_context *brw, const char *name, uint32_t offset,
 	  int index, char *fmt, ...) PRINTFLIKE(5, 6);
@@ -76,7 +81,7 @@ static void
 batch_out(struct brw_context *brw, const char *name, uint32_t offset,
 	  int index, char *fmt, ...)
 {
-   uint32_t *data = brw->batch.bo->virtual + offset;
+   uint32_t *data = batch_in(brw, offset);
    va_list va;
 
    fprintf(stderr, "0x%08x:      0x%08x: %8s: ",
@@ -90,7 +95,7 @@ static void
 batch_out64(struct brw_context *brw, const char *name, uint32_t offset,
             int index, char *fmt, ...)
 {
-   uint32_t *tmp = brw->batch.bo->virtual + offset;
+   uint32_t *tmp = batch_in(brw, offset);
 
    /* Swap the dwords since we want to handle this as a 64b value, but the data
     * is typically emitted as dwords.
@@ -122,7 +127,7 @@ get_965_surfacetype(unsigned int surfacetype)
 static void dump_vs_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "VS_STATE";
-   struct brw_vs_unit_state *vs = brw->batch.bo->virtual + offset;
+   struct brw_vs_unit_state *vs = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "thread0\n");
    batch_out(brw, name, offset, 1, "thread1\n");
@@ -137,7 +142,7 @@ static void dump_vs_state(struct brw_context *brw, uint32_t offset)
 static void dump_gs_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "GS_STATE";
-   struct brw_gs_unit_state *gs = brw->batch.bo->virtual + offset;
+   struct brw_gs_unit_state *gs = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "thread0\n");
    batch_out(brw, name, offset, 1, "thread1\n");
@@ -152,7 +157,7 @@ static void dump_gs_state(struct brw_context *brw, uint32_t offset)
 static void dump_clip_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "CLIP_STATE";
-   struct brw_clip_unit_state *clip = brw->batch.bo->virtual + offset;
+   struct brw_clip_unit_state *clip = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "thread0\n");
    batch_out(brw, name, offset, 1, "thread1\n");
@@ -171,7 +176,7 @@ static void dump_clip_state(struct brw_context *brw, uint32_t offset)
 static void dump_sf_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "SF_STATE";
-   struct brw_sf_unit_state *sf = brw->batch.bo->virtual + offset;
+   struct brw_sf_unit_state *sf = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "thread0\n");
    batch_out(brw, name, offset, 1, "thread1\n");
@@ -187,7 +192,7 @@ static void dump_sf_state(struct brw_context *brw, uint32_t offset)
 static void dump_wm_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "WM_STATE";
-   struct brw_wm_unit_state *wm = brw->batch.bo->virtual + offset;
+   struct brw_wm_unit_state *wm = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "thread0\n");
    batch_out(brw, name, offset, 1, "thread1\n");
@@ -214,7 +219,7 @@ static void dump_wm_state(struct brw_context *brw, uint32_t offset)
 static void dump_surface_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "SURF";
-   uint32_t *surf = brw->batch.bo->virtual + offset;
+   uint32_t *surf = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "%s %s\n",
 	     get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)),
@@ -238,7 +243,7 @@ static void dump_surface_state(struct brw_context *brw, uint32_t offset)
 static void dump_gen7_surface_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "SURF";
-   uint32_t *surf = brw->batch.bo->virtual + offset;
+   uint32_t *surf = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "%s %s %s\n",
              get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)),
@@ -277,7 +282,7 @@ static float q_to_float(uint32_t data, int integer_end, int integer_start,
 static void
 dump_gen8_surface_state(struct brw_context *brw, uint32_t offset, int index)
 {
-   uint32_t *surf = brw->batch.bo->virtual + offset;
+   uint32_t *surf = batch_in(brw, offset);
    int aux_mode = surf[6] & INTEL_MASK(2, 0);
    const char *aux_str;
    char *name;
@@ -354,8 +359,7 @@ dump_sdc(struct brw_context *brw, uint32_t offset)
    const char *name = "SDC";
 
    if (brw->gen >= 5 && brw->gen <= 6) {
-      struct gen5_sampler_default_color *sdc = (brw->batch.bo->virtual +
-                                                offset);
+      struct gen5_sampler_default_color *sdc = batch_in(brw, offset);
       batch_out(brw, name, offset, 0, "unorm rgba\n");
       batch_out(brw, name, offset, 1, "r %f\n", sdc->f[0]);
       batch_out(brw, name, offset, 2, "b %f\n", sdc->f[1]);
@@ -369,7 +373,7 @@ dump_sdc(struct brw_context *brw, uint32_t offset)
       batch_out(brw, name, offset, 10, "s16 ba\n");
       batch_out(brw, name, offset, 11, "s8 rgba\n");
    } else {
-      float *sdc = brw->batch.bo->virtual + offset;
+      float *sdc = batch_in(brw, offset);
       batch_out(brw, name, offset, 0, "r %f\n", sdc[0]);
       batch_out(brw, name, offset, 1, "g %f\n", sdc[1]);
       batch_out(brw, name, offset, 2, "b %f\n", sdc[2]);
@@ -381,7 +385,7 @@ static void dump_sampler_state(struct brw_context *brw,
 			       uint32_t offset, uint32_t size)
 {
    unsigned i;
-   uint32_t *samp = brw->batch.bo->virtual + offset;
+   uint32_t *samp = batch_in(brw, offset);
 
    for (i = 0; i < size / 16; i++) {
       char name[20];
@@ -400,7 +404,7 @@ static void dump_sampler_state(struct brw_context *brw,
 static void gen7_dump_sampler_state(struct brw_context *brw,
                                     uint32_t offset, uint32_t size)
 {
-   const uint32_t *samp = brw->batch.bo->virtual + offset;
+   const uint32_t *samp = batch_in(brw, offset);
    char name[20];
 
    for (int i = 0; i < size / 16; i++) {
@@ -441,7 +445,7 @@ static void dump_sf_viewport_state(struct brw_context *brw,
 				   uint32_t offset)
 {
    const char *name = "SF VP";
-   struct brw_sf_viewport *vp = brw->batch.bo->virtual + offset;
+   struct brw_sf_viewport *vp = batch_in(brw, offset);
 
    assert(brw->gen < 7);
 
@@ -462,7 +466,7 @@ static void dump_clip_viewport_state(struct brw_context *brw,
 				     uint32_t offset)
 {
    const char *name = "CLIP VP";
-   struct brw_clipper_viewport *vp = brw->batch.bo->virtual + offset;
+   struct brw_clipper_viewport *vp = batch_in(brw, offset);
 
    assert(brw->gen < 7);
 
@@ -476,7 +480,7 @@ static void dump_sf_clip_viewport_state(struct brw_context *brw,
 					uint32_t offset)
 {
    const char *name = "SF_CLIP VP";
-   struct gen7_sf_clip_viewport *vp = brw->batch.bo->virtual + offset;
+   struct gen7_sf_clip_viewport *vp = batch_in(brw, offset);
 
    assert(brw->gen >= 7);
 
@@ -491,7 +495,7 @@ static void dump_sf_clip_viewport_state(struct brw_context *brw,
    batch_out(brw, name, offset, 9, "guardband ymin = %f\n", vp->guardband.ymin);
    batch_out(brw, name, offset, 10, "guardband ymax = %f\n", vp->guardband.ymax);
    if (brw->gen >= 8) {
-      float *cc_vp = brw->batch.bo->virtual + offset;
+      float *cc_vp = batch_in(brw, offset);
       batch_out(brw, name, offset, 12, "Min extents: %.2fx%.2f\n",
                 cc_vp[12], cc_vp[14]);
       batch_out(brw, name, offset, 14, "Max extents: %.2fx%.2f\n",
@@ -503,7 +507,7 @@ static void dump_sf_clip_viewport_state(struct brw_context *brw,
 static void dump_cc_viewport_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "CC VP";
-   struct brw_cc_viewport *vp = brw->batch.bo->virtual + offset;
+   struct brw_cc_viewport *vp = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "min_depth = %f\n", vp->min_depth);
    batch_out(brw, name, offset, 1, "max_depth = %f\n", vp->max_depth);
@@ -512,7 +516,7 @@ static void dump_cc_viewport_state(struct brw_context *brw, uint32_t offset)
 static void dump_depth_stencil_state(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "D_S";
-   struct gen6_depth_stencil_state *ds = brw->batch.bo->virtual + offset;
+   struct gen6_depth_stencil_state *ds = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0,
 	     "stencil %sable, func %d, write %sable\n",
@@ -546,7 +550,7 @@ static void dump_cc_state_gen4(struct brw_context *brw, uint32_t offset)
 static void dump_cc_state_gen6(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "CC";
-   struct gen6_color_calc_state *cc = brw->batch.bo->virtual + offset;
+   struct gen6_color_calc_state *cc = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0,
 	     "alpha test format %s, round disable %d, stencil ref %d, "
@@ -573,7 +577,7 @@ static void dump_blend_state(struct brw_context *brw, uint32_t offset)
 static void
 gen8_dump_blend_state(struct brw_context *brw, uint32_t offset, uint32_t size)
 {
-   const uint32_t *blend = brw->batch.bo->virtual + offset;
+   const uint32_t *blend = batch_in(brw, offset);
    const char *logicop[] =
    {
         "LOGICOP_CLEAR (BLACK)",
@@ -660,7 +664,7 @@ static void
 dump_scissor(struct brw_context *brw, uint32_t offset)
 {
    const char *name = "SCISSOR";
-   struct gen6_scissor_rect *scissor = brw->batch.bo->virtual + offset;
+   struct gen6_scissor_rect *scissor = batch_in(brw, offset);
 
    batch_out(brw, name, offset, 0, "xmin %d, ymin %d\n",
 	     scissor->xmin, scissor->ymin);
@@ -672,8 +676,8 @@ static void
 dump_vs_constants(struct brw_context *brw, uint32_t offset, uint32_t size)
 {
    const char *name = "VS_CONST";
-   uint32_t *as_uint = brw->batch.bo->virtual + offset;
-   float *as_float = brw->batch.bo->virtual + offset;
+   uint32_t *as_uint = batch_in(brw, offset);
+   float *as_float = batch_in(brw, offset);
    int i;
 
    for (i = 0; i < size / 4; i += 4) {
@@ -688,8 +692,8 @@ static void
 dump_wm_constants(struct brw_context *brw, uint32_t offset, uint32_t size)
 {
    const char *name = "WM_CONST";
-   uint32_t *as_uint = brw->batch.bo->virtual + offset;
-   float *as_float = brw->batch.bo->virtual + offset;
+   uint32_t *as_uint = batch_in(brw, offset);
+   float *as_float = batch_in(brw, offset);
    int i;
 
    for (i = 0; i < size / 4; i += 4) {
@@ -705,7 +709,7 @@ static void dump_binding_table(struct brw_context *brw, uint32_t offset,
 {
    char name[20];
    int i;
-   uint32_t *data = brw->batch.bo->virtual + offset;
+   uint32_t *data = batch_in(brw, offset);
 
    for (i = 0; i < size / 4; i++) {
       if (data[i] == 0)
-- 
2.11.0



More information about the mesa-dev mailing list