Am 17.05.2017 um 11:17 schrieb Samuel Pitoiset:
> RadeonSI needs to do a special lowering for Gather4 with integer
> formats, but with bindless samplers we just can't access the index.
> 
> Instead, store the return type in the instruction like the target.
> 
> Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>
> ---
>  src/gallium/auxiliary/tgsi/tgsi_ureg.c     |  7 +++++--
>  src/gallium/auxiliary/tgsi/tgsi_ureg.h     | 11 ++++++++---
>  src/gallium/include/pipe/p_shader_tokens.h |  2 ++
>  src/mesa/state_tracker/st_atifs_to_tgsi.c  |  2 +-
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 17 ++---------------
>  src/mesa/state_tracker/st_mesa_to_tgsi.c   | 21 +++++++++++++++++++++
>  src/mesa/state_tracker/st_mesa_to_tgsi.h   |  4 ++++
>  7 files changed, 43 insertions(+), 21 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c 
> b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> index 9eb00d0919..1cdb95cc95 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> @@ -1289,7 +1289,7 @@ ureg_fixup_label(struct ureg_program *ureg,
>  void
>  ureg_emit_texture(struct ureg_program *ureg,
>                    unsigned extended_token,
> -                  unsigned target, unsigned num_offsets)
> +                  unsigned target, unsigned return_type, unsigned 
> num_offsets)
>  {
>     union tgsi_any_token *out, *insn;
>  
> @@ -1300,6 +1300,7 @@ ureg_emit_texture(struct ureg_program *ureg,
>  
>     out[0].value = 0;
>     out[0].insn_texture.Texture = target;
> +   out[0].insn_texture.ReturnType = return_type;
>     out[0].insn_texture.NumOffsets = num_offsets;
>  }
>  
> @@ -1386,6 +1387,7 @@ ureg_tex_insn(struct ureg_program *ureg,
>                const struct ureg_dst *dst,
>                unsigned nr_dst,
>                unsigned target,
> +              unsigned return_type,
>                const struct tgsi_texture_offset *texoffsets,
>                unsigned nr_offset,
>                const struct ureg_src *src,
> @@ -1407,7 +1409,8 @@ ureg_tex_insn(struct ureg_program *ureg,
>                           nr_dst,
>                           nr_src);
>  
> -   ureg_emit_texture( ureg, insn.extended_token, target, nr_offset );
> +   ureg_emit_texture( ureg, insn.extended_token, target, return_type,
> +                      nr_offset );
>  
>     for (i = 0; i < nr_offset; i++)
>        ureg_emit_texture_offset( ureg, &texoffsets[i]);
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h 
> b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
> index 6d2f5c0e99..54f95ba565 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
> @@ -555,6 +555,7 @@ ureg_tex_insn(struct ureg_program *ureg,
>                const struct ureg_dst *dst,
>                unsigned nr_dst,
>                unsigned target,
> +              unsigned return_type,
>                const struct tgsi_texture_offset *texoffsets,
>                unsigned nr_offset,
>                const struct ureg_src *src,
> @@ -596,7 +597,7 @@ ureg_emit_label(struct ureg_program *ureg,
>  void
>  ureg_emit_texture(struct ureg_program *ureg,
>                    unsigned insn_token,
> -                  unsigned target, unsigned num_offsets);
> +                  unsigned target, unsigned return_type, unsigned 
> num_offsets);
>  
>  void
>  ureg_emit_texture_offset(struct ureg_program *ureg,
> @@ -748,6 +749,7 @@ static inline void ureg_##op( struct ureg_program *ureg,  
>               \
>                                struct ureg_src src1 )                    \
>  {                                                                       \
>     unsigned opcode = TGSI_OPCODE_##op;                                  \
> +   unsigned return_type = TGSI_RETURN_TYPE_UNKNOWN;                     \
>     struct ureg_emit_insn_result insn;                                   \
>     if (ureg_dst_is_empty(dst))                                          \
>        return;                                                           \
> @@ -756,7 +758,8 @@ static inline void ureg_##op( struct ureg_program *ureg,  
>               \
>                           dst.Saturate,                                  \
>                           1,                                             \
>                           2);                                            \
> -   ureg_emit_texture( ureg, insn.extended_token, target, 0 );                
> \
> +   ureg_emit_texture( ureg, insn.extended_token, target,                \
> +                      return_type, 0 );                                 \
>     ureg_emit_dst( ureg, dst );                                          \
>     ureg_emit_src( ureg, src0 );                                         \
>     ureg_emit_src( ureg, src1 );                                         \
> @@ -796,6 +799,7 @@ static inline void ureg_##op( struct ureg_program *ureg,  
>               \
>                                struct ureg_src src3 )                    \
>  {                                                                       \
>     unsigned opcode = TGSI_OPCODE_##op;                                  \
> +   unsigned return_type = TGSI_RETURN_TYPE_UNKNOWN;                     \
>     struct ureg_emit_insn_result insn;                                   \
>     if (ureg_dst_is_empty(dst))                                          \
>        return;                                                           \
> @@ -804,7 +808,8 @@ static inline void ureg_##op( struct ureg_program *ureg,  
>               \
>                           dst.Saturate,                                  \
>                           1,                                             \
>                           4);                                            \
> -   ureg_emit_texture( ureg, insn.extended_token, target, 0 );                
> \
> +   ureg_emit_texture( ureg, insn.extended_token, target,                \
> +                      return_type, 0 );                                 \
>     ureg_emit_dst( ureg, dst );                                          \
>     ureg_emit_src( ureg, src0 );                                         \
>     ureg_emit_src( ureg, src1 );                                         \
> diff --git a/src/gallium/include/pipe/p_shader_tokens.h 
> b/src/gallium/include/pipe/p_shader_tokens.h
> index a671121f10..dfc477a73c 100644
> --- a/src/gallium/include/pipe/p_shader_tokens.h
> +++ b/src/gallium/include/pipe/p_shader_tokens.h
> @@ -233,6 +233,7 @@ enum tgsi_return_type {
>     TGSI_RETURN_TYPE_SINT,
>     TGSI_RETURN_TYPE_UINT,
>     TGSI_RETURN_TYPE_FLOAT,
> +   TGSI_RETURN_TYPE_UNKNOWN,
>     TGSI_RETURN_TYPE_COUNT
>  };
>  
> @@ -695,6 +696,7 @@ struct tgsi_instruction_texture
>     unsigned Texture  : 8;    /* TGSI_TEXTURE_ */
>     unsigned NumOffsets : 4;
>     unsigned Padding : 20;
> +   unsigned ReturnType : 3; /* TGSI_RETURN_TYPE_x */
>  };
Aside from the padding bug, I can't say I like the idea much. The issue
here is that with the SAMPLE opcodes, it is impossible to fill in. So,
basically, with TEX instructions, you should take that information from
here, whereas with SAMPLE, it will come from the resource dcl. This is
quite inconsistent.
However, I suppose it's workable, so I won't stop you (the texture
target is also similarly unused with sample opcodes already). I suppose
potentially sample opcodes could possibly not use
tgsi_instruction_texture at all but something else (it's only needed for
the offset stuff).

Roland


>  
>  /* for texture offsets in GLSL and DirectX.
> diff --git a/src/mesa/state_tracker/st_atifs_to_tgsi.c 
> b/src/mesa/state_tracker/st_atifs_to_tgsi.c
> index 8b9c332feb..ff20511d95 100644
> --- a/src/mesa/state_tracker/st_atifs_to_tgsi.c
> +++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
> @@ -334,7 +334,7 @@ compile_setupinst(struct st_translate *t,
>        src[1] = t->samplers[r];
>        /* the texture target is still unknown, it will be fixed in the draw 
> call */
>        ureg_tex_insn(t->ureg, TGSI_OPCODE_TEX, dst, 1, TGSI_TEXTURE_2D,
> -                    NULL, 0, src, 2);
> +                    TGSI_RETURN_TYPE_UNKNOWN, NULL, 0, src, 2);
>     } else if (texinst->Opcode == ATI_FRAGMENT_SHADER_PASS_OP) {
>        ureg_insn(t->ureg, TGSI_OPCODE_MOV, dst, 1, src, 1);
>     }
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
> b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 54bc70f57b..9620ef760f 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -5877,6 +5877,7 @@ compile_tgsi_instruction(struct st_translate *t,
>                      inst->op,
>                      dst, num_dst,
>                      tex_target,
> +                    st_translate_texture_type(inst->tex_type),
>                      texoffsets, inst->tex_offset_num_offset,
>                      src, num_src);
>        return;
> @@ -6570,24 +6571,10 @@ st_translate_program(
>     /* texture samplers */
>     for (i = 0; i < frag_const->MaxTextureImageUnits; i++) {
>        if (program->samplers_used & (1u << i)) {
> -         unsigned type;
> +         unsigned type = 
> st_translate_texture_type(program->sampler_types[i]);
>  
>           t->samplers[i] = ureg_DECL_sampler(ureg, i);
>  
> -         switch (program->sampler_types[i]) {
> -         case GLSL_TYPE_INT:
> -            type = TGSI_RETURN_TYPE_SINT;
> -            break;
> -         case GLSL_TYPE_UINT:
> -            type = TGSI_RETURN_TYPE_UINT;
> -            break;
> -         case GLSL_TYPE_FLOAT:
> -            type = TGSI_RETURN_TYPE_FLOAT;
> -            break;
> -         default:
> -            unreachable("not reached");
> -         }
> -
>           ureg_DECL_sampler_view( ureg, i, program->sampler_targets[i],
>                                   type, type, type, type );
>        }
> diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c 
> b/src/mesa/state_tracker/st_mesa_to_tgsi.c
> index b3721d8703..17cc5f4ea6 100644
> --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
> +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
> @@ -223,6 +223,26 @@ st_translate_texture_target(GLuint textarget, GLboolean 
> shadow)
>  
>  
>  /**
> + * Map GLSL base type to TGSI return type.
> + */
> +unsigned
> +st_translate_texture_type(enum glsl_base_type type)
> +{
> +     switch (type) {
> +     case GLSL_TYPE_INT:
> +             return TGSI_RETURN_TYPE_SINT;
> +     case GLSL_TYPE_UINT:
> +             return TGSI_RETURN_TYPE_UINT;
> +     case GLSL_TYPE_FLOAT:
> +             return TGSI_RETURN_TYPE_FLOAT;
> +     default:
> +             debug_assert(!"unexpected texture type");
> +             return TGSI_RETURN_TYPE_UNKNOWN;
> +     }
> +}
> +
> +
> +/**
>   * Translate a (1 << TEXTURE_x_INDEX) bit into a TGSI_TEXTURE_x enum.
>   */
>  static unsigned
> @@ -536,6 +556,7 @@ compile_instruction(
>                       dst, num_dst, 
>                       st_translate_texture_target( inst->TexSrcTarget,
>                                                 inst->TexShadow ),
> +                     TGSI_RETURN_TYPE_UNKNOWN,
>                       NULL, 0,
>                       src, num_src );
>        return;
> diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.h 
> b/src/mesa/state_tracker/st_mesa_to_tgsi.h
> index b4d9af635a..106cf85a3e 100644
> --- a/src/mesa/state_tracker/st_mesa_to_tgsi.h
> +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.h
> @@ -34,6 +34,8 @@
>  #include "pipe/p_compiler.h"
>  #include "pipe/p_defines.h"
>  
> +#include "compiler/glsl_types.h"
> +
>  #if defined __cplusplus
>  extern "C" {
>  #endif
> @@ -63,6 +65,8 @@ st_translate_mesa_program(
>  unsigned
>  st_translate_texture_target(GLuint textarget, GLboolean shadow);
>  
> +unsigned
> +st_translate_texture_type(enum glsl_base_type type);
>  
>  #if defined __cplusplus
>  } /* extern "C" */
> 

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to