[Mesa-dev] [PATCH 1/2] state_tracker: Initialize the draw context only when needed.
Eric Anholt
eric at anholt.net
Wed Aug 3 17:27:52 UTC 2016
It's only used for rarely-used deprecated GL features
(feedback/rasterpos), so we can skip the memory allocation and
initialization for it most of the time.
Saves about 659k (out of 1605k) of maximum memory size according to massif
on simulated vc4 glsl-algebraic-add-add-1
---
src/mesa/state_tracker/st_cb_feedback.c | 5 ++++-
src/mesa/state_tracker/st_cb_rasterpos.c | 5 ++++-
src/mesa/state_tracker/st_draw.c | 31 +++++++++++++++++++++++--------
src/mesa/state_tracker/st_draw.h | 2 ++
src/mesa/state_tracker/st_draw_feedback.c | 5 +++--
5 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c
index 735e268be870..a18f4f76bcf2 100644
--- a/src/mesa/state_tracker/st_cb_feedback.c
+++ b/src/mesa/state_tracker/st_cb_feedback.c
@@ -274,7 +274,10 @@ static void
st_RenderMode(struct gl_context *ctx, GLenum newMode )
{
struct st_context *st = st_context(ctx);
- struct draw_context *draw = st->draw;
+ struct draw_context *draw = st_get_draw_context(st);
+
+ if (!st->draw)
+ return;
if (newMode == GL_RENDER) {
/* restore normal VBO draw function */
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index 29c148471801..5dda0e2c8b7b 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -219,10 +219,13 @@ static void
st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
{
struct st_context *st = st_context(ctx);
- struct draw_context *draw = st->draw;
+ struct draw_context *draw = st_get_draw_context(st);
struct rastpos_stage *rs;
const struct gl_client_array **saved_arrays = ctx->Array._DrawArrays;
+ if (!st->draw)
+ return;
+
if (ctx->VertexProgram._Current == NULL ||
ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) {
/* No vertex shader/program is enabled, used the simple/fast fixed-
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index b248dafc9a20..f4af23da97f3 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -346,8 +346,29 @@ st_init_draw(struct st_context *st)
vbo_set_draw_func(ctx, st_draw_vbo);
vbo_set_indirect_draw_func(ctx, st_indirect_draw_vbo);
+}
+
+
+void
+st_destroy_draw(struct st_context *st)
+{
+ draw_destroy(st->draw);
+}
- st->draw = draw_create(st->pipe); /* for selection/feedback */
+/**
+ * Getter for the draw_context, so that initialization of it can happen only
+ * when needed (the TGSI exec machines take up quite a bit of memory).
+ */
+struct draw_context *
+st_get_draw_context(struct st_context *st)
+{
+ if (!st->draw) {
+ st->draw = draw_create(st->pipe);
+ if (!st->draw) {
+ _mesa_error(st->ctx, GL_OUT_OF_MEMORY, "feedback fallback allocation");
+ return NULL;
+ }
+ }
/* Disable draw options that might convert points/lines to tris, etc.
* as that would foul-up feedback/selection mode.
@@ -356,16 +377,10 @@ st_init_draw(struct st_context *st)
draw_wide_point_threshold(st->draw, 1000.0f);
draw_enable_line_stipple(st->draw, FALSE);
draw_enable_point_sprites(st->draw, FALSE);
-}
-
-void
-st_destroy_draw(struct st_context *st)
-{
- draw_destroy(st->draw);
+ return st->draw;
}
-
/**
* Draw a quad with given position, texcoords and color.
*/
diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h
index d85c3b7facdd..fc863819c7e0 100644
--- a/src/mesa/state_tracker/st_draw.h
+++ b/src/mesa/state_tracker/st_draw.h
@@ -47,6 +47,8 @@ void st_init_draw( struct st_context *st );
void st_destroy_draw( struct st_context *st );
+struct draw_context *st_get_draw_context(struct st_context *st);
+
extern void
st_draw_vbo(struct gl_context *ctx,
const struct _mesa_prim *prims,
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index e76694d4b2b0..6cc7dd77701d 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -123,7 +123,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
{
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
- struct draw_context *draw = st->draw;
+ struct draw_context *draw = st_get_draw_context(st);
const struct st_vertex_program *vp;
const struct pipe_shader_state *vs;
struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
@@ -136,7 +136,8 @@ st_feedback_draw_vbo(struct gl_context *ctx,
const GLubyte *low_addr = NULL;
const void *mapped_indices = NULL;
- assert(draw);
+ if (!draw)
+ return;
st_flush_bitmap_cache(st);
st_invalidate_readpix_cache(st);
--
2.8.1
More information about the mesa-dev
mailing list