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 <chrisf@ijw.co.nz>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Chris Forbes
2013-10-05 18:26:56 +13:00
parent f93a63bfcc
commit 88ee9bc9d1
8 changed files with 42 additions and 7 deletions

View File

@@ -493,6 +493,7 @@ private:
/** Flags to _texture() */ /** Flags to _texture() */
#define TEX_PROJECT 1 #define TEX_PROJECT 1
#define TEX_OFFSET 2 #define TEX_OFFSET 2
#define TEX_COMPONENT 4
ir_function_signature *_texture(ir_texture_opcode opcode, ir_function_signature *_texture(ir_texture_opcode opcode,
builtin_available_predicate avail, builtin_available_predicate avail,
@@ -3322,6 +3323,18 @@ builtin_builder::_texture(ir_texture_opcode opcode,
tex->offset = var_ref(offset); 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 /* The "bias" parameter comes /after/ the "offset" parameter, which is
* inconsistent with both textureLodOffset and textureGradOffset. * inconsistent with both textureLodOffset and textureGradOffset.
*/ */

View File

@@ -1586,7 +1586,7 @@ enum ir_texture_opcode {
* <type> <sampler> <coordinate> <sample_index>) * <type> <sampler> <coordinate> <sample_index>)
* (txs <type> <sampler> <lod>) * (txs <type> <sampler> <lod>)
* (lod <type> <sampler> <coordinate>) * (lod <type> <sampler> <coordinate>)
* (tg4 <type> <sampler> <coordinate> 0) * (tg4 <type> <sampler> <coordinate> <offset> <component>)
* (query_levels <type> <sampler>) * (query_levels <type> <sampler>)
*/ */
class ir_texture : public ir_rvalue { class ir_texture : public ir_rvalue {
@@ -1655,6 +1655,7 @@ public:
ir_rvalue *lod; /**< Floating point LOD */ ir_rvalue *lod; /**< Floating point LOD */
ir_rvalue *bias; /**< Floating point LOD bias */ ir_rvalue *bias; /**< Floating point LOD bias */
ir_rvalue *sample_index; /**< MSAA sample index */ ir_rvalue *sample_index; /**< MSAA sample index */
ir_rvalue *component; /**< Gather component selector */
struct { struct {
ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */ ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */ ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */

View File

@@ -248,7 +248,6 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
switch (this->op) { switch (this->op) {
case ir_tex: case ir_tex:
case ir_lod: case ir_lod:
case ir_tg4:
case ir_query_levels: case ir_query_levels:
break; break;
case ir_txb: 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.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); new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(mem_ctx, ht);
break; break;
case ir_tg4:
new_tex->lod_info.component = this->lod_info.component->clone(mem_ctx, ht);
break;
} }
return new_tex; return new_tex;

View File

@@ -214,7 +214,6 @@ ir_texture::accept(ir_hierarchical_visitor *v)
switch (this->op) { switch (this->op) {
case ir_tex: case ir_tex:
case ir_lod: case ir_lod:
case ir_tg4:
case ir_query_levels: case ir_query_levels:
break; break;
case ir_txb: case ir_txb:
@@ -243,6 +242,11 @@ ir_texture::accept(ir_hierarchical_visitor *v)
if (s != visit_continue) if (s != visit_continue)
return (s == visit_continue_with_parent) ? visit_continue : s; return (s == visit_continue_with_parent) ? visit_continue : s;
break; 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); return (s == visit_stop) ? s : v->visit_leave(this);

View File

@@ -287,7 +287,6 @@ void ir_print_visitor::visit(ir_texture *ir)
{ {
case ir_tex: case ir_tex:
case ir_lod: case ir_lod:
case ir_tg4:
case ir_query_levels: case ir_query_levels:
break; break;
case ir_txb: case ir_txb:
@@ -308,6 +307,9 @@ void ir_print_visitor::visit(ir_texture *ir)
ir->lod_info.grad.dPdy->accept(this); ir->lod_info.grad.dPdy->accept(this);
printf(")"); printf(")");
break; break;
case ir_tg4:
ir->lod_info.component->accept(this);
break;
}; };
printf(")"); printf(")");
} }

View File

@@ -934,6 +934,7 @@ ir_reader::read_texture(s_expression *expr)
s_list *s_shadow = NULL; s_list *s_shadow = NULL;
s_expression *s_lod = NULL; s_expression *s_lod = NULL;
s_expression *s_sample_index = NULL; s_expression *s_sample_index = NULL;
s_expression *s_component = NULL;
ir_texture_opcode op = ir_tex; /* silence warning */ ir_texture_opcode op = ir_tex; /* silence warning */
@@ -948,7 +949,7 @@ ir_reader::read_texture(s_expression *expr)
s_pattern txs_pattern[] = s_pattern txs_pattern[] =
{ "txs", s_type, s_sampler, s_lod }; { "txs", s_type, s_sampler, s_lod };
s_pattern tg4_pattern[] = 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[] = s_pattern query_levels_pattern[] =
{ "query_levels", s_type, s_sampler }; { "query_levels", s_type, s_sampler };
s_pattern other_pattern[] = s_pattern other_pattern[] =
@@ -1089,6 +1090,13 @@ ir_reader::read_texture(s_expression *expr)
} }
break; 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: default:
// tex and lod don't have any extra parameters. // tex and lod don't have any extra parameters.
break; break;

View File

@@ -57,7 +57,6 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir)
switch (ir->op) { switch (ir->op) {
case ir_tex: case ir_tex:
case ir_lod: case ir_lod:
case ir_tg4:
case ir_query_levels: case ir_query_levels:
break; break;
case ir_txb: 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.dPdx);
handle_rvalue(&ir->lod_info.grad.dPdy); handle_rvalue(&ir->lod_info.grad.dPdy);
break; break;
case ir_tg4:
handle_rvalue(&ir->lod_info.component);
break;
} }
return visit_continue; return visit_continue;

View File

@@ -275,7 +275,6 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
switch (ir->op) { switch (ir->op) {
case ir_tex: case ir_tex:
case ir_lod: case ir_lod:
case ir_tg4:
case ir_query_levels: case ir_query_levels:
break; break;
case ir_txb: case ir_txb:
@@ -297,6 +296,10 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
do_graft(&ir->lod_info.grad.dPdy)) do_graft(&ir->lod_info.grad.dPdy))
return visit_stop; return visit_stop;
break; break;
case ir_tg4:
if (do_graft(&ir->lod_info.component))
return visit_stop;
break;
} }
return visit_continue; return visit_continue;