i915g: implement surface clear functions using hw-clear
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Sun, 6 Mar 2011 11:36:46 +0000 (12:36 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 10 Mar 2011 22:04:20 +0000 (23:04 +0100)
Tested by temporarily using util_clear even when not using the blitter.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
src/gallium/drivers/i915/i915_clear.c
src/gallium/drivers/i915/i915_context.c
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i915/i915_surface.c

index b5d6d8a01a318e6baca2d8598111153acf24bc6b..d11361b675f8139d4e9273e542314cb4930f74c4 100644 (file)
@@ -40,7 +40,7 @@
 #include "i915_resource.h"
 #include "i915_state.h"
 
-static void
+void
 i915_clear_emit(struct pipe_context *pipe, unsigned buffers, const float *rgba,
                 double depth, unsigned stencil,
                 unsigned destx, unsigned desty, unsigned width, unsigned height)
index 0af62a3465142f7559ac40f3ba8dd6e83735e589..f1a14bc259ec646589e4a6830e393e222da36e17 100644 (file)
@@ -103,6 +103,9 @@ static void i915_destroy(struct pipe_context *pipe)
    int i;
 
    draw_destroy(i915->draw);
+
+   if (i915->blitter)
+      util_blitter_destroy(i915->blitter);
    
    if(i915->batch)
       i915->iws->batchbuffer_destroy(i915->batch);
@@ -167,6 +170,10 @@ i915_create_context(struct pipe_screen *screen, void *priv)
    draw_install_aaline_stage(i915->draw, &i915->base);
    draw_install_aapoint_stage(i915->draw, &i915->base);
 
+   /* Create blitter last - calls state creation functions. */
+   i915->blitter = util_blitter_create(&i915->base);
+   assert(i915->blitter);
+
    i915->dirty = ~0;
    i915->hardware_dirty = ~0;
    i915->immediate_dirty = ~0;
index ed3fb4796b330a73832cff33b220b227776cfc29..96abaf3f23a2f031de0c8c085c171a2d5c87e036 100644 (file)
@@ -38,6 +38,7 @@
 #include "tgsi/tgsi_scan.h"
 
 #include "util/u_slab.h"
+#include "util/u_blitter.h"
 
 
 struct i915_winsys;
@@ -239,6 +240,8 @@ struct i915_context {
 
    struct i915_winsys_batchbuffer *batch;
 
+   struct blitter_context* blitter;
+
    /** Vertex buffer */
    struct i915_winsys_buffer *vbo;
    size_t vbo_offset;
@@ -332,6 +335,9 @@ void i915_clear_blitter(struct pipe_context *pipe, unsigned buffers, const float
                         double depth, unsigned stencil);
 void i915_clear_render(struct pipe_context *pipe, unsigned buffers, const float *rgba,
                        double depth, unsigned stencil);
+void i915_clear_emit(struct pipe_context *pipe, unsigned buffers, const float *rgba,
+                     double depth, unsigned stencil,
+                     unsigned destx, unsigned desty, unsigned width, unsigned height);
 
 
 /***********************************************************************
index 5df370eb0b094668de990c82903feb7410896a46..5dcb6c2ee7fb8855bbaea4905175dcbb9e2d1251 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "i915_surface.h"
 #include "i915_resource.h"
+#include "i915_state.h"
 #include "i915_blit.h"
 #include "i915_reg.h"
 #include "i915_screen.h"
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
 
+/*
+ * surface functions using the render engine
+ */
+
+static void
+i915_clear_render_target_render(struct pipe_context *pipe,
+                                struct pipe_surface *dst,
+                                const float *rgba,
+                                unsigned dstx, unsigned dsty,
+                                unsigned width, unsigned height)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   struct pipe_framebuffer_state fb_state;
+
+   util_blitter_save_framebuffer(i915->blitter, &i915->framebuffer);
+
+   fb_state.width = dst->width;
+   fb_state.height = dst->height;
+   fb_state.nr_cbufs = 1;
+   fb_state.cbufs[0] = dst;
+   fb_state.zsbuf = NULL;
+   pipe->set_framebuffer_state(pipe, &fb_state);
+
+   if (i915->dirty)
+      i915_update_derived(i915);
+
+   i915_clear_emit(pipe, PIPE_CLEAR_COLOR, rgba, 0.0, 0x0,
+                   dstx, dsty, width, height);
+
+   pipe->set_framebuffer_state(pipe, &i915->blitter->saved_fb_state);
+   util_unreference_framebuffer_state(&i915->blitter->saved_fb_state);
+   i915->blitter->saved_fb_state.nr_cbufs = ~0;
+}
+
+static void
+i915_clear_depth_stencil_render(struct pipe_context *pipe,
+                                struct pipe_surface *dst,
+                                unsigned clear_flags,
+                                double depth,
+                                unsigned stencil,
+                                unsigned dstx, unsigned dsty,
+                                unsigned width, unsigned height)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   struct pipe_framebuffer_state fb_state;
+
+   util_blitter_save_framebuffer(i915->blitter, &i915->framebuffer);
+
+   fb_state.width = dst->width;
+   fb_state.height = dst->height;
+   fb_state.nr_cbufs = 0;
+   fb_state.zsbuf = dst;
+   pipe->set_framebuffer_state(pipe, &fb_state);
+
+   if (i915->dirty)
+      i915_update_derived(i915);
+
+   i915_clear_emit(pipe, clear_flags & PIPE_CLEAR_DEPTHSTENCIL,
+                   NULL, depth, stencil,
+                   dstx, dsty, width, height);
+
+   pipe->set_framebuffer_state(pipe, &i915->blitter->saved_fb_state);
+   util_unreference_framebuffer_state(&i915->blitter->saved_fb_state);
+   i915->blitter->saved_fb_state.nr_cbufs = ~0;
+}
+
+/*
+ * surface functions using the blitter
+ */
 
 /* Assumes all values are within bounds -- no checking at this level -
  * do it higher up if required.
@@ -82,11 +152,11 @@ i915_surface_copy(struct pipe_context *pipe,
 
 
 static void
-i915_clear_render_target(struct pipe_context *pipe,
-                         struct pipe_surface *dst,
-                         const float *rgba,
-                         unsigned dstx, unsigned dsty,
-                         unsigned width, unsigned height)
+i915_clear_render_target_blitter(struct pipe_context *pipe,
+                                 struct pipe_surface *dst,
+                                 const float *rgba,
+                                 unsigned dstx, unsigned dsty,
+                                 unsigned width, unsigned height)
 {
    struct i915_texture *tex = i915_texture(dst->texture);
    struct pipe_resource *pt = &tex->b.b;
@@ -108,13 +178,13 @@ i915_clear_render_target(struct pipe_context *pipe,
 }
 
 static void
-i915_clear_depth_stencil(struct pipe_context *pipe,
-                         struct pipe_surface *dst,
-                         unsigned clear_flags,
-                         double depth,
-                         unsigned stencil,
-                         unsigned dstx, unsigned dsty,
-                         unsigned width, unsigned height)
+i915_clear_depth_stencil_blitter(struct pipe_context *pipe,
+                                 struct pipe_surface *dst,
+                                 unsigned clear_flags,
+                                 double depth,
+                                 unsigned stencil,
+                                 unsigned dstx, unsigned dsty,
+                                 unsigned width, unsigned height)
 {
    struct i915_texture *tex = i915_texture(dst->texture);
    struct pipe_resource *pt = &tex->b.b;
@@ -193,8 +263,13 @@ void
 i915_init_surface_functions(struct i915_context *i915)
 {
    i915->base.resource_copy_region = i915_surface_copy;
-   i915->base.clear_render_target = i915_clear_render_target;
-   i915->base.clear_depth_stencil = i915_clear_depth_stencil;
+   if (i915_screen(i915->base.screen)->debug.use_blitter) {
+      i915->base.clear_render_target = i915_clear_render_target_blitter;
+      i915->base.clear_depth_stencil = i915_clear_depth_stencil_blitter;
+   } else {
+      i915->base.clear_render_target = i915_clear_render_target_render;
+      i915->base.clear_depth_stencil = i915_clear_depth_stencil_render;
+   }
    i915->base.create_surface = i915_create_surface;
    i915->base.surface_destroy = i915_surface_destroy;
 }