i965g: fragment shader immediates working
authorKeith Whitwell <keithw@vmware.com>
Fri, 20 Nov 2009 04:02:42 +0000 (20:02 -0800)
committerKeith Whitwell <keithw@vmware.com>
Fri, 20 Nov 2009 04:02:42 +0000 (20:02 -0800)
src/gallium/drivers/i965/brw_curbe.c
src/gallium/drivers/i965/brw_wm.h
src/gallium/drivers/i965/brw_wm_pass0.c

index 3e821d5afeedf12a81880f6e738c982904835c2d..3f031577d5ac7a028817cb5cd788b65d35fd713e 100644 (file)
@@ -182,16 +182,32 @@ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw)
 
    /* fragment shader constants */
    if (brw->curbe.wm_size) {
+      const struct brw_fragment_shader *fs = brw->curr.fragment_shader;
       GLuint offset = brw->curbe.wm_start * 16;
-      unsigned nr = brw->wm.prog_data->nr_params;
+      GLuint nr_immediate, nr_const;
+
+      nr_immediate = fs->immediates.nr;
+      if (nr_immediate) {
+         memcpy(&buf[offset], 
+                fs->immediates.data,
+                nr_immediate * 4 * sizeof(float));
 
-      const GLfloat *value = screen->buffer_map( screen,
-                                                brw->curr.fragment_constants,
-                                                PIPE_BUFFER_USAGE_CPU_READ);
+         offset += nr_immediate * 4;
+      }
 
-      memcpy(&buf[offset], value, nr * 4 * sizeof(float));
+      nr_const = fs->info.file_max[TGSI_FILE_CONSTANT] + 1;
+/*      nr_const = brw->wm.prog_data->nr_params; */
+      if (nr_const) {
+         const GLfloat *value = screen->buffer_map( screen,
+                                                    brw->curr.fragment_constants,
+                                                    PIPE_BUFFER_USAGE_CPU_READ);
 
-      screen->buffer_unmap( screen, brw->curr.fragment_constants );
+         memcpy(&buf[offset], value,
+                nr_const * 4 * sizeof(float));
+         
+         screen->buffer_unmap( screen, 
+                               brw->curr.fragment_constants );
+      }
    }
 
 
@@ -226,7 +242,7 @@ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw)
    /* vertex shader constants */
    if (brw->curbe.vs_size) {
       GLuint offset = brw->curbe.vs_start * 16;
-      struct brw_vertex_shader *vs = brw->curr.vertex_shader;
+      const struct brw_vertex_shader *vs = brw->curr.vertex_shader;
       GLuint nr_immediate, nr_const;
 
       nr_immediate = vs->immediates.nr;
index f85a8af878d3c5d6bf6c952afc5cbf19922ff276..b7d807dcb352618d790c44781521c83ca175269b 100644 (file)
@@ -129,12 +129,6 @@ struct brw_wm_ref {
    GLuint insn:24;
 };
 
-struct brw_wm_imm_ref {
-   const struct brw_wm_ref *ref;
-   GLfloat imm1f;
-};
-
-
 struct brw_wm_instruction {
    struct brw_wm_value *dst[4];
    struct brw_wm_ref *src[3][4];
@@ -272,9 +266,6 @@ struct brw_wm_compile {
    struct brw_wm_instruction instruction[BRW_WM_MAX_INSN];
    GLuint nr_insns;
 
-   struct brw_wm_imm_ref imm_ref[BRW_WM_MAX_CONST];
-   GLuint nr_imm_refs;
-
    struct brw_wm_grf pass2_grf[BRW_WM_MAX_GRF/2];
 
    GLuint grf_limit;
index 7bb341e2c2c0c08ba62f203e212c6c3e020863b6..0bacad2b0f088efca3a790a0d6d8214f13351bac 100644 (file)
@@ -30,6 +30,7 @@
   */
 
 #include "util/u_memory.h"
+#include "util/u_math.h"
 
 #include "brw_debug.h"
 #include "brw_wm.h"
@@ -97,9 +98,10 @@ static void pass0_set_fpreg_ref( struct brw_wm_compile *c,
 }
 
 static const struct brw_wm_ref *get_param_ref( struct brw_wm_compile *c, 
-                                              const GLfloat *param_ptr )
+                                              unsigned idx,
+                                               unsigned component)
 {
-   GLuint i = c->prog_data.nr_params++;
+   GLuint i = idx * 4 + component;
    
    if (i >= BRW_WM_MAX_PARAM) {
       debug_printf("%s: out of params\n", __FUNCTION__);
@@ -109,8 +111,7 @@ static const struct brw_wm_ref *get_param_ref( struct brw_wm_compile *c,
    else {
       struct brw_wm_ref *ref = get_ref(c);
 
-      c->prog_data.param[i] = param_ptr;
-      c->nr_creg = (i+16)/16;
+      c->nr_creg = MAX2(c->nr_creg, (i+16)/16);
 
       /* Push the offsets into hw_reg.  These will be added to the
        * real register numbers once one is allocated in pass2.
@@ -125,37 +126,6 @@ static const struct brw_wm_ref *get_param_ref( struct brw_wm_compile *c,
 }
 
 
-/** Return a ref to an immediate value */
-static const struct brw_wm_ref *get_imm_ref( struct brw_wm_compile *c,
-                                            const GLfloat *imm1f )
-{
-   GLuint i;
-
-   /* Search for an existing const value matching the request:
-    */
-   for (i = 0; i < c->nr_imm_refs; i++) {
-      if (c->imm_ref[i].imm1f == *imm1f) 
-        return c->imm_ref[i].ref;
-   }
-
-   /* Else try to add a new one:
-    */
-   if (c->nr_imm_refs < Elements(c->imm_ref)) {
-      GLuint i = c->nr_imm_refs++;
-
-      /* An immediate is a special type of parameter:
-       */
-      c->imm_ref[i].imm1f = *imm1f;
-      c->imm_ref[i].ref = get_param_ref(c, imm1f);
-
-      return c->imm_ref[i].ref;
-   }
-   else {
-      debug_printf("%s: out of imm_refs\n", __FUNCTION__);
-      c->prog_data.error = 1;
-      return NULL;
-   }
-}
 
 
 /* Lookup our internal registers
@@ -177,11 +147,15 @@ static const struct brw_wm_ref *pass0_get_reg( struct brw_wm_compile *c,
         break;
 
       case TGSI_FILE_CONSTANT:
-        ref = get_param_ref(c, &c->env_param[idx][component]);
+        ref = get_param_ref(c, 
+                             c->fp->info.immediate_count + idx,
+                             component);
         break;
 
       case TGSI_FILE_IMMEDIATE:
-        ref = get_imm_ref(c, &c->immediate[idx].v[component]);
+        ref = get_param_ref(c, 
+                             idx,
+                             component);
         break;
 
       default: