svga: reduce unmapping/remapping of the default constant buffer
[mesa.git] / src / gallium / drivers / svga / svga_pipe_sampler.c
index 845eebbd0148bcfebc0179b5616e7d7050502fec..5d7af701ad401dbb78fabf998c6ab45efecb1a79 100644 (file)
@@ -277,6 +277,8 @@ svga_create_sampler_state(struct pipe_context *pipe,
             cso->mipfilter == SVGA3D_TEX_FILTER_NONE ? "SVGA3D_TEX_FILTER_NONE" : "SOMETHING");
 
    svga->hud.num_sampler_objects++;
+   SVGA_STATS_COUNT_INC(svga_screen(svga->pipe.screen)->sws,
+                        SVGA_STATS_COUNT_SAMPLER);
 
    return cso;
 }
@@ -284,7 +286,7 @@ svga_create_sampler_state(struct pipe_context *pipe,
 
 static void
 svga_bind_sampler_states(struct pipe_context *pipe,
-                         unsigned shader,
+                         enum pipe_shader_type shader,
                          unsigned start,
                          unsigned num,
                          void **samplers)
@@ -367,6 +369,8 @@ svga_create_sampler_view(struct pipe_context *pipe,
    sv->id = SVGA3D_INVALID_ID;
 
    svga->hud.num_samplerview_objects++;
+   SVGA_STATS_COUNT_INC(svga_screen(svga->pipe.screen)->sws,
+                        SVGA_STATS_COUNT_SAMPLERVIEW);
 
    return &sv->base;
 }
@@ -413,7 +417,7 @@ svga_sampler_view_destroy(struct pipe_context *pipe,
 
 static void
 svga_set_sampler_views(struct pipe_context *pipe,
-                       unsigned shader,
+                       enum pipe_shader_type shader,
                        unsigned start,
                        unsigned num,
                        struct pipe_sampler_view **views)
@@ -433,6 +437,20 @@ svga_set_sampler_views(struct pipe_context *pipe,
    if (!svga_have_vgpu10(svga) && shader != PIPE_SHADER_FRAGMENT)
       return;
 
+   SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SETSAMPLERVIEWS);
+
+   /* This bit of code works around a quirk in the CSO module.
+    * If start=num=0 it means all sampler views should be released.
+    * Note that the CSO module treats sampler views for fragment shaders
+    * differently than other shader types.
+    */
+   if (start == 0 && num == 0 && svga->curr.num_sampler_views[shader] > 0) {
+      for (i = 0; i < svga->curr.num_sampler_views[shader]; i++) {
+         pipe_sampler_view_release(pipe, &svga->curr.sampler_views[shader][i]);
+      }
+      any_change = TRUE;
+   }
+
    for (i = 0; i < num; i++) {
       enum pipe_texture_target target;
 
@@ -463,7 +481,7 @@ svga_set_sampler_views(struct pipe_context *pipe,
    }
 
    if (!any_change) {
-      return;
+      goto done;
    }
 
    /* find highest non-null sampler_views[] entry */
@@ -493,30 +511,49 @@ svga_set_sampler_views(struct pipe_context *pipe,
    }
 
    /* Check if any of the sampler view resources collide with the framebuffer
-    * color buffers or depth stencil resource. If so, enable the NEW_FRAME_BUFFER
+    * color buffers or depth stencil resource. If so, set the NEW_FRAME_BUFFER
     * dirty bit so that emit_framebuffer can be invoked to create backed view
     * for the conflicted surface view.
     */
-   for (i = 0; i < svga->curr.framebuffer.nr_cbufs; i++) {
-      if (svga->curr.framebuffer.cbufs[i]) {
-         struct svga_surface *s = svga_surface(svga->curr.framebuffer.cbufs[i]);
-         if (svga_check_sampler_view_resource_collision(svga, s->handle, shader)) {
-            svga->dirty |= SVGA_NEW_FRAME_BUFFER;
-            break;
-         }
-      }
+   if (svga_check_sampler_framebuffer_resource_collision(svga, shader)) {
+      svga->dirty |= SVGA_NEW_FRAME_BUFFER;
    }
 
-   if (svga->curr.framebuffer.zsbuf) {
-      struct svga_surface *s = svga_surface(svga->curr.framebuffer.zsbuf);
-      if (s) {
-         if (svga_check_sampler_view_resource_collision(svga, s->handle, shader)) {
-            svga->dirty |= SVGA_NEW_FRAME_BUFFER;
-         }
+done:
+   SVGA_STATS_TIME_POP(svga_sws(svga));
+}
+
+/**
+ * Clean up sampler, sampler view state at context destruction time
+ */
+void
+svga_cleanup_sampler_state(struct svga_context *svga)
+{
+   enum pipe_shader_type shader;
+
+   if (!svga_have_vgpu10(svga))
+      return;
+
+   for (shader = 0; shader <= PIPE_SHADER_GEOMETRY; shader++) {
+      unsigned i;
+
+      for (i = 0; i < svga->state.hw_draw.num_sampler_views[shader]; i++) {
+         pipe_sampler_view_release(&svga->pipe,
+                                   &svga->state.hw_draw.sampler_views[shader][i]);
       }
    }
-}
+   
+   /* free polygon stipple state */
+   if (svga->polygon_stipple.sampler) {
+      svga->pipe.delete_sampler_state(&svga->pipe, svga->polygon_stipple.sampler);
+   }
 
+   if (svga->polygon_stipple.sampler_view) {
+      svga->pipe.sampler_view_destroy(&svga->pipe,
+                                      &svga->polygon_stipple.sampler_view->base);
+   }
+   pipe_resource_reference(&svga->polygon_stipple.texture, NULL);
+}
 
 void
 svga_init_sampler_functions( struct svga_context *svga )