i915g: implement copy_region using u_blitter
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 11 Mar 2011 19:21:00 +0000 (20:21 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Sat, 12 Mar 2011 19:32:29 +0000 (20:32 +0100)
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>works
src/gallium/drivers/i915/i915_context.c
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/i915/i915_surface.c

index f1a14bc259ec646589e4a6830e393e222da36e17..5dbf0cfcbf12b07a53f4c3aca367308ec8fec83b 100644 (file)
@@ -170,6 +170,9 @@ 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);
 
+   /* augmented draw pipeline clobbers state functions */
+   i915_init_fixup_state_functions(i915);
+
    /* Create blitter last - calls state creation functions. */
    i915->blitter = util_blitter_create(&i915->base);
    assert(i915->blitter);
index 62becbcccbf00b4190d1782954ee0633022daf0c..51a364b042c04c712e15bd692d25c01207e38bb4 100644 (file)
@@ -240,8 +240,6 @@ struct i915_context {
 
    struct i915_winsys_batchbuffer *batch;
 
-   struct blitter_context* blitter;
-
    /** Vertex buffer */
    struct i915_winsys_buffer *vbo;
    size_t vbo_offset;
@@ -257,6 +255,26 @@ struct i915_context {
    int num_validation_buffers;
 
    struct util_slab_mempool transfer_pool;
+
+   /** blitter/hw-clear */
+   struct blitter_context* blitter;
+
+   /** State tracking needed by u_blitter for save/restore. */
+   void *saved_fs;
+   void (*saved_bind_fs_state)(struct pipe_context *pipe, void *shader);
+   void *saved_vs;
+   struct pipe_clip_state saved_clip;
+   struct i915_velems_state *saved_velems;
+   unsigned saved_nr_vertex_buffers;
+   struct pipe_vertex_buffer saved_vertex_buffers[PIPE_MAX_ATTRIBS];
+   unsigned saved_nr_samplers;
+   void *saved_samplers[PIPE_MAX_SAMPLERS];
+   void (*saved_bind_sampler_states)(struct pipe_context *pipe,
+                                     unsigned num, void **sampler);
+   unsigned saved_nr_sampler_views;
+   struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
+   void (*saved_set_sampler_views)(struct pipe_context *pipe,
+                                   unsigned num, struct pipe_sampler_view **views);
 };
 
 /* A flag for each state_tracker state object:
@@ -344,6 +362,7 @@ void i915_clear_emit(struct pipe_context *pipe, unsigned buffers, const float *r
  * 
  */
 void i915_init_state_functions( struct i915_context *i915 );
+void i915_init_fixup_state_functions( struct i915_context *i915 );
 void i915_init_flush_functions( struct i915_context *i915 );
 void i915_init_string_functions( struct i915_context *i915 );
 
index 4d134c1e163643a4ccc7424ae5c3f54ab94fdc27..1b57c5776f21e7c819ec556bc522ad18a1b4fb3f 100644 (file)
@@ -287,6 +287,17 @@ i915_create_sampler_state(struct pipe_context *pipe,
    return cso;
 }
 
+static void i915_fixup_bind_sampler_states(struct pipe_context *pipe,
+                                           unsigned num, void **sampler)
+{
+   struct i915_context *i915 = i915_context(pipe);
+
+   i915->saved_nr_samplers = num;
+   memcpy(&i915->saved_samplers, sampler, sizeof(void *) * num);
+
+   i915->saved_bind_sampler_states(pipe, num, sampler);
+}
+
 static void i915_bind_sampler_states(struct pipe_context *pipe,
                                      unsigned num, void **sampler)
 {
@@ -465,6 +476,17 @@ i915_create_fs_state(struct pipe_context *pipe,
    return ifs;
 }
 
+static void
+i915_fixup_bind_fs_state(struct pipe_context *pipe, void *shader)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   draw_flush(i915->draw);
+
+   i915->saved_fs = shader;
+
+   i915->saved_bind_fs_state(pipe, shader);
+}
+
 static void
 i915_bind_fs_state(struct pipe_context *pipe, void *shader)
 {
@@ -505,6 +527,8 @@ static void i915_bind_vs_state(struct pipe_context *pipe, void *shader)
 {
    struct i915_context *i915 = i915_context(pipe);
 
+   i915->saved_vs = shader;
+
    /* just pass-through to draw module */
    draw_bind_vertex_shader(i915->draw, (struct draw_vertex_shader *) shader);
 
@@ -571,6 +595,27 @@ static void i915_set_constant_buffer(struct pipe_context *pipe,
 }
 
 
+static void
+i915_fixup_set_fragment_sampler_views(struct pipe_context *pipe,
+                                      unsigned num,
+                                      struct pipe_sampler_view **views)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   int i;
+
+   for (i = 0; i < num; i++)
+      pipe_sampler_view_reference(&i915->saved_sampler_views[i],
+                                  views[i]);
+
+   for (i = num; i < i915->saved_nr_sampler_views; i++)
+      pipe_sampler_view_reference(&i915->saved_sampler_views[i],
+                                  NULL);
+
+   i915->saved_nr_sampler_views = num;
+
+   i915->saved_set_sampler_views(pipe, num, views);
+}
+
 static void i915_set_fragment_sampler_views(struct pipe_context *pipe,
                                             unsigned num,
                                             struct pipe_sampler_view **views)
@@ -658,6 +703,8 @@ static void i915_set_clip_state( struct pipe_context *pipe,
    struct i915_context *i915 = i915_context(pipe);
    draw_flush(i915->draw);
 
+   i915->saved_clip = *clip;
+
    draw_set_clip_state(i915->draw, clip);
 
    i915->dirty |= I915_NEW_CLIP;
@@ -779,6 +826,9 @@ static void i915_set_vertex_buffers(struct pipe_context *pipe,
    struct draw_context *draw = i915->draw;
    int i;
 
+   util_copy_vertex_buffers(i915->saved_vertex_buffers,
+                            &i915->saved_nr_vertex_buffers,
+                            buffers, count);
 #if 0
    /* XXX doesn't look like this is needed */
    /* unmap old */
@@ -819,6 +869,8 @@ i915_bind_vertex_elements_state(struct pipe_context *pipe,
    struct i915_context *i915 = i915_context(pipe);
    struct i915_velems_state *i915_velems = (struct i915_velems_state *) velems;
 
+   i915->saved_velems = velems;
+
    /* pass-through to draw module */
    if (i915_velems) {
       draw_set_vertex_elements(i915->draw,
@@ -897,3 +949,14 @@ i915_init_state_functions( struct i915_context *i915 )
    i915->base.set_index_buffer = i915_set_index_buffer;
    i915->base.redefine_user_buffer = u_default_redefine_user_buffer;
 }
+
+void
+i915_init_fixup_state_functions( struct i915_context *i915 )
+{
+   i915->saved_bind_fs_state = i915->base.bind_fs_state;
+   i915->base.bind_fs_state = i915_fixup_bind_fs_state;
+   i915->saved_bind_sampler_states = i915->base.bind_fragment_sampler_states;
+   i915->base.bind_fragment_sampler_states = i915_fixup_bind_sampler_states;
+   i915->saved_set_sampler_views = i915->base.set_fragment_sampler_views;
+   i915->base.set_fragment_sampler_views = i915_fixup_set_fragment_sampler_views;
+}
index 5dcb6c2ee7fb8855bbaea4905175dcbb9e2d1251..d02c420f6c236b0b6bf5c51c57a4ce5b0c5d4dd4 100644 (file)
  * surface functions using the render engine
  */
 
+static void
+i915_surface_copy_render(struct pipe_context *pipe,
+                         struct pipe_resource *dst, unsigned dst_level,
+                         unsigned dstx, unsigned dsty, unsigned dstz,
+                         struct pipe_resource *src, unsigned src_level,
+                         const struct pipe_box *src_box)
+{
+   struct i915_context *i915 = i915_context(pipe);
+
+   util_blitter_save_blend(i915->blitter, (void *)i915->blend);
+   util_blitter_save_depth_stencil_alpha(i915->blitter, (void *)i915->depth_stencil);
+   util_blitter_save_stencil_ref(i915->blitter, &i915->stencil_ref);
+   util_blitter_save_rasterizer(i915->blitter, (void *)i915->rasterizer);
+   util_blitter_save_fragment_shader(i915->blitter, i915->saved_fs);
+   util_blitter_save_vertex_shader(i915->blitter, i915->saved_vs);
+   util_blitter_save_viewport(i915->blitter, &i915->viewport);
+   util_blitter_save_clip(i915->blitter, &i915->saved_clip);
+   util_blitter_save_vertex_elements(i915->blitter, i915->saved_velems);
+   util_blitter_save_vertex_buffers(i915->blitter, i915->saved_nr_vertex_buffers,
+                                    i915->saved_vertex_buffers);
+
+   util_blitter_save_framebuffer(i915->blitter, &i915->framebuffer);
+
+   util_blitter_save_fragment_sampler_states(i915->blitter,
+                                             i915->saved_nr_samplers,
+                                             i915->saved_samplers);
+   util_blitter_save_fragment_sampler_views(i915->blitter,
+                                            i915->saved_nr_sampler_views,
+                                            i915->saved_sampler_views);
+
+   util_blitter_copy_region(i915->blitter, dst, dst_level, dstx, dsty, dstz,
+                            src, src_level, src_box, TRUE);
+}
+
 static void
 i915_clear_render_target_render(struct pipe_context *pipe,
                                 struct pipe_surface *dst,
@@ -112,11 +146,11 @@ i915_clear_depth_stencil_render(struct pipe_context *pipe,
  * do it higher up if required.
  */
 static void
-i915_surface_copy(struct pipe_context *pipe,
-                  struct pipe_resource *dst, unsigned dst_level,
-                  unsigned dstx, unsigned dsty, unsigned dstz,
-                  struct pipe_resource *src, unsigned src_level,
-                  const struct pipe_box *src_box)
+i915_surface_copy_blitter(struct pipe_context *pipe,
+                          struct pipe_resource *dst, unsigned dst_level,
+                          unsigned dstx, unsigned dsty, unsigned dstz,
+                          struct pipe_resource *src, unsigned src_level,
+                          const struct pipe_box *src_box)
 {
    struct i915_texture *dst_tex = i915_texture(dst);
    struct i915_texture *src_tex = i915_texture(src);
@@ -150,7 +184,6 @@ i915_surface_copy(struct pipe_context *pipe,
                    (short) src_box->width, (short) src_box->height );
 }
 
-
 static void
 i915_clear_render_target_blitter(struct pipe_context *pipe,
                                  struct pipe_surface *dst,
@@ -262,11 +295,12 @@ i915_surface_destroy(struct pipe_context *ctx,
 void
 i915_init_surface_functions(struct i915_context *i915)
 {
-   i915->base.resource_copy_region = i915_surface_copy;
    if (i915_screen(i915->base.screen)->debug.use_blitter) {
+      i915->base.resource_copy_region = i915_surface_copy_blitter;
       i915->base.clear_render_target = i915_clear_render_target_blitter;
       i915->base.clear_depth_stencil = i915_clear_depth_stencil_blitter;
    } else {
+      i915->base.resource_copy_region = i915_surface_copy_render;
       i915->base.clear_render_target = i915_clear_render_target_render;
       i915->base.clear_depth_stencil = i915_clear_depth_stencil_render;
    }