gallium: simplify tgsi_full_immediate struct
authorKeith Whitwell <keithw@vmware.com>
Tue, 21 Jul 2009 23:39:00 +0000 (00:39 +0100)
committerKeith Whitwell <keithw@vmware.com>
Wed, 22 Jul 2009 11:42:09 +0000 (12:42 +0100)
Remove the need to have a pointer in this struct by just including
the immediate data inline.  Having a pointer in the struct introduces
complications like needing to alloc/free the data pointed to, uncertainty
about who owns the data, etc.  There doesn't seem to be a need for it,
and it is unlikely to make much difference plus or minus to performance.

Added some asserts as we now will trip up on immediates with more
than four elements.  There were actually already quite a few such asserts,
but the >4 case could be used in the future to specify indexable immediate
ranges, such as lookup tables.

26 files changed:
src/gallium/auxiliary/draw/draw_pipe_pstipple.c
src/gallium/auxiliary/draw/draw_vs_aos.c
src/gallium/auxiliary/gallivm/tgsitollvm.cpp
src/gallium/auxiliary/tgsi/tgsi_build.c
src/gallium/auxiliary/tgsi/tgsi_build.h
src/gallium/auxiliary/tgsi/tgsi_dump.c
src/gallium/auxiliary/tgsi/tgsi_dump_c.c
src/gallium/auxiliary/tgsi/tgsi_exec.c
src/gallium/auxiliary/tgsi/tgsi_parse.c
src/gallium/auxiliary/tgsi/tgsi_parse.h
src/gallium/auxiliary/tgsi/tgsi_ppc.c
src/gallium/auxiliary/tgsi/tgsi_sse2.c
src/gallium/auxiliary/tgsi/tgsi_text.c
src/gallium/drivers/cell/ppu/cell_gen_fp.c
src/gallium/drivers/i915simple/i915_fpc_translate.c
src/gallium/drivers/i965simple/brw_vs_emit.c
src/gallium/drivers/nv20/nv20_vertprog.c
src/gallium/drivers/nv30/nv30_fragprog.c
src/gallium/drivers/nv30/nv30_vertprog.c
src/gallium/drivers/nv40/nv40_fragprog.c
src/gallium/drivers/nv40/nv40_vertprog.c
src/gallium/drivers/nv50/nv50_program.c
src/gallium/drivers/r300/r300_fs.c
src/gallium/drivers/r300/r300_vs.c
src/gallium/include/pipe/p_shader_tokens.h
src/mesa/state_tracker/st_mesa_to_tgsi.c

index 30a6d2919d96441c2d16e3ff851c886f8db20564..283502cdf3e3bd31afd3114df5b0a854fe6b13ec 100644 (file)
@@ -256,7 +256,10 @@ pstip_transform_inst(struct tgsi_transform_context *ctx,
          uint size = 4;
          immed = tgsi_default_full_immediate();
          immed.Immediate.NrTokens = 1 + size; /* one for the token itself */
-         immed.u.Pointer = (void *) value;
+         immed.u[0].Float = value[0];
+         immed.u[1].Float = value[1];
+         immed.u[2].Float = value[2];
+         immed.u[3].Float = value[3];
          ctx->emit_immediate(ctx, &immed);
       }
 
