Move the fp_machine struct into s_nvfragmprog.c since (except for program
authorBrian Paul <brian.paul@tungstengraphics.com>
Tue, 10 Oct 2006 21:43:31 +0000 (21:43 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Tue, 10 Oct 2006 21:43:31 +0000 (21:43 +0000)
debug) it's only used there.

src/mesa/drivers/common/driverfuncs.c
src/mesa/main/dd.h
src/mesa/main/mtypes.h
src/mesa/shader/program.c
src/mesa/swrast/s_nvfragprog.c
src/mesa/swrast/swrast.h

index 3ccbe54817a4e3c8bc7f802624958398c5aba652..1e44904b930a450ab5e6834320c9014543f0b7e7 100644 (file)
@@ -126,6 +126,9 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->BindProgram = NULL;
    driver->NewProgram = _mesa_new_program;
    driver->DeleteProgram = _mesa_delete_program;
+#if FEATURE_MESA_program_debug
+   driver->GetFragmentProgramRegister = _swrast_get_program_register;
+#endif /* FEATURE_MESA_program_debug */
 
    /* simple state commands */
    driver->AlphaFunc = NULL;
index 1b8cf6304e56a32eb54743dd77d5b4ba72759a60..26cabc90963b07c7f4f5b2f8a2424724a7b3bb21 100644 (file)
@@ -591,8 +591,9 @@ struct dd_function_table {
    /** Notify driver that a program string has been specified. */
    void (*ProgramStringNotify)(GLcontext *ctx, GLenum target, 
                               struct gl_program *prog);
-   
-
+   /** Get value of a fragment program register during program execution. */
+   void (*GetFragmentProgramRegister)(GLcontext *ctx, enum register_file file,
+                                      GLuint index, GLfloat val[4]);
 
    /** Query if program can be loaded onto hardware */
    GLboolean (*IsProgramNative)(GLcontext *ctx, GLenum target, 
index 2bb6d93c39055e9964f87c1f1209f27d5c8d8291..ff6b053c2305edc39421987a60d13d811d0de4b8 100644 (file)
@@ -1808,18 +1808,6 @@ struct gl_evaluators
 };
 
 
-/**
- * State used during execution of fragment programs.
- */
-struct fp_machine
-{
-   GLfloat Temporaries[MAX_NV_FRAGMENT_PROGRAM_TEMPS][4];
-   GLfloat Inputs[MAX_NV_FRAGMENT_PROGRAM_INPUTS][4];
-   GLfloat Outputs[MAX_NV_FRAGMENT_PROGRAM_OUTPUTS][4];
-   GLuint CondCodes[4];
-};
-
-
 /**
  * Names of the various vertex/fragment program register files, etc.
  * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
@@ -1963,14 +1951,13 @@ struct gl_vertex_program_state
  */
 struct gl_fragment_program_state
 {
-   GLboolean Enabled;                    /* GL_VERTEX_PROGRAM_NV */
-   GLboolean _Enabled;                   /* Enabled and valid program? */
-   GLboolean _Active;
-   struct gl_fragment_program *Current;  /* ptr to currently bound program */
-   const struct gl_fragment_program *_Current; /* ptr to currently active program 
+   GLboolean Enabled;     /**< User-set fragment program enable flag */
+   GLboolean _Enabled;    /**< Fragment program enabled and valid? */
+   GLboolean _Active;     /**< Is a user program or internal program active? */
+   struct gl_fragment_program *Current;  /**< User-bound program */
+   const struct gl_fragment_program *_Current; /**< currently active program 
                                               (including internal programs) */
-   struct fp_machine Machine;            /* machine state */
-   GLfloat Parameters[MAX_NV_FRAGMENT_PROGRAM_PARAMS][4]; /* Env params */
+   GLfloat Parameters[MAX_NV_FRAGMENT_PROGRAM_PARAMS][4]; /**< Env params */
 
 #if FEATURE_MESA_program_debug
    GLprogramcallbackMESA Callback;
index f999e0695ba54fd87e72a5dabe5b93d7122c2fff..8aed74110c0cba9ce7fb11a78a8690fd2d158599 100644 (file)
@@ -2163,7 +2163,8 @@ _mesa_GetProgramRegisterfvMESA(GLenum target,
                            "glGetProgramRegisterfvMESA(registerName)");
                return;
             }
-            COPY_4V(v, ctx->FragmentProgram.Machine.Temporaries[i]);
+            ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_TEMPORARY,
+                                                   i, v);
          }
          else if (reg[0] == 'f' && reg[1] == '[') {
             /* Fragment input attribute */
@@ -2171,7 +2172,8 @@ _mesa_GetProgramRegisterfvMESA(GLenum target,
             for (i = 0; i < ctx->Const.FragmentProgram.MaxAttribs; i++) {
                const char *name = _mesa_nv_fragment_input_register_name(i);
                if (_mesa_strncmp(reg + 2, name, 4) == 0) {
-                  COPY_4V(v, ctx->FragmentProgram.Machine.Inputs[i]);
+                  ctx->Driver.GetFragmentProgramRegister(ctx,
+                                                         PROGRAM_INPUT, i, v);
                   return;
                }
             }
@@ -2181,15 +2183,18 @@ _mesa_GetProgramRegisterfvMESA(GLenum target,
          }
          else if (_mesa_strcmp(reg, "o[COLR]") == 0) {
             /* Fragment output color */
-            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_RESULT_COLR]);
+            ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT,
+                                                   FRAG_RESULT_COLR, v);
          }
          else if (_mesa_strcmp(reg, "o[COLH]") == 0) {
             /* Fragment output color */
-            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_RESULT_COLH]);
+            ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT,
+                                                   FRAG_RESULT_COLH, v);
          }
          else if (_mesa_strcmp(reg, "o[DEPR]") == 0) {
             /* Fragment output depth */
-            COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_RESULT_DEPR]);
+            ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT,
+                                                   FRAG_RESULT_DEPR, v);
          }
          else {
             /* try user-defined identifiers */
@@ -2210,5 +2215,4 @@ _mesa_GetProgramRegisterfvMESA(GLenum target,
                      "glGetProgramRegisterfvMESA(target)");
          return;
    }
