diff options
author | Keith Whitwell <keith@tungstengraphics.com> | 2009-07-15 23:44:53 +0100 |
---|---|---|
committer | Keith Whitwell <keithw@vmware.com> | 2009-07-16 09:53:07 +0100 |
commit | 6175653d0bceedba1f599d27111bab14f312f134 (patch) | |
tree | adf7ba396a1621549b4842d047709129dc87646a /src | |
parent | 3a3b83e5112b725e22f05b32a273a2351b820944 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/auxiliary/draw/draw_private.h | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_vs.c | 21 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_vs_exec.c | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_vs_sse.c | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_exec.c | 45 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_exec.h | 22 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_quad_fs.c | 30 |
7 files changed, 71 insertions, 53 deletions
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h index 81e4eae401c..e4fa23cc403 100644 --- a/src/gallium/auxiliary/draw/draw_private.h +++ b/src/gallium/auxiliary/draw/draw_private.h @@ -185,7 +185,7 @@ struct draw_context uint position_output; /** TGSI program interpreter runtime state */ - struct tgsi_exec_machine machine; + struct tgsi_exec_machine *machine; uint num_samplers; struct tgsi_sampler **samplers; diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c index c057cd67fde..1b48a52c666 100644 --- a/src/gallium/auxiliary/draw/draw_vs.c +++ b/src/gallium/auxiliary/draw/draw_vs.c @@ -146,16 +146,8 @@ draw_delete_vertex_shader(struct draw_context *draw, boolean draw_vs_init( struct draw_context *draw ) { - tgsi_exec_machine_init(&draw->vs.machine); - - /* FIXME: give this machine thing a proper constructor: - */ - draw->vs.machine.Inputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16); - if (!draw->vs.machine.Inputs) - return FALSE; - - draw->vs.machine.Outputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16); - if (!draw->vs.machine.Outputs) + draw->vs.machine = tgsi_exec_machine_create(); + if (!draw->vs.machine) return FALSE; draw->vs.emit_cache = translate_cache_create(); @@ -178,12 +170,6 @@ draw_vs_init( struct draw_context *draw ) void draw_vs_destroy( struct draw_context *draw ) { - if (draw->vs.machine.Inputs) - align_free(draw->vs.machine.Inputs); - - if (draw->vs.machine.Outputs) - align_free(draw->vs.machine.Outputs); - if (draw->vs.fetch_cache) translate_cache_destroy(draw->vs.fetch_cache); @@ -196,8 +182,7 @@ draw_vs_destroy( struct draw_context *draw ) if (draw->vs.aligned_constant_storage) align_free((void*)draw->vs.aligned_constant_storage); - tgsi_exec_machine_free_data(&draw->vs.machine); - + tgsi_exec_machine_destroy(draw->vs.machine); } diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c index f2368dde5c2..8c488bf11f0 100644 --- a/src/gallium/auxiliary/draw/draw_vs_exec.c +++ b/src/gallium/auxiliary/draw/draw_vs_exec.c @@ -201,7 +201,7 @@ draw_create_vs_exec(struct draw_context *draw, vs->base.run_linear = vs_exec_run_linear; vs->base.delete = vs_exec_delete; vs->base.create_varient = draw_vs_varient_generic; - vs->machine = &draw->vs.machine; + vs->machine = draw->vs.machine; return &vs->base; } diff --git a/src/gallium/auxiliary/draw/draw_vs_sse.c b/src/gallium/auxiliary/draw/draw_vs_sse.c index 77ba5152f9f..2b3b78487f3 100644 --- a/src/gallium/auxiliary/draw/draw_vs_sse.c +++ b/src/gallium/auxiliary/draw/draw_vs_sse.c @@ -184,7 +184,7 @@ draw_create_vs_sse(struct draw_context *draw, vs->base.immediates = align_malloc(TGSI_EXEC_NUM_IMMEDIATES * 4 * sizeof(float), 16); - vs->machine = &draw->vs.machine; + vs->machine = draw->vs.machine; x86_init_func( &vs->sse2_program ); diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 5cb322a5fa2..d9ebd955c82 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 da22baad3ef..f1866b7658c 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) { diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c b/src/gallium/drivers/softpipe/sp_quad_fs.c index ca637a1d6a4..28f8d1a60ea 100644 --- a/src/gallium/drivers/softpipe/sp_quad_fs.c +++ b/src/gallium/drivers/softpipe/sp_quad_fs.c @@ -52,7 +52,7 @@ struct quad_shade_stage { struct quad_stage stage; /**< base class */ - struct tgsi_exec_machine machine; + struct tgsi_exec_machine *machine; struct tgsi_exec_vector *inputs, *outputs; }; @@ -73,7 +73,7 @@ shade_quad(struct quad_stage *qs, struct quad_header *quad) { struct quad_shade_stage *qss = quad_shade_stage( qs ); struct softpipe_context *softpipe = qs->softpipe; - struct tgsi_exec_machine *machine = &qss->machine; + struct tgsi_exec_machine *machine = qss->machine; boolean z_written; /* Consts do not require 16 byte alignment. */ @@ -146,7 +146,7 @@ shade_begin(struct quad_stage *qs) struct softpipe_context *softpipe = qs->softpipe; softpipe->fs->prepare( softpipe->fs, - &qss->machine, + qss->machine, (struct tgsi_sampler **) softpipe->tgsi.frag_samplers_list ); @@ -159,9 +159,8 @@ shade_destroy(struct quad_stage *qs) { struct quad_shade_stage *qss = (struct quad_shade_stage *) qs; - tgsi_exec_machine_free_data(&qss->machine); - FREE( qss->inputs ); - FREE( qss->outputs ); + tgsi_exec_machine_destroy(qss->machine); + FREE( qs ); } @@ -170,19 +169,24 @@ struct quad_stage * sp_quad_shade_stage( struct softpipe_context *softpipe ) { struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage); - - /* allocate storage for program inputs/outputs, aligned to 16 bytes */ - qss->inputs = MALLOC(PIPE_MAX_ATTRIBS * sizeof(*qss->inputs) + 16); - qss->outputs = MALLOC(PIPE_MAX_ATTRIBS * sizeof(*qss->outputs) + 16); - qss->machine.Inputs = align16(qss->inputs); - qss->machine.Outputs = align16(qss->outputs); + if (!qss) + goto fail; qss->stage.softpipe = softpipe; qss->stage.begin = shade_begin; qss->stage.run = shade_quad; qss->stage.destroy = shade_destroy; - tgsi_exec_machine_init( &qss->machine ); + qss->machine = tgsi_exec_machine_create(); + if (!qss->machine) + goto fail; return &qss->stage; + +fail: + if (qss && qss->machine) + tgsi_exec_machine_destroy(qss->machine); + + FREE(qss); + return NULL; } |