From d4658ddb7333e44dfe2a8423a749635b286cc33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Thu, 27 Nov 2025 08:34:39 -0800 Subject: [PATCH] iris: Move code to emit binding tables to its own function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allow us to reduce a bit the size of iris_upload_dirty_render_state() and in next patches some improvements to this new function will be done. Reviewed-by: Tapani Pälli Signed-off-by: José Roberto de Souza Part-of: --- src/gallium/drivers/iris/iris_state.c | 90 +++++++++++++++------------ 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index 3f1c4377d8c..05208a4b606 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -6936,6 +6936,54 @@ setup_autostrip_state(struct iris_context *ice, #endif } +static void +iris_emit_binding_tables(struct iris_context *ice, struct iris_batch *batch, + uint64_t stage_dirty) +{ + struct iris_binder *binder = &ice->state.binder; + + for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { + /* Gfx9 requires 3DSTATE_BINDING_TABLE_POINTERS_XS to be re-emitted + * in order to commit constants. TODO: Investigate "Disable Gather + * at Set Shader" to go back to legacy mode... + */ + if (stage_dirty & ((IRIS_STAGE_DIRTY_BINDINGS_VS | + (GFX_VER == 9 ? IRIS_STAGE_DIRTY_CONSTANTS_VS : 0)) + << stage)) { + iris_emit_cmd(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS), ptr) { + ptr._3DCommandSubOpcode = 38 + stage; + ptr.PointertoVSBindingTable = + binder->bt_offset[stage] >> IRIS_BT_OFFSET_SHIFT; + } + } + } + + for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { + if (stage_dirty & (IRIS_STAGE_DIRTY_BINDINGS_VS << stage)) { + iris_populate_binding_table(ice, batch, stage, false); + } + } + + for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { + if (!(stage_dirty & (IRIS_STAGE_DIRTY_SAMPLER_STATES_VS << stage)) || + !ice->shaders.prog[stage]) + continue; + + iris_upload_sampler_states(ice, stage); + + 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_DOMAIN_NONE); + + iris_emit_cmd(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS), ptr) { + ptr._3DCommandSubOpcode = 43 + stage; + ptr.PointertoVSSamplerState = shs->sampler_table.offset; + } + } +} + static void iris_upload_dirty_render_state(struct iris_context *ice, struct iris_batch *batch, @@ -6967,7 +7015,6 @@ iris_upload_dirty_render_state(struct iris_context *ice, return; struct iris_genx_state *genx = ice->state.genx; - struct iris_binder *binder = &ice->state.binder; struct iris_fs_data *fs_data = iris_fs_data(ice->shaders.prog[MESA_SHADER_FRAGMENT]); @@ -7345,21 +7392,7 @@ iris_upload_dirty_render_state(struct iris_context *ice, emit_push_constant_packet_all(ice, batch, nobuffer_stages, NULL); #endif - for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { - /* Gfx9 requires 3DSTATE_BINDING_TABLE_POINTERS_XS to be re-emitted - * in order to commit constants. TODO: Investigate "Disable Gather - * at Set Shader" to go back to legacy mode... - */ - if (stage_dirty & ((IRIS_STAGE_DIRTY_BINDINGS_VS | - (GFX_VER == 9 ? IRIS_STAGE_DIRTY_CONSTANTS_VS : 0)) - << stage)) { - iris_emit_cmd(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS), ptr) { - ptr._3DCommandSubOpcode = 38 + stage; - ptr.PointertoVSBindingTable = - binder->bt_offset[stage] >> IRIS_BT_OFFSET_SHIFT; - } - } - } + iris_emit_binding_tables(ice, batch, stage_dirty); if (GFX_VER >= 11 && (dirty & IRIS_DIRTY_RENDER_BUFFER)) { // XXX: we may want to flag IRIS_DIRTY_MULTISAMPLE (or SAMPLE_MASK?) @@ -7382,31 +7415,6 @@ iris_upload_dirty_render_state(struct iris_context *ice, if (dirty & IRIS_DIRTY_RENDER_BUFFER) trace_framebuffer_state(&batch->trace, NULL, &ice->state.framebuffer); - for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { - if (stage_dirty & (IRIS_STAGE_DIRTY_BINDINGS_VS << stage)) { - iris_populate_binding_table(ice, batch, stage, false); - } - } - - for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) { - if (!(stage_dirty & (IRIS_STAGE_DIRTY_SAMPLER_STATES_VS << stage)) || - !ice->shaders.prog[stage]) - continue; - - iris_upload_sampler_states(ice, stage); - - 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_DOMAIN_NONE); - - iris_emit_cmd(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS), ptr) { - ptr._3DCommandSubOpcode = 43 + stage; - ptr.PointertoVSSamplerState = shs->sampler_table.offset; - } - } - if (ice->state.need_border_colors) iris_use_pinned_bo(batch, border_color_pool->bo, false, IRIS_DOMAIN_NONE);