svga: Implement the pipe clear_render_target functionality v2
authorThomas Hellstrom <thellstrom@vmware.com>
Fri, 28 Oct 2016 18:33:53 +0000 (11:33 -0700)
committerBrian Paul <brianp@vmware.com>
Thu, 3 Nov 2016 20:29:22 +0000 (14:29 -0600)
v2: Accounted for the fact that svga_try_clear_render_target also
honors conditional rendering.

Testing done: Excercised all functions in a separate feature branch. Forced
emission of conditional rendering commands when necessary.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/svga/svga_context.c
src/gallium/drivers/svga/svga_context.h
src/gallium/drivers/svga/svga_pipe_clear.c
src/gallium/drivers/svga/svga_pipe_query.c

index 52fc654cf3e3d6e2d7ddeffe52dbe8f3038c1c85..21ce508905262e6d1e73b09d6388a23420a0cef8 100644 (file)
@@ -273,6 +273,7 @@ struct pipe_context *svga_context_create(struct pipe_screen *screen,
    }
 
    svga->dirty = ~0;
+   svga->pred.query_id = SVGA3D_INVALID_ID;
 
    return &svga->pipe;
 
index 5148372753d9aeae3685da4e82ea530deafcb407..3e65384a07a2c458c67f91faa70323edca613872 100644 (file)
@@ -583,6 +583,12 @@ struct svga_context
 
    /** Alternate rasterizer states created for point sprite */
    struct svga_rasterizer_state *rasterizer_no_cull[2];
+
+   /** Current conditional rendering predicate */
+   struct {
+      SVGA3dQueryId query_id;
+      boolean cond;
+   } pred;
 };
 
 /* A flag for each state_tracker state object:
@@ -622,7 +628,6 @@ struct svga_context
 
 
 
-
 /***********************************************************************
  * svga_screen_texture.c: 
  */
index 12f3050f56988a7f5dfe5fa842447dce3a5f2381..803afc60ff8098d0bab2e5342776ef4d95541c95 100644 (file)
@@ -451,9 +451,138 @@ svga_clear_texture(struct pipe_context *pipe,
    }
 }
 
+/**
+ * \brief  Clear the whole render target using vgpu10 functionality
+ *
+ * \param svga[in]  The svga context
+ * \param dst[in]  The surface to clear
+ * \param color[in]  Clear color
+ * \return PIPE_OK if all well, PIPE_ERROR_OUT_OF_MEMORY if ran out of
+ * command submission resources.
+ */
+static enum pipe_error
+svga_try_clear_render_target(struct svga_context *svga,
+                             struct pipe_surface *dst,
+                             const union pipe_color_union *color)
+{
+   struct pipe_surface *rtv =
+      svga_validate_surface_view(svga, svga_surface(dst));
+
+   if (!rtv)
+      return PIPE_ERROR_OUT_OF_MEMORY;
+
+   return SVGA3D_vgpu10_ClearRenderTargetView(svga->swc, rtv, color->f);
+ }
+
+/**
+ * \brief  Clear part of render target using gallium blitter utilities
+ *
+ * \param svga[in]  The svga context
+ * \param dst[in]  The surface to clear
+ * \param color[in]  Clear color
+ * \param dstx[in]  Clear region left
+ * \param dsty[in]  Clear region top
+ * \param width[in]  Clear region width
+ * \param height[in]  Clear region height
+ */
+static void
+svga_blitter_clear_render_target(struct svga_context *svga,
+                                 struct pipe_surface *dst,
+                                 const union pipe_color_union *color,
+                                 unsigned dstx, unsigned dsty,
+                                 unsigned width, unsigned height)
+{
+   begin_blit(svga);
+   util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer);
+
+   util_blitter_clear_render_target(svga->blitter, dst, color,
+                                    dstx, dsty, width, height);
+}
+
+/**
+ * \brief Toggle conditional rendering if already enabled
+ *
+ * \param svga[in]  The svga context
+ * \param render_condition_enabled[in]  Whether to ignore requests to turn
+ * conditional rendering off
+ * \param on[in]  Whether to turn conditional rendering on or off
+ */
+static void
+svga_toggle_render_condition(struct svga_context *svga,
+                             boolean render_condition_enabled,
+                             boolean on)
+{
+   SVGA3dQueryId query_id;
+   enum pipe_error ret;
+
+   if (render_condition_enabled ||
+       svga->pred.query_id == SVGA3D_INVALID_ID) {
+      return;
+   }
+
+   /*
+    * If we get here, it means that the system supports
+    * conditional rendering since svga->pred.query_id has already been
+    * modified for this context and thus support has already been
+    * verified.
+    */
+   query_id = on ? svga->pred.query_id : SVGA3D_INVALID_ID;
+
+   ret = SVGA3D_vgpu10_SetPredication(svga->swc, query_id,
+                                      (uint32) svga->pred.cond);
+   if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
+      svga_context_flush(svga, NULL);
+      ret = SVGA3D_vgpu10_SetPredication(svga->swc, query_id,
+                                         (uint32) svga->pred.cond);
+      assert(ret == PIPE_OK);
+   }
+}
+
+/**
+ * \brief Clear render target pipe callback
+ *
+ * \param pipe[in]  The pipe context
+ * \param dst[in]  The surface to clear
+ * \param color[in]  Clear color
+ * \param dstx[in]  Clear region left
+ * \param dsty[in]  Clear region top
+ * \param width[in]  Clear region width
+ * \param height[in]  Clear region height
+ * \param render_condition_enabled[in]  Whether to use conditional rendering
+ * to clear (if elsewhere enabled).
+ */
+static void
+svga_clear_render_target(struct pipe_context *pipe,
+                         struct pipe_surface *dst,
+                         const union pipe_color_union *color,
+                         unsigned dstx, unsigned dsty,
+                         unsigned width, unsigned height,
+                         bool render_condition_enabled)
+{
+    struct svga_context *svga = svga_context( pipe );
+
+    svga_toggle_render_condition(svga, render_condition_enabled, FALSE);
+    if (!svga_have_vgpu10(svga) || dstx != 0 || dsty != 0 ||
+        width != dst->width || height != dst->height) {
+       svga_blitter_clear_render_target(svga, dst, color, dstx, dsty, width,
+                                        height);
+    } else {
+       enum pipe_error ret;
+       
+       ret = svga_try_clear_render_target(svga, dst, color);
+       if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
+          svga_context_flush( svga, NULL );
+          ret = svga_try_clear_render_target(svga, dst, color);
+       }
+       
+       assert (ret == PIPE_OK);
+    }
+    svga_toggle_render_condition(svga, render_condition_enabled, TRUE);
+}
 
 void svga_init_clear_functions(struct svga_context *svga)
 {
+   svga->pipe.clear_render_target = svga_clear_render_target;
    svga->pipe.clear_texture = svga_clear_texture;
    svga->pipe.clear = svga_clear;
 }
index 5de3937474ea9dcf4c5ba8c5fcd50827470a618f..a7bfb4ea265d06a5efb6854f3897b358948b2bc8 100644 (file)
@@ -1239,6 +1239,8 @@ svga_render_condition(struct pipe_context *pipe, struct pipe_query *q,
          ret = SVGA3D_vgpu10_SetPredication(svga->swc, queryId,
                                             (uint32) condition);
       }
+      svga->pred.query_id = queryId;
+      svga->pred.cond = condition;
    }
 }