mesa/st: initial attempt at RG support for gallium drivers
authorDave Airlie <airlied@redhat.com>
Wed, 11 Aug 2010 09:04:05 +0000 (19:04 +1000)
committerDave Airlie <airlied@redhat.com>
Sat, 2 Oct 2010 07:03:15 +0000 (17:03 +1000)
passes all piglit RG tests with softpipe.

src/mesa/state_tracker/st_atom_texture.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c

index 981129621c745d954c29262d99d4842ee6ceeda0..029b0403462f6c9bca782a475217c4ef8cecd50d 100644 (file)
@@ -52,7 +52,7 @@
  *
  * \param format     PIPE_FORMAT_*.
  * \param swizzle    Texture swizzle, a bitmask computed using MAKE_SWIZZLE4.
- * \param depthmode  One of GL_LUMINANCE, GL_INTENSITY, GL_ALPHA.
+ * \param depthmode  One of GL_LUMINANCE, GL_INTENSITY, GL_ALPHA, GL_RED.
  */
 static GLuint apply_depthmode(enum pipe_format format,
                               GLuint swizzle, GLenum depthmode)
@@ -96,6 +96,14 @@ static GLuint apply_depthmode(enum pipe_format format,
             else if (swiz[i] < SWIZZLE_W)
                swiz[i] = SWIZZLE_ZERO;
          break;
+      case GL_RED:
+        /* Rewrite reads W to 1, XYZ to X00 */
+        for (i = 0; i < 4; i++)
+           if (swiz[i] == SWIZZLE_W)
+              swiz[i] = SWIZZLE_ONE;
+           else if (swiz[i] == SWIZZLE_Y || swiz[i] == SWIZZLE_Z)
+              swiz[i] = SWIZZLE_ZERO;
+        break;
    }
 
    return MAKE_SWIZZLE4(swiz[0], swiz[1], swiz[2], swiz[3]);
index 71bd4729e03dc5862109cccddc4f79a95997b559..ac1f6812b85f96fa1a166d4ff427f4a285e833df 100644 (file)
@@ -260,6 +260,18 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
    case PIPE_FORMAT_R16G16B16A16_SNORM:
       strb->Base.InternalFormat = GL_RGBA16;
       break;
+   case PIPE_FORMAT_R8_UNORM:
+      strb->Base.InternalFormat = GL_R8;
+      break;
+   case PIPE_FORMAT_R8G8_UNORM:
+      strb->Base.InternalFormat = GL_RG8;
+      break;
+   case PIPE_FORMAT_R16_UNORM:
+      strb->Base.InternalFormat = GL_R16;
+      break;
+   case PIPE_FORMAT_R16G16_UNORM:
+      strb->Base.InternalFormat = GL_RG16;
+      break;
    default:
       _mesa_problem(NULL,
                    "Unexpected format in st_new_renderbuffer_fb");
index 225f75e3af0824ee2850904e012d9f1246a63977..9b09601bbc52fbefacbf8c60de0860e4eca43e2c 100644 (file)
@@ -373,6 +373,12 @@ void st_init_extensions(struct st_context *st)
       ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
    }
 
+   if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
+                                   PIPE_TEXTURE_2D, 0,
+                                   PIPE_BIND_SAMPLER_VIEW, 0)) {
+      ctx->Extensions.ARB_texture_rg = GL_TRUE;
+   }
+
    /* s3tc support */
    if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
                                    PIPE_TEXTURE_2D, 0,
index 95064605d7f90ba6e0635758fa1b8df7844f87e5..b7c54cef841df83c14b44cf037d3f2946b963e01 100644 (file)
@@ -202,6 +202,14 @@ st_mesa_format_to_pipe_format(gl_format mesaFormat)
    case MESA_FORMAT_SARGB8:
       return PIPE_FORMAT_B8G8R8A8_SRGB;
 #endif
+   case MESA_FORMAT_R8:
+      return PIPE_FORMAT_R8_UNORM;
+   case MESA_FORMAT_R16:
+      return PIPE_FORMAT_R16_UNORM;
+   case MESA_FORMAT_RG88:
+      return PIPE_FORMAT_R8G8_UNORM;
+   case MESA_FORMAT_RG1616:
+      return PIPE_FORMAT_R16G16_UNORM;
    default:
       assert(0);
       return PIPE_FORMAT_NONE;
@@ -299,6 +307,15 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
    case PIPE_FORMAT_B8G8R8A8_SRGB:
       return MESA_FORMAT_SARGB8;
 #endif
+
+   case PIPE_FORMAT_R8_UNORM:
+      return MESA_FORMAT_R8;
+   case PIPE_FORMAT_R16_UNORM:
+      return MESA_FORMAT_R16;
+   case PIPE_FORMAT_R8G8_UNORM:
+      return MESA_FORMAT_RG88;
+   case PIPE_FORMAT_R16G16_UNORM:
+      return MESA_FORMAT_RG1616;
    default:
       assert(0);
       return MESA_FORMAT_NONE;
@@ -688,6 +705,55 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
       return default_srgba_format( screen, target, sample_count, bindings,
                                    geom_flags );
 
+   case GL_RED:
+   case GL_R8:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_R8_UNORM;
+      return PIPE_FORMAT_NONE;
+   case GL_RG:
+   case GL_RG8:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_R8G8_UNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_R16:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_R16_UNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_R16_UNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_RG16:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_R16G16_UNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_COMPRESSED_RED_RGTC1:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_UNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_RGTC1_UNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_COMPRESSED_SIGNED_RED_RGTC1:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC1_SNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_RGTC1_SNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_COMPRESSED_RG_RGTC2:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_UNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_RGTC2_UNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_COMPRESSED_SIGNED_RG_RGTC2:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_RGTC2_SNORM, target,
+                                     sample_count, bindings, geom_flags))
+             return PIPE_FORMAT_RGTC2_SNORM;
+      return PIPE_FORMAT_NONE;
+
    default:
       return PIPE_FORMAT_NONE;
    }