<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 9, 2014 at 4:07 AM, Iago Toral Quiroga <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is necessary to handle conversions between array types where<br>
the driver does not support the dst format requested by the client and<br>
chooses a different format instead.<br>
<br>
We will need this in _mesa_format_convert, so move it to format_utils.c,<br>
prefix it with '_mesa_' and make it available to other files.<br></blockquote><div><br></div><div>I think we'd probably rather have this in glformat.h if we can as it deals with GL formats. Otherwise, looks good.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
src/mesa/main/format_utils.c | 198 +++++++++++++++++++++++++++++++++++++++<br>
src/mesa/main/format_utils.h | 3 +<br>
src/mesa/main/texstore.c | 216 ++-----------------------------------------<br>
3 files changed, 210 insertions(+), 207 deletions(-)<br>
<br>
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c<br>
index 541d19a..ba0be13 100644<br>
--- a/src/mesa/main/format_utils.c<br>
+++ b/src/mesa/main/format_utils.c<br>
@@ -26,6 +26,7 @@<br>
#include "glformats.h"<br>
#include "format_pack.h"<br>
#include "format_unpack.h"<br>
+#include "enums.h"<br>
<br>
mesa_array_format RGBA8888_FLOAT =<br>
MESA_ARRAY_FORMAT(4, 1, 1, 1, 4, 0, 1, 2, 3);<br>
@@ -55,6 +56,203 @@ invert_swizzle(uint8_t dst[4], const uint8_t src[4])<br>
dst[i] = j;<br>
}<br>
<br>
+enum {<br>
+ ZERO = 4,<br>
+ ONE = 5<br>
+};<br>
+<br>
+enum {<br>
+ IDX_LUMINANCE = 0,<br>
+ IDX_ALPHA,<br>
+ IDX_INTENSITY,<br>
+ IDX_LUMINANCE_ALPHA,<br>
+ IDX_RGB,<br>
+ IDX_RGBA,<br>
+ IDX_RED,<br>
+ IDX_GREEN,<br>
+ IDX_BLUE,<br>
+ IDX_BGR,<br>
+ IDX_BGRA,<br>
+ IDX_ABGR,<br>
+ IDX_RG,<br>
+ MAX_IDX<br>
+};<br>
+<br>
+#define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)<br>
+#define MAP2(x,y) MAP4(x, y, ZERO, ZERO)<br>
+#define MAP3(x,y,z) MAP4(x, y, z, ZERO)<br>
+#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }<br>
+<br>
+static const struct {<br>
+ GLubyte format_idx;<br>
+ GLubyte to_rgba[6];<br>
+ GLubyte from_rgba[6];<br>
+} mappings[MAX_IDX] =<br>
+{<br>
+ {<br>
+ IDX_LUMINANCE,<br>
+ MAP4(0,0,0,ONE),<br>
+ MAP1(0)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_ALPHA,<br>
+ MAP4(ZERO, ZERO, ZERO, 0),<br>
+ MAP1(3)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_INTENSITY,<br>
+ MAP4(0, 0, 0, 0),<br>
+ MAP1(0),<br>
+ },<br>
+<br>
+ {<br>
+ IDX_LUMINANCE_ALPHA,<br>
+ MAP4(0,0,0,1),<br>
+ MAP2(0,3)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_RGB,<br>
+ MAP4(0,1,2,ONE),<br>
+ MAP3(0,1,2)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_RGBA,<br>
+ MAP4(0,1,2,3),<br>
+ MAP4(0,1,2,3),<br>
+ },<br>
+<br>
+ {<br>
+ IDX_RED,<br>
+ MAP4(0, ZERO, ZERO, ONE),<br>
+ MAP1(0),<br>
+ },<br>
+<br>
+ {<br>
+ IDX_GREEN,<br>
+ MAP4(ZERO, 0, ZERO, ONE),<br>
+ MAP1(1),<br>
+ },<br>
+<br>
+ {<br>
+ IDX_BLUE,<br>
+ MAP4(ZERO, ZERO, 0, ONE),<br>
+ MAP1(2),<br>
+ },<br>
+<br>
+ {<br>
+ IDX_BGR,<br>
+ MAP4(2,1,0,ONE),<br>
+ MAP3(2,1,0)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_BGRA,<br>
+ MAP4(2,1,0,3),<br>
+ MAP4(2,1,0,3)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_ABGR,<br>
+ MAP4(3,2,1,0),<br>
+ MAP4(3,2,1,0)<br>
+ },<br>
+<br>
+ {<br>
+ IDX_RG,<br>
+ MAP4(0, 1, ZERO, ONE),<br>
+ MAP2(0, 1)<br>
+ },<br>
+};<br>
+<br>
+/**<br>
+ * Convert a GL image format enum to an IDX_* value (see above).<br>
+ */<br>
+static int<br>
+get_map_idx(GLenum value)<br>
+{<br>
+ switch (value) {<br>
+ case GL_LUMINANCE:<br>
+ case GL_LUMINANCE_INTEGER_EXT:<br>
+ return IDX_LUMINANCE;<br>
+ case GL_ALPHA:<br>
+ case GL_ALPHA_INTEGER:<br>
+ return IDX_ALPHA;<br>
+ case GL_INTENSITY:<br>
+ return IDX_INTENSITY;<br>
+ case GL_LUMINANCE_ALPHA:<br>
+ case GL_LUMINANCE_ALPHA_INTEGER_EXT:<br>
+ return IDX_LUMINANCE_ALPHA;<br>
+ case GL_RGB:<br>
+ case GL_RGB_INTEGER:<br>
+ return IDX_RGB;<br>
+ case GL_RGBA:<br>
+ case GL_RGBA_INTEGER:<br>
+ return IDX_RGBA;<br>
+ case GL_RED:<br>
+ case GL_RED_INTEGER:<br>
+ return IDX_RED;<br>
+ case GL_GREEN:<br>
+ return IDX_GREEN;<br>
+ case GL_BLUE:<br>
+ return IDX_BLUE;<br>
+ case GL_BGR:<br>
+ case GL_BGR_INTEGER:<br>
+ return IDX_BGR;<br>
+ case GL_BGRA:<br>
+ case GL_BGRA_INTEGER:<br>
+ return IDX_BGRA;<br>
+ case GL_ABGR_EXT:<br>
+ return IDX_ABGR;<br>
+ case GL_RG:<br>
+ case GL_RG_INTEGER:<br>
+ return IDX_RG;<br>
+ default:<br>
+ _mesa_problem(NULL, "Unexpected inFormat %s",<br>
+ _mesa_lookup_enum_by_nr(value));<br>
+ return 0;<br>
+ }<br>
+}<br>
+<br>
+/**<br>
+ * When promoting texture formats (see below) we need to compute the<br>
+ * mapping of dest components back to source components.<br>
+ * This function does that.<br>
+ * \param inFormat the incoming format of the texture<br>
+ * \param outFormat the final texture format<br>
+ * \return map[6] a full 6-component map<br>
+ */<br>
+void<br>
+_mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map)<br>
+{<br>
+ const int inFmt = get_map_idx(inFormat);<br>
+ const int outFmt = get_map_idx(outFormat);<br>
+ const GLubyte *in2rgba = mappings[inFmt].to_rgba;<br>
+ const GLubyte *rgba2out = mappings[outFmt].from_rgba;<br>
+ int i;<br>
+<br>
+ for (i = 0; i < 4; i++)<br>
+ map[i] = in2rgba[rgba2out[i]];<br>
+<br>
+ map[ZERO] = ZERO;<br>
+ map[ONE] = ONE;<br>
+<br>
+#if 0<br>
+ printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",<br>
+ inFormat, _mesa_lookup_enum_by_nr(inFormat),<br>
+ outFormat, _mesa_lookup_enum_by_nr(outFormat),<br>
+ map[0],<br>
+ map[1],<br>
+ map[2],<br>
+ map[3],<br>
+ map[4],<br>
+ map[5]);<br>
+#endif<br>
+}<br>
+<br>
static GLenum<br>
gl_type_for_array_format_datatype(enum mesa_array_format_datatype type)<br>
{<br>
diff --git a/src/mesa/main/format_utils.h b/src/mesa/main/format_utils.h<br>
index 8d25e51..28b4715 100644<br>
--- a/src/mesa/main/format_utils.h<br>
+++ b/src/mesa/main/format_utils.h<br>
@@ -179,6 +179,9 @@ _mesa_swizzle_and_convert(void *dst, GLenum dst_type, int num_dst_channels,<br>
const uint8_t swizzle[4], bool normalized, int count);<br>
<br>
void<br>
+_mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map);<br>
+<br>
+void<br>
_mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,<br>
void *void_src, uint32_t src_format, size_t src_stride,<br>
size_t width, size_t height);<br>
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c<br>
index 3ac8bcf..de9f4df 100644<br>
--- a/src/mesa/main/texstore.c<br>
+++ b/src/mesa/main/texstore.c<br>
@@ -89,204 +89,6 @@ enum {<br>
typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);<br>
<br>
<br>
-enum {<br>
- IDX_LUMINANCE = 0,<br>
- IDX_ALPHA,<br>
- IDX_INTENSITY,<br>
- IDX_LUMINANCE_ALPHA,<br>
- IDX_RGB,<br>
- IDX_RGBA,<br>
- IDX_RED,<br>
- IDX_GREEN,<br>
- IDX_BLUE,<br>
- IDX_BGR,<br>
- IDX_BGRA,<br>
- IDX_ABGR,<br>
- IDX_RG,<br>
- MAX_IDX<br>
-};<br>
-<br>
-#define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)<br>
-#define MAP2(x,y) MAP4(x, y, ZERO, ZERO)<br>
-#define MAP3(x,y,z) MAP4(x, y, z, ZERO)<br>
-#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }<br>
-<br>
-<br>
-static const struct {<br>
- GLubyte format_idx;<br>
- GLubyte to_rgba[6];<br>
- GLubyte from_rgba[6];<br>
-} mappings[MAX_IDX] =<br>
-{<br>
- {<br>
- IDX_LUMINANCE,<br>
- MAP4(0,0,0,ONE),<br>
- MAP1(0)<br>
- },<br>
-<br>
- {<br>
- IDX_ALPHA,<br>
- MAP4(ZERO, ZERO, ZERO, 0),<br>
- MAP1(3)<br>
- },<br>
-<br>
- {<br>
- IDX_INTENSITY,<br>
- MAP4(0, 0, 0, 0),<br>
- MAP1(0),<br>
- },<br>
-<br>
- {<br>
- IDX_LUMINANCE_ALPHA,<br>
- MAP4(0,0,0,1),<br>
- MAP2(0,3)<br>
- },<br>
-<br>
- {<br>
- IDX_RGB,<br>
- MAP4(0,1,2,ONE),<br>
- MAP3(0,1,2)<br>
- },<br>
-<br>
- {<br>
- IDX_RGBA,<br>
- MAP4(0,1,2,3),<br>
- MAP4(0,1,2,3),<br>
- },<br>
-<br>
- {<br>
- IDX_RED,<br>
- MAP4(0, ZERO, ZERO, ONE),<br>
- MAP1(0),<br>
- },<br>
-<br>
- {<br>
- IDX_GREEN,<br>
- MAP4(ZERO, 0, ZERO, ONE),<br>
- MAP1(1),<br>
- },<br>
-<br>
- {<br>
- IDX_BLUE,<br>
- MAP4(ZERO, ZERO, 0, ONE),<br>
- MAP1(2),<br>
- },<br>
-<br>
- {<br>
- IDX_BGR,<br>
- MAP4(2,1,0,ONE),<br>
- MAP3(2,1,0)<br>
- },<br>
-<br>
- {<br>
- IDX_BGRA,<br>
- MAP4(2,1,0,3),<br>
- MAP4(2,1,0,3)<br>
- },<br>
-<br>
- {<br>
- IDX_ABGR,<br>
- MAP4(3,2,1,0),<br>
- MAP4(3,2,1,0)<br>
- },<br>
-<br>
- {<br>
- IDX_RG,<br>
- MAP4(0, 1, ZERO, ONE),<br>
- MAP2(0, 1)<br>
- },<br>
-};<br>
-<br>
-<br>
-<br>
-/**<br>
- * Convert a GL image format enum to an IDX_* value (see above).<br>
- */<br>
-static int<br>
-get_map_idx(GLenum value)<br>
-{<br>
- switch (value) {<br>
- case GL_LUMINANCE:<br>
- case GL_LUMINANCE_INTEGER_EXT:<br>
- return IDX_LUMINANCE;<br>
- case GL_ALPHA:<br>
- case GL_ALPHA_INTEGER:<br>
- return IDX_ALPHA;<br>
- case GL_INTENSITY:<br>
- return IDX_INTENSITY;<br>
- case GL_LUMINANCE_ALPHA:<br>
- case GL_LUMINANCE_ALPHA_INTEGER_EXT:<br>
- return IDX_LUMINANCE_ALPHA;<br>
- case GL_RGB:<br>
- case GL_RGB_INTEGER:<br>
- return IDX_RGB;<br>
- case GL_RGBA:<br>
- case GL_RGBA_INTEGER:<br>
- return IDX_RGBA;<br>
- case GL_RED:<br>
- case GL_RED_INTEGER:<br>
- return IDX_RED;<br>
- case GL_GREEN:<br>
- return IDX_GREEN;<br>
- case GL_BLUE:<br>
- return IDX_BLUE;<br>
- case GL_BGR:<br>
- case GL_BGR_INTEGER:<br>
- return IDX_BGR;<br>
- case GL_BGRA:<br>
- case GL_BGRA_INTEGER:<br>
- return IDX_BGRA;<br>
- case GL_ABGR_EXT:<br>
- return IDX_ABGR;<br>
- case GL_RG:<br>
- case GL_RG_INTEGER:<br>
- return IDX_RG;<br>
- default:<br>
- _mesa_problem(NULL, "Unexpected inFormat %s",<br>
- _mesa_lookup_enum_by_nr(value));<br>
- return 0;<br>
- }<br>
-}<br>
-<br>
-<br>
-/**<br>
- * When promoting texture formats (see below) we need to compute the<br>
- * mapping of dest components back to source components.<br>
- * This function does that.<br>
- * \param inFormat the incoming format of the texture<br>
- * \param outFormat the final texture format<br>
- * \return map[6] a full 6-component map<br>
- */<br>
-static void<br>
-compute_component_mapping(GLenum inFormat, GLenum outFormat,<br>
- GLubyte *map)<br>
-{<br>
- const int inFmt = get_map_idx(inFormat);<br>
- const int outFmt = get_map_idx(outFormat);<br>
- const GLubyte *in2rgba = mappings[inFmt].to_rgba;<br>
- const GLubyte *rgba2out = mappings[outFmt].from_rgba;<br>
- int i;<br>
-<br>
- for (i = 0; i < 4; i++)<br>
- map[i] = in2rgba[rgba2out[i]];<br>
-<br>
- map[ZERO] = ZERO;<br>
- map[ONE] = ONE;<br>
-<br>
-#if 0<br>
- printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",<br>
- inFormat, _mesa_lookup_enum_by_nr(inFormat),<br>
- outFormat, _mesa_lookup_enum_by_nr(outFormat),<br>
- map[0],<br>
- map[1],<br>
- map[2],<br>
- map[3],<br>
- map[4],<br>
- map[5]);<br>
-#endif<br>
-}<br>
-<br>
-<br>
/**<br>
* Make a temporary (color) texture image with GLfloat components.<br>
* Apply all needed pixel unpacking and pixel transfer operations.<br>
@@ -394,7 +196,7 @@ _mesa_make_temp_float_image(struct gl_context *ctx, GLuint dims,<br>
return NULL;<br>
}<br>
<br>
- compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);<br>
+ _mesa_compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);<br>
<br>
n = srcWidth * srcHeight * srcDepth;<br>
for (i = 0; i < n; i++) {<br>
@@ -503,7 +305,7 @@ make_temp_uint_image(struct gl_context *ctx, GLuint dims,<br>
return NULL;<br>
}<br>
<br>
- compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);<br>
+ _mesa_compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);<br>
<br>
n = srcWidth * srcHeight * srcDepth;<br>
for (i = 0; i < n; i++) {<br>
@@ -634,7 +436,7 @@ _mesa_make_temp_ubyte_image(struct gl_context *ctx, GLuint dims,<br>
return NULL;<br>
}<br>
<br>
- compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);<br>
+ _mesa_compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);<br>
<br>
n = srcWidth * srcHeight * srcDepth;<br>
for (i = 0; i < n; i++) {<br>
@@ -1532,8 +1334,8 @@ texstore_swizzle(TEXSTORE_PARAMS)<br>
}<br>
swap = need_swap ? map_3210 : map_identity;<br>
<br>
- compute_component_mapping(srcFormat, baseInternalFormat, base2src);<br>
- compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base);<br>
+ _mesa_compute_component_mapping(srcFormat, baseInternalFormat, base2src);<br>
+ _mesa_compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base);<br>
invert_swizzle(dst2rgba, rgba2dst);<br>
<br>
for (i = 0; i < 4; i++) {<br>
@@ -1603,8 +1405,8 @@ texstore_via_float(TEXSTORE_PARAMS)<br>
<br>
need_convert = false;<br>
if (baseInternalFormat != _mesa_get_format_base_format(dstFormat)) {<br>
- compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba);<br>
- compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base);<br>
+ _mesa_compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba);<br>
+ _mesa_compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base);<br>
for (i = 0; i < 4; ++i) {<br>
map[i] = base2rgba[rgba2base[i]];<br>
if (map[i] != i)<br>
@@ -1673,8 +1475,8 @@ texstore_rgba_integer(TEXSTORE_PARAMS)<br>
}<br>
<br>
invert_swizzle(dst2rgba, rgba2dst);<br>
- compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba);<br>
- compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base);<br>
+ _mesa_compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba);<br>
+ _mesa_compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base);<br>
<br>
for (i = 0; i < 4; ++i) {<br>
if (dst2rgba[i] == MESA_FORMAT_SWIZZLE_NONE)<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div></div></div>