mojoshader.c
changeset 1161 6085abb2edaa
parent 1160 24ee60c85ec3
child 1162 de0613aa8f07
equal deleted inserted replaced
1160:24ee60c85ec3 1161:6085abb2edaa
 10455         if (info->members == NULL)
 10455         if (info->members == NULL)
 10456             return 1;  // we'll check ctx->out_of_memory later.
 10456             return 1;  // we'll check ctx->out_of_memory later.
 10457         memset(info->members, '\0', len);
 10457         memset(info->members, '\0', len);
 10458     } // else
 10458     } // else
 10459 
 10459 
 10460     int i;
 10460     unsigned int i;
 10461     const uint32 *member = (const uint32 *) (start + typeptr[6]);
 10461     const uint32 *member = (const uint32 *) (start + typeptr[6]);
 10462     for (i = 0; i < info->member_count; i++)
 10462     for (i = 0; i < info->member_count; i++)
 10463     {
 10463     {
 10464         MOJOSHADER_symbolStructMember *mbr = &info->members[i];
 10464         MOJOSHADER_symbolStructMember *mbr = &info->members[i];
 10465         const uint32 name = SWAP32(member[0]);
 10465         const uint32 name = SWAP32(member[0]);
 11169 
 11169 
 11170 
 11170 
 11171 static void free_sym_typeinfo(MOJOSHADER_free f, void *d,
 11171 static void free_sym_typeinfo(MOJOSHADER_free f, void *d,
 11172                               MOJOSHADER_symbolTypeInfo *typeinfo)
 11172                               MOJOSHADER_symbolTypeInfo *typeinfo)
 11173 {
 11173 {
 11174     int i;
 11174     unsigned int i;
 11175     for (i = 0; i < typeinfo->member_count; i++)
 11175     for (i = 0; i < typeinfo->member_count; i++)
 11176     {
 11176     {
 11177         f((void *) typeinfo->members[i].name, d);
 11177         f((void *) typeinfo->members[i].name, d);
 11178         free_sym_typeinfo(f, d, &typeinfo->members[i].info);
 11178         free_sym_typeinfo(f, d, &typeinfo->members[i].info);
 11179     } // for
 11179     } // for
 12050                                                       void *d)
 12050                                                       void *d)
 12051 {
 12051 {
 12052     // !!! FIXME: This is copypasta ripped from parse_preshader -flibit
 12052     // !!! FIXME: This is copypasta ripped from parse_preshader -flibit
 12053     int i;
 12053     int i;
 12054 
 12054 
 12055     const uint32 *tokens = (const uint32 *) buf;
       
 12056     uint32 tokcount = _len / 4;
       
 12057 
       
 12058     // !!! FIXME: This is stupid. -flibit
       
 12059     Context fillerContext;
       
 12060     fillerContext.malloc = m;
       
 12061     fillerContext.free = f;
       
 12062     fillerContext.malloc_data = d;
       
 12063     fillerContext.out_of_memory = 0;
       
 12064 
       
 12065     MOJOSHADER_preshader *preshader = NULL;
       
 12066 
       
 12067     const uint32 version_magic = 0x46580000;
       
 12068     const uint32 min_version = 0x00000200 | version_magic;
       
 12069     const uint32 max_version = 0x00000201 | version_magic;
       
 12070     const uint32 version = SWAP32(tokens[0]);
       
 12071     if (version < min_version || version > max_version)
       
 12072     {
       
 12073         // fail because the shader will malfunction w/o this.
       
 12074         goto parsePreshader_notAPreshader;
       
 12075     } // if
       
 12076 
       
 12077     tokens++;
       
 12078     tokcount++;
       
 12079 
       
 12080     // All sections of a preshader are packed into separate comment tokens,
 12055     // All sections of a preshader are packed into separate comment tokens,
 12081     //  inside the containing comment token block. Find them all before
 12056     //  inside the containing comment token block. Find them all before
 12082     //  we start, so we don't care about the order they appear in the file.
 12057     //  we start, so we don't care about the order they appear in the file.
 12083     PreshaderBlockInfo ctab = { 0, 0, 0 };
 12058     PreshaderBlockInfo ctab = { 0, 0, 0 };
 12084     PreshaderBlockInfo prsi = { 0, 0, 0 };
 12059     PreshaderBlockInfo prsi = { 0, 0, 0 };
 12085     PreshaderBlockInfo fxlc = { 0, 0, 0 };
 12060     PreshaderBlockInfo fxlc = { 0, 0, 0 };
 12086     PreshaderBlockInfo clit = { 0, 0, 0 };
 12061     PreshaderBlockInfo clit = { 0, 0, 0 };
       
 12062 
       
 12063     const uint32 *tokens = (const uint32 *) buf;
       
 12064     uint32 tokcount = _len / 4;
       
 12065 
       
 12066     // !!! FIXME: This is stupid. -flibit
       
 12067     Context fillerContext;
       
 12068     fillerContext.malloc = m;
       
 12069     fillerContext.free = f;
       
 12070     fillerContext.malloc_data = d;
       
 12071     fillerContext.out_of_memory = 0;
       
 12072 
       
 12073     MOJOSHADER_preshader *preshader = NULL;
       
 12074 
       
 12075     const uint32 version_magic = 0x46580000;
       
 12076     const uint32 min_version = 0x00000200 | version_magic;
       
 12077     const uint32 max_version = 0x00000201 | version_magic;
       
 12078     const uint32 version = SWAP32(tokens[0]);
       
 12079     if (version < min_version || version > max_version)
       
 12080     {
       
 12081         // fail because the shader will malfunction w/o this.
       
 12082         goto parsePreshader_notAPreshader;
       
 12083     } // if
       
 12084 
       
 12085     tokens++;
       
 12086     tokcount++;
 12087 
 12087 
 12088     while (tokcount > 0)
 12088     while (tokcount > 0)
 12089     {
 12089     {
 12090         uint32 subtokcount = 0;
 12090         uint32 subtokcount = 0;
 12091         // !!! FIXME: Passing a NULL ctx! -flibit
 12091         // !!! FIXME: Passing a NULL ctx! -flibit
 12399 
 12399 
 12400 void MOJOSHADER_freePreshader(const MOJOSHADER_preshader *preshader,
 12400 void MOJOSHADER_freePreshader(const MOJOSHADER_preshader *preshader,
 12401                               MOJOSHADER_free f,
 12401                               MOJOSHADER_free f,
 12402                               void *d)
 12402                               void *d)
 12403 {
 12403 {
 12404     int i, j;
 12404     unsigned int i, j;
 12405     if (preshader != NULL)
 12405     if (preshader != NULL)
 12406     {
 12406     {
 12407         f((void *) preshader->literals, d);
 12407         f((void *) preshader->literals, d);
 12408         for (i = 0; i < preshader->instruction_count; i++)
 12408         for (i = 0; i < preshader->instruction_count; i++)
       
 12409         {
 12409             for (j = 0; j < preshader->instructions[i].operand_count; j++)
 12410             for (j = 0; j < preshader->instructions[i].operand_count; j++)
 12410                 f((void *) preshader->instructions[i].operands[j].array_registers, d);
 12411                 f((void *) preshader->instructions[i].operands[j].array_registers, d);
       
 12412         } // for
 12411         f((void *) preshader->instructions, d);
 12413         f((void *) preshader->instructions, d);
 12412         f((void *) preshader->registers, d);
 12414         f((void *) preshader->registers, d);
 12413         free_symbols(f, d, preshader->symbols, preshader->symbol_count);
 12415         free_symbols(f, d, preshader->symbols, preshader->symbol_count);
 12414         f((void *) preshader, d);
 12416         f((void *) preshader, d);
 12415     } // if
 12417     } // if