Mesa (mesa_7_5_branch): mesa: Allocate tokens from the heap.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Mon Jun 8 16:02:35 UTC 2009


Module: Mesa
Branch: mesa_7_5_branch
Commit: 42678dba941b5a734e6aa03b530653d9c5341a70
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=42678dba941b5a734e6aa03b530653d9c5341a70

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Jun  8 16:27:59 2009 +0100

mesa: Allocate tokens from the heap.

The recent increase ST_MAX_SHADER_TOKENS to 8K causes stack overflows on
windows.

Failure to allocate is not being propagated to the caller. This is not
a regression since the previous _mesa_malloc result wasn't being
checked as well. Unfortunately it is not easy to fix, as the callers of
these functions do not have failure propagation mechanism either, and
so on. So leaving a just fixme note for now.

---

 src/mesa/state_tracker/st_program.c |   40 +++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 3492610..06030f6 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -55,20 +55,6 @@
 #define TGSI_DEBUG 0
 
 
-/** XXX we should use the version of this from u_memory.h but including
- * that header causes symbol collisions.
- */
-static INLINE void *
-mem_dup(const void *src, uint size)
-{
-   void *dup = _mesa_malloc(size);
-   if (dup)
-      _mesa_memcpy(dup, src, size);
-   return dup;
-}
-
-
-
 /**
  * Translate a Mesa vertex shader into a TGSI shader.
  * \param outputMapping  to map vertex program output registers (VERT_RESULT_x)
@@ -84,7 +70,7 @@ st_translate_vertex_program(struct st_context *st,
                             const ubyte *outputSemanticIndex)
 {
    struct pipe_context *pipe = st->pipe;
-   struct tgsi_token tokens[ST_MAX_SHADER_TOKENS];
+   struct tgsi_token *tokens;
    GLuint defaultOutputMapping[VERT_RESULT_MAX];
    struct pipe_shader_state vs;
    GLuint attr, i;
@@ -102,6 +88,13 @@ st_translate_vertex_program(struct st_context *st,
    GLbitfield input_flags[MAX_PROGRAM_INPUTS];
    GLbitfield output_flags[MAX_PROGRAM_OUTPUTS];
 
+   tokens =  (struct tgsi_token *)MALLOC(ST_MAX_SHADER_TOKENS * sizeof *tokens);
+   if(!tokens) {
+      /* FIXME: propagate error to the caller */
+      assert(0);
+      return;
+   }
+
    memset(&vs, 0, sizeof(vs));
    memset(input_flags, 0, sizeof(input_flags));
    memset(output_flags, 0, sizeof(output_flags));
@@ -347,7 +340,9 @@ st_translate_vertex_program(struct st_context *st,
    assert(num_tokens < ST_MAX_SHADER_TOKENS);
 
    vs.tokens = (struct tgsi_token *)
-      mem_dup(tokens, num_tokens * sizeof(tokens[0]));
+      _mesa_realloc(tokens,
+                    ST_MAX_SHADER_TOKENS * sizeof *tokens,
+                    num_tokens * sizeof *tokens);
 
    stvp->num_inputs = vs_num_inputs;
    stvp->state = vs; /* struct copy */
@@ -375,7 +370,7 @@ st_translate_fragment_program(struct st_context *st,
                               const GLuint inputMapping[])
 {
    struct pipe_context *pipe = st->pipe;
-   struct tgsi_token tokens[ST_MAX_SHADER_TOKENS];
+   struct tgsi_token *tokens;
    GLuint outputMapping[FRAG_RESULT_MAX];
    GLuint defaultInputMapping[FRAG_ATTRIB_MAX];
    struct pipe_shader_state fs;
@@ -395,6 +390,13 @@ st_translate_fragment_program(struct st_context *st,
    GLbitfield input_flags[MAX_PROGRAM_INPUTS];
    GLbitfield output_flags[MAX_PROGRAM_OUTPUTS];
 
+   tokens =  (struct tgsi_token *)MALLOC(ST_MAX_SHADER_TOKENS * sizeof *tokens);
+   if(!tokens) {
+      /* FIXME: propagate error to the caller */
+      assert(0);
+      return;
+   }
+
    memset(&fs, 0, sizeof(fs));
    memset(input_flags, 0, sizeof(input_flags));
    memset(output_flags, 0, sizeof(output_flags));
@@ -536,7 +538,9 @@ st_translate_fragment_program(struct st_context *st,
    assert(num_tokens < ST_MAX_SHADER_TOKENS);
 
    fs.tokens = (struct tgsi_token *)
-      mem_dup(tokens, num_tokens * sizeof(tokens[0]));
+      _mesa_realloc(tokens,
+                    ST_MAX_SHADER_TOKENS * sizeof *tokens,
+                    num_tokens * sizeof *tokens);
 
    stfp->state = fs; /* struct copy */
    stfp->driver_shader = pipe->create_fs_state(pipe, &fs);




More information about the mesa-commit mailing list