mesa: Fix arb parse constants
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 19 Sep 2008 11:04:52 +0000 (13:04 +0200)
committerJakob Bornecrantz <jakob@tungstengraphics.com>
Fri, 19 Sep 2008 11:04:52 +0000 (13:04 +0200)
src/mesa/shader/arbprogparse.c
src/mesa/state_tracker/st_mesa_to_tgsi.c

index 26ccdc7395a3e977a581441cdc3e441f3d19a202..5e81477592a9b162014338c6f626880778993224 100644 (file)
  * \author Karl Rasche
  */
 
+/**
+Notes on program parameters, etc.
+
+The instructions we emit will use six kinds of source registers:
+
+  PROGRAM_INPUT      - input registers
+  PROGRAM_TEMPORARY  - temp registers
+  PROGRAM_ADDRESS    - address/indirect register
+  PROGRAM_SAMPLER    - texture sampler
+  PROGRAM_CONSTANT   - indexes into program->Parameters, a known constant/literal
+  PROGRAM_STATE_VAR  - indexes into program->Parameters, and may actually be:
+                       + a state variable, like "state.fog.color", or
+                       + a pointer to a "program.local[k]" parameter, or
+                       + a pointer to a "program.env[k]" parameter
+
+Basically, all the program.local[] and program.env[] values will get mapped
+into the unified gl_program->Parameters array.  This solves the problem of
+having three separate program parameter arrays.
+*/
+
+
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "shader/grammar/grammar_mesa.h"
@@ -1871,7 +1892,11 @@ parse_param_elements (GLcontext * ctx, const GLubyte ** inst,
                                         const_values, 4);
          if (param_var->param_binding_begin == ~0U)
             param_var->param_binding_begin = idx;
-         param_var->param_binding_type = PROGRAM_CONSTANT;
+         param_var->param_binding_type = PROGRAM_STATE_VAR;
+         /* Note: when we reference this parameter in an instruction later,
+          * we'll check if it's really a constant/immediate and set the
+          * instruction register type appropriately.
+          */
          param_var->param_binding_length++;
          Program->Base.NumParameters++;
          break;
@@ -2578,6 +2603,16 @@ parse_src_reg (GLcontext * ctx, const GLubyte ** inst,
          return 1;
    }
 
+   if (*File == PROGRAM_STATE_VAR) {
+      /* If we're referencing the Program->Parameters[] array, check if the
+       * parameter is really a constant/literal.  If so, set File to CONSTANT.
+       */
+      assert(*Index < Program->Base.Parameters->NumParameters);
+      enum register_file file = Program->Base.Parameters->Parameters[*Index].Type;
+      if (file == PROGRAM_CONSTANT)
+         *File = PROGRAM_CONSTANT;
+   }
+
    /* Add attributes to InputsRead only if they are used the program.
     * This avoids the handling of unused ATTRIB declarations in the drivers. */
    if (*File == PROGRAM_INPUT)
index b9807bb8074155640f661fe8367aa68a016a4860..524d8890b5cb71ea5e3f2f1acd4c91926b670b4c 100644 (file)
@@ -77,6 +77,7 @@ map_register_file(
    case PROGRAM_CONSTANT:
       if (indirectAccess)
          return TGSI_FILE_CONSTANT;
+      assert(immediateMapping[index] != ~0);
       return TGSI_FILE_IMMEDIATE;
    case PROGRAM_INPUT:
       return TGSI_FILE_INPUT;
@@ -118,6 +119,7 @@ map_register_file_index(
    case TGSI_FILE_IMMEDIATE:
       if (indirectAccess)
          return index;
+      assert(immediateMapping[index] != ~0);
       return immediateMapping[index];
 
    default:
@@ -242,14 +244,6 @@ compile_instruction(
          immediateMapping,
          indirectAccess );
 
-      /**
-       * This not at all the correct solution.
-       * FIXME: Roll this up in the above map functions
-       */
-      if (fullsrc->SrcRegister.File == TGSI_FILE_IMMEDIATE && fullsrc->SrcRegister.Index == ~0) {
-         fullsrc->SrcRegister.File = TGSI_FILE_CONSTANT;
-         fullsrc->SrcRegister.Index = inst->SrcReg[i].Index;
-      }
 
       /* swizzle (ext swizzle also depends on negation) */
       {