gallium: make a copy of the vertex shader's token array.

This solves problems when the state tracker frees the token array when the
draw module still needs it.
This commit is contained in:
Brian 2008-03-24 16:31:15 -06:00
parent 7f43029377
commit ae146e4bc8
3 changed files with 17 additions and 3 deletions

View file

@ -38,6 +38,8 @@
#include "draw_context.h"
#include "draw_vs.h"
#include "tgsi/util/tgsi_parse.h"
static INLINE unsigned
compute_clipmask(const float *clip, /*const*/ float plane[][4], unsigned nr)
@ -187,6 +189,7 @@ vs_exec_run( struct draw_vertex_shader *shader,
static void
vs_exec_delete( struct draw_vertex_shader *dvs )
{
FREE((void*) dvs->state.tokens);
FREE( dvs );
}
@ -196,11 +199,13 @@ draw_create_vs_exec(struct draw_context *draw,
const struct pipe_shader_state *state)
{
struct draw_vertex_shader *vs = CALLOC_STRUCT( draw_vertex_shader );
uint nt = tgsi_num_tokens(state->tokens);
if (vs == NULL)
return NULL;
vs->state = *state;
/* we make a private copy of the tokens */
vs->state.tokens = mem_dup(state->tokens, nt * sizeof(state->tokens[0]));
vs->prepare = vs_exec_prepare;
vs->run = vs_exec_run;
vs->delete = vs_exec_delete;

View file

@ -38,6 +38,8 @@
#include "draw_context.h"
#include "draw_vs.h"
#include "tgsi/util/tgsi_parse.h"
#ifdef MESA_LLVM
#include "gallivm/gallivm.h"
@ -186,6 +188,7 @@ vs_llvm_delete( struct draw_vertex_shader *base )
/* Do something to free compiled shader:
*/
FREE( (void*) shader->base.state.tokens );
FREE( shader );
}
@ -197,12 +200,14 @@ draw_create_vs_llvm(struct draw_context *draw,
const struct pipe_shader_state *templ)
{
struct draw_llvm_vertex_shader *vs;
uint nt = tgsi_num_tokens(templ->tokens);
vs = CALLOC_STRUCT( draw_llvm_vertex_shader );
if (vs == NULL)
return NULL;
vs->base.state = templ;
/* we make a private copy of the tokens */
vs->base.state.tokens = mem_dup(templ->tokens, nt * sizeof(templ->tokens[0]));
vs->base.prepare = vs_llvm_prepare;
vs->base.run = vs_llvm_run;
vs->base.delete = vs_llvm_delete;

View file

@ -43,6 +43,7 @@
#include "rtasm/rtasm_x86sse.h"
#include "tgsi/exec/tgsi_sse2.h"
#include "tgsi/util/tgsi_parse.h"
typedef void (XSTDCALL *codegen_function) (
@ -204,6 +205,7 @@ vs_sse_delete( struct draw_vertex_shader *base )
x86_release_func( &shader->sse2_program );
FREE( (void*) shader->base.state.tokens );
FREE( shader );
}
@ -213,6 +215,7 @@ draw_create_vs_sse(struct draw_context *draw,
const struct pipe_shader_state *templ)
{
struct draw_sse_vertex_shader *vs;
uint nt = tgsi_num_tokens(templ->tokens);
if (!draw->use_sse)
return NULL;
@ -221,7 +224,8 @@ draw_create_vs_sse(struct draw_context *draw,
if (vs == NULL)
return NULL;
vs->base.state = *templ;
/* we make a private copy of the tokens */
vs->base.state.tokens = mem_dup(templ->tokens, nt * sizeof(templ->tokens[0]));
vs->base.prepare = vs_sse_prepare;
vs->base.run = vs_sse_run;
vs->base.delete = vs_sse_delete;