svga: implement blit
authorMarek Olšák <maraeo@gmail.com>
Wed, 12 Sep 2012 22:50:54 +0000 (00:50 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 30 Sep 2012 16:57:57 +0000 (18:57 +0200)
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_blit.c
src/gallium/drivers/svga/svga_swtnl_draw.c

index cc1ac84adfc7de71e82cbb4a07868f7896f09ac4..7147d5a8f87f0c7bea204c04824c9dc2784fc9be 100644 (file)
@@ -56,6 +56,8 @@ static void svga_destroy( struct pipe_context *pipe )
    struct svga_context *svga = svga_context( pipe );
    unsigned shader;
 
+   util_blitter_destroy(svga->blitter);
+
    svga_cleanup_framebuffer( svga );
    svga_cleanup_tss_binding( svga );
 
index f243b4f5da6cf4b53b734a6a20070bbf253b6b70..f2f26da1cd53d719c840c4bd83219e38cce0cde5 100644 (file)
@@ -31,6 +31,7 @@
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
 
+#include "util/u_blitter.h"
 #include "util/u_double_list.h"
 
 #include "tgsi/tgsi_scan.h"
@@ -314,6 +315,7 @@ struct svga_context
 {
    struct pipe_context pipe;
    struct svga_winsys_context *swc;
+   struct blitter_context *blitter;
 
    struct {
       boolean no_swtnl;
index 8e114d3e30eb745332bf4135848de31ccdbe325a..34ac995ef60cd529c485f595eb244c5a66ea6f7a 100644 (file)
@@ -29,6 +29,7 @@
 #include "svga_cmd.h"
 #include "svga_surface.h"
 
+#include "util/u_format.h"
 #include "util/u_surface.h"
 
 #define FILE_DEBUG_FLAG DEBUG_BLIT
@@ -150,8 +151,71 @@ static void svga_surface_copy(struct pipe_context *pipe,
 }
 
 
+static void svga_blit(struct pipe_context *pipe,
+                      const struct pipe_blit_info *blit_info)
+{
+   struct svga_context *svga = svga_context(pipe);
+   struct pipe_blit_info info = *blit_info;
+
+   if (info.src.resource->nr_samples > 1 &&
+       info.dst.resource->nr_samples <= 1 &&
+       !util_format_is_depth_or_stencil(info.src.resource->format) &&
+       !util_format_is_pure_integer(info.src.resource->format)) {
+      debug_printf("svga: color resolve unimplemented\n");
+      return;
+   }
+
+   if (util_try_blit_via_copy_region(pipe, &info)) {
+      return; /* done */
+   }
+
+   if (info.mask & PIPE_MASK_S) {
+      debug_printf("svga: cannot blit stencil, skipping\n");
+      info.mask &= ~PIPE_MASK_S;
+   }
+
+   if (!util_blitter_is_blit_supported(svga->blitter, &info)) {
+      debug_printf("svga: blit unsupported %s -> %s\n",
+                   util_format_short_name(info.src.resource->format),
+                   util_format_short_name(info.dst.resource->format));
+      return;
+   }
+
+   /* XXX turn off occlusion and streamout queries */
+
+   util_blitter_save_vertex_buffers(svga->blitter,
+                                    svga->curr.num_vertex_buffers,
+                                    svga->curr.vb);
+   util_blitter_save_vertex_elements(svga->blitter, (void*)svga->curr.velems);
+   util_blitter_save_vertex_shader(svga->blitter, svga->curr.vs);
+   /*util_blitter_save_geometry_shader(svga->blitter, svga->curr.gs);*/
+   /*util_blitter_save_so_targets(svga->blitter, svga->num_so_targets,
+                     (struct pipe_stream_output_target**)svga->so_targets);*/
+   util_blitter_save_rasterizer(svga->blitter, (void*)svga->curr.rast);
+   util_blitter_save_viewport(svga->blitter, &svga->curr.viewport);
+   util_blitter_save_scissor(svga->blitter, &svga->curr.scissor);
+   util_blitter_save_fragment_shader(svga->blitter, svga->curr.fs);
+   util_blitter_save_blend(svga->blitter, (void*)svga->curr.blend);
+   util_blitter_save_depth_stencil_alpha(svga->blitter,
+                                         (void*)svga->curr.depth);
+   util_blitter_save_stencil_ref(svga->blitter, &svga->curr.stencil_ref);
+   /*util_blitter_save_sample_mask(svga->blitter, svga->sample_mask);*/
+   util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer);
+   util_blitter_save_fragment_sampler_states(svga->blitter,
+                     svga->curr.num_samplers,
+                     (void**)svga->curr.sampler);
+   util_blitter_save_fragment_sampler_views(svga->blitter,
+                     svga->curr.num_sampler_views,
+                     svga->curr.sampler_views);
+   /*util_blitter_save_render_condition(svga->blitter, svga->render_cond_query,
+                                      svga->render_cond_mode);*/
+   util_blitter_blit(svga->blitter, &info);
+}
+
+
 void
 svga_init_blit_functions(struct svga_context *svga)
 {
    svga->pipe.resource_copy_region = svga_surface_copy;
+   svga->pipe.blit = svga_blit;
 }
index 212f11a8230805ed88b7a94e80324e2923d83f53..4aeeb673ec938728b62d30e6897f3d1974e87c05 100644 (file)
@@ -154,6 +154,13 @@ boolean svga_init_swtnl( struct svga_context *svga )
 
    draw_set_render(svga->swtnl.draw, svga->swtnl.backend);
 
+   svga->blitter = util_blitter_create(&svga->pipe);
+   if (!svga->blitter)
+      goto fail;
+
+   /* must be done before installing Draw stages */
+   util_blitter_cache_all_shaders(svga->blitter);
+
    draw_install_aaline_stage(svga->swtnl.draw, &svga->pipe);
    draw_install_aapoint_stage(svga->swtnl.draw, &svga->pipe);
    draw_install_pstipple_stage(svga->swtnl.draw, &svga->pipe);
@@ -164,6 +171,9 @@ boolean svga_init_swtnl( struct svga_context *svga )
    return TRUE;
 
 fail:
+   if (svga->blitter)
+      util_blitter_destroy(svga->blitter);
+
    if (svga->swtnl.backend)
       svga->swtnl.backend->destroy( svga->swtnl.backend );