From 9385d94bc919de4d26aaae21dad88bb062643e9c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 20 Oct 2025 13:10:59 +1000 Subject: [PATCH] nir: add a flag for functions that are used in cmat calls. With coopmat2 a bunch of functions need a lot of lowering passes to happen before they can be lowered, so mark them as to be lowered later. Drivers needing these should call the nir_remove_non_cmat_call_entrypoints where they remove entrypoints now, and call the original nir_remove_non_entrypoints after lowering coopmat2. Reviewed-by: Georg Lehmann Part-of: --- src/compiler/nir/nir.c | 10 ++++++++++ src/compiler/nir/nir.h | 3 +++ src/compiler/nir/nir_clone.c | 1 + src/compiler/nir/nir_serialize.c | 3 +++ 4 files changed, 17 insertions(+) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index c949b515584..13a8067284e 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -626,6 +626,7 @@ nir_function_create(nir_shader *shader, const char *name) func->params = NULL; func->impl = NULL; func->is_entrypoint = false; + func->cmat_call = false; func->is_preamble = false; func->dont_inline = false; func->should_inline = false; @@ -3767,6 +3768,15 @@ nir_remove_non_entrypoints(nir_shader *nir) assert(exec_list_length(&nir->functions) == 1); } +void +nir_remove_non_cmat_call_entrypoints(nir_shader *nir) +{ + nir_foreach_function_safe(func, nir) { + if (!func->is_entrypoint && !func->cmat_call) + exec_node_remove(&func->node); + } +} + void nir_remove_non_exported(nir_shader *nir) { diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 0e77de695cc..0226b9b259f 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3811,6 +3811,8 @@ typedef struct nir_function { uint32_t driver_attributes; bool is_entrypoint; + /* called by a cmat call */ + bool cmat_call; /* from SPIR-V linkage, only for libraries */ bool is_exported; bool is_preamble; @@ -4013,6 +4015,7 @@ nir_shader_get_function_for_name(const nir_shader *shader, const char *name) * functions from a shader and library respectively. */ void nir_remove_non_entrypoints(nir_shader *shader); +void nir_remove_non_cmat_call_entrypoints(nir_shader *nir); void nir_remove_non_exported(nir_shader *shader); void nir_remove_entrypoints(nir_shader *shader); void nir_fixup_is_exported(nir_shader *shader); diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index 7a2d396b87d..aa9159fe73f 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -758,6 +758,7 @@ nir_function_clone(nir_shader *ns, const nir_function *fxn) } } nfxn->is_entrypoint = fxn->is_entrypoint; + nfxn->cmat_call = fxn->cmat_call; nfxn->is_preamble = fxn->is_preamble; nfxn->should_inline = fxn->should_inline; nfxn->dont_inline = fxn->dont_inline; diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c index ef60df3effc..74ab945eb2e 100644 --- a/src/compiler/nir/nir_serialize.c +++ b/src/compiler/nir/nir_serialize.c @@ -2026,6 +2026,8 @@ write_function(write_ctx *ctx, const nir_function *fxn) flags |= 0x80; if (fxn->workgroup_size[0] || fxn->workgroup_size[1] || fxn->workgroup_size[2]) flags |= 0x100; + if (fxn->cmat_call) + flags |= 0x200; blob_write_uint32(ctx->blob, flags); if (fxn->name && !ctx->strip) blob_write_string(ctx->blob, fxn->name); @@ -2128,6 +2130,7 @@ read_function(read_ctx *ctx) fxn->dont_inline = flags & 0x20; fxn->is_subroutine = flags & 0x40; fxn->is_tmp_globals_wrapper = flags & 0x80; + fxn->cmat_call = flags & 0x200; return fxn; }