freedreno/ir3: detect scheduler fail

There are some cases where the scheduler can get itself into impossible
situations, by scheduling the wrong write to pred or addr register
first.  (Ie. it could end up being unable to schedule any instruction if
some instruction which depends on the current addr/reg value also
depends on another addr/reg value.)

To solve this we'd need to be able to insert extra mov instructions
(which would also help when register assignment gets into impossible
situations).  To do that, we'd need to move the nop padding from sched
into legalize.

But to start with, just detect when we get into an impossible situation
and bail, rather than sitting forever in an infinite loop.  This way it
will at least fall back to the old compiler, which might even work if
you are lucky.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit b823abedf8d1ddba9aeaa43c4a239cb90664dae4)
freedreno/ir3: add TXB

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit c99f09f4be29f3f7560607edf001497e1b5abfbf)
freedreno/ir3: add DDX/DDY

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit ef858ac77055eb3c6bebd01719cee681959123a0)
freedreno/ir3: bit of debug

Make it easier to figure out which compiler stage failed.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 08ee0488e6ae4c3728f00b24a2744cb3bd1929e8)
freedreno/ir3: fix error in bail logic

all_delayed will also be true if we didn't attempt to schedule anything
due to no more instructions using current addr/pred.  We rely on coming
in to block_sched_undelayed() to detect and clean up when there are no
more uses of the current addr/pred, which isn't necessarily an error.

This fixes a regression introduced in b823abed.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 73ff4c5f70286ffe72ce6a60b68a8274d7425478)
freedreno/ir3: fix constlen with relative addressing

We can't rely on the value from the assembler if relative addressing is
used.  So instead use the max of declared-consts (which does not include
compiler immediates) and what we get from the assembler (which does).

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 5d8f40a53a58c984906bc6509f01e31cc41ed1da)

Conflicts:
	src/gallium/drivers/freedreno/ir3/ir3_shader.c
freedreno/ir3: add no-copy-propagate fallback step

Most of the things the new compiler still has trouble with basically
amount to cp stage removing too many copies.  But without the cp stage,
the shaders the new compiler produces are still better (perf and
correctness) than the old compiler.  So a simple thing to do until I
have more time to work on it is first trying falling back to new
compiler without cp, before finally falling back to old compiler.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit fd4884e9291cd941c31e9ed7858a42bec2f1eca8)
freedreno: don't overflow cmdstream buffer so much

We currently aren't too clever about dealing with running out of
cmdstream buffer space.  Since we use a single buffer for both drawing
and tiling commands, we need to ensure there is enough space at the tail
of the cmdstream buffer to fit the tiling commands.

Until we get more clever, the easy solution is a threshold to trigger
flushing rendering even if the application does not trigger flush (swap,
changing render target, etc).  This way we at least don't crash for apps
that do several thousand draw calls (like some piglit tests do).

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 4f338c9bbff090d606afdc22373cc7869b0d0c89)
freedreno/ir3: fix potential segfault in RA

Triggered by shaders like:

  FRAG
  PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1
  DCL OUT[0], COLOR
  DCL CONST[0]
  DCL TEMP[0..2], LOCAL
    0: IF CONST[0].xxxx :0
    1:   MOV TEMP[0], TEMP[1]
    2: ELSE :0
    3:   MOV TEMP[0], TEMP[2]
    4: ENDIF
    5: MOV OUT[0], TEMP[0]
    6: END

not really a sane shader, although driver segfaulting is probably
not the appropriate response.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit a2c22d80d4efc793a29150360f428a76f9c8589d)
freedreno: update generated headers

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 564183f39c24c1674fd71df42c83a2e34d1c7291)
freedreno/a3xx: enable hw primitive-restart

Since software primitive-restart emulation is going to be removed (and
anyways, mostly seemed to be crash prone in combination with
u_primconvert and oddball scenarios (like PIPE_PRIM_POLYGON with only a
single vertex), might as well do it in hardware (which fortunately
didn't turn out to be too hard to figure out).

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 720cfb6fe9a3dafadf3bc034008f7c5c15973866)
freedreno/a3xx: handle rendering to layer != 0

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 2ed7640eeccfbfdff0862fd92b05b3f0175d3c64)
freedreno: update generated headers

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 1fba4905690b9798c4d1e45e9679ea2f3c43ecf8)
freedreno/a3xx: format fixes

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 480fe244dd41a034111963440a9f51999cfc9035)
util/u_format: add _is_alpha()

Because of render-to-alpha (000x) shenanigans, freedreno needs to do
some special handling when rendering to alpha-only formats.  And I
noticed that while we had _is_luminance(), _is_intensity(), etc, an
_is_alpha() helper was missing.  So fix that.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 3e0a82b52ebbf306adb0dd0f0990f7a8e8b271c5)
freedreno/a3xx: alpha render-target shenanigans

We need the .w component to end up in .x, since the hw appears to fetch
gl_FragColor starting with the .x coordinate regardless of MRT format.
As long as we are doing this, we might as well throw out the remaining
unneeded components.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 80058c0f08ea94d3de96909027a792e397fa9262)
freedreno/ir3: fix FSLT/etc handling to return 0/-1 instead of 0/1.0

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 572ffca050ff646bd9cdd031a44ec97966741745)
freedreno/ir3: INEG operates on src0, not src1

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 10273f84c22a5baaa5d23ea4d408bc50ef2e3b6e)
freedreno/ir3: add UARL support

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 8edf83b37738393bede502aae937a868ed98fefd)
freedreno/ir3: negate result of USLT/etc

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Rob Clark <robclark@freedesktop.org>
(cherry picked from commit 11d72553c5aaf5e7d3b2ab7d73f5cb8610aeb685)