mojoshader_effects.c
changeset 1063 b10281d6eb45
parent 1053 513af64373ad
child 1074 3fdc7cbd0c37
equal deleted inserted replaced
1062:ea5c89942bd3 1063:b10281d6eb45
    25     {
    25     {
    26         temps = (double *) alloca(sizeof (double) * preshader->temp_count);
    26         temps = (double *) alloca(sizeof (double) * preshader->temp_count);
    27         memset(temps, '\0', sizeof (double) * preshader->temp_count);
    27         memset(temps, '\0', sizeof (double) * preshader->temp_count);
    28     } // if
    28     } // if
    29 
    29 
    30     double dst[4];
    30     double dst[4] = { 0, 0, 0, 0 };
    31     double src[3][4];
    31     double src[3][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
    32     const double *src0 = src[0];
    32     const double *src0 = &src[0][0];
    33     const double *src1 = src[1];
    33     const double *src1 = &src[1][0];
    34     const double *src2 = src[2];
    34     const double *src2 = &src[2][0];
    35 
    35 
    36     MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
    36     MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
    37     int instit;
    37     int instit;
    38 
    38 
    39     for (instit = 0; instit < preshader->instruction_count; instit++, inst++)
    39     for (instit = 0; instit < preshader->instruction_count; instit++, inst++)
    40     {
    40     {
    41         const MOJOSHADER_preshaderOperand *operand = inst->operands;
    41         const MOJOSHADER_preshaderOperand *operand = inst->operands;
    42         const int elems = inst->element_count;
    42         const int elems = inst->element_count;
    43         const int elemsbytes = sizeof (double) * elems;
    43         const int elemsbytes = sizeof (double) * elems;
    44         const int isscalarop = (inst->opcode >= scalarstart);
    44         const int isscalarop = (inst->opcode >= scalarstart);
       
    45 
       
    46         assert(elems >= 0);
       
    47         assert(elems <= 4);
    45 
    48 
    46         // load up our operands...
    49         // load up our operands...
    47         int opiter, elemiter;
    50         int opiter, elemiter;
    48         for (opiter = 0; opiter < inst->operand_count-1; opiter++, operand++)
    51         for (opiter = 0; opiter < inst->operand_count-1; opiter++, operand++)
    49         {
    52         {
    52             switch (operand->type)
    55             switch (operand->type)
    53             {
    56             {
    54                 case MOJOSHADER_PRESHADEROPERAND_LITERAL:
    57                 case MOJOSHADER_PRESHADEROPERAND_LITERAL:
    55                 {
    58                 {
    56                     const double *lit = &preshader->literals[index];
    59                     const double *lit = &preshader->literals[index];
       
    60                     assert((index + elems) <= preshader->literal_count);
    57                     if (!isscalar)
    61                     if (!isscalar)
    58                         memcpy(src[opiter], lit, elemsbytes);
    62                         memcpy(&src[opiter][0], lit, elemsbytes);
    59                     else
    63                     else
    60                     {
    64                     {
    61                         const double val = *lit;
    65                         const double val = *lit;
    62                         for (elemiter = 0; elemiter < elems; elemiter++)
    66                         for (elemiter = 0; elemiter < elems; elemiter++)
    63                             src[opiter][elemiter] = val;
    67                             src[opiter][elemiter] = val;
    86                             src[opiter][cpy] = outregs[index+cpy];
    90                             src[opiter][cpy] = outregs[index+cpy];
    87                     } // else
    91                     } // else
    88                     break;
    92                     break;
    89 
    93 
    90                 case MOJOSHADER_PRESHADEROPERAND_TEMP:
    94                 case MOJOSHADER_PRESHADEROPERAND_TEMP:
    91                     if (isscalar)
    95                     if (temps != NULL)
    92                         src[opiter][0] = temps[index];
    96                     {
    93                     else
    97                         if (isscalar)
    94                         memcpy(src[opiter], temps + index, elemsbytes);
    98                             src[opiter][0] = temps[index];
       
    99                         else
       
   100                             memcpy(src[opiter], temps + index, elemsbytes);
       
   101                     } // if
    95                     break;
   102                     break;
    96 
   103 
    97                 default:
   104                 default:
    98                     assert(0 && "unexpected preshader operand type.");
   105                     assert(0 && "unexpected preshader operand type.");
    99                     break;
   106                     return;
   100             } // switch
   107             } // switch
   101         } // for
   108         } // for
   102 
   109 
   103         // run the actual instruction, store result to dst.
   110         // run the actual instruction, store result to dst.
   104         int i;
   111         int i;
   168                 break;
   175                 break;
   169         } // switch
   176         } // switch
   170 
   177 
   171         // Figure out where dst wants to be stored.
   178         // Figure out where dst wants to be stored.
   172         if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP)
   179         if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP)
       
   180         {
       
   181             assert(preshader->temp_count >=
       
   182                     operand->index + (elemsbytes / sizeof (double)));
   173             memcpy(temps + operand->index, dst, elemsbytes);
   183             memcpy(temps + operand->index, dst, elemsbytes);
       
   184         } // if
   174         else
   185         else
   175         {
   186         {
   176             assert(operand->type == MOJOSHADER_PRESHADEROPERAND_OUTPUT);
   187             assert(operand->type == MOJOSHADER_PRESHADEROPERAND_OUTPUT);
   177             for (i = 0; i < elems; i++)
   188             for (i = 0; i < elems; i++)
   178                 outregs[operand->index + i] = (float) dst[i];
   189                 outregs[operand->index + i] = (float) dst[i];