From b75b52530a2dd5e5d715e393164eed99e7957f3a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 18 Aug 2018 23:43:14 -0700 Subject: [PATCH] iris: Move things to iris_shader_state We didn't originally have this struct, so we had lots of ad-hoc arrays. Now that we have it, it makes sense to group things there. --- src/gallium/drivers/iris/iris_context.h | 12 ++++---- src/gallium/drivers/iris/iris_state.c | 39 +++++++++++++------------ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h index cfa2d70bf20..5111d59de75 100644 --- a/src/gallium/drivers/iris/iris_context.h +++ b/src/gallium/drivers/iris/iris_context.h @@ -240,6 +240,12 @@ struct iris_shader_state { struct iris_const_buffer constbuf[PIPE_MAX_CONSTANT_BUFFERS]; struct pipe_resource *ssbo[PIPE_MAX_SHADER_BUFFERS]; struct iris_state_ref ssbo_surface_state[PIPE_MAX_SHADER_BUFFERS]; + + struct iris_state_ref sampler_table; + struct iris_sampler_state *samplers[IRIS_MAX_TEXTURE_SAMPLERS]; + struct iris_sampler_view *textures[IRIS_MAX_TEXTURE_SAMPLERS]; + unsigned num_samplers; + unsigned num_textures; }; /** @@ -344,12 +350,8 @@ struct iris_context { struct iris_shader_state shaders[MESA_SHADER_STAGES]; - struct iris_state_ref sampler_table[MESA_SHADER_STAGES]; + /** Do any samplers (for any stage) need border color? */ bool need_border_colors; - struct iris_sampler_state *samplers[MESA_SHADER_STAGES][IRIS_MAX_TEXTURE_SAMPLERS]; - struct iris_sampler_view *textures[MESA_SHADER_STAGES][IRIS_MAX_TEXTURE_SAMPLERS]; - unsigned num_samplers[MESA_SHADER_STAGES]; - unsigned num_textures[MESA_SHADER_STAGES]; struct pipe_stream_output_target *so_target[PIPE_MAX_SO_BUFFERS]; bool streamout_active; diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index ce4b68464ab..f6a06bb7926 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -1115,34 +1115,33 @@ iris_bind_sampler_states(struct pipe_context *ctx, { struct iris_context *ice = (struct iris_context *) ctx; gl_shader_stage stage = stage_from_pipe(p_stage); + struct iris_shader_state *shs = &ice->state.shaders[stage]; assert(start + count <= IRIS_MAX_TEXTURE_SAMPLERS); - ice->state.num_samplers[stage] = - MAX2(ice->state.num_samplers[stage], start + count); + shs->num_samplers = MAX2(shs->num_samplers, start + count); for (int i = 0; i < count; i++) { - ice->state.samplers[stage][start + i] = states[i]; + shs->samplers[start + i] = states[i]; } /* Assemble the SAMPLER_STATEs into a contiguous table that lives * in the dynamic state memory zone, so we can point to it via the * 3DSTATE_SAMPLER_STATE_POINTERS_* commands. */ - void *map = upload_state(ice->state.dynamic_uploader, - &ice->state.sampler_table[stage], + void *map = upload_state(ice->state.dynamic_uploader, &shs->sampler_table, count * 4 * GENX(SAMPLER_STATE_length), 32); if (unlikely(!map)) return; - struct pipe_resource *res = ice->state.sampler_table[stage].res; - ice->state.sampler_table[stage].offset += + struct pipe_resource *res = shs->sampler_table.res; + shs->sampler_table.offset += iris_bo_offset_from_base_address(iris_resource_bo(res)); /* Make sure all land in the same BO */ iris_border_color_pool_reserve(ice, IRIS_MAX_TEXTURE_SAMPLERS); for (int i = 0; i < count; i++) { - struct iris_sampler_state *state = ice->state.samplers[stage][i]; + struct iris_sampler_state *state = shs->samplers[i]; if (!state) { memset(map, 0, 4 * GENX(SAMPLER_STATE_length)); @@ -1389,18 +1388,19 @@ iris_set_sampler_views(struct pipe_context *ctx, { struct iris_context *ice = (struct iris_context *) ctx; gl_shader_stage stage = stage_from_pipe(p_stage); + struct iris_shader_state *shs = &ice->state.shaders[stage]; unsigned i; for (i = 0; i < count; i++) { pipe_sampler_view_reference((struct pipe_sampler_view **) - &ice->state.textures[stage][i], views[i]); + &shs->textures[i], views[i]); } - for (; i < ice->state.num_textures[stage]; i++) { + for (; i < shs->num_textures; i++) { pipe_sampler_view_reference((struct pipe_sampler_view **) - &ice->state.textures[stage][i], NULL); + &shs->textures[i], NULL); } - ice->state.num_textures[stage] = count; + shs->num_textures = count; ice->state.dirty |= (IRIS_DIRTY_BINDINGS_VS << stage); } @@ -3054,8 +3054,8 @@ iris_populate_binding_table(struct iris_context *ice, //assert(prog_data->binding_table.texture_start == //(ice->state.num_textures[stage] ? s : 0xd0d0d0d0)); - for (int i = 0; i < ice->state.num_textures[stage]; i++) { - struct iris_sampler_view *view = ice->state.textures[stage][i]; + for (int i = 0; i < shs->num_textures; i++) { + struct iris_sampler_view *view = shs->textures[i]; bt_map[s++] = view ? use_sampler_view(batch, view) : use_null_surface(batch, ice); } @@ -3171,7 +3171,8 @@ iris_restore_context_saved_bos(struct iris_context *ice, } for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { - struct pipe_resource *res = ice->state.sampler_table[stage].res; + struct iris_shader_state *shs = &ice->state.shaders[stage]; + struct pipe_resource *res = shs->sampler_table.res; if (res) iris_use_pinned_bo(batch, iris_resource_bo(res), false); } @@ -3397,13 +3398,14 @@ iris_upload_render_state(struct iris_context *ice, !ice->shaders.prog[stage]) continue; - struct pipe_resource *res = ice->state.sampler_table[stage].res; + struct iris_shader_state *shs = &ice->state.shaders[stage]; + struct pipe_resource *res = shs->sampler_table.res; if (res) iris_use_pinned_bo(batch, iris_resource_bo(res), false); iris_emit_cmd(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS), ptr) { ptr._3DCommandSubOpcode = 43 + stage; - ptr.PointertoVSSamplerState = ice->state.sampler_table[stage].offset; + ptr.PointertoVSSamplerState = shs->sampler_table.offset; } } @@ -3770,7 +3772,8 @@ iris_destroy_state(struct iris_context *ice) pipe_surface_reference(&ice->state.framebuffer.zsbuf, NULL); for (int stage = 0; stage < MESA_SHADER_STAGES; stage++) { - pipe_resource_reference(&ice->state.sampler_table[stage].res, NULL); + struct iris_shader_state *shs = &ice->state.shaders[stage]; + pipe_resource_reference(&shs->sampler_table.res, NULL); } free(ice->state.genx); -- 2.30.2