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@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9069>
This commit is contained in:
Jason Ekstrand 2020-10-23 12:25:27 -05:00 committed by Marge Bot
parent 4a35d27b87
commit 9d1d55f0fd
4 changed files with 28 additions and 21 deletions

View file

@ -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 */

View file

@ -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;
}

View file

@ -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) {

View file

@ -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;