+static nir_ssa_def *
+load_layer_id(const nir_input_attachment_options *options, nir_builder *b)
+{
+ if (options->use_layer_id_sysval)
+ return nir_load_layer_id(b);
+
+ nir_variable *layer_id =
+ nir_find_variable_with_location(b->shader, nir_var_shader_in,
+ VARYING_SLOT_LAYER);
+
+ if (layer_id == NULL) {
+ layer_id = nir_variable_create(b->shader, nir_var_shader_in,
+ glsl_int_type(), NULL);
+ layer_id->data.location = VARYING_SLOT_LAYER;
+ layer_id->data.interpolation = INTERP_MODE_FLAT;
+ layer_id->data.driver_location = b->shader->num_inputs++;
+ }
+
+ return nir_load_var(b, layer_id);
+}
+