diff options
Diffstat (limited to 'src/compiler/nir/nir.c')
-rw-r--r-- | src/compiler/nir/nir.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 7ed93e1f409..1352d4cd3b4 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -324,6 +324,78 @@ nir_local_variable_create(nir_function_impl *impl, } nir_variable * +nir_create_variable_with_location(nir_shader *shader, nir_variable_mode mode, int location, + const struct glsl_type *type) +{ + /* Only supporting non-array, or arrayed-io types, because otherwise we don't + * know how much to increment num_inputs/outputs + */ + assert(glsl_get_length(type) <= 1); + + const char *name; + switch (mode) { + case nir_var_shader_in: + if (shader->info.stage == MESA_SHADER_VERTEX) + name = gl_vert_attrib_name(location); + else + name = gl_varying_slot_name_for_stage(location, shader->info.stage); + break; + + case nir_var_shader_out: + if (shader->info.stage == MESA_SHADER_FRAGMENT) + name = gl_frag_result_name(location); + else + name = gl_varying_slot_name_for_stage(location, shader->info.stage); + break; + + case nir_var_system_value: + name = gl_system_value_name(location); + break; + + default: + unreachable("Unsupported variable mode"); + } + + nir_variable *var = nir_variable_create(shader, mode, type, name); + var->data.location = location; + + switch (mode) { + case nir_var_shader_in: + var->data.driver_location = shader->num_inputs++; + break; + + case nir_var_shader_out: + var->data.driver_location = shader->num_outputs++; + break; + + case nir_var_system_value: + break; + + default: + unreachable("Unsupported variable mode"); + } + + return var; +} + +nir_variable * +nir_get_variable_with_location(nir_shader *shader, nir_variable_mode mode, int location, + const struct glsl_type *type) +{ + nir_variable *var = nir_find_variable_with_location(shader, mode, location); + if (var) { + /* If this shader has location_fracs, this builder function is not suitable. */ + assert(var->data.location_frac == 0); + + /* The variable for the slot should match what we expected. */ + assert(type == var->type); + return var; + } + + return nir_create_variable_with_location(shader, mode, location, type); +} + +nir_variable * nir_find_variable_with_location(nir_shader *shader, nir_variable_mode mode, unsigned location) |