ilo: add BLT-based blitting methods to ilo_blitter
[mesa.git] / src / gallium / drivers / ilo / ilo_3d_pipeline_gen6.c
index 490883acdc428db2fcc99b4cbfa09b1c49929827..c60fc014005779176350f367853aee837dcd8e85 100644 (file)
@@ -210,7 +210,8 @@ gen6_pipeline_common_base_address(struct ilo_3d_pipeline *p,
                                   struct gen6_pipeline_session *session)
 {
    /* STATE_BASE_ADDRESS */
-   if (session->state_bo_changed || session->instruction_bo_changed) {
+   if (session->state_bo_changed || session->instruction_bo_changed ||
+       session->batch_bo_changed) {
       if (p->dev->gen == ILO_GEN(6))
          gen6_wa_pipe_control_post_sync(p, false);
 
@@ -290,8 +291,8 @@ gen6_pipeline_common_urb(struct ilo_3d_pipeline *p,
        *          VS-generated output data, output URB availability isn't a
        *          factor."
        */
-      if (vs_entry_size < ilo->vertex_elements->num_elements)
-         vs_entry_size = ilo->vertex_elements->num_elements;
+      if (vs_entry_size < ilo->ve->count)
+         vs_entry_size = ilo->ve->count;
 
       gs_entry_size = (gs) ? gs->out.count :
          (vs && vs->stream_output) ? vs_entry_size : 0;
@@ -299,7 +300,7 @@ gen6_pipeline_common_urb(struct ilo_3d_pipeline *p,
       /* in bytes */
       vs_entry_size *= sizeof(float) * 4;
       gs_entry_size *= sizeof(float) * 4;
-      vs_total_size = ilo->urb.size * 1024;
+      vs_total_size = ilo->dev->urb_size;
 
       if (gs_active) {
          vs_total_size /= 2;
@@ -396,21 +397,21 @@ gen6_pipeline_vf(struct ilo_3d_pipeline *p,
                  struct gen6_pipeline_session *session)
 {
    /* 3DSTATE_INDEX_BUFFER */
-   if (DIRTY(INDEX_BUFFER)) {
+   if (DIRTY(INDEX_BUFFER) || session->batch_bo_changed) {
       p->gen6_3DSTATE_INDEX_BUFFER(p->dev,
-            &ilo->index_buffer, false, p->cp);
+            &ilo->ib.state, session->info->primitive_restart, p->cp);
    }
 
    /* 3DSTATE_VERTEX_BUFFERS */
-   if (DIRTY(VERTEX_BUFFERS)) {
+   if (DIRTY(VERTEX_BUFFERS) || DIRTY(VERTEX_ELEMENTS) ||
+       session->batch_bo_changed) {
       p->gen6_3DSTATE_VERTEX_BUFFERS(p->dev,
-            ilo->vertex_buffers.buffers, NULL,
-            (1 << ilo->vertex_buffers.num_buffers) - 1, p->cp);
+            ilo->vb.states, ilo->vb.enabled_mask, ilo->ve, p->cp);
    }
 
    /* 3DSTATE_VERTEX_ELEMENTS */
    if (DIRTY(VERTEX_ELEMENTS) || DIRTY(VS)) {
-      const struct ilo_vertex_element *ive = ilo->vertex_elements;
+      const struct ilo_ve_state *ve = ilo->ve;
       bool last_velement_edgeflag = false;
       bool prepend_generate_ids = false;
 
@@ -419,15 +420,14 @@ gen6_pipeline_vf(struct ilo_3d_pipeline *p,
 
          if (info->edgeflag_in >= 0) {
             /* we rely on the state tracker here */
-            assert(info->edgeflag_in ==  ive->num_elements - 1);
+            assert(info->edgeflag_in == ve->count - 1);
             last_velement_edgeflag = true;
          }
 
          prepend_generate_ids = (info->has_instanceid || info->has_vertexid);
       }
 
-      p->gen6_3DSTATE_VERTEX_ELEMENTS(p->dev,
-            ive->elements, ive->num_elements,
+      p->gen6_3DSTATE_VERTEX_ELEMENTS(p->dev, ve,
             last_velement_edgeflag, prepend_generate_ids, p->cp);
    }
 }
@@ -478,10 +478,9 @@ gen6_pipeline_vs(struct ilo_3d_pipeline *p,
    /* 3DSTATE_VS */
    if (emit_3dstate_vs) {
       const struct ilo_shader *vs = (ilo->vs)? ilo->vs->shader : NULL;
-      const int num_samplers = ilo->samplers[PIPE_SHADER_VERTEX].num_samplers;
+      const int num_samplers = ilo->sampler[PIPE_SHADER_VERTEX].count;
 
-      p->gen6_3DSTATE_VS(p->dev,
-            vs, ilo->max_vs_threads, num_samplers, p->cp);
+      p->gen6_3DSTATE_VS(p->dev, vs, num_samplers, p->cp);
    }
 
    if (emit_3dstate_constant_vs && p->dev->gen == ILO_GEN(6))
@@ -506,19 +505,17 @@ gen6_pipeline_gs(struct ilo_3d_pipeline *p,
       if (gs)
          assert(!gs->pcb.clip_state_size);
 
-      p->gen6_3DSTATE_GS(p->dev,
-            gs, ilo->max_gs_threads, vs,
+      p->gen6_3DSTATE_GS(p->dev, gs, vs,
             (vs) ? vs->cache_offset + vs->gs_offsets[num_vertices - 1] : 0,
             p->cp);
    }
 }
 
-static void
-gen6_pipeline_gs_svbi(struct ilo_3d_pipeline *p,
-                      const struct ilo_context *ilo,
-                      struct gen6_pipeline_session *session)
+bool
+gen6_pipeline_update_max_svbi(struct ilo_3d_pipeline *p,
+                              const struct ilo_context *ilo,
+                              struct gen6_pipeline_session *session)
 {
-   /* 3DSTATE_GS_SVB_INDEX */
    if (DIRTY(VS) || DIRTY(GS) || DIRTY(STREAM_OUTPUT_TARGETS)) {
       const struct pipe_stream_output_info *so_info =
          (ilo->gs) ? &ilo->gs->info.stream_output :
@@ -526,17 +523,18 @@ gen6_pipeline_gs_svbi(struct ilo_3d_pipeline *p,
       unsigned max_svbi = 0xffffffff;
       int i;
 
-      /* get max_svbi */
-      for (i = 0; so_info && i < so_info->num_outputs; i++) {
+      for (i = 0; i < so_info->num_outputs; i++) {
          const int output_buffer = so_info->output[i].output_buffer;
          const struct pipe_stream_output_target *so =
-            ilo->stream_output_targets.targets[output_buffer];
+            ilo->so.states[output_buffer];
          const int struct_size = so_info->stride[output_buffer] * 4;
          const int elem_size = so_info->output[i].num_components * 4;
          int buf_size, count;
 
-         if (!so)
-            continue;
+         if (!so) {
+            max_svbi = 0;
+            break;
+         }
 
          buf_size = so->buffer_size - so_info->output[i].dst_offset * 4;
 
@@ -548,14 +546,34 @@ gen6_pipeline_gs_svbi(struct ilo_3d_pipeline *p,
             max_svbi = count;
       }
 
+      if (p->state.so_max_vertices != max_svbi) {
+         p->state.so_max_vertices = max_svbi;
+         return true;
+      }
+   }
+
+   return false;
+}
+
+static void
+gen6_pipeline_gs_svbi(struct ilo_3d_pipeline *p,
+                      const struct ilo_context *ilo,
+                      struct gen6_pipeline_session *session)
+{
+   const bool emit = gen6_pipeline_update_max_svbi(p, ilo, session);
+
+   /* 3DSTATE_GS_SVB_INDEX */
+   if (emit) {
       if (p->dev->gen == ILO_GEN(6))
          gen6_wa_pipe_control_post_sync(p, false);
 
       p->gen6_3DSTATE_GS_SVB_INDEX(p->dev,
-            0, p->state.so_num_vertices, max_svbi,
+            0, p->state.so_num_vertices, p->state.so_max_vertices,
             false, p->cp);
 
       if (session->hw_ctx_changed) {
+         int i;
+
          /*
           * From the Sandy Bridge PRM, volume 2 part 1, page 148:
           *
@@ -570,9 +588,6 @@ gen6_pipeline_gs_svbi(struct ilo_3d_pipeline *p,
                   i, 0, 0xffffffff, false, p->cp);
          }
       }
-
-      /* remember the state for calculating primtive emitted in software */
-      p->state.so_max_vertices = max_svbi;
    }
 }
 
@@ -584,20 +599,22 @@ gen6_pipeline_clip(struct ilo_3d_pipeline *p,
    /* 3DSTATE_CLIP */
    if (DIRTY(RASTERIZER) || DIRTY(FS) ||
        DIRTY(VIEWPORT) || DIRTY(FRAMEBUFFER)) {
-      bool enable_guardband;
-      float x1, x2, y1, y2;
+      bool enable_guardband = true;
+      unsigned i;
 
       /*
        * We do not do 2D clipping yet.  Guard band test should only be enabled
        * when the viewport is larger than the framebuffer.
        */
-      x1 = fabs(ilo->viewport.scale[0]) * -1.0f + ilo->viewport.translate[0];
-      x2 = fabs(ilo->viewport.scale[0]) *  1.0f + ilo->viewport.translate[0];
-      y1 = fabs(ilo->viewport.scale[1]) * -1.0f + ilo->viewport.translate[1];
-      y2 = fabs(ilo->viewport.scale[1]) *  1.0f + ilo->viewport.translate[1];
-      enable_guardband =
-         (x1 <= 0.0f && x2 >= (float) ilo->framebuffer.width &&
-          y1 <= 0.0f && y2 >= (float) ilo->framebuffer.height);
+      for (i = 0; i < ilo->viewport.count; i++) {
+         const struct ilo_viewport_cso *vp = &ilo->viewport.cso[i];
+
+         if (vp->min_x > 0.0f || vp->max_x < ilo->fb.state.width ||
+             vp->min_y > 0.0f || vp->max_y < ilo->fb.state.height) {
+            enable_guardband = false;
+            break;
+         }
+      }
 
       p->gen6_3DSTATE_CLIP(p->dev,
             ilo->rasterizer,
@@ -618,8 +635,7 @@ gen6_pipeline_sf(struct ilo_3d_pipeline *p,
          (ilo->gs)? ilo->gs->shader :
          (ilo->vs)? ilo->vs->shader : NULL;
 
-      p->gen6_3DSTATE_SF(p->dev,
-            ilo->rasterizer, fs, last_sh, p->cp);
+      p->gen6_3DSTATE_SF(p->dev, ilo->rasterizer, fs, last_sh, p->cp);
    }
 }
 
@@ -634,7 +650,7 @@ gen6_pipeline_sf_rect(struct ilo_3d_pipeline *p,
          gen6_wa_pipe_control_post_sync(p, false);
 
       p->gen6_3DSTATE_DRAWING_RECTANGLE(p->dev, 0, 0,
-            ilo->framebuffer.width, ilo->framebuffer.height, p->cp);
+            ilo->fb.state.width, ilo->fb.state.height, p->cp);
    }
 }
 
@@ -652,13 +668,10 @@ gen6_pipeline_wm(struct ilo_3d_pipeline *p,
        DIRTY(BLEND) || DIRTY(DEPTH_STENCIL_ALPHA) ||
        DIRTY(RASTERIZER)) {
       const struct ilo_shader *fs = (ilo->fs)? ilo->fs->shader : NULL;
-      const int num_samplers =
-         ilo->samplers[PIPE_SHADER_FRAGMENT].num_samplers;
-      const bool dual_blend = (!ilo->blend->logicop_enable &&
-                                  ilo->blend->rt[0].blend_enable &&
-                                  util_blend_state_is_dual(ilo->blend, 0));
-      const bool cc_may_kill = (ilo->depth_stencil_alpha->alpha.enabled ||
-                                   ilo->blend->alpha_to_coverage);
+      const int num_samplers = ilo->sampler[PIPE_SHADER_FRAGMENT].count;
+      const bool dual_blend = ilo->blend->dual_blend;
+      const bool cc_may_kill = (ilo->dsa->alpha.enabled ||
+                                ilo->blend->alpha_to_coverage);
 
       if (fs)
          assert(!fs->pcb.clip_state_size);
@@ -666,9 +679,8 @@ gen6_pipeline_wm(struct ilo_3d_pipeline *p,
       if (p->dev->gen == ILO_GEN(6) && session->hw_ctx_changed)
          gen6_wa_pipe_control_wm_max_threads_stall(p);
 
-      p->gen6_3DSTATE_WM(p->dev,
-            fs, ilo->max_wm_threads, num_samplers,
-            ilo->rasterizer, dual_blend, cc_may_kill, p->cp);
+      p->gen6_3DSTATE_WM(p->dev, fs, num_samplers,
+            &ilo->rasterizer->state, dual_blend, cc_may_kill, p->cp);
    }
 }
 
@@ -680,12 +692,8 @@ gen6_pipeline_wm_multisample(struct ilo_3d_pipeline *p,
    /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
    if (DIRTY(SAMPLE_MASK) || DIRTY(FRAMEBUFFER)) {
       const uint32_t *packed_sample_pos;
-      int num_samples = 1;
-
-      if (ilo->framebuffer.nr_cbufs)
-         num_samples = ilo->framebuffer.cbufs[0]->texture->nr_samples;
 
-      packed_sample_pos = (num_samples > 1) ?
+      packed_sample_pos = (ilo->fb.num_samples > 1) ?
          &p->packed_sample_position_4x : &p->packed_sample_position_1x;
 
       if (p->dev->gen == ILO_GEN(6)) {
@@ -693,11 +701,12 @@ gen6_pipeline_wm_multisample(struct ilo_3d_pipeline *p,
          gen6_wa_pipe_control_wm_multisample_flush(p);
       }
 
-      p->gen6_3DSTATE_MULTISAMPLE(p->dev, num_samples, packed_sample_pos,
-            ilo->rasterizer->half_pixel_center, p->cp);
+      p->gen6_3DSTATE_MULTISAMPLE(p->dev,
+            ilo->fb.num_samples, packed_sample_pos,
+            ilo->rasterizer->state.half_pixel_center, p->cp);
 
       p->gen6_3DSTATE_SAMPLE_MASK(p->dev,
-            (num_samples > 1) ? ilo->sample_mask : 0x1, p->cp);
+            (ilo->fb.num_samples > 1) ? ilo->sample_mask : 0x1, p->cp);
    }
 }
 
@@ -707,14 +716,13 @@ gen6_pipeline_wm_depth(struct ilo_3d_pipeline *p,
                        struct gen6_pipeline_session *session)
 {
    /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
-   if (DIRTY(FRAMEBUFFER)) {
+   if (DIRTY(FRAMEBUFFER) || session->batch_bo_changed) {
       if (p->dev->gen == ILO_GEN(6)) {
          gen6_wa_pipe_control_post_sync(p, false);
          gen6_wa_pipe_control_wm_depth_flush(p);
       }
 
-      p->gen6_3DSTATE_DEPTH_BUFFER(p->dev,
-            ilo->framebuffer.zsbuf, false, p->cp);
+      p->gen6_3DSTATE_DEPTH_BUFFER(p->dev, ilo->fb.state.zsbuf, p->cp);
 
       /* TODO */
       p->gen6_3DSTATE_CLEAR_PARAMS(p->dev, 0, p->cp);
@@ -728,7 +736,7 @@ gen6_pipeline_wm_raster(struct ilo_3d_pipeline *p,
 {
    /* 3DSTATE_POLY_STIPPLE_PATTERN and 3DSTATE_POLY_STIPPLE_OFFSET */
    if ((DIRTY(RASTERIZER) || DIRTY(POLY_STIPPLE)) &&
-       ilo->rasterizer->poly_stipple_enable) {
+       ilo->rasterizer->state.poly_stipple_enable) {
       if (p->dev->gen == ILO_GEN(6))
          gen6_wa_pipe_control_post_sync(p, false);
 
@@ -739,17 +747,17 @@ gen6_pipeline_wm_raster(struct ilo_3d_pipeline *p,
    }
 
    /* 3DSTATE_LINE_STIPPLE */
-   if (DIRTY(RASTERIZER) && ilo->rasterizer->line_stipple_enable) {
+   if (DIRTY(RASTERIZER) && ilo->rasterizer->state.line_stipple_enable) {
       if (p->dev->gen == ILO_GEN(6))
          gen6_wa_pipe_control_post_sync(p, false);
 
       p->gen6_3DSTATE_LINE_STIPPLE(p->dev,
-            ilo->rasterizer->line_stipple_pattern,
-            ilo->rasterizer->line_stipple_factor + 1, p->cp);
+            ilo->rasterizer->state.line_stipple_pattern,
+            ilo->rasterizer->state.line_stipple_factor + 1, p->cp);
    }
 
    /* 3DSTATE_AA_LINE_PARAMETERS */
-   if (DIRTY(RASTERIZER) && ilo->rasterizer->line_smooth) {
+   if (DIRTY(RASTERIZER) && ilo->rasterizer->state.line_smooth) {
       if (p->dev->gen == ILO_GEN(6))
          gen6_wa_pipe_control_post_sync(p, false);
 
@@ -765,23 +773,23 @@ gen6_pipeline_state_viewports(struct ilo_3d_pipeline *p,
    /* SF_CLIP_VIEWPORT and CC_VIEWPORT */
    if (p->dev->gen >= ILO_GEN(7) && DIRTY(VIEWPORT)) {
       p->state.SF_CLIP_VIEWPORT = p->gen7_SF_CLIP_VIEWPORT(p->dev,
-            &ilo->viewport, 1, p->cp);
+            ilo->viewport.cso, ilo->viewport.count, p->cp);
 
       p->state.CC_VIEWPORT = p->gen6_CC_VIEWPORT(p->dev,
-            &ilo->viewport, 1, p->cp);
+            ilo->viewport.cso, ilo->viewport.count, p->cp);
 
       session->viewport_state_changed = true;
    }
    /* SF_VIEWPORT, CLIP_VIEWPORT, and CC_VIEWPORT */
    else if (DIRTY(VIEWPORT)) {
       p->state.CLIP_VIEWPORT = p->gen6_CLIP_VIEWPORT(p->dev,
-            &ilo->viewport, 1, p->cp);
+            ilo->viewport.cso, ilo->viewport.count, p->cp);
 
       p->state.SF_VIEWPORT = p->gen6_SF_VIEWPORT(p->dev,
-            &ilo->viewport, 1, p->cp);
+            ilo->viewport.cso, ilo->viewport.count, p->cp);
 
       p->state.CC_VIEWPORT = p->gen6_CC_VIEWPORT(p->dev,
-            &ilo->viewport, 1, p->cp);
+            ilo->viewport.cso, ilo->viewport.count, p->cp);
 
       session->viewport_state_changed = true;
    }
@@ -795,18 +803,16 @@ gen6_pipeline_state_cc(struct ilo_3d_pipeline *p,
    /* BLEND_STATE */
    if (DIRTY(BLEND) || DIRTY(FRAMEBUFFER) || DIRTY(DEPTH_STENCIL_ALPHA)) {
       p->state.BLEND_STATE = p->gen6_BLEND_STATE(p->dev,
-            ilo->blend, &ilo->framebuffer,
-            &ilo->depth_stencil_alpha->alpha, p->cp);
+            ilo->blend, &ilo->fb, &ilo->dsa->alpha, p->cp);
 
       session->cc_state_blend_changed = true;
    }
 
    /* COLOR_CALC_STATE */
    if (DIRTY(DEPTH_STENCIL_ALPHA) || DIRTY(STENCIL_REF) || DIRTY(BLEND_COLOR)) {
-      p->state.COLOR_CALC_STATE = p->gen6_COLOR_CALC_STATE(p->dev,
-            &ilo->stencil_ref,
-            ilo->depth_stencil_alpha->alpha.ref_value,
-            &ilo->blend_color, p->cp);
+      p->state.COLOR_CALC_STATE =
+         p->gen6_COLOR_CALC_STATE(p->dev, &ilo->stencil_ref,
+               ilo->dsa->alpha.ref_value, &ilo->blend_color, p->cp);
 
       session->cc_state_cc_changed = true;
    }
@@ -814,8 +820,7 @@ gen6_pipeline_state_cc(struct ilo_3d_pipeline *p,
    /* DEPTH_STENCIL_STATE */
    if (DIRTY(DEPTH_STENCIL_ALPHA)) {
       p->state.DEPTH_STENCIL_STATE =
-         p->gen6_DEPTH_STENCIL_STATE(p->dev,
-               ilo->depth_stencil_alpha, p->cp);
+         p->gen6_DEPTH_STENCIL_STATE(p->dev, ilo->dsa, p->cp);
 
       session->cc_state_dsa_changed = true;
    }
@@ -827,9 +832,10 @@ gen6_pipeline_state_scissors(struct ilo_3d_pipeline *p,
                              struct gen6_pipeline_session *session)
 {
    /* SCISSOR_RECT */
-   if (DIRTY(SCISSOR)) {
+   if (DIRTY(SCISSOR) || DIRTY(VIEWPORT)) {
+      /* there should be as many scissors as there are viewports */
       p->state.SCISSOR_RECT = p->gen6_SCISSOR_RECT(p->dev,
-            &ilo->scissor, 1, p->cp);
+            &ilo->scissor, ilo->viewport.count, p->cp);
 
       session->scissor_state_changed = true;
    }
@@ -846,12 +852,13 @@ gen6_pipeline_state_surfaces_rt(struct ilo_3d_pipeline *p,
       uint32_t *surface_state = &p->state.wm.SURFACE_STATE[offset];
       int i;
 
-      for (i = 0; i < ilo->framebuffer.nr_cbufs; i++) {
-         const struct pipe_surface *surface = ilo->framebuffer.cbufs[i];
+      for (i = 0; i < ilo->fb.state.nr_cbufs; i++) {
+         const struct ilo_surface_cso *surface =
+            (const struct ilo_surface_cso *) ilo->fb.state.cbufs[i];
 
-         assert(surface);
+         assert(surface && surface->is_rt);
          surface_state[i] =
-            p->gen6_surf_SURFACE_STATE(p->dev, surface, p->cp);
+            p->gen6_SURFACE_STATE(p->dev, &surface->u.rt, true, p->cp);
       }
 
       /*
@@ -859,14 +866,14 @@ gen6_pipeline_state_surfaces_rt(struct ilo_3d_pipeline *p,
        * brw_update_renderbuffer_surfaces() does.  I don't know why.
        */
       if (i == 0) {
-         struct pipe_surface null_surface;
+         struct ilo_view_surface null_surface;
 
-         memset(&null_surface, 0, sizeof(null_surface));
-         null_surface.width = ilo->framebuffer.width;
-         null_surface.height = ilo->framebuffer.height;
+         ilo_gpe_init_view_surface_null(p->dev,
+               ilo->fb.state.width, ilo->fb.state.height,
+               1, 0, &null_surface);
 
          surface_state[i] =
-            p->gen6_surf_SURFACE_STATE(p->dev, &null_surface, p->cp);
+            p->gen6_SURFACE_STATE(p->dev, &null_surface, true, p->cp);
 
          i++;
       }
@@ -888,9 +895,8 @@ gen6_pipeline_state_surfaces_so(struct ilo_3d_pipeline *p,
    const struct ilo_shader_state *vs = ilo->vs;
    const struct ilo_shader_state *gs = ilo->gs;
    const struct pipe_stream_output_target **so_targets =
-      (const struct pipe_stream_output_target **)
-      ilo->stream_output_targets.targets;
-   const int num_so_targets = ilo->stream_output_targets.num_targets;
+      (const struct pipe_stream_output_target **) ilo->so.states;
+   const int num_so_targets = ilo->so.count;
 
    if (p->dev->gen != ILO_GEN(6))
       return;
@@ -933,10 +939,9 @@ gen6_pipeline_state_surfaces_view(struct ilo_3d_pipeline *p,
                                   int shader_type,
                                   struct gen6_pipeline_session *session)
 {
-   const struct pipe_sampler_view **views =
-      (const struct pipe_sampler_view **)
-      ilo->sampler_views[shader_type].views;
-   const int num_views = ilo->sampler_views[shader_type].num_views;
+   const struct pipe_sampler_view * const *views =
+      (const struct pipe_sampler_view **) ilo->view[shader_type].states;
+   const int num_views = ilo->view[shader_type].count;
    uint32_t *surface_state;
    int offset, i;
    bool skip = false;
@@ -975,8 +980,11 @@ gen6_pipeline_state_surfaces_view(struct ilo_3d_pipeline *p,
 
    for (i = 0; i < num_views; i++) {
       if (views[i]) {
+         const struct ilo_view_cso *cso =
+            (const struct ilo_view_cso *) views[i];
+
          surface_state[i] =
-            p->gen6_view_SURFACE_STATE(p->dev, views[i], p->cp);
+            p->gen6_SURFACE_STATE(p->dev, &cso->surface, false, p->cp);
       }
       else {
          surface_state[i] = 0;
@@ -995,9 +1003,8 @@ gen6_pipeline_state_surfaces_const(struct ilo_3d_pipeline *p,
                                    int shader_type,
                                    struct gen6_pipeline_session *session)
 {
-   const struct pipe_constant_buffer *buffers =
-      ilo->constant_buffers[shader_type].buffers;
-   const int num_buffers = ilo->constant_buffers[shader_type].num_buffers;
+   const struct ilo_cbuf_cso *buffers = ilo->cbuf[shader_type].cso;
+   const int num_buffers = ilo->cbuf[shader_type].count;
    uint32_t *surface_state;
    int offset, i;
    bool skip = false;
@@ -1035,9 +1042,11 @@ gen6_pipeline_state_surfaces_const(struct ilo_3d_pipeline *p,
       return;
 
    for (i = 0; i < num_buffers; i++) {
-      if (buffers[i].buffer) {
+      if (buffers[i].resource) {
+         const struct ilo_view_surface *surf = &buffers[i].surface;
+
          surface_state[i] =
-            p->gen6_cbuf_SURFACE_STATE(p->dev, &buffers[i], p->cp);
+            p->gen6_SURFACE_STATE(p->dev, surf, false, p->cp);
       }
       else {
          surface_state[i] = 0;
@@ -1115,14 +1124,12 @@ gen6_pipeline_state_samplers(struct ilo_3d_pipeline *p,
                              int shader_type,
                              struct gen6_pipeline_session *session)
 {
-   const struct pipe_sampler_state **samplers =
-      (const struct pipe_sampler_state **)
-      ilo->samplers[shader_type].samplers;
-   const struct pipe_sampler_view **views =
-      (const struct pipe_sampler_view **)
-      ilo->sampler_views[shader_type].views;
-   const int num_samplers = ilo->samplers[shader_type].num_samplers;
-   const int num_views = ilo->sampler_views[shader_type].num_views;
+   const struct ilo_sampler_cso * const *samplers =
+      ilo->sampler[shader_type].cso;
+   const struct pipe_sampler_view * const *views =
+      (const struct pipe_sampler_view **) ilo->view[shader_type].states;
+   const int num_samplers = ilo->sampler[shader_type].count;
+   const int num_views = ilo->view[shader_type].count;
    uint32_t *sampler_state, *border_color_state;
    bool emit_border_color = false;
    bool skip = false;
@@ -1171,7 +1178,7 @@ gen6_pipeline_state_samplers(struct ilo_3d_pipeline *p,
       for (i = 0; i < num_samplers; i++) {
          border_color_state[i] = (samplers[i]) ?
             p->gen6_SAMPLER_BORDER_COLOR_STATE(p->dev,
-                  &samplers[i]->border_color, p->cp) : 0;
+                  samplers[i], p->cp) : 0;
       }
    }
 
@@ -1293,11 +1300,24 @@ gen6_pipeline_prepare(const struct ilo_3d_pipeline *p,
 
    if (session->hw_ctx_changed) {
       /* these should be enough to make everything uploaded */
+      session->batch_bo_changed = true;
       session->state_bo_changed = true;
       session->instruction_bo_changed = true;
       session->prim_changed = true;
    }
    else {
+      /*
+       * Any state that involves resources needs to be re-emitted when the
+       * batch bo changed.  This is because we do not pin the resources and
+       * their offsets (or existence) may change between batch buffers.
+       *
+       * Since we messed around with ILO_3D_PIPELINE_INVALIDATE_BATCH_BO in
+       * handle_invalid_batch_bo(), use ILO_3D_PIPELINE_INVALIDATE_STATE_BO as
+       * a temporary workaround.
+       */
+      session->batch_bo_changed =
+         (p->invalidate_flags & ILO_3D_PIPELINE_INVALIDATE_STATE_BO);
+
       session->state_bo_changed =
          (p->invalidate_flags & ILO_3D_PIPELINE_INVALIDATE_STATE_BO);
       session->instruction_bo_changed =
@@ -1502,7 +1522,7 @@ gen6_pipeline_estimate_states(const struct ilo_3d_pipeline *p,
     * sampler views (vs, fs)
     * constant buffers (vs, fs)
     */
-   count = ilo->framebuffer.nr_cbufs;
+   count = ilo->fb.state.nr_cbufs;
 
    if (ilo->gs)
       count += ilo->gs->info.stream_output.num_outputs;
@@ -1510,8 +1530,8 @@ gen6_pipeline_estimate_states(const struct ilo_3d_pipeline *p,
       count += ilo->vs->info.stream_output.num_outputs;
 
    for (shader_type = 0; shader_type < PIPE_SHADER_TYPES; shader_type++) {
-      count += ilo->sampler_views[shader_type].num_views;
-      count += ilo->constant_buffers[shader_type].num_buffers;
+      count += ilo->view[shader_type].count;
+      count += ilo->cbuf[shader_type].count;
    }
 
    if (count) {
@@ -1521,7 +1541,7 @@ gen6_pipeline_estimate_states(const struct ilo_3d_pipeline *p,
 
    /* samplers (vs, fs) */
    for (shader_type = 0; shader_type < PIPE_SHADER_TYPES; shader_type++) {
-      count = ilo->samplers[shader_type].num_samplers;
+      count = ilo->sampler[shader_type].count;
       if (count) {
          size += gen6->estimate_state_size(p->dev,
                ILO_GPE_GEN6_SAMPLER_BORDER_COLOR_STATE, count);
@@ -1636,9 +1656,7 @@ ilo_3d_pipeline_init_gen6(struct ilo_3d_pipeline *p)
    GEN6_USE(p, DEPTH_STENCIL_STATE, gen6);
    GEN6_USE(p, SCISSOR_RECT, gen6);
    GEN6_USE(p, BINDING_TABLE_STATE, gen6);
-   GEN6_USE(p, surf_SURFACE_STATE, gen6);
-   GEN6_USE(p, view_SURFACE_STATE, gen6);
-   GEN6_USE(p, cbuf_SURFACE_STATE, gen6);
+   GEN6_USE(p, SURFACE_STATE, gen6);
    GEN6_USE(p, so_SURFACE_STATE, gen6);
    GEN6_USE(p, SAMPLER_STATE, gen6);
    GEN6_USE(p, SAMPLER_BORDER_COLOR_STATE, gen6);