From 4274dc2c4cbb72a306a3e59a5d9e98f4f2ce661a Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:43:27 +0100 Subject: [PATCH 1/2] compute: copy descriptor words through VCC as a scalar temporary A direct compute program may park descriptor words in VCC with s_mov and move them back. The move into s106/s107 used to refuse eagerly with "descriptor used as mask". The words are now copied with their symbols, and every consumer that reads VCC as a mask or as numeric data (carry-in, cndmask, branches, SALU, DPP, readlane selectors, SMEM offsets) requires numeric VCC words, so a real descriptor-as-mask use still refuses. --- src/gfx1013_direct_compute.inl | 52 ++++--- tests/cmake/native_vcc_descriptor_copy.cmake | 16 +++ tests/native_vcc_descriptor_copy_check.py | 134 +++++++++++++++++++ 3 files changed, 187 insertions(+), 15 deletions(-) create mode 100644 tests/cmake/native_vcc_descriptor_copy.cmake create mode 100644 tests/native_vcc_descriptor_copy_check.py diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index 1c67781351..c8e5bb7131 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -178,6 +178,8 @@ struct DirectCompute { // M0 holds ordinary numeric ALU bits here, not an implicit memory/indexing operand. const bool numeric_m0 = !graphics_input && n == 124 && i.enc != Encoding::Mubuf && i.enc != Encoding::Smem; if (n <= 106 || n == 126 || n == 127 || (!graphics_input && n == 107) || numeric_m0 || (n >= 256 && n < 512)) { + if (!graphics_input && (n == 106 || n == 107)) + sgpr_limit = 108; analysis.require_numeric(i, n, sgpr_limit); return read(n); } @@ -2924,6 +2926,9 @@ struct DirectCompute { auto n = i.name; if (compute) { if (const auto offset = heap_offset_add(i, state)) { + const auto base = i.src[1 - *offset]; + if (base == 106 || base == 107) + analysis.require_numeric(i, base, 108); // The heap base is slot 0 of ResourceDescriptorHeap: the low word keeps the byte offset, the carry is 0. write(i.dst, operand32(i, i.src[*offset])); write(128, "0"); @@ -3208,6 +3213,10 @@ struct DirectCompute { return; } if (auto field = byte_descriptor_field(i,state,heap_window)) { + if (compute) + for (auto src : {i.src[0], i.src[1]}) + if (src == 106 || src == 107) + analysis.require_numeric(i, src, 108); // Keep derived words symbolic, including the status bit until a // later instruction overwrites it. Never let a numeric branch // observe a placeholder for this field or its SCC. @@ -3355,30 +3364,34 @@ struct DirectCompute { return i.subword && j < 2 ? subword(value, i.src_select[j], i.src_sext[j]) : value; }; if (n == "s_mov_b32" || n == "s_mov_b64") { + const bool pair = n == "s_mov_b64"; + const unsigned src = i.src[0], last_scalar = compute ? 107 : 105; const bool exec_hi = i.dst == 127 && (wave64 || (compute && n == "s_mov_b32")); if (i.dst > 106 && i.dst != 126 && !(compute && i.dst == 107) && !exec_hi && !(compute && i.dst == 124 && n == "s_mov_b32")) refuse(i.pc, "direct scalar move destination"); - if (i.src[0] <= 105 && !state[i.src[0]].numeric()) { - if (i.dst > 105) + const bool symbolic_low = src <= last_scalar && !state[src].numeric(); + const bool symbolic_high = pair && src <= 106 && !state[src + 1].numeric(); + const bool copies_vcc = compute && ((src >= 106 && src <= 107) || (i.dst >= 106 && i.dst <= 107)); + if (symbolic_low || (copies_vcc && symbolic_high)) { + if (i.dst > last_scalar) refuse(i.pc, "descriptor used as mask"); - if (n == "s_mov_b64" && ((i.dst | i.src[0]) & 1)) + if (pair && ((i.dst | src) & 1)) refuse(i.pc, "unaligned scalar pair"); - auto indexed = [](const Symbol &v) { - return v.type == Symbol::Type::indexed_descriptor || v.type == Symbol::Type::sampler_word; - }; - if (indexed(state[i.src[0]])) - write(i.dst, read(i.src[0])); - if (n == "s_mov_b64" && indexed(state.at(i.src[0] + 1))) - write(i.dst + 1, read(i.src[0] + 1)); - // Transfer tracks symbolic low words; preserve numeric high words of a pair independently. - if (n == "s_mov_b64" && state.at(i.src[0] + 1).numeric()) - write(i.dst + 1, operand32(i, i.src[0] + 1)); + // Transfer copies each identity. An indexed descriptor keeps + // its runtime slot index. A heap address keeps its byte offset. + for (unsigned j = 0; j < (pair ? 2u : 1u); ++j) { + const auto word = src + j; + if (state[word].numeric()) + write(i.dst + j, operand32(i, word)); + else if (state[word].type == Symbol::Type::indexed_descriptor || state[word].type == Symbol::Type::sampler_word || + (copies_vcc && state[word].type == Symbol::Type::heap_offset)) + write(i.dst + j, read(word)); + } return; } string a = val(0); if (n == "s_mov_b64") { - unsigned src = i.src[0]; if (src >= 240 && src != 255) refuse(i.pc, "floating inline constant in 64-bit move"); if ((i.dst & 1) || (src < 128 && (src & 1))) @@ -4478,7 +4491,11 @@ struct DirectCompute { if (i.dpp_bank_mask != 15) apply_mask(i.dpp_bank_mask, ir.binary("and", ir.binary("lshr", lane, "2"), "3")); string previous; - if (!write_enabled.empty()) previous = read(i.dst); + if (!write_enabled.empty()) { + if (!graphics_input && (i.dst == 106 || i.dst == 107)) + analysis.require_numeric(i, i.dst, 108); + previous = read(i.dst); + } arithmetic(i, state, &word); if (!previous.empty()) write(i.dst, select(write_enabled, read(i.dst), previous)); @@ -4657,6 +4674,11 @@ struct DirectCompute { } else { unsigned r = i.op == 4 || i.op == 5 ? 128 : i.op == 6 || i.op == 7 ? 106 : 126; + if (r == 106) { + analysis.require_numeric(i, 106, 108); + if (wave64) + analysis.require_numeric(i, 107, 108); + } auto mask = wave64 && r != 128 ? ir.binary("or", read(r), read(r + 1)) : read(r); auto pred = cmp((i.op & 1) ? "ne" : "eq", mask, "0"); if (virtual_waves) yield_virtual_wave(select(pred,to_string(i.target()),to_string(i.next))); diff --git a/tests/cmake/native_vcc_descriptor_copy.cmake b/tests/cmake/native_vcc_descriptor_copy.cmake new file mode 100644 index 0000000000..3d0598deeb --- /dev/null +++ b/tests/cmake/native_vcc_descriptor_copy.cmake @@ -0,0 +1,16 @@ +if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/dxc.exe" AND + EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + set(checker "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_vcc_descriptor_copy_check.py") + add_test(NAME native_vcc_descriptor_copy_controls COMMAND "${INTAKE_PYTHON}" -B + "${checker}" controls "$" "${DXC_BIN_DIR}") + set_tests_properties(native_vcc_descriptor_copy_controls PROPERTIES TIMEOUT 120) + if(TARGET offscreen_check) + foreach(adapter IN ITEMS warp hardware) + add_test(NAME native_vcc_descriptor_copy_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${checker}" hardware "$" "${DXC_BIN_DIR}" + "$" ${adapter}) + set_tests_properties(native_vcc_descriptor_copy_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) + endforeach() + endif() + unset(checker) +endif() diff --git a/tests/native_vcc_descriptor_copy_check.py b/tests/native_vcc_descriptor_copy_check.py new file mode 100644 index 0000000000..613d2f4d75 --- /dev/null +++ b/tests/native_vcc_descriptor_copy_check.py @@ -0,0 +1,134 @@ +"""Check source-built descriptor moves through VCC in direct compute.""" +from pathlib import Path +import re +import subprocess +import sys +import tempfile + +from native_direct_container_check import compute, words +from native_image_atomic_check import render + + +def mov(dst, src, *, pair=False): + return 0xbe800000 | dst << 16 | (4 if pair else 3) << 8 | src + + +VCC_LO, VCC_HI, EXEC, M0, ZERO = 106, 107, 126, 124, 128 +END = 0xbf810000 +VCCZ = 0xbf860001 # Target skips the fallthrough s_endpgm. +WAIT = 0xbf8cc07f +SETUP = (mov(1, ZERO), mov(4, 0, pair=True)) +LOAD = (0xf4080000 | 16 << 6 | 2, 125 << 25, WAIT) # s[16:19], s[4:5], 0 +PARK = (mov(VCC_LO, 18, pair=True),) +CLEAR = mov(18, ZERO, pair=True) +STORE = ( + 0x1a << 25 | 1 << 17 | 130, # v_lshlrev_b32 v1, 2, v0 (local x) + 0x7e000200 | 2 << 17 | 135, # v_mov_b32 v2, 7 + 0xe0701000, 128 << 24 | 4 << 16 | 2 << 8 | 1, # buffer_store_dword, offen +) +VOPC = (0x7c000000 | 0xc2 << 17 | ZERO,) # v_cmp_eq_u32 vcc, 0, v0 +CARRY = (0xd70f0000 | VCC_LO << 8 | 3, ZERO | 256 << 9) # v_add_co_u32 v3, vcc, 0, v0 +CNDMASK = 1 << 25 | 3 << 17 | ZERO # v_cndmask_b32 v3, 0, v0, vcc + +BASELINE = (*SETUP, CLEAR, *LOAD, *STORE) +PAIR_COPY = (*SETUP, *LOAD, *PARK, CLEAR, mov(18, VCC_LO, pair=True), *STORE) +WORD_COPY = (*SETUP, *LOAD, mov(VCC_LO, 18), mov(VCC_HI, 19), CLEAR, + mov(18, VCC_LO), mov(19, VCC_HI), *STORE) + + +def compile_shader(cli, sdk, work, name, code, *, wave64): + source = work / f'{name}.cdx' + shader = source.with_suffix('.cso') + source.write_bytes(compute(words(*code, END), threads=64 if wave64 else 32, + table=True, wave32=not wave64)) + result = subprocess.run([cli, sdk, work / 'cache', 'gfx1013-container-cs', source, shader], + capture_output=True, text=True, timeout=30) + return shader, result + + +def accept(cli, sdk, work, name, code, *, wave64): + shader, result = compile_shader(cli, sdk, work, name, code, wave64=wave64) + assert result.returncode == 0 and shader.is_file(), (name, result.stdout, result.stderr) + return shader + + +def reject(cli, sdk, work, name, prefix, consumer, message, *, wave64, tail=()): + shader, result = compile_shader(cli, sdk, work, name, (*prefix, *consumer, *tail), wave64=wave64) + diagnostic = f'native compute +0x{4 * len(prefix):x}: {message}' + assert result.returncode and not shader.exists(), (name, result.stdout, result.stderr) + assert diagnostic in result.stderr.splitlines(), (name, diagnostic, result.stderr) + + +def store_call(sdk, shader): + dump = subprocess.run([Path(sdk) / 'dxc.exe', '-dumpbin', shader], + capture_output=True, text=True, timeout=30, check=True).stdout + stores = [line.strip() for line in dump.splitlines() + if 'call void @dx.op.' in line and 'bufferstore' in line.lower()] + assert len(stores) == 1 and re.fullmatch( + r'call void @dx\.op\.rawBufferStore\.i32\(i32 140, %dx\.types\.Handle %\w+, ' + r'i32 %\w+, i32 undef, i32 %\w+, i32 undef, i32 undef, i32 undef, i8 1, i32 4\)' + r'(?: #[0-9]+)?(?:\s*;.*)?', stores[0] + ), dump + return stores[0] + + +def controls(cli, sdk, work): + for wave64 in (False, True): + width = 64 if wave64 else 32 + baseline = store_call(sdk, accept(cli, sdk, work, f'base{width}', BASELINE, wave64=wave64)) + for name, code in (('pair', PAIR_COPY), ('word', WORD_COPY)): + shader = accept(cli, sdk, work, f'{name}{width}', code, wave64=wave64) + assert store_call(sdk, shader) == baseline, name + + parked = (*SETUP, *LOAD, *PARK) + reject(cli, sdk, work, f'vccz{width}', parked, (VCCZ,), 'unbound numeric SGPR s106', + wave64=wave64, tail=(END,)) + # A single symbolic half keeps the diagnostic independent of operand evaluation order. + cndmask_input = (*parked, mov(VCC_HI, ZERO)) if wave64 else parked + reject(cli, sdk, work, f'cndmask{width}', cndmask_input, (CNDMASK,), 'unbound numeric SGPR s106', + wave64=wave64) + reject(cli, sdk, work, f'exec{width}', parked, (mov(EXEC, VCC_LO, pair=True),), + 'descriptor used as mask', wave64=wave64) + reject(cli, sdk, work, f'm0{width}', parked, (mov(M0, VCC_HI),), + 'descriptor used as mask', wave64=wave64) + reject(cli, sdk, work, f'no-restore{width}', (*parked, CLEAR, *STORE[:2]), STORE[2:], + 'non-contiguous resource descriptor', wave64=wave64) + + for name, clobber in (('compare', VOPC), ('carry', CARRY)): + overwritten = (*parked, *clobber) + accept(cli, sdk, work, f'{name}-vccz{width}', (*overwritten, VCCZ, END), wave64=wave64) + if not wave64: + reject(cli, sdk, work, f'{name}-hi{width}', overwritten, (mov(M0, VCC_HI),), + 'descriptor used as mask', wave64=False) + + # Move a mixed pair (numeric low, descriptor high), and restore the + # high descriptor through another mixed pair without touching s18. + mixed = (*SETUP, *LOAD, mov(22, ZERO), mov(23, 19), mov(VCC_LO, 22, pair=True), + mov(19, ZERO), mov(22, VCC_LO, pair=True), mov(19, 23), *STORE) + store_call(sdk, accept(cli, sdk, work, 'mixed', mixed, wave64=True)) + high_only = (*SETUP, *LOAD, mov(VCC_LO, ZERO), mov(VCC_HI, 19)) + reject(cli, sdk, work, 'vccz-high64', high_only, (VCCZ,), 'unbound numeric SGPR s107', + wave64=True, tail=(END,)) + reject(cli, sdk, work, 'cndmask-high64', high_only, (CNDMASK,), 'unbound numeric SGPR s107', + wave64=True) + print('VCC descriptor copies, raw UAV store and numeric-use refusals matched') + + +def hardware(cli, sdk, work, renderer, adapter): + wave = render(renderer, adapter, '--shader-wave32') + assert wave.returncode == 0, (wave.stdout, wave.stderr) + case = work / 'store.bin' + for width in (32, 64): + case.write_bytes(words(1, *([7] * width), *([0xc5c5c5c5] * (320 - width)))) + for name, code in (('pair', PAIR_COPY), ('word', WORD_COPY)): + shader = accept(cli, sdk, work, f'{name}{width}', code, wave64=width == 64) + result = render(renderer, adapter, '--compute-store-sized-case', shader, case) + assert result.returncode == 0, (name, width, result.stdout, result.stderr) + assert 'groups=1 compared_words=320 mismatches=0' in result.stdout, result.stdout + print(f'{name} wave{width}: 320 output and guard words matched') + + +if __name__ == '__main__': + mode, cli, sdk, *args = sys.argv[1:] + with tempfile.TemporaryDirectory() as temp: + {'controls': controls, 'hardware': hardware}[mode](cli, sdk, Path(temp), *args) From 95414551b56ffe09c19fc35ba666927f2efdc6a9 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sat, 28 Nov 2026 21:12:33 +0100 Subject: [PATCH 2/2] compute: carry symbolic descriptor words through VCC in wave64 SMEM loads and lane spills A wave64 table or heap-offset descriptor load may end at s106/s107, and the program then spills the descriptor with v_writelane_b32 (vcc_lo/vcc_hi included) and reloads it with v_readlane_b32. Both refused before: "symbolic scalar memory destination overlaps wave64 VCC" for the load, then "unbound numeric SGPR s106" for the spill. With the scalar-temporary VCC model of the previous commit, the load writes the descriptor symbols into s106/s107, the spill and reload carry them like other SGPRs, and a reload into M0, EXEC or above is still refused. A later read of VCC as a mask still refuses with the existing reason. --- src/gfx1013_compute_native.cpp | 2 +- src/gfx1013_direct_compute.inl | 10 +--- tests/cmake/native_vcc_descriptor_copy.cmake | 5 ++ tests/native_direct_container_check.py | 5 +- tests/native_heap_offset_add_check.py | 6 +-- tests/native_vcc_descriptor_copy_check.py | 54 +++++++++++++++++++- 6 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/gfx1013_compute_native.cpp b/src/gfx1013_compute_native.cpp index 202e43b4e5..7fc06d27e0 100644 --- a/src/gfx1013_compute_native.cpp +++ b/src/gfx1013_compute_native.cpp @@ -672,7 +672,7 @@ State transfer(const Inst &i, State s, bool wave64, bool graphics, bool heap_win if (auto lane = guest_spill_lane(i, wave64)) { const auto key = std::make_pair(i.dst, *lane); const auto value = source(i, i.src[0], s); - if (i.src[0] <= 105 && identity_spill(value)) + if (i.src[0] <= 107 && identity_spill(value)) s.lane_spills[key] = value; else s.lane_spills.erase(key); diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index c8e5bb7131..35f4cbc685 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -632,12 +632,6 @@ struct DirectCompute { return; } const bool root = low.type == Symbol::Type::root_address; - // Table and heap-offset descriptor lowering track identities and slot indices instead of - // loading payload bits. - if (wave64 && !graphics_input && i.op < 8 && - (low.type == Symbol::Type::table || low.type == Symbol::Type::heap_offset) && - i.dst + memory_count(i) > 106) - refuse(i.pc, "symbolic scalar memory destination overlaps wave64 VCC"); if (low.type == Symbol::Type::heap_offset) { // A resource-heap address formed by s_add_u32 (heap_offset_add): the same slot read as the SGPR-offset // load below, with the byte offset in the low word. @@ -3465,12 +3459,12 @@ struct DirectCompute { if (slot != state.lane_spills.end()) { if (!slot->second) refuse(i.pc, "symbolic VGPR lane read has conflicting incoming values"); - if (i.dst > 105) + if (i.dst > 107) // s106/s107 (VCC) hold scalar data here; M0, EXEC and above do not refuse(i.pc, "symbolic VGPR lane read needs an ordinary SGPR destination"); return; // Transfer associated the destination SGPR with this identity. } } - if (!reading && i.src[0] <= 105 && identity_spill(state[i.src[0]])) { + if (!reading && i.src[0] <= 107 && identity_spill(state[i.src[0]])) { if (!guest) refuse(i.pc, "symbolic VGPR lane write needs a constant lane"); return; diff --git a/tests/cmake/native_vcc_descriptor_copy.cmake b/tests/cmake/native_vcc_descriptor_copy.cmake index 3d0598deeb..3d8a7f27a7 100644 --- a/tests/cmake/native_vcc_descriptor_copy.cmake +++ b/tests/cmake/native_vcc_descriptor_copy.cmake @@ -4,6 +4,11 @@ if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND EXISTS "${DXC_BIN_DIR}/ add_test(NAME native_vcc_descriptor_copy_controls COMMAND "${INTAKE_PYTHON}" -B "${checker}" controls "$" "${DXC_BIN_DIR}") set_tests_properties(native_vcc_descriptor_copy_controls PROPERTIES TIMEOUT 120) + foreach(case IN ITEMS smem_store smem_mask smem_range spill_image spill_mask) + add_test(NAME native_vcc_descriptor_copy_${case} COMMAND "${INTAKE_PYTHON}" -B + "${checker}" ${case} "$" "${DXC_BIN_DIR}") + set_tests_properties(native_vcc_descriptor_copy_${case} PROPERTIES TIMEOUT 120) + endforeach() if(TARGET offscreen_check) foreach(adapter IN ITEMS warp hardware) add_test(NAME native_vcc_descriptor_copy_${adapter} COMMAND "${INTAKE_PYTHON}" -B diff --git a/tests/native_direct_container_check.py b/tests/native_direct_container_check.py index 22b41cf886..0ed09041b6 100644 --- a/tests/native_direct_container_check.py +++ b/tests/native_direct_container_check.py @@ -548,9 +548,8 @@ def atomic_program(instructions): check("address-vs", "gfx1013-container-vs", root_vs) check("address-cs", cs, compute(words(*root_load, end), root_descriptor=True)) check("wave64-smem-symbolic-vcc-dst", cs, - compute(words(0xbe810380, 0xf4080000 | 104 << 6, 125 << 25, end), - threads=64, table=True, wave32=False), - "symbolic scalar memory destination overlaps wave64 VCC") + compute(words(0xbe810380, 0xf40c0000 | 100 << 6, 125 << 25, end), + threads=64, table=True, wave32=False)) check("wave32-smem-cross-vcc", cs, compute(words(0xf40c0000 | 104 << 6, 125 << 25, end), root_descriptor=True), "unsupported scalar memory destination range") diff --git a/tests/native_heap_offset_add_check.py b/tests/native_heap_offset_add_check.py index 4d5f8978b2..2b9fb69873 100644 --- a/tests/native_heap_offset_add_check.py +++ b/tests/native_heap_offset_add_check.py @@ -40,10 +40,8 @@ "scc_clobbered": (SELECT + [ADD_LO, 0xBF070808, ADD_HI] + LOAD + END, HIGH_WORD), # s_add_u32 s10, s5, 0x40: a constant offset is not a GPU selection; the heap table is used as a number "constant": (SELECT + [0x800AFF05, 0x40, ADD_HI] + LOAD + END, "unbound numeric SGPR s5"), - # Wave64, s_load_dwordx4 s[104:107], s[10:11], 0x0: the slot index would be written into VCC, which the wave64 - # model keeps as mask data, so the overlap refusal comes before the heap contract. - "wave64_vcc_dst": (SELECT + [ADD_LO, ADD_HI, 0xF4081A05, 0xFA000000] + END, - "symbolic scalar memory destination overlaps wave64 VCC", 64), + # Wave64, s_load_dwordx4 s[104:107], s[10:11], 0x0 also reaches the heap contract check. + "wave64_vcc_dst": (SELECT + [ADD_LO, ADD_HI, 0xF4081A05, 0xFA000000] + END, HEAP_CONTRACT, 64), } diff --git a/tests/native_vcc_descriptor_copy_check.py b/tests/native_vcc_descriptor_copy_check.py index 613d2f4d75..fca39da5dd 100644 --- a/tests/native_vcc_descriptor_copy_check.py +++ b/tests/native_vcc_descriptor_copy_check.py @@ -1,4 +1,4 @@ -"""Check source-built descriptor moves through VCC in direct compute.""" +"""Check source-built descriptor moves, scalar loads and lane spills through VCC.""" from pathlib import Path import re import subprocess @@ -7,6 +7,7 @@ from native_direct_container_check import compute, words from native_image_atomic_check import render +from native_lane_access_check import readlane, writelane def mov(dst, src, *, pair=False): @@ -16,9 +17,11 @@ def mov(dst, src, *, pair=False): VCC_LO, VCC_HI, EXEC, M0, ZERO = 106, 107, 126, 124, 128 END = 0xbf810000 VCCZ = 0xbf860001 # Target skips the fallthrough s_endpgm. +VCCNZ = 0xbf870001 WAIT = 0xbf8cc07f SETUP = (mov(1, ZERO), mov(4, 0, pair=True)) LOAD = (0xf4080000 | 16 << 6 | 2, 125 << 25, WAIT) # s[16:19], s[4:5], 0 +LOAD_VCC = (0xf4080000 | 104 << 6 | 2, 125 << 25, WAIT) # s[104:107], s[4:5], 0 PARK = (mov(VCC_LO, 18, pair=True),) CLEAR = mov(18, ZERO, pair=True) STORE = ( @@ -35,6 +38,20 @@ def mov(dst, src, *, pair=False): WORD_COPY = (*SETUP, *LOAD, mov(VCC_LO, 18), mov(VCC_HI, 19), CLEAR, mov(18, VCC_LO), mov(19, VCC_HI), *STORE) +IMAGE_DESC = 100 +SPILL_VGPR = 78 +LOAD_IMAGE = (0xf40c0000 | IMAGE_DESC << 6 | 2, 125 << 25, WAIT) +SPILL_IMAGE = ( + *SETUP, *LOAD_IMAGE, + *(word for lane in range(8) for word in writelane(SPILL_VGPR, IMAGE_DESC + lane, 128 + lane)), + *(mov(reg, ZERO, pair=True) for reg in range(IMAGE_DESC, VCC_HI, 2)), + *(word for lane in range(8) for word in readlane(IMAGE_DESC + lane, SPILL_VGPR, 128 + lane)), +) +IMAGE_STORE = ( + *(0x7e000200 | reg << 17 | ZERO for reg in (0, 1, 4, 5, 6, 7)), + 0xf0200f08, (IMAGE_DESC // 4) << 16 | 4 << 8, # image_store v[4:7], v[0:1], s[100:107], dim:2D +) + def compile_shader(cli, sdk, work, name, code, *, wave64): source = work / f'{name}.cdx' @@ -114,6 +131,36 @@ def controls(cli, sdk, work): print('VCC descriptor copies, raw UAV store and numeric-use refusals matched') +def smem_store(cli, sdk, work): + # Change the SRSRC field to s[104:107] and use the loaded descriptor directly. + store = (*STORE[:3], STORE[3] & ~(31 << 16) | (104 // 4) << 16) + shader = accept(cli, sdk, work, 'smem-store', (*SETUP, *LOAD_VCC, *store), wave64=True) + store_call(sdk, shader) + + +def smem_mask(cli, sdk, work): + reject(cli, sdk, work, 'smem-mask', (*SETUP, *LOAD_VCC), (VCCNZ,), + 'unbound numeric SGPR s106', wave64=True, tail=(END,)) + + +def smem_range(cli, sdk, work): + # s_load_dwordx8 s[104:111], s[4:5], 0 + reject(cli, sdk, work, 'smem-range', SETUP, (0xf40c0000 | 104 << 6 | 2, 125 << 25, WAIT), + 'unsupported scalar memory destination range', wave64=True) + + +def spill_image(cli, sdk, work): + shader = accept(cli, sdk, work, 'spill-image', (*SPILL_IMAGE, *IMAGE_STORE), wave64=True) + dump = subprocess.run([Path(sdk) / 'dxc.exe', '-dumpbin', shader], + capture_output=True, text=True, timeout=30, check=True).stdout + assert 'call void @dx.op.textureStore.f32(' in dump, dump + + +def spill_mask(cli, sdk, work): + reject(cli, sdk, work, 'spill-mask', SPILL_IMAGE, (VCCNZ,), + 'unbound numeric SGPR s106', wave64=True, tail=(END,)) + + def hardware(cli, sdk, work, renderer, adapter): wave = render(renderer, adapter, '--shader-wave32') assert wave.returncode == 0, (wave.stdout, wave.stderr) @@ -131,4 +178,7 @@ def hardware(cli, sdk, work, renderer, adapter): if __name__ == '__main__': mode, cli, sdk, *args = sys.argv[1:] with tempfile.TemporaryDirectory() as temp: - {'controls': controls, 'hardware': hardware}[mode](cli, sdk, Path(temp), *args) + cases = {'controls': controls, 'hardware': hardware, + 'smem_store': smem_store, 'smem_mask': smem_mask, 'smem_range': smem_range, + 'spill_image': spill_image, 'spill_mask': spill_mask} + cases[mode](cli, sdk, Path(temp), *args)