glsl: Add a new ir_txs (textureSize) opcode to ir_texture.

One unique aspect of TXS is that it doesn't have a coordinate.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Kenneth Graunke 2011-02-25 14:45:33 -08:00
parent 8f26b59f53
commit 1e3bcbdf31
11 changed files with 65 additions and 36 deletions

View File

@ -1121,7 +1121,7 @@ ir_dereference::is_lvalue() const
}
const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf" };
const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txs" };
const char *ir_texture::opcode_string()
{
@ -1150,11 +1150,15 @@ ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type)
this->sampler = sampler;
this->type = type;
assert(sampler->type->sampler_type == (int) type->base_type);
if (sampler->type->sampler_shadow)
assert(type->vector_elements == 4 || type->vector_elements == 1);
else
assert(type->vector_elements == 4);
if (this->op == ir_txs) {
assert(type->base_type == GLSL_TYPE_INT);
} else {
assert(sampler->type->sampler_type == (int) type->base_type);
if (sampler->type->sampler_shadow)
assert(type->vector_elements == 4 || type->vector_elements == 1);
else
assert(type->vector_elements == 4);
}
}

View File

@ -1212,7 +1212,8 @@ enum ir_texture_opcode {
ir_txb, /**< Texture look-up with LOD bias */
ir_txl, /**< Texture look-up with explicit LOD */
ir_txd, /**< Texture look-up with partial derivatvies */
ir_txf /**< Texel fetch with explicit LOD */
ir_txf, /**< Texel fetch with explicit LOD */
ir_txs /**< Texture size */
};
@ -1233,6 +1234,7 @@ enum ir_texture_opcode {
* (txl <type> <sampler> <coordinate> 0 1 ( ) <lod>)
* (txd <type> <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
* (txf <type> <sampler> <coordinate> 0 <lod>)
* (txs <type> <sampler> <lod>)
*/
class ir_texture : public ir_rvalue {
public:

View File

@ -222,7 +222,8 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
new_tex->type = this->type;
new_tex->sampler = this->sampler->clone(mem_ctx, ht);
new_tex->coordinate = this->coordinate->clone(mem_ctx, ht);
if (this->coordinate)
new_tex->coordinate = this->coordinate->clone(mem_ctx, ht);
if (this->projector)
new_tex->projector = this->projector->clone(mem_ctx, ht);
if (this->shadow_comparitor) {
@ -240,6 +241,7 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
break;
case ir_txl:
case ir_txf:
case ir_txs:
new_tex->lod_info.lod = this->lod_info.lod->clone(mem_ctx, ht);
break;
case ir_txd:

View File

@ -171,9 +171,11 @@ ir_texture::accept(ir_hierarchical_visitor *v)
if (s != visit_continue)
return (s == visit_continue_with_parent) ? visit_continue : s;
s = this->coordinate->accept(v);
if (s != visit_continue)
return (s == visit_continue_with_parent) ? visit_continue : s;
if (this->coordinate) {
s = this->coordinate->accept(v);
if (s != visit_continue)
return (s == visit_continue_with_parent) ? visit_continue : s;
}
if (this->projector) {
s = this->projector->accept(v);
@ -203,6 +205,7 @@ ir_texture::accept(ir_hierarchical_visitor *v)
break;
case ir_txl:
case ir_txf:
case ir_txs:
s = this->lod_info.lod->accept(v);
if (s != visit_continue)
return (s == visit_continue_with_parent) ? visit_continue : s;

View File

@ -244,19 +244,21 @@ void ir_print_visitor::visit(ir_texture *ir)
ir->sampler->accept(this);
printf(" ");
ir->coordinate->accept(this);
if (ir->op != ir_txs) {
ir->coordinate->accept(this);
printf(" ");
printf(" ");
if (ir->offset != NULL) {
ir->offset->accept(this);
} else {
printf("0");
if (ir->offset != NULL) {
ir->offset->accept(this);
} else {
printf("0");
}
printf(" ");
}
printf(" ");
if (ir->op != ir_txf) {
if (ir->op != ir_txf && ir->op != ir_txs) {
if (ir->projector)
ir->projector->accept(this);
else
@ -280,6 +282,7 @@ void ir_print_visitor::visit(ir_texture *ir)
break;
case ir_txl:
case ir_txf:
case ir_txs:
ir->lod_info.lod->accept(this);
break;
case ir_txd:

View File

@ -885,6 +885,8 @@ ir_reader::read_texture(s_expression *expr)
{ "tex", s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow };
s_pattern txf_pattern[] =
{ "txf", s_type, s_sampler, s_coord, s_offset, s_lod };
s_pattern txs_pattern[] =
{ "txs", s_type, s_sampler, s_lod };
s_pattern other_pattern[] =
{ tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
@ -892,6 +894,8 @@ ir_reader::read_texture(s_expression *expr)
op = ir_tex;
} else if (MATCH(expr, txf_pattern)) {
op = ir_txf;
} else if (MATCH(expr, txs_pattern)) {
op = ir_txs;
} else if (MATCH(expr, other_pattern)) {
op = ir_texture::get_opcode(tag->value());
if (op == -1)
@ -920,25 +924,27 @@ ir_reader::read_texture(s_expression *expr)
}
tex->set_sampler(sampler, type);
// Read coordinate (any rvalue)
tex->coordinate = read_rvalue(s_coord);
if (tex->coordinate == NULL) {
ir_read_error(NULL, "when reading coordinate in (%s ...)",
tex->opcode_string());
return NULL;
}
// Read texel offset - either 0 or an rvalue.
s_int *si_offset = SX_AS_INT(s_offset);
if (si_offset == NULL || si_offset->value() != 0) {
tex->offset = read_rvalue(s_offset);
if (tex->offset == NULL) {
ir_read_error(s_offset, "expected 0 or an expression");
if (op != ir_txs) {
// Read coordinate (any rvalue)
tex->coordinate = read_rvalue(s_coord);
if (tex->coordinate == NULL) {
ir_read_error(NULL, "when reading coordinate in (%s ...)",
tex->opcode_string());
return NULL;
}
// Read texel offset - either 0 or an rvalue.
s_int *si_offset = SX_AS_INT(s_offset);
if (si_offset == NULL || si_offset->value() != 0) {
tex->offset = read_rvalue(s_offset);
if (tex->offset == NULL) {
ir_read_error(s_offset, "expected 0 or an expression");
return NULL;
}
}
}
if (op != ir_txf) {
if (op != ir_txf && op != ir_txs) {
s_int *proj_as_int = SX_AS_INT(s_proj);
if (proj_as_int && proj_as_int->value() == 1) {
tex->projector = NULL;
@ -973,6 +979,7 @@ ir_reader::read_texture(s_expression *expr)
break;
case ir_txl:
case ir_txf:
case ir_txs:
tex->lod_info.lod = read_rvalue(s_lod);
if (tex->lod_info.lod == NULL) {
ir_read_error(NULL, "when reading LOD in (%s ...)",

View File

@ -63,6 +63,7 @@ ir_rvalue_visitor::visit_leave(ir_texture *ir)
break;
case ir_txf:
case ir_txl:
case ir_txs:
handle_rvalue(&ir->lod_info.lod);
break;
case ir_txd:

View File

@ -258,6 +258,7 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
break;
case ir_txf:
case ir_txl:
case ir_txs:
if (do_graft(&ir->lod_info.lod))
return visit_stop;
break;

View File

@ -716,6 +716,7 @@ fs_visitor::emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate,
inst = emit(FS_OPCODE_TXD, dst);
break;
case ir_txf:
case ir_txs:
assert(!"GLSL 1.30 features unsupported");
break;
}
@ -837,6 +838,7 @@ fs_visitor::emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate,
break;
}
case ir_txf:
case ir_txs:
assert(!"GLSL 1.30 features unsupported");
break;
}
@ -926,6 +928,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
break;
}
case ir_txf:
case ir_txs:
assert(!"GLSL 1.30 features unsupported");
break;
}
@ -949,7 +952,8 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate,
case ir_txb: inst = emit(FS_OPCODE_TXB, dst); break;
case ir_txl: inst = emit(FS_OPCODE_TXL, dst); break;
case ir_txd: inst = emit(FS_OPCODE_TXD, dst); break;
case ir_txf: assert(!"TXF unsupported.");
case ir_txf: assert(!"TXF unsupported."); break;
case ir_txs: assert(!"TXS unsupported."); break;
}
inst->base_mrf = base_mrf;
inst->mlen = mlen;

View File

@ -2148,6 +2148,7 @@ ir_to_mesa_visitor::visit(ir_texture *ir)
dy = this->result;
break;
case ir_txf:
case ir_txs:
assert(!"GLSL 1.30 features unsupported");
break;
}

View File

@ -2469,6 +2469,7 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir)
ir->lod_info.grad.dPdy->accept(this);
dy = this->result;
break;
case ir_txs:
case ir_txf: /* TODO: use TGSI_OPCODE_TXF here */
assert(!"GLSL 1.30 features unsupported");
break;