exec_node_remove(®->node);
}
-void
-nir_shader_add_variable(nir_shader *shader, nir_variable *var)
+struct exec_list *
+nir_variable_list_for_mode(nir_shader *shader, nir_variable_mode mode)
{
- switch (var->data.mode) {
- case nir_num_variable_modes:
- case nir_var_all:
- assert(!"invalid mode");
- break;
-
+ switch (mode) {
case nir_var_function_temp:
assert(!"nir_shader_add_variable cannot be used for local variables");
- break;
+ return NULL;
case nir_var_shader_temp:
- exec_list_push_tail(&shader->globals, &var->node);
- break;
+ return &shader->globals;
case nir_var_shader_in:
- exec_list_push_tail(&shader->inputs, &var->node);
- break;
+ return &shader->inputs;
case nir_var_shader_out:
- exec_list_push_tail(&shader->outputs, &var->node);
- break;
+ return &shader->outputs;
case nir_var_uniform:
case nir_var_mem_ubo:
case nir_var_mem_ssbo:
- exec_list_push_tail(&shader->uniforms, &var->node);
- break;
+ return &shader->uniforms;
case nir_var_mem_shared:
assert(gl_shader_stage_is_compute(shader->info.stage));
- exec_list_push_tail(&shader->shared, &var->node);
- break;
+ return &shader->shared;
case nir_var_mem_global:
assert(!"nir_shader_add_variable cannot be used for global memory");
- break;
+ return NULL;
case nir_var_system_value:
- exec_list_push_tail(&shader->system_values, &var->node);
- break;
+ return &shader->system_values;
case nir_var_mem_push_const:
assert(!"nir_var_push_constant is not supposed to be used for variables");
- break;
+ return NULL;
+
+ default:
+ assert(!"invalid mode");
+ return NULL;
}
}
+void
+nir_shader_add_variable(nir_shader *shader, nir_variable *var)
+{
+ struct exec_list *var_list =
+ nir_variable_list_for_mode(shader, var->data.mode);
+ if (var_list)
+ exec_list_push_tail(var_list, &var->node);
+}
+
nir_variable *
nir_variable_create(nir_shader *shader, nir_variable_mode mode,
const struct glsl_type *type, const char *name)
struct nir_variable_data *members;
} nir_variable;
+
+static inline bool
+_nir_shader_variable_has_mode(nir_variable *var, unsigned modes)
+{
+ /* This isn't a shader variable */
+ assert(!(modes & nir_var_function_temp));
+ return var->data.mode & modes;
+}
+
#define nir_foreach_variable(var, var_list) \
foreach_list_typed(nir_variable, var, node, var_list)
#define nir_foreach_variable_safe(var, var_list) \
foreach_list_typed_safe(nir_variable, var, node, var_list)
+#define nir_foreach_variable_with_modes(var, shader, modes) \
+ nir_foreach_variable(var, nir_variable_list_for_mode(shader, modes)) \
+ if (_nir_shader_variable_has_mode(var, modes))
+
+#define nir_foreach_variable_with_modes_safe(var, shader, modes) \
+ nir_foreach_variable_safe(var, nir_variable_list_for_mode(shader, modes)) \
+ if (_nir_shader_variable_has_mode(var, modes))
+
#define nir_foreach_shader_in_variable(var, shader) \
nir_foreach_variable(var, &(shader)->inputs)
void nir_reg_remove(nir_register *reg);
+struct exec_list *
+nir_variable_list_for_mode(nir_shader *shader, nir_variable_mode mode);
+
/** Adds a variable to the appropriate list in nir_shader */
void nir_shader_add_variable(nir_shader *shader, nir_variable *var);