st/mesa: don't store non-fragment sampler states and views in st_context

those are unused.

st_context: 10120 -> 3704 bytes

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Marek Olšák
2017-11-16 00:32:22 +01:00
parent e843667733
commit 08496c5d52
6 changed files with 61 additions and 62 deletions

View File

@@ -258,13 +258,18 @@ update_shader_samplers(struct st_context *st,
GLbitfield free_slots = ~prog->SamplersUsed; GLbitfield free_slots = ~prog->SamplersUsed;
GLbitfield external_samplers_used = prog->ExternalSamplersUsed; GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
unsigned unit, num_samplers; unsigned unit, num_samplers;
struct pipe_sampler_state local_samplers[PIPE_MAX_SAMPLERS];
const struct pipe_sampler_state *states[PIPE_MAX_SAMPLERS]; const struct pipe_sampler_state *states[PIPE_MAX_SAMPLERS];
if (samplers_used == 0x0) { if (samplers_used == 0x0) {
if (out_num_samplers)
*out_num_samplers = 0; *out_num_samplers = 0;
return; return;
} }
if (!samplers)
samplers = local_samplers;
num_samplers = util_last_bit(samplers_used); num_samplers = util_last_bit(samplers_used);
/* loop over sampler units (aka tex image units) */ /* loop over sampler units (aka tex image units) */
@@ -320,6 +325,8 @@ update_shader_samplers(struct st_context *st,
} }
cso_set_samplers(st->cso_context, shader_stage, num_samplers, states); cso_set_samplers(st->cso_context, shader_stage, num_samplers, states);
if (out_num_samplers)
*out_num_samplers = num_samplers; *out_num_samplers = num_samplers;
} }
@@ -331,9 +338,7 @@ st_update_vertex_samplers(struct st_context *st)
update_shader_samplers(st, update_shader_samplers(st,
PIPE_SHADER_VERTEX, PIPE_SHADER_VERTEX,
ctx->VertexProgram._Current, ctx->VertexProgram._Current, NULL, NULL);
st->state.samplers[PIPE_SHADER_VERTEX],
&st->state.num_samplers[PIPE_SHADER_VERTEX]);
} }
@@ -345,9 +350,7 @@ st_update_tessctrl_samplers(struct st_context *st)
if (ctx->TessCtrlProgram._Current) { if (ctx->TessCtrlProgram._Current) {
update_shader_samplers(st, update_shader_samplers(st,
PIPE_SHADER_TESS_CTRL, PIPE_SHADER_TESS_CTRL,
ctx->TessCtrlProgram._Current, ctx->TessCtrlProgram._Current, NULL, NULL);
st->state.samplers[PIPE_SHADER_TESS_CTRL],
&st->state.num_samplers[PIPE_SHADER_TESS_CTRL]);
} }
} }
@@ -360,9 +363,7 @@ st_update_tesseval_samplers(struct st_context *st)
if (ctx->TessEvalProgram._Current) { if (ctx->TessEvalProgram._Current) {
update_shader_samplers(st, update_shader_samplers(st,
PIPE_SHADER_TESS_EVAL, PIPE_SHADER_TESS_EVAL,
ctx->TessEvalProgram._Current, ctx->TessEvalProgram._Current, NULL, NULL);
st->state.samplers[PIPE_SHADER_TESS_EVAL],
&st->state.num_samplers[PIPE_SHADER_TESS_EVAL]);
} }
} }
@@ -375,9 +376,7 @@ st_update_geometry_samplers(struct st_context *st)
if (ctx->GeometryProgram._Current) { if (ctx->GeometryProgram._Current) {
update_shader_samplers(st, update_shader_samplers(st,
PIPE_SHADER_GEOMETRY, PIPE_SHADER_GEOMETRY,
ctx->GeometryProgram._Current, ctx->GeometryProgram._Current, NULL, NULL);
st->state.samplers[PIPE_SHADER_GEOMETRY],
&st->state.num_samplers[PIPE_SHADER_GEOMETRY]);
} }
} }
@@ -390,8 +389,8 @@ st_update_fragment_samplers(struct st_context *st)
update_shader_samplers(st, update_shader_samplers(st,
PIPE_SHADER_FRAGMENT, PIPE_SHADER_FRAGMENT,
ctx->FragmentProgram._Current, ctx->FragmentProgram._Current,
st->state.samplers[PIPE_SHADER_FRAGMENT], st->state.frag_samplers,
&st->state.num_samplers[PIPE_SHADER_FRAGMENT]); &st->state.num_frag_samplers);
} }
@@ -403,8 +402,6 @@ st_update_compute_samplers(struct st_context *st)
if (ctx->ComputeProgram._Current) { if (ctx->ComputeProgram._Current) {
update_shader_samplers(st, update_shader_samplers(st,
PIPE_SHADER_COMPUTE, PIPE_SHADER_COMPUTE,
ctx->ComputeProgram._Current, ctx->ComputeProgram._Current, NULL, NULL);
st->state.samplers[PIPE_SHADER_COMPUTE],
&st->state.num_samplers[PIPE_SHADER_COMPUTE]);
} }
} }

