return;
nir_function *func = nir_function_create(shader, ir->function_name());
+ if (strcmp(ir->function_name(), "main") == 0)
+ func->is_entrypoint = true;
func->num_params = ir->parameters.length() +
(ir->return_type != glsl_type::void_type);
func->num_params = 0;
func->params = NULL;
func->impl = NULL;
+ func->is_entrypoint = false;
return func;
}
* If the function is only declared and not implemented, this is NULL.
*/
nir_function_impl *impl;
+
+ bool is_entrypoint;
} nir_function;
typedef struct nir_shader_compiler_options {
unsigned constant_data_size;
} nir_shader;
+#define nir_foreach_function(func, shader) \
+ foreach_list_typed(nir_function, func, node, &(shader)->functions)
+
static inline nir_function_impl *
nir_shader_get_entrypoint(nir_shader *shader)
{
- assert(exec_list_length(&shader->functions) == 1);
- struct exec_node *func_node = exec_list_get_head(&shader->functions);
- nir_function *func = exec_node_data(nir_function, func_node, node);
+ nir_function *func = NULL;
+
+ nir_foreach_function(function, shader) {
+ assert(func == NULL);
+ if (function->is_entrypoint) {
+ func = function;
+#ifndef NDEBUG
+ break;
+#endif
+ }
+ }
+
+ if (!func)
+ return NULL;
+
assert(func->num_params == 0);
assert(func->impl);
return func->impl;
}
-#define nir_foreach_function(func, shader) \
- foreach_list_typed(nir_function, func, node, &(shader)->functions)
-
nir_shader *nir_shader_create(void *mem_ctx,
gl_shader_stage stage,
const nir_shader_compiler_options *options,
{
build->shader = nir_shader_create(mem_ctx, stage, options, NULL);
nir_function *func = nir_function_create(build->shader, "main");
+ func->is_entrypoint = true;
build->exact = false;
build->impl = nir_function_impl_create(func);
build->cursor = nir_after_cf_list(&build->impl->body);
nfxn->num_params = fxn->num_params;
nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
+ nfxn->is_entrypoint = fxn->is_entrypoint;
/* 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
blob_write_uint32(ctx->blob, val);
}
+ blob_write_uint32(ctx->blob, fxn->is_entrypoint);
+
/* At first glance, it looks like we should write the function_impl here.
* However, call instructions need to be able to reference at least the
* function and those will get processed as we write the function_impls.
fxn->params[i].num_components = val & 0xff;
fxn->params[i].bit_size = (val >> 8) & 0xff;
}
+
+ fxn->is_entrypoint = blob_read_uint32(ctx->blob);
}
void
ralloc_free(b);
+ entry_point->is_entrypoint = true;
return entry_point;
}