[Mesa-dev] [PATCH] nir: add support for 4 constant offsets in tg4

Eric Anholt eric at anholt.net
Fri Mar 30 19:35:37 UTC 2018


Karol Herbst <kherbst at redhat.com> writes:

> Nvidia hardware can do that natively so there is no need to lower that to four
> TG4s instructions.
>
> Signed-off-by: Karol Herbst <kherbst at redhat.com>
> ---
>  src/compiler/glsl/glsl_to_nir.cpp | 25 ++++++++++++++++++-------
>  src/compiler/nir/nir.h            |  9 ++++++++-
>  src/compiler/nir/nir_print.c      |  9 +++++++++
>  3 files changed, 35 insertions(+), 8 deletions(-)
>
> diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
> index c4a6d52a5b2..4ea5f1616a7 100644
> --- a/src/compiler/glsl/glsl_to_nir.cpp
> +++ b/src/compiler/glsl/glsl_to_nir.cpp
> @@ -2042,7 +2042,9 @@ nir_visitor::visit(ir_texture *ir)
>        num_srcs++;
>     if (ir->shadow_comparator != NULL)
>        num_srcs++;
> -   if (ir->offset != NULL)
> +   if (ir->offset != NULL && ir->offset->type->is_array())
> +      num_srcs += ir->offset->type->array_size();
> +   else if (ir->offset != NULL)
>        num_srcs++;
>  
>     nir_tex_instr *instr = nir_tex_instr_create(this->shader, num_srcs);
> @@ -2097,12 +2099,21 @@ nir_visitor::visit(ir_texture *ir)
>  
>     if (ir->offset != NULL) {
>        /* we don't support multiple offsets yet */
> -      assert(ir->offset->type->is_vector() || ir->offset->type->is_scalar());
> -
> -      instr->src[src_number].src =
> -         nir_src_for_ssa(evaluate_rvalue(ir->offset));
> -      instr->src[src_number].src_type = nir_tex_src_offset;
> -      src_number++;
> +      if (ir->offset->type->is_vector() || ir->offset->type->is_scalar()) {
> +         instr->src[src_number].src =
> +            nir_src_for_ssa(evaluate_rvalue(ir->offset));
> +         instr->src[src_number].src_type = nir_tex_src_offset;
> +         src_number++;
> +      } else if (ir->offset->type->is_array()) {
> +         for (int i = 0; i < ir->offset->type->array_size(); i++) {
> +            instr->src[src_number].src =
> +               nir_src_for_ssa(evaluate_rvalue(ir->offset->as_constant()->get_array_element(i)->as_rvalue()));
> +            instr->src[src_number].src_type = (nir_tex_src_type)(nir_tex_src_offset + i);
> +            src_number++;
> +         }
> +      } else {
> +         assert(false);

Maybe just do assert(ir->offset->type->is_array()) in the previous block
instead of the extra else.  And optionally pull
ir->offset->as_constant() out to a temporary for nicer column wrapping.
Other than that, this seems good.

Reviewed-by: Eric Anholt <eric at anholt.net>

If I'm reading my specs right, I'll be able to use this on vc6, too.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180330/c305ded4/attachment.sig>


More information about the mesa-dev mailing list