index 9e37a26c1e2577f1c0c690657be1ca3910a75b8a..68402bed5f33f027041502f9641f70a133c4792b 100644 (file)
@@ -1891,8 +1891,9 @@ static boolean note_immediate( struct aos_compilation *cp,
    unsigned pos = cp->num_immediates++;
    unsigned j;
 
+   assert( imm->Immediate.NrTokens <= 4 + 1 );
    for (j = 0; j < imm->Immediate.NrTokens - 1; j++) {
-      cp->vaos->machine->immediate[pos][j] = imm->u.ImmediateFloat32[j].Float;
+      cp->vaos->machine->immediate[pos][j] = imm->u[j].Float;
    }
 
    return TRUE;
index 5b08200d1424c4185eecdf61c4d13b09a84f535f..9c8f89d5206c7e46ce770efcd2f83fafab359628 100644 (file)
@@ -160,10 +160,11 @@ translate_immediate(Storage *storage,
 {
    float vec[4];
    int i;
+   assert( imm->Immediate.NrTokens <= 4 + 1 );
    for (i = 0; i < imm->Immediate.NrTokens - 1; ++i) {
       switch (imm->Immediate.DataType) {
       case TGSI_IMM_FLOAT32:
-         vec[i] = imm->u.ImmediateFloat32[i].Float;
+         vec[i] = imm->u[i].Float;
          break;
       default:
          assert(0);
@@ -179,10 +180,11 @@ translate_immediateir(StorageSoa *storage,
 {
    float vec[4];
    int i;
+   assert( imm->Immediate.NrTokens <= 4 + 1 );
    for (i = 0; i < imm->Immediate.NrTokens - 1; ++i) {
       switch (imm->Immediate.DataType) {
       case TGSI_IMM_FLOAT32:
-         vec[i] = imm->u.ImmediateFloat32[i].Float;
+         vec[i] = imm->u[i].Float;
          break;
       default:
          assert(0);
index d272533d63c764b365317270cf983363f0aee398..010d501c601a901a7ecffc2a0d8c9c5dae54b1fb 100644 (file)
@@ -335,7 +335,10 @@ tgsi_default_full_immediate( void )
    struct tgsi_full_immediate fullimm;
 
    fullimm.Immediate = tgsi_default_immediate();
-   fullimm.u.Pointer = (void *) 0;
+   fullimm.u[0].Float = 0.0f;
+   fullimm.u[1].Float = 0.0f;
+   fullimm.u[2].Float = 0.0f;
+   fullimm.u[3].Float = 0.0f;
 
    return fullimm;
 }
@@ -352,19 +355,19 @@ immediate_grow(
    header_bodysize_grow( header );
 }
 
-struct tgsi_immediate_float32
+union tgsi_immediate_data
 tgsi_build_immediate_float32(
    float value,
    struct tgsi_immediate *immediate,
    struct tgsi_header *header )
 {
-   struct tgsi_immediate_float32 immediate_float32;
+   union tgsi_immediate_data immediate_data;
 
-   immediate_float32.Float = value;
+   immediate_data.Float = value;
 
    immediate_grow( immediate, header );
 
-   return immediate_float32;
+   return immediate_data;
 }
 
 unsigned
@@ -384,16 +387,18 @@ tgsi_build_full_immediate(
 
    *immediate = tgsi_build_immediate( header );
 
+   assert( full_imm->Immediate.NrTokens <= 4 + 1 );
+
    for( i = 0; i < full_imm->Immediate.NrTokens - 1; i++ ) {
-      struct tgsi_immediate_float32 *if32;
+      union tgsi_immediate_data *data;
 
       if( maxsize <= size )
          return  0;
-      if32 = (struct tgsi_immediate_float32 *) &tokens[size];
+      data = (union tgsi_immediate_data *) &tokens[size];
       size++;
 
-      *if32 = tgsi_build_immediate_float32(
-         full_imm->u.ImmediateFloat32[i].Float,
+      *data = tgsi_build_immediate_float32(
+         full_imm->u[i].Float,
          immediate,
          header );
    }
index 9a3a077cf2b2e746ed4d7bc33546796c858859e3..17d977b05971dd3ae80e8110051aa6c7094bb53f 100644 (file)
@@ -119,7 +119,7 @@ tgsi_build_immediate(
 struct tgsi_full_immediate
 tgsi_default_full_immediate( void );
 
-struct tgsi_immediate_float32
+union tgsi_immediate_data
 tgsi_build_immediate_float32(
    float value,
    struct tgsi_immediate *immediate,
index a6994ecd48b5c5d212fa157a60f3d7d8e2d80098..e1cd8479cb4b12850d507a0f3e71f6b4d2be9295 100644 (file)
@@ -295,10 +295,12 @@ iter_immediate(
    ENM( imm->Immediate.DataType, immediate_type_names );
 
    TXT( " { " );
+
+   assert( imm->Immediate.NrTokens <= 4 + 1 );
    for (i = 0; i < imm->Immediate.NrTokens - 1; i++) {
       switch (imm->Immediate.DataType) {
       case TGSI_IMM_FLOAT32:
-         FLT( imm->u.ImmediateFloat32[i].Float );
+         FLT( imm->u[i].Float );
          break;
       default:
          assert( 0 );
index 3dc61c48ca371428730738608e0e97e729527a63..c944760ca67fd540e0c48d6f46d1bc8e7f17d3b3 100644 (file)
@@ -283,12 +283,13 @@ dump_immediate_verbose(
       UIX( imm->Immediate.Padding );
    }
 
+   assert( imm->Immediate.NrTokens <= 4 + 1 );
    for( i = 0; i < imm->Immediate.NrTokens - 1; i++ ) {
       EOL();
       switch( imm->Immediate.DataType ) {
       case TGSI_IMM_FLOAT32:
          TXT( "\nFloat: " );
-         FLT( imm->u.ImmediateFloat32[i].Float );
+         FLT( imm->u[i].Float );
          break;
 
       default:
index fe571a86bcad95c2bf7fea9f5b5c3764c9243046..8c68a10a38ef923a41c3340edd9b751f1cb85b60 100644 (file)
@@ -301,14 +301,14 @@ tgsi_exec_machine_bind_shader(
       case TGSI_TOKEN_TYPE_IMMEDIATE:
          {
             uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1;
-            assert( size % 4 == 0 );
-            assert( mach->ImmLimit + size / 4 <= TGSI_EXEC_NUM_IMMEDIATES );
+            assert( size <= 4 );
+            assert( mach->ImmLimit + 1 <= TGSI_EXEC_NUM_IMMEDIATES );
 
             for( i = 0; i < size; i++ ) {
-               mach->Imms[mach->ImmLimit + i / 4][i % 4] = 
-                 parse.FullToken.FullImmediate.u.ImmediateFloat32[i].Float;
+               mach->Imms[mach->ImmLimit][i] = 
+                 parse.FullToken.FullImmediate.u[i].Float;
             }
-            mach->ImmLimit += size / 4;
+            mach->ImmLimit += 1;
          }
          break;
 
index 7f2cfb7988fdd69e37512cea6732662d05b4c506..4870f82b6bd111d23bcd7bdecff7d5f33d70f587 100644 (file)
@@ -42,9 +42,6 @@ void
 tgsi_full_token_free(
    union tgsi_full_token *full_token )
 {
-   if( full_token->Token.Type == TGSI_TOKEN_TYPE_IMMEDIATE ) {
-      FREE( (void *) full_token->FullImmediate.u.Pointer );
-   }
 }
 
 unsigned
@@ -156,14 +153,8 @@ tgsi_parse_token(
       case TGSI_IMM_FLOAT32:
          {
             uint imm_count = imm->Immediate.NrTokens - 1;
-            struct tgsi_immediate_float32 *data;
-
-            data = (struct tgsi_immediate_float32 *) MALLOC(sizeof(struct tgsi_immediate_float32) * imm_count);
-            if (data) {
-               for (i = 0; i < imm_count; i++) {
-                  next_token(ctx, &data[i]);
-               }
-               imm->u.ImmediateFloat32 = data;
+            for (i = 0; i < imm_count; i++) {
+               next_token(ctx, &imm->u[i]);
             }
          }
          break;
index a289e26e3aca6b6e08b31472e9e3971931b5967a..1035bda1a87391b9ce674dee326cefe5929cf616 100644 (file)
@@ -73,11 +73,7 @@ struct tgsi_full_declaration
 struct tgsi_full_immediate
 {
    struct tgsi_immediate   Immediate;
-   union
-   {
-      const void                          *Pointer;
-      const struct tgsi_immediate_float32 *ImmediateFloat32;
-   } u;
+   union tgsi_immediate_data u[4];
 };
 
 #define TGSI_FULL_MAX_DST_REGISTERS 2
index 0c64ae5713100db80969b05529326239710f1542..fddf54460a2633769f88e0287d74d075ba8ed38c 100644 (file)
@@ -1333,7 +1333,7 @@ tgsi_emit_ppc(const struct tgsi_token *tokens,
             assert(num_immediates < TGSI_EXEC_NUM_IMMEDIATES);
             for (i = 0; i < size; i++) {
                immediates[num_immediates][i] =
-                 parse.FullToken.FullImmediate.u.ImmediateFloat32[i].Float;
+                 parse.FullToken.FullImmediate.u[i].Float;
             }
             num_immediates++;
          }
index 4c3343d26c31ab92fe67f8eb9d8f124caac08f97..c3470176f93bd45f0023f5e0cbd323b1d003e580 100644 (file)
@@ -2953,7 +2953,7 @@ tgsi_emit_sse2(
             assert(num_immediates < TGSI_EXEC_NUM_IMMEDIATES);
             for( i = 0; i < size; i++ ) {
                immediates[num_immediates][i] =
-                 parse.FullToken.FullImmediate.u.ImmediateFloat32[i].Float;
+                 parse.FullToken.FullImmediate.u[i].Float;
             }
 #if 0
             debug_printf("SSE FS immediate[%d] = %f %f %f %f\n",
index a76bbc914001f5c67df4c232de6afc4c32780a42..3024da6a328b9331d8c2bf0264aee67d9e8c8709 100644 (file)
@@ -1091,7 +1091,10 @@ static boolean parse_immediate( struct translate_ctx *ctx )
    imm = tgsi_default_full_immediate();
    imm.Immediate.NrTokens += 4;
    imm.Immediate.DataType = TGSI_IMM_FLOAT32;
-   imm.u.Pointer = values;
+   imm.u[0].Float = values[0];
+   imm.u[1].Float = values[1];
+   imm.u[2].Float = values[2];
+   imm.u[3].Float = values[3];
 
    advance = tgsi_build_full_immediate(
       &imm,
index 5a889a6119daaf41036e64bc2374dc2a1c6a9a1b..7cd5656a7e6ac2097abd1fd73fd8900dd8be1e00 100644 (file)
@@ -1875,9 +1875,9 @@ emit_immediate(struct codegen *gen, const struct tgsi_full_immediate *immed)
    assert(gen->num_imm < MAX_TEMPS);
 
    for (ch = 0; ch < 4; ch++) {
-      float val = immed->u.ImmediateFloat32[ch].Float;
+      float val = immed->u[ch].Float;
 
-      if (ch > 0 && val == immed->u.ImmediateFloat32[ch - 1].Float) {
+      if (ch > 0 && val == immed->u[ch - 1].Float) {
          /* re-use previous register */
          gen->imm_regs[gen->num_imm][ch] = gen->imm_regs[gen->num_imm][ch - 1];
       }
index 961c1bf213478c3e61d3ab4c4d79eececbb805a6..89504ced2767e2cdec13f5e68259a4b8457244e8 100644 (file)
@@ -975,8 +975,9 @@ i915_translate_instructions(struct i915_fp_compile *p,
                = &parse.FullToken.FullImmediate;
             const uint pos = p->num_immediates++;
             uint j;
+            assert( imm->Immediate.NrTokens <= 4 + 1 );
             for (j = 0; j < imm->Immediate.NrTokens - 1; j++) {
-               p->immediates[pos][j] = imm->u.ImmediateFloat32[j].Float;
+               p->immediates[pos][j] = imm->u[j].Float;
             }
          }
          break;
index e03d65348216c7839bc1075a14519f367204d4aa..3ee82d95b3a4875766bf39a9a23c2fc014202443 100644 (file)
@@ -1294,10 +1294,10 @@ void brw_vs_emit(struct brw_vs_compile *c)
       case TGSI_TOKEN_TYPE_IMMEDIATE: {
          struct tgsi_full_immediate *imm = &parse.FullToken.FullImmediate;
          assert(imm->Immediate.NrTokens == 4 + 1);
-         c->prog_data.imm_buf[c->prog_data.num_imm][0] = imm->u.ImmediateFloat32[0].Float;
-         c->prog_data.imm_buf[c->prog_data.num_imm][1] = imm->u.ImmediateFloat32[1].Float;
-         c->prog_data.imm_buf[c->prog_data.num_imm][2] = imm->u.ImmediateFloat32[2].Float;
-         c->prog_data.imm_buf[c->prog_data.num_imm][3] = imm->u.ImmediateFloat32[3].Float;
+         c->prog_data.imm_buf[c->prog_data.num_imm][0] = imm->u[0].Float;
+         c->prog_data.imm_buf[c->prog_data.num_imm][1] = imm->u[1].Float;
+         c->prog_data.imm_buf[c->prog_data.num_imm][2] = imm->u[2].Float;
+         c->prog_data.imm_buf[c->prog_data.num_imm][3] = imm->u[3].Float;
          c->prog_data.num_imm++;
       }
          break;
index c1e588902b23ef116a690ef00646bcb128c034e6..388245ecb042a430ed800588a497ec88423726e1 100644 (file)
@@ -617,10 +617,10 @@ nv20_vertprog_translate(struct nv20_context *nv20,
                        assert(imm->Immediate.NrTokens == 4 + 1);
                        vpc->imm[vpc->nr_imm++] =
                                constant(vpc, -1,
-                                        imm->u.ImmediateFloat32[0].Float,
-                                        imm->u.ImmediateFloat32[1].Float,
-                                        imm->u.ImmediateFloat32[2].Float,
-                                        imm->u.ImmediateFloat32[3].Float);
+                                        imm->u[0].Float,
+                                        imm->u[1].Float,
+                                        imm->u[2].Float,
+                                        imm->u[3].Float);
                }
                        break;
                case TGSI_TOKEN_TYPE_INSTRUCTION:
index 1d1c556fb11b8417479813696bec0a6ed4008aff..a48ba9782b329e47e32431f5fb48379ed36ef1c3 100644 (file)
@@ -704,10 +704,10 @@ nv30_fragprog_prepare(struct nv30_fpc *fpc)
                        assert(imm->Immediate.DataType == TGSI_IMM_FLOAT32);
                        assert(fpc->nr_imm < MAX_IMM);
 
-                       vals[0] = imm->u.ImmediateFloat32[0].Float;
-                       vals[1] = imm->u.ImmediateFloat32[1].Float;
-                       vals[2] = imm->u.ImmediateFloat32[2].Float;
-                       vals[3] = imm->u.ImmediateFloat32[3].Float;
+                       vals[0] = imm->u[0].Float;
+                       vals[1] = imm->u[1].Float;
+                       vals[2] = imm->u[2].Float;
+                       vals[3] = imm->u[3].Float;
                        fpc->imm[fpc->nr_imm++] = constant(fpc, -1, vals);
                }
                        break;
index c7514efcfeaf6d753e6bc6c6b0c42dc09ef9f487..14a5c0260d073a6c139a0ac537bbcdcc2f4beeb7 100644 (file)
@@ -617,10 +617,10 @@ nv30_vertprog_translate(struct nv30_context *nv30,
                        assert(imm->Immediate.NrTokens == 4 + 1);
                        vpc->imm[vpc->nr_imm++] =
                                constant(vpc, -1,
-                                        imm->u.ImmediateFloat32[0].Float,
-                                        imm->u.ImmediateFloat32[1].Float,
-                                        imm->u.ImmediateFloat32[2].Float,
-                                        imm->u.ImmediateFloat32[3].Float);
+                                        imm->u[0].Float,
+                                        imm->u[1].Float,
+                                        imm->u[2].Float,
+                                        imm->u[3].Float);
                }
                        break;
                case TGSI_TOKEN_TYPE_INSTRUCTION:
index 680976da56b5a3a48216fbcdbc996219d44cc0d9..32d9ed1a7f810657e3d23f3b53b7d72c2250ac7e 100644 (file)
@@ -790,10 +790,10 @@ nv40_fragprog_prepare(struct nv40_fpc *fpc)
                        assert(imm->Immediate.DataType == TGSI_IMM_FLOAT32);
                        assert(fpc->nr_imm < MAX_IMM);
 
-                       vals[0] = imm->u.ImmediateFloat32[0].Float;
-                       vals[1] = imm->u.ImmediateFloat32[1].Float;
-                       vals[2] = imm->u.ImmediateFloat32[2].Float;
-                       vals[3] = imm->u.ImmediateFloat32[3].Float;
+                       vals[0] = imm->u[0].Float;
+                       vals[1] = imm->u[1].Float;
+                       vals[2] = imm->u[2].Float;
+                       vals[3] = imm->u[3].Float;
                        fpc->imm[fpc->nr_imm++] = constant(fpc, -1, vals);
                }
                        break;
index e75e8d3f4243a2fe0ba619a1056ae1a4e8665f70..0382dbba8f6b1d9e36f760c3565511b962db8dee 100644 (file)
@@ -788,10 +788,10 @@ nv40_vertprog_translate(struct nv40_context *nv40,
                        assert(imm->Immediate.NrTokens == 4 + 1);
                        vpc->imm[vpc->nr_imm++] =
                                constant(vpc, -1,
-                                        imm->u.ImmediateFloat32[0].Float,
-                                        imm->u.ImmediateFloat32[1].Float,
-                                        imm->u.ImmediateFloat32[2].Float,
-                                        imm->u.ImmediateFloat32[3].Float);
+                                        imm->u[0].Float,
+                                        imm->u[1].Float,
+                                        imm->u[2].Float,
+                                        imm->u[3].Float);
                }
                        break;
                case TGSI_TOKEN_TYPE_INSTRUCTION:
index 5f7d06dbecbf6479aa522444da28c2281f74d8fc..4ec9c03305fb8f765f7756b6d141f614043e3ba9 100644 (file)
@@ -1809,10 +1809,10 @@ nv50_program_tx_prep(struct nv50_pc *pc)
                        const struct tgsi_full_immediate *imm =
                                &p.FullToken.FullImmediate;
 
-                       ctor_immd(pc, imm->u.ImmediateFloat32[0].Float,
-                                     imm->u.ImmediateFloat32[1].Float,
-                                     imm->u.ImmediateFloat32[2].Float,
-                                     imm->u.ImmediateFloat32[3].Float);
+                       ctor_immd(pc, imm->u[0].Float,
+                                     imm->u[1].Float,
+                                     imm->u[2].Float,
+                                     imm->u[3].Float);
                }
                        break;
                case TGSI_TOKEN_TYPE_DECLARATION:
index 4b304306d0f9027db1a0d076c36789c338653b68..8672e211bc4e6dd8e08fd0f9bba03ca590be8683 100644 (file)
@@ -67,8 +67,7 @@ void r300_translate_fragment_shader(struct r300_context* r300,
                 for (i = 0; i < 4; i++) {
                     consts->constants[assembler->imm_offset +
                         assembler->imm_count][i] =
-                        parser.FullToken.FullImmediate.u.ImmediateFloat32[i]
-                        .Float;
+                        parser.FullToken.FullImmediate.u[i].Float;
                 }
                 assembler->imm_count++;
                 break;
index f87435f9f07f843055c186985218ff0395137948..a664a316e8c6e75d4a7926fea86e2a583bf14d8b 100644 (file)
@@ -378,8 +378,7 @@ void r300_translate_vertex_shader(struct r300_context* r300,
                 for (i = 0; i < 4; i++) {
                     consts->constants[assembler->imm_offset +
                         assembler->imm_count][i] =
-                        parser.FullToken.FullImmediate.u.ImmediateFloat32[i]
-                        .Float;
+                        parser.FullToken.FullImmediate.u[i].Float;
                 }
                 assembler->imm_count++;
                 break;
index b00cfe3423c733e250820b780d50417a113a7d35..b87aae6197301be6f0a175d8d99b8102a7634d46 100644 (file)
@@ -152,7 +152,7 @@ struct tgsi_immediate
    unsigned Extended   : 1;  /**< BOOL */
 };
 
-struct tgsi_immediate_float32
+union tgsi_immediate_data
 {
    float Float;
 };
index e150dff9bbcfb16087a1280cfec17b1267da6649..6380cd6b2a8e8cceb5607f9f01f8b216a18a1296 100644 (file)
@@ -225,11 +225,15 @@ static struct tgsi_full_immediate
 make_immediate(const float *value, uint size)
 {
    struct tgsi_full_immediate imm;
+   unsigned i;
 
    imm = tgsi_default_full_immediate();
    imm.Immediate.NrTokens += size;
    imm.Immediate.DataType = TGSI_IMM_FLOAT32;
-   imm.u.Pointer = value;
+
+   for (i = 0; i < size; i++)
+      imm.u[i].Float = value[i];
+
    return imm;
 }