[Mesa-dev] [PATCH V2 2/3] glsl: add new expression types for interpolateAt*

Chris Forbes chrisf at ijw.co.nz
Mon Nov 11 23:46:24 PST 2013


Sorry, that commit message ended up a mess.

On Tue, Nov 12, 2013 at 8:45 PM, Chris Forbes <chrisf at ijw.co.nz> wrote:
> Will be used to implement interpolateAtCentroid(), interpolateAtOffset()
> and interpolateAtSample() from ARB_gpu_shader5
> Will be used to implement interpolateAtCentroid() from ARB_gpu_shader5.
>
> Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
> ---
>  src/glsl/ir.cpp                            |  6 ++++++
>  src/glsl/ir.h                              | 27 +++++++++++++++++++++++++--
>  src/glsl/ir_builder.cpp                    | 18 ++++++++++++++++++
>  src/glsl/ir_builder.h                      |  4 ++++
>  src/glsl/ir_constant_expression.cpp        |  2 ++
>  src/glsl/ir_validate.cpp                   | 18 ++++++++++++++++++
>  src/mesa/program/ir_to_mesa.cpp            |  3 +++
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  3 +++
>  8 files changed, 79 insertions(+), 2 deletions(-)
>
> diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
> index 1b49736..8a5f9e7 100644
> --- a/src/glsl/ir.cpp
> +++ b/src/glsl/ir.cpp
> @@ -251,6 +251,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
>     case ir_unop_dFdx:
>     case ir_unop_dFdy:
>     case ir_unop_bitfield_reverse:
> +   case ir_unop_interpolate_at_centroid:
>        this->type = op0->type;
>        break;
>
> @@ -405,6 +406,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1)
>     case ir_binop_rshift:
>     case ir_binop_bfm:
>     case ir_binop_ldexp:
> +   case ir_binop_interpolate_at_offset:
> +   case ir_binop_interpolate_at_sample:
>        this->type = op0->type;
>        break;
>
> @@ -527,6 +530,7 @@ static const char *const operator_strs[] = {
>     "find_msb",
>     "find_lsb",
>     "noise",
> +   "interpolate_at_centroid",
>     "+",
>     "-",
>     "*",
> @@ -560,6 +564,8 @@ static const char *const operator_strs[] = {
>     "ubo_load",
>     "ldexp",
>     "vector_extract",
> +   "interpolate_at_offset",
> +   "interpolate_at_sample",
>     "fma",
>     "lrp",
>     "csel",
> diff --git a/src/glsl/ir.h b/src/glsl/ir.h
> index 7b905ef..2a5b612 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -1199,9 +1199,16 @@ enum ir_expression_operation {
>     ir_unop_noise,
>
>     /**
> +    * Interpolate fs input at centroid
> +    *
> +    * operand0 is the fs input.
> +    */
> +   ir_unop_interpolate_at_centroid,
> +
> +   /**
>      * A sentinel marking the last of the unary operations.
>      */
> -   ir_last_unop = ir_unop_noise,
> +   ir_last_unop = ir_unop_interpolate_at_centroid,
>
>     ir_binop_add,
>     ir_binop_sub,
> @@ -1320,9 +1327,25 @@ enum ir_expression_operation {
>     ir_binop_vector_extract,
>
>     /**
> +    * Interpolate fs input at offset
> +    *
> +    * operand0 is the fs input
> +    * operand1 is the offset from the pixel center
> +    */
> +   ir_binop_interpolate_at_offset,
> +
> +   /**
> +    * Interpolate fs input at sample position
> +    *
> +    * operand0 is the fs input
> +    * operand1 is the sample ID
> +    */
> +   ir_binop_interpolate_at_sample,
> +
> +   /**
>      * A sentinel marking the last of the binary operations.
>      */
> -   ir_last_binop = ir_binop_vector_extract,
> +   ir_last_binop = ir_binop_interpolate_at_sample,
>
>     /**
>      * \name Fused floating-point multiply-add, part of ARB_gpu_shader5.
> diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp
> index 6c49734..791b280 100644
> --- a/src/glsl/ir_builder.cpp
> +++ b/src/glsl/ir_builder.cpp
> @@ -496,6 +496,24 @@ b2f(operand a)
>  }
>
>  ir_expression *
> +interpolate_at_centroid(operand a)
> +{
> +   return expr(ir_unop_interpolate_at_centroid, a);
> +}
> +
> +ir_expression *
> +interpolate_at_offset(operand a, operand b)
> +{
> +   return expr(ir_binop_interpolate_at_offset, a, b);
> +}
> +
> +ir_expression *
> +interpolate_at_sample(operand a, operand b)
> +{
> +   return expr(ir_binop_interpolate_at_sample, a, b);
> +}
> +
> +ir_expression *
>  fma(operand a, operand b, operand c)
>  {
>     return expr(ir_triop_fma, a, b, c);
> diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h
> index 1f07788..3c8780a 100644
> --- a/src/glsl/ir_builder.h
> +++ b/src/glsl/ir_builder.h
> @@ -184,6 +184,10 @@ ir_expression *i2b(operand a);
>  ir_expression *f2b(operand a);
>  ir_expression *b2f(operand a);
>
> +ir_expression *interpolate_at_centroid(operand a);
> +ir_expression *interpolate_at_offset(operand a, operand b);
> +ir_expression *interpolate_at_sample(operand a, operand b);
> +
>  ir_expression *fma(operand a, operand b, operand c);
>  ir_expression *lrp(operand x, operand y, operand a);
>  ir_expression *csel(operand a, operand b, operand c);
> diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
> index 0efd1d5..ca92768 100644
> --- a/src/glsl/ir_constant_expression.cpp
> +++ b/src/glsl/ir_constant_expression.cpp
> @@ -415,6 +415,8 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
>        case ir_binop_lshift:
>        case ir_binop_rshift:
>        case ir_binop_ldexp:
> +      case ir_binop_interpolate_at_offset:
> +      case ir_binop_interpolate_at_sample:
>        case ir_binop_vector_extract:
>        case ir_triop_csel:
>        case ir_triop_bitfield_extract:
> diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
> index 13e41a0..4ed8d35 100644
> --- a/src/glsl/ir_validate.cpp
> +++ b/src/glsl/ir_validate.cpp
> @@ -410,6 +410,11 @@ ir_validate::visit_leave(ir_expression *ir)
>        /* XXX what can we assert here? */
>        break;
>
> +   case ir_unop_interpolate_at_centroid:
> +      assert(ir->operands[0]->type == ir->type);
> +      assert(ir->operands[0]->type->is_float());
> +      break;
> +
>     case ir_binop_add:
>     case ir_binop_sub:
>     case ir_binop_mul:
> @@ -546,6 +551,19 @@ ir_validate::visit_leave(ir_expression *ir)
>               && ir->operands[1]->type->is_integer());
>        break;
>
> +   case ir_binop_interpolate_at_offset:
> +      assert(ir->operands[0]->type == ir->type);
> +      assert(ir->operands[0]->type->is_float());
> +      assert(ir->operands[1]->type->components() == 2);
> +      assert(ir->operands[1]->type->is_float());
> +      break;
> +
> +   case ir_binop_interpolate_at_sample:
> +      assert(ir->operands[0]->type == ir->type);
> +      assert(ir->operands[0]->type->is_float());
> +      assert(ir->operands[1]->type == glsl_type::int_type);
> +      break;
> +
>     case ir_triop_fma:
>        assert(ir->type->base_type == GLSL_TYPE_FLOAT);
>        assert(ir->type == ir->operands[0]->type);
> diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
> index c833a12..5fc4340 100644
> --- a/src/mesa/program/ir_to_mesa.cpp
> +++ b/src/mesa/program/ir_to_mesa.cpp
> @@ -1501,6 +1501,9 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
>     case ir_binop_carry:
>     case ir_binop_borrow:
>     case ir_binop_imul_high:
> +   case ir_unop_interpolate_at_centroid:
> +   case ir_binop_interpolate_at_offset:
> +   case ir_binop_interpolate_at_sample:
>        assert(!"not supported");
>        break;
>
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 0eaf746..f1017ee 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -2007,6 +2007,9 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
>     case ir_binop_carry:
>     case ir_binop_borrow:
>     case ir_binop_imul_high:
> +   case ir_unop_interpolate_at_centroid:
> +   case ir_binop_interpolate_at_offset:
> +   case ir_binop_interpolate_at_sample:
>        /* This operation is not supported, or should have already been handled.
>         */
>        assert(!"Invalid ir opcode in glsl_to_tgsi_visitor::visit()");
> --
> 1.8.4.2
>


More information about the mesa-dev mailing list