summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiang Yu <yuq825@gmail.com>2022-01-06 14:25:07 +0800
committerMarge Bot <emma+marge@anholt.net>2022-02-01 10:28:05 +0000
commit92d6b2735b7a29fa9cb4cb37566231732ecff617 (patch)
treeeda1ec71a49b3e2f3d7dc4de23fec29333bf057b
parent13ffd46a0fbedf37ebd4625bd3c9055e79516480 (diff)
glsl: ir_texture add clamp field
For ARB_sparse_texture_clamp to hold the lodClamp parameter. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Signed-off-by: Qiang Yu <yuq825@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14488>
-rw-r--r--src/compiler/glsl/ir.h25
-rw-r--r--src/compiler/glsl/ir_clone.cpp5
-rw-r--r--src/compiler/glsl/ir_equals.cpp3
-rw-r--r--src/compiler/glsl/ir_hv_accept.cpp6
-rw-r--r--src/compiler/glsl/ir_print_visitor.cpp9
-rw-r--r--src/compiler/glsl/ir_reader.cpp24
-rw-r--r--src/compiler/glsl/ir_rvalue_visitor.cpp1
-rw-r--r--src/compiler/glsl/opt_tree_grafting.cpp3
8 files changed, 62 insertions, 14 deletions
diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index 1842c6d6b81..e8097728cb2 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -1884,18 +1884,19 @@ enum ir_texture_opcode {
* Texel offset (0 or an expression)
* | Projection divisor
* | | Shadow comparator
- * | | |
- * v v v
- * (tex <type> <sampler> <coordinate> <sparse> 0 1 ( ))
- * (txb <type> <sampler> <coordinate> <sparse> 0 1 ( ) <bias>)
- * (txl <type> <sampler> <coordinate> <sparse> 0 1 ( ) <lod>)
- * (txd <type> <sampler> <coordinate> <sparse> 0 1 ( ) (dPdx dPdy))
- * (txf <type> <sampler> <coordinate> <sparse> 0 <lod>)
+ * | | | Lod clamp
+ * | | | |
+ * v v v v
+ * (tex <type> <sampler> <coordinate> <sparse> 0 1 ( ) ( ))
+ * (txb <type> <sampler> <coordinate> <sparse> 0 1 ( ) ( ) <bias>)
+ * (txl <type> <sampler> <coordinate> <sparse> 0 1 ( ) <lod>)
+ * (txd <type> <sampler> <coordinate> <sparse> 0 1 ( ) ( ) (dPdx dPdy))
+ * (txf <type> <sampler> <coordinate> <sparse> 0 <lod>)
* (txf_ms
- * <type> <sampler> <coordinate> <sparse> <sample_index>)
+ * <type> <sampler> <coordinate> <sparse> <sample_index>)
* (txs <type> <sampler> <lod>)
* (lod <type> <sampler> <coordinate>)
- * (tg4 <type> <sampler> <coordinate> <sparse> <offset> <component>)
+ * (tg4 <type> <sampler> <coordinate> <sparse> <offset> <component>)
* (query_levels <type> <sampler>)
* (samples_identical <sampler> <coordinate>)
*/
@@ -1904,7 +1905,8 @@ public:
ir_texture(enum ir_texture_opcode op, bool sparse = false)
: ir_rvalue(ir_type_texture),
op(op), sampler(NULL), coordinate(NULL), projector(NULL),
- shadow_comparator(NULL), offset(NULL), is_sparse(sparse)
+ shadow_comparator(NULL), offset(NULL), clamp(NULL),
+ is_sparse(sparse)
{
memset(&lod_info, 0, sizeof(lod_info));
}
@@ -1965,6 +1967,9 @@ public:
/** Texel offset. */
ir_rvalue *offset;
+ /** Lod clamp. */
+ ir_rvalue *clamp;
+
union {
ir_rvalue *lod; /**< Floating point LOD */
ir_rvalue *bias; /**< Floating point LOD bias */
diff --git a/src/compiler/glsl/ir_clone.cpp b/src/compiler/glsl/ir_clone.cpp
index 857a1b85d96..dcf02b5d29a 100644
--- a/src/compiler/glsl/ir_clone.cpp
+++ b/src/compiler/glsl/ir_clone.cpp
@@ -218,9 +218,10 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
new_tex->coordinate = this->coordinate->clone(mem_ctx, ht);
if (this->projector)
new_tex->projector = this->projector->clone(mem_ctx, ht);
- if (this->shadow_comparator) {
+ if (this->shadow_comparator)
new_tex->shadow_comparator = this->shadow_comparator->clone(mem_ctx, ht);
- }
+ if (this->clamp)
+ new_tex->clamp = this->clamp->clone(mem_ctx, ht);
if (this->offset != NULL)
new_tex->offset = this->offset->clone(mem_ctx, ht);
diff --git a/src/compiler/glsl/ir_equals.cpp b/src/compiler/glsl/ir_equals.cpp
index 8ad6fa93f64..e26c7d82233 100644
--- a/src/compiler/glsl/ir_equals.cpp
+++ b/src/compiler/glsl/ir_equals.cpp
@@ -152,6 +152,9 @@ ir_texture::equals(const ir_instruction *ir, enum ir_node_type ignore) const
if (!possibly_null_equals(offset, other->offset, ignore))
return false;
+ if (!possibly_null_equals(clamp, other->clamp, ignore))
+ return false;
+
if (!sampler->equals(other->sampler, ignore))
return false;
diff --git a/src/compiler/glsl/ir_hv_accept.cpp b/src/compiler/glsl/ir_hv_accept.cpp
index 6e5e25378e1..93eda6783e0 100644
--- a/src/compiler/glsl/ir_hv_accept.cpp
+++ b/src/compiler/glsl/ir_hv_accept.cpp
@@ -190,6 +190,12 @@ ir_texture::accept(ir_hierarchical_visitor *v)
return (s == visit_continue_with_parent) ? visit_continue : s;
}
+ if (this->clamp) {
+ s = this->clamp->accept(v);
+ if (s != visit_continue)
+ return (s == visit_continue_with_parent) ? visit_continue : s;
+ }
+
switch (this->op) {
case ir_tex:
case ir_lod:
diff --git a/src/compiler/glsl/ir_print_visitor.cpp b/src/compiler/glsl/ir_print_visitor.cpp
index 3da0abede14..8e7204f9715 100644
--- a/src/compiler/glsl/ir_print_visitor.cpp
+++ b/src/compiler/glsl/ir_print_visitor.cpp
@@ -349,6 +349,15 @@ void ir_print_visitor::visit(ir_texture *ir)
}
}
+ if (ir->op == ir_tex || ir->op == ir_txb || ir->op == ir_txd) {
+ if (ir->clamp) {
+ fprintf(f, " ");
+ ir->clamp->accept(this);
+ } else {
+ fprintf(f, " ()");
+ }
+ }
+
fprintf(f, " ");
switch (ir->op)
{
diff --git a/src/compiler/glsl/ir_reader.cpp b/src/compiler/glsl/ir_reader.cpp
index c7eb5624c3a..31ded355d0b 100644
--- a/src/compiler/glsl/ir_reader.cpp
+++ b/src/compiler/glsl/ir_reader.cpp
@@ -943,6 +943,7 @@ ir_reader::read_texture(s_expression *expr)
s_expression *s_offset = NULL;
s_expression *s_proj = NULL;
s_list *s_shadow = NULL;
+ s_list *s_clamp = NULL;
s_expression *s_lod = NULL;
s_expression *s_sample_index = NULL;
s_expression *s_component = NULL;
@@ -950,7 +951,11 @@ ir_reader::read_texture(s_expression *expr)
ir_texture_opcode op = ir_tex; /* silence warning */
s_pattern tex_pattern[] =
- { "tex", s_type, s_sampler, s_coord, s_sparse, s_offset, s_proj, s_shadow };
+ { "tex", s_type, s_sampler, s_coord, s_sparse, s_offset, s_proj, s_shadow, s_clamp };
+ s_pattern txb_pattern[] =
+ { "txb", s_type, s_sampler, s_coord, s_sparse, s_offset, s_proj, s_shadow, s_clamp, s_lod };
+ s_pattern txd_pattern[] =
+ { "txd", s_type, s_sampler, s_coord, s_sparse, s_offset, s_proj, s_shadow, s_clamp, s_lod };
s_pattern lod_pattern[] =
{ "lod", s_type, s_sampler, s_coord };
s_pattern txf_pattern[] =
@@ -972,6 +977,10 @@ ir_reader::read_texture(s_expression *expr)
op = ir_lod;
} else if (MATCH(expr, tex_pattern)) {
op = ir_tex;
+ } else if (MATCH(expr, txb_pattern)) {
+ op = ir_txb;
+ } else if (MATCH(expr, txd_pattern)) {
+ op = ir_txd;
} else if (MATCH(expr, txf_pattern)) {
op = ir_txf;
} else if (MATCH(expr, txf_ms_pattern)) {
@@ -1080,6 +1089,19 @@ ir_reader::read_texture(s_expression *expr)
}
}
+ if (op == ir_tex || op == ir_txb || op == ir_txd) {
+ if (s_clamp->subexpressions.is_empty()) {
+ tex->clamp = NULL;
+ } else {
+ tex->clamp = read_rvalue(s_clamp);
+ if (tex->clamp == NULL) {
+ ir_read_error(NULL, "when reading clamp in (%s ..)",
+ tex->opcode_string());
+ return NULL;
+ }
+ }
+ }
+
switch (op) {
case ir_txb:
tex->lod_info.bias = read_rvalue(s_lod);
diff --git a/src/compiler/glsl/ir_rvalue_visitor.cpp b/src/compiler/glsl/ir_rvalue_visitor.cpp
index 72dd6201ec9..d7a4f6689a9 100644
--- a/src/compiler/glsl/ir_rvalue_visitor.cpp
+++ b/src/compiler/glsl/ir_rvalue_visitor.cpp
@@ -53,6 +53,7 @@ ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir)
handle_rvalue(&ir->projector);
handle_rvalue(&ir->shadow_comparator);
handle_rvalue(&ir->offset);
+ handle_rvalue(&ir->clamp);
switch (ir->op) {
case ir_tex:
diff --git a/src/compiler/glsl/opt_tree_grafting.cpp b/src/compiler/glsl/opt_tree_grafting.cpp
index 6b5d93af661..13ed6963696 100644
--- a/src/compiler/glsl/opt_tree_grafting.cpp
+++ b/src/compiler/glsl/opt_tree_grafting.cpp
@@ -267,7 +267,8 @@ ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
if (do_graft(&ir->coordinate) ||
do_graft(&ir->projector) ||
do_graft(&ir->offset) ||
- do_graft(&ir->shadow_comparator))
+ do_graft(&ir->shadow_comparator) ||
+ do_graft(&ir->clamp))
return visit_stop;
switch (ir->op) {