From 42678dba941b5a734e6aa03b530653d9c5341a70 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 8 Jun 2009 16:27:59 +0100 Subject: 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 file changed, 22 insertions(+), 18 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 34926101ed0..06030f6cd8e 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); -- cgit v1.2.3 From b6753adbc71a2d13e8ec095251f62cb267429de7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 8 Jun 2009 10:44:48 -0600 Subject: st/mesa: remove invalid assertion It's legal for ARB_vertex_program programs to not write to result.position. The results are undefined in that case. This assertion was causing us to abort/exit though. --- src/mesa/state_tracker/st_program.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 06030f6cd8e..72ca8524582 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -290,9 +290,6 @@ st_translate_vertex_program(struct st_context *st, } } - assert(vs_output_semantic_name[0] == TGSI_SEMANTIC_POSITION); - - if (outputMapping) { /* find max output slot referenced to compute vs_num_outputs */ GLuint maxSlot = 0; -- cgit v1.2.3 From 34bb024cf2d02d5d5cb672ead05fa131bdff6dd8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 8 Jun 2009 16:11:17 -0600 Subject: st/mesa: fix incorrect bufObj Length assignment, remove unneeded assertion --- src/mesa/state_tracker/st_cb_bufferobjects.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a94e11fff12..fbe6aa25de6 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -251,7 +251,7 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, map = obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); if(obj->Pointer) { obj->Offset = 0; - obj->Length = obj->Size; + obj->Length = length; map += offset; } @@ -270,7 +270,6 @@ st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target, /* Subrange is relative to mapped range */ assert(offset >= 0); assert(length >= 0); - assert(offset < obj->Length); assert(offset + length <= obj->Length); pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, -- cgit v1.2.3 From 76a1017e978f8e51114d765c8c98ff25da13042b Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 9 Jun 2009 18:32:18 +0100 Subject: mesa/st: fix tracking of mapped buffer ranges In st_bufferobj_map_range(), set obj->Offset consistently with its usage elsewhere. --- src/mesa/state_tracker/st_cb_bufferobjects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index fbe6aa25de6..19a0e673623 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -250,7 +250,7 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, map = obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); if(obj->Pointer) { - obj->Offset = 0; + obj->Offset = offset; obj->Length = length; map += offset; } -- cgit v1.2.3