View File

@@ -216,7 +216,21 @@ update_textures(struct st_context *st,
*out_num_textures = num_textures; *out_num_textures = num_textures;
} }
/* Same as update_textures, but don't store the views in st_context. */
static void
update_textures_local(struct st_context *st,
enum pipe_shader_type shader_stage,
const struct gl_program *prog,
unsigned *out_num_textures)
{
struct pipe_sampler_view *local_views[PIPE_MAX_SAMPLERS] = {0};
update_textures(st, shader_stage, prog, local_views, out_num_textures);
unsigned num = *out_num_textures;
for (unsigned i = 0; i < num; i++)
pipe_sampler_view_reference(&local_views[i], NULL);
}
void void
st_update_vertex_textures(struct st_context *st) st_update_vertex_textures(struct st_context *st)
@@ -224,10 +238,8 @@ st_update_vertex_textures(struct st_context *st)
const struct gl_context *ctx = st->ctx; const struct gl_context *ctx = st->ctx;
if (ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits > 0) { if (ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits > 0) {
update_textures(st, update_textures_local(st, PIPE_SHADER_VERTEX,
PIPE_SHADER_VERTEX,
ctx->VertexProgram._Current, ctx->VertexProgram._Current,
st->state.sampler_views[PIPE_SHADER_VERTEX],
&st->state.num_sampler_views[PIPE_SHADER_VERTEX]); &st->state.num_sampler_views[PIPE_SHADER_VERTEX]);
} }
} }
@@ -241,7 +253,7 @@ st_update_fragment_textures(struct st_context *st)
update_textures(st, update_textures(st,
PIPE_SHADER_FRAGMENT, PIPE_SHADER_FRAGMENT,
ctx->FragmentProgram._Current, ctx->FragmentProgram._Current,
st->state.sampler_views[PIPE_SHADER_FRAGMENT], st->state.frag_sampler_views,
&st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]); &st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
} }
@@ -252,10 +264,8 @@ st_update_geometry_textures(struct st_context *st)
const struct gl_context *ctx = st->ctx; const struct gl_context *ctx = st->ctx;
if (ctx->GeometryProgram._Current) { if (ctx->GeometryProgram._Current) {
update_textures(st, update_textures_local(st, PIPE_SHADER_GEOMETRY,
PIPE_SHADER_GEOMETRY,
ctx->GeometryProgram._Current, ctx->GeometryProgram._Current,
st->state.sampler_views[PIPE_SHADER_GEOMETRY],
&st->state.num_sampler_views[PIPE_SHADER_GEOMETRY]); &st->state.num_sampler_views[PIPE_SHADER_GEOMETRY]);
} }
} }
@@ -267,10 +277,8 @@ st_update_tessctrl_textures(struct st_context *st)
const struct gl_context *ctx = st->ctx; const struct gl_context *ctx = st->ctx;
if (ctx->TessCtrlProgram._Current) { if (ctx->TessCtrlProgram._Current) {
update_textures(st, update_textures_local(st, PIPE_SHADER_TESS_CTRL,
PIPE_SHADER_TESS_CTRL,
ctx->TessCtrlProgram._Current, ctx->TessCtrlProgram._Current,
st->state.sampler_views[PIPE_SHADER_TESS_CTRL],
&st->state.num_sampler_views[PIPE_SHADER_TESS_CTRL]); &st->state.num_sampler_views[PIPE_SHADER_TESS_CTRL]);
} }
} }
@@ -282,10 +290,8 @@ st_update_tesseval_textures(struct st_context *st)
const struct gl_context *ctx = st->ctx; const struct gl_context *ctx = st->ctx;
if (ctx->TessEvalProgram._Current) { if (ctx->TessEvalProgram._Current) {
update_textures(st, update_textures_local(st, PIPE_SHADER_TESS_EVAL,
PIPE_SHADER_TESS_EVAL,
ctx->TessEvalProgram._Current, ctx->TessEvalProgram._Current,
st->state.sampler_views[PIPE_SHADER_TESS_EVAL],
&st->state.num_sampler_views[PIPE_SHADER_TESS_EVAL]); &st->state.num_sampler_views[PIPE_SHADER_TESS_EVAL]);
} }
} }
@@ -297,10 +303,8 @@ st_update_compute_textures(struct st_context *st)
const struct gl_context *ctx = st->ctx; const struct gl_context *ctx = st->ctx;
if (ctx->ComputeProgram._Current) { if (ctx->ComputeProgram._Current) {
update_textures(st, update_textures_local(st, PIPE_SHADER_COMPUTE,
PIPE_SHADER_COMPUTE,
ctx->ComputeProgram._Current, ctx->ComputeProgram._Current,
st->state.sampler_views[PIPE_SHADER_COMPUTE],
&st->state.num_sampler_views[PIPE_SHADER_COMPUTE]); &st->state.num_sampler_views[PIPE_SHADER_COMPUTE]);
} }
} }

