summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2019-01-13 10:39:41 -0800
committerKenneth Graunke <[email protected]>2019-02-11 21:34:45 -0800
commitf5c7df4dc95ca115b1a1c916b0b133692a7ea6d9 (patch)
tree7eb9abcca491dafa9e08ee7293969d52ede42e17 /src/compiler/glsl
parent120f9b8362284e6e8ad62aa85a9e2578db73f272 (diff)
nir: Gather texture bitmasks in gl_nir_lower_samplers_as_deref.
Eric and I would like a bitmask of which samplers are used, similar to prog->SamplersUsed, but available in NIR. The linker uses SamplersUsed for resource limit checking, but later optimizations may eliminate more samplers. So instead of propagating it through, we gather a new one. While there, we also gather the existing textures_used_by_txf bitmask. Gathering these bitfields in nir_shader_gather_info is awkward at best. The main reason is that it introduces an ordering dependency between the two passes. If gathering runs before lower_samplers_as_deref, it can't look at var->data.binding. If the driver doesn't use the full lowering to texture_index/texture_array_size (like radeonsi), then the gathering can't use those fields. Gathering might be run early /and/ late, first to get varying info, and later to update it after variant lowering. At this point, should gathering work on pre-lowered or post-lowered code? Pre-lowered is also harder due to the presence of structure types. Just doing the gathering when we do the lowering alleviates these ordering problems. This fixes ordering issues in i965 and makes the txf info gathering work for radeonsi (though they don't use it). Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/compiler/glsl')
-rw-r--r--src/compiler/glsl/gl_nir_lower_samplers_as_deref.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
index c8f17ef9aaa..ea32195d42f 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
@@ -197,6 +197,26 @@ lower_deref(nir_builder *b, struct lower_samplers_as_deref_state *state,
return new_deref;
}
+static void
+record_textures_used(struct shader_info *info,
+ nir_deref_instr *deref,
+ nir_texop op)
+{
+ nir_variable *var = nir_deref_instr_get_variable(deref);
+
+ /* Structs have been lowered already, so get_aoa_size is sufficient. */
+ const unsigned size =
+ glsl_type_is_array(var->type) ? glsl_get_aoa_size(var->type) : 1;
+ unsigned mask = ((1ull << MAX2(size, 1)) - 1) << var->data.binding;
+
+ info->textures_used |= mask;
+
+ if (op == nir_texop_txf ||
+ op == nir_texop_txf_ms ||
+ op == nir_texop_txf_ms_mcs)
+ info->textures_used_by_txf |= mask;
+}
+
static bool
lower_sampler(nir_tex_instr *instr, struct lower_samplers_as_deref_state *state,
nir_builder *b)
@@ -217,6 +237,7 @@ lower_sampler(nir_tex_instr *instr, struct lower_samplers_as_deref_state *state,
if (texture_deref) {
nir_instr_rewrite_src(&instr->instr, &instr->src[texture_idx].src,
nir_src_for_ssa(&texture_deref->dest.ssa));
+ record_textures_used(&b->shader->info, texture_deref, instr->op);
}
}
@@ -297,6 +318,9 @@ gl_nir_lower_samplers_as_deref(nir_shader *shader,
state.remap_table = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
_mesa_key_string_equal);
+ shader->info.textures_used = 0;
+ shader->info.textures_used_by_txf = 0;
+
nir_foreach_function(function, shader) {
if (function->impl)
progress |= lower_impl(function->impl, &state);