u_blitter: add a msaa parameter to util_blitter_clear
[mesa.git] / src / gallium / drivers / svga / svga_state_tss.c
index eb3f81ab63faa2ad68f07d20c4f304df4902d985..95b1a9e952dc5fcb00649b3eeed9445fbcd7b119 100644 (file)
@@ -28,6 +28,7 @@
 #include "pipe/p_defines.h"
 #include "util/u_math.h"
 
+#include "svga_resource_texture.h"
 #include "svga_sampler_view.h"
 #include "svga_winsys.h"
 #include "svga_context.h"
@@ -39,7 +40,8 @@
 /**
  * Called when tearing down a context to free resources and samplers.
  */
-void svga_cleanup_tss_binding(struct svga_context *svga)
+void
+svga_cleanup_tss_binding(struct svga_context *svga)
 {
    const enum pipe_shader_type shader = PIPE_SHADER_FRAGMENT;
    unsigned i;
@@ -48,8 +50,8 @@ void svga_cleanup_tss_binding(struct svga_context *svga)
       struct svga_hw_view_state *view = &svga->state.hw_draw.views[i];
       if (view) {
          svga_sampler_view_reference(&view->v, NULL);
-         pipe_sampler_view_release(&svga->pipe,
-                                   &svga->curr.sampler_views[shader][i]);
+         pipe_sampler_view_reference(&svga->curr.sampler_views[shader][i],
+                                     NULL);
          pipe_resource_reference(&view->texture, NULL);
          view->dirty = TRUE;
       }
@@ -106,7 +108,7 @@ emit_tex_binding_unit(struct svga_context *svga,
        view->max_lod != max_lod) {
 
       svga_sampler_view_reference(&view->v, NULL);
-      pipe_resource_reference( &view->texture, texture );
+      pipe_resource_reference(&view->texture, texture);
 
       view->dirty = TRUE;
       view->min_lod = min_lod;
@@ -137,14 +139,13 @@ emit_tex_binding_unit(struct svga_context *svga,
 
 
 static enum pipe_error
-update_tss_binding(struct svga_context *svga, 
-                   unsigned dirty )
+update_tss_binding(struct svga_context *svga, unsigned dirty)
 {
    const enum pipe_shader_type shader = PIPE_SHADER_FRAGMENT;
    boolean reemit = svga->rebind.flags.texture_samplers;
    unsigned i;
-   unsigned count = MAX2( svga->curr.num_sampler_views[shader],
-                          svga->state.hw_draw.num_views );
+   unsigned count = MAX2(svga->curr.num_sampler_views[shader],
+                         svga->state.hw_draw.num_views);
 
    struct bind_queue queue;
 
@@ -152,7 +153,7 @@ update_tss_binding(struct svga_context *svga,
       return PIPE_OK;
 
    queue.bind_count = 0;
-   
+
    for (i = 0; i < count; i++) {
       emit_tex_binding_unit(svga, i,
                             svga->curr.sampler[shader][i],
@@ -175,22 +176,30 @@ update_tss_binding(struct svga_context *svga,
                             &queue);
    }
 
+   svga->state.hw_draw.num_backed_views = 0;
+
    if (queue.bind_count) {
       SVGA3dTextureState *ts;
 
-      if (SVGA3D_BeginSetTextureState( svga->swc,
-                                       &ts,
-                                       queue.bind_count ) != PIPE_OK)
+      if (SVGA3D_BeginSetTextureState(svga->swc, &ts,
+                                      queue.bind_count) != PIPE_OK)
          goto fail;
 
       for (i = 0; i < queue.bind_count; i++) {
          struct svga_winsys_surface *handle;
+         struct svga_hw_view_state *view = queue.bind[i].view;
 
          ts[i].stage = queue.bind[i].unit;
          ts[i].name = SVGA3D_TS_BIND_TEXTURE;
 
-         if (queue.bind[i].view->v) {
-            handle = queue.bind[i].view->v->handle;
+         if (view->v) {
+            handle = view->v->handle;
+
+            /* Keep track of number of views with a backing copy
+             * of texture.
+             */
+            if (handle != svga_texture(view->texture)->handle)
+               svga->state.hw_draw.num_backed_views++;
          }
          else {
             handle = NULL;
@@ -200,11 +209,11 @@ update_tss_binding(struct svga_context *svga,
                                        NULL,
                                        handle,
                                        SVGA_RELOC_READ);
-         
+
          queue.bind[i].view->dirty = FALSE;
       }
 
-      SVGA_FIFOCommitAll( svga->swc );
+      SVGA_FIFOCommitAll(svga->swc);
    }
 
    svga->rebind.flags.texture_samplers = FALSE;
@@ -247,7 +256,7 @@ svga_reemit_tss_bindings(struct svga_context *svga)
    }
 
    /* Polygon stipple */
-   if (svga->curr.rast->templ.poly_stipple_enable) {
+   if (svga->curr.rast && svga->curr.rast->templ.poly_stipple_enable) {
       const unsigned unit = svga->state.hw_draw.fs->pstipple_sampler_unit;
       struct svga_hw_view_state *view = &svga->state.hw_draw.views[unit];
 
@@ -261,9 +270,7 @@ svga_reemit_tss_bindings(struct svga_context *svga)
    if (queue.bind_count) {
       SVGA3dTextureState *ts;
 
-      ret = SVGA3D_BeginSetTextureState(svga->swc,
-                                        &ts,
-                                        queue.bind_count);
+      ret = SVGA3D_BeginSetTextureState(svga->swc, &ts, queue.bind_count);
       if (ret != PIPE_OK) {
          return ret;
       }
@@ -294,6 +301,7 @@ svga_reemit_tss_bindings(struct svga_context *svga)
 
 struct svga_tracked_state svga_hw_tss_binding = {
    "texture binding emit",
+   SVGA_NEW_FRAME_BUFFER |
    SVGA_NEW_TEXTURE_BINDING |
    SVGA_NEW_STIPPLE |
    SVGA_NEW_SAMPLER,
@@ -301,8 +309,6 @@ struct svga_tracked_state svga_hw_tss_binding = {
 };
 
 
-/***********************************************************************
- */
 
 struct ts_queue {
    unsigned ts_count;
@@ -311,10 +317,7 @@ struct ts_queue {
 
 
 static inline void
-svga_queue_tss( struct ts_queue *q,
-                unsigned unit,
-                unsigned tss,
-                unsigned value )
+svga_queue_tss(struct ts_queue *q, unsigned unit, unsigned tss, unsigned value)
 {
    assert(q->ts_count < ARRAY_SIZE(q->ts));
    q->ts[q->ts_count].stage = unit;
@@ -329,7 +332,7 @@ do {                                                                    \
    assert(unit < ARRAY_SIZE(svga->state.hw_draw.ts));                     \
    STATIC_ASSERT(SVGA3D_TS_##token < ARRAY_SIZE(svga->state.hw_draw.ts[unit])); \
    if (svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] != val) {        \
-      svga_queue_tss( queue, unit, SVGA3D_TS_##token, val );            \
+      svga_queue_tss(queue, unit, SVGA3D_TS_##token, val);             \
       svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] = val;            \
    }                                                                    \
 } while (0)
@@ -340,7 +343,7 @@ do {                                                                    \
    assert(unit < ARRAY_SIZE(svga->state.hw_draw.ts));                     \
    STATIC_ASSERT(SVGA3D_TS_##token < ARRAY_SIZE(svga->state.hw_draw.ts[unit])); \
    if (svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] != val) {        \
-      svga_queue_tss( queue, unit, SVGA3D_TS_##token, val );            \
+      svga_queue_tss(queue, unit, SVGA3D_TS_##token, val);              \
       svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] = val;            \
    }                                                                    \
 } while (0)
@@ -377,8 +380,7 @@ emit_tss_unit(struct svga_context *svga, unsigned unit,
 }
 
 static enum pipe_error
-update_tss(struct svga_context *svga, 
-           unsigned dirty )
+update_tss(struct svga_context *svga, unsigned dirty)
 {
    const enum pipe_shader_type shader = PIPE_SHADER_FRAGMENT;
    unsigned i;
@@ -402,20 +404,16 @@ update_tss(struct svga_context *svga,
                     svga->polygon_stipple.sampler,
                     &queue);
    }
+
    if (queue.ts_count) {
       SVGA3dTextureState *ts;
 
-      if (SVGA3D_BeginSetTextureState( svga->swc,
-                                       &ts,
-                                       queue.ts_count ) != PIPE_OK)
+      if (SVGA3D_BeginSetTextureState(svga->swc, &ts, queue.ts_count) != PIPE_OK)
          goto fail;
 
-      memcpy( ts,
-              queue.ts,
-              queue.ts_count * sizeof queue.ts[0]);
-      
-      SVGA_FIFOCommitAll( svga->swc );
+      memcpy(ts, queue.ts, queue.ts_count * sizeof queue.ts[0]);
+
+      SVGA_FIFOCommitAll(svga->swc);
    }
 
    return PIPE_OK;