Kenneth Graunke <kenn...@whitecape.org> writes:

> Consider the following code sequence:
>
>    mul(8)          g4<1>F          g1<0,4,1>.wzwwF g3<4,4,1>.wzwwF
>    mov.sat(8)      m1<1>.xyF       g4<4,4,1>F
>    mul(8)          g4<1>F          g1<0,4,1>.xxyxF g3<4,4,1>.xxyxF
>    mov.sat(8)      m1<1>.zwF       g4<4,4,1>F
>
> The compute-to-MRF pass will discover the first mov.sat and attempt to
> replace it by rewriting earlier instructions.  Everything works out,
> so it replaces scan_inst's destination file, reg, and reg_offset,
> resulting in:
>
>    mul(8)          m1<1>F          g1<0,4,1>.wzwwF g3<4,4,1>.wzwwF
>    mul(8)          g4<1>F          g1<0,4,1>.xxyxF g3<4,4,1>.xxyxF
>    mov.sat(8)      m1<1>.zwF       g4<4,4,1>F
>
> Unfortunately, it loses the .xy writemask on the mov.sat's MRF
> destination.  While this doesn't pose an immediate problem, it then
> proceeds to transform the second mov.sat, resulting in:
>
>    mul(8)          m1<1>F          g1<0,4,1>.wzwwF g3<4,4,1>.wzwwF
>    mul(8)          m1<1>F          g1<0,4,1>.xxyxF g3<4,4,1>.xxyxF
>
> Instead of writing both halves of the vector (like the original code),
> it overwrites the full vector both times, clobbering the desired .xy
> values.
>
> When encountering a MOV, the compute-to-MRF code scans for instructions
> which generate channels of the MOV source.  It ensures that all
> necessary channels are available (possibly written by several
> instructions).  In this case, *more* channels are available than
> necessary, so we want to take the subset that's actually used.
> Taking the bitwise and of both writemasks should accomplish that.
>
> This was discovered by analyzing an ARB_vertex_program test
> (glean/vertProg1/MUL test (with swizzle and masking)) with my new
> Mesa IR -> Vec4 IR translator code.  However, it should be possible
> with GLSL programs as well.
>
> NOTE: This is a candidate for stable release branches.
>
> Cc: Eric Anholt <e...@anholt.net>
> Signed-off-by: Kenneth Graunke <kenn...@whitecape.org>

Thanks for the asm in the commit message, which made things clear.

Reviewed-by: Eric Anholt <e...@anholt.net>

Attachment: pgpERawFFjoFG.pgp
Description: PGP signature

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

Reply via email to