zink: only allocate ntv residency info if it will be used
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 14 Jan 2022 14:51:47 +0000 (09:51 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 20 Jan 2022 15:51:30 +0000 (15:51 +0000)
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>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
src/gallium/drivers/zink/zink_compiler.c
src/gallium/drivers/zink/zink_compiler.h

index 82da393..8e84948 100644 (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);
index b9e27bc..f582c5c 100644 (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 |
index 62a831e..1303646 100644 (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;
 };