i965/fs: Disable CSE optimization for untyped & typed surface reads
[mesa.git] / src / mesa / drivers / dri / i965 / brw_sf_state.c
index 2fecd1eaeb3cf923dac636963179c5eda6e2d611..b126f82ebbff0d62e04988ca8242f248e46bfbbc 100644 (file)
@@ -34,6 +34,7 @@
 #include "main/mtypes.h"
 #include "main/macros.h"
 #include "main/fbobject.h"
+#include "main/viewport.h"
 #include "brw_context.h"
 #include "brw_state.h"
 #include "brw_defines.h"
 static void upload_sf_vp(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
-   const GLfloat depth_scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
    struct brw_sf_viewport *sfv;
    GLfloat y_scale, y_bias;
+   float scale[3], translate[3];
    const bool render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer);
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
 
    sfv = brw_state_batch(brw, AUB_TRACE_SF_VP_STATE,
                         sizeof(*sfv), 32, &brw->sf.vp_offset);
    memset(sfv, 0, sizeof(*sfv));
 
+   /* Accessing the fields Width and Height of gl_framebuffer to produce the
+    * values to program the viewport and scissor is fine as long as the
+    * gl_framebuffer has atleast one attachment.
+    */
+   assert(ctx->DrawBuffer->_HasAttachments);
+
    if (render_to_fbo) {
       y_scale = 1.0;
       y_bias = 0;
@@ -63,12 +69,13 @@ static void upload_sf_vp(struct brw_context *brw)
 
    /* _NEW_VIEWPORT */
 
-   sfv->viewport.m00 = v[MAT_SX];
-   sfv->viewport.m11 = v[MAT_SY] * y_scale;
-   sfv->viewport.m22 = v[MAT_SZ] * depth_scale;
-   sfv->viewport.m30 = v[MAT_TX];
-   sfv->viewport.m31 = v[MAT_TY] * y_scale + y_bias;
-   sfv->viewport.m32 = v[MAT_TZ] * depth_scale;
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   sfv->viewport.m00 = scale[0];
+   sfv->viewport.m11 = scale[1] * y_scale;
+   sfv->viewport.m22 = scale[2];
+   sfv->viewport.m30 = translate[0];
+   sfv->viewport.m31 = translate[1] * y_scale + y_bias;
+   sfv->viewport.m32 = translate[2];
 
    /* _NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT
     * for DrawBuffer->_[XY]{min,max}
@@ -109,16 +116,15 @@ static void upload_sf_vp(struct brw_context *brw)
       sfv->scissor.ymax = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin - 1;
    }
 
-   brw->state.dirty.cache |= CACHE_NEW_SF_VP;
+   brw->ctx.NewDriverState |= BRW_NEW_SF_VP;
 }
 
 const struct brw_tracked_state brw_sf_vp = {
    .dirty = {
-      .mesa  = (_NEW_VIEWPORT |
-               _NEW_SCISSOR |
-               _NEW_BUFFERS),
+      .mesa  = _NEW_BUFFERS |
+               _NEW_SCISSOR |
+               _NEW_VIEWPORT,
       .brw   = BRW_NEW_BATCH,
-      .cache = 0
    },
    .emit = upload_sf_vp
 };
@@ -136,7 +142,7 @@ static void upload_sf_unit( struct brw_context *brw )
 
    memset(sf, 0, sizeof(*sf));
 
-   /* BRW_NEW_PROGRAM_CACHE | CACHE_NEW_SF_PROG */
+   /* BRW_NEW_PROGRAM_CACHE | BRW_NEW_SF_PROG_DATA */
    sf->thread0.grf_reg_count = ALIGN(brw->sf.prog_data->total_grf, 16) / 16 - 1;
    sf->thread0.kernel_start_pointer =
       brw_program_reloc(brw,
@@ -150,7 +156,7 @@ static void upload_sf_unit( struct brw_context *brw )
    sf->thread3.dispatch_grf_start_reg = 3;
    sf->thread3.urb_entry_read_offset = BRW_SF_URB_ENTRY_READ_OFFSET;
 
-   /* CACHE_NEW_SF_PROG */
+   /* BRW_NEW_SF_PROG_DATA */
    sf->thread3.urb_entry_read_length = brw->sf.prog_data->urb_read_length;
 
    /* BRW_NEW_URB_FENCE */
@@ -172,7 +178,7 @@ static void upload_sf_unit( struct brw_context *brw )
    if (unlikely(INTEL_DEBUG & DEBUG_STATS))
       sf->thread4.stats_enable = 1;
 
-   /* CACHE_NEW_SF_VP */
+   /* BRW_NEW_SF_VP */
    sf->sf5.sf_viewport_state_offset = (brw->batch.bo->offset64 +
                                       brw->sf.vp_offset) >> 5; /* reloc */
 
@@ -183,10 +189,10 @@ static void upload_sf_unit( struct brw_context *brw )
       sf->sf6.scissor = 1;
 
    /* _NEW_POLYGON */
-   if (ctx->Polygon.FrontFace == GL_CCW)
-      sf->sf5.front_winding = BRW_FRONTWINDING_CCW;
-   else
+   if (ctx->Polygon._FrontBit)
       sf->sf5.front_winding = BRW_FRONTWINDING_CW;
+   else
+      sf->sf5.front_winding = BRW_FRONTWINDING_CCW;
 
    /* _NEW_BUFFERS
     * The viewport is inverted for rendering to a FBO, and that inverts
@@ -214,7 +220,7 @@ static void upload_sf_unit( struct brw_context *brw )
 
    /* _NEW_LINE */
    sf->sf6.line_width =
-      CLAMP(ctx->Line.Width, 1.0, ctx->Const.MaxLineWidth) * (1<<1);
+      CLAMP(ctx->Line.Width, 1.0f, ctx->Const.MaxLineWidth) * (1<<1);
 
    sf->sf6.line_endcap_aa_region_width = 1;
    if (ctx->Line.SmoothFlag)
@@ -253,9 +259,10 @@ static void upload_sf_unit( struct brw_context *brw )
 
    /* _NEW_POINT */
    sf->sf7.sprite_point = ctx->Point.PointSprite;
-   sf->sf7.point_size = CLAMP(rint(CLAMP(ctx->Point.Size,
-                                        ctx->Point.MinSize,
-                                        ctx->Point.MaxSize)), 1, 255) * (1<<3);
+   sf->sf7.point_size = CLAMP(rintf(CLAMP(ctx->Point.Size,
+                                          ctx->Point.MinSize,
+                                          ctx->Point.MaxSize)), 1.0f, 255.0f) *
+                        (1<<3);
    /* _NEW_PROGRAM | _NEW_POINT */
    sf->sf7.use_point_size_state = !(ctx->VertexProgram.PointSizeEnabled ||
                                    ctx->Point._Attenuated);
@@ -292,23 +299,23 @@ static void upload_sf_unit( struct brw_context *brw )
                                             (sf->sf5.viewport_transform << 1)),
                           I915_GEM_DOMAIN_INSTRUCTION, 0);
 
