[Mesa-dev] [PATCH 02/10] glsl: add ir_texture_samples texture opcode

Ian Romanick idr at freedesktop.org
Tue Sep 8 20:00:37 PDT 2015


On 08/27/2015 08:48 PM, Ilia Mirkin wrote:
> Will be used for textureSamples()
> 
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
>  src/glsl/ir.cpp                            | 5 +++--
>  src/glsl/ir.h                              | 3 ++-
>  src/glsl/ir_clone.cpp                      | 1 +
>  src/glsl/ir_equals.cpp                     | 1 +
>  src/glsl/ir_hv_accept.cpp                  | 1 +
>  src/glsl/ir_print_visitor.cpp              | 6 ++++--
>  src/glsl/ir_reader.cpp                     | 6 +++++-
>  src/glsl/ir_rvalue_visitor.cpp             | 1 +
>  src/glsl/opt_tree_grafting.cpp             | 1 +
>  src/mesa/program/ir_to_mesa.cpp            | 3 +++
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 ++
>  11 files changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
> index 724861b..fb58c3b 100644
> --- a/src/glsl/ir.cpp
> +++ b/src/glsl/ir.cpp
> @@ -1398,7 +1398,7 @@ ir_dereference::is_lvalue() const
>  }
>  
>  
> -static const char * const tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod", "tg4", "query_levels" };
> +static const char * const tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod", "tg4", "query_levels", "texture_samples" };
>  
>  const char *ir_texture::opcode_string()
>  {
> @@ -1427,7 +1427,8 @@ ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type)
>     this->sampler = sampler;
>     this->type = type;
>  
> -   if (this->op == ir_txs || this->op == ir_query_levels) {
> +   if (this->op == ir_txs || this->op == ir_query_levels ||
> +       this->op == ir_texture_samples) {
>        assert(type->base_type == GLSL_TYPE_INT);
>     } else if (this->op == ir_lod) {
>        assert(type->vector_elements == 2);
> diff --git a/src/glsl/ir.h b/src/glsl/ir.h
> index ede8caa..e31812d 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -1914,7 +1914,8 @@ enum ir_texture_opcode {
>     ir_txs,		/**< Texture size */
>     ir_lod,		/**< Texture lod query */
>     ir_tg4,		/**< Texture gather */
> -   ir_query_levels      /**< Texture levels query */
> +   ir_query_levels,     /**< Texture levels query */
> +   ir_texture_samples,  /**< Texture samples query */
>  };
>  
>  
> diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
> index a8fac18..a2cd672 100644
> --- a/src/glsl/ir_clone.cpp
> +++ b/src/glsl/ir_clone.cpp
> @@ -222,6 +222,7 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
>     case ir_tex:
>     case ir_lod:
>     case ir_query_levels:
> +   case ir_texture_samples:
>        break;
>     case ir_txb:
>        new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht);
> diff --git a/src/glsl/ir_equals.cpp b/src/glsl/ir_equals.cpp
> index cc1964e..5f0785e 100644
> --- a/src/glsl/ir_equals.cpp
> +++ b/src/glsl/ir_equals.cpp
> @@ -151,6 +151,7 @@ ir_texture::equals(const ir_instruction *ir, enum ir_node_type ignore) const
>     case ir_tex:
>     case ir_lod:
>     case ir_query_levels:
> +   case ir_texture_samples:
>        break;
>     case ir_txb:
>        if (!lod_info.bias->equals(other->lod_info.bias, ignore))
> diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
> index d3662cf..6495cc4 100644
> --- a/src/glsl/ir_hv_accept.cpp
> +++ b/src/glsl/ir_hv_accept.cpp
> @@ -194,6 +194,7 @@ ir_texture::accept(ir_hierarchical_visitor *v)
>     case ir_tex:
>     case ir_lod:
>     case ir_query_levels:
> +   case ir_texture_samples:
>        break;
>     case ir_txb:
>        s = this->lod_info.bias->accept(v);
> diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
> index 8dbd938..5cfac94 100644
> --- a/src/glsl/ir_print_visitor.cpp
> +++ b/src/glsl/ir_print_visitor.cpp
> @@ -274,7 +274,8 @@ void ir_print_visitor::visit(ir_texture *ir)
>     ir->sampler->accept(this);
>     fprintf(f, " ");
>  
> -   if (ir->op != ir_txs && ir->op != ir_query_levels) {
> +   if (ir->op != ir_txs && ir->op != ir_query_levels &&
> +       ir->op != ir_texture_samples) {
>        ir->coordinate->accept(this);
>  
>        fprintf(f, " ");
> @@ -290,7 +291,7 @@ void ir_print_visitor::visit(ir_texture *ir)
>  
>     if (ir->op != ir_txf && ir->op != ir_txf_ms &&
>         ir->op != ir_txs && ir->op != ir_tg4 &&
> -       ir->op != ir_query_levels) {
> +       ir->op != ir_query_levels && ir->op != ir_texture_samples) {
>        if (ir->projector)
>  	 ir->projector->accept(this);
>        else
> @@ -310,6 +311,7 @@ void ir_print_visitor::visit(ir_texture *ir)
>     case ir_tex:
>     case ir_lod:
>     case ir_query_levels:
> +   case ir_texture_samples:
>        break;
>     case ir_txb:
>        ir->lod_info.bias->accept(this);
> diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
> index 469837f..4953ec4 100644
> --- a/src/glsl/ir_reader.cpp
> +++ b/src/glsl/ir_reader.cpp
> @@ -960,6 +960,8 @@ ir_reader::read_texture(s_expression *expr)
>        { "tg4", s_type, s_sampler, s_coord, s_offset, s_component };
>     s_pattern query_levels_pattern[] =
>        { "query_levels", s_type, s_sampler };
> +   s_pattern texture_samples_pattern[] =
> +      { "samples", s_type, s_sampler };
>     s_pattern other_pattern[] =
>        { tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
>  
> @@ -977,6 +979,8 @@ ir_reader::read_texture(s_expression *expr)
>        op = ir_tg4;
>     } else if (MATCH(expr, query_levels_pattern)) {
>        op = ir_query_levels;
> +   } else if (MATCH(expr, texture_samples_pattern)) {
> +      op = ir_texture_samples;
>     } else if (MATCH(expr, other_pattern)) {
>        op = ir_texture::get_opcode(tag->value());
>        if (op == (ir_texture_opcode) -1)
> @@ -1029,7 +1033,7 @@ ir_reader::read_texture(s_expression *expr)
>  
>     if (op != ir_txf && op != ir_txf_ms &&
>         op != ir_txs && op != ir_lod && op != ir_tg4 &&
> -       op != ir_query_levels) {
> +       op != ir_query_levels && op != ir_texture_samples) {
>        s_int *proj_as_int = SX_AS_INT(s_proj);
>        if (proj_as_int && proj_as_int->value() == 1) {
>  	 tex->projector = NULL;
> diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp
> index 2eee3da..a6966f5 100644
> --- a/src/glsl/ir_rvalue_visitor.cpp
> +++ b/src/glsl/ir_rvalue_visitor.cpp
> @@ -58,6 +58,7 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir)
>     case ir_tex:
>     case ir_lod:
>     case ir_query_levels:
> +   case ir_texture_samples:
>        break;
>     case ir_txb:
>        handle_rvalue(&ir->lod_info.bias);
> diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp
> index 7f2ee6c..a7a219c 100644
> --- a/src/glsl/opt_tree_grafting.cpp
> +++ b/src/glsl/opt_tree_grafting.cpp
> @@ -274,6 +274,7 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
>     case ir_tex:
>     case ir_lod:
>     case ir_query_levels:
> +   case ir_texture_samples:
>        break;
>     case ir_txb:
>        if (do_graft(&ir->lod_info.bias))
> diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
> index 8f58f3e..ed009d3 100644
> --- a/src/mesa/program/ir_to_mesa.cpp
> +++ b/src/mesa/program/ir_to_mesa.cpp
> @@ -1919,6 +1919,9 @@ ir_to_mesa_visitor::visit(ir_texture *ir)
>     case ir_query_levels:
>        assert(!"Unexpected ir_query_levels opcode");
>        break;
> +   case ir_texture_samples:
> +      assert(!"Unexpected ir_texture_samples opcode");
> +      break;

I think this should be unreachable(), like below.  What that changed,
this patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

I'll also give a preemptive R-b on a follow-up patch that converts the
other assert(!"Unexpected ... opcode"); lines to unreachable(). :)

>     }
>  
>     const glsl_type *sampler_type = ir->sampler->type;
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 95a25c1..72abedd 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -3231,6 +3231,8 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir)
>     case ir_lod:
>        opcode = TGSI_OPCODE_LODQ;
>        break;
> +   case ir_texture_samples:
> +      unreachable("unexpected texture op");
>     }
>  
>     if (ir->projector) {
> 



More information about the mesa-dev mailing list