i965: Fold ABO state upload code into the SSBO/UBO state upload code.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 3 Nov 2017 21:52:05 +0000 (14:52 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 15 Nov 2017 17:37:32 +0000 (09:37 -0800)
Having this separate could potentially make programs that rebind atomics
but no other surfaces ever so slightly faster.  But it's a tiny amount
of code to add to the existing UBO/SSBO atom, and very related.

The extra atoms have a cost on every draw call, and so dropping some of
them would be nice.  This also reclaims a dirty bit.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_gs_surface_state.c
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_state_upload.c
src/mesa/drivers/dri/i965/brw_tcs_surface_state.c
src/mesa/drivers/dri/i965/brw_tes_surface_state.c
src/mesa/drivers/dri/i965/brw_vs_surface_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/genX_state_upload.c
src/mesa/drivers/dri/i965/intel_buffer_objects.c

index 72a81a0ec1a7f77c918f19ab029cc4c26de6a69d..66483fbf7d085569bce0ad20b674719fc1dc65fa 100644 (file)
@@ -195,7 +195,6 @@ enum brw_state_id {
    BRW_STATE_RASTERIZER_DISCARD,
    BRW_STATE_STATS_WM,
    BRW_STATE_UNIFORM_BUFFER,
-   BRW_STATE_ATOMIC_BUFFER,
    BRW_STATE_IMAGE_UNITS,
    BRW_STATE_META_IN_PROGRESS,
    BRW_STATE_PUSH_CONSTANT_ALLOCATION,
@@ -288,7 +287,6 @@ enum brw_state_id {
 #define BRW_NEW_RASTERIZER_DISCARD      (1ull << BRW_STATE_RASTERIZER_DISCARD)
 #define BRW_NEW_STATS_WM                (1ull << BRW_STATE_STATS_WM)
 #define BRW_NEW_UNIFORM_BUFFER          (1ull << BRW_STATE_UNIFORM_BUFFER)
-#define BRW_NEW_ATOMIC_BUFFER           (1ull << BRW_STATE_ATOMIC_BUFFER)
 #define BRW_NEW_IMAGE_UNITS             (1ull << BRW_STATE_IMAGE_UNITS)
 #define BRW_NEW_META_IN_PROGRESS        (1ull << BRW_STATE_META_IN_PROGRESS)
 #define BRW_NEW_PUSH_CONSTANT_ALLOCATION (1ull << BRW_STATE_PUSH_CONSTANT_ALLOCATION)
@@ -1413,10 +1411,6 @@ brw_update_sol_surface(struct brw_context *brw,
 void brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
                              struct brw_stage_state *stage_state,
                              struct brw_stage_prog_data *prog_data);
-void brw_upload_abo_surfaces(struct brw_context *brw,
-                             const struct gl_program *prog,
-                             struct brw_stage_state *stage_state,
-                             struct brw_stage_prog_data *prog_data);
 void brw_upload_image_surfaces(struct brw_context *brw,
                                const struct gl_program *prog,
                                struct brw_stage_state *stage_state,
index 570f3fb4dd22ce094930d440eb1180ca441afa09..6f2629eb29d03d1ca56e7cd9fd9844b5b54bf59a 100644 (file)
@@ -91,28 +91,6 @@ const struct brw_tracked_state brw_gs_ubo_surfaces = {
    .emit = brw_upload_gs_ubo_surfaces,
 };
 
-static void
-brw_upload_gs_abo_surfaces(struct brw_context *brw)
-{
-   /* _NEW_PROGRAM */
-   const struct gl_program *gp = brw->programs[MESA_SHADER_GEOMETRY];
-
-   if (gp) {
-      /* BRW_NEW_GS_PROG_DATA */
-      brw_upload_abo_surfaces(brw, gp, &brw->gs.base, brw->gs.base.prog_data);
-   }
-}
-
-const struct brw_tracked_state brw_gs_abo_surfaces = {
-   .dirty = {
-      .mesa = _NEW_PROGRAM,
-      .brw = BRW_NEW_ATOMIC_BUFFER |
-             BRW_NEW_BATCH |
-             BRW_NEW_GS_PROG_DATA,
-   },
-   .emit = brw_upload_gs_abo_surfaces,
-};
-
 static void
 brw_upload_gs_image_surfaces(struct brw_context *brw)
 {
index 397dfc9aa504efc90fb7e02ecfc5ae9918cffe4a..cf13eca3438bfc3b540cfd51519343c1b5b986d0 100644 (file)
@@ -58,16 +58,12 @@ extern const struct brw_tracked_state brw_recalculate_urb_fence;
 extern const struct brw_tracked_state brw_sf_vp;
 extern const struct brw_tracked_state brw_cs_texture_surfaces;
 extern const struct brw_tracked_state brw_vs_ubo_surfaces;
-extern const struct brw_tracked_state brw_vs_abo_surfaces;
 extern const struct brw_tracked_state brw_vs_image_surfaces;
 extern const struct brw_tracked_state brw_tcs_ubo_surfaces;
-extern const struct brw_tracked_state brw_tcs_abo_surfaces;
 extern const struct brw_tracked_state brw_tcs_image_surfaces;
 extern const struct brw_tracked_state brw_tes_ubo_surfaces;
-extern const struct brw_tracked_state brw_tes_abo_surfaces;
 extern const struct brw_tracked_state brw_tes_image_surfaces;
 extern const struct brw_tracked_state brw_gs_ubo_surfaces;
-extern const struct brw_tracked_state brw_gs_abo_surfaces;
 extern const struct brw_tracked_state brw_gs_image_surfaces;
 extern const struct brw_tracked_state brw_renderbuffer_surfaces;
 extern const struct brw_tracked_state brw_renderbuffer_read_surfaces;
@@ -78,10 +74,8 @@ extern const struct brw_tracked_state brw_tes_binding_table;
 extern const struct brw_tracked_state brw_tcs_binding_table;
 extern const struct brw_tracked_state brw_vs_binding_table;
 extern const struct brw_tracked_state brw_wm_ubo_surfaces;
-extern const struct brw_tracked_state brw_wm_abo_surfaces;
 extern const struct brw_tracked_state brw_wm_image_surfaces;
 extern const struct brw_tracked_state brw_cs_ubo_surfaces;
-extern const struct brw_tracked_state brw_cs_abo_surfaces;
 extern const struct brw_tracked_state brw_cs_image_surfaces;
 
 extern const struct brw_tracked_state brw_psp_urb_cbs;
index da464ef7b144a88c50ace7a780e09e0a02d21740..20c59c6e9dc4c592e2dae73dcdc03fead795ec18 100644 (file)
@@ -204,7 +204,7 @@ void brw_init_state( struct brw_context *brw )
    ctx->DriverFlags.NewUniformBuffer = BRW_NEW_UNIFORM_BUFFER;
    ctx->DriverFlags.NewShaderStorageBuffer = BRW_NEW_UNIFORM_BUFFER;
    ctx->DriverFlags.NewTextureBuffer = BRW_NEW_TEXTURE_BUFFER;
-   ctx->DriverFlags.NewAtomicBuffer = BRW_NEW_ATOMIC_BUFFER;
+   ctx->DriverFlags.NewAtomicBuffer = BRW_NEW_UNIFORM_BUFFER;
    ctx->DriverFlags.NewImageUnits = BRW_NEW_IMAGE_UNITS;
    ctx->DriverFlags.NewDefaultTessLevels = BRW_NEW_DEFAULT_TESS_LEVELS;
    ctx->DriverFlags.NewIntelConservativeRasterization = BRW_NEW_CONSERVATIVE_RASTERIZATION;
@@ -323,7 +323,6 @@ static struct dirty_bit_map brw_bits[] = {
    DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD),
    DEFINE_BIT(BRW_NEW_STATS_WM),
    DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER),
-   DEFINE_BIT(BRW_NEW_ATOMIC_BUFFER),
    DEFINE_BIT(BRW_NEW_IMAGE_UNITS),
    DEFINE_BIT(BRW_NEW_META_IN_PROGRESS),
    DEFINE_BIT(BRW_NEW_PUSH_CONSTANT_ALLOCATION),
index f4f9abc06204aa3a1c670beb060c017ad54fcc4c..73179c006a06a42a5b5ca34ba7bf81105055320f 100644 (file)
@@ -91,29 +91,6 @@ const struct brw_tracked_state brw_tcs_ubo_surfaces = {
    .emit = brw_upload_tcs_ubo_surfaces,
 };
 
-static void
-brw_upload_tcs_abo_surfaces(struct brw_context *brw)
-{
-   /* _NEW_PROGRAM */
-   const struct gl_program *tcp = brw->programs[MESA_SHADER_TESS_CTRL];
-
-   if (tcp) {
-      /* BRW_NEW_TCS_PROG_DATA */
-      brw_upload_abo_surfaces(brw, tcp, &brw->tcs.base,
-                              brw->tcs.base.prog_data);
-   }
-}
-
-const struct brw_tracked_state brw_tcs_abo_surfaces = {
-   .dirty = {
-      .mesa = _NEW_PROGRAM,
-      .brw = BRW_NEW_ATOMIC_BUFFER |
-             BRW_NEW_BATCH |
-             BRW_NEW_TCS_PROG_DATA,
-   },
-   .emit = brw_upload_tcs_abo_surfaces,
-};
-
 static void
 brw_upload_tcs_image_surfaces(struct brw_context *brw)
 {
index 85b285d86884237b82f67b642b3dc3ac9482acc4..6e9e58a4f170830da99af837c9c42c58af9826b7 100644 (file)
@@ -91,29 +91,6 @@ const struct brw_tracked_state brw_tes_ubo_surfaces = {
    .emit = brw_upload_tes_ubo_surfaces,
 };
 
-static void
-brw_upload_tes_abo_surfaces(struct brw_context *brw)
-{
-   /* _NEW_PROGRAM */
-   const struct gl_program *tep = brw->programs[MESA_SHADER_TESS_EVAL];
-
-   if (tep) {
-      /* BRW_NEW_TES_PROG_DATA */
-      brw_upload_abo_surfaces(brw, tep, &brw->tes.base,
-                              brw->tes.base.prog_data);
-   }
-}
-
-const struct brw_tracked_state brw_tes_abo_surfaces = {
-   .dirty = {
-      .mesa = _NEW_PROGRAM,
-      .brw = BRW_NEW_ATOMIC_BUFFER |
-             BRW_NEW_BATCH |
-             BRW_NEW_TES_PROG_DATA,
-   },
-   .emit = brw_upload_tes_abo_surfaces,
-};
-
 static void
 brw_upload_tes_image_surfaces(struct brw_context *brw)
 {
index 24c22e087d97e5b52f7d571a33fca602d949d778..289c791b872db2bf8a42d95716043eb6597c79a3 100644 (file)
@@ -93,28 +93,6 @@ const struct brw_tracked_state brw_vs_ubo_surfaces = {
    .emit = brw_upload_vs_ubo_surfaces,
 };
 
-static void
-brw_upload_vs_abo_surfaces(struct brw_context *brw)
-{
-   /* _NEW_PROGRAM */
-   const struct gl_program *vp = brw->programs[MESA_SHADER_VERTEX];
-
-   if (vp) {
-      /* BRW_NEW_VS_PROG_DATA */
-      brw_upload_abo_surfaces(brw, vp, &brw->vs.base, brw->vs.base.prog_data);
-   }
-}
-
-const struct brw_tracked_state brw_vs_abo_surfaces = {
-   .dirty = {
-      .mesa = _NEW_PROGRAM,
-      .brw = BRW_NEW_ATOMIC_BUFFER |
-             BRW_NEW_BATCH |
-             BRW_NEW_VS_PROG_DATA,
-   },
-   .emit = brw_upload_vs_abo_surfaces,
-};
-
 static void
 brw_upload_vs_image_surfaces(struct brw_context *brw)
 {
index a4804401fc5ae5806d2d9a5a763174f3c0f49803..adf60a840b07d2216cf8455729fb222c3fff5674 100644 (file)
@@ -1270,7 +1270,9 @@ brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
 {
    struct gl_context *ctx = &brw->ctx;
 
-   if (!prog)
+   if (!prog || (prog->info.num_ubos == 0 &&
+                 prog->info.num_ssbos == 0 &&
+                 prog->info.num_abos == 0))
       return;
 
    uint32_t *ubo_surf_offsets =
@@ -1283,9 +1285,16 @@ brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
                             ISL_FORMAT_R32G32B32A32_FLOAT, 0);
    }
 
-   uint32_t *ssbo_surf_offsets =
-      &stage_state->surf_offset[prog_data->binding_table.ssbo_start] +
-      prog->info.num_abos;
+   uint32_t *abo_surf_offsets =
+      &stage_state->surf_offset[prog_data->binding_table.ssbo_start];
+   uint32_t *ssbo_surf_offsets = abo_surf_offsets + prog->info.num_abos;
+
+   for (int i = 0; i < prog->info.num_abos; i++) {
+      struct gl_buffer_binding *binding =
+         &ctx->AtomicBufferBindings[prog->sh.AtomicBuffers[i]->Binding];
+      upload_buffer_surface(brw, binding, &abo_surf_offsets[i],
+                            ISL_FORMAT_RAW, RELOC_WRITE);
+   }
 
    for (int i = 0; i < prog->info.num_ssbos; i++) {
       struct gl_buffer_binding *binding =
@@ -1296,9 +1305,7 @@ brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
    }
 
    stage_state->push_constants_dirty = true;
-
-   if (prog->info.num_ubos || prog->info.num_ssbos)
-      brw->ctx.NewDriverState |= BRW_NEW_SURFACES;
+   brw->ctx.NewDriverState |= BRW_NEW_SURFACES;
 }
 
 static void
@@ -1344,72 +1351,6 @@ const struct brw_tracked_state brw_cs_ubo_surfaces = {
    .emit = brw_upload_cs_ubo_surfaces,
 };
 
-void
-brw_upload_abo_surfaces(struct brw_context *brw,
-                        const struct gl_program *prog,
-                        struct brw_stage_state *stage_state,
-                        struct brw_stage_prog_data *prog_data)
-{
-   struct gl_context *ctx = &brw->ctx;
-   uint32_t *surf_offsets =
-      &stage_state->surf_offset[prog_data->binding_table.ssbo_start];
-
-   if (prog->info.num_abos) {
-      for (unsigned i = 0; i < prog->info.num_abos; i++) {
-         struct gl_buffer_binding *binding =
-            &ctx->AtomicBufferBindings[prog->sh.AtomicBuffers[i]->Binding];
-         upload_buffer_surface(brw, binding, &surf_offsets[i],
-                               ISL_FORMAT_RAW, RELOC_WRITE);
-      }
-
-      brw->ctx.NewDriverState |= BRW_NEW_SURFACES;
-   }
-}
-
-static void
-brw_upload_wm_abo_surfaces(struct brw_context *brw)
-{
-   /* _NEW_PROGRAM */
-   const struct gl_program *wm = brw->programs[MESA_SHADER_FRAGMENT];
-
-   if (wm) {
-      /* BRW_NEW_FS_PROG_DATA */
-      brw_upload_abo_surfaces(brw, wm, &brw->wm.base, brw->wm.base.prog_data);
-   }
-}
-
-const struct brw_tracked_state brw_wm_abo_surfaces = {
-   .dirty = {
-      .mesa = _NEW_PROGRAM,
-      .brw = BRW_NEW_ATOMIC_BUFFER |
-             BRW_NEW_BATCH |
-             BRW_NEW_FS_PROG_DATA,
-   },
-   .emit = brw_upload_wm_abo_surfaces,
-};
-
-static void
-brw_upload_cs_abo_surfaces(struct brw_context *brw)
-{
-   /* _NEW_PROGRAM */
-   const struct gl_program *cp = brw->programs[MESA_SHADER_COMPUTE];
-
-   if (cp) {
-      /* BRW_NEW_CS_PROG_DATA */
-      brw_upload_abo_surfaces(brw, cp, &brw->cs.base, brw->cs.base.prog_data);
-   }
-}
-
-const struct brw_tracked_state brw_cs_abo_surfaces = {
-   .dirty = {
-      .mesa = _NEW_PROGRAM,
-      .brw = BRW_NEW_ATOMIC_BUFFER |
-             BRW_NEW_BATCH |
-             BRW_NEW_CS_PROG_DATA,
-   },
-   .emit = brw_upload_cs_abo_surfaces,
-};
-
 static void
 brw_upload_cs_image_surfaces(struct brw_context *brw)
 {
index 453b8e4adda7214755f671444c8243674de3db30..d4b0de850c9be732c0cee9a9098b1ba3db5a3119 100644 (file)
@@ -5483,19 +5483,14 @@ genX(init_atoms)(struct brw_context *brw)
        */
       &brw_vs_pull_constants,
       &brw_vs_ubo_surfaces,
-      &brw_vs_abo_surfaces,
       &brw_tcs_pull_constants,
       &brw_tcs_ubo_surfaces,
-      &brw_tcs_abo_surfaces,
       &brw_tes_pull_constants,
       &brw_tes_ubo_surfaces,
-      &brw_tes_abo_surfaces,
       &brw_gs_pull_constants,
       &brw_gs_ubo_surfaces,
-      &brw_gs_abo_surfaces,
       &brw_wm_pull_constants,
       &brw_wm_ubo_surfaces,
-      &brw_wm_abo_surfaces,
       &gen6_renderbuffer_surfaces,
       &brw_renderbuffer_read_surfaces,
       &brw_texture_surfaces,
@@ -5575,19 +5570,14 @@ genX(init_atoms)(struct brw_context *brw)
        */
       &brw_vs_pull_constants,
       &brw_vs_ubo_surfaces,
-      &brw_vs_abo_surfaces,
       &brw_tcs_pull_constants,
       &brw_tcs_ubo_surfaces,
-      &brw_tcs_abo_surfaces,
       &brw_tes_pull_constants,
       &brw_tes_ubo_surfaces,
-      &brw_tes_abo_surfaces,
       &brw_gs_pull_constants,
       &brw_gs_ubo_surfaces,
-      &brw_gs_abo_surfaces,
       &brw_wm_pull_constants,
       &brw_wm_ubo_surfaces,
-      &brw_wm_abo_surfaces,
       &gen6_renderbuffer_surfaces,
       &brw_renderbuffer_read_surfaces,
       &brw_texture_surfaces,
@@ -5657,7 +5647,6 @@ genX(init_atoms)(struct brw_context *brw)
       &genX(cs_push_constants),
       &genX(cs_pull_constants),
       &brw_cs_ubo_surfaces,
-      &brw_cs_abo_surfaces,
       &brw_cs_texture_surfaces,
       &brw_cs_work_groups_surface,
       &genX(cs_samplers),
index 49e68bd7392e23ae8b68f2623da29b616bf0a6d4..8268040911aa701551890baedc38c964db0444a7 100644 (file)
@@ -107,7 +107,7 @@ alloc_buffer_object(struct brw_context *brw,
    if (intel_obj->Base.UsageHistory & USAGE_TEXTURE_BUFFER)
       brw->ctx.NewDriverState |= BRW_NEW_TEXTURE_BUFFER;
    if (intel_obj->Base.UsageHistory & USAGE_ATOMIC_COUNTER_BUFFER)
-      brw->ctx.NewDriverState |= BRW_NEW_ATOMIC_BUFFER;
+      brw->ctx.NewDriverState |= BRW_NEW_UNIFORM_BUFFER;
 
    mark_buffer_inactive(intel_obj);
    mark_buffer_invalid(intel_obj);