~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/arbprogparse.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Mesa 3-D graphics library
3
 
 * Version:  6.5
 
3
 * Version:  6.5.1
4
4
 *
5
5
 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6
6
 *
36
36
#include "grammar_mesa.h"
37
37
#include "program.h"
38
38
#include "context.h"
 
39
#include "macros.h"
39
40
#include "mtypes.h"
40
41
#include "program_instruction.h"
41
42
 
42
43
 
43
 
#define MAX_INSTRUCTIONS 256
 
44
/* For ARB programs, use the NV instruction limits */
 
45
#define MAX_INSTRUCTIONS MAX2(MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS, \
 
46
                              MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS)
44
47
 
45
48
 
46
49
/**
74
77
};
75
78
 
76
79
 
77
 
#ifndef __extension__
78
 
#if !defined(__GNUC__) || (__GNUC__ < 2) || \
79
 
    ((__GNUC__ == 2) && (__GNUC_MINOR__ <= 7))
80
 
# define __extension__
81
 
#endif
82
 
#endif
83
80
 
84
81
/* TODO:
85
82
 *    Fragment Program Stuff:
165
162
 
166
163
typedef GLubyte *production;
167
164
 
 
165
 
168
166
/**
169
167
 * This is the text describing the rules to parse the grammar
170
168
 */
171
 
__extension__ static char arb_grammar_text[] =
 
169
LONGSTRING static char arb_grammar_text[] =
172
170
#include "arbprogram_syn.h"
173
171
;
174
172
 
580
578
}
581
579
 
582
580
static struct var_cache *
583
 
var_cache_find (struct var_cache *va, GLubyte * name)
 
581
var_cache_find (struct var_cache *va, const GLubyte * name)
584
582
{
585
583
   /*struct var_cache *first = va;*/
586
584
 
597
595
   return NULL;
598
596
}
599
597
 
 
598
 
 
599
 
 
600
/**
 
601
 * Called when an error is detected while parsing/compiling a program.
 
602
 * Sets the ctx->Program.ErrorString field to descript and records a
 
603
 * GL_INVALID_OPERATION error.
 
604
 * \param position  position of error in program string
 
605
 * \param descrip  verbose error description
 
606
 */
 
607
static void
 
608
program_error(GLcontext *ctx, GLint position, const char *descrip)
 
609
{
 
610
   if (descrip) {
 
611
      const char *prefix = "glProgramString(", *suffix = ")";
 
612
      char *str = (char *) _mesa_malloc(_mesa_strlen(descrip) +
 
613
                                        _mesa_strlen(prefix) +
 
614
                                        _mesa_strlen(suffix) + 1);
 
615
      if (str) {
 
616
         _mesa_sprintf(str, "%s%s%s", prefix, descrip, suffix);
 
617
         _mesa_error(ctx, GL_INVALID_OPERATION, str);
 
618
         _mesa_free(str);
 
619
      }
 
620
   }
 
621
   _mesa_set_program_error(ctx, position, descrip);
 
622
}
 
623
 
 
624
 
 
625
 
600
626
/**
601
627
 * constructs an integer from 4 GLubytes in LE format
602
628
 */
603
629
static GLuint
604
 
parse_position (GLubyte ** inst)
 