-   brw->state.dirty.cache |= CACHE_NEW_SF_UNIT;
+   brw->ctx.NewDriverState |= BRW_NEW_GEN4_UNIT_STATE;
 }
 
 const struct brw_tracked_state brw_sf_unit = {
    .dirty = {
-      .mesa  = (_NEW_POLYGON |
-               _NEW_PROGRAM |
-               _NEW_LIGHT |
-               _NEW_LINE |
-               _NEW_POINT |
-               _NEW_SCISSOR |
-               _NEW_BUFFERS),
-      .brw   = (BRW_NEW_BATCH |
-               BRW_NEW_PROGRAM_CACHE |
-               BRW_NEW_URB_FENCE),
-      .cache = (CACHE_NEW_SF_VP |
-               CACHE_NEW_SF_PROG)
+      .mesa  = _NEW_BUFFERS |
+               _NEW_LIGHT |
+               _NEW_LINE |
+               _NEW_POINT |
+               _NEW_POLYGON |
+               _NEW_PROGRAM |
+               _NEW_SCISSOR,
+      .brw   = BRW_NEW_BATCH |
+               BRW_NEW_PROGRAM_CACHE |
+               BRW_NEW_SF_PROG_DATA |
+               BRW_NEW_SF_VP |
+               BRW_NEW_URB_FENCE,
    },
    .emit = upload_sf_unit,
 };