mojoshader.c
changeset 1223 32ab7e4fbdc6
parent 1206 8073819b258d
child 1224 21cd84f1aa0a
equal deleted inserted replaced
1222:c6e847dd9d4b 1223:32ab7e4fbdc6
   519                 var->constant = array[start];
   519                 var->constant = array[start];
   520                 var->used = 0;
   520                 var->used = 0;
   521                 var->emit_position = -1;
   521                 var->emit_position = -1;
   522                 var->next = ctx->variables;
   522                 var->next = ctx->variables;
   523                 ctx->variables = var;
   523                 ctx->variables = var;
   524             } // else
   524             } // if
   525 
   525 
   526             start = i;   // set this as new start of sequence.
   526             start = i;   // set this as new start of sequence.
   527         } // if
   527         } // if
   528 
   528 
   529         prev = i;
   529         prev = i;
  1265     // !!! FIXME:  (but only s0 through s3, not all 16 of them.)
  1265     // !!! FIXME:  (but only s0 through s3, not all 16 of them.)
  1266 
  1266 
  1267     if (ctx->instruction_count != 0)
  1267     if (ctx->instruction_count != 0)
  1268         fail(ctx, "DCL token must come before any instructions");
  1268         fail(ctx, "DCL token must come before any instructions");
  1269 
  1269 
  1270     else if (shader_is_vertex(ctx))
  1270     else if (shader_is_vertex(ctx) || shader_is_pixel(ctx))
  1271     {
  1271     {
  1272         if (regtype == REG_TYPE_SAMPLER)
  1272         if (regtype == REG_TYPE_SAMPLER)
  1273             add_sampler(ctx, regnum, (TextureType) ctx->dwords[0], 0);
  1273             add_sampler(ctx, regnum, (TextureType) ctx->dwords[0], 0);
  1274         else
  1274         else
  1275         {
  1275         {
  1281                 return;
  1281                 return;
  1282             } // if
  1282             } // if
  1283             add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
  1283             add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
  1284         } // else
  1284         } // else
  1285     } // if
  1285     } // if
  1286 
       
  1287     else if (shader_is_pixel(ctx))
       
  1288     {
       
  1289         if (regtype == REG_TYPE_SAMPLER)
       
  1290             add_sampler(ctx, regnum, (TextureType) ctx->dwords[0], 0);
       
  1291         else
       
  1292         {
       
  1293             const MOJOSHADER_usage usage = (MOJOSHADER_usage) ctx->dwords[0];
       
  1294             const int index = ctx->dwords[1];
       
  1295             add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
       
  1296         } // else
       
  1297     } // else if
       
  1298 
  1286 
  1299     else
  1287     else
  1300     {
  1288     {
  1301         fail(ctx, "unsupported shader type."); // should be caught elsewhere.
  1289         fail(ctx, "unsupported shader type."); // should be caught elsewhere.
  1302         return;
  1290         return;
  3555         prev = item;
  3543         prev = item;
  3556         item = next;
  3544         item = next;
  3557     } // while
  3545     } // while
  3558 
  3546 
  3559     // okay, now deal with uniform/constant arrays...
  3547     // okay, now deal with uniform/constant arrays...
  3560     VariableList *var;
  3548     for (VariableList *var = ctx->variables; var != NULL; var = var->next)
  3561     for (var = ctx->variables; var != NULL; var = var->next)
       
  3562     {
  3549     {
  3563         if (var->used)
  3550         if (var->used)
  3564         {
  3551         {
  3565             if (var->constant)
  3552             if (var->constant)
  3566             {
  3553             {
  3578 
  3565 
  3579     // ...and uniforms...
  3566     // ...and uniforms...
  3580     for (item = ctx->uniforms.next; item != NULL; item = item->next)
  3567     for (item = ctx->uniforms.next; item != NULL; item = item->next)
  3581     {
  3568     {
  3582         int arraysize = -1;
  3569         int arraysize = -1;
       
  3570         VariableList *var = NULL;
  3583 
  3571 
  3584         // check if this is a register contained in an array...
  3572         // check if this is a register contained in an array...
  3585         if (item->regtype == REG_TYPE_CONST)
  3573         if (item->regtype == REG_TYPE_CONST)
  3586         {
  3574         {
  3587             for (var = ctx->variables; var != NULL; var = var->next)
  3575             for (var = ctx->variables; var != NULL; var = var->next)
  3692         return retval;
  3680         return retval;
  3693     } // if
  3681     } // if
  3694 
  3682 
  3695     verify_swizzles(ctx);
  3683     verify_swizzles(ctx);
  3696 
  3684 
       
  3685     if (!ctx->mainfn)
       
  3686         ctx->mainfn = StrDup(ctx, "main");
       
  3687 
  3697     // Version token always comes first.
  3688     // Version token always comes first.
  3698     ctx->current_position = 0;
  3689     ctx->current_position = 0;
  3699     rc = parse_version_token(ctx, profile);
  3690     rc = parse_version_token(ctx, profile);
  3700 
       
  3701     if (!ctx->mainfn)
       
  3702         ctx->mainfn = StrDup(ctx, "main");
       
  3703 
  3691 
  3704     // drop out now if this definitely isn't bytecode. Saves lots of
  3692     // drop out now if this definitely isn't bytecode. Saves lots of
  3705     //  meaningless errors flooding through.
  3693     //  meaningless errors flooding through.
  3706     if (rc < 0)
  3694     if (rc < 0)
  3707     {
  3695     {