630
parse_position (const GLubyte ** inst)
605
631
{
606
632
   GLuint value;
607
633
 
623
649
 * \return       The location on the var_cache corresponding the the string starting at I
624
650
 */
625
651
static struct var_cache *
626
 
parse_string (GLubyte ** inst, struct var_cache **vc_head,
 
652
parse_string (const GLubyte ** inst, struct var_cache **vc_head,
627
653
              struct arb_program *Program, GLuint * found)
628
654
{
629
 
   GLubyte *i = *inst;
 
655
   const GLubyte *i = *inst;
630
656
   struct var_cache *va = NULL;
631
657
   (void) Program;
632
658
 
649
675
}
650
676
 
651
677
static char *
652
 
parse_string_without_adding (GLubyte ** inst, struct arb_program *Program)
 
678
parse_string_without_adding (const GLubyte ** inst, struct arb_program *Program)
653
679
{
654
 
   GLubyte *i = *inst;
 
680
   const GLubyte *i = *inst;
655
681
   (void) Program;
656
682
   
657
683
   *inst += _mesa_strlen ((char *) i) + 1;
663
689
 * \return -1 if we parse '-', return 1 otherwise
664
690
 */
665
691
static GLint
666
 
parse_sign (GLubyte ** inst)
 
692
parse_sign (const GLubyte ** inst)
667
693
{
668
694
   /*return *(*inst)++ != '+'; */
669
695
 
683
709
 * parses and returns signed integer
684
710
 */
685
711
static GLint
686
 
parse_integer (GLubyte ** inst, struct arb_program *Program)
 
712
parse_integer (const GLubyte ** inst, struct arb_program *Program)
687
713
{
688
714
   GLint sign;
689
715
   GLint value;
720
746
  in the string.
721
747
*/
722
748
static GLdouble
723
 
parse_float_string(GLubyte ** inst, struct arb_program *Program, GLdouble *scale)
 
749
parse_float_string(const GLubyte ** inst, struct arb_program *Program, GLdouble *scale)
724
750
{
725
751
   GLdouble value = 0.0;
726
752
   GLdouble oscale = 1.0;
753
779
     12.34e-4
754
780
 */
755
781
static GLfloat
756
 
parse_float (GLubyte ** inst, struct arb_program *Program)
 
782
parse_float (const GLubyte ** inst, struct arb_program *Program)
757
783
{
758
784
   GLint exponent;
759
785
   GLdouble whole, fraction, fracScale = 1.0;
773
799
/**
774
800
 */
775
801
static GLfloat
776
 
parse_signed_float (GLubyte ** inst, struct arb_program *Program)
 
802
parse_signed_float (const GLubyte ** inst, struct arb_program *Program)
777
803
{
778
804
   GLint sign = parse_sign (inst);
779
805
   GLfloat value = parse_float (inst, Program);
787
813
 * \param values - The 4 component vector with the constant value in it
788
814
 */
789
815
static GLvoid
790
 
parse_constant (GLubyte ** inst, GLfloat *values, struct arb_program *Program,
 
816
parse_constant (const GLubyte ** inst, GLfloat *values, struct arb_program *Program,
791
817
                GLboolean use)
792
818
{
793
819
   GLuint components, i;
825
851
 * \return 0 on sucess, 1 on error
826
852
 */
827
853
static GLuint
828
 
parse_relative_offset (GLcontext *ctx, GLubyte **inst, struct arb_program *Program,
829
 
                        GLint *offset)
 
854
parse_relative_offset(GLcontext *ctx, const GLubyte **inst,
 
855
                      struct arb_program *Program, GLint *offset)
830
856
{
831
857
   (void) ctx;
832
858
   *offset = parse_integer(inst, Program);
838
864
 * \return 0 on sucess, 1 on error
839
865
 */
840
866
static GLuint
841
 
parse_color_type (GLcontext * ctx, GLubyte ** inst, struct arb_program *Program,
 
867
parse_color_type (GLcontext * ctx, const GLubyte ** inst, struct arb_program *Program,
842
868
                  GLint * color)
843
869
{
844
870
   (void) ctx; (void) Program;
852
878
 * \return 0 on sucess, 1 on error
853
879
 */
854
880
static GLuint
855
 
parse_generic_attrib_num(GLcontext *ctx, GLubyte ** inst,
 
881
parse_generic_attrib_num(GLcontext *ctx, const GLubyte ** inst,
856
882
                       struct arb_program *Program, GLuint *attrib)
857
883
{
858
884
   GLint i = parse_integer(inst, Program);
859
885
 
860
886
   if ((i < 0) || (i >= MAX_VERTEX_PROGRAM_ATTRIBS))
861
887
   {
862
 
      _mesa_set_program_error (ctx, Program->Position,
863
 
                               "Invalid generic vertex attribute index");
864
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Invalid generic vertex attribute index");
865
 
 
 
888
      program_error(ctx, Program->Position,
 
889
                    "Invalid generic vertex attribute index");
866
890
      return 1;
867
891
   }
868
892
 
877
901
 * \return 0 on sucess, 1 on error
878
902
 */
879
903
static GLuint
880
 
parse_output_color_num (GLcontext * ctx, GLubyte ** inst,
 
904
parse_output_color_num (GLcontext * ctx, const GLubyte ** inst,
881
905
                    struct arb_program *Program, GLuint * color)
882
906
{
883
907
   GLint i = parse_integer (inst, Program);
884
908
 
885
909
   if ((i < 0) || (i >= (int)ctx->Const.MaxDrawBuffers)) {
886
 
      _mesa_set_program_error (ctx, Program->Position,
887
 
                               "Invalid draw buffer index");
888
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Invalid draw buffer index");
 
910
      program_error(ctx, Program->Position, "Invalid draw buffer index");
889
911
      return 1;
890
912
   }
891
913
 
899
921
 * \return 0 on sucess, 1 on error
900
922
 */
901
923
static GLuint
902
 
parse_texcoord_num (GLcontext * ctx, GLubyte ** inst,
 
924
parse_texcoord_num (GLcontext * ctx, const GLubyte ** inst,
903
925
                    struct arb_program *Program, GLuint * coord)
904
926
{
905
927
   GLint i = parse_integer (inst, Program);
906
928
 
907
929
   if ((i < 0) || (i >= (int)ctx->Const.MaxTextureUnits)) {
908
 
      _mesa_set_program_error (ctx, Program->Position,
909
 
                               "Invalid texture unit index");
910
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Invalid texture unit index");
 
930
      program_error(ctx, Program->Position, "Invalid texture unit index");
911
931
      return 1;
912
932
   }
913
933
 
920
940
 * \return 0 on sucess, 1 on error
921
941
 */
922
942
static GLuint
923
 
parse_weight_num (GLcontext * ctx, GLubyte ** inst, struct arb_program *Program,
 
943
parse_weight_num (GLcontext * ctx, const GLubyte ** inst, struct arb_program *Program,
924
944
                  GLint * coord)
925
945
{
926
946
   *coord = parse_integer (inst, Program);
927
947
 
928
948
   if ((*coord < 0) || (*coord >= 1)) {
929
 
      _mesa_set_program_error (ctx, Program->Position,
930
 
                               "Invalid weight index");
931
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Invalid weight index");
 
949
      program_error(ctx, Program->Position, "Invalid weight index");
932
950
      return 1;
933
951
   }
934
952
 
940
958
 * \return 0 on sucess, 1 on error
941
959
 */
942
960
static GLuint
943
 
parse_clipplane_num (GLcontext * ctx, GLubyte ** inst,
 
961
parse_clipplane_num (GLcontext * ctx, const GLubyte ** inst,
944
962
                     struct arb_program *Program, GLint * coord)
945
963
{
946
964
   *coord = parse_integer (inst, Program);
947
965
 
948
966
   if ((*coord < 0) || (*coord >= (GLint) ctx->Const.MaxClipPlanes)) {
949
 
      _mesa_set_program_error (ctx, Program->Position,
950
 
                               "Invalid clip plane index");
951
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Invalid clip plane index");
 
967
      program_error(ctx, Program->Position, "Invalid clip plane index");
952
968
      return 1;
953
969
   }
954
970
 
960
976
 * \return 0 on front face, 1 on back face
961
977
 */
962
978
static GLuint
963
 
parse_face_type (GLubyte ** inst)
 
979
parse_face_type (const GLubyte ** inst)
964
980
{
965
981
   switch (*(*inst)++) {
966
982
      case FACE_FRONT:
983
999
 * \return 0 on sucess, 1 on failure
984
1000
 */
985
1001
static GLuint
986
 
parse_matrix (GLcontext * ctx, GLubyte ** inst, struct arb_program *Program,
 
1002
parse_matrix (GLcontext * ctx, const GLubyte ** inst, struct arb_program *Program,
987
1003
              GLint * matrix, GLint * matrix_idx, GLint * matrix_modifier)
988
1004
{
989
1005
   GLubyte mat = *(*inst)++;
995
1011
         *matrix = STATE_MODELVIEW;
996
1012
         *matrix_idx = parse_integer (inst, Program);
997
1013
         if (*matrix_idx > 0) {
998
 
            _mesa_set_program_error (ctx, Program->Position,
999
 
               "ARB_vertex_blend not supported\n");
1000
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1001
 
               "ARB_vertex_blend not supported\n");
 
1014
            program_error(ctx, Program->Position,
 
1015
                          "ARB_vertex_blend not supported");
1002
1016
            return 1;
1003
1017
         }
1004
1018
         break;
1015
1029
         *matrix = STATE_TEXTURE;
1016
1030
         *matrix_idx = parse_integer (inst, Program);
1017
1031
         if (*matrix_idx >= (GLint) ctx->Const.MaxTextureUnits) {
1018
 
            _mesa_set_program_error (ctx, Program->Position,
1019
 
                                     "Invalid Texture Unit");
1020
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1021
 
                         "Invalid Texture Unit: %d", *matrix_idx);
 
1032
            program_error(ctx, Program->Position, "Invalid Texture Unit");
 
1033
            /* bad *matrix_id */
1022
1034
            return 1;
1023
1035
         }
1024
1036
         break;
1026
1038
         /* This is not currently supported (ARB_matrix_palette) */
1027
1039
      case MATRIX_PALETTE:
1028
1040
         *matrix_idx = parse_integer (inst, Program);
1029
 
         _mesa_set_program_error (ctx, Program->Position,
1030
 
              "ARB_matrix_palette not supported\n");
1031
 
         _mesa_error (ctx, GL_INVALID_OPERATION,
1032
 
              "ARB_matrix_palette not supported\n");
 
1041
         program_error(ctx, Program->Position,
 
1042
                       "ARB_matrix_palette not supported");
1033
1043
         return 1;
1034
1044
         break;
1035
1045
 
1037
1047
         *matrix = STATE_PROGRAM;
1038
1048
         *matrix_idx = parse_integer (inst, Program);
1039
1049
         if (*matrix_idx >= (GLint) ctx->Const.MaxProgramMatrices) {
1040
 
            _mesa_set_program_error (ctx, Program->Position,
1041
 
                                     "Invalid Program Matrix");
1042
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1043
 
                         "Invalid Program Matrix: %d", *matrix_idx);
 
1050
            program_error(ctx, Program->Position, "Invalid Program Matrix");
 
1051
            /* bad *matrix_idx */
1044
1052
            return 1;
1045
1053
         }
1046
1054
         break;
1074
1082
 * \return             - 0 on sucess, 1 on error
1075
1083
 */
1076
1084
static GLuint
1077
 
parse_state_single_item (GLcontext * ctx, GLubyte ** inst,
 
1085
parse_state_single_item (GLcontext * ctx, const GLubyte ** inst,
1078
1086
                         struct arb_program *Program, GLint * state_tokens)
1079
1087
{
1080
1088
   switch (*(*inst)++) {
1106
1114
 
1107
1115
         /* Check the value of state_tokens[1] against the # of lights */
1108
1116
         if (state_tokens[1] >= (GLint) ctx->Const.MaxLights) {
1109
 
            _mesa_set_program_error (ctx, Program->Position,
1110
 
                                     "Invalid Light Number");
1111
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1112
 
                         "Invalid Light Number: %d", state_tokens[1]);
 
1117
            program_error(ctx, Program->Position, "Invalid Light Number");
 
1118
            /* bad state_tokens[1] */
1113
1119
            return 1;
1114
1120
         }
1115
1121
 
1156
1162
 
1157
1163
         /* Check the value of state_tokens[1] against the # of lights */
1158
1164
         if (state_tokens[1] >= (GLint) ctx->Const.MaxLights) {
1159
 
            _mesa_set_program_error (ctx, Program->Position,
1160
 
                                     "Invalid Light Number");
1161
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1162
 
                         "Invalid Light Number: %d", state_tokens[1]);
 
1165
            program_error(ctx, Program->Position, "Invalid Light Number");
 
1166
            /* bad state_tokens[1] */
1163
1167
            return 1;
1164
1168
         }
1165
1169
 
1290
1294
         if ((**inst) != 0) {                                   /* Either the last row, 0 */
1291
1295
            state_tokens[4] = parse_integer (inst, Program);
1292
1296
            if (state_tokens[4] < state_tokens[3]) {
1293
 
               _mesa_set_program_error (ctx, Program->Position,
1294
 
                     "Second matrix index less than the first");
1295
 
               _mesa_error (ctx, GL_INVALID_OPERATION,
1296
 
                     "Second matrix index (%d) less than the first (%d)",
1297
 
                     state_tokens[4], state_tokens[3]);
 
1297
               program_error(ctx, Program->Position,
 
1298
                             "Second matrix index less than the first");
 
1299
               /* state_tokens[4] vs. state_tokens[3] */
1298
1300
               return 1;
1299
1301
            }
1300
1302
         }
1339
1341
 * \return             - 0 on sucess, 1 on failure
1340
1342
 */
1341
1343
static GLuint
1342
 
parse_program_single_item (GLcontext * ctx, GLubyte ** inst,
 
1344
parse_program_single_item (GLcontext * ctx, const GLubyte ** inst,
1343
1345
                           struct arb_program *Program, GLint * state_tokens)
1344
1346
{
1345
1347
   if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB)
1359
1361
             ||
1360
1362
             ((Program->Base.Target == GL_VERTEX_PROGRAM_ARB) &&
1361
1363
              (state_tokens[2] >= (GLint) ctx->Const.VertexProgram.MaxEnvParams))) {
1362
 
            _mesa_set_program_error (ctx, Program->Position,
1363
 
                                     "Invalid Program Env Parameter");
1364
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1365
 
                         "Invalid Program Env Parameter: %d",
1366
 
                         state_tokens[2]);
 
1364
            program_error(ctx, Program->Position,
 
1365
                          "Invalid Program Env Parameter");
 
1366
            /* bad state_tokens[2] */
1367
1367
            return 1;
1368
1368
         }
1369
1369
 
1379
1379
             ||
1380
1380
             ((Program->Base.Target == GL_VERTEX_PROGRAM_ARB) &&
1381
1381
              (state_tokens[2] >= (GLint) ctx->Const.VertexProgram.MaxLocalParams))) {
1382
 
            _mesa_set_program_error (ctx, Program->Position,
1383
 
                                     "Invalid Program Local Parameter");
1384
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
1385
 
                         "Invalid Program Local Parameter: %d",
1386
 
                         state_tokens[2]);
 
1382
            program_error(ctx, Program->Position,
 
1383
                          "Invalid Program Local Parameter");
 
1384
            /* bad state_tokens[2] */
1387
1385
            return 1;
1388
1386
         }
1389
1387
         break;
1439
1437
 *
1440
1438
 * \param inputReg  returns the input register index, one of the
1441
1439
 *                  VERT_ATTRIB_* or FRAG_ATTRIB_* values.
1442
 
 * \return returns 0 on sucess, 1 on error
 
1440
 * \return returns 0 on success, 1 on error
1443
1441
 */
1444
1442
static GLuint
1445
 
parse_attrib_binding(GLcontext * ctx, GLubyte ** inst,
 
1443
parse_attrib_binding(GLcontext * ctx, const GLubyte ** inst,
1446
1444
                     struct arb_program *Program,
1447
1445
                     GLuint *inputReg, GLuint *is_generic)
1448
1446
{
1485
1483
 
1486
1484
         case VERTEX_ATTRIB_WEIGHT:
1487
1485
            {
1488
 
               const char *msg = "ARB_vertex_blend not supported";
1489
1486
               GLint weight;
1490
1487
               err = parse_weight_num (ctx, inst, Program, &weight);
1491
1488
               *inputReg = VERT_ATTRIB_WEIGHT;
1492
 
               _mesa_set_program_error(ctx, Program->Position, msg);
1493
 
               _mesa_error(ctx, GL_INVALID_OPERATION, msg);
 
1489
#if 1
 
1490
               /* hack for Warcraft (see bug 8060) */
 
1491
               _mesa_warning(ctx, "Application error: vertex program uses 'vertex.weight' but GL_ARB_vertex_blend not supported.");
 
1492
               break;
 
1493
#else
 
1494
               program_error(ctx, Program->Position,
 
1495
                             "ARB_vertex_blend not supported");
 
1496
               return 1;
 
1497
#endif
1494
1498
            }
1495
 
            return 1;
1496
1499
 
1497
1500
         case VERTEX_ATTRIB_NORMAL:
1498
1501
            *inputReg = VERT_ATTRIB_NORMAL;
1528
1531
            {
1529
1532
               const char *msg = "ARB_palette_matrix not supported";
1530
1533
               parse_integer (inst, Program);
1531
 
               _mesa_set_program_error (ctx, Program->Position, msg);
1532
 
               _mesa_error (ctx, GL_INVALID_OPERATION, msg);
 
1534
               program_error(ctx, Program->Position, msg);
1533
1535
            }
1534
1536
            return 1;
1535
1537
 
1536
1538
         case VERTEX_ATTRIB_GENERIC:
1537
1539
            {
1538
1540
               GLuint attrib;
1539
 
 
1540
1541
               err = parse_generic_attrib_num(ctx, inst, Program, &attrib);
1541
 
 
1542
 
                           if (!err) {
 
1542
               if (!err) {
1543
1543
                  *is_generic = 1;
1544
1544
                  /* Add VERT_ATTRIB_GENERIC0 here because ARB_vertex_program's
1545
1545
                   * attributes do not alias the conventional vertex
1560
1560
   }
1561
1561
 
1562
1562
   if (err) {
1563
 
      const char *msg = "Bad attribute binding";
1564
 
      _mesa_set_program_error(ctx, Program->Position, msg);
1565
 
      _mesa_error(ctx, GL_INVALID_OPERATION, msg);
 
1563
      program_error(ctx, Program->Position, "Bad attribute binding");
1566
1564
   }
1567
1565
 
1568
1566
   Program->Base.InputsRead |= (1 << *inputReg);
1580
1578
 *                   one of the VERT_RESULT_* or FRAG_RESULT_* values.
1581
1579
 */
1582
1580
static GLuint
1583
 
parse_result_binding(GLcontext *ctx, GLubyte **inst,
 
1581
parse_result_binding(GLcontext *ctx, const GLubyte **inst,
1584
1582
                     GLuint *outputReg, struct arb_program *Program)
1585
1583
{
1586
1584
   const GLubyte token = *(*inst)++;
1671
1669
 * \return 0 on sucess, 1 on error
1672
1670
 */
1673
1671
static GLint
1674
 
parse_attrib (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
1672
parse_attrib (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
1675
1673
              struct arb_program *Program)
1676
1674
{
1677
1675
   GLuint found;
1685
1683
         _mesa_malloc (_mesa_strlen ((char *) attrib_var->name) + 40);
1686
1684
      _mesa_sprintf (error_msg, "Duplicate Varible Declaration: %s",
1687
1685
                     attrib_var->name);
1688
 
 
1689
 
      _mesa_set_program_error (ctx, Program->Position, error_msg);
1690
 
      _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
1691
 
 
 
1686
      program_error(ctx, Program->Position, error_msg);
1692
1687
      _mesa_free (error_msg);
1693
1688
      return 1;
1694
1689
   }
1700
1695
      return 1;
1701
1696
 
1702
1697
   if (generic_attrib_check(*vc_head)) {
1703
 
      _mesa_set_program_error(ctx, Program->Position,
1704
 
                              "Cannot use both a generic vertex attribute "
1705
 
                              "and a specific attribute of the same type");
1706
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
1707
 
                  "Cannot use both a generic vertex attribute and a specific "
1708
 
                  "attribute of the same type");
 
1698
      program_error(ctx, Program->Position,
 
1699
                    "Cannot use both a generic vertex attribute "
 
1700
                    "and a specific attribute of the same type");
1709
1701
      return 1;
1710
1702
   }
1711
1703
 
1719
1711
 *               if we get a signed or unsigned float for scalar constants
1720
1712
 */
1721
1713
static GLuint
1722
 
parse_param_elements (GLcontext * ctx, GLubyte ** inst,
 
1714
parse_param_elements (GLcontext * ctx, const GLubyte ** inst,
1723
1715
                      struct var_cache *param_var,
1724
1716
                      struct arb_program *Program, GLboolean use)
1725
1717
{
1796
1788
                  out_of_range = 1;
1797
1789
            }
1798
1790
            if (out_of_range) {
1799
 
               _mesa_set_program_error (ctx, Program->Position,
1800
 
                                        "Invalid Program Parameter");
1801
 
               _mesa_error (ctx, GL_INVALID_OPERATION,
1802
 
                            "Invalid Program Parameter: %d", end_idx);
 
1791
               program_error(ctx, Program->Position,
 
1792
                             "Invalid Program Parameter"); /*end_idx*/
1803
1793
               return 1;
1804
1794
            }
1805
1795
 
1820
1810
         parse_constant (inst, const_values, Program, use);
1821
1811
         idx = _mesa_add_named_constant(Program->Base.Parameters,
1822
1812
                                        (char *) param_var->name,
1823
 
                                        const_values);
 
1813
                                        const_values, 4);
1824
1814
         if (param_var->param_binding_begin == ~0U)
1825
1815
            param_var->param_binding_begin = idx;
1826
1816
         param_var->param_binding_length++;
1828
1818
         break;
1829
1819
 
1830
1820
      default:
1831
 
         _mesa_set_program_error(ctx, Program->Position,
1832
 
                                 "Unexpected token in parse_param_elements()");
1833
 
         _mesa_error(ctx, GL_INVALID_OPERATION,
1834
 
                     "Unexpected token in parse_param_elements()");
 
1821
         program_error(ctx, Program->Position,
 
1822
                       "Unexpected token (in parse_param_elements())");
1835
1823
         return 1;
1836
1824
   }
1837
1825
 
1842
1830
       || ((Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB)
1843
1831
           && (Program->Base.NumParameters >=
1844
1832
               ctx->Const.FragmentProgram.MaxLocalParams))) {
1845
 
      _mesa_set_program_error (ctx, Program->Position,
1846
 
                               "Too many parameter variables");
1847
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Too many parameter variables");
 
1833
      program_error(ctx, Program->Position, "Too many parameter variables");
1848
1834
      return 1;
1849
1835
   }
1850
1836
 
1860
1846
 * \return 0 on sucess, 1 on error
1861
1847
 */
1862
1848
static GLuint
1863
 
parse_param (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
1849
parse_param (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
1864
1850
             struct arb_program *Program)
1865
1851
{
1866
1852
   GLuint found, err;
1876
1862
         _mesa_malloc (_mesa_strlen ((char *) param_var->name) + 40);
1877
1863
      _mesa_sprintf (error_msg, "Duplicate Varible Declaration: %s",
1878
1864
                     param_var->name);
1879
 
 
1880
 
      _mesa_set_program_error (ctx, Program->Position, error_msg);
1881
 
      _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
1882
 
 
 
1865
      program_error (ctx, Program->Position, error_msg);
1883
1866
      _mesa_free (error_msg);
1884
1867
      return 1;
1885
1868
   }
1887
1870
   specified_length = parse_integer (inst, Program);
1888
1871
 
1889
1872
   if (specified_length < 0) {
1890
 
      _mesa_set_program_error (ctx, Program->Position,
1891
 
                               "Negative parameter array length");
1892
 
      _mesa_error (ctx, GL_INVALID_OPERATION,
1893
 
                   "Negative parameter array length: %d", specified_length);
 
1873
      program_error(ctx, Program->Position, "Negative parameter array length");
1894
1874
      return 1;
1895
1875
   }
1896
1876
 
1918
1898
   /* Test array length here! */
1919
1899
   if (specified_length) {
1920
1900
      if (specified_length != (int)param_var->param_binding_length) {
1921
 
         const char *msg
1922
 
            = "Declared parameter array length does not match parameter list";
1923
 
         _mesa_set_program_error(ctx, Program->Position, msg);
1924
 
         _mesa_error(ctx, GL_INVALID_OPERATION, msg);
 
1901
         program_error(ctx, Program->Position,
 
1902
              "Declared parameter array length does not match parameter list");
1925
1903
      }
1926
1904
   }
1927
1905
 
1934
1912
 *
1935
1913
 */
1936
1914
static GLuint
1937
 
parse_param_use (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
1915
parse_param_use (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
1938
1916
                 struct arb_program *Program, struct var_cache **new_var)
1939
1917
{
1940
1918
   struct var_cache *param_var;
1970
1948
 * \return 0 on sucess, 1 on error
1971
1949
 */
1972
1950
static GLuint
1973
 
parse_temp (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
1951
parse_temp (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
1974
1952
            struct arb_program *Program)
1975
1953
{
1976
1954
   GLuint found;
1984
1962
            _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40);
1985
1963
         _mesa_sprintf (error_msg, "Duplicate Varible Declaration: %s",
1986
1964
                        temp_var->name);
1987
 
 
1988
 
         _mesa_set_program_error (ctx, Program->Position, error_msg);
1989
 
         _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
1990
 
 
 
1965
         program_error(ctx, Program->Position, error_msg);
1991
1966
         _mesa_free (error_msg);
1992
1967
         return 1;
1993
1968
      }
2000
1975
          || ((Program->Base.Target == GL_VERTEX_PROGRAM_ARB)
2001
1976
              && (Program->Base.NumTemporaries >=
2002
1977
                  ctx->Const.VertexProgram.MaxTemps))) {
2003
 
         _mesa_set_program_error (ctx, Program->Position,
2004
 
                                  "Too many TEMP variables declared");
2005
 
         _mesa_error (ctx, GL_INVALID_OPERATION,
2006
 
                      "Too many TEMP variables declared");
 
1978
         program_error(ctx, Program->Position,
 
1979
                       "Too many TEMP variables declared");
2007
1980
         return 1;
2008
1981
      }
2009
1982
 
2021
1994
 * \return 0 on sucess, 1 on error
2022
1995
 */
2023
1996
static GLuint
2024
 
parse_output (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
1997
parse_output (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
2025
1998
              struct arb_program *Program)
2026
1999
{
2027
2000
   GLuint found;
2035
2008
         _mesa_malloc (_mesa_strlen ((char *) output_var->name) + 40);
2036
2009
      _mesa_sprintf (error_msg, "Duplicate Varible Declaration: %s",
2037
2010
                     output_var->name);
2038
 
 
2039
 
      _mesa_set_program_error (ctx, Program->Position, error_msg);
2040
 
      _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
2041
 
 
 
2011
      program_error (ctx, Program->Position, error_msg);
2042
2012
      _mesa_free (error_msg);
2043
2013
      return 1;
2044
2014
   }
2055
2025
 * \return 0 on sucess, 1 on error
2056
2026
 */
2057
2027
static GLuint
2058
 
parse_alias (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
2028
parse_alias (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
2059
2029
             struct arb_program *Program)
2060
2030
{
2061
2031
   GLuint found;
2069
2039
         _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40);
2070
2040
      _mesa_sprintf (error_msg, "Duplicate Varible Declaration: %s",
2071
2041
                     temp_var->name);
2072
 
 
2073
 
      _mesa_set_program_error (ctx, Program->Position, error_msg);
2074
 
      _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
2075
 
 
 
2042
      program_error(ctx, Program->Position, error_msg);
2076
2043
      _mesa_free (error_msg);
2077
2044
      return 1;
2078
2045
   }
2087
2054
         _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40);
2088
2055
      _mesa_sprintf (error_msg, "Alias value %s is not defined",
2089
2056
                     temp_var->alias_binding->name);
2090
 
 
2091
 
      _mesa_set_program_error (ctx, Program->Position, error_msg);
2092
 
      _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
2093
 
 
 
2057
      program_error (ctx, Program->Position, error_msg);
2094
2058
      _mesa_free (error_msg);
2095
2059
      return 1;
2096
2060
   }
2104
2068
 * \return 0 on sucess, 1 on error
2105
2069
 */
2106
2070
static GLuint
2107
 
parse_address (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
2071
parse_address (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
2108
2072
               struct arb_program *Program)
2109
2073
{
2110
2074
   GLuint found;
2118
2082
            _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40);
2119
2083
         _mesa_sprintf (error_msg, "Duplicate Varible Declaration: %s",
2120
2084
                        temp_var->name);
2121
 
 
2122
 
         _mesa_set_program_error (ctx, Program->Position, error_msg);
2123
 
         _mesa_error (ctx, GL_INVALID_OPERATION, error_msg);
2124
 
 
 
2085
         program_error (ctx, Program->Position, error_msg);
2125
2086
         _mesa_free (error_msg);
2126
2087
         return 1;
2127
2088
      }
2131
2092
      if (Program->Base.NumAddressRegs >=
2132
2093
          ctx->Const.VertexProgram.MaxAddressRegs) {
2133
2094
         const char *msg = "Too many ADDRESS variables declared";
2134
 
         _mesa_set_program_error(ctx, Program->Position, msg);
2135
 
                                  
2136
 
         _mesa_error(ctx, GL_INVALID_OPERATION, msg);
 
2095
         program_error(ctx, Program->Position, msg);
2137
2096
         return 1;
2138
2097
      }
2139
2098
 
2151
2110
 * \return 0 on sucess, 1 on error
2152
2111
 */
2153
2112
static GLint
2154
 
parse_declaration (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
2113
parse_declaration (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head,
2155
2114
                   struct arb_program *Program)
2156
2115
{
2157
2116
   GLint err = 0;
2200
2159
 * \return 0 on sucess, 1 on error
2201
2160
 */
2202
2161
static GLuint
2203
 
parse_masked_dst_reg (GLcontext * ctx, GLubyte ** inst,
 
2162
parse_masked_dst_reg (GLcontext * ctx, const GLubyte ** inst,
2204
2163
                      struct var_cache **vc_head, struct arb_program *Program,
2205
2164
                      enum register_file *File, GLuint *Index, GLint *WriteMask)
2206
2165
{
2223
2182
 
2224
2183
         /* If the name has never been added to our symbol table, we're hosed */
2225
2184
         if (!result) {
2226
 
            _mesa_set_program_error (ctx, Program->Position,
2227
 
                                     "0: Undefined variable");
2228
 
            _mesa_error (ctx, GL_INVALID_OPERATION, "0: Undefined variable: %s",
2229
 
                         dst->name);
 
2185
            program_error(ctx, Program->Position, "0: Undefined variable");
2230
2186
            return 1;
2231
2187
         }
2232
2188
 
2243
2199
 
2244
2200
               /* If the var type is not vt_output or vt_temp, no go */
2245
2201
            default:
2246
 
               _mesa_set_program_error (ctx, Program->Position,
2247
 
                                        "Destination register is read only");
2248
 
               _mesa_error (ctx, GL_INVALID_OPERATION,
2249
 
                            "Destination register is read only: %s",
2250
 
                            dst->name);
 
2202
               program_error(ctx, Program->Position,
 
2203
                             "Destination register is read only");
2251
2204
               return 1;
2252
2205
         }
2253
2206
         break;
2254
2207
 
2255
2208
      default:
2256
 
         _mesa_set_program_error (ctx, Program->Position,
2257
 
                                  "Unexpected opcode in parse_masked_dst_reg()");
2258
 
         _mesa_error (ctx, GL_INVALID_OPERATION,
2259
 
                      "Unexpected opcode in parse_masked_dst_reg()");
 
2209
         program_error(ctx, Program->Position,
 
2210
                       "Unexpected opcode in parse_masked_dst_reg()");
2260
2211
         return 1;
2261
2212
   }
2262
2213
 
2268
2219
   */
2269
2220
   /*if ((Program->HintPositionInvariant) && (*File == PROGRAM_OUTPUT) &&
2270
2221
      (*Index == 0))   {
2271
 
      _mesa_set_program_error (ctx, Program->Position,
2272
 
                  "Vertex program specified position invariance and wrote vertex position");
2273
 
      _mesa_error (ctx, GL_INVALID_OPERATION,
 
2222
      program_error(ctx, Program->Position,
2274
2223
                  "Vertex program specified position invariance and wrote vertex position");
2275
2224
   }*/
2276
2225
 
2300
2249
 * \return 0 on sucess, 1 on error
2301
2250
 */
2302
2251
static GLuint
2303
 
parse_address_reg (GLcontext * ctx, GLubyte ** inst,
 
2252
parse_address_reg (GLcontext * ctx, const GLubyte ** inst,
2304
2253
                          struct var_cache **vc_head,
2305
2254
                          struct arb_program *Program, GLint * Index)
2306
2255
{
2314
2263
 
2315
2264
   /* If the name has never been added to our symbol table, we're hosed */
2316
2265
   if (!result) {
2317
 
      _mesa_set_program_error (ctx, Program->Position, "Undefined variable");
2318
 
      _mesa_error (ctx, GL_INVALID_OPERATION, "Undefined variable: %s",
2319
 
                   dst->name);
 
2266
      program_error(ctx, Program->Position, "Undefined variable");
2320
2267
      return 1;
2321
2268
   }
2322
2269
 
2323
2270
   if (dst->type != vt_address) {
2324
 
      _mesa_set_program_error (ctx, Program->Position,
2325
 
                               "Variable is not of type ADDRESS");
2326
 
      _mesa_error (ctx, GL_INVALID_OPERATION,
2327
 
                   "Variable: %s is not of type ADDRESS", dst->name);
 
2271
      program_error(ctx, Program->Position, "Variable is not of type ADDRESS");
2328
2272
      return 1;
2329
2273
   }
2330
2274
 
2341
2285
 * \return 0 on sucess, 1 on error
2342
2286
 */
2343
2287
static GLuint
2344
 
parse_masked_address_reg (GLcontext * ctx, GLubyte ** inst,
 
2288
parse_masked_address_reg (GLcontext * ctx, const GLubyte ** inst,
2345
2289
                          struct var_cache **vc_head,
2346
2290
                          struct arb_program *Program, GLint * Index,
2347
2291
                          GLboolean * WriteMask)
2369
2313
 * swizzle, or just 1 component for a scalar src register selection
2370
2314
 */
2371
2315
static void
2372
 
parse_swizzle_mask(GLubyte ** inst, GLubyte *swizzle, GLint len)
 
2316
parse_swizzle_mask(const GLubyte ** inst, GLubyte *swizzle, GLint len)
2373
2317
{
2374
2318
   GLint i;
2375
2319
 
2405
2349
 * \return negateMask  four element bitfield
2406
2350
 */
2407
2351
static void
2408
 
parse_extended_swizzle_mask(GLubyte **inst, GLubyte swizzle[4],
 
2352
parse_extended_swizzle_mask(const GLubyte **inst, GLubyte swizzle[4],
2409
2353
                            GLubyte *negateMask)
2410
2354
{
2411
2355
   GLint i;
2446
2390
 
2447
2391
 
2448
2392
static GLuint
2449
 
parse_src_reg (GLcontext * ctx, GLubyte ** inst, struct var_cache **vc_head,
 
2393
parse_src_reg (GLcontext * ctx, const GLubyte ** inst,
 
2394
               struct var_cache **vc_head,
2450
2395
               struct arb_program *Program,
2451
2396
               enum register_file * File, GLint * Index,
2452
2397
               GLboolean *IsRelOffset )
2476
2421
         src->attrib_is_generic = is_generic;
2477
2422
         var_cache_append(vc_head, src);
2478
2423
         if (generic_attrib_check(*vc_head)) {
2479
 
            const char *msg = "Cannot use both a generic vertex attribute "
2480
 
               "and a specific attribute of the same type";
2481
 
            _mesa_set_program_error (ctx, Program->Position, msg);
2482
 
            _mesa_error (ctx, GL_INVALID_OPERATION, msg);
 
2424
            program_error(ctx, Program->Position,
 
2425
                          "Cannot use both a generic vertex attribute "
 
2426
                          "and a specific attribute of the same type");
2483
2427
            return 1;
2484
2428
         }
2485
2429
         break;
2492
2436
               Program->Position = parse_position (inst);
2493
2437
 
2494
2438
               if (!found) {
2495
 
                  _mesa_set_program_error (ctx, Program->Position,
2496
 
                                           "2: Undefined variable");
2497
 
                  _mesa_error (ctx, GL_INVALID_OPERATION,
2498
 
                               "2: Undefined variable: %s", src->name);
 
2439
                  program_error(ctx, Program->Position,
 
2440
                                "2: Undefined variable"); /* src->name */
2499
2441
                  return 1;
2500
2442
               }
2501
2443
 
2507
2449
 
2508
2450
                     if ((offset < 0)
2509
2451
                         || (offset >= (int)src->param_binding_length)) {
2510
 
                        _mesa_set_program_error (ctx, Program->Position,
2511
 
                                                 "Index out of range");
2512
 
                        _mesa_error (ctx, GL_INVALID_OPERATION,
2513
 
                                     "Index %d out of range for %s", offset,
2514
 
                                     src->name);
 
2452
                        program_error(ctx, Program->Position,
 
2453
                                      "Index out of range");
 
2454
                        /* offset, src->name */
2515
2455
                        return 1;
2516
2456
                     }
2517
2457
 
2559
2499
 
2560
2500
         /* If the name has never been added to our symbol table, we're hosed */
2561
2501
         if (!found) {
2562
 
            _mesa_set_program_error (ctx, Program->Position,
2563
 
                                     "3: Undefined variable");
2564
 
            _mesa_error (ctx, GL_INVALID_OPERATION, "3: Undefined variable: %s",
2565
 
                         src->name);
 
2502
            program_error(ctx, Program->Position,
 
2503
                          "3: Undefined variable"); /* src->name */
2566
2504
            return 1;
2567
2505
         }
2568
2506
 
2585
2523
 
2586
2524
               /* If the var type is vt_output no go */
2587
2525
            default:
2588
 
               _mesa_set_program_error (ctx, Program->Position,
2589
 
                                        "destination register is read only");
2590
 
               _mesa_error (ctx, GL_INVALID_OPERATION,
2591
 
                            "destination register is read only: %s",
2592
 
                            src->name);
 
2526
               program_error(ctx, Program->Position,
 
2527
                             "destination register is read only");
 
2528
               /* bad src->name */
2593
2529
               return 1;
2594
2530
         }
2595
2531
         break;
2596
2532
 
2597
2533
      default:
2598
 
         _mesa_set_program_error (ctx, Program->Position,
2599
 
                                  "Unknown token in parse_src_reg");
2600
 
         _mesa_error (ctx, GL_INVALID_OPERATION,
2601
 
                      "Unknown token in parse_src_reg");
 
2534
         program_error(ctx, Program->Position,
 
2535
                       "Unknown token in parse_src_reg");
2602
2536
         return 1;
2603
2537
   }
2604
2538
 
2609
2543
 * Parse fragment program vector source register.
2610
2544
 */
2611
2545
static GLuint
2612
 
parse_fp_vector_src_reg(GLcontext * ctx, GLubyte ** inst,
 
2546
parse_fp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst,
2613
2547
                        struct var_cache **vc_head,
2614
2548
                        struct arb_program *program,
2615
2549
                        struct prog_src_register *reg)
2632
2566
 
2633
2567
   reg->File = file;
2634
2568
   reg->Index = index;
2635
 
   reg->Abs = 0;                /* NV only */
2636
 
   reg->NegateAbs = 0;          /* NV only */
2637
2569
   reg->NegateBase = negate;
2638
2570
   reg->Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
2639
2571
   return 0;
2640
2572
}
2641
2573
 
2642
2574
 
 
2575
/**
 
2576
 * Parse fragment program destination register.
 
2577
 * \return 1 if error, 0 if no error.
 
2578
 */
2643
2579
static GLuint 
2644
 
parse_fp_dst_reg(GLcontext * ctx, GLubyte ** inst,
 
2580
parse_fp_dst_reg(GLcontext * ctx, const GLubyte ** inst,
2645
2581
                 struct var_cache **vc_head, struct arb_program *Program,
2646
2582
                 struct prog_dst_register *reg )
2647
2583
{
2652
2588
   if (parse_masked_dst_reg (ctx, inst, vc_head, Program, &file, &idx, &mask))
2653
2589
      return 1;
2654
2590
 
2655
 
   reg->CondMask = 0;           /* NV only */
2656
 
   reg->CondSwizzle = 0;        /* NV only */
2657
2591
   reg->File = file;
2658
2592
   reg->Index = idx;
2659
2593
   reg->WriteMask = mask;
2663
2597
 
2664
2598
/**
2665
2599
 * Parse fragment program scalar src register.
 
2600
 * \return 1 if error, 0 if no error.
2666
2601
 */
2667
2602
static GLuint
2668
 
parse_fp_scalar_src_reg (GLcontext * ctx, GLubyte ** inst,
 
2603
parse_fp_scalar_src_reg (GLcontext * ctx, const GLubyte ** inst,
2669
2604
                         struct var_cache **vc_head,
2670
2605
                         struct arb_program *Program,
2671
2606
                         struct prog_src_register *reg )
2688
2623
 
2689
2624
   reg->File = File;
2690
2625
   reg->Index = Index;
2691
 
   reg->Abs = 0;                /* NV only */
2692
 
   reg->NegateAbs = 0;          /* NV only */
2693
2626
   reg->NegateBase = Negate;
2694
2627
   reg->Swizzle = (Swizzle[0] << 0);
2695
2628
 
2700
2633
/**
2701
2634
 * This is a big mother that handles getting opcodes into the instruction
2702
2635
 * and handling the src & dst registers for fragment program instructions
 
2636
 * \return 1 if error, 0 if no error
2703
2637
 */
2704
2638
static GLuint
2705
 
parse_fp_instruction (GLcontext * ctx, GLubyte ** inst,
 
2639
parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst,
2706
2640
                      struct var_cache **vc_head, struct arb_program *Program,
2707
2641
                      struct prog_instruction *fp)
2708
2642
{
2711
2645
   GLubyte instClass, type, code;
2712
2646
   GLboolean rel;
2713
2647
 
2714
 
   _mesa_init_instruction(fp);
 
2648
   _mesa_init_instructions(fp, 1);
2715
2649
 
2716
2650
   /* Record the position in the program string for debugging */
2717
2651
   fp->StringPos = Program->Position;
3048
2982
               /* TODO ARB_fragment_program_shadow code */
3049
2983
               break;
3050
2984
         }
3051
 
         Program->TexturesUsed[texcoord] |= (1<<fp->TexSrcTarget);
 
2985
         Program->TexturesUsed[texcoord] |= (1 << fp->TexSrcTarget);
 
2986
         /* Check that both "2D" and "CUBE" (for example) aren't both used */
 
2987
         if (_mesa_bitcount(Program->TexturesUsed[texcoord]) > 1) {
 
2988
            program_error(ctx, Program->Position,
 
2989
                          "multiple targets used on one texture image unit");
 
2990
            return 1;
 
2991
         }
3052
2992
         break;
3053
2993
 
3054
2994
      case OP_TEX_KIL:
3057
2997
            return 1;
3058
2998
         fp->Opcode = OPCODE_KIL;
3059
2999
         break;
 
3000
      default:
 
3001
         _mesa_problem(ctx, "bad type 0x%x in parse_fp_instruction()", type);
 
3002
         return 1;
3060
3003
   }
3061
3004
 
3062
3005
   return 0;
3063
3006
}
3064
3007
 
3065
3008
static GLuint 
3066
 
parse_vp_dst_reg(GLcontext * ctx, GLubyte ** inst,
 
3009
parse_vp_dst_reg(GLcontext * ctx, const GLubyte ** inst,
3067
3010
                 struct var_cache **vc_head, struct arb_program *Program,
3068
3011
                 struct prog_dst_register *reg )
3069
3012
{
3089
3032
 * \return 0 on sucess, 1 on error
3090
3033
 */
3091
3034
static GLuint
3092
 
parse_vp_address_reg (GLcontext * ctx, GLubyte ** inst,
 
3035
parse_vp_address_reg (GLcontext * ctx, const GLubyte ** inst,
3093
3036
                      struct var_cache **vc_head,
3094
3037
                      struct arb_program *Program,
3095
3038
                      struct prog_dst_register *reg)
3114
3057
 * Parse vertex program vector source register.
3115
3058
 */
3116
3059
static GLuint
3117
 
parse_vp_vector_src_reg(GLcontext * ctx, GLubyte ** inst,
 
3060
parse_vp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst,
3118
3061
                        struct var_cache **vc_head,
3119
3062
                        struct arb_program *program,
3120
3063
                        struct prog_src_register *reg )
3146
3089
 
3147
3090
 
3148
3091
static GLuint
3149
 
parse_vp_scalar_src_reg (GLcontext * ctx, GLubyte ** inst,
 
3092
parse_vp_scalar_src_reg (GLcontext * ctx, const GLubyte ** inst,
3150
3093
                         struct var_cache **vc_head,
3151
3094
                         struct arb_program *Program,
3152
3095
                         struct prog_src_register *reg )
3181
3124
 * and handling the src & dst registers for vertex program instructions
3182
3125
 */
3183
3126
static GLuint
3184
 
parse_vp_instruction (GLcontext * ctx, GLubyte ** inst,
 
3127
parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst,
3185
3128
                      struct var_cache **vc_head, struct arb_program *Program,
3186
3129
                      struct prog_instruction *vp)
3187
3130
{
3194
3137
   /* The actual opcode name */
3195
3138
   code = *(*inst)++;
3196
3139
 
3197
 
   _mesa_init_instruction(vp);
 
3140
   _mesa_init_instructions(vp, 1);
3198
3141
   /* Record the position in the program string for debugging */
3199
3142
   vp->StringPos = Program->Position;
3200
3143
 
3642
3585
 * \return 1 on error, 0 on success
3643
3586
 */
3644
3587
static GLint
3645
 
parse_instructions(GLcontext * ctx, GLubyte * inst, struct var_cache **vc_head,
3646
 
                  struct arb_program *Program)
 
3588
parse_instructions(GLcontext * ctx, const GLubyte * inst,
 
3589
                   struct var_cache **vc_head, struct arb_program *Program)
3647
3590
{
3648
3591
   const GLuint maxInst = (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB)
3649
3592
      ? ctx->Const.FragmentProgram.MaxInstructions
3702
3645
         case INSTRUCTION:
3703
3646
            /* check length */
3704
3647
            if (Program->Base.NumInstructions + 1 >= maxInst) {
3705
 
               const char *msg = "Max instruction count exceeded";
3706
 
               _mesa_set_program_error(ctx, Program->Position, msg);
3707
 
               _mesa_error(ctx, GL_INVALID_OPERATION, msg);
 
3648
               program_error(ctx, Program->Position,
 
3649
                             "Max instruction count exceeded");
3708
3650
               return 1;
3709
3651
            }
3710
3652
            Program->Position = parse_position (&inst);
3737
3679
   /* Finally, tag on an OPCODE_END instruction */
3738
3680
   {
3739
3681
      const GLuint numInst = Program->Base.NumInstructions;
3740
 
      _mesa_init_instruction(Program->Base.Instructions + numInst);
 
3682
      _mesa_init_instructions(Program->Base.Instructions + numInst, 1);
3741
3683
      Program->Base.Instructions[numInst].Opcode = OPCODE_END;
3742
3684
      /* YYY Wrong Position in program, whatever, at least not random -> crash
3743
3685
         Program->Position = parse_position (&inst);
3812
3754
   /* These are not supported at this time */
3813
3755
   if ((ctx->Extensions.ARB_vertex_blend ||
3814
3756
        ctx->Extensions.EXT_vertex_weighting)
3815
 
       && !enable_ext(ctx, id, "point_parameters"))
 
3757
       && !enable_ext(ctx, id, "vertex_blend"))
3816
3758
      return GL_FALSE;
3817
3759
   if (ctx->Extensions.ARB_matrix_palette
3818
3760
       && !enable_ext(ctx, id, "matrix_palette"))
3837
3779
       && !enable_ext(ctx, id, "draw_buffers"))
3838
3780
      return GL_FALSE;
3839
3781
 
 
3782
#if 1
 
3783
   /* hack for Warcraft (see bug 8060) */
 
3784
   enable_ext(ctx, id, "vertex_blend");
 
3785
#endif
 
3786
 
3840
3787
   return GL_TRUE;
3841
3788
}
3842
3789
 
3939
3886
      GLint i;
3940
3887
      for (i = 0; i < len; i++) {
3941
3888
         if (str[i] == '\0') {
3942
 
            _mesa_set_program_error (ctx, i, "invalid character");
3943
 
            _mesa_error (ctx, GL_INVALID_OPERATION,
3944
 
                         "glProgramStringARB(illegal character)");
 
3889
            program_error(ctx, i, "illegal character");
3945
3890
            grammar_destroy (arbprogram_syn_id);
3946
3891
            return GL_FALSE;
3947
3892
         }
3964
3909
 
3965
3910
   /* Syntax parse error */
3966
3911
   if (err) {
3967
 
      _mesa_free(strz);
3968
 
      _mesa_free(parsed);
3969
 
      grammar_get_last_error ((GLubyte *) error_msg, 300, &error_pos);
3970
 
      _mesa_set_program_error (ctx, error_pos, error_msg);
3971
 
      _mesa_error (ctx, GL_INVALID_OPERATION,
3972
 
                   "glProgramStringARB(syntax error)");
 
3912
      grammar_get_last_error((GLubyte *) error_msg, 300, &error_pos);
 
3913
      program_error(ctx, error_pos, error_msg);
3973
3914
 
 
3915
#if DEBUG_PARSING
3974
3916
      /* useful for debugging */
3975
 
#if DEBUG_PARSING
3976
3917
      do {
3977
3918
         int line, col;
3978
3919
         char *s;
3979
3920
         fprintf(stderr, "program: %s\n", (char *) strz);
3980
3921
         fprintf(stderr, "Error Pos: %d\n", ctx->program.ErrorPos);
3981
 
         s = (char *) _mesa_find_line_column(strz, strz+ctx->program.ErrorPos, &line, &col);
 
3922
         s = (char *) _mesa_find_line_column(strz, strz+ctx->program.ErrorPos,
 
3923
                                             &line, &col);
3982
3924
         fprintf(stderr, "line %d col %d: %s\n", line, col, s);
3983
3925
      } while (0)
3984
3926
#endif
3985
3927
 
 
3928
      _mesa_free(strz);
 
3929
      _mesa_free(parsed);
 
3930
 
3986
3931
      grammar_destroy (arbprogram_syn_id);
3987
3932
      return GL_FALSE;
3988
3933
   }
3997
3942
 
3998
3943
   /* Initialize the arb_program struct */
3999
3944
   program->Base.String = strz;
4000
 
   program->Base.Instructions = (struct prog_instruction *)
4001
 
      _mesa_malloc(MAX_INSTRUCTIONS * sizeof(struct prog_instruction));
 
3945
   program->Base.Instructions = _mesa_alloc_instructions(MAX_INSTRUCTIONS);
4002
3946
   program->Base.NumInstructions =
4003
3947
   program->Base.NumTemporaries =
4004
3948
   program->Base.NumParameters =
4026
3970
 
4027
3971
   /* Check the grammer rev */
4028
3972
   if (*inst++ != REVISION) {
4029
 
      _mesa_set_program_error (ctx, 0, "Grammar version mismatch");
4030
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
4031
 
                  "glProgramStringARB(Grammar version mismatch)");
 
3973
      program_error (ctx, 0, "Grammar version mismatch");
4032
3974
      err = GL_TRUE;
4033
3975
   }
4034
3976
   else {
4047
3989
   /* Reallocate the instruction array from size [MAX_INSTRUCTIONS]
4048
3990
    * to size [ap.Base.NumInstructions].
4049
3991
    */
4050
 
   program->Base.Instructions = (struct prog_instruction *)
4051
 
      _mesa_realloc(program->Base.Instructions,
4052
 
             MAX_INSTRUCTIONS * sizeof(struct prog_instruction),/*orig*/
4053
 
             program->Base.NumInstructions * sizeof(struct prog_instruction));
4054
 
   
 
3992
   program->Base.Instructions
 
3993
      = _mesa_realloc_instructions(program->Base.Instructions,
 
3994
                                   MAX_INSTRUCTIONS,
 
3995
                                   program->Base.NumInstructions);
 
3996
 
4055
3997
   return !err;
4056
3998
}
4057
3999
 
4080
4022
   program->Base.NumParameters   = ap.Base.NumParameters;
4081
4023
   program->Base.NumAttributes   = ap.Base.NumAttributes;
4082
4024
   program->Base.NumAddressRegs  = ap.Base.NumAddressRegs;
 
4025
   program->Base.NumNativeInstructions = ap.Base.NumNativeInstructions;
 
4026
   program->Base.NumNativeTemporaries = ap.Base.NumNativeTemporaries;
 
4027
   program->Base.NumNativeParameters = ap.Base.NumNativeParameters;
 
4028
   program->Base.NumNativeAttributes = ap.Base.NumNativeAttributes;
 
4029
   program->Base.NumNativeAddressRegs = ap.Base.NumNativeAddressRegs;
4083
4030
   program->NumAluInstructions   = ap.NumAluInstructions;
4084
4031
   program->NumTexInstructions   = ap.NumTexInstructions;
4085
4032
   program->NumTexIndirections   = ap.NumTexIndirections;
4101
4048
   program->Base.Parameters    = ap.Base.Parameters;
4102
4049
 
4103
4050
#if DEBUG_FP
4104
 
   _mesa_print_program(&program.Base);
 
4051
   _mesa_printf("____________Fragment program %u ________\n", program->Base.ID);
 
4052
   _mesa_print_program(&program->Base);
4105
4053
#endif
4106
4054
}
4107
4055
 
4135
4083
   program->Base.NumParameters   = ap.Base.NumParameters;
4136
4084
   program->Base.NumAttributes   = ap.Base.NumAttributes;
4137
4085
   program->Base.NumAddressRegs  = ap.Base.NumAddressRegs;
 
4086
   program->Base.NumNativeInstructions = ap.Base.NumNativeInstructions;
 
4087
   program->Base.NumNativeTemporaries = ap.Base.NumNativeTemporaries;
 
4088
   program->Base.NumNativeParameters = ap.Base.NumNativeParameters;
 
4089
   program->Base.NumNativeAttributes = ap.Base.NumNativeAttributes;
 
4090
   program->Base.NumNativeAddressRegs = ap.Base.NumNativeAddressRegs;
4138
4091
   program->Base.InputsRead     = ap.Base.InputsRead;
4139
4092
   program->Base.OutputsWritten = ap.Base.OutputsWritten;
4140
4093
   program->IsPositionInvariant = ap.HintPositionInvariant;
4148
4101
   program->Base.Parameters = ap.Base.Parameters; 
4149
4102
 
4150
4103
#if DEBUG_VP
 
4104
   _mesa_printf("____________Vertex program %u __________\n", program->Base.ID);
4151
4105
   _mesa_print_program(&program->Base);
4152
4106
#endif
4153
4107
}