r600g: pad the DMA CS to a multiple of 8 dwords
[mesa.git] / src / mesa / main / texcompress.c
index 58b346be39429e2fd4bb61663f08befb97280899..734294e4536da7fc84d980587f864b5ec8b7850b 100644 (file)
 #include "formats.h"
 #include "mfeatures.h"
 #include "mtypes.h"
+#include "context.h"
 #include "texcompress.h"
 #include "texcompress_fxt1.h"
 #include "texcompress_rgtc.h"
 #include "texcompress_s3tc.h"
 #include "texcompress_etc.h"
-#include "swrast/s_context.h"
 
 
 /**
@@ -265,7 +265,8 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
          n += 3;
       }
    }
-   if (ctx->Extensions.S3_s3tc) {
+   if (_mesa_is_desktop_gl(ctx)
+       && ctx->Extensions.ANGLE_texture_compression_dxt) {
       if (formats) {
          formats[n++] = GL_RGB_S3TC;
          formats[n++] = GL_RGB4_S3TC;
@@ -523,129 +524,71 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
 
 
 /**
- * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
- * \param srcRowStride  stride in bytes between rows of blocks in the
- *                      compressed source image.
+ * Return a texel-fetch function for the given format, or NULL if
+ * invalid format.
  */
-void
-_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
-                       const GLubyte *src, GLint srcRowStride,
-                       GLfloat *dest)
+compressed_fetch_func
+_mesa_get_compressed_fetch_func(gl_format format)
 {
-   void (*fetch)(const struct swrast_texture_image *texImage,
-                 GLint i, GLint j, GLint k, GLfloat *texel);
-   struct swrast_texture_image texImage;  /* dummy teximage */
-   GLuint i, j;
-   GLuint bytes, bw, bh;
-
-   bytes = _mesa_get_format_bytes(format);
-   _mesa_get_format_block_size(format, &bw, &bh);
-
-   /* setup dummy texture image info */
-   memset(&texImage, 0, sizeof(texImage));
-   texImage.Map = (void *) src;
-
-   /* XXX This line is a bit of a hack to adapt to the row stride
-    * convention used by the texture decompression functions.
-    */
-   texImage.RowStride = srcRowStride * bh / bytes;
-
    switch (format) {
-   /* DXT formats */
    case MESA_FORMAT_RGB_DXT1:
-      fetch = _mesa_fetch_texel_rgb_dxt1;
-      break;
    case MESA_FORMAT_RGBA_DXT1:
-      fetch = _mesa_fetch_texel_rgba_dxt1;
-      break;
    case MESA_FORMAT_RGBA_DXT3:
-      fetch = _mesa_fetch_texel_rgba_dxt3;
-      break;
    case MESA_FORMAT_RGBA_DXT5:
-      fetch = _mesa_fetch_texel_rgba_dxt5;
-      break;
-
-   /* FXT1 formats */
+   case MESA_FORMAT_SRGB_DXT1:
+   case MESA_FORMAT_SRGBA_DXT1:
+   case MESA_FORMAT_SRGBA_DXT3:
+   case MESA_FORMAT_SRGBA_DXT5:
+      return _mesa_get_dxt_fetch_func(format);
    case MESA_FORMAT_RGB_FXT1:
-      fetch = _mesa_fetch_texel_2d_f_rgb_fxt1;
-      break;
    case MESA_FORMAT_RGBA_FXT1:
-      fetch = _mesa_fetch_texel_2d_f_rgba_fxt1;
-      break;
-
-   /* Red/RG formats */
+      return _mesa_get_fxt_fetch_func(format);
    case MESA_FORMAT_RED_RGTC1:
-      fetch = _mesa_fetch_texel_red_rgtc1;
-      break;
-   case MESA_FORMAT_SIGNED_RED_RGTC1:
-      fetch = _mesa_fetch_texel_signed_red_rgtc1;
-      break;
-   case MESA_FORMAT_RG_RGTC2:
-      fetch = _mesa_fetch_texel_rg_rgtc2;
-      break;
-   case MESA_FORMAT_SIGNED_RG_RGTC2:
-      fetch = _mesa_fetch_texel_signed_rg_rgtc2;
-      break;
-
-   /* L/LA formats */
    case MESA_FORMAT_L_LATC1:
-      fetch = _mesa_fetch_texel_l_latc1;
-      break;
+   case MESA_FORMAT_SIGNED_RED_RGTC1:
    case MESA_FORMAT_SIGNED_L_LATC1:
-      fetch = _mesa_fetch_texel_signed_l_latc1;
-      break;
+   case MESA_FORMAT_RG_RGTC2:
    case MESA_FORMAT_LA_LATC2:
-      fetch = _mesa_fetch_texel_la_latc2;
-      break;
+   case MESA_FORMAT_SIGNED_RG_RGTC2:
    case MESA_FORMAT_SIGNED_LA_LATC2:
-      fetch = _mesa_fetch_texel_signed_la_latc2;
-      break;
-
-   /* ETC1 formats */
+      return _mesa_get_compressed_rgtc_func(format);
    case MESA_FORMAT_ETC1_RGB8:
-      fetch = _mesa_fetch_texel_2d_f_etc1_rgb8;
-      break;
+      return _mesa_get_etc_fetch_func(format);
+   default:
+      return NULL;
+   }
+}
 
-   /* ETC2 formats */
-   case MESA_FORMAT_ETC2_RGB8:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_rgb8; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_SRGB8:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_srgb8; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_RGBA8_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_rgba8_eac; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_R11_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_r11_eac; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_RG11_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_rg11_eac; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_signed_r11_eac; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_signed_rg11_eac; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1; -- not implemented yet */
-      break;
-   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1; -- not implemented yet */
-      break;
 
-   default:
+/**
+ * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
+ * \param srcRowStride  stride in bytes between rows of blocks in the
+ *                      compressed source image.
+ */
+void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+                       const GLubyte *src, GLint srcRowStride,
+                       GLfloat *dest)
+{
+   compressed_fetch_func fetch;
+   GLuint i, j;
+   GLuint bytes, bw, bh;
+   GLint stride;
+
+   bytes = _mesa_get_format_bytes(format);
+   _mesa_get_format_block_size(format, &bw, &bh);
+
+   fetch = _mesa_get_compressed_fetch_func(format);
+   if (!fetch) {
       _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
       return;
    }
+   stride = srcRowStride * bh / bytes;
 
    for (j = 0; j < height; j++) {
       for (i = 0; i < width; i++) {
-         fetch(&texImage, i, j, 0, dest);
+         fetch(src, NULL, stride, i, j, 0, dest);
          dest += 4;
       }
    }