From 48d7e7a9b85d1391aaf2a605319b23e6e13fa096 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Tue, 4 Jun 2019 22:29:13 -0700 Subject: [PATCH] iris: Only upload surface state for grid info when needed 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 [v1] Reviewed-by: Kenneth Graunke --- src/gallium/drivers/iris/iris_draw.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/iris/iris_draw.c b/src/gallium/drivers/iris/iris_draw.c index fd937ec..0f7ca37 100644 --- a/src/gallium/drivers/iris/iris_draw.c +++ b/src/gallium/drivers/iris/iris_draw.c @@ -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, -- 2.7.4