[PATCH 1/5] d3dcompiler: Store the swizzle unshifted.

Matteo Bruni matteo.mystral at gmail.com
Tue Feb 11 11:37:31 CST 2020


On Wed, Feb 5, 2020 at 9:53 PM Zebediah Figura <z.figura12 at gmail.com> wrote:
>
> From: Zebediah Figura <zfigura at codeweavers.com>
>
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
>  dlls/d3dcompiler_43/asmshader.y           |  4 +--
>  dlls/d3dcompiler_43/bytecodewriter.c      |  6 +---
>  dlls/d3dcompiler_43/d3dcompiler_private.h | 38 +++++++++++------------
>  dlls/d3dcompiler_43/utils.c               |  8 ++---
>  4 files changed, 26 insertions(+), 30 deletions(-)
>
> diff --git a/dlls/d3dcompiler_43/asmshader.y b/dlls/d3dcompiler_43/asmshader.y
> index 32b37d0885d..1b7a07313fc 100644
> --- a/dlls/d3dcompiler_43/asmshader.y
> +++ b/dlls/d3dcompiler_43/asmshader.y
> @@ -1148,11 +1148,11 @@ swizzle:              /* empty */
>                              else {
>                                  DWORD last, i;
>
> -                                $$ = $2.swizzle << BWRITERVS_SWIZZLE_SHIFT;
> +                                $$ = $2.swizzle;
>                                  /* Fill the swizzle by extending the last component */
>                                  last = ($2.swizzle >> 2 * ($2.idx - 1)) & 0x03;
>                                  for(i = $2.idx; i < 4; i++){
> -                                    $$ |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i);
> +                                    $$ |= last << (2 * i);
>                                  }
>                                  TRACE("Got a swizzle: %08x\n", $$);
>                              }
> diff --git a/dlls/d3dcompiler_43/bytecodewriter.c b/dlls/d3dcompiler_43/bytecodewriter.c
> index 14162ab212b..42013dfba3f 100644
> --- a/dlls/d3dcompiler_43/bytecodewriter.c
> +++ b/dlls/d3dcompiler_43/bytecodewriter.c
> @@ -342,8 +342,6 @@ static void put_dword(struct bytecode_buffer *buffer, DWORD value) {
>  /* bwriter -> d3d9 conversion functions. */
>  static DWORD d3d9_swizzle(DWORD bwriter_swizzle)
>  {
> -    /* Currently a NOP, but this allows changing the internal definitions
> -     * without side effects. */
>      DWORD ret = 0;
>
>      if ((bwriter_swizzle & BWRITERVS_X_X) == BWRITERVS_X_X) ret |= D3DVS_X_X;
> @@ -1270,9 +1268,7 @@ static void instr_ps_1_0123_texld(struct bc_writer *This,
>          This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod);
>      } else if(instr->src[0].type == BWRITERSPR_TEMP) {
>
> -        swizzlemask = (3 << BWRITERVS_SWIZZLE_SHIFT) |
> -            (3 << (BWRITERVS_SWIZZLE_SHIFT + 2)) |
> -            (3 << (BWRITERVS_SWIZZLE_SHIFT + 4));
> +        swizzlemask = 3 | (3 << 2) | (3 << 4);
>          if((instr->src[0].u.swizzle & swizzlemask) == (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z)) {
>              TRACE("writing texreg2rgb\n");
>              This->funcs->opcode(This, instr, D3DSIO_TEXREG2RGB & D3DSI_OPCODE_MASK, buffer);
> diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
> index 45dbff7225b..5fc3161f5f0 100644
> --- a/dlls/d3dcompiler_43/d3dcompiler_private.h
> +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
> @@ -542,25 +542,25 @@ enum bwritershader_param_srcmod_type
>  #define BWRITERVS_SWIZZLE_SHIFT      16
>  #define BWRITERVS_SWIZZLE_MASK       (0xFF << BWRITERVS_SWIZZLE_SHIFT)
>
> -#define BWRITERVS_X_X       (0 << BWRITERVS_SWIZZLE_SHIFT)
> -#define BWRITERVS_X_Y       (1 << BWRITERVS_SWIZZLE_SHIFT)
> -#define BWRITERVS_X_Z       (2 << BWRITERVS_SWIZZLE_SHIFT)
> -#define BWRITERVS_X_W       (3 << BWRITERVS_SWIZZLE_SHIFT)
> -
> -#define BWRITERVS_Y_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
> -#define BWRITERVS_Y_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
> -#define BWRITERVS_Y_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
> -#define BWRITERVS_Y_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
> -
> -#define BWRITERVS_Z_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
> -#define BWRITERVS_Z_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
> -#define BWRITERVS_Z_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
> -#define BWRITERVS_Z_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
> -
> -#define BWRITERVS_W_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
> -#define BWRITERVS_W_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
> -#define BWRITERVS_W_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
> -#define BWRITERVS_W_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
> +#define BWRITERVS_X_X       (0)
> +#define BWRITERVS_X_Y       (1)
> +#define BWRITERVS_X_Z       (2)
> +#define BWRITERVS_X_W       (3)
> +
> +#define BWRITERVS_Y_X       (0 << 2)
> +#define BWRITERVS_Y_Y       (1 << 2)
> +#define BWRITERVS_Y_Z       (2 << 2)
> +#define BWRITERVS_Y_W       (3 << 2)
> +
> +#define BWRITERVS_Z_X       (0 << 4)
> +#define BWRITERVS_Z_Y       (1 << 4)
> +#define BWRITERVS_Z_Z       (2 << 4)
> +#define BWRITERVS_Z_W       (3 << 4)
> +
> +#define BWRITERVS_W_X       (0 << 6)
> +#define BWRITERVS_W_Y       (1 << 6)
> +#define BWRITERVS_W_Z       (2 << 6)
> +#define BWRITERVS_W_W       (3 << 6)
>
>  #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
>
> diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c
> index 1436ed6bf3e..b2b1e25bbdc 100644
> --- a/dlls/d3dcompiler_43/utils.c
> +++ b/dlls/d3dcompiler_43/utils.c
> @@ -291,10 +291,10 @@ static const char *debug_print_swizzle(DWORD arg)
>              return ".w";
>      }
>
> -    swizzle[0] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 0)) & 0x03;
> -    swizzle[1] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 2)) & 0x03;
> -    swizzle[2] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 4)) & 0x03;
> -    swizzle[3] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 6)) & 0x03;
> +    swizzle[0] = arg & 3;
> +    swizzle[1] = (arg >> 2) & 3;
> +    swizzle[2] = (arg >> 4) & 3;
> +    swizzle[3] = (arg >> 6) & 3;
>
>      ret[0] = '.';
>      for (i = 0; i < 4; ++i)
> --
> 2.25.0

Now BWRITERVS_SWIZZLE_SHIFT and BWRITERVS_SWIZZLE_MASK are unused. Are
you going to need them in the future or can they just be dropped?



More information about the wine-devel mailing list