i965: re-org of some of the new constant buffer code
authorBrian Paul <brianp@vmware.com>
Fri, 10 Apr 2009 00:37:03 +0000 (18:37 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 10 Apr 2009 00:37:03 +0000 (18:37 -0600)
Plus, begin the new code for vertex shader const buffers.

src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_curbe.c
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c

index c6e15c89148f6d37bdcce083e6d2b5170fd2e4da..6a9252d0375ebcf691b0b8749a44c845e48b82b4 100644 (file)
@@ -159,6 +159,7 @@ struct brw_state_flags {
 struct brw_vertex_program {
    struct gl_vertex_program program;
    GLuint id;
+   dri_bo *const_buffer;    /** Program constant buffer/surface */
 };
 
 
@@ -168,8 +169,7 @@ struct brw_fragment_program {
    GLuint id;  /**< serial no. to identify frag progs, never re-used */
    GLboolean isGLSL;  /**< really, any IF/LOOP/CONT/BREAK instructions */
 
-   /** Program constant buffer/surface */
-   dri_bo *const_buffer;
+   dri_bo *const_buffer;    /** Program constant buffer/surface */
 };
 
 
index a6bfb7507e77b722c86b3744030258ec15343e4f..08b602a5abee86116b4c6dd2621f36d2e3808e5c 100644 (file)
@@ -333,37 +333,55 @@ static void prepare_constant_buffer(struct brw_context *brw)
 
 
 /**
- * Vertex/fragment shader constants are stored in a pseudo 1D texture.
- * This function updates the constants in that buffer.
+ * Copy Mesa program parameters into given constant buffer.
  */
 static void
-update_texture_constant_buffer(struct brw_context *brw)
+update_constant_buffer(struct brw_context *brw,
+                       const struct gl_program_parameter_list *params,
+                       dri_bo *const_buffer)
 {
-   struct brw_fragment_program *fp =
-      (struct brw_fragment_program *) brw->fragment_program;
-   const struct gl_program_parameter_list *params = fp->program.Base.Parameters;
    const int size = params->NumParameters * 4 * sizeof(GLfloat);
 
-   assert(fp->const_buffer);
-   assert(fp->const_buffer->size >= size);
-
-   /* copy constants into the buffer */
+   /* copy Mesa program constants into the buffer */
    if (size > 0) {
       GLubyte *map;
-      dri_bo_map(fp->const_buffer, GL_TRUE);
-      map = fp->const_buffer->virtual;
+
+      assert(const_buffer);
+      assert(const_buffer->size >= size);
+
+      dri_bo_map(const_buffer, GL_TRUE);
+      map = const_buffer->virtual;
       memcpy(map, params->ParameterValues, size);
-      dri_bo_unmap(fp->const_buffer);
+      dri_bo_unmap(const_buffer);
    }
 }
 
 
+static void
+update_vertex_constant_buffer(struct brw_context *brw)
+{
+   struct brw_vertex_program *vp =
+      (struct brw_vertex_program *) brw->vertex_program;
+   update_constant_buffer(brw, vp->program.Base.Parameters, vp->const_buffer);
+}
+
+
+static void
+update_fragment_constant_buffer(struct brw_context *brw)
+{
+   struct brw_fragment_program *fp =
+      (struct brw_fragment_program *) brw->fragment_program;
+   update_constant_buffer(brw, fp->program.Base.Parameters, fp->const_buffer);
+}
+
+
 static void emit_constant_buffer(struct brw_context *brw)
 {
    struct intel_context *intel = &brw->intel;
    GLuint sz = brw->curbe.total_size;
 
-   update_texture_constant_buffer(brw);
+   update_vertex_constant_buffer(brw);
+   update_fragment_constant_buffer(brw);
 
    BEGIN_BATCH(2, IGNORE_CLIPRECTS);
    if (sz == 0) {
index fbf1ddd1e3ecf617941bb48048223e2e7a187952..cc65157259de62191edd6d70110168d93f913728 100644 (file)
@@ -134,24 +134,6 @@ static void brwProgramStringNotify( GLcontext *ctx,
         brw->state.dirty.brw |= BRW_NEW_FRAGMENT_PROGRAM;
       newFP->id = brw->program_id++;      
       newFP->isGLSL = brw_wm_is_glsl(fprog);
-
-      /* alloc constant buffer/surface */
-      {
-         const struct gl_program_parameter_list *params = prog->Parameters;
-         const int size = params->NumParameters * 4 * sizeof(GLfloat);
-
-         /* free old const buffer if too small */
-         if (newFP->const_buffer && newFP->const_buffer->size < size) {
-            dri_bo_unreference(newFP->const_buffer);
-            newFP->const_buffer = NULL;
-         }
-
-         if (!newFP->const_buffer) {
-            newFP->const_buffer = drm_intel_bo_alloc(intel->bufmgr,
-                                                     "fp_const_buffer",
-                                                     size, 64);
-         }
-      }
    }
    else if (target == GL_VERTEX_PROGRAM_ARB) {
       struct gl_vertex_program *vprog = (struct gl_vertex_program *) prog;
index 0fb2bdacef31ee752b23da426d4f650476ea33b2..40d6c38f4fa91a6bcd99f03a79f54da8e410d228 100644 (file)
@@ -379,26 +379,40 @@ brw_create_constant_surface( struct brw_context *brw,
 
 
 /**
- * Update the constant buffer surface.
+ * Update the surface state for a constant buffer.
+ * The constant buffer will be (re)allocated here if needed.
  */
-static void
+static dri_bo *
 brw_update_constant_surface( GLcontext *ctx,
-                             const struct brw_fragment_program *fp )
+                             GLuint surf,
+                             dri_bo *const_buffer,
+                             const struct gl_program_parameter_list *params)
 {
    struct brw_context *brw = brw_context(ctx);
    struct brw_wm_surface_key key;
-   const GLuint surf = SURF_INDEX_FRAG_CONST_BUFFER;
-   const GLuint numParams = fp->program.Base.Parameters->NumParameters;
+   struct intel_context *intel = &brw->intel;
+   const int size = params->NumParameters * 4 * sizeof(GLfloat);
+
+   /* free old const buffer if too small */
+   if (const_buffer && const_buffer->size < size) {
+      dri_bo_unreference(const_buffer);
+      const_buffer = NULL;
+   }
+
+   /* alloc new buffer if needed */
+   if (!const_buffer) {
+      const_buffer =
+         drm_intel_bo_alloc(intel->bufmgr, "vp/fp_const_buffer", size, 64);
+   }
 
    memset(&key, 0, sizeof(key));
 
    key.format = MESA_FORMAT_RGBA_FLOAT32;
    key.internal_format = GL_RGBA;
-   key.bo = fp->const_buffer;
-
+   key.bo = const_buffer;
    key.depthmode = GL_NONE;
-   key.pitch = numParams;
-   key.width = numParams;
+   key.pitch = params->NumParameters;
+   key.width = params->NumParameters;
    key.height = 1;
    key.depth = 1;
    key.cpp = 16;
@@ -417,6 +431,8 @@ brw_update_constant_surface( GLcontext *ctx,
    if (brw->wm.surf_bo[surf] == NULL) {
       brw->wm.surf_bo[surf] = brw_create_constant_surface(brw, &key);
    }
+
+   return const_buffer;
 }
 
 
@@ -587,16 +603,33 @@ static void prepare_wm_surfaces(struct brw_context *brw )
    old_nr_surfaces = brw->wm.nr_surfaces;
    brw->wm.nr_surfaces = MAX_DRAW_BUFFERS;
 
-   /* Update surface for fragment shader constant buffer */
+   /* Update surface / buffer for vertex shader constant buffer */
    {
-      const GLuint surf = SURF_INDEX_FRAG_CONST_BUFFER + 1;
-      const struct brw_fragment_program *fp =
-         brw_fragment_program_const(brw->fragment_program);
+      const GLuint surf = SURF_INDEX_VERT_CONST_BUFFER + 1;
+      struct brw_vertex_program *vp =
+         (struct brw_vertex_program *) brw->vertex_program;
+      vp->const_buffer =
+         brw_update_constant_surface(ctx,
+                                     SURF_INDEX_VERT_CONST_BUFFER,
+                                     vp->const_buffer,
+                                     vp->program.Base.Parameters);
 
-      brw_update_constant_surface(ctx, fp);
       brw->wm.nr_surfaces = surf + 1;
    }
 
+   /* Update surface / buffer for fragment shader constant buffer */
+   {
+      const GLuint surf = SURF_INDEX_FRAG_CONST_BUFFER + 1;
+      struct brw_fragment_program *fp =
+         (struct brw_fragment_program *) brw->fragment_program;
+      fp->const_buffer =
+         brw_update_constant_surface(ctx,
+                                     SURF_INDEX_FRAG_CONST_BUFFER,
+                                     fp->const_buffer,
+                                     fp->program.Base.Parameters);
+
+      brw->wm.nr_surfaces = surf + 1;
+   }
 
    /* Update surfaces for textures */
    for (i = 0; i < BRW_MAX_TEX_UNIT; i++) {