-
 }
index 658b6efe32ddaed0d955d9d4451854e5a0a0db38..d3525320764335ab98702378af19635b9cd5972e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  6.5.2
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
 /* if 1, print some debugging info */
 #define DEBUG_FRAG 0
 
+
+/**
+ * Virtual machine state used during execution of a fragment programs.
+ */
+struct fp_machine
+{
+   GLfloat Temporaries[MAX_NV_FRAGMENT_PROGRAM_TEMPS][4];
+   GLfloat Inputs[MAX_NV_FRAGMENT_PROGRAM_INPUTS][4];
+   GLfloat Outputs[MAX_NV_FRAGMENT_PROGRAM_OUTPUTS][4];
+   GLuint CondCodes[4];
+};
+
+
+#if FEATURE_MESA_program_debug
+static struct fp_machine *CurrentMachine = NULL;
+
+/**
+ * For GL_MESA_program_debug.
+ * Return current value (4*GLfloat) of a fragment program register.
+ * Called via ctx->Driver.GetFragmentProgramRegister().
+ */
+void
+_swrast_get_program_register(GLcontext *ctx, enum register_file file,
+                             GLuint index, GLfloat val[4])
+{
+   if (CurrentMachine) {
+      switch (file) {
+      case PROGRAM_INPUT:
+         COPY_4V(val, CurrentMachine->Inputs[index]);
+         break;
+      case PROGRAM_OUTPUT:
+         COPY_4V(val, CurrentMachine->Outputs[index]);
+         break;
+      case PROGRAM_TEMPORARY:
+         COPY_4V(val, CurrentMachine->Temporaries[index]);
+         break;
+      default:
+         _mesa_problem(NULL,
+                       "bad register file in _swrast_get_program_register");
+      }
+   }
+}
+#endif /* FEATURE_MESA_program_debug */
+
+
 /**
  * Fetch a texel.
  */
