From: Chris Forbes Date: Sat, 5 Oct 2013 05:26:56 +0000 (+1300) Subject: glsl: Add support for specifying the component in textureGather X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=88ee9bc9d1dd66ddb9721dc44574b8caaa26df70;p=mesa.git glsl: Add support for specifying the component in textureGather ARB_gpu_shader5 introduces new variants of textureGather* which have an explicit component selector, rather than relying purely on the sampler's swizzle state. This patch adds the GLSL plumbing for the extra parameter. Signed-off-by: Chris Forbes Reviewed-by: Kenneth Graunke --- diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp index 40084f79f51..75c6da81e31 100644 --- a/src/glsl/builtin_functions.cpp +++ b/src/glsl/builtin_functions.cpp @@ -493,6 +493,7 @@ private: /** Flags to _texture() */ #define TEX_PROJECT 1 #define TEX_OFFSET 2 +#define TEX_COMPONENT 4 ir_function_signature *_texture(ir_texture_opcode opcode, builtin_available_predicate avail, @@ -3322,6 +3323,18 @@ builtin_builder::_texture(ir_texture_opcode opcode, tex->offset = var_ref(offset); } + if (opcode == ir_tg4) { + if (flags & TEX_COMPONENT) { + ir_variable *component = + new(mem_ctx) ir_variable(glsl_type::int_type, "comp", ir_var_const_in); + sig->parameters.push_tail(component); + tex->lod_info.component = var_ref(component); + } + else { + tex->lod_info.component = imm(0); + } + } + /* The "bias" parameter comes /after/ the "offset" parameter, which is * inconsistent with both textureLodOffset and textureGradOffset. */ diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 37f79f44588..1a4a3a2e36b 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -1586,7 +1586,7 @@ enum ir_texture_opcode { * ) * (txs ) * (lod ) - * (tg4 0) + * (tg4 ) * (query_levels ) */ class ir_texture : public ir_rvalue { @@ -1655,6 +1655,7 @@ public: ir_rvalue *lod; /**< Floating point LOD */ ir_rvalue *bias; /**< Floating point LOD bias */ ir_rvalue *sample_index; /**< MSAA sample index */ + ir_rvalue *component; /**< Gather component selector */ struct { ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */ ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */ diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 8a40cb01b2f..dde22e01846 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -248,7 +248,6 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const switch (this->op) { case ir_tex: case ir_lod: - case ir_tg4: case ir_query_levels: break; case ir_txb: @@ -266,6 +265,9 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(mem_ctx, ht); new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(mem_ctx, ht); break; + case ir_tg4: + new_tex->lod_info.component = this->lod_info.component->clone(mem_ctx, ht); + break; } return new_tex; diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp index 3aa008ac982..941b25e97c4 100644 --- a/src/glsl/ir_hv_accept.cpp +++ b/src/glsl/ir_hv_accept.cpp @@ -214,7 +214,6 @@ ir_texture::accept(ir_hierarchical_visitor *v) switch (this->op) { case ir_tex: case ir_lod: - case ir_tg4: case ir_query_levels: break; case ir_txb: @@ -243,6 +242,11 @@ ir_texture::accept(ir_hierarchical_visitor *v) if (s != visit_continue) return (s == visit_continue_with_parent) ? visit_continue : s; break; + case ir_tg4: + s = this->lod_info.component->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + break; } return (s == visit_stop) ? s : v->visit_leave(this); diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp index 531adc2997d..f85e573c43e 100644 --- a/src/glsl/ir_print_visitor.cpp +++ b/src/glsl/ir_print_visitor.cpp @@ -287,7 +287,6 @@ void ir_print_visitor::visit(ir_texture *ir) { case ir_tex: case ir_lod: - case ir_tg4: case ir_query_levels: break; case ir_txb: @@ -308,6 +307,9 @@ void ir_print_visitor::visit(ir_texture *ir) ir->lod_info.grad.dPdy->accept(this); printf(")"); break; + case ir_tg4: + ir->lod_info.component->accept(this); + break; }; printf(")"); } diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index ea0c09aebeb..00e2db9a3f0 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -934,6 +934,7 @@ ir_reader::read_texture(s_expression *expr) s_list *s_shadow = NULL; s_expression *s_lod = NULL; s_expression *s_sample_index = NULL; + s_expression *s_component = NULL; ir_texture_opcode op = ir_tex; /* silence warning */ @@ -948,7 +949,7 @@ ir_reader::read_texture(s_expression *expr) s_pattern txs_pattern[] = { "txs", s_type, s_sampler, s_lod }; s_pattern tg4_pattern[] = - { "tg4", s_type, s_sampler, s_coord, s_offset }; + { "tg4", s_type, s_sampler, s_coord, s_offset, s_component }; s_pattern query_levels_pattern[] = { "query_levels", s_type, s_sampler }; s_pattern other_pattern[] = @@ -1089,6 +1090,13 @@ ir_reader::read_texture(s_expression *expr) } break; } + case ir_tg4: + tex->lod_info.component = read_rvalue(s_component); + if (tex->lod_info.component == NULL) { + ir_read_error(NULL, "when reading component in (tg4 ...)"); + return NULL; + } + break; default: // tex and lod don't have any extra parameters. break; diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp index 2a79e4d8fb9..9d8ccd94a06 100644 --- a/src/glsl/ir_rvalue_visitor.cpp +++ b/src/glsl/ir_rvalue_visitor.cpp @@ -57,7 +57,6 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir) switch (ir->op) { case ir_tex: case ir_lod: - case ir_tg4: case ir_query_levels: break; case ir_txb: @@ -75,6 +74,9 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir) handle_rvalue(&ir->lod_info.grad.dPdx); handle_rvalue(&ir->lod_info.grad.dPdy); break; + case ir_tg4: + handle_rvalue(&ir->lod_info.component); + break; } return visit_continue; diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp index bbdc4375983..46c06e6c4a5 100644 --- a/src/glsl/opt_tree_grafting.cpp +++ b/src/glsl/opt_tree_grafting.cpp @@ -275,7 +275,6 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir) switch (ir->op) { case ir_tex: case ir_lod: - case ir_tg4: case ir_query_levels: break; case ir_txb: @@ -297,6 +296,10 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir) do_graft(&ir->lod_info.grad.dPdy)) return visit_stop; break; + case ir_tg4: + if (do_graft(&ir->lod_info.component)) + return visit_stop; + break; } return visit_continue;