Mesa (master): spirv: Store the nir_function in vtn_function
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Feb 16 21:05:23 UTC 2021
Module: Mesa
Branch: master
Commit: 9d1d55f0fdacaf589e7a7598d8f6902ec4cabde0
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9d1d55f0fdacaf589e7a7598d8f6902ec4cabde0
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Fri Oct 23 12:25:27 2020 -0500
spirv: Store the nir_function in vtn_function
This is a better mapping as not all nir_functions have impls.
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9069>
---
src/compiler/spirv/spirv_to_nir.c | 4 ++--
src/compiler/spirv/vtn_cfg.c | 40 ++++++++++++++++++++++-----------------
src/compiler/spirv/vtn_opencl.c | 3 ++-
src/compiler/spirv/vtn_private.h | 2 +-
4 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 84f572e03a6..a765fd5cbf1 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -5766,7 +5766,7 @@ static nir_function *
vtn_emit_kernel_entry_point_wrapper(struct vtn_builder *b,
nir_function *entry_point)
{
- vtn_assert(entry_point == b->entry_point->func->impl->function);
+ vtn_assert(entry_point == b->entry_point->func->nir_func);
vtn_fail_if(!entry_point->name, "entry points are required to have a name");
const char *func_name =
ralloc_asprintf(b->shader, "__wrapped_%s", entry_point->name);
@@ -5959,7 +5959,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
if (!options->create_library) {
vtn_assert(b->entry_point->value_type == vtn_value_type_function);
- nir_function *entry_point = b->entry_point->func->impl->function;
+ nir_function *entry_point = b->entry_point->func->nir_func;
vtn_assert(entry_point);
/* post process entry_points with input params */
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 6c024954244..0e3454ab44a 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -114,11 +114,11 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
{
struct vtn_function *vtn_callee =
vtn_value(b, w[3], vtn_value_type_function)->func;
- struct nir_function *callee = vtn_callee->impl->function;
vtn_callee->referenced = true;
- nir_call_instr *call = nir_call_instr_create(b->nb.shader, callee);
+ nir_call_instr *call = nir_call_instr_create(b->nb.shader,
+ vtn_callee->nir_func);
unsigned param_idx = 0;
@@ -200,9 +200,14 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
glsl_type_add_to_function_params(func_type->params[i]->type, func, &idx);
assert(idx == num_params);
- b->func->impl = nir_function_impl_create(func);
- nir_builder_init(&b->nb, func->impl);
- b->nb.cursor = nir_before_cf_list(&b->func->impl->body);
+ b->func->nir_func = func;
+
+ /* Set up a nir_function_impl and the builder so we can load arguments
+ * directly in our OpFunctionParameter handler.
+ */
+ nir_function_impl *impl = nir_function_impl_create(func);
+ nir_builder_init(&b->nb, impl);
+ b->nb.cursor = nir_before_cf_list(&impl->body);
b->nb.exact = b->exact;
b->func_param_idx = 0;
@@ -219,7 +224,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
break;
case SpvOpFunctionParameter: {
- vtn_assert(b->func_param_idx < b->func->impl->function->num_params);
+ vtn_assert(b->func_param_idx < b->func->nir_func->num_params);
struct vtn_type *type = vtn_get_type(b, w[1]);
struct vtn_ssa_value *value = vtn_create_ssa_value(b, type->type);
vtn_ssa_value_load_function_param(b, value, &b->func_param_idx);
@@ -1226,8 +1231,8 @@ static struct nir_block *
vtn_new_unstructured_block(struct vtn_builder *b, struct vtn_function *func)
{
struct nir_block *n = nir_block_create(b->shader);
- exec_list_push_tail(&func->impl->body, &n->cf_node.node);
- n->cf_node.parent = &func->impl->cf_node;
+ exec_list_push_tail(&func->nir_func->impl->body, &n->cf_node.node);
+ n->cf_node.parent = &func->nir_func->impl->cf_node;
return n;
}
@@ -1250,7 +1255,7 @@ vtn_emit_cf_func_unstructured(struct vtn_builder *b, struct vtn_function *func,
struct list_head work_list;
list_inithead(&work_list);
- func->start_block->block = nir_start_block(func->impl);
+ func->start_block->block = nir_start_block(func->nir_func->impl);
list_addtail(&func->start_block->node.link, &work_list);
while (!list_is_empty(&work_list)) {
struct vtn_block *block =
@@ -1333,7 +1338,7 @@ vtn_emit_cf_func_unstructured(struct vtn_builder *b, struct vtn_function *func,
case SpvOpKill: {
nir_discard(&b->nb);
- nir_goto(&b->nb, b->func->impl->end_block);
+ nir_goto(&b->nb, b->func->nir_func->impl->end_block);
break;
}
@@ -1341,7 +1346,7 @@ vtn_emit_cf_func_unstructured(struct vtn_builder *b, struct vtn_function *func,
case SpvOpReturn:
case SpvOpReturnValue: {
vtn_emit_ret_store(b, block);
- nir_goto(&b->nb, b->func->impl->end_block);
+ nir_goto(&b->nb, b->func->nir_func->impl->end_block);
break;
}
@@ -1361,15 +1366,16 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
env_var_as_boolean("MESA_SPIRV_FORCE_UNSTRUCTURED", false);
}
- nir_builder_init(&b->nb, func->impl);
+ nir_function_impl *impl = func->nir_func->impl;
+ nir_builder_init(&b->nb, impl);
b->func = func;
- b->nb.cursor = nir_after_cf_list(&func->impl->body);
+ b->nb.cursor = nir_after_cf_list(&impl->body);
b->nb.exact = b->exact;
b->has_loop_continue = false;
b->phi_table = _mesa_pointer_hash_table_create(b);
if (b->shader->info.stage == MESA_SHADER_KERNEL || force_unstructured) {
- b->func->impl->structured = false;
+ impl->structured = false;
vtn_emit_cf_func_unstructured(b, func, instruction_handler);
} else {
vtn_emit_cf_list_structured(b, &func->body, NULL, NULL,
@@ -1379,15 +1385,15 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
vtn_foreach_instruction(b, func->start_block->label, func->end,
vtn_handle_phi_second_pass);
- nir_rematerialize_derefs_in_use_blocks_impl(func->impl);
+ nir_rematerialize_derefs_in_use_blocks_impl(impl);
/* Continue blocks for loops get inserted before the body of the loop
* but instructions in the continue may use SSA defs in the loop body.
* Therefore, we need to repair SSA to insert the needed phi nodes.
*/
- if (b->func->impl->structured &&
+ if (func->nir_func->impl->structured &&
(b->has_loop_continue || b->has_early_terminate))
- nir_repair_ssa_impl(func->impl);
+ nir_repair_ssa_impl(impl);
func->emitted = true;
}
diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c
index 338b9c23f07..2b01e744e27 100644
--- a/src/compiler/spirv/vtn_opencl.c
+++ b/src/compiler/spirv/vtn_opencl.c
@@ -811,7 +811,8 @@ handle_printf(struct vtn_builder *b, uint32_t opcode,
glsl_struct_type(fields, num_srcs - 1, "printf", true);
/* Step 3, create a variable of that type and populate its fields */
- nir_variable *var = nir_local_variable_create(b->func->impl, struct_type, NULL);
+ nir_variable *var = nir_local_variable_create(b->func->nir_func->impl,
+ struct_type, NULL);
nir_deref_instr *deref_var = nir_build_deref_var(&b->nb, var);
size_t fmt_pos = 0;
for (unsigned i = 1; i < num_srcs; ++i) {
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 28f6a80e1ab..df16b8a335d 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -268,7 +268,7 @@ struct vtn_function {
bool referenced;
bool emitted;
- nir_function_impl *impl;
+ nir_function *nir_func;
struct vtn_block *start_block;
struct list_head body;
More information about the mesa-commit
mailing list