@@ -1379,6 +1424,15 @@ execute_program( GLcontext *ctx,
 }
 
 
+/**
+ * Initialize the virtual fragment program machine state prior to running
+ * fragment program on a fragment.  This involves initializing the input
+ * registers, condition codes, etc.
+ * \param machine  the virtual machine state to init
+ * \param program  the fragment program we're about to run
+ * \param span  the span of pixels we'll operate on
+ * \param col  which element (column) of the span we'll operate on
+ */
 static void
 init_machine( GLcontext *ctx, struct fp_machine *machine,
               const struct gl_fragment_program *program,
@@ -1451,37 +1505,30 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
 }
 
 
-
 /**
- * Execute the current fragment program, operating on the given span.
+ * Run fragment program on the pixels in span from 'start' to 'end' - 1.
  */
-void
-_swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
+static void
+run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end)
 {
    const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
+   struct fp_machine machine;
    GLuint i;
 
-   ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */
+   CurrentMachine = &machine;
 
-   if (program->Base.Parameters) {
-      _mesa_load_state_parameters(ctx, program->Base.Parameters);
-   }   
-
-   for (i = 0; i < span->end; i++) {
+   for (i = start; i < end; i++) {
       if (span->array->mask[i]) {
-         init_machine(ctx, &ctx->FragmentProgram.Machine,
-                      ctx->FragmentProgram._Current, span, i);
+         init_machine(ctx, &machine, program, span, i);
 
-         if (!execute_program(ctx, program, ~0,
-                              &ctx->FragmentProgram.Machine, span, i)) {
+         if (!execute_program(ctx, program, ~0, &machine, span, i)) {
             span->array->mask[i] = GL_FALSE;  /* killed fragment */
             span->writeAll = GL_FALSE;
          }
 
          /* Store output registers */
          {
-            const GLfloat *colOut
-               = ctx->FragmentProgram.Machine.Outputs[FRAG_RESULT_COLR];
+            const GLfloat *colOut = machine.Outputs[FRAG_RESULT_COLR];
             UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][RCOMP], colOut[0]);
             UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][GCOMP], colOut[1]);
             UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][BCOMP], colOut[2]);
@@ -1489,8 +1536,7 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
          }
          /* depth value */
          if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) {
-            const GLfloat depth
-               = ctx->FragmentProgram.Machine.Outputs[FRAG_RESULT_DEPR][2];
+            const GLfloat depth = machine.Outputs[FRAG_RESULT_DEPR][2];
             if (depth <= 0.0)
                span->array->z[i] = 0;
             else if (depth >= 1.0)
@@ -1500,6 +1546,26 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
          }
       }
    }
+   CurrentMachine = NULL;
+}
+
+
+/**
+ * Execute the current fragment program for all the fragments
+ * in the given span.
+ */
+void
+_swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
+{
+   const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
+
+   ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */
+
+   if (program->Base.Parameters) {
+      _mesa_load_state_parameters(ctx, program->Base.Parameters);
+   }   
+
+   run_program(ctx, span, 0, span->end);
 
    if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) {
       span->interpMask &= ~SPAN_Z;
index 2a21234253933b61e9d7262ad7c8d7f9731cf1d2..6d384fbec262247ae66346295c4a3530017ba38b 100644 (file)
@@ -255,6 +255,13 @@ extern void
 _swrast_eject_texture_images(GLcontext *ctx);
 
 
+#if FEATURE_MESA_program_debug
+extern void
+_swrast_get_program_register(GLcontext *, enum register_file file,
+                             GLuint index, GLfloat val[4]);
+#endif /* FEATURE_MESA_program_debug */
+
+
 /**
  * The driver interface for the software rasterizer.
  * XXX this may go away.