void
-link_invalidate_variable_locations(exec_list *ir, int input_base,
- int output_base)
+link_invalidate_variable_locations(exec_list *ir)
{
foreach_list(node, ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if (var == NULL)
continue;
- int base;
- switch (var->mode) {
- case ir_var_shader_in:
- base = input_base;
- break;
- case ir_var_shader_out:
- base = output_base;
- break;
- default:
- continue;
- }
-
- /* Only assign locations for generic attributes / varyings / etc.
+ /* Only assign locations for variables that lack an explicit location.
+ * Explicit locations are set for all built-in variables, generic vertex
+ * shader inputs (via layout(location=...)), and generic fragment shader
+ * outputs (also via layout(location=...)).
*/
- if ((var->location >= base) && !var->explicit_location)
+ if (!var->explicit_location) {
var->location = -1;
+ var->location_frac = 0;
+ }
- if ((var->location == -1) && !var->explicit_location) {
+ /* ir_variable::is_unmatched_generic_inout is used by the linker while
+ * connecting outputs from one stage to inputs of the next stage.
+ *
+ * There are two implicit assumptions here. First, we assume that any
+ * built-in variable (i.e., non-generic in or out) will have
+ * explicit_location set. Second, we assume that any generic in or out
+ * will not have explicit_location set.
+ *
+ * This second assumption will only be valid until
+ * GL_ARB_separate_shader_objects is supported. When that extension is
+ * implemented, this function will need some modifications.
+ */
+ if (!var->explicit_location) {
var->is_unmatched_generic_inout = 1;
- var->location_frac = 0;
} else {
var->is_unmatched_generic_inout = 0;
}
/* Mark all generic shader inputs and outputs as unpaired. */
if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) {
link_invalidate_variable_locations(
- prog->_LinkedShaders[MESA_SHADER_VERTEX]->ir,
- VERT_ATTRIB_GENERIC0, VARYING_SLOT_VAR0);
+ prog->_LinkedShaders[MESA_SHADER_VERTEX]->ir);
}
if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) {
link_invalidate_variable_locations(
- prog->_LinkedShaders[MESA_SHADER_GEOMETRY]->ir,
- VARYING_SLOT_VAR0, VARYING_SLOT_VAR0);
+ prog->_LinkedShaders[MESA_SHADER_GEOMETRY]->ir);
}
if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] != NULL) {
link_invalidate_variable_locations(
- prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir,
- VARYING_SLOT_VAR0, FRAG_RESULT_DATA0);
+ prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir);
}
/* FINISHME: The value of the max_attribute_index parameter is
ir.push_tail(var);
- link_invalidate_variable_locations(&ir,
- VERT_ATTRIB_GENERIC0,
- VARYING_SLOT_VAR0);
+ link_invalidate_variable_locations(&ir);
EXPECT_EQ(-1, var->location);
EXPECT_EQ(0u, var->location_frac);
ir.push_tail(var);
- link_invalidate_variable_locations(&ir,
- VERT_ATTRIB_GENERIC0,
- VARYING_SLOT_VAR0);
+ link_invalidate_variable_locations(&ir);
EXPECT_EQ(VERT_ATTRIB_GENERIC0, var->location);
EXPECT_EQ(0u, var->location_frac);
ir.push_tail(var);
- link_invalidate_variable_locations(&ir,
- VERT_ATTRIB_GENERIC0,
- VARYING_SLOT_VAR0);
+ link_invalidate_variable_locations(&ir);
EXPECT_EQ(VERT_ATTRIB_GENERIC0, var->location);
EXPECT_EQ(2u, var->location_frac);
ir.push_tail(var);
- link_invalidate_variable_locations(&ir,
- VERT_ATTRIB_GENERIC0,
- VARYING_SLOT_VAR0);
+ link_invalidate_variable_locations(&ir);
EXPECT_EQ(VERT_ATTRIB_POS, var->location);
EXPECT_EQ(0u, var->location_frac);
ir.push_tail(var);
- link_invalidate_variable_locations(&ir,
- VERT_ATTRIB_GENERIC0,
- VARYING_SLOT_VAR0);
+ link_invalidate_variable_locations(&ir);
EXPECT_EQ(-1, var->location);
EXPECT_EQ(0u, var->location_frac);
ir.push_tail(var);
- link_invalidate_variable_locations(&ir,
- VERT_ATTRIB_GENERIC0,
- VARYING_SLOT_VAR0);
+ link_invalidate_variable_locations(&ir);
EXPECT_EQ(VARYING_SLOT_COL0, var->location);
EXPECT_EQ(0u, var->location_frac);