Mesa (main): st/mesa: don't track FS sampler views for bitmap/drawpix in st_context
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Jun 27 13:07:33 UTC 2021
Module: Mesa
Branch: main
Commit: 8106d9a807336b38997f09a6f072ae2fd4009d46
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8106d9a807336b38997f09a6f072ae2fd4009d46
Author: Marek Olšák <marek.olsak at amd.com>
Date: Sat Jun 5 22:10:12 2021 -0400
st/mesa: don't track FS sampler views for bitmap/drawpix in st_context
Just query the sampler views from the update function. This will help
optimize sampler view updates.
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11428>
---
src/mesa/state_tracker/st_atom_texture.c | 6 ++----
src/mesa/state_tracker/st_cb_bitmap.c | 25 ++++++++++-------------
src/mesa/state_tracker/st_cb_drawpixels.c | 34 +++++++++++++++++--------------
src/mesa/state_tracker/st_context.c | 6 ------
src/mesa/state_tracker/st_context.h | 1 -
5 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index 8d0d343fbaf..f2667ffced3 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -319,10 +319,8 @@ st_update_fragment_textures(struct st_context *st)
{
const struct gl_context *ctx = st->ctx;
- update_textures(st,
- PIPE_SHADER_FRAGMENT,
- ctx->FragmentProgram._Current,
- st->state.frag_sampler_views);
+ update_textures_local(st, PIPE_SHADER_FRAGMENT,
+ ctx->FragmentProgram._Current);
}
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index ffa6dcb3f07..b3f48ba2b91 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -241,16 +241,19 @@ setup_render_state(struct gl_context *ctx,
/* user textures, plus the bitmap texture */
{
- struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
- uint num = MAX2(fpv->bitmap_sampler + 1,
- st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
- memcpy(sampler_views, st->state.frag_sampler_views,
- sizeof(sampler_views));
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS] = {};
+ unsigned num_views =
+ st_get_sampler_views(st, PIPE_SHADER_FRAGMENT,
+ ctx->FragmentProgram._Current, sampler_views);
+
+ num_views = MAX2(fpv->bitmap_sampler + 1, num_views);
sampler_views[fpv->bitmap_sampler] = sv;
- pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num, 0,
+ pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_views, 0,
sampler_views);
- st->state.num_sampler_views[PIPE_SHADER_FRAGMENT] =
- MAX2(st->state.num_sampler_views[PIPE_SHADER_FRAGMENT], num);
+ st->state.num_sampler_views[PIPE_SHADER_FRAGMENT] = num_views;
+
+ for (unsigned i = 0; i < num_views; i++)
+ pipe_sampler_view_reference(&sampler_views[i], NULL);
}
/* viewport state: viewport matching window dims */
@@ -456,8 +459,6 @@ st_flush_bitmap_cache(struct st_context *st)
BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
sv,
cache->color);
-
- pipe_sampler_view_reference(&sv, NULL);
}
/* release/free the texture */
@@ -643,8 +644,6 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
if (sv) {
draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
width, height, sv, ctx->Current.RasterColor);
-
- pipe_sampler_view_reference(&sv, NULL);
}
/* release/free the texture */
@@ -785,8 +784,6 @@ out:
pipe_resource_reference(&vb.buffer.resource, NULL);
- pipe_sampler_view_reference(&sv, NULL);
-
/* We uploaded modified constants, need to invalidate them. */
st->dirty |= ST_NEW_FS_CONSTANTS;
}
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 62ee6ad2a7e..49478bf368d 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -867,30 +867,38 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
}
}
+ unsigned tex_width = sv[0]->texture->width0;
+ unsigned tex_height = sv[0]->texture->height0;
+
/* user textures, plus the drawpix textures */
if (fpv) {
/* drawing a color image */
- struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
- uint num = MAX3(fpv->drawpix_sampler + 1,
- fpv->pixelmap_sampler + 1,
- st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS] = {0};
+ unsigned num_views =
+ st_get_sampler_views(st, PIPE_SHADER_FRAGMENT,
+ ctx->FragmentProgram._Current, sampler_views);
- memcpy(sampler_views, st->state.frag_sampler_views,
- sizeof(sampler_views));
+ num_views = MAX3(fpv->drawpix_sampler + 1, fpv->pixelmap_sampler + 1,
+ num_views);
sampler_views[fpv->drawpix_sampler] = sv[0];
if (sv[1])
sampler_views[fpv->pixelmap_sampler] = sv[1];
- pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num, 0,
+ pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_views, 0,
sampler_views);
- st->state.num_sampler_views[PIPE_SHADER_FRAGMENT] =
- MAX2(st->state.num_sampler_views[PIPE_SHADER_FRAGMENT], num);
+ st->state.num_sampler_views[PIPE_SHADER_FRAGMENT] = num_views;
+
+ for (unsigned i = 0; i < num_views; i++)
+ pipe_sampler_view_reference(&sampler_views[i], NULL);
} else {
/* drawing a depth/stencil image */
pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_sampler_view,
0, sv);
st->state.num_sampler_views[PIPE_SHADER_FRAGMENT] =
MAX2(st->state.num_sampler_views[PIPE_SHADER_FRAGMENT], num_sampler_view);
+
+ for (unsigned i = 0; i < num_sampler_view; i++)
+ pipe_sampler_view_reference(&sv[i], NULL);
}
/* viewport state: viewport matching window dims */
@@ -923,9 +931,9 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
const float clip_x1 = x1 / (float) fb_width * 2.0f - 1.0f;
const float clip_y1 = y1 / (float) fb_height * 2.0f - 1.0f;
const float maxXcoord = normalized ?
- ((float) width / sv[0]->texture->width0) : (float) width;
+ ((float) width / tex_width) : (float) width;
const float maxYcoord = normalized
- ? ((float) height / sv[0]->texture->height0) : (float) height;
+ ? ((float) height / tex_height) : (float) height;
const float sLeft = 0.0f, sRight = maxXcoord;
const float tTop = invertTex ? maxYcoord : 0.0f;
const float tBot = invertTex ? 0.0f : maxYcoord;
@@ -1435,9 +1443,6 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
driver_fp, fpv,
ctx->Current.RasterColor,
GL_FALSE, write_depth, write_stencil);
- pipe_sampler_view_reference(&sv[0], NULL);
- if (num_sampler_view > 1)
- pipe_sampler_view_reference(&sv[1], NULL);
/* free the texture (but may persist in the cache) */
pipe_resource_reference(&pt, NULL);
@@ -1975,7 +1980,6 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
invertTex, write_depth, write_stencil);
pipe_resource_reference(&pt, NULL);
- pipe_sampler_view_reference(&sv[0], NULL);
}
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index a79c8ba0636..6b57538eb86 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -454,8 +454,6 @@ st_context_free_zombie_objects(struct st_context *st)
static void
st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
{
- uint i;
-
st_destroy_atoms(st);
st_destroy_draw(st);
st_destroy_clear(st);
@@ -467,10 +465,6 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
st_destroy_bound_texture_handles(st);
st_destroy_bound_image_handles(st);
- for (i = 0; i < ARRAY_SIZE(st->state.frag_sampler_views); i++) {
- pipe_sampler_view_reference(&st->state.frag_sampler_views[i], NULL);
- }
-
/* free glReadPixels cache data */
st_invalidate_readpix_cache(st);
util_throttle_deinit(st->screen, &st->throttle);
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 618fe760691..85744032d13 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -210,7 +210,6 @@ struct st_context
struct pipe_sampler_state frag_samplers[PIPE_MAX_SAMPLERS];
GLuint num_vert_samplers;
GLuint num_frag_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;
More information about the mesa-commit
mailing list