i965/vec4: Make with_writemask() non-static.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm.c
index 39cbbb756ff3473ddec6cc5eea20f74dc83968f0..3df2b7df4ce4df3a004fb71fbcae411ecbde8447 100644 (file)
@@ -140,7 +140,6 @@ bool do_wm_prog(struct brw_context *brw,
                struct brw_fragment_program *fp,
                struct brw_wm_prog_key *key)
 {
-   struct intel_context *intel = &brw->intel;
    struct brw_wm_compile *c;
    const GLuint *program;
    struct gl_shader *fs = NULL;
@@ -184,7 +183,7 @@ bool do_wm_prog(struct brw_context *brw,
 
       c->prog_data.total_scratch = brw_get_scratch_size(c->last_scratch);
 
-      brw_get_scratch_bo(intel, &brw->wm.scratch_bo,
+      brw_get_scratch_bo(brw, &brw->wm.scratch_bo,
                         c->prog_data.total_scratch * brw->max_wm_threads);
    }
 
@@ -203,7 +202,7 @@ bool do_wm_prog(struct brw_context *brw,
 }
 
 static bool
-key_debug(struct intel_context *intel, const char *name, int a, int b)
+key_debug(struct brw_context *brw, const char *name, int a, int b)
 {
    if (a != b) {
       perf_debug("  %s %d->%d\n", name, a, b);
@@ -214,25 +213,25 @@ key_debug(struct intel_context *intel, const char *name, int a, int b)
 }
 
 bool
-brw_debug_recompile_sampler_key(struct intel_context *intel,
+brw_debug_recompile_sampler_key(struct brw_context *brw,
                                 const struct brw_sampler_prog_key_data *old_key,
                                 const struct brw_sampler_prog_key_data *key)
 {
    bool found = false;
 
    for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
-      found |= key_debug(intel, "EXT_texture_swizzle or DEPTH_TEXTURE_MODE",
+      found |= key_debug(brw, "EXT_texture_swizzle or DEPTH_TEXTURE_MODE",
                          old_key->swizzles[i], key->swizzles[i]);
    }
-   found |= key_debug(intel, "GL_CLAMP enabled on any texture unit's 1st coordinate",
+   found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 1st coordinate",
                       old_key->gl_clamp_mask[0], key->gl_clamp_mask[0]);
-   found |= key_debug(intel, "GL_CLAMP enabled on any texture unit's 2nd coordinate",
+   found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 2nd coordinate",
                       old_key->gl_clamp_mask[1], key->gl_clamp_mask[1]);
-   found |= key_debug(intel, "GL_CLAMP enabled on any texture unit's 3rd coordinate",
+   found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 3rd coordinate",
                       old_key->gl_clamp_mask[2], key->gl_clamp_mask[2]);
-   found |= key_debug(intel, "GL_MESA_ycbcr texturing\n",
+   found |= key_debug(brw, "GL_MESA_ycbcr texturing\n",
                       old_key->yuvtex_mask, key->yuvtex_mask);
-   found |= key_debug(intel, "GL_MESA_ycbcr UV swapping\n",
+   found |= key_debug(brw, "GL_MESA_ycbcr UV swapping\n",
                       old_key->yuvtex_swap_mask, key->yuvtex_swap_mask);
 
    return found;
@@ -243,7 +242,6 @@ brw_wm_debug_recompile(struct brw_context *brw,
                        struct gl_shader_program *prog,
                        const struct brw_wm_prog_key *key)
 {
-   struct intel_context *intel = &brw->intel;
    struct brw_cache_item *c = NULL;
    const struct brw_wm_prog_key *old_key = NULL;
    bool found = false;
@@ -268,31 +266,29 @@ brw_wm_debug_recompile(struct brw_context *brw,
       return;
    }
 
-   found |= key_debug(intel, "alphatest, computed depth, depth test, or "
+   found |= key_debug(brw, "alphatest, computed depth, depth test, or "
                       "depth write",
                       old_key->iz_lookup, key->iz_lookup);
-   found |= key_debug(intel, "depth statistics",
+   found |= key_debug(brw, "depth statistics",
                       old_key->stats_wm, key->stats_wm);
-   found |= key_debug(intel, "flat shading",
+   found |= key_debug(brw, "flat shading",
                       old_key->flat_shade, key->flat_shade);
-   found |= key_debug(intel, "number of color buffers",
+   found |= key_debug(brw, "number of color buffers",
                       old_key->nr_color_regions, key->nr_color_regions);
-   found |= key_debug(intel, "sample alpha to coverage",
-                      old_key->sample_alpha_to_coverage, key->sample_alpha_to_coverage);
-   found |= key_debug(intel, "rendering to FBO",
+   found |= key_debug(brw, "MRT alpha test or alpha-to-coverage",
+                      old_key->replicate_alpha, key->replicate_alpha);
+   found |= key_debug(brw, "rendering to FBO",
                       old_key->render_to_fbo, key->render_to_fbo);
-   found |= key_debug(intel, "fragment color clamping",
+   found |= key_debug(brw, "fragment color clamping",
                       old_key->clamp_fragment_color, key->clamp_fragment_color);
-   found |= key_debug(intel, "line smoothing",
+   found |= key_debug(brw, "line smoothing",
                       old_key->line_aa, key->line_aa);
-   found |= key_debug(intel, "proj_attrib_mask",
-                      old_key->proj_attrib_mask, key->proj_attrib_mask);
-   found |= key_debug(intel, "renderbuffer height",
+   found |= key_debug(brw, "renderbuffer height",
                       old_key->drawable_height, key->drawable_height);
-   found |= key_debug(intel, "vertex shader outputs",
-                      old_key->vp_outputs_written, key->vp_outputs_written);
+   found |= key_debug(brw, "input slots valid",
+                      old_key->input_slots_valid, key->input_slots_valid);
 
-   found |= brw_debug_recompile_sampler_key(intel, &old_key->tex, &key->tex);
+   found |= brw_debug_recompile_sampler_key(brw, &old_key->tex, &key->tex);
 
    if (!found) {
       perf_debug("  Something else\n");
@@ -302,11 +298,12 @@ brw_wm_debug_recompile(struct brw_context *brw,
 void
 brw_populate_sampler_prog_key_data(struct gl_context *ctx,
                                   const struct gl_program *prog,
+                                   unsigned sampler_count,
                                   struct brw_sampler_prog_key_data *key)
 {
-   struct intel_context *intel = intel_context(ctx);
+   struct brw_context *brw = brw_context(ctx);
 
-   for (int s = 0; s < MAX_SAMPLERS; s++) {
+   for (int s = 0; s < sampler_count; s++) {
       key->swizzles[s] = SWIZZLE_NOOP;
 
       if (!(prog->SamplersUsed & (1 << s)))
@@ -327,7 +324,7 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
          /* Haswell handles texture swizzling as surface format overrides
           * (except for GL_ALPHA); all other platforms need MOVs in the shader.
           */
-         if (!intel->is_haswell || alpha_depth)
+         if (!brw->is_haswell || alpha_depth)
             key->swizzles[s] = brw_get_texture_swizzle(ctx, t);
 
         if (img->InternalFormat == GL_YCBCR_MESA) {
@@ -352,8 +349,7 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 static void brw_wm_populate_key( struct brw_context *brw,
                                 struct brw_wm_prog_key *key )
 {
-   struct gl_context *ctx = &brw->intel.ctx;
-   struct intel_context *intel = &brw->intel;
+   struct gl_context *ctx = &brw->ctx;
    /* BRW_NEW_FRAGMENT_PROGRAM */
    const struct brw_fragment_program *fp = 
       (struct brw_fragment_program *)brw->fragment_program;
@@ -366,7 +362,7 @@ static void brw_wm_populate_key( struct brw_context *brw,
 
    /* Build the index for table lookup
     */
-   if (intel->gen < 6) {
+   if (brw->gen < 6) {
       /* _NEW_COLOR */
       if (fp->program.UsesKill || ctx->Color.AlphaEnabled)
         lookup |= IZ_PS_KILL_ALPHATEST_BIT;
@@ -381,7 +377,7 @@ static void brw_wm_populate_key( struct brw_context *brw,
       if (ctx->Depth.Test && ctx->Depth.Mask) /* ?? */
         lookup |= IZ_DEPTH_WRITE_ENABLE_BIT;
 
-      /* _NEW_STENCIL */
+      /* _NEW_STENCIL | _NEW_BUFFERS */
       if (ctx->Stencil._Enabled) {
         lookup |= IZ_STENCIL_TEST_ENABLE_BIT;
 
@@ -396,10 +392,10 @@ static void brw_wm_populate_key( struct brw_context *brw,
 
    /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
    if (ctx->Line.SmoothFlag) {
-      if (brw->intel.reduced_primitive == GL_LINES) {
+      if (brw->reduced_primitive == GL_LINES) {
         line_aa = AA_ALWAYS;
       }
-      else if (brw->intel.reduced_primitive == GL_TRIANGLES) {
+      else if (brw->reduced_primitive == GL_TRIANGLES) {
         if (ctx->Polygon.FrontMode == GL_LINE) {
            line_aa = AA_SOMETIMES;
 
@@ -420,17 +416,8 @@ static void brw_wm_populate_key( struct brw_context *brw,
 
    key->line_aa = line_aa;
 
-   if (intel->gen < 6)
-      key->stats_wm = brw->intel.stats_wm;
-
-   /* BRW_NEW_WM_INPUT_DIMENSIONS */
-   /* Only set this for fixed function.  The optimization it enables isn't
-    * useful for programs using shaders.
-    */
-   if (ctx->Shader.CurrentFragmentProgram)
-      key->proj_attrib_mask = ~(GLbitfield64) 0;
-   else
-      key->proj_attrib_mask = brw->wm.input_size_masks[4-1];
+   if (brw->gen < 6)
+      key->stats_wm = brw->stats_wm;
 
    /* _NEW_LIGHT */
    key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT);
@@ -439,7 +426,8 @@ static void brw_wm_populate_key( struct brw_context *brw,
    key->clamp_fragment_color = ctx->Color._ClampFragmentColor;
 
    /* _NEW_TEXTURE */
-   brw_populate_sampler_prog_key_data(ctx, prog, &key->tex);
+   brw_populate_sampler_prog_key_data(ctx, prog, brw->wm.sampler_count,
+                                      &key->tex);
 
    /* _NEW_BUFFERS */
    /*
@@ -472,12 +460,14 @@ static void brw_wm_populate_key( struct brw_context *brw,
 
    /* _NEW_BUFFERS */
    key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers;
-  /* _NEW_MULTISAMPLE */
-   key->sample_alpha_to_coverage = ctx->Multisample.SampleAlphaToCoverage;
 
-   /* CACHE_NEW_VS_PROG */
-   if (intel->gen < 6)
-      key->vp_outputs_written = brw->vs.prog_data->outputs_written;
+   /* _NEW_MULTISAMPLE, _NEW_COLOR, _NEW_BUFFERS */
+   key->replicate_alpha = ctx->DrawBuffer->_NumColorDrawBuffers > 1 &&
+      (ctx->Multisample.SampleAlphaToCoverage || ctx->Color.AlphaEnabled);
+
+   /* BRW_NEW_VUE_MAP_GEOM_OUT */
+   if (brw->gen < 6)
+      key->input_slots_valid = brw->vue_map_geom_out.slots_valid;
 
    /* The unique fragment program ID */
    key->program_string_id = fp->id;
@@ -487,8 +477,7 @@ static void brw_wm_populate_key( struct brw_context *brw,
 static void
 brw_upload_wm_prog(struct brw_context *brw)
 {
-   struct intel_context *intel = &brw->intel;
-   struct gl_context *ctx = &intel->ctx;
+   struct gl_context *ctx = &brw->ctx;
    struct brw_wm_prog_key key;
    struct brw_fragment_program *fp = (struct brw_fragment_program *)
       brw->fragment_program;
@@ -519,9 +508,9 @@ const struct brw_tracked_state brw_wm_prog = {
                _NEW_TEXTURE |
                _NEW_MULTISAMPLE),
       .brw   = (BRW_NEW_FRAGMENT_PROGRAM |
-               BRW_NEW_WM_INPUT_DIMENSIONS |
-               BRW_NEW_REDUCED_PRIMITIVE),
-      .cache = CACHE_NEW_VS_PROG,
+               BRW_NEW_REDUCED_PRIMITIVE |
+                BRW_NEW_VUE_MAP_GEOM_OUT |
+                BRW_NEW_STATS_WM)
    },
    .emit = brw_upload_wm_prog
 };