i965: Make the old VS backend record pull constant references in pull_params[].
[mesa.git] / src / mesa / drivers / dri / i965 / brw_gs.c
index f213ae20acd3d7d2bc33e3d55adb844d733499e3..f4656af13eb96ac5011f81dcece24fac25853de7 100644 (file)
@@ -42,7 +42,7 @@
 #include "brw_state.h"
 #include "brw_gs.h"
 
-
+#include "glsl/ralloc.h"
 
 static void compile_gs_prog( struct brw_context *brw,
                             struct brw_gs_prog_key *key )
@@ -50,8 +50,15 @@ static void compile_gs_prog( struct brw_context *brw,
    struct intel_context *intel = &brw->intel;
    struct brw_gs_compile c;
    const GLuint *program;
+   void *mem_ctx;
    GLuint program_size;
 
+   /* Gen6: VF has already converted into polygon, and LINELOOP is
+    * converted to LINESTRIP at the beginning of the 3D pipeline.
+    */
+   if (intel->gen >= 6)
+      return;
+
    memset(&c, 0, sizeof(c));
    
    c.key = *key;
@@ -67,10 +74,11 @@ static void compile_gs_prog( struct brw_context *brw,
 
    c.nr_bytes = c.nr_regs * REG_SIZE;
 
+   mem_ctx = NULL;
    
    /* Begin the compilation:
     */
-   brw_init_compile(brw, &c.func);
+   brw_init_compile(brw, &c.func, mem_ctx);
 
    c.func.single_program_flow = 1;
 
@@ -84,12 +92,6 @@ static void compile_gs_prog( struct brw_context *brw,
     * already been weeded out by this stage:
     */
 
-   /* Gen6: VF has already converted into polygon, and LINELOOP is
-    * converted to LINESTRIP at the beginning of the 3D pipeline.
-    */
-   if (intel->gen == 6)
-      return;
-
    switch (key->primitive) {
    case GL_QUADS:
       brw_gs_quads( &c, key );
@@ -101,6 +103,7 @@ static void compile_gs_prog( struct brw_context *brw,
       brw_gs_lines( &c );
       break;
    default:
+      ralloc_free(mem_ctx);
       return;
    }
 
@@ -118,14 +121,12 @@ static void compile_gs_prog( struct brw_context *brw,
       printf("\n");
     }
 
-   /* Upload
-    */
-   drm_intel_bo_unreference(brw->gs.prog_bo);
-   brw->gs.prog_bo = brw_upload_cache(&brw->cache, BRW_GS_PROG,
-                                     &c.key, sizeof(c.key),
-                                     program, program_size,
-                                     &c.prog_data, sizeof(c.prog_data),
-                                     &brw->gs.prog_data);
+   brw_upload_cache(&brw->cache, BRW_GS_PROG,
+                   &c.key, sizeof(c.key),
+                   program, program_size,
+                   &c.prog_data, sizeof(c.prog_data),
+                   &brw->gs.prog_offset, &brw->gs.prog_data);
+   ralloc_free(mem_ctx);
 }
 
 static const GLenum gs_prim[GL_POLYGON+1] = {  
@@ -164,7 +165,7 @@ static void populate_key( struct brw_context *brw,
       key->pv_first = GL_TRUE;
    }
 
-   key->need_gs_prog = (intel->gen == 6)
+   key->need_gs_prog = (intel->gen >= 6)
       ? 0
       : (brw->primitive == GL_QUADS ||
         brw->primitive == GL_QUAD_STRIP ||
@@ -185,15 +186,12 @@ static void prepare_gs_prog(struct brw_context *brw)
       brw->gs.prog_active = key.need_gs_prog;
    }
 
-   drm_intel_bo_unreference(brw->gs.prog_bo);
-   brw->gs.prog_bo = NULL;
-
    if (brw->gs.prog_active) {
-      brw->gs.prog_bo = brw_search_cache(&brw->cache, BRW_GS_PROG,
-                                        &key, sizeof(key),
-                                        &brw->gs.prog_data);
-      if (brw->gs.prog_bo == NULL)
+      if (!brw_search_cache(&brw->cache, BRW_GS_PROG,
+                           &key, sizeof(key),
+                           &brw->gs.prog_offset, &brw->gs.prog_data)) {
         compile_gs_prog( brw, &key );
+      }
    }
 }