Skip to content
Open
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4638,7 +4638,7 @@ if(EXISTS "${INTAKE_PYTHON}")
foreach(control IN ITEMS swapped-axes dropped-store b-offset c-unpredicated f-peer f-broadcast f-second-fill g-swapped-offsets g-overlap
j-scalar-dropped h-inner-unpredicated k-block-entered m-else-unswitched n-unmasked o-mask-kept o-subset-remask-dropped
n-dropped-broadcast p-dropped-andn2 p-dropped-or p-block-entered q-block-entered q-not-all-ones
s-min-strict s-borrow-flipped)
s-min-inclusive s-borrow-flipped)
add_test(NAME startup_gfx2hlsl_compute_${control}_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_compute_check.py" control ${control} "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
Expand Down
27 changes: 17 additions & 10 deletions tests/startup_gfx2hlsl_compute_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
binary <llvm-mc> reassemble the fixture sources and compare them with the words below
dispatch <dxc> <offscreen_check> <warp|hardware>
translate, compile with DXC cs_6_0, dispatch and compare every word
control <swapped-axes|dropped-store|b-offset|c-unpredicated|j-scalar-dropped|h-inner-unpredicated|m-else-unswitched|n-unmasked|o-mask-kept|s-min-strict|s-borrow-flipped> <dxc> <offscreen_check> <warp|hardware>
control <swapped-axes|dropped-store|b-offset|c-unpredicated|j-scalar-dropped|h-inner-unpredicated|m-else-unswitched|n-unmasked|o-mask-kept|s-min-inclusive|s-borrow-flipped> <dxc> <offscreen_check> <warp|hardware>
the same dispatch with a mutated translation, which must mismatch

The fixtures are source-built gfx1013 compute programs. The root signature puts two root constants (key, stride)
Expand Down Expand Up @@ -643,7 +643,7 @@ def scc_fixture():
"""Group (x, y) of the 4 x 4 grid takes S0 = edge[x], S1 = edge[y] (0, -1, INT_MAX, INT_MIN); the runner accepts at most 5 groups per axis. Each s_add/s_sub/s_min/s_max forms is run
twice (the destination apart from S0, then the destination that is S0) and its SCC read right after; word 0 of the
group holds the 16 SCC bits, word 1 a hash of the 16 results. RDNA 2 ISA: s_add_u32 carry out, s_sub_u32 borrow,
s_add_i32 / s_sub_i32 signed overflow, s_min / s_max SCC = (D == S0)."""
s_add_i32 / s_sub_i32 signed overflow, s_min / s_max SCC is set only when S0 is strictly smaller / larger."""
lines = ['s_mov_b32 s10, s6', 's_mov_b32 s11, 0', 's_load_dwordx8 s[12:19], s[10:11], 0x0', 's_waitcnt lgkmcnt(0)',
's_lshl_b32 s24, s8, 2', 's_add_u32 s24, s24, s7', 'v_lshlrev_b32 v4, 3, s24', 's_mov_b32 s22, s7',
's_mov_b32 s23, s8']
Expand Down Expand Up @@ -686,9 +686,8 @@ def signed(x):
scc = not -(1 << 31) <= signed(x) - signed(b) < (1 << 31)
else:
view = signed if op.endswith('i32') else (lambda v: v)
pick = min if 'min' in op else max
result = pick(x, b, key=view)
scc = result == x
scc = view(x) < view(b) if 'min' in op else view(x) > view(b)
result = x if scc else b
bits |= int(scc) << (2 * n + alias)
hashed = ((hashed ^ result) << 1) & MASK
return bits, hashed
Expand Down Expand Up @@ -1590,7 +1589,8 @@ def check_scc_modelled():
# its sources, ahead of the branch.
words = {'s_add_u32 s23, s7, -1': '07c11780', 's_sub_u32 s23, s7, 1': '07819780',
's_add_i32 s23, s7, 0x7fffffff': '07ff1781ffffff7f', 's_sub_i32 s23, s7, 1': '07819781',
's_min_u32 s23, s7, 4': '07849783', 's_max_i32 s23, s7, 4': '07841784', 's_wqm_b32 s23, s7': '070997be',
's_min_u32 s23, s7, 4': '07849783', 's_max_u32 s23, s7, 4': '07849784',
's_min_i32 s23, s7, 4': '07841783', 's_max_i32 s23, s7, 4': '07841784', 's_wqm_b32 s23, s7': '070997be',
's_cselect_b32 s24, 1, 0': '81801885', 's_cbranch_scc1 1': '010085bf'}
SPLICE.update(words)
for line, word in words.items(): # the decoder prints each hand-assembled word as its line (literals in hex)
Expand All @@ -1603,10 +1603,16 @@ def check_scc_modelled():
('s_add_i32 s23, s7, 0x7fffffff',
'scc = (((((s7) ^ (s7 + 0x7fffffffu)) & ((0x7fffffffu) ^ (s7 + 0x7fffffffu))) >> 31) != 0);'),
('s_sub_i32 s23, s7, 1', 'scc = (((((s7) ^ (0x00000001u)) & ((s7) ^ (s7 - 0x00000001u))) >> 31) != 0);'),
('s_min_u32 s23, s7, 4', 'scc = ((s7) <= (0x00000004u));'),
('s_max_i32 s23, s7, 4', 'scc = (int(s7) >= int(0x00000004u));')):
('s_min_u32 s23, s7, 4', 'scc = ((s7) < (0x00000004u));'),
('s_max_u32 s23, s7, 4', 'scc = ((s7) > (0x00000004u));'),
('s_min_i32 s23, s7, 4', 'scc = (int(s7) < int(0x00000004u));'),
('s_max_i32 s23, s7, 4', 'scc = (int(s7) > int(0x00000004u));')):
text = translate('A', code=splice(op, 's_cbranch_scc1 1', 'v_mov_b32 v3, 0')).hlsl_cs()
assert scc in text and text.index(scc) < text.index('pc = (scc)'), (op, text)
# Case S packs two SCC bits each for min_u, max_u, min_i, max_i in bits 8..15 (separate and aliased destination).
assert all(scc_reference(x, x)[0] >> 8 == 0 for x in SCC_EDGES)
assert scc_reference(0, MASK)[0] >> 8 == 0xc3 # 0 < UINT_MAX, but 0 > -1
assert scc_reference(MASK, 0)[0] >> 8 == 0x3c
# A reader whose last SCC writer the lowering still does not model is refused by name (s_wqm is not lowered).
refused('scc from an SCC write that is not modelled in s_cbranch_scc1', lambda: translate(
'A', code=splice('s_wqm_b32 s23, s7', 's_cbranch_scc1 1', 'v_mov_b32 v3, 0')))
Expand Down Expand Up @@ -2551,8 +2557,8 @@ def check_binary(llvm_mc):
MBCNT_COUNT = f'countbits(0x85241249u & ((1u << {MBCNT_LANE}) - 1u))'
CONTROLS = {
'join-load-zero': ('join-load', 's24 = ul24_7;', 's24 = 0u;'),
# s_min_u32 sets SCC when S0 is chosen, equal operands included: a strict compare differs at S0 == S1.
's-min-strict': ('S', '(s20) <= (s21)', '(s20) < (s21)'),
# Setting SCC on a tie changes bit 8 of the group's first word; the min result is unchanged.
's-min-inclusive': ('S', 'scc = ((s20) < (s21));', 'scc = ((s20) <= (s21));'),
# s_sub_u32 borrow: the first source is the smaller one.
's-borrow-flipped': ('S', '(s20) < (s21);\n s24 = s20 - s21;', '(s21) < (s20);\n s24 = s20 - s21;'),
'swapped-axes': ('A', ' s7 = gid.x;\n s8 = gid.y;\n', ' s7 = gid.y;\n s8 = gid.x;\n'),
Expand Down Expand Up @@ -2594,6 +2600,7 @@ def check_binary(llvm_mc):

# First bad word for controls with a pinned mismatch.
CONTROL_MISMATCH = {
's-min-inclusive': 'word=0 expected=00000000 actual=00000100',
'join-load-zero': 'word=0 expected=8b02a7f1 actual=00000000',
'f-second-fill': 'word=1 expected=00000094 actual=00000000',
'd-mask': 'word=8 expected=00000008 actual=00000009',
Expand Down
8 changes: 4 additions & 4 deletions tests/startup_gfx2hlsl_scalar_null_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ def run_stage(*instructions, varying=()):
('s_sub_u32 null, s0, s1', 'scc = (s0) < (s1);'),
('s_add_i32 null, s0, s1', 'scc = (((((s0) ^ (s0 + s1)) & ((s1) ^ (s0 + s1))) >> 31) != 0);'),
('s_sub_i32 null, s0, s1', 'scc = (((((s0) ^ (s1)) & ((s0) ^ (s0 - s1))) >> 31) != 0);'),
('s_min_u32 null, s0, s1', 'scc = ((s0) <= (s1));'),
('s_max_u32 null, s0, s1', 'scc = ((s0) >= (s1));'),
('s_min_i32 null, s0, s1', 'scc = (int(s0) <= int(s1));'),
('s_max_i32 null, s0, s1', 'scc = (int(s0) >= int(s1));')):
('s_min_u32 null, s0, s1', 'scc = ((s0) < (s1));'),
('s_max_u32 null, s0, s1', 'scc = ((s0) > (s1));'),
('s_min_i32 null, s0, s1', 'scc = (int(s0) < int(s1));'),
('s_max_i32 null, s0, s1', 'scc = (int(s0) > int(s1));')):
st = ProbeStage()
st.one(asm.split()[0], asm)
check(f'{asm} computes only its SCC {st.lines}', st.lines == [scc_line])
Expand Down
4 changes: 2 additions & 2 deletions tools/startup/gfx2hlsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11482,7 +11482,7 @@ def low(n):
def add_sub_min_max_scc(base, a, b, result):
"""The SCC expression of s_add/s_sub/s_min/s_max_{i,u}32 over the source texts a and b and the result text.
s_add_u32: carry out; s_sub_u32: borrow (S0 < S1); s_add_i32 / s_sub_i32: signed overflow (the sign of the result
differs from the sign the operands imply); s_min / s_max: SCC = (D == S0), the first source was chosen."""
differs from the sign the operands imply); s_min / s_max: S0 < S1 / S0 > S1 (RDNA 2 ISA, SOP2 opcodes 6-9)."""
if base == 's_add_u32':
return '(%s) < (%s)' % (result, a)
if base == 's_sub_u32':
Expand All @@ -11492,7 +11492,7 @@ def add_sub_min_max_scc(base, a, b, result):
if base == 's_sub_i32':
return '(((((%s) ^ (%s)) & ((%s) ^ (%s))) >> 31) != 0)' % (a, b, a, result)
cast = 'int' if base.endswith('_i32') else ''
return '(%s(%s) %s %s(%s))' % (cast, a, '<=' if base.startswith('s_min') else '>=', cast, b)
return '(%s(%s) %s %s(%s))' % (cast, a, '<' if base.startswith('s_min') else '>', cast, b)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate cached translations for the new SCC semantics

When upgrading while retaining a populated X2W_SHADER_CACHE on the gfx2hlsl path, completed shaders continue using the inclusive predicate. pipeline_key() and compute_key() still use revision 29, matching the unchanged runtime constants in src/startup_stubs/d3d12_draw.inl, and pending_keys() skips existing manifest/bytecode pairs without checking translator changes. The bundled Case S produces different HLSL but retains its previous cache key, so affected cached shaders still set SCC on ties until the cache is manually cleared. Advance the affected cache revisions on both translator and runtime sides, or otherwise invalidate completed translations, alongside this semantic change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on Linux with source-built inputs: the same warm cache caused gfx2hlsl.py --pending to skip Case S compute, a graphics pair, and a slot-57 mesh+pixel pair. Cold translation produced different DXIL for all three. The slot-57 pixel path shares this SCC lowering but has its own key; that key also names captured .mesh57-state / .s57 inputs, so a blanket bump needs a capture-compatibility plan. #3382 also uses 30/30cs for a different translation change. I’m leaving the review open rather than reusing those seeds. Would you prefer to stage the SCC invalidation after #3382 with a coordinated revision and slot-57 compatibility plan?


PACK_B16 = frozenset(('s_pack_ll_b32_b16', 's_pack_lh_b32_b16', 's_pack_hh_b32_b16'))
SCA = {
Expand Down
Loading