[Mesa-dev] [PATCH 5/9] i965: Implement NIR intrinsics for loading VS system values.

Jason Ekstrand jason at jlekstrand.net
Wed Mar 11 15:33:24 PDT 2015


I'm not terribly happy with how this worked out, I'm not going to NAK it as
I think it's the best we can do at the moment.

The reason why Connor (and others) have chosen to emit these things at the
top of the shader is because they frequently require some computation and
we don't want to duplicate that if we don't have to.  However, it also
leads to variables with very long live ranges which we don't want either.
Once we have GVN, we can value-number system value intrinsics.  This will
ensure that we only do the (potentially expensive) caluculation once and
GCM will ensure that they land as far down the program as we can put them.
However, until we have GVN, this seems like as good as we're going to get
at the moment.
--Jason

On Mon, Mar 9, 2015 at 1:58 AM, Kenneth Graunke <kenneth at whitecape.org>
wrote:

> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
>  src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 51
> ++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> index c5ed55c..d700523 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> @@ -363,6 +363,30 @@ emit_system_values_block(nir_block *block, void
> *void_visitor)
>
>        nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
>        switch (intrin->intrinsic) {
> +      case nir_intrinsic_load_vertex_id:
> +         unreachable("should be lowered by lower_vertex_id().");
> +
> +      case nir_intrinsic_load_vertex_id_zero_base:
> +         assert(v->stage == MESA_SHADER_VERTEX);
> +         reg = &v->nir_system_values[SYSTEM_VALUE_VERTEX_ID_ZERO_BASE];
> +         if (reg->file == BAD_FILE)
> +            *reg =
> *v->emit_vs_system_value(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE);
> +         break;
> +
> +      case nir_intrinsic_load_base_vertex:
> +         assert(v->stage == MESA_SHADER_VERTEX);
> +         reg = &v->nir_system_values[SYSTEM_VALUE_BASE_VERTEX];
> +         if (reg->file == BAD_FILE)
> +            *reg = *v->emit_vs_system_value(SYSTEM_VALUE_BASE_VERTEX);
> +         break;
> +
> +      case nir_intrinsic_load_instance_id:
> +         assert(v->stage == MESA_SHADER_VERTEX);
> +         reg = &v->nir_system_values[SYSTEM_VALUE_INSTANCE_ID];
> +         if (reg->file == BAD_FILE)
> +            *reg = *v->emit_vs_system_value(SYSTEM_VALUE_INSTANCE_ID);
> +         break;
> +
>        case nir_intrinsic_load_sample_pos:
>           assert(v->stage == MESA_SHADER_FRAGMENT);
>           reg = &v->nir_system_values[SYSTEM_VALUE_SAMPLE_POS];
> @@ -1344,6 +1368,33 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr
> *instr)
>                 *emit_frontfacing_interpolation()));
>        break;
>
> +   case nir_intrinsic_load_vertex_id:
> +      unreachable("should be lowered by lower_vertex_id()");
> +
> +   case nir_intrinsic_load_vertex_id_zero_base: {
> +      fs_reg vertex_id =
> nir_system_values[SYSTEM_VALUE_VERTEX_ID_ZERO_BASE];
> +      assert(vertex_id.file != BAD_FILE);
> +      dest.type = vertex_id.type;
> +      emit(MOV(dest, vertex_id));
> +      break;
> +   }
> +
> +   case nir_intrinsic_load_base_vertex: {
> +      fs_reg base_vertex = nir_system_values[SYSTEM_VALUE_BASE_VERTEX];
> +      assert(base_vertex.file != BAD_FILE);
> +      dest.type = base_vertex.type;
> +      emit(MOV(dest, base_vertex));
> +      break;
> +   }
> +
> +   case nir_intrinsic_load_instance_id: {
> +      fs_reg instance_id = nir_system_values[SYSTEM_VALUE_INSTANCE_ID];
> +      assert(instance_id.file != BAD_FILE);
> +      dest.type = instance_id.type;
> +      emit(MOV(dest, instance_id));
> +      break;
> +   }
> +
>     case nir_intrinsic_load_sample_mask_in: {
>        fs_reg sample_mask_in =
> nir_system_values[SYSTEM_VALUE_SAMPLE_MASK_IN];
>        assert(sample_mask_in.file != BAD_FILE);
> --
> 2.2.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150311/ce0e7873/attachment-0001.html>


More information about the mesa-dev mailing list