<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 2, 2014 at 2:32 AM, Iago Toral <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"><div class="HOEnZb"><div class="h5">On Mon, 2014-12-01 at 11:14 -0800, Jason Ekstrand wrote:<br>
><br>
><br>
> On Mon, Dec 1, 2014 at 3:04 AM, Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>><br>
> wrote:<br>
> From: Samuel Iglesias Gonsalvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
><br>
> We will use this later on to handle uint conversion scenarios<br>
> in a master<br>
> convert function.<br>
><br>
> v2:<br>
> - Modify pack_uint_*() function generation to use c.datatype()<br>
> and<br>
> f.datatype().<br>
> - Remove UINT_TO_FLOAT() macro usage from pack_uint*()<br>
> - Remove "if not f.is_normalized()" conditional as<br>
> pack_uint*()<br>
> functions are only autogenerated for non normalized formats.<br>
><br>
> Signed-off-by: Samuel Iglesias Gonsalvez<br>
> <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
> ---<br>
> src/mesa/main/format_pack.c.mako | 82<br>
> ++++++++++++++++++++++++++++++++++++++++<br>
> src/mesa/main/format_pack.h | 3 ++<br>
> 2 files changed, 85 insertions(+)<br>
><br>
> diff --git a/src/mesa/main/format_pack.c.mako<br>
> b/src/mesa/main/format_pack.c.mako<br>
> index aced58d..7feb3f8 100644<br>
> --- a/src/mesa/main/format_pack.c.mako<br>
> +++ b/src/mesa/main/format_pack.c.mako<br>
> @@ -149,6 +149,56 @@ pack_ubyte_r11g11b10_float(const GLubyte<br>
> src[4], void *dst)<br>
> *d = float3_to_r11g11b10f(rgb);<br>
> }<br>
><br>
> +/* uint packing functions */<br>
> +<br>
> +%for f in rgb_formats:<br>
> + %if not f.is_int():<br>
> + <% continue %><br>
> + %elif f.is_normalized():<br>
> + <% continue %><br>
> + %elif f.is_compressed():<br>
> + <% continue %><br>
> + %endif<br>
> +<br>
> +static inline void<br>
> +pack_uint_${f.short_name()}(const GLuint 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 c.type == parser.FLOAT and c.size == 16:<br>
> + _mesa_float_to_half(src[${i}]);<br>
<br>
</div></div>Jason, I think this float handling shouldn't be here.... we only allow<br>
packing/unpacking between integer types, right? In that case maybe we<br>
should add an assertion to catch these other cases.<br>
<span class=""><br>
> + %else:<br>
> + (${c.datatype()}) src[${i}];<br>
><br>
><br>
> I think we're missing the clamping here. We should probably use the<br>
> same clamping functions that we cooked up for swizzle_and_convert.<br>
> We'll have to be careful though because the source gets interpreted as<br>
> signed vs. unsigned depending on the destination format.<br>
<br>
</span>So you mean that we should use _mesa_unsigned_to_unsigned when c.type ==<br>
parser.UNSIGNED and _mesa_signed_to_signed when c.type == parser.SIGNED.<br>
<br>
If there is nothing wrong with what I suggest above, then I think this<br>
is how it should look like in the end:<br>
<span class=""><br>
${c.datatype()} ${<a href="http://c.name" target="_blank">c.name</a>} =<br>
</span>%if c.type == parser.SIGNED:<br>
_mesa_signed_to_signed(src[${i}], ${c.size});<br>
%elif c.type == parser.UNSIGNED:<br>
_mesa_unsigned_to_unsigned(src[${i}], ${c.size});<br>
%else:<br>
assert(!"Invalid type: only integer types are allowed");<br>
%endif<br></blockquote><div><br></div><div>Looks good to me.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
><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>
> /* float packing functions */<br>
><br>
> @@ -297,6 +347,38 @@ _mesa_pack_ubyte_rgba_row(mesa_format<br>
> format, GLuint n,<br>
> }<br>
><br>
> /**<br>
> + * Pack a row of GLuint rgba[4] values to the destination.<br>
> + */<br>
> +void<br>
> +_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,<br>
> + const GLuint src[][4], void *dst)<br>
> +{<br>
> + GLuint i;<br>
> + GLubyte *d = dst;<br>
> +<br>
> + switch (format) {<br>
> +%for f in rgb_formats:<br>
> + %if not f.is_int():<br>
> + <% continue %><br>
> + %elif f.is_normalized():<br>
> + <% continue %><br>
> + %elif 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_uint_${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>
> diff --git a/src/mesa/main/format_pack.h<br>
> b/src/mesa/main/format_pack.h<br>
> index 2577def..1582ad1 100644<br>
> --- a/src/mesa/main/format_pack.h<br>
> +++ b/src/mesa/main/format_pack.h<br>
> @@ -77,6 +77,9 @@ extern void<br>
> _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,<br>
> const GLubyte src[][4], void *dst);<br>
><br>
> +extern void<br>
> +_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,<br>
> + const GLuint src[][4], void *dst);<br>
><br>
> extern void<br>
> _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width,<br>
> GLuint height,<br>
> --<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>
><br>
><br>
<br>
<br>
</div></div></blockquote></div><br></div></div>