nir: Add a find_variable_with_[driver_]location helper
[mesa.git] / src / compiler / nir / nir_lower_input_attachments.c
index 72dd7afc33a15cdefdbaa7a051b7efbf7edeff82..20fa801b45d4abe169a1210be73fc30f1c4ec18f 100644 (file)
 static nir_ssa_def *
 load_frag_coord(nir_builder *b)
 {
-   nir_foreach_variable(var, &b->shader->inputs) {
-      if (var->data.location == VARYING_SLOT_POS)
-         return nir_load_var(b, var);
+   nir_variable *pos =
+      nir_find_variable_with_location(b->shader, nir_var_shader_in,
+                                      VARYING_SLOT_POS);
+   if (pos == NULL) {
+      pos = nir_variable_create(b->shader, nir_var_shader_in,
+                                glsl_vec4_type(), NULL);
+      pos->data.location = VARYING_SLOT_POS;
    }
-
-   nir_variable *pos = nir_variable_create(b->shader, nir_var_shader_in,
-                                           glsl_vec4_type(), NULL);
-   pos->data.location = VARYING_SLOT_POS;
    /**
     * From Vulkan spec:
     *   "The OriginLowerLeft execution mode must not be used; fragment entry
@@ -131,7 +131,6 @@ try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
                                                         bool use_fragcoord_sysval)
 {
    nir_deref_instr *deref = nir_src_as_deref(tex->src[0].src);
-   assert(glsl_type_is_image(deref->type));
 
    if (glsl_get_sampler_dim(deref->type) != GLSL_SAMPLER_DIM_SUBPASS_MS)
       return false;