i915g: handle more formats in copy
authorStéphane Marchesin <marcheu@chromium.org>
Mon, 26 May 2014 13:48:11 +0000 (06:48 -0700)
committerStéphane Marchesin <marcheu@chromium.org>
Tue, 27 May 2014 06:08:49 +0000 (23:08 -0700)
We can handle depth, luminance,... copies by simply replacing the
format with a known format of the same bpp.

src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/i915/i915_state.h
src/gallium/drivers/i915/i915_surface.c

index b2f52d5d689ddf0dd116b794e39a66d1f27ba964..c90fcfd74919e08e11fb72d2bd64078b8b0b6fd2 100644 (file)
@@ -42,6 +42,7 @@
 #include "i915_state_inlines.h"
 #include "i915_fpc.h"
 #include "i915_resource.h"
+#include "i915_state.h"
 
 /* The i915 (and related graphics cores) do not support GL_CLAMP.  The
  * Intel drivers for "other operating systems" implement GL_CLAMP as
@@ -812,6 +813,26 @@ i915_set_sampler_views(struct pipe_context *pipe, unsigned shader,
 }
 
 
+struct pipe_sampler_view *
+i915_create_sampler_view_custom(struct pipe_context *pipe,
+                                struct pipe_resource *texture,
+                                const struct pipe_sampler_view *templ,
+                                unsigned width0,
+                                unsigned height0)
+{
+   struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
+
+   if (view) {
+      *view = *templ;
+      view->reference.count = 1;
+      view->texture = NULL;
+      pipe_resource_reference(&view->texture, texture);
+      view->context = pipe;
+   }
+
+   return view;
+}
+
 static struct pipe_sampler_view *
 i915_create_sampler_view(struct pipe_context *pipe,
                          struct pipe_resource *texture,
index f529329d8c276f830f94695de40ef60d0acac935..56ebb2ddb868780d45ecaa1d9a62b31a282bf15a 100644 (file)
@@ -53,5 +53,11 @@ extern struct i915_tracked_state i915_hw_constants;
 
 void i915_update_derived(struct i915_context *i915);
 void i915_emit_hardware_state(struct i915_context *i915);
+struct pipe_sampler_view *
+i915_create_sampler_view_custom(struct pipe_context *pipe,
+                                struct pipe_resource *texture,
+                                const struct pipe_sampler_view *templ,
+                                unsigned width0,
+                                unsigned height0);
 
 #endif
index df662873001942eed184f1ab9e1d2bc6abd90f84..6e9558e54df01833c7744a7aa11b8d4346ade448 100644 (file)
 #include "util/u_pack_color.h"
 #include "util/u_surface.h"
 
+static struct pipe_surface *
+i915_create_surface_custom(struct pipe_context *ctx,
+                           struct pipe_resource *pt,
+                           const struct pipe_surface *surf_tmpl,
+                           unsigned width0,
+                           unsigned height0);
 /*
  * surface functions using the render engine
  */
@@ -75,25 +81,61 @@ i915_surface_copy_render(struct pipe_context *pipe,
                          struct pipe_resource *src, unsigned src_level,
                          const struct pipe_box *src_box)
 {
+   struct pipe_screen *screen = pipe->screen;
    struct i915_context *i915 = i915_context(pipe);
+   struct i915_texture *dst_tex = i915_texture(dst);
+   struct i915_texture *src_tex = i915_texture(src);
+   unsigned src_width0 = src->width0;
+   unsigned src_height0 = src->height0;
+   unsigned dst_width0 = dst->width0;
+   unsigned dst_height0 = dst->height0;
+   unsigned layout;
+   struct pipe_box dstbox;
+   struct pipe_sampler_view src_templ, *src_view;
+   struct pipe_surface dst_templ, *dst_view;
 
    /* Fallback for buffers. */
-   if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
+   if ((dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER)) {
       util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
                                 src, src_level, src_box);
       return;
    }
 
+   layout = util_format_description(dst_templ.format)->layout;
    if (!util_blitter_is_copy_supported(i915->blitter, dst, src)) {
-      util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
-                                src, src_level, src_box);
-      return;
+      switch (util_format_get_blocksize(dst_templ.format)) {
+         case 1:
+            dst_templ.format = PIPE_FORMAT_I8_UNORM;
+            break;
+         case 2:
+            dst_templ.format = PIPE_FORMAT_B5G6R5_UNORM;
+            break;
+         case 4:
+            dst_templ.format = PIPE_FORMAT_B8G8R8A8_UNORM;
+            break;
+         default:
+            debug_printf("i915: copy_region: Unhandled format: %s. Falling back to software.\n"
+                         "i915: copy_region: Software fallback doesn't work for tiled textures.\n",
+                         util_format_short_name(dst_templ.format));
+      }
+      src_templ.format = dst_templ.format;
    }
 
    i915_util_blitter_save_states(i915);
 
-   util_blitter_copy_texture(i915->blitter, dst, dst_level, dstx, dsty, dstz,
-                            src, src_level, src_box);
+   util_blitter_default_dst_texture(&dst_templ, dst, dst_level, dstz);
+   util_blitter_default_src_texture(&src_templ, src, src_level);
+
+   dst_view = i915_create_surface_custom(pipe, dst, &dst_templ, dst_width0, dst_height0);
+   src_view = i915_create_sampler_view_custom(pipe, src, &src_templ, src_width0, src_height0);
+
+   u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height),
+            abs(src_box->depth), &dstbox);
+
+   util_blitter_blit_generic(i915->blitter, dst_view, &dstbox,
+                             src_view, src_box, src_width0, src_height0,
+                             PIPE_MASK_RGBAZS, PIPE_TEX_FILTER_NEAREST, NULL);
 }
 
 static void
@@ -314,9 +356,11 @@ i915_clear_depth_stencil_blitter(struct pipe_context *pipe,
 
 
 static struct pipe_surface *
-i915_create_surface(struct pipe_context *ctx,
-                    struct pipe_resource *pt,
-                    const struct pipe_surface *surf_tmpl)
+i915_create_surface_custom(struct pipe_context *ctx,
+                           struct pipe_resource *pt,
+                           const struct pipe_surface *surf_tmpl,
+                           unsigned width0,
+                           unsigned height0)
 {
    struct pipe_surface *ps;
 
@@ -331,8 +375,8 @@ i915_create_surface(struct pipe_context *ctx,
       pipe_reference_init(&ps->reference, 1);
       pipe_resource_reference(&ps->texture, pt);
       ps->format = surf_tmpl->format;
-      ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level);
-      ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level);
+      ps->width = u_minify(width0, surf_tmpl->u.tex.level);
+      ps->height = u_minify(height0, surf_tmpl->u.tex.level);
       ps->u.tex.level = surf_tmpl->u.tex.level;
       ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
       ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
@@ -341,6 +385,15 @@ i915_create_surface(struct pipe_context *ctx,
    return ps;
 }
 
+static struct pipe_surface *
+i915_create_surface(struct pipe_context *ctx,
+                    struct pipe_resource *pt,
+                    const struct pipe_surface *surf_tmpl)
+{
+   return i915_create_surface_custom(ctx, pt, surf_tmpl,
+                                     pt->width0, pt->height0);
+}
+
 static void
 i915_surface_destroy(struct pipe_context *ctx,
                      struct pipe_surface *surf)