svga: Performance fixes
[mesa.git] / src / gallium / drivers / svga / svga_pipe_misc.c
index 71601543a9c34155d69614a3d5026d4990f97c16..61b4897c5d69292458dbb195a904e353a5eb2e19 100644 (file)
  *
  **********************************************************/
 
-#include "svga_cmd.h"
-
 #include "util/u_framebuffer.h"
 #include "util/u_inlines.h"
 #include "util/u_pstipple.h"
 
+#include "svga_cmd.h"
 #include "svga_context.h"
 #include "svga_screen.h"
 #include "svga_surface.h"
 #include "svga_resource_texture.h"
 
 
-static void svga_set_scissor_states( struct pipe_context *pipe,
-                                     unsigned start_slot,
-                                     unsigned num_scissors,
-                                     const struct pipe_scissor_state *scissors )
+static void
+svga_set_scissor_states(struct pipe_context *pipe,
+                        unsigned start_slot,
+                        unsigned num_scissors,
+                        const struct pipe_scissor_state *scissors)
 {
+   ASSERTED struct svga_screen *svgascreen = svga_screen(pipe->screen);
    struct svga_context *svga = svga_context(pipe);
+   unsigned i, num_sc;
+
+   assert(start_slot + num_scissors <= svgascreen->max_viewports);
+
+   for (i = 0, num_sc = start_slot; i < num_scissors; i++)  {
+      svga->curr.scissor[num_sc++] = scissors[i]; /* struct copy */
+   }
 
-   memcpy( &svga->curr.scissor, scissors, sizeof(*scissors) );
    svga->dirty |= SVGA_NEW_SCISSOR;
 }
 
@@ -81,7 +88,8 @@ svga_set_polygon_stipple(struct pipe_context *pipe,
 }
 
 
-void svga_cleanup_framebuffer(struct svga_context *svga)
+void
+svga_cleanup_framebuffer(struct svga_context *svga)
 {
    struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
    struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
@@ -103,8 +111,9 @@ void svga_cleanup_framebuffer(struct svga_context *svga)
 #define DEPTH_BIAS_SCALE_FACTOR_D32    ((float)(1<<31))
 
 
-static void svga_set_framebuffer_state(struct pipe_context *pipe,
-                                      const struct pipe_framebuffer_state *fb)
+static void
+svga_set_framebuffer_state(struct pipe_context *pipe,
+                           const struct pipe_framebuffer_state *fb)
 {
    struct svga_context *svga = svga_context(pipe);
    struct pipe_framebuffer_state *dst = &svga->curr.framebuffer;
@@ -119,18 +128,6 @@ static void svga_set_framebuffer_state(struct pipe_context *pipe,
    dst->height = fb->height;
    dst->nr_cbufs = fb->nr_cbufs;
 
-   /* Check if we need to propagate any of the render targets which we may
-    * be unbinding.
-    */
-   for (i = 0; i < dst->nr_cbufs; i++) {
-      struct pipe_surface *s = i < fb->nr_cbufs ? fb->cbufs[i] : NULL;
-      if (dst->cbufs[i] && dst->cbufs[i] != s) {
-         if (svga_surface_needs_propagation(dst->cbufs[i])) {
-            svga_propagate_surface(svga, dst->cbufs[i]);
-         }
-      }
-   }
-
    /* Check that all surfaces are the same size.
     * Actually, the virtual hardware may support rendertargets with
     * different size, depending on the host API and driver,
@@ -160,17 +157,7 @@ static void svga_set_framebuffer_state(struct pipe_context *pipe,
 
    util_copy_framebuffer_state(dst, fb);
 
-   /* Set the rendered-to flags */
-   for (i = 0; i < dst->nr_cbufs; i++) {
-      struct pipe_surface *s = dst->cbufs[i];
-      if (s) {
-         struct svga_texture *t = svga_texture(s->texture);
-         svga_set_texture_rendered_to(t, s->u.tex.first_layer, s->u.tex.level);
-      }
-   }
-
-   if (svga->curr.framebuffer.zsbuf)
-   {
+   if (svga->curr.framebuffer.zsbuf) {
       switch (svga->curr.framebuffer.zsbuf->format) {
       case PIPE_FORMAT_Z16_UNORM:
          svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D16;
@@ -191,13 +178,6 @@ static void svga_set_framebuffer_state(struct pipe_context *pipe,
          svga->curr.depthscale = 0.0f;
          break;
       }
-
-      /* Set rendered-to flag */
-      {
-         struct pipe_surface *s = dst->zsbuf;
-         struct svga_texture *t = svga_texture(s->texture);
-         svga_set_texture_rendered_to(t, s->u.tex.first_layer, s->u.tex.level);
-      }
    }
    else {
       svga->curr.depthscale = 0.0f;
@@ -207,9 +187,9 @@ static void svga_set_framebuffer_state(struct pipe_context *pipe,
 }
 
 
-
-static void svga_set_clip_state( struct pipe_context *pipe,
-                                 const struct pipe_clip_state *clip )
+static void
+svga_set_clip_state(struct pipe_context *pipe,
+                    const struct pipe_clip_state *clip)
 {
    struct svga_context *svga = svga_context(pipe);
 
@@ -219,18 +199,21 @@ static void svga_set_clip_state( struct pipe_context *pipe,
 }
 
 
-
-/* Called when driver state tracker notices changes to the viewport
- * matrix:
- */
-static void svga_set_viewport_states( struct pipe_context *pipe,
-                                      unsigned start_slot,
-                                      unsigned num_viewports,
-                                      const struct pipe_viewport_state *viewports )
+static void
+svga_set_viewport_states(struct pipe_context *pipe,
+                         unsigned start_slot,
+                         unsigned num_viewports,
+                         const struct pipe_viewport_state *viewports)
 {
    struct svga_context *svga = svga_context(pipe);
+   ASSERTED struct svga_screen *svgascreen = svga_screen(pipe->screen);
+   unsigned i, num_vp;
 
-   svga->curr.viewport = *viewports; /* struct copy */
+   assert(start_slot + num_viewports <= svgascreen->max_viewports);
+
+   for (i = 0, num_vp = start_slot; i < num_viewports; i++)  {
+      svga->curr.viewport[num_vp++] = viewports[i]; /* struct copy */
+   }
 
    svga->dirty |= SVGA_NEW_VIEWPORT;
 }
@@ -238,7 +221,7 @@ static void svga_set_viewport_states( struct pipe_context *pipe,
 
 /**
  * Called by state tracker to specify a callback function the driver
- * can use to report info back to the state tracker.
+ * can use to report info back to the gallium frontend.
  */
 static void
 svga_set_debug_callback(struct pipe_context *pipe,
@@ -256,7 +239,8 @@ svga_set_debug_callback(struct pipe_context *pipe,
 }
 
 
-void svga_init_misc_functions( struct svga_context *svga )
+void
+svga_init_misc_functions(struct svga_context *svga)
 {
    svga->pipe.set_scissor_states = svga_set_scissor_states;
    svga->pipe.set_polygon_stipple = svga_set_polygon_stipple;
@@ -265,5 +249,3 @@ void svga_init_misc_functions( struct svga_context *svga )
    svga->pipe.set_viewport_states = svga_set_viewport_states;
    svga->pipe.set_debug_callback = svga_set_debug_callback;
 }
-
-