[virglrenderer-devel] [PATCHv3] shader: improve TXQ translation

Dave Airlie airlied at gmail.com
Mon Feb 29 00:02:50 UTC 2016


On 29 February 2016 at 09:42,  <marcandre.lureau at redhat.com> wrote:
> From: Marc-André Lureau <marcandre.lureau at redhat.com>
>
> TXQ may query levels and size.
>
> Fixes all piglit texturesize tests and others.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
> ---
>  src/vrend_shader.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 46 insertions(+), 6 deletions(-)
>
> diff --git a/src/vrend_shader.c b/src/vrend_shader.c
> index 885b384..835618d 100644
> --- a/src/vrend_shader.c
> +++ b/src/vrend_shader.c
> @@ -25,6 +25,7 @@
>  #include "tgsi/tgsi_info.h"
>  #include "tgsi/tgsi_iterate.h"
>  #include "util/u_memory.h"
> +#include "util/u_math.h"
>  #include <string.h>
>  #include <stdio.h>
>  #include <math.h>
> @@ -966,7 +967,7 @@ static int translate_tex(struct dump_ctx *ctx,
>                           const char *dstconv,
>                           const char *dtypeprefix)
>  {
> -   const char *twm, *gwm = NULL, *txfi;
> +   const char *twm = "", *gwm = NULL, *txfi;
>     bool is_shad = false;
>     char buf[512];
>     char offbuf[128] = {0};
> @@ -1033,13 +1034,52 @@ static int translate_tex(struct dump_ctx *ctx,
>
>        /* need to emit a textureQueryLevels */
>        if (inst->Dst[0].Register.WriteMask & 0x8) {
> -         ctx->uses_txq_levels = true;
> -         snprintf(buf, 255, "%s = %s(%s(textureQueryLevels(%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index]);
> -         return emit_buf(ctx, buf);
> -      } else {
> -         snprintf(buf, 255, "%s = %s(%s(textureSize(%s%s)));\n", dsts[0], dstconv, dtypeprefix, srcs[sampler_index], bias);
> +
> +         if (inst->Texture.Texture != TGSI_TEXTURE_BUFFER &&
> +             inst->Texture.Texture != TGSI_TEXTURE_RECT &&
> +             inst->Texture.Texture != TGSI_TEXTURE_2D_MSAA &&
> +             inst->Texture.Texture != TGSI_TEXTURE_2D_ARRAY_MSAA) {
> +            ctx->uses_txq_levels = true;
> +            if (inst->Dst[0].Register.WriteMask & 0x7)
> +               twm = ".w";
> +            snprintf(buf, 255, "%s%s = %s(textureQueryLevels(%s));\n", dsts[0], twm, dtypeprefix, srcs[sampler_index]);
> +            emit_buf(ctx, buf);
> +         }
> +

All the code below with & 0x7 could be pulled out a level,
and the two if & 0x7 levels collapsed into one section.

also we should be using the EMIT_BUF_WITH_RET macro in both places.

> +         if (inst->Dst[0].Register.WriteMask & 0x7) {
> +            switch (inst->Texture.Texture) {
> +            case TGSI_TEXTURE_1D:
> +            case TGSI_TEXTURE_BUFFER:
> +            case TGSI_TEXTURE_SHADOW1D:
> +               twm = ".x";
> +               break;
> +            case TGSI_TEXTURE_1D_ARRAY:
> +            case TGSI_TEXTURE_SHADOW1D_ARRAY:
> +            case TGSI_TEXTURE_2D:
> +            case TGSI_TEXTURE_SHADOW2D:
> +            case TGSI_TEXTURE_RECT:
> +            case TGSI_TEXTURE_SHADOWRECT:
> +            case TGSI_TEXTURE_CUBE:
> +            case TGSI_TEXTURE_SHADOWCUBE:
> +               twm = ".xy";
> +               break;
> +            case TGSI_TEXTURE_3D:
> +            case TGSI_TEXTURE_2D_ARRAY:
> +            case TGSI_TEXTURE_SHADOW2D_ARRAY:
> +            case TGSI_TEXTURE_SHADOWCUBE_ARRAY:
> +            case TGSI_TEXTURE_CUBE_ARRAY:
> +               twm = ".xyz";
> +               break;
> +            }
> +         }
> +      }
> +
> +      if (inst->Dst[0].Register.WriteMask & 0x7) {
> +         snprintf(buf, 255, "%s%s = %s(textureSize(%s%s))%s;\n", dsts[0], twm, dtypeprefix, srcs[sampler_index], bias, util_bitcount(inst->Dst[0].Register.WriteMask) > 1 ? writemask : "");
>           return emit_buf(ctx, buf);
>        }
> +

However even with that I get bad code generated, because we have a
writemask in dsts[0] already and twm then provides another one.
0:17(1): error: cannot access field `x' of non-structure / non-vector
0:17(1): error: type mismatch
0:17(1): error: value of type float cannot be assigned to variable of type error

temp0[0].yzw = vec3(((vec4(0,0,0,1)).yzw));
temp0[1].x.x = intBitsToFloat(textureSize(fssamp0, int((fsconst0[0].xxxx).w)));

for all the 1D and buffer sampling tests.

Dave.


More information about the virglrenderer-devel mailing list