summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2011-02-25 14:45:33 -0800
committerKenneth Graunke <kenneth@whitecape.org>2011-08-23 11:16:30 -0700
commit1e3bcbdf31f09666ba358f35ff9486faee3642ca (patch)
tree39562690d676bc99140a67492219475215d0c0bb /src
parent8f26b59f53d6d80bf7d3c39a4dd3c438a2c305a4 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/glsl/ir.cpp16
-rw-r--r--src/glsl/ir.h4
-rw-r--r--src/glsl/ir_clone.cpp4
-rw-r--r--src/glsl/ir_hv_accept.cpp9
-rw-r--r--src/glsl/ir_print_visitor.cpp21
-rw-r--r--src/glsl/ir_reader.cpp37
-rw-r--r--src/glsl/ir_rvalue_visitor.cpp1
-rw-r--r--src/glsl/opt_tree_grafting.cpp1
-rw-r--r--src/mesa/drivers/dri/i965/brw_fs_visitor.cpp6
-rw-r--r--src/mesa/program/ir_to_mesa.cpp1
-rw-r--r--src/mesa/state_tracker/st_glsl_to_tgsi.cpp1
11 files changed, 65 insertions, 36 deletions
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 6f8676ecce..41ed4f114c 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -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);
+ }
}
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 04fa97bf56..990aaa16af 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -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:
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 069bb85e8d..f0757365dd 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -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:
diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
index 4a607dc874..d33fc85bf0 100644
--- a/src/glsl/ir_hv_accept.cpp
+++ b/src/glsl/ir_hv_accept.cpp
@@ -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;
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index 518910bd12..ea7858224b 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -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:
diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
index f3a621734b..22009eebcb 100644
--- a/src/glsl/ir_reader.cpp
+++ b/src/glsl/ir_reader.cpp
@@ -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 ...)",
diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp
index ed6c7cb6a1..193bcd2d7b 100644
--- a/src/glsl/ir_rvalue_visitor.cpp
+++ b/src/glsl/ir_rvalue_visitor.cpp
@@ -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:
diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp
index 1ef940f9c7..22a1749b9d 100644
--- a/src/glsl/opt_tree_grafting.cpp
+++ b/src/glsl/opt_tree_grafting.cpp
@@ -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;
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 33ad12763f..764351a34f 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -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;
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index ec3fba182d..b222005d1a 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -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;
}
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 4b3e00c424..6f0d9fa3f8 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -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;