[Mesa-dev] [PATCH 1/5] glsl: Add support for specifying the component in textureGather
Kenneth Graunke
kenneth at whitecape.org
Sat Oct 5 10:54:51 PDT 2013
On 10/05/2013 03:38 AM, Chris Forbes wrote:
> 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 <chrisf at ijw.co.nz>
> ---
> src/glsl/builtin_functions.cpp | 11 +++++++++++
> src/glsl/ir.h | 3 ++-
> src/glsl/ir_clone.cpp | 4 +++-
> src/glsl/ir_hv_accept.cpp | 6 +++++-
> src/glsl/ir_print_visitor.cpp | 4 +++-
> src/glsl/ir_reader.cpp | 10 +++++++++-
> src/glsl/ir_rvalue_visitor.cpp | 4 +++-
> src/glsl/opt_tree_grafting.cpp | 5 ++++-
> 8 files changed, 40 insertions(+), 7 deletions(-)
>
> diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
> index 40084f7..3c1ab94 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,16 @@ builtin_builder::_texture(ir_texture_opcode opcode,
> tex->offset = var_ref(offset);
> }
>
> + 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 if (opcode == ir_tg4) {
Modern Mesa style is:
} else if (opcode == ir_tg4) {
> + tex->lod_info.component = imm(0);
> + }
but this might be clearer if you wrote it as:
if (opcode == ir_tg4) {
if (flags & TEX_COMPONENT) {
...
} else {
tex->lod_info.component = imm(0);
}
}
With either of those changes, patches 1-2 are:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
> +
> /* 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 37f79f4..1a4a3a2 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -1586,7 +1586,7 @@ enum ir_texture_opcode {
> * <type> <sampler> <coordinate> <sample_index>)
> * (txs <type> <sampler> <lod>)
> * (lod <type> <sampler> <coordinate>)
> - * (tg4 <type> <sampler> <coordinate> 0)
> + * (tg4 <type> <sampler> <coordinate> <offset> <component>)
> * (query_levels <type> <sampler>)
> */
> 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 8a40cb0..dde22e0 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 3aa008a..941b25e 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 531adc2..f85e573 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 ea0c09a..00e2db9 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 2a79e4d..9d8ccd9 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 bbdc437..46c06e6 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;
>
More information about the mesa-dev
mailing list