mojoshader.c
changeset 524 03eea2f0762c
parent 523 699696afd731
child 525 0493d39de79a
equal deleted inserted replaced
523:699696afd731 524:03eea2f0762c
  5735     ctx->constant_count++;
  5735     ctx->constant_count++;
  5736 
  5736 
  5737     return item;
  5737     return item;
  5738 } // alloc_constant_listitem
  5738 } // alloc_constant_listitem
  5739 
  5739 
       
  5740 
  5740 static void state_DEF(Context *ctx)
  5741 static void state_DEF(Context *ctx)
  5741 {
  5742 {
  5742     const RegisterType regtype = ctx->dest_arg.regtype;
  5743     const RegisterType regtype = ctx->dest_arg.regtype;
  5743     const int regnum = ctx->dest_arg.regnum;
  5744     const int regnum = ctx->dest_arg.regnum;
  5744 
  5745 
  6515     const uint32 constants = SWAP32(ctx->tokens[5]);
  6516     const uint32 constants = SWAP32(ctx->tokens[5]);
  6516     const uint32 constantinfo = SWAP32(ctx->tokens[6]);
  6517     const uint32 constantinfo = SWAP32(ctx->tokens[6]);
  6517     const uint32 target = SWAP32(ctx->tokens[8]);
  6518     const uint32 target = SWAP32(ctx->tokens[8]);
  6518     uint32 i = 0;
  6519     uint32 i = 0;
  6519 
  6520 
  6520     if (id != 0x42415443)  // 0x42415443 == 'CTAB'
  6521     if (id != CTAB_ID)
  6521         return;  // not the constant table.
  6522         return;  // not the constant table.
  6522 
  6523 
  6523     if (size != 28)
  6524     if (size != CTAB_SIZE)
  6524         return;  // only handle this version of the struct.
  6525         return;  // only handle this version of the struct.
  6525 
  6526 
  6526     if (version != ctx->version_token) goto corrupt_ctab;
  6527     if (version != ctx->version_token) goto corrupt_ctab;
  6527     if (creator >= bytes) goto corrupt_ctab;
  6528     if (creator >= bytes) goto corrupt_ctab;
  6528     if ((constantinfo + (constants * 20)) >= bytes) goto corrupt_ctab;
  6529     if ((constantinfo + (constants * CINFO_SIZE)) >= bytes) goto corrupt_ctab;
  6529     if (target >= bytes) goto corrupt_ctab;
  6530     if (target >= bytes) goto corrupt_ctab;
  6530 
  6531 
  6531     ctx->have_ctab = 1;
  6532     ctx->have_ctab = 1;
  6532 
  6533 
  6533     for (i = 0; i < constants; i++)
  6534     for (i = 0; i < constants; i++)
  6534     {
  6535     {
  6535         // we only care about deciding which variables might be arrays at
  6536         const uint8 *ptr = start + constantinfo + (i * CINFO_SIZE);
  6536         //  the moment, but there's lots of other good info in the CTAB.
       
  6537         const uint8 *ptr = start + constantinfo + (i * 20);
       
  6538         const uint32 name = SWAP32(*((uint32 *) (ptr + 0)));
  6537         const uint32 name = SWAP32(*((uint32 *) (ptr + 0)));
  6539         const uint16 regset = SWAP16(*((uint16 *) (ptr + 4)));
  6538         const uint16 regset = SWAP16(*((uint16 *) (ptr + 4)));
  6540         const uint16 regidx = SWAP16(*((uint16 *) (ptr + 6)));
  6539         const uint16 regidx = SWAP16(*((uint16 *) (ptr + 6)));
  6541         const uint16 regcnt = SWAP16(*((uint16 *) (ptr + 8)));
  6540         const uint16 regcnt = SWAP16(*((uint16 *) (ptr + 8)));
  6542         const uint32 typeinf = SWAP32(*((uint32 *) (ptr + 12)));
  6541         const uint32 typeinf = SWAP32(*((uint32 *) (ptr + 12)));
  7469                 f((void *) data->samplers[i].name, d);
  7468                 f((void *) data->samplers[i].name, d);
  7470         } // for
  7469         } // for
  7471         f((void *) data->samplers, d);
  7470         f((void *) data->samplers, d);
  7472     } // if
  7471     } // if
  7473 
  7472 
       
  7473     if (data->symbols != NULL)
       
  7474     {
       
  7475         for (i = 0; i < data->symbol_count; i++)
       
  7476         {
       
  7477             if (data->symbols[i].name != NULL)
       
  7478                 f((void *) data->symbols[i].name, d);
       
  7479             if (data->symbols[i].default_value != NULL)
       
  7480                 f((void *) data->symbols[i].default_value, d);
       
  7481         } // for
       
  7482         f((void *) data->symbols, d);
       
  7483     } // if
       
  7484 
  7474     if ((data->error != NULL) && (data->error != out_of_mem_str))
  7485     if ((data->error != NULL) && (data->error != out_of_mem_str))
  7475         f((void *) data->error, d);
  7486         f((void *) data->error, d);
  7476 
  7487 
  7477     f(data, d);
  7488     f(data, d);
  7478 } // MOJOSHADER_freeParseData
  7489 } // MOJOSHADER_freeParseData