iris: Only upload surface state for grid info when needed
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 5 Jun 2019 05:29:13 +0000 (22:29 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 12 Jun 2019 00:57:37 +0000 (17:57 -0700)
Special care is needed to ensure that when we have two consecutive
calls with the same grid size, we only bail in the second one if it
either don't need the surface state or the surface state was already
uploaded.

v2: Instead of having a new bool in ice->state to know whether we had
    a surface, check whether we have state->ref.  (Ken)
    Clean up the logic a little bit by adding 'grid_updated' local. (Ken)

Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com> [v1]
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/iris/iris_draw.c

index fd937ec7138afc8718ebd9e5f41b2c83fe3ee08d..0f7ca37561fbead15f716e0cbe05c6fb2b53179a 100644 (file)
@@ -253,8 +253,9 @@ iris_update_grid_size_resource(struct iris_context *ice,
    struct iris_state_ref *grid_ref = &ice->state.grid_size;
    struct iris_state_ref *state_ref = &ice->state.grid_surf_state;
 
-   // XXX: if the shader doesn't actually care about the grid info,
-   // don't bother uploading the surface?
+   const struct iris_compiled_shader *shader = ice->shaders.prog[MESA_SHADER_COMPUTE];
+   bool grid_needs_surface = shader->bt.used_mask[IRIS_SURFACE_GROUP_CS_WORK_GROUPS];
+   bool grid_updated = false;
 
    if (grid->indirect) {
       pipe_resource_reference(&grid_ref->res, grid->indirect);
@@ -264,17 +265,22 @@ iris_update_grid_size_resource(struct iris_context *ice,
        * re-upload it properly.
        */
       memset(ice->state.last_grid, 0, sizeof(ice->state.last_grid));
-   } else {
-      /* If the size is the same, we don't need to upload anything. */
-      if (memcmp(ice->state.last_grid, grid->grid, sizeof(grid->grid)) == 0)
-         return;
-
+      grid_updated = true;
+   } else if (memcmp(ice->state.last_grid, grid->grid, sizeof(grid->grid)) != 0) {
       memcpy(ice->state.last_grid, grid->grid, sizeof(grid->grid));
-
       u_upload_data(ice->state.dynamic_uploader, 0, sizeof(grid->grid), 4,
                     grid->grid, &grid_ref->offset, &grid_ref->res);
+      grid_updated = true;
    }
 
+   /* If we changed the grid, the old surface state is invalid. */
+   if (grid_updated)
+      pipe_resource_reference(&state_ref->res, NULL);
+
+   /* Skip surface upload if we don't need it or we already have one */
+   if (!grid_needs_surface || state_ref->res)
+      return;
+
    void *surf_map = NULL;
    u_upload_alloc(ice->state.surface_uploader, 0, isl_dev->ss.size,
                   isl_dev->ss.align, &state_ref->offset, &state_ref->res,