st/mesa: program struct comments
[mesa.git] / src / mesa / state_tracker / st_atom_constbuf.c
index 5ac81bd4ee27e4ce04612521a5fd4b9abb312a12..f1d08a3e1665e5cdb118eec3c6828193a686e971 100644 (file)
@@ -32,8 +32,8 @@
  */
 
 #include "main/imports.h"
-#include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
+#include "program/prog_parameter.h"
+#include "program/prog_print.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
@@ -44,7 +44,6 @@
 #include "st_atom.h"
 #include "st_atom_constbuf.h"
 #include "st_program.h"
-#include "st_inlines.h"
 
 
 /**
@@ -60,12 +59,18 @@ void st_upload_constants( struct st_context *st,
    struct pipe_resource **cbuf = &st->state.constants[shader_type];
 
    assert(shader_type == PIPE_SHADER_VERTEX ||
-          shader_type == PIPE_SHADER_FRAGMENT);
+          shader_type == PIPE_SHADER_FRAGMENT ||
+          shader_type == PIPE_SHADER_GEOMETRY);
 
    /* update constants */
    if (params && params->NumParameters) {
       const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
 
+      /* Update the constants which come from fixed-function state, such as
+       * transformation matrices, fog factors, etc.  The rest of the values in
+       * the parameters list are explicitly set by the user with glUniform,
+       * glProgramParameter(), etc.
+       */
       _mesa_load_state_parameters(st->ctx, params);
 
       /* We always need to get a new buffer, to keep the drivers simple and
@@ -84,15 +89,17 @@ void st_upload_constants( struct st_context *st,
       }
 
       /* load Mesa constants into the constant buffer */
-      if (cbuf)
-         st_no_flush_pipe_buffer_write(st, *cbuf,
-                                      0, paramBytes,
-                                      params->ParameterValues);
+      pipe_buffer_write(st->pipe, *cbuf,
+                                   0, paramBytes,
+                                   params->ParameterValues);
 
       st->pipe->set_constant_buffer(st->pipe, shader_type, 0, *cbuf);
    }
-   else {
+   else if (*cbuf) {
       st->constants.tracked_state[shader_type].dirty.mesa = 0x0;
+
+      pipe_resource_reference(cbuf, NULL);
+      st->pipe->set_constant_buffer(st->pipe, shader_type, 0, NULL);
    }
 }
 
@@ -141,3 +148,24 @@ const struct st_tracked_state st_update_fs_constants = {
    update_fs_constants                                 /* update */
 };
 
+/* Geometry shader:
+ */
+static void update_gs_constants(struct st_context *st )
+{
+   struct st_geometry_program *gp = st->gp;
+   struct gl_program_parameter_list *params;
+
+   if (gp) {
+      params = gp->Base.Base.Parameters;
+      st_upload_constants( st, params, PIPE_SHADER_GEOMETRY );
+   }
+}
+
+const struct st_tracked_state st_update_gs_constants = {
+   "st_update_gs_constants",                           /* name */
+   {                                                   /* dirty */
+      (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS),          /* mesa */
+      ST_NEW_GEOMETRY_PROGRAM,                         /* st */
+   },
+   update_gs_constants                                 /* update */
+};