View File

@@ -224,10 +224,10 @@ setup_render_state(struct gl_context *ctx,
{ {
struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
uint num = MAX2(fpv->bitmap_sampler + 1, uint num = MAX2(fpv->bitmap_sampler + 1,
st->state.num_samplers[PIPE_SHADER_FRAGMENT]); st->state.num_frag_samplers);
uint i; uint i;
for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++) { for (i = 0; i < st->state.num_frag_samplers; i++) {
samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i]; samplers[i] = &st->state.frag_samplers[i];
} }
if (atlas) if (atlas)
samplers[fpv->bitmap_sampler] = &st->bitmap.atlas_sampler; samplers[fpv->bitmap_sampler] = &st->bitmap.atlas_sampler;
@@ -242,7 +242,7 @@ setup_render_state(struct gl_context *ctx,
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
uint num = MAX2(fpv->bitmap_sampler + 1, uint num = MAX2(fpv->bitmap_sampler + 1,
st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]); st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT], memcpy(sampler_views, st->state.frag_sampler_views,
sizeof(sampler_views)); sizeof(sampler_views));
sampler_views[fpv->bitmap_sampler] = sv; sampler_views[fpv->bitmap_sampler] = sv;
cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num, sampler_views); cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num, sampler_views);

View File

@@ -736,11 +736,11 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
const struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; const struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
uint num = MAX3(fpv->drawpix_sampler + 1, uint num = MAX3(fpv->drawpix_sampler + 1,
fpv->pixelmap_sampler + 1, fpv->pixelmap_sampler + 1,
st->state.num_samplers[PIPE_SHADER_FRAGMENT]); st->state.num_frag_samplers);
uint i; uint i;
for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++) for (i = 0; i < st->state.num_frag_samplers; i++)
samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i]; samplers[i] = &st->state.frag_samplers[i];
samplers[fpv->drawpix_sampler] = &sampler; samplers[fpv->drawpix_sampler] = &sampler;
if (sv[1]) if (sv[1])
@@ -763,7 +763,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
fpv->pixelmap_sampler + 1, fpv->pixelmap_sampler + 1,
st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]); st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT], memcpy(sampler_views, st->state.frag_sampler_views,
sizeof(sampler_views)); sizeof(sampler_views));
sampler_views[fpv->drawpix_sampler] = sv[0]; sampler_views[fpv->drawpix_sampler] = sv[0];

View File

@@ -254,7 +254,7 @@ st_invalidate_state(struct gl_context *ctx)
static void static void
st_destroy_context_priv(struct st_context *st, bool destroy_pipe) st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
{ {
uint shader, i; uint i;
st_destroy_atoms(st); st_destroy_atoms(st);
st_destroy_draw(st); st_destroy_draw(st);
@@ -267,11 +267,9 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
st_destroy_bound_texture_handles(st); st_destroy_bound_texture_handles(st);
st_destroy_bound_image_handles(st); st_destroy_bound_image_handles(st);
for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) { for (i = 0; i < ARRAY_SIZE(st->state.frag_sampler_views); i++) {
for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) {
pipe_sampler_view_release(st->pipe, pipe_sampler_view_release(st->pipe,
&st->state.sampler_views[shader][i]); &st->state.frag_sampler_views[i]);
}
} }
/* free glReadPixels cache data */ /* free glReadPixels cache data */

View File

@@ -151,9 +151,9 @@ struct st_context
struct pipe_blend_state blend; struct pipe_blend_state blend;
struct pipe_depth_stencil_alpha_state depth_stencil; struct pipe_depth_stencil_alpha_state depth_stencil;
struct pipe_rasterizer_state rasterizer; struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; struct pipe_sampler_state frag_samplers[PIPE_MAX_SAMPLERS];
GLuint num_samplers[PIPE_SHADER_TYPES]; GLuint num_frag_samplers;
struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; struct pipe_sampler_view *frag_sampler_views[PIPE_MAX_SAMPLERS];
GLuint num_sampler_views[PIPE_SHADER_TYPES]; GLuint num_sampler_views[PIPE_SHADER_TYPES];
struct pipe_clip_state clip; struct pipe_clip_state clip;
struct { struct {