Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -13883,7 +13883,7 @@ lane masks and the discard destination. Run

`tools/startup/gfx2hlsl.py` lowers the gfx1013 binary16 interpolation pair `v_interp_p1ll_f16` / `v_interp_p2_f16` (#1996, item C). The attribute channel holds two binary16 values that the vertex stage exports with `compr`; half `h` of channel `c` is float channel `2 * c + h` of the parameter, and the pair becomes `(vD & 0xffff0000u) | f32tof16(i.paramN.<channel>)`, with the upper half of the destination kept. Only the plain form and `high` are lowered: `clamp`, an output modifier, a source modifier, a `p2` whose third source is not the matching `p1ll` result, and an attribute that the vertex stage does not export are refused. A vertex stage that packs the halves into a plain 32-bit export (no `compr`, e.g. with `v_cvt_pkrtz_f16_f32`) is lowered too, for all four channels: half `h` of channel `c` is `f16tof32(word_c >> 16 * h)`, carried by the extra interpolated outputs `hparamN_lo` and `hparamN_hi` that exist only when the pixel stage reads the attribute this way. An attribute exported both with `compr` and plain, and a read of a channel the plain export leaves `off`, are refused; the compr export still fills only `x` and `y`. `tests/startup_gfx2hlsl_interp_f16_check.py` evaluates the translated text on the CPU against a reference from the ISA layout and fails when the lowering is removed or the `high` bit is inverted; `binary <llvm-mc>` reassembles the fixtures and `draw` is the desktop readback (tests `startup_gfx2hlsl_interp_f16_controls`, `_warp` and `_hardware`). The `op_sel` bits (word 0 bits 11 to 14, each refused on its own) and any read of the upper 16 bits of a `p2` destination stay refused because no source states them for gfx10. Either of two kinds of evidence would lift the refusals: a source that states the gfx10 behaviour of the high 16 bits of the `v_interp_p2_f16` destination and of `op_sel` (kept, cleared or written), or a hardware draw on RDNA that reads back both halves of a `p2` result for each `op_sel` value and compares them with the lowering.

The startup pixel stage lowers DPP16 quad swaps (#2125 item B): `v_mov_b32_dpp` and the VOP2 forms in the integer and binary32 operation tables with `quad_perm:[1,0,3,2]`, `[2,3,0,1]` or `[3,2,1,0]` and full `row_mask`/`bank_mask` read the source from the neighbouring pixel of the 2x2 quad (X, Y or diagonal), written as `QuadReadAcrossX`, `QuadReadAcrossY` and `QuadReadAcrossDiagonal` (SM 6.0, helper lanes included). The second source of a VOP2 keeps the lane's own register. The form needs a straight-line pixel stage at entry EXEC, proven whole-quad by an earlier `s_wqm_b64 exec, exec` (a partly covered quad has inactive source lanes that the hardware masks and `QuadReadAcross*` does not; a later write to EXEC or a restored older copy drops the proof), and plain VGPR operands; vertex stages, broadcast and pair selections (items A and C), row shifts, mirrors, DPP8, partial masks, `fi:1`, source modifiers and operations without a table entry are refused. FXC ps_5_1 has no quad intrinsic, so `translate_to` compiles a pair that uses one with DXC as vs_6_0/ps_6_0 (`X2W_DXC`, then PATH) and refuses it when no DXC exists. `tests/startup_gfx2hlsl_dpp_quad_swap_check.py` builds three pixel programs from the lane rule (OR and move forms, plus `v_min_u32_dpp` of the exchanged and own positions, #2023 item H, whose reference is the integer unsigned minimum and which also rejects a maximum) (the packed position in v0, the neighbour at x^1, y^1 or both, an own-lane control), draws 16 x 16 pixels and compares every word with an integer reference; three wrong exchanges, a missing exchange and (for the minimum) a maximum must read a different image, and a reference with one swap dropped must be rejected. Run `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_dpp_quad_swap_' -V`. The Python controls run on Linux; the draws need DXC and `offscreen_check` on Windows.
The startup pixel stage lowers DPP16 quad swaps (#2125 item B): `v_mov_b32_dpp` and the VOP2 forms in the integer and binary32 operation tables with `quad_perm:[1,0,3,2]`, `[2,3,0,1]` or `[3,2,1,0]` and full `row_mask`/`bank_mask` read the source from the neighbouring pixel of the 2x2 quad (X, Y or diagonal), written as `QuadReadAcrossX`, `QuadReadAcrossY` and `QuadReadAcrossDiagonal` (SM 6.0, helper lanes included). The second source of a VOP2 keeps the lane's own register. The form needs a straight-line pixel stage at entry EXEC, proven whole-quad by an earlier `s_wqm_b64 exec, exec` (a partly covered quad has inactive source lanes that the hardware masks and `QuadReadAcross*` does not; a later write to EXEC or a restored older copy drops the proof), and plain VGPR operands; vertex stages, broadcast and pair selections (items A and C), row shifts, mirrors, DPP8, partial masks, source modifiers and operations without a table entry are refused. `fi:1` (fetch inactive) is accepted under the same whole-quad proof, where no source lane is disabled, and gives the same translation. FXC ps_5_1 has no quad intrinsic, so `translate_to` compiles a pair that uses one with DXC as vs_6_0/ps_6_0 (`X2W_DXC`, then PATH) and refuses it when no DXC exists. `tests/startup_gfx2hlsl_dpp_quad_swap_check.py` builds three pixel programs from the lane rule (OR and move forms, plus `v_min_u32_dpp` of the exchanged and own positions, #2023 item H, whose reference is the integer unsigned minimum and which also rejects a maximum) (the packed position in v0, the neighbour at x^1, y^1 or both, an own-lane control), draws 16 x 16 pixels and compares every word with an integer reference; three wrong exchanges, a missing exchange and (for the minimum) a maximum must read a different image, and a reference with one swap dropped must be rejected. Run `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_dpp_quad_swap_' -V`. The Python controls run on Linux; the draws need DXC and `offscreen_check` on Windows.

The startup pixel stage lowers constant-lane SGPR spills (#2125 item E): `v_writelane_b32 vN, sM, k` followed by `v_readlane_b32 sD, vN, k` with an inline constant lane `k` (0..31) becomes one scalar slot per (VGPR, lane), written and read back as plain assignments. Both instructions ignore EXEC and touch only lane `k`, so with a constant `k` and a VGPR that no other instruction names, no cross-lane read exists to model. Refused, each with a reason: a lane chosen by an SGPR, lanes outside 0..31, a VGPR that any other instruction also names (vector use or register range), a read of a slot nothing wrote, branches (write-before-read needs straight-line order), a lane mask, `m0` or modifier on the value, a destination that is not a plain SGPR, and vertex stages. A constant value reloads as a constant. `tests/startup_gfx2hlsl_sgpr_spill_check.py` builds a pixel program with four slots in three VGPRs, clobbers the source SGPRs, reloads them (one slot after a second write) and ORs each word into the packed screen position; it draws 16 x 16 pixels and compares every word with an integer reference computed from the slot rule. Four wrong lowerings (overwrite ignored, lane 31 read as lane 0, a second VGPR read as the first, no reload) must read a different image. Run `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sgpr_spill_' -V`. The Python controls and the `binary` assembler check run on Linux; the draws need DXC and `offscreen_check` on Windows.

Expand Down Expand Up @@ -14641,7 +14641,7 @@ ctest --preset release --no-tests=error -R '^cpu_aot_vex_parity$' -V

### gfx1013 pixel DPP16 quad broadcast

The pixel translator lowers `quad_perm:[k,k,k,k]` (k = 0 to 3) with full `row_mask` and `bank_mask` on `v_mov_b32` and the VOP1/VOP2 float, integer and integer-to-float forms to `QuadReadLaneAt(value, k)`. The four lanes of a pixel quad are one 2 x 2 block (lane = x & 1 | (y & 1) << 1). It is accepted only in a straight-line pixel stage that ran `s_wqm_b64 exec, exec` (or `s_wqm_b32 exec_lo, exec_lo`) with EXEC unchanged since: the entry EXEC can leave out lanes of a partly covered quad, and the guest would then read an inactive source lane while `QuadReadLaneAt` returns a helper lane's value. Without that proof the instruction is refused, as are swaps, pair broadcasts, row shifts, mirrors, DPP8, partial masks, `fi`, `bound_ctrl:0`, non-VGPR sources and vertex stages. A stage that holds a quad read compiles as `ps_6_0` with DXC (`X2W_DXC`, the Windows Kits `bin` folder or `PATH`), and its vertex stage as `vs_6_0`.
The pixel translator lowers `quad_perm:[k,k,k,k]` (k = 0 to 3) with full `row_mask` and `bank_mask` on `v_mov_b32` and the VOP1/VOP2 float, integer and integer-to-float forms to `QuadReadLaneAt(value, k)`. The four lanes of a pixel quad are one 2 x 2 block (lane = x & 1 | (y & 1) << 1). It is accepted only in a straight-line pixel stage that ran `s_wqm_b64 exec, exec` (or `s_wqm_b32 exec_lo, exec_lo`) with EXEC unchanged since: the entry EXEC can leave out lanes of a partly covered quad, and the guest would then read an inactive source lane while `QuadReadLaneAt` returns a helper lane's value. Without that proof the instruction is refused, as are swaps, pair broadcasts, row shifts, mirrors, DPP8, partial masks, `bound_ctrl:0`, non-VGPR sources and vertex stages. `fi:1` is accepted with the proof and changes nothing, since no source lane is disabled. A stage that holds a quad read compiles as `ps_6_0` with DXC (`X2W_DXC`, the Windows Kits `bin` folder or `PATH`), and its vertex stage as `vs_6_0`.

Reproduce: `ctest --preset dev --no-tests=error -R "^startup_gfx2hlsl_dpp_quad_broadcast" -V`. The controls cover the translation, every refusal and the missing `s_wqm`; the WARP and hardware draws compare all 256 pixels of two fixtures with a CPU reference, with wrong-lane and own-lane translations as failing controls. This does not establish full-game startup.

Expand Down
9 changes: 8 additions & 1 deletion tests/startup_gfx2hlsl_dpp_pair_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ def controls():
accepted = 'v_mov_b32_dpp v2, v1 quad_perm:[1,1,3,3] row_mask:0xf bank_mask:0xf'
check('accepted form translates', refused(accepted) is None, str(refused(accepted)))
check('bound_ctrl does not change the lowering', refused(accepted + ' bound_ctrl:1') is None)
stages = [Probe(), Probe()]
stages[0].one('v_mov_b32_dpp', accepted + ' bound_ctrl:1 fi:1')
stages[1].one('v_mov_b32_dpp', accepted)
check('fi:1 does not change the lowering (no source lane of a whole quad is disabled)',
stages[0].lines == stages[1].lines and any('QuadReadLaneAt' in line for line in stages[0].lines))
check('quad swap also translates', refused(accepted.replace('[1,1,3,3]', '[1,0,3,2]')) is None)
check('quad broadcast also translates', refused(accepted.replace('[1,1,3,3]', '[0,0,0,0]')) is None)
for label, asm, kwargs in (
Expand All @@ -259,7 +264,9 @@ def controls():
('a mirror control', 'v_mov_b32_dpp v2, v1 row_mirror row_mask:0xf bank_mask:0xf', {}),
('a partial row mask', accepted.replace('row_mask:0xf', 'row_mask:0x5'), {}),
('a partial bank mask', accepted.replace('bank_mask:0xf', 'bank_mask:0xe'), {}),
('fi', accepted + ' fi:1', {}),
('fi:1 with an entry mask not proven whole-quad', accepted + ' fi:1', {'wqm_exec': False}),
('fi:1 with an unknown entry mask', accepted + ' fi:1', {'exec_known': False}),
('fi:1 in a program with branches', accepted + ' fi:1', {'has_branches': True}),
('no control', 'v_mov_b32_dpp v2, v1 row_mask:0xf bank_mask:0xf', {}),
('a vertex stage', accepted, {'kind': 'vs'}),
('a program with branches', accepted, {'has_branches': True}),
Expand Down
16 changes: 14 additions & 2 deletions tests/startup_gfx2hlsl_dpp_quad_broadcast_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
against the reference and match their own plain-Python image.

Refused (the single-lane model cannot read a neighbour, or the quad may be partly off): swaps, pair broadcasts, row
shifts, mirrors, DPP8, a partial row_mask or bank_mask, fi, bound_ctrl:0, a scalar or constant source, a vertex
shifts, mirrors, DPP8, a partial row_mask or bank_mask, fi:1 without the whole-quad proof, bound_ctrl:0, a scalar or constant source, a vertex
stage, a pixel stage after EXEC changed or with branches, and operations outside the VOP1/VOP2 tables.
"""
import re
Expand Down Expand Up @@ -223,7 +223,6 @@ def controls():
'partial row_mask': 'v_mov_b32_dpp v1, v0 quad_perm:[1,1,1,1] row_mask:0xe bank_mask:0xf',
'partial bank_mask': 'v_mov_b32_dpp v1, v0 quad_perm:[1,1,1,1] row_mask:0xf bank_mask:0x7',
'no masks': 'v_mov_b32_dpp v1, v0 quad_perm:[1,1,1,1]',
'fi': sane + ' fi:1',
'bound_ctrl:0': sane + ' bound_ctrl:0',
'scalar source': 'v_mov_b32_dpp v1, s2 quad_perm:[1,1,1,1]' + DPP,
'constant source': 'v_mov_b32_dpp v1, 1.0 quad_perm:[1,1,1,1]' + DPP,
Expand All @@ -240,6 +239,19 @@ def controls():
check('refused: s_wqm into another register', refused_in_stage(OTHER_WQM_WORDS))
check('refused: pixel stage with branches', refused(sane, branches=True))
check('control: the sane line itself translates', not refused(sane))
# fi:1 only decides what a disabled source lane returns, and the whole quad is proven active.
with_fi = 'v_subrev_f32_dpp v1, v0, v0 quad_perm:[0,0,0,0]' + DPP + ' bound_ctrl:1 fi:1'
stages = [Probe(), Probe()]
stages[0].one('v_subrev_f32_dpp', with_fi)
stages[1].one('v_subrev_f32_dpp', with_fi[:-len(' fi:1')])
check('fi:1 does not change the broadcast lowering', stages[0].lines == stages[1].lines)
# The DPP source is SRC0 and v_subrev computes SRC1 - SRC0 (#1996 item B): the lane's own word minus lane 0.
check('v_subrev_f32_dpp of a register with itself is own lane minus quad lane 0',
stages[0].lines == ['v256 = QuadReadLaneAt(v0, 0u);', 'v1 = U(F(v0) - F(v256));'], str(stages[0].lines))
check('refused: fi:1 without s_wqm exec, exec', refused(with_fi, quad_exec=False))
check('refused: fi:1 with EXEC no longer the entry mask', refused(with_fi, exec_known=False))
check('refused: fi:1 in a pixel stage with branches', refused(with_fi, branches=True))
check('refused: fi:1 in a vertex stage', refused(with_fi, kind='vs'))


def check_binary(llvm_mc):
Expand Down
30 changes: 29 additions & 1 deletion tests/startup_gfx2hlsl_dpp_quad_swap_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def controls():
('partial bank_mask', base.replace('bank_mask:0xf', 'bank_mask:0x5'), {}),
('row_mirror', 'v_mov_b32_dpp v5, v0 row_mirror row_mask:0xf bank_mask:0xf', {}),
('DPP8', 'v_mov_b32_dpp v5, v0 dpp8:[1,0,3,2,5,4,7,6]', {}),
('fi:1', base + ' fi:1', {}),
('fi:0 spelling', base + ' fi:0', {}),
('fi:1 with EXEC no longer the entry mask', base + ' fi:1', {'exec_known': False}),
('fi:1 with entry EXEC not proven whole-quad', base + ' fi:1', {'wqm_exec': False}),
('negated source', 'v_add_f32_dpp v5, -v0, v1 quad_perm:[1,0,3,2] row_mask:0xf bank_mask:0xf', {}),
('SGPR source', 'v_mov_b32_dpp v5, s0 quad_perm:[1,0,3,2] row_mask:0xf bank_mask:0xf', {}),
('operation without a table entry', 'v_cvt_f64_f32_dpp v[5:6], v0 quad_perm:[1,0,3,2] row_mask:0xf bank_mask:0xf', {}),
Expand Down Expand Up @@ -238,6 +240,32 @@ def controls():
except G.Unsupported as reason:
check('refused: whole-quad proof dropped by a restored exec copy (%s)' % reason, 'whole-quad' in str(reason))

# 4b'. fi:1 (fetch inactive, bit 18 of the DPP dword) decides what a disabled source lane returns. With the whole
# quad proven active there is none, so the translation is the one without it; without the proof it stays refused.
for name in NAMES:
plain = fixture(name)[1]
with_fi = bytearray(plain)
for off, _size, mnemonic, _asm in G.decode(plain):
if mnemonic.endswith('_dpp'):
with_fi[off + 6] |= 4
decoded = [asm for _, _, mnemonic, asm in G.decode(bytes(with_fi)) if mnemonic.endswith('_dpp')]
check('%s fixture with FI set decodes to three fi:1 swaps' % name,
len(decoded) == 3 and all(asm.endswith(' fi:1') for asm in decoded), str(decoded))
check('%s fixture with fi:1 translates to the text without it' % name,
pipeline(bytes(with_fi)).hlsl_ps() == pipeline(plain).hlsl_ps())
try:
pipeline(bytes(with_fi)[len(WQM):]).hlsl_ps()
check('%s fixture with fi:1 and no s_wqm exec is refused' % name, False)
except G.Unsupported as reason:
check('%s fixture with fi:1 and no s_wqm exec is refused (%s)' % (name, reason), 'whole-quad' in str(reason))
branched = Probe()
branched.has_branches = True
try:
branched.one('v_min_u32_dpp', dpp_text('v_min_u32_dpp', 'v5, v0, v0', (1, 0, 3, 2)) + ' fi:1')
check('refused: fi:1 in a shader with branches', False)
except G.Unsupported:
check('refused: fi:1 in a shader with branches', True)

# 4c. The min fixture keeps src1 in its own lane and its reference is neither the plain exchange nor a maximum.
line = pipeline(fixture('min')[1]).hlsl_ps()
check('v_min_u32_dpp lowers to min(exchanged src0, own src1)',
Expand Down
10 changes: 7 additions & 3 deletions tools/startup/gfx2hlsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ def dpp_pair(self, base, asm, ops, mods):
lane keeps the one quad_perm names for its own position in the quad. That needs all four lanes of the quad to
run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and a
whole-quad exec mask (proved by s_wqm exec, exec on the entry mask; a restored exact mask loses it). Every
other control (other permutations, row_*, wave_*, a partial row or bank mask, fi, a vertex stage) is refused by
other control (other permutations, row_*, wave_*, a partial row or bank mask, a vertex stage) is refused by
name, since the single lane cannot read a neighbour."""
perms = [m for m in mods if m.startswith('quad_perm:')]
rest = [m for m in mods if not m.startswith('quad_perm:')]
Expand Down Expand Up @@ -2211,7 +2211,7 @@ def lower(self, base, asm, ops, mods):
# Accepted only where the whole quad is proven active: a straight-line pixel stage that ran s_wqm exec, exec and
# whose EXEC is still that mask (helper lanes are active, so no source lane is off). bound_ctrl then has
# nothing to decide (the source lane is never disabled), so it is accepted and ignored. Everything else a DPP word can say stays refused: other controls (pair
# broadcasts, row shifts, mirrors, DPP8), a masked row or bank, fi, and a vertex stage.
# broadcasts, row shifts, mirrors, DPP8), a masked row or bank, and a vertex stage (dpp() drops fi:1 first).
DPP_TEMP = 256 # hidden VGPR that holds the quad read; the hardware has v0..v255 only
DPP_OUTPUT_MODS = ('clamp', 'mul:2', 'mul:4', 'div:2')

Expand Down Expand Up @@ -2270,8 +2270,12 @@ def dpp_broadcast(self, base, ops, mods):
# map onto the SM 6.0 quad intrinsics, which read the other lane of the 2x2 pixel quad and keep
# helper lanes active. Only a pixel stage at entry EXEC qualifies, and only after `s_wqm exec, exec`
# proved whole-quad EXEC: the hardware can return 0 or the old value for a source lane whose EXEC bit
# is off (an uncovered pixel of an edge quad), and the intrinsics have no such case. Other permutations, DPP8, row shifts and partial masks stay refused.
# is off (an uncovered pixel of an edge quad), and the intrinsics have no such case. Other permutations, fi:1 without that proof, DPP8, row shifts and partial masks stay refused.
def dpp(self, base, ops, mods):
# fi:1 (fetch inactive, DPP16 dword bit 18; LLVM AMDGPU `fi`, Mesa ACO fetch_inactive) only decides what a
# disabled source lane returns. Every lowering below is taken only with the whole quad proven active, so no
# source lane is disabled and it decides nothing.
mods = [m for m in mods if m != 'fi:1']
if any(re.fullmatch(r'quad_perm:\[([0-3]),\1,\1,\1\]', mod) for mod in mods):
return self.dpp_broadcast(base, ops, mods)
perm = None
Expand Down
Loading