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>
This commit is contained in:
Qiang Yu
2022-01-06 14:25:07 +08:00
committed by Marge Bot
parent 13ffd46a0f
commit 92d6b2735b
8 changed files with 62 additions and 14 deletions

View File

@@ -1884,12 +1884,13 @@ 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>)
* | | | 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))
* (txd <type> <sampler> <coordinate> <sparse> 0 1 ( ) ( ) (dPdx dPdy))
* (txf <type> <sampler> <coordinate> <sparse> 0 <lod>)
* (txf_ms
* <type> <sampler> <coordinate> <sparse> <sample_index>)
@@ -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 */

View File

@@ -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);

View File

@@ -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;

View File

@@ -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:

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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:

View File

@@ -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) {