From 8a95b438806b8f1521de6934287da667c47aa695 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 26 Oct 2020 14:35:55 +1000 Subject: [PATCH] spirv/nir: parse function control and store in nir. This just lets the nir access the inline/dont inline attributes Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir.c | 2 ++ src/compiler/nir/nir.h | 3 +++ src/compiler/nir/nir_clone.c | 2 ++ src/compiler/nir/nir_print.c | 5 +++-- src/compiler/nir/nir_serialize.c | 6 ++++++ src/compiler/spirv/vtn_cfg.c | 3 +++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index c52906b5210..9748f9e1d14 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -485,6 +485,8 @@ nir_function_create(nir_shader *shader, const char *name) func->impl = NULL; func->is_entrypoint = false; func->is_preamble = false; + func->dont_inline = false; + func->should_inline = false; return func; } diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 566173d50b2..98095961e6e 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3322,6 +3322,9 @@ typedef struct nir_function { bool is_entrypoint; bool is_preamble; + /* from SPIR-V function control */ + bool should_inline; + bool dont_inline; /* from SPIR-V */ } nir_function; typedef enum { diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index 0e8ea70be50..02571203c54 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -665,6 +665,8 @@ nir_function_clone(nir_shader *ns, const nir_function *fxn) } nfxn->is_entrypoint = fxn->is_entrypoint; nfxn->is_preamble = fxn->is_preamble; + nfxn->should_inline = fxn->should_inline; + nfxn->dont_inline = fxn->dont_inline; /* At first glance, it looks like we should clone the function_impl here. * However, call instructions need to be able to reference at least the diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 5b779344889..48fa1577f69 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -2148,8 +2148,9 @@ print_function(nir_function *function, print_state *state) { FILE *fp = state->fp; - fprintf(fp, "decl_function %s (%d params)", function->name, - function->num_params); + fprintf(fp, "decl_function %s (%d params) %s", function->name, + function->num_params, function->dont_inline ? "(noinline)" : + function->should_inline ? "(inline)" : ""); fprintf(fp, "\n"); diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c index 831920d5a81..5d783ec3c55 100644 --- a/src/compiler/nir/nir_serialize.c +++ b/src/compiler/nir/nir_serialize.c @@ -1887,6 +1887,10 @@ write_function(write_ctx *ctx, const nir_function *fxn) flags |= 0x4; if (fxn->impl) flags |= 0x8; + if (fxn->should_inline) + flags |= 0x10; + if (fxn->dont_inline) + flags |= 0x20; blob_write_uint32(ctx->blob, flags); if (fxn->name) blob_write_string(ctx->blob, fxn->name); @@ -1931,6 +1935,8 @@ read_function(read_ctx *ctx) fxn->is_preamble = flags & 0x2; if (flags & 0x8) fxn->impl = NIR_SERIALIZE_FUNC_HAS_IMPL; + fxn->should_inline = flags & 0x10; + fxn->dont_inline = flags & 0x20; } static void diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c index 072065fe870..6882e9fb67d 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -201,6 +201,9 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode, if (func_type->return_type->base_type != vtn_base_type_void) num_params++; + func->should_inline = b->func->control & SpvFunctionControlInlineMask; + func->dont_inline = b->func->control & SpvFunctionControlDontInlineMask; + func->num_params = num_params; func->params = ralloc_array(b->shader, nir_parameter, num_params);