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 <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8180>
This commit is contained in:
Marek Olšák 2021-01-11 10:37:57 -05:00
parent 8436d9c594
commit f8fe2ca600
2 changed files with 10 additions and 9 deletions

View file

@ -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)

View file

@ -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;