intel: Add a new "common" library for more code sharing
[mesa.git] / src / mesa / drivers / dri / i965 / brw_clip.c
index 1c54b918d73cf323334a1a732ad3425d37396c63..4c9d5c56c121f03b8f2abc57975ef4903b01bd5f 100644 (file)
@@ -29,7 +29,6 @@
   *   Keith Whitwell <keithw@vmware.com>
   */
 
-#include "main/glheader.h"
 #include "main/macros.h"
 #include "main/enums.h"
 
@@ -42,7 +41,7 @@
 #include "brw_state.h"
 #include "brw_clip.h"
 
-#include "glsl/ralloc.h"
+#include "util/ralloc.h"
 
 #define FRONT_UNFILLED_BIT  0x1
 #define BACK_UNFILLED_BIT   0x2
@@ -55,7 +54,6 @@ static void compile_clip_prog( struct brw_context *brw,
    const GLuint *program;
    void *mem_ctx;
    GLuint program_size;
-   GLuint i;
 
    memset(&c, 0, sizeof(c));
 
@@ -63,7 +61,7 @@ static void compile_clip_prog( struct brw_context *brw,
 
    /* Begin the compilation:
     */
-   brw_init_compile(brw, &c.func, mem_ctx);
+   brw_init_codegen(brw->intelScreen->devinfo, &c.func, mem_ctx);
 
    c.func.single_program_flow = 1;
 
@@ -87,7 +85,7 @@ static void compile_clip_prog( struct brw_context *brw,
    /* For some reason the thread is spawned with only 4 channels
     * unmasked.
     */
-   brw_set_mask_control(&c.func, BRW_MASK_DISABLE);
+   brw_set_default_mask_control(&c.func, BRW_MASK_DISABLE);
 
 
    /* Would ideally have the option of producing a program which could
@@ -107,11 +105,10 @@ static void compile_clip_prog( struct brw_context *brw,
       brw_emit_point_clip( &c );
       break;
    default:
-      assert(0);
-      return;
+      unreachable("not reached");
    }
 
-   brw_compact_instructions(&c.func);
+   brw_compact_instructions(&c.func, 0, 0, NULL);
 
    /* get the program
     */
@@ -119,14 +116,13 @@ static void compile_clip_prog( struct brw_context *brw,
 
    if (unlikely(INTEL_DEBUG & DEBUG_CLIP)) {
       fprintf(stderr, "clip:\n");
-      for (i = 0; i < program_size / sizeof(struct brw_instruction); i++)
-        brw_disasm(stderr, &((struct brw_instruction *)program)[i],
-                   brw->gen, false);
+      brw_disassemble(brw->intelScreen->devinfo, c.func.store,
+                      0, program_size, stderr);
       fprintf(stderr, "\n");
    }
 
    brw_upload_cache(&brw->cache,
-                   BRW_CLIP_PROG,
+                   BRW_CACHE_CLIP_PROG,
                    &c.key, sizeof(c.key),
                    program, program_size,
                    &c.prog_data, sizeof(c.prog_data),
@@ -136,12 +132,23 @@ static void compile_clip_prog( struct brw_context *brw,
 
 /* Calculate interpolants for triangle and line rasterization.
  */
-static void
+void
 brw_upload_clip_prog(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
    struct brw_clip_prog_key key;
 
+   if (!brw_state_dirty(brw,
+                        _NEW_BUFFERS |
+                        _NEW_LIGHT |
+                        _NEW_POLYGON |
+                        _NEW_TRANSFORM,
+                        BRW_NEW_BLORP |
+                        BRW_NEW_INTERPOLATION_MAP |
+                        BRW_NEW_REDUCED_PRIMITIVE |
+                        BRW_NEW_VUE_MAP_GEOM_OUT))
+      return;
+
    memset(&key, 0, sizeof(key));
 
    /* Populate the key:
@@ -226,10 +233,10 @@ brw_upload_clip_prog(struct brw_context *brw)
               /* _NEW_POLYGON, _NEW_BUFFERS */
               key.offset_units = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD * 2;
               key.offset_factor = ctx->Polygon.OffsetFactor * ctx->DrawBuffer->_MRD;
+              key.offset_clamp = ctx->Polygon.OffsetClamp * ctx->DrawBuffer->_MRD;
            }
 
-           switch (ctx->Polygon.FrontFace) {
-           case GL_CCW:
+           if (!ctx->Polygon._FrontBit) {
               key.fill_ccw = fill_front;
               key.fill_cw = fill_back;
               key.offset_ccw = offset_front;
@@ -237,8 +244,7 @@ brw_upload_clip_prog(struct brw_context *brw)
               if (ctx->Light.Model.TwoSide &&
                   key.fill_cw != CLIP_CULL)
                  key.copy_bfc_cw = 1;
-              break;
-           case GL_CW:
+           } else {
               key.fill_cw = fill_front;
               key.fill_ccw = fill_back;
               key.offset_cw = offset_front;
@@ -246,29 +252,14 @@ brw_upload_clip_prog(struct brw_context *brw)
               if (ctx->Light.Model.TwoSide &&
                   key.fill_ccw != CLIP_CULL)
                  key.copy_bfc_ccw = 1;
-              break;
            }
         }
       }
    }
 
-   if (!brw_search_cache(&brw->cache, BRW_CLIP_PROG,
+   if (!brw_search_cache(&brw->cache, BRW_CACHE_CLIP_PROG,
                         &key, sizeof(key),
                         &brw->clip.prog_offset, &brw->clip.prog_data)) {
       compile_clip_prog( brw, &key );
    }
 }
-
-
-const struct brw_tracked_state brw_clip_prog = {
-   .dirty = {
-      .mesa  = (_NEW_LIGHT |
-               _NEW_TRANSFORM |
-               _NEW_POLYGON |
-               _NEW_BUFFERS),
-      .brw   = (BRW_NEW_REDUCED_PRIMITIVE |
-                BRW_NEW_VUE_MAP_GEOM_OUT |
-                BRW_NEW_INTERPOLATION_MAP)
-   },
-   .emit = brw_upload_clip_prog
-};