From f8fe2ca600b2c1a0029fd71ab502e51385e4526d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 11 Jan 2021 10:37:57 -0500 Subject: [PATCH] st/mesa: optimize binding and unbinding shader images - use local variable num_images - only unbind the number of shader images that we have bound Reviewed-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Eric Anholt Part-of: --- src/mesa/state_tracker/st_atom_image.c | 18 +++++++++--------- src/mesa/state_tracker/st_context.h | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mesa/state_tracker/st_atom_image.c b/src/mesa/state_tracker/st_atom_image.c index f4c0a1a..37f12cf 100644 --- a/src/mesa/state_tracker/st_atom_image.c +++ b/src/mesa/state_tracker/st_atom_image.c @@ -161,14 +161,13 @@ st_bind_images(struct st_context *st, struct gl_program *prog, { unsigned i; struct pipe_image_view images[MAX_IMAGE_UNIFORMS]; - struct gl_program_constants *c; if (!prog || !st->pipe->set_shader_images) return; - c = &st->ctx->Const.Program[prog->info.stage]; + unsigned num_images = prog->info.num_images; - for (i = 0; i < prog->info.num_images; i++) { + for (i = 0; i < num_images; i++) { struct pipe_image_view *img = &images[i]; st_convert_image_from_unit(st, img, prog->sh.ImageUnits[i], @@ -176,14 +175,15 @@ st_bind_images(struct st_context *st, struct gl_program *prog, } struct pipe_context *pipe = st->pipe; - pipe->set_shader_images(pipe, shader_type, 0, - prog->info.num_images, images); + pipe->set_shader_images(pipe, shader_type, 0, num_images, images); + /* clear out any stale shader images */ - if (prog->info.num_images < c->MaxImageUniforms) { - pipe->set_shader_images(pipe, shader_type, prog->info.num_images, - c->MaxImageUniforms - prog->info.num_images, - NULL); + unsigned last_num_images = st->state.num_images[shader_type]; + if (num_images < last_num_images) { + pipe->set_shader_images(pipe, shader_type, num_images, + last_num_images - num_images, NULL); } + st->state.num_images[shader_type] = num_images; } void st_bind_vs_images(struct st_context *st) diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 274bda9..b8246dd 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -208,6 +208,7 @@ struct st_context struct pipe_sampler_view *vert_sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_sampler_view *frag_sampler_views[PIPE_MAX_SAMPLERS]; GLuint num_sampler_views[PIPE_SHADER_TYPES]; + unsigned num_images[PIPE_SHADER_TYPES]; struct pipe_clip_state clip; unsigned constbuf0_enabled_shader_mask; unsigned fb_width; -- 2.7.4