zink: only allocate ntv residency info if it will be used

odds are it will never be used, so don't bother allocating

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14381>
This commit is contained in:
Mike Blumenkrantz 2022-01-14 09:51:47 -05:00 committed by Marge Bot
parent 7e7c94afaa
commit d76694a18f
3 changed files with 19 additions and 6 deletions

View file

@ -3901,10 +3901,15 @@ nir_to_spirv(struct nir_shader *s, const struct zink_shader_info *sinfo, uint32_
sizeof(SpvId), entry->ssa_alloc);
if (!ctx.defs)
goto fail;
ctx.resident_defs = ralloc_array_size(ctx.mem_ctx,
sizeof(SpvId), entry->ssa_alloc);
if (!ctx.resident_defs)
goto fail;
if (sinfo->have_sparse) {
/* this could be huge, so only alloc if needed since it's extremely unlikely to
* ever be used by anything except cts
*/
ctx.resident_defs = ralloc_array_size(ctx.mem_ctx,
sizeof(SpvId), entry->ssa_alloc);
if (!ctx.resident_defs)
goto fail;
}
ctx.num_defs = entry->ssa_alloc;
nir_index_local_regs(entry);

View file

@ -1712,13 +1712,17 @@ lower_1d_shadow(nir_shader *shader)
}
static void
scan_nir(nir_shader *shader)
scan_nir(nir_shader *shader, struct zink_shader *zs)
{
nir_foreach_function(function, shader) {
if (!function->impl)
continue;
nir_foreach_block_safe(block, function->impl) {
nir_foreach_instr_safe(instr, block) {
if (instr->type == nir_instr_type_tex) {
nir_tex_instr *tex = nir_instr_as_tex(instr);
zs->sinfo.have_sparse |= tex->is_sparse;
}
if (instr->type != nir_instr_type_intrinsic)
continue;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
@ -1751,6 +1755,9 @@ scan_nir(nir_shader *shader)
shader->info.images_used |= mask;
}
if (intr->intrinsic == nir_intrinsic_is_sparse_texels_resident ||
intr->intrinsic == nir_intrinsic_image_deref_sparse_load)
zs->sinfo.have_sparse = true;
}
}
}
@ -1865,7 +1872,7 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
if (has_bindless_io)
NIR_PASS_V(nir, lower_bindless_io);
scan_nir(nir);
scan_nir(nir, ret);
foreach_list_typed_reverse_safe(nir_variable, var, node, &nir->variables) {
if (_nir_shader_variable_has_mode(var, nir_var_uniform |

View file

@ -56,6 +56,7 @@ struct zink_shader_info {
unsigned so_info_slots[PIPE_MAX_SO_OUTPUTS];
bool last_vertex;
bool have_xfb;
bool have_sparse;
};