nir: generate lowered IO in nir_lower_passthrough_edgeflags
authorMarek Olšák <marek.olsak@amd.com>
Thu, 13 Aug 2020 14:27:57 +0000 (10:27 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 24 Aug 2020 19:07:18 +0000 (19:07 +0000)
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6442>

src/compiler/nir/nir_lower_passthrough_edgeflags.c

index 0afcaa0b1256b88ed2d4fdfa2682c2d5fb24852d..eb142ce600ce4968c2827b3416d5fab710d5541d 100644 (file)
@@ -35,12 +35,57 @@ lower_impl(nir_function_impl *impl)
    nir_builder_init(&b, impl);
    b.cursor = nir_before_cf_list(&impl->body);
 
+   /* The edge flag is the last input in st/mesa. */
+   assert(shader->num_inputs == util_bitcount64(shader->info.inputs_read));
+   assert(shader->num_outputs == util_bitcount64(shader->info.outputs_written));
+
+   /* Lowered IO only uses intrinsics. It doesn't use variables. */
+   if (shader->info.io_lowered) {
+      /* Load an edge flag. */
+      nir_intrinsic_instr *load =
+         nir_intrinsic_instr_create(shader, nir_intrinsic_load_input);
+      load->num_components = 1;
+      load->src[0] = nir_src_for_ssa(nir_imm_int(&b, 0));
+      nir_ssa_dest_init(&load->instr, &load->dest,
+                        load->num_components, 32, NULL);
+
+      nir_intrinsic_set_base(load, shader->num_inputs++);
+      nir_intrinsic_set_component(load, 0);
+      nir_intrinsic_set_type(load, nir_type_float32);
+
+      nir_io_semantics load_sem = {0};
+      load_sem.location = VERT_ATTRIB_EDGEFLAG;
+      load_sem.num_slots = 1;
+      nir_intrinsic_set_io_semantics(load, load_sem);
+      nir_builder_instr_insert(&b, &load->instr);
+
+      /* Store an edge flag. */
+      nir_intrinsic_instr *store =
+         nir_intrinsic_instr_create(shader, nir_intrinsic_store_output);
+      store->num_components = 1;
+      store->src[0] = nir_src_for_ssa(&load->dest.ssa);
+      store->src[1] = nir_src_for_ssa(nir_imm_int(&b, 0));
+
+      nir_intrinsic_set_base(store, shader->num_outputs++);
+      nir_intrinsic_set_component(store, 0);
+      nir_intrinsic_set_type(store, nir_type_float32);
+      nir_intrinsic_set_write_mask(store, 0x1);
+
+      nir_io_semantics semantics = {0};
+      semantics.location = VARYING_SLOT_EDGE;
+      semantics.num_slots = 1;
+      nir_intrinsic_set_io_semantics(store, semantics);
+      nir_builder_instr_insert(&b, &store->instr);
+
+      nir_metadata_preserve(impl, nir_metadata_block_index |
+                                  nir_metadata_dominance);
+      return;
+   }
+
    in  = nir_variable_create(shader, nir_var_shader_in,
                              glsl_vec4_type(), "edgeflag_in");
    in->data.location = VERT_ATTRIB_EDGEFLAG;
 
-   /* The edge flag is the last input in st/mesa. */
-   assert(shader->num_inputs == util_bitcount64(shader->info.inputs_read));
    in->data.driver_location = shader->num_inputs++;
    shader->info.inputs_read |= BITFIELD64_BIT(VERT_ATTRIB_EDGEFLAG);