<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 7, 2015 at 11:20 PM, Iago Toral Quiroga <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Samuel Iglesias Gonsalvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
<br>
This will be used to unify code in pack.c.<br>
<br>
v2:<br>
- Modify pack_int_*() function generator to use c.datatype() and<br>
f.datatype()<br>
<br>
Signed-off-by: Samuel Iglesias Gonsalvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
---<br>
src/mesa/main/format_pack.h | 3 ++<br>
src/mesa/main/format_pack.py | 121 +++++++++++++++++++++++++++++++++++++++++++<br>
2 files changed, 124 insertions(+)<br>
<br>
diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h<br>
index 1582ad1..6087fc3 100644<br>
--- a/src/mesa/main/format_pack.h<br>
+++ b/src/mesa/main/format_pack.h<br>
@@ -68,6 +68,9 @@ extern gl_pack_ubyte_stencil_func<br>
_mesa_get_pack_ubyte_stencil_func(mesa_format format);<br>
<br>
<br>
+extern void<br>
+_mesa_pack_int_rgba_row(mesa_format format, GLuint n,<br>
+ const GLint src[][4], void *dst);<br>
<br>
extern void<br>
_mesa_pack_float_rgba_row(mesa_format format, GLuint n,<br>
diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py<br>
index 3240d24..8d605be 100644<br>
--- a/src/mesa/main/format_pack.py<br>
+++ b/src/mesa/main/format_pack.py<br>
@@ -213,6 +213,99 @@ pack_uint_${f.short_name()}(const GLuint src[4], void *dst)<br>
}<br>
%endfor<br>
<br>
+/* int packing functions */<br>
+<br>
+%for f in rgb_formats:<br>
+ %if <a href="http://f.name" target="_blank">f.name</a> in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):<br>
+ <% continue %><br>
+ %elif f.is_compressed():<br>
+ <% continue %><br>
+ %endif<br></blockquote><div><br></div><div>Aren't the integer pack/unpack functions for non-normalized integer formats only? I think this batch of functions needs to be reworked. Bunch of comments below. I'm sorry if I haven't noticed and commented on this earlier.<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>
+static inline void<br>
+pack_int_${f.short_name()}(const GLint src[4], void *dst)<br>
+{<br>
+ %for (i, c) in enumerate(f.channels):<br>
+ <% i = f.swizzle.inverse()[i] %><br>
+ %if c.type == 'x':<br>
+ <% continue %><br>
+ %endif<br>
+<br>
+ ${c.datatype()} ${<a href="http://c.name" target="_blank">c.name</a>} =<br>
+ %if not f.is_normalized():<br>
+ %if c.type == parser.FLOAT and c.size == 32:<br>
+ INT_TO_FLOAT(src[${i}]);<br>
+ %elif c.type == parser.FLOAT and c.size == 16:<br>
+ _mesa_float_to_half(INT_TO_FLOAT(src[${i}]));<br></blockquote><div><br></div><div>Why are we converting to float for a non-normalized destination?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ %else:<br>
+ (${c.datatype()}) src[${i}];<br>
+ %endif<br>
+ %elif c.type == parser.UNSIGNED:<br>
+ %if f.colorspace == 'srgb' and <a href="http://c.name" target="_blank">c.name</a> in 'rgb':<br>
+ util_format_linear_to_srgb_8unorm(src[${i}]);<br></blockquote><div><br></div><div>We shouldn't have SRGB for non-normlized formats<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ %else:<br>
+ CLAMP(src[${i}], 0, MAX_UINT(${c.size}));<br></blockquote><div><br></div><div>We have signed_to_unsigned etc. functions for this. If not, we should add them.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ %endif<br>
+ %elif c.type == parser.SIGNED:<br>
+ CLAMP(src[${i}], 0, MAX_UINT(${c.size}));<br></blockquote><div><br></div><div>Same here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ %elif c.type == parser.FLOAT:<br>
+ %if c.size == 32:<br>
+ _mesa_snorm_to_float(src[${i}], 8);<br>
+ %elif c.size == 16:<br>
+ _mesa_snorm_to_half(src[${i}], 8);<br></blockquote><div><br></div><div>Again, why are we doing snorm?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ %else:<br>
+ <% assert False %><br>
+ %endif<br>
+ %else:<br>
+ <% assert False %><br>
+ %endif<br>
+ %endfor<br>
+<br>
+ %if f.layout == parser.ARRAY:<br>
+ ${f.datatype()} *d = (${f.datatype()} *)dst;<br>
+ %for (i, c) in enumerate(f.channels):<br>
+ %if c.type == 'x':<br>
+ <% continue %><br>
+ %endif<br>
+ d[${i}] = ${<a href="http://c.name" target="_blank">c.name</a>};<br>
+ %endfor<br>
+ %elif f.layout == parser.PACKED:<br>
+ ${f.datatype()} d = 0;<br>
+ %for (i, c) in enumerate(f.channels):<br>
+ %if c.type == 'x':<br>
+ <% continue %><br>
+ %endif<br>
+ d |= PACK(${<a href="http://c.name" target="_blank">c.name</a>}, ${c.shift}, ${c.size});<br>
+ %endfor<br>
+ (*(${f.datatype()} *)dst) = d;<br>
+ %else:<br>
+ <% assert False %><br>
+ %endif<br>
+}<br>
+%endfor<br>
+<br>
+static inline void<br>
+pack_int_r9g9b9e5_float(const GLint src[4], void *dst)<br>
+{<br>
+ GLuint *d = (GLuint *) dst;<br>
+ GLfloat rgb[3];<br>
+ rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);<br>
+ rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);<br>
+ rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);<br>
+ *d = float3_to_rgb9e5(rgb);<br>
+}<br>
+<br>
+static inline void<br>
+pack_int_r11g11b10_float(const GLint src[4], void *dst)<br>
+{<br>
+ GLuint *d = (GLuint *) dst;<br>
+ GLfloat rgb[3];<br>
+ rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);<br>
+ rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);<br>
+ rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);<br>
+ *d = float3_to_r11g11b10f(rgb);<br>
+}<br>
+<br>
/* float packing functions */<br>
<br>
%for f in rgb_formats:<br>
@@ -396,6 +489,34 @@ _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,<br>
}<br>
<br>
/**<br>
+ * Pack a row of GLint rgba[4] values to the destination.<br>
+ */<br>
+void<br>
+_mesa_pack_int_rgba_row(mesa_format format, GLuint n,<br>
+ const GLint src[][4], void *dst)<br>
+{<br>
+ GLuint i;<br>
+ GLubyte *d = dst;<br>
+<br>
+ switch (format) {<br>
+%for f in rgb_formats:<br>
+ %if f.is_compressed():<br>
+ <% continue %><br>
+ %endif<br>
+<br>
+ case ${<a href="http://f.name" target="_blank">f.name</a>}:<br>
+ for (i = 0; i < n; ++i) {<br>
+ pack_int_${f.short_name()}(src[i], d);<br>
+ d += ${f.block_size() / 8};<br>
+ }<br>
+ break;<br>
+%endfor<br>
+ default:<br>
+ assert(!"Invalid format");<br>
+ }<br>
+}<br>
+<br>
+/**<br>
* Pack a row of GLfloat rgba[4] values to the destination.<br>
*/<br>
void<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><br></div></div>