st/mesa: handle SNORM formats in generic CopyPixels path
authorMarek Olšák <maraeo@gmail.com>
Thu, 6 Jun 2013 11:45:24 +0000 (13:45 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 30 Jun 2013 20:14:37 +0000 (22:14 +0200)
v2: check desc->is_mixed in util_format_is_snorm

src/gallium/auxiliary/util/u_format.c
src/gallium/auxiliary/util/u_format.h
src/mesa/state_tracker/st_cb_drawpixels.c

index 9bdc2eabf11502ec5825cb4ca7a9f8d1fbb0dbd7..686ca8a898e8990667409dfae512cf53d1e7de51 100644 (file)
@@ -131,6 +131,26 @@ util_format_is_pure_uint(enum pipe_format format)
    return (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED && desc->channel[i].pure_integer) ? TRUE : FALSE;
 }
 
+/**
+ * Returns true if all non-void channels are normalized signed.
+ */
+boolean
+util_format_is_snorm(enum pipe_format format)
+{
+   const struct util_format_description *desc = util_format_description(format);
+   int i;
+
+   if (desc->is_mixed)
+      return FALSE;
+
+   i = util_format_get_first_non_void_channel(format);
+   if (i == -1)
+      return FALSE;
+
+   return desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED &&
+          !desc->channel[i].pure_integer &&
+          desc->channel[i].normalized;
+}
 
 boolean
 util_format_is_luminance_alpha(enum pipe_format format)
index 9774a2b4c82c0d26df4652b8339bcb7a3645a42d..bb729c0959b6276bbb25ab8a9ca2c8cd2d648b5e 100644 (file)
@@ -645,6 +645,9 @@ util_format_is_pure_sint(enum pipe_format format);
 boolean
 util_format_is_pure_uint(enum pipe_format format);
 
+boolean
+util_format_is_snorm(enum pipe_format format);
+
 /**
  * Check if the src format can be blitted to the destination format with
  * a simple memcpy.  For example, blitting from RGBA to RGBx is OK, but not
index 0200a627025ff126994ff7b2d11bd8b0f9b502f3..2ce4728ad8dffc975978d366d35745830982b4dc 100644 (file)
@@ -1546,6 +1546,7 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
 
    if (!screen->is_format_supported(screen, srcFormat, st->internal_target, 0,
                                     srcBind)) {
+      /* srcFormat is non-renderable. Find a compatible renderable format. */
       if (type == GL_DEPTH) {
          srcFormat = st_choose_format(st, GL_DEPTH_COMPONENT, GL_NONE,
                                       GL_NONE, st->internal_target, 0,
@@ -1569,6 +1570,11 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
                                          GL_NONE, st->internal_target, 0,
                                          srcBind, FALSE);
          }
+         else if (util_format_is_snorm(srcFormat)) {
+            srcFormat = st_choose_format(st, GL_RGBA16_SNORM, GL_NONE,
+                                         GL_NONE, st->internal_target, 0,
+                                         srcBind, FALSE);
+         }
          else {
             srcFormat = st_choose_format(st, GL_RGBA, GL_NONE,
                                          GL_NONE, st->internal_target, 0,