glsl: ir_texture support sprase texture

Sparse ir_texture will set is_sparse and use struct type to
hold both residency code and sampled texel.

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/14362>
This commit is contained in:
Qiang Yu 2021-12-28 22:14:11 +08:00
parent 67b4c88512
commit dd84769c55
6 changed files with 60 additions and 22 deletions

View File

@ -1807,7 +1807,16 @@ ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type)
assert(sampler != NULL);
assert(type != NULL);
this->sampler = sampler;
this->type = type;
if (this->is_sparse) {
/* code holds residency info */
glsl_struct_field fields[2] = {
glsl_struct_field(glsl_type::int_type, "code"),
glsl_struct_field(type, "texel"),
};
this->type = glsl_type::get_struct_instance(fields, 2, "struct");
} else
this->type = type;
if (this->op == ir_txs || this->op == ir_query_levels ||
this->op == ir_texture_samples) {

View File

@ -1878,30 +1878,30 @@ enum ir_texture_opcode {
* selected from \c ir_texture_opcodes. In the printed IR, these will
* appear as:
*
* Texel offset (0 or an expression)
* | Projection divisor
* | | Shadow comparator
* | | |
* v v v
* (tex <type> <sampler> <coordinate> 0 1 ( ))
* (txb <type> <sampler> <coordinate> 0 1 ( ) <bias>)
* (txl <type> <sampler> <coordinate> 0 1 ( ) <lod>)
* (txd <type> <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
* (txf <type> <sampler> <coordinate> 0 <lod>)
* 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>)
* (txf_ms
* <type> <sampler> <coordinate> <sample_index>)
* <type> <sampler> <coordinate> <sparse> <sample_index>)
* (txs <type> <sampler> <lod>)
* (lod <type> <sampler> <coordinate>)
* (tg4 <type> <sampler> <coordinate> <offset> <component>)
* (tg4 <type> <sampler> <coordinate> <sparse> <offset> <component>)
* (query_levels <type> <sampler>)
* (samples_identical <sampler> <coordinate>)
*/
class ir_texture : public ir_rvalue {
public:
ir_texture(enum ir_texture_opcode op)
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)
shadow_comparator(NULL), offset(NULL), is_sparse(sparse)
{
memset(&lod_info, 0, sizeof(lod_info));
}
@ -1972,6 +1972,9 @@ public:
ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
} grad;
} lod_info;
/* Whether a sparse texture */
bool is_sparse;
};

View File

@ -210,7 +210,7 @@ ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const
ir_texture *
ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
{
ir_texture *new_tex = new(mem_ctx) ir_texture(this->op);
ir_texture *new_tex = new(mem_ctx) ir_texture(this->op, this->is_sparse);
new_tex->type = this->type;
new_tex->sampler = this->sampler->clone(mem_ctx, ht);

View File

@ -137,6 +137,9 @@ ir_texture::equals(const ir_instruction *ir, enum ir_node_type ignore) const
if (op != other->op)
return false;
if (is_sparse != other->is_sparse)
return false;
if (!possibly_null_equals(coordinate, other->coordinate, ignore))
return false;

View File

@ -321,6 +321,9 @@ void ir_print_visitor::visit(ir_texture *ir)
fprintf(f, " ");
if (ir->op != ir_lod && ir->op != ir_samples_identical)
fprintf(f, "%d ", ir->is_sparse);
if (ir->offset != NULL) {
ir->offset->accept(this);
} else {

View File

@ -936,6 +936,7 @@ ir_texture *
ir_reader::read_texture(s_expression *expr)
{
s_symbol *tag = NULL;
s_expression *s_sparse = NULL;
s_expression *s_type = NULL;
s_expression *s_sampler = NULL;
s_expression *s_coord = NULL;
@ -949,23 +950,23 @@ 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_offset, s_proj, s_shadow };
{ "tex", s_type, s_sampler, s_coord, s_sparse, s_offset, s_proj, s_shadow };
s_pattern lod_pattern[] =
{ "lod", s_type, s_sampler, s_coord };
s_pattern txf_pattern[] =
{ "txf", s_type, s_sampler, s_coord, s_offset, s_lod };
{ "txf", s_type, s_sampler, s_coord, s_sparse, s_offset, s_lod };
s_pattern txf_ms_pattern[] =
{ "txf_ms", s_type, s_sampler, s_coord, s_sample_index };
{ "txf_ms", s_type, s_sampler, s_coord, s_sparse, s_sample_index };
s_pattern txs_pattern[] =
{ "txs", s_type, s_sampler, s_lod };
s_pattern tg4_pattern[] =
{ "tg4", s_type, s_sampler, s_coord, s_offset, s_component };
{ "tg4", s_type, s_sampler, s_coord, s_sparse, s_offset, s_component };
s_pattern query_levels_pattern[] =
{ "query_levels", s_type, s_sampler };
s_pattern texture_samples_pattern[] =
{ "samples", s_type, s_sampler };
s_pattern other_pattern[] =
{ tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
{ tag, s_type, s_sampler, s_coord, s_sparse, s_offset, s_proj, s_shadow, s_lod };
if (MATCH(expr, lod_pattern)) {
op = ir_lod;
@ -992,7 +993,17 @@ ir_reader::read_texture(s_expression *expr)
return NULL;
}
ir_texture *tex = new(mem_ctx) ir_texture(op);
bool is_sparse = false;
if (s_sparse) {
s_int *sparse = SX_AS_INT(s_sparse);
if (sparse == NULL) {
ir_read_error(NULL, "when reading sparse");
return NULL;
}
is_sparse = sparse->value();
}
ir_texture *tex = new(mem_ctx) ir_texture(op, is_sparse);
// Read return type
const glsl_type *type = read_type(s_type);
@ -1009,6 +1020,15 @@ ir_reader::read_texture(s_expression *expr)
tex->opcode_string());
return NULL;
}
if (is_sparse) {
const glsl_type *texel = type->field_type("texel");
if (texel == glsl_type::error_type) {
ir_read_error(NULL, "invalid type for sparse texture");
return NULL;
}
type = texel;
}
tex->set_sampler(sampler, type);
if (op != ir_txs) {