nir/lower_input_attachments: Refactor to use an options struct
[mesa.git] / src / compiler / nir / nir_lower_input_attachments.c
index 20fa801b45d4abe169a1210be73fc30f1c4ec18f..2e6e56806ee6bf82e078a597c88b0315987ed275 100644 (file)
 #include "nir_builder.h"
 
 static nir_ssa_def *
-load_frag_coord(nir_builder *b)
+load_frag_coord(const nir_input_attachment_options *options, nir_builder *b)
 {
+   if (options->use_fragcoord_sysval)
+      return nir_load_frag_coord(b);
+
    nir_variable *pos =
       nir_find_variable_with_location(b->shader, nir_var_shader_in,
                                       VARYING_SLOT_POS);
@@ -49,7 +52,7 @@ load_frag_coord(nir_builder *b)
 
 static bool
 try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
-                     bool use_fragcoord_sysval)
+                     const nir_input_attachment_options *options)
 {
    nir_deref_instr *deref = nir_src_as_deref(load->src[0]);
    assert(glsl_type_is_image(deref->type));
@@ -65,8 +68,7 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
    nir_builder_init(&b, impl);
    b.cursor = nir_instr_remove(&load->instr);
 
-   nir_ssa_def *frag_coord = use_fragcoord_sysval ? nir_load_frag_coord(&b)
-                                                  : load_frag_coord(&b);
+   nir_ssa_def *frag_coord = load_frag_coord(options, &b);
    frag_coord = nir_f2i32(&b, frag_coord);
    nir_ssa_def *offset = nir_ssa_for_src(&b, load->src[1], 2);
    nir_ssa_def *pos = nir_iadd(&b, frag_coord, offset);
@@ -128,7 +130,7 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
 
 static bool
 try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
-                                                        bool use_fragcoord_sysval)
+                      const nir_input_attachment_options *options)
 {
    nir_deref_instr *deref = nir_src_as_deref(tex->src[0].src);
 
@@ -139,8 +141,7 @@ try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
    nir_builder_init(&b, impl);
    b.cursor = nir_before_instr(&tex->instr);
 
-   nir_ssa_def *frag_coord = use_fragcoord_sysval ? nir_load_frag_coord(&b)
-                                                  : load_frag_coord(&b);
+   nir_ssa_def *frag_coord = load_frag_coord(options, &b);
    frag_coord = nir_f2i32(&b, frag_coord);
 
    nir_ssa_def *layer = nir_load_layer_id(&b);
@@ -155,7 +156,8 @@ try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
 }
 
 bool
-nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
+nir_lower_input_attachments(nir_shader *shader,
+                            const nir_input_attachment_options *options)
 {
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
    bool progress = false;
@@ -173,7 +175,7 @@ nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
                if (tex->op == nir_texop_fragment_mask_fetch ||
                    tex->op == nir_texop_fragment_fetch) {
                   progress |= try_lower_input_texop(function->impl, tex,
-                                                    use_fragcoord_sysval);
+                                                    options);
                }
                break;
             }
@@ -182,7 +184,7 @@ nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
 
                if (load->intrinsic == nir_intrinsic_image_deref_load) {
                   progress |= try_lower_input_load(function->impl, load,
-                                                   use_fragcoord_sysval);
+                                                   options);
                }
                break;
             }