i915g: Support more texture and render target formats.
authorStéphane Marchesin <marcheu@chromium.org>
Wed, 22 Jun 2011 23:23:02 +0000 (16:23 -0700)
committerStéphane Marchesin <marcheu@chromium.org>
Wed, 22 Jun 2011 23:44:54 +0000 (16:44 -0700)
src/gallium/drivers/i915/i915_clear.c
src/gallium/drivers/i915/i915_screen.c
src/gallium/drivers/i915/i915_state_emit.c
src/gallium/drivers/i915/i915_state_sampler.c
src/gallium/drivers/i915/i915_state_static.c

index 4a97746e981eeb9865faa59ed686def381da6ed8..fcb208d6dae2f4cf9c7e68bb301c14e78b30e587 100644 (file)
@@ -66,7 +66,7 @@ i915_clear_emit(struct pipe_context *pipe, unsigned buffers, const float *rgba,
       else
          clear_color = (u_color.ui & 0xffff) | (u_color.ui << 16);
 
-      util_pack_color(rgba, PIPE_FORMAT_B8G8R8A8_UNORM, &u_color);
+      util_pack_color(rgba, cbuf->format, &u_color);
       clear_color8888 = u_color.ui;
    } else
       clear_color = clear_color8888 = 0;
index c86baa58b2897e7c2aa059e9b8c0a8c98d89a370..ec070568f4eea427a4ea3b89c272c17a6486268a 100644 (file)
@@ -264,6 +264,8 @@ i915_is_format_supported(struct pipe_screen *screen,
    static const enum pipe_format tex_supported[] = {
       PIPE_FORMAT_B8G8R8A8_UNORM,
       PIPE_FORMAT_B8G8R8X8_UNORM,
+      PIPE_FORMAT_R8G8B8A8_UNORM,
+      PIPE_FORMAT_R8G8B8X8_UNORM,
       PIPE_FORMAT_B5G6R5_UNORM,
       PIPE_FORMAT_L8_UNORM,
       PIPE_FORMAT_A8_UNORM,
@@ -283,7 +285,11 @@ i915_is_format_supported(struct pipe_screen *screen,
    };
    static const enum pipe_format render_supported[] = {
       PIPE_FORMAT_B8G8R8A8_UNORM,
+      PIPE_FORMAT_R8G8B8A8_UNORM,
       PIPE_FORMAT_B5G6R5_UNORM,
+      PIPE_FORMAT_L8_UNORM,
+      PIPE_FORMAT_A8_UNORM,
+      PIPE_FORMAT_I8_UNORM,
       PIPE_FORMAT_NONE  /* list terminator */
    };
    static const enum pipe_format depth_supported[] = {
index 0155cd8351004e9420b926514169667255ed2b6e..b7ccba8cd83ad66742270d565e61d5786dc2977d 100644 (file)
@@ -34,7 +34,9 @@
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
+#include "pipe/p_format.h"
 
+#include "util/u_format.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
@@ -341,21 +343,72 @@ emit_constants(struct i915_context *i915)
    }
 }
 
+static const struct
+{
+   enum pipe_format format;
+   uint hw_swizzle;
+} fixup_formats[] = {
+   { PIPE_FORMAT_R8G8B8A8_UNORM, 0x21030000 /* BGRA */},
+   { PIPE_FORMAT_L8_UNORM,       0x00000000 /* RRRR */},
+   { PIPE_FORMAT_I8_UNORM,       0x00000000 /* RRRR */},
+   { PIPE_FORMAT_A8_UNORM,       0x33330000 /* AAAA */},
+   { PIPE_FORMAT_NONE,           0x00000000},
+};
+
+static boolean need_fixup(enum pipe_format f)
+{
+   for(int i=0; fixup_formats[i].format != PIPE_FORMAT_NONE; i++)
+      if (fixup_formats[i].format == f)
+         return TRUE;
+
+   return FALSE;
+}
+
+static uint fixup_swizzle(enum pipe_format f)
+{
+   for(int i=0; fixup_formats[i].format != PIPE_FORMAT_NONE; i++)
+      if (fixup_formats[i].format == f)
+         return fixup_formats[i].hw_swizzle;
+
+   return 0;
+}
+
 static void
 validate_program(struct i915_context *i915, unsigned *batch_space)
 {
-   *batch_space = i915->fs->program_len;
+   struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
+
+   /* we need more batch space if we want to emulate rgba framebuffers */
+   *batch_space = i915->fs->program_len + (need_fixup(cbuf_surface->format) ? 3 : 0);
 }
 
 static void
 emit_program(struct i915_context *i915)
 {
-      uint i;
-      /* we should always have, at least, a pass-through program */
-      assert(i915->fs->program_len > 0);
-      for (i = 0; i < i915->fs->program_len; i++) {
-         OUT_BATCH(i915->fs->program[i]);
-      }
+   struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
+   boolean need_format_fixup = need_fixup(cbuf_surface->format);
+   uint i;
+
+   /* we should always have, at least, a pass-through program */
+   assert(i915->fs->program_len > 0);
+   for (i = 0; i < i915->fs->program_len; i++) {
+         if ((i == 0) && need_format_fixup)
+            OUT_BATCH(i915->fs->program[i] + 3);
+         else
+            OUT_BATCH(i915->fs->program[i]);
+   }
+
+   /* we emit an additional mov with swizzle to fake RGBA framebuffers */
+   if (need_format_fixup) {
+      /* mov out_color, out_color.zyxw */
+      OUT_BATCH(A0_MOV |
+                (REG_TYPE_OC << A0_DEST_TYPE_SHIFT) |
+                A0_DEST_CHANNEL_ALL |
+                (REG_TYPE_OC << A0_SRC0_TYPE_SHIFT) |
+                (T_DIFFUSE << A0_SRC0_NR_SHIFT));
+      OUT_BATCH(fixup_swizzle(cbuf_surface->format));
+      OUT_BATCH(0);
+   }
 }
 
 static void
index be70e7a92c9c9cab472aae82e16b0b96c4818221..aa1dd443fbc869be561f9a28def08e4dadbbbe4f 100644 (file)
@@ -208,10 +208,8 @@ static uint translate_texture_format(enum pipe_format pipeFormat)
       return MAPSURF_32BIT | MT_32BIT_XRGB8888;
    case PIPE_FORMAT_R8G8B8A8_UNORM:
       return MAPSURF_32BIT | MT_32BIT_ABGR8888;
-#if 0
    case PIPE_FORMAT_R8G8B8X8_UNORM:
       return MAPSURF_32BIT | MT_32BIT_XBGR8888;
-#endif
    case PIPE_FORMAT_YUYV:
       return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
    case PIPE_FORMAT_UYVY:
index 2865298318c965d3b68ca437176e01f248bb18ae..7116c0a5ca13c583668cf1252aa1f82895a8301b 100644 (file)
@@ -42,6 +42,12 @@ static unsigned translate_format(enum pipe_format format)
       return COLOR_BUF_ARGB8888;
    case PIPE_FORMAT_B5G6R5_UNORM:
       return COLOR_BUF_RGB565;
+   case PIPE_FORMAT_R8G8B8A8_UNORM:
+      return COLOR_BUF_ARGB8888;
+   case PIPE_FORMAT_L8_UNORM:
+   case PIPE_FORMAT_A8_UNORM:
+   case PIPE_FORMAT_I8_UNORM:
+      return COLOR_BUF_8BIT;
    default:
       assert(0);
       return 0;
@@ -137,7 +143,8 @@ static void update_framebuffer(struct i915_context *i915)
       i915->static_dirty |= I915_DST_RECT;
    }
 
-   i915->hardware_dirty |= I915_HW_STATIC;
+   /* we also send a new program to make sure the fixup for RGBA surfaces happens */
+   i915->hardware_dirty |= I915_HW_STATIC | I915_HW_PROGRAM;
 
    /* flush the cache in case we sample from the old renderbuffers */
    i915_set_flush_dirty(i915, I915_FLUSH_CACHE);