From d29f10a7ca063b63a4e29062cf3ed0151e8ebd68 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 24 Jan 2020 16:01:04 +0100 Subject: [PATCH] nir: add nir_intrinsic_interp_deref_at_vertex From the SPV_AMD_shader_explicit_vertex_parameter extension: "Returns the value of the input without any interpolation, i.e. the raw output value of previous shader stage." Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/compiler/nir/nir_divergence_analysis.c | 1 + src/compiler/nir/nir_gather_info.c | 1 + src/compiler/nir/nir_intrinsics.py | 8 +++++--- src/compiler/nir/nir_linking_helpers.c | 3 ++- src/compiler/nir/nir_lower_array_deref_of_vec.c | 1 + src/compiler/nir/nir_lower_indirect_derefs.c | 1 + src/compiler/nir/nir_lower_io.c | 5 ++++- src/compiler/nir/nir_lower_io_arrays_to_elements.c | 10 +++++++--- src/compiler/nir/nir_lower_io_to_scalar.c | 7 +++++-- src/compiler/nir/nir_lower_io_to_temporaries.c | 6 ++++-- src/compiler/nir/nir_lower_io_to_vector.c | 3 ++- src/compiler/nir/nir_lower_phis_to_scalar.c | 1 + 12 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/compiler/nir/nir_divergence_analysis.c b/src/compiler/nir/nir_divergence_analysis.c index 397015263e1..f0c8bfad7b2 100644 --- a/src/compiler/nir/nir_divergence_analysis.c +++ b/src/compiler/nir/nir_divergence_analysis.c @@ -269,6 +269,7 @@ visit_intrinsic(bool *divergent, nir_intrinsic_instr *instr, case nir_intrinsic_interp_deref_at_offset: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_centroid: + case nir_intrinsic_interp_deref_at_vertex: case nir_intrinsic_load_tess_coord: case nir_intrinsic_load_point_coord: case nir_intrinsic_load_frag_coord: diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c index 9267db95b77..0a89c4b9b44 100644 --- a/src/compiler/nir/nir_gather_info.c +++ b/src/compiler/nir/nir_gather_info.c @@ -209,6 +209,7 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader, case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: case nir_intrinsic_load_deref: case nir_intrinsic_store_deref:{ nir_deref_instr *deref = nir_src_as_deref(instr->src[0]); diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py index 9269ac99a2d..6ebc76eb88b 100644 --- a/src/compiler/nir/nir_intrinsics.py +++ b/src/compiler/nir/nir_intrinsics.py @@ -170,9 +170,9 @@ intrinsic("copy_deref", src_comp=[-1, -1], indices=[DST_ACCESS, SRC_ACCESS]) # Interpolation of input. The interp_deref_at* intrinsics are similar to the # load_var intrinsic acting on a shader input except that they interpolate the -# input differently. The at_sample and at_offset intrinsics take an -# additional source that is an integer sample id or a vec2 position offset -# respectively. +# input differently. The at_sample, at_offset and at_vertex intrinsics take an +# additional source that is an integer sample id, a vec2 position offset, or a +# vertex ID respectively. intrinsic("interp_deref_at_centroid", dest_comp=0, src_comp=[1], flags=[ CAN_ELIMINATE, CAN_REORDER]) @@ -180,6 +180,8 @@ intrinsic("interp_deref_at_sample", src_comp=[1, 1], dest_comp=0, flags=[CAN_ELIMINATE, CAN_REORDER]) intrinsic("interp_deref_at_offset", src_comp=[1, 2], dest_comp=0, flags=[CAN_ELIMINATE, CAN_REORDER]) +intrinsic("interp_deref_at_vertex", src_comp=[1, 1], dest_comp=0, + flags=[CAN_ELIMINATE, CAN_REORDER]) # Gets the length of an unsized array at the end of a buffer intrinsic("deref_buffer_array_length", src_comp=[-1], dest_comp=1, diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c index e1cf58f3514..6e49c8737c5 100644 --- a/src/compiler/nir/nir_linking_helpers.c +++ b/src/compiler/nir/nir_linking_helpers.c @@ -523,7 +523,8 @@ gather_varying_component_info(nir_shader *consumer, if (intr->intrinsic != nir_intrinsic_load_deref && intr->intrinsic != nir_intrinsic_interp_deref_at_centroid && intr->intrinsic != nir_intrinsic_interp_deref_at_sample && - intr->intrinsic != nir_intrinsic_interp_deref_at_offset) + intr->intrinsic != nir_intrinsic_interp_deref_at_offset && + intr->intrinsic != nir_intrinsic_interp_deref_at_vertex) continue; nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); diff --git a/src/compiler/nir/nir_lower_array_deref_of_vec.c b/src/compiler/nir/nir_lower_array_deref_of_vec.c index 2a70dd1ddbc..0766a1beb71 100644 --- a/src/compiler/nir/nir_lower_array_deref_of_vec.c +++ b/src/compiler/nir/nir_lower_array_deref_of_vec.c @@ -80,6 +80,7 @@ nir_lower_array_deref_of_vec_impl(nir_function_impl *impl, intrin->intrinsic != nir_intrinsic_interp_deref_at_centroid && intrin->intrinsic != nir_intrinsic_interp_deref_at_sample && intrin->intrinsic != nir_intrinsic_interp_deref_at_offset && + intrin->intrinsic != nir_intrinsic_interp_deref_at_vertex && intrin->intrinsic != nir_intrinsic_store_deref) continue; diff --git a/src/compiler/nir/nir_lower_indirect_derefs.c b/src/compiler/nir/nir_lower_indirect_derefs.c index 58365628885..9e8a844b534 100644 --- a/src/compiler/nir/nir_lower_indirect_derefs.c +++ b/src/compiler/nir/nir_lower_indirect_derefs.c @@ -126,6 +126,7 @@ lower_indirect_derefs_block(nir_block *block, nir_builder *b, intrin->intrinsic != nir_intrinsic_interp_deref_at_centroid && intrin->intrinsic != nir_intrinsic_interp_deref_at_sample && intrin->intrinsic != nir_intrinsic_interp_deref_at_offset && + intrin->intrinsic != nir_intrinsic_interp_deref_at_vertex && intrin->intrinsic != nir_intrinsic_store_deref) continue; diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 1483ef208c3..f10022936d0 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -520,7 +520,8 @@ lower_interpolate_at(nir_intrinsic_instr *intrin, struct lower_io_state *state, nir_intrinsic_set_interp_mode(bary_setup, var->data.interpolation); if (intrin->intrinsic == nir_intrinsic_interp_deref_at_sample || - intrin->intrinsic == nir_intrinsic_interp_deref_at_offset) + intrin->intrinsic == nir_intrinsic_interp_deref_at_offset || + intrin->intrinsic == nir_intrinsic_interp_deref_at_vertex) nir_src_copy(&bary_setup->src[0], &intrin->src[1], bary_setup); nir_builder_instr_insert(b, &bary_setup->instr); @@ -581,6 +582,7 @@ nir_lower_io_block(nir_block *block, case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: /* We can optionally lower these to load_interpolated_input */ if (options->use_interpolated_input_intrinsics) break; @@ -653,6 +655,7 @@ nir_lower_io_block(nir_block *block, case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: assert(vertex_index == NULL); replacement = lower_interpolate_at(intrin, state, var, offset, component_offset, deref->type); diff --git a/src/compiler/nir/nir_lower_io_arrays_to_elements.c b/src/compiler/nir/nir_lower_io_arrays_to_elements.c index 428860fef45..c4c7c5cc9c7 100644 --- a/src/compiler/nir/nir_lower_io_arrays_to_elements.c +++ b/src/compiler/nir/nir_lower_io_arrays_to_elements.c @@ -167,7 +167,8 @@ lower_array(nir_builder *b, nir_intrinsic_instr *intr, nir_variable *var, intr->num_components, intr->dest.ssa.bit_size, NULL); if (intr->intrinsic == nir_intrinsic_interp_deref_at_offset || - intr->intrinsic == nir_intrinsic_interp_deref_at_sample) { + intr->intrinsic == nir_intrinsic_interp_deref_at_sample || + intr->intrinsic == nir_intrinsic_interp_deref_at_vertex) { nir_src_copy(&element_intr->src[1], &intr->src[1], &element_intr->instr); } @@ -232,7 +233,8 @@ create_indirects_mask(nir_shader *shader, intr->intrinsic != nir_intrinsic_store_deref && intr->intrinsic != nir_intrinsic_interp_deref_at_centroid && intr->intrinsic != nir_intrinsic_interp_deref_at_sample && - intr->intrinsic != nir_intrinsic_interp_deref_at_offset) + intr->intrinsic != nir_intrinsic_interp_deref_at_offset && + intr->intrinsic != nir_intrinsic_interp_deref_at_vertex) continue; nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); @@ -277,7 +279,8 @@ lower_io_arrays_to_elements(nir_shader *shader, nir_variable_mode mask, intr->intrinsic != nir_intrinsic_store_deref && intr->intrinsic != nir_intrinsic_interp_deref_at_centroid && intr->intrinsic != nir_intrinsic_interp_deref_at_sample && - intr->intrinsic != nir_intrinsic_interp_deref_at_offset) + intr->intrinsic != nir_intrinsic_interp_deref_at_offset && + intr->intrinsic != nir_intrinsic_interp_deref_at_vertex) continue; nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); @@ -327,6 +330,7 @@ lower_io_arrays_to_elements(nir_shader *shader, nir_variable_mode mask, case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: case nir_intrinsic_load_deref: case nir_intrinsic_store_deref: if ((mask & nir_var_shader_in && mode == nir_var_shader_in) || diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c b/src/compiler/nir/nir_lower_io_to_scalar.c index 1277a8a7373..adbcf0ef975 100644 --- a/src/compiler/nir/nir_lower_io_to_scalar.c +++ b/src/compiler/nir/nir_lower_io_to_scalar.c @@ -217,7 +217,8 @@ lower_load_to_scalar_early(nir_builder *b, nir_intrinsic_instr *intr, chan_intr->src[0] = nir_src_for_ssa(&deref->dest.ssa); if (intr->intrinsic == nir_intrinsic_interp_deref_at_offset || - intr->intrinsic == nir_intrinsic_interp_deref_at_sample) + intr->intrinsic == nir_intrinsic_interp_deref_at_sample || + intr->intrinsic == nir_intrinsic_interp_deref_at_vertex) nir_src_copy(&chan_intr->src[1], &intr->src[1], &chan_intr->instr); nir_builder_instr_insert(b, &chan_intr->instr); @@ -311,7 +312,8 @@ nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask) intr->intrinsic != nir_intrinsic_store_deref && intr->intrinsic != nir_intrinsic_interp_deref_at_centroid && intr->intrinsic != nir_intrinsic_interp_deref_at_sample && - intr->intrinsic != nir_intrinsic_interp_deref_at_offset) + intr->intrinsic != nir_intrinsic_interp_deref_at_offset && + intr->intrinsic != nir_intrinsic_interp_deref_at_vertex) continue; nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); @@ -350,6 +352,7 @@ nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask) case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: case nir_intrinsic_load_deref: if ((mask & nir_var_shader_in && mode == nir_var_shader_in) || (mask & nir_var_shader_out && mode == nir_var_shader_out)) diff --git a/src/compiler/nir/nir_lower_io_to_temporaries.c b/src/compiler/nir/nir_lower_io_to_temporaries.c index f92489b9d51..1ede0238e4f 100644 --- a/src/compiler/nir/nir_lower_io_to_temporaries.c +++ b/src/compiler/nir/nir_lower_io_to_temporaries.c @@ -199,7 +199,8 @@ emit_interp(nir_builder *b, nir_deref_instr **old_interp_deref, new_interp->src[0] = nir_src_for_ssa(&new_interp_deref->dest.ssa); if (interp->intrinsic == nir_intrinsic_interp_deref_at_sample || - interp->intrinsic == nir_intrinsic_interp_deref_at_offset) { + interp->intrinsic == nir_intrinsic_interp_deref_at_offset || + interp->intrinsic == nir_intrinsic_interp_deref_at_vertex) { new_interp->src[1] = interp->src[1]; } @@ -262,7 +263,8 @@ fixup_interpolation(struct lower_io_state *state, nir_function_impl *impl, if (interp->intrinsic == nir_intrinsic_interp_deref_at_centroid || interp->intrinsic == nir_intrinsic_interp_deref_at_sample || - interp->intrinsic == nir_intrinsic_interp_deref_at_offset) { + interp->intrinsic == nir_intrinsic_interp_deref_at_offset || + interp->intrinsic == nir_intrinsic_interp_deref_at_vertex) { fixup_interpolation_instr(state, interp, b); } } diff --git a/src/compiler/nir/nir_lower_io_to_vector.c b/src/compiler/nir/nir_lower_io_to_vector.c index 82c4bdf8749..05412e2375d 100644 --- a/src/compiler/nir/nir_lower_io_to_vector.c +++ b/src/compiler/nir/nir_lower_io_to_vector.c @@ -411,7 +411,8 @@ nir_lower_io_to_vector_impl(nir_function_impl *impl, nir_variable_mode modes) case nir_intrinsic_load_deref: case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: - case nir_intrinsic_interp_deref_at_offset: { + case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: { nir_deref_instr *old_deref = nir_src_as_deref(intrin->src[0]); if (!(old_deref->mode & modes)) break; diff --git a/src/compiler/nir/nir_lower_phis_to_scalar.c b/src/compiler/nir/nir_lower_phis_to_scalar.c index bea9dc40753..45894dee352 100644 --- a/src/compiler/nir/nir_lower_phis_to_scalar.c +++ b/src/compiler/nir/nir_lower_phis_to_scalar.c @@ -100,6 +100,7 @@ is_phi_src_scalarizable(nir_phi_src *src, case nir_intrinsic_interp_deref_at_centroid: case nir_intrinsic_interp_deref_at_sample: case nir_intrinsic_interp_deref_at_offset: + case nir_intrinsic_interp_deref_at_vertex: case nir_intrinsic_load_uniform: case nir_intrinsic_load_ubo: case nir_intrinsic_load_ssbo: -- 2.30.2