From 6175653d0bceedba1f599d27111bab14f312f134 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 15 Jul 2009 23:44:53 +0100 Subject: gallium: proper constructor and destructor for tgsi_exec_machine Centralize the creation, initialization and destruction of this struct. Use align_malloc instead of home-brew alternatives. --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 45 ++++++++++++++++++++++++++++++---- src/gallium/auxiliary/tgsi/tgsi_exec.h | 22 ++++++----------- 2 files changed, 48 insertions(+), 19 deletions(-) (limited to 'src/gallium/auxiliary/tgsi') diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 5cb322a5fa..d9ebd955c8 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -365,15 +365,38 @@ tgsi_exec_machine_bind_shader( } -void -tgsi_exec_machine_init( - struct tgsi_exec_machine *mach ) +struct tgsi_exec_machine * +tgsi_exec_machine_create( void ) { + struct tgsi_exec_machine *mach; uint i; - mach->Temps = (struct tgsi_exec_vector *) tgsi_align_128bit( mach->_Temps); + mach = align_malloc( sizeof *mach, 16 ); + if (!mach) + goto fail; + mach->Addrs = &mach->Temps[TGSI_EXEC_TEMP_ADDR]; + mach->Samplers = NULL; + mach->Consts = NULL; + mach->Inputs = NULL; + mach->Outputs = NULL; + mach->Tokens = NULL; + mach->Primitives = NULL; + mach->InterpCoefs = NULL; + mach->Instructions = NULL; + mach->Declarations = NULL; + + mach->Inputs = align_malloc(PIPE_MAX_ATTRIBS * + sizeof(struct tgsi_exec_vector), 16); + if (!mach->Inputs) + goto fail; + + mach->Outputs = align_malloc(PIPE_MAX_ATTRIBS * + sizeof(struct tgsi_exec_vector), 16); + if (!mach->Outputs) + goto fail; + /* Setup constants. */ for( i = 0; i < 4; i++ ) { mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].u[i] = 0x00000000; @@ -393,11 +416,22 @@ tgsi_exec_machine_init( (void) print_chan; (void) print_temp; #endif + + return mach; + +fail: + if (mach) { + align_free(mach->Inputs); + align_free(mach->Outputs); + align_free(mach); + } + + return NULL; } void -tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach) +tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach) { if (mach->Instructions) { FREE(mach->Instructions); @@ -409,6 +443,7 @@ tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach) mach->Declarations = NULL; mach->NumDeclarations = 0; } + align_free(mach); } diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h b/src/gallium/auxiliary/tgsi/tgsi_exec.h index da22baad3e..f1866b7658 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.h +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h @@ -187,20 +187,16 @@ struct tgsi_exec_labels struct tgsi_exec_machine { /* Total = program temporaries + internal temporaries - * + 1 padding to align to 16 bytes */ - struct tgsi_exec_vector _Temps[TGSI_EXEC_NUM_TEMPS + - TGSI_EXEC_NUM_TEMP_EXTRAS + 1]; + struct tgsi_exec_vector Temps[TGSI_EXEC_NUM_TEMPS + + TGSI_EXEC_NUM_TEMP_EXTRAS]; + + float Imms[TGSI_EXEC_NUM_IMMEDIATES][4]; - /* - * This will point to _Temps after aligning to 16B boundary. - */ - struct tgsi_exec_vector *Temps; struct tgsi_exec_vector *Addrs; struct tgsi_sampler **Samplers; - float Imms[TGSI_EXEC_NUM_IMMEDIATES][4]; unsigned ImmLimit; const float (*Consts)[4]; struct tgsi_exec_vector *Inputs; @@ -251,9 +247,11 @@ struct tgsi_exec_machine struct tgsi_exec_labels Labels; }; +struct tgsi_exec_machine * +tgsi_exec_machine_create( void ); + void -tgsi_exec_machine_init( - struct tgsi_exec_machine *mach ); +tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach); void @@ -268,10 +266,6 @@ tgsi_exec_machine_run( struct tgsi_exec_machine *mach ); -void -tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach); - - static INLINE void tgsi_set_kill_mask(struct tgsi_exec_machine *mach, unsigned mask) { -- cgit v1.2.3