[Mesa-dev] [PATCH 05/10] glsl: Add lowering pass for GLSL ES 3.00 pack/unpack operations

Chad Versace chad.versace at linux.intel.com
Thu Jan 10 11:07:57 PST 2013


On 01/10/2013 10:36 AM, Ian Romanick wrote:
> On 01/10/2013 12:10 AM, Chad Versace wrote:
>> Lower them to arithmetic and bit manipulation expressions.
>>
>> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
>> ---
>>   src/glsl/Makefile.sources           |    1 +
>>   src/glsl/ir_optimization.h          |   18 +
>>   src/glsl/lower_packing_builtins.cpp | 1566 +++++++++++++++++++++++++++++++++++
>>   3 files changed, 1585 insertions(+)
>>   create mode 100644 src/glsl/lower_packing_builtins.cpp


>> +      switch (expr->operation) {
>> +      case ir_unop_pack_snorm_2x16:
>> +         assert((*rvalue)->type == glsl_type::uint_type);
>> +         assert(op0->type == glsl_type::vec2_type);
> 
> Aren't all of these assertions already handled by ir_validate?

You're right. I'll remove them.

>> +   /**
>> +    * \brief Pack two uint16's into a single uint32.
>> +    *
>> +    * Interpret the given uvec2 as a uint16 pair. Pack the pair into a uint32
>> +    * where the least significant bits specify the first element of the pair.
>> +    * Return the uint32 as a uint rvalue.
>> +    *
>> +    * This function generates IR that approximates the following GLSL:
>> +    *
>> +    *    uvec2 *u = UVEC2_RVAL;
>> +    *    return (u.y << 16) | (u.x & 0xffff);
>> +    */
>> +   ir_rvalue*
>> +   pack_uvec2_to_uint(void *mem_ctx, ir_rvalue *uvec2_rval)
>> +   {
>> +      assert(uvec2_rval->type == glsl_type::uvec2_type);
>> +
>> +      /* uvec2 u = uvec2_rval; */
>> +      ir_variable *u2 =
>> +         new(mem_ctx) ir_variable(glsl_type::uvec2_type,
>> +                                  "tmp_pack_uvec2_to_uint",
>> +                                  ir_var_temporary);
>> +      insert_instruction(u2);
>> +      insert_instruction(
>> +         new(mem_ctx) ir_assignment(
>> +            new(mem_ctx) ir_dereference_variable(u2),
>> +            uvec2_rval));
>> +
>> +      /* return (u.y << 16) | (u.x & 0xffff); */
>> +      return
>> +         new(mem_ctx) ir_expression(ir_binop_bit_or,
>> +           new(mem_ctx) ir_expression(ir_binop_lshift,
>> +             new(mem_ctx) ir_swizzle(
>> +                new(mem_ctx) ir_dereference_variable(u2),
>> +                1, 0, 0, 0, 1),
>> +             new(mem_ctx) ir_constant(16u)),
>> +           new(mem_ctx) ir_expression(ir_binop_bit_and,
>> +             new(mem_ctx) ir_swizzle(
>> +                new(mem_ctx) ir_dereference_variable(u2),
>> +                0, 0, 0, 0, 1),
>> +             new(mem_ctx) ir_constant(0xffffu)));
> 
> Reading this just turned my brain to mush.  I can't image what writing it did to
> yours. :)  ir_builder, perhaps?  You may need to add a couple methods (lsr, lsl,
> etc.), but that doesn't seem like a bad thing...

Good idea.

Even though all this brain-warping code will be replaced by ir_builder chains,
I'm glad I wrote it. I learned much about nuances of the IR while struggling
to write this mess.



More information about the mesa-dev mailing list