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
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
(["tests/compute_store_check.py", *COMMON_LLVM], {}),
(["tests/compute_load_format_check.py", *COMMON_LLVM], {}),
(["tests/compute_heap_view_check.py", *COMMON_LLVM], {}),
(["tests/compute_heap_store_check.py", *COMMON_LLVM], {}),
(["tests/pixel_aot_check.py", *COMMON_LLVM], {}),
(["tests/sampled_coverage_check.py", *COMMON_LLVM], {}),
(["tests/pixel_compare_gather_check.py", "--binary", "llvm-mc-15", "llvm-objcopy-15", "libLLVM-15.so.1"], {}),
Expand Down Expand Up @@ -255,6 +256,7 @@ jobs:
tests/compute_alu_bcnt64_check.py \
tests/compute_load_format_check.py \
tests/compute_heap_view_check.py \
tests/compute_heap_store_check.py \
tests/startup_ngg_slice_check.py \
tests/startup_gfx2hlsl_handler_arity_check.py \
tests/run_checks_parallel_check.py
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ python3 -m venv out/pe-env
./out/pe-env/bin/python -B tests/compute_alu_bcnt64_check.py
./out/pe-env/bin/python -B tests/compute_load_format_check.py
./out/pe-env/bin/python -B tests/compute_heap_view_check.py
./out/pe-env/bin/python -B tests/compute_heap_store_check.py
./out/pe-env/bin/python -B tests/startup_ngg_slice_check.py
./out/pe-env/bin/python -B tests/mesh_dynamic_aot_check.py
./out/pe-env/bin/python -B tests/mesh_lane_spill_check.py
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,8 @@ if(EXISTS "${INTAKE_PYTHON}")
# Compute translator: buffer_load_format with the V# taken from a run-time heap view record.
add_test(NAME compute_heap_view_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/compute_heap_view_check.py" controls)
add_test(NAME compute_heap_store_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/compute_heap_store_check.py" controls)
# Startup shader translator: signed and unsigned three-source integer min, max and median.
add_test(NAME startup_gfx2hlsl_int_med3_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_int_med3_check.py")
Expand Down Expand Up @@ -7565,6 +7567,11 @@ if(EXISTS "${INTAKE_PYTHON}")
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(compute_store_aot_heap_view_load_${adapter} PROPERTIES TIMEOUT 180
SKIP_RETURN_CODE 77)
add_test(NAME compute_store_aot_heap_view_store_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/compute_heap_store_check.py" draw "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(compute_store_aot_heap_view_store_${adapter} PROPERTIES TIMEOUT 120
SKIP_RETURN_CODE 77)
add_test(NAME compute_store_aot_mtbuf_store_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/compute_store_check.py" draw-mtbuf-store "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
Expand Down
8 changes: 8 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -5155,6 +5155,14 @@ ctest --preset dev --no-tests=error -R '^compute_(store_aot_descriptor_load_form
python3 -B tests/compute_load_format_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
```

### Heap-view UINT4 buffer stores

The gfx1013 compute fixture translates one indexed `buffer_store_format_xyzw` that writes four raw 32-bit components to a fixed u0. `--heap-store-view SLOT_WORD TABLE_OFFSET COUNT TABLE_BUFFER_BYTES OUTPUT_BYTES` selects a 32-byte record in the [t0 view table](#heap-view-buffer-loads) using a word already loaded from b0. The caller supplies the table extent and writable u0 extent separately. The D3D12 root UAV used by the fixture carries a GPU address with no size limit. [Direct3D 12 root signatures](https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signatures-overview)

The view must be live and describe format 75 (`BUF_FMT_32_32_32_32_UINT`) with identity channel selectors. The store uses the view base, stride, dispatch thread index and instruction byte offset. Only a complete aligned texel within the record count, stride and declared u0 extent is written. The fixture models view selection within one bound buffer. [LLVM format table](https://releases.llvm.org/15.0.0/docs/AMDGPUModifierSyntax.html#ufmt) · [AMD RDNA 2 shader ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf)

Run `ctest --preset dev -R '^compute_(heap_store_controls|store_aot_heap_view_store_(warp|hardware))$' --output-on-failure`. The fixture checks all 320 readback words across twelve cases. These include distinct live ranges, one texel ending exactly at the u0 limit, and a partial texel that must leave the sentinel intact. Eight mutations exercise the base, stride, record count, format, lifetime, output extent and slot limit. Removing the per-index extent check lets the next thread write past the last complete texel.

### Heap-view buffer loads

The gfx1013 compute store profile can now take the t0 V# of a `buffer_load_format_x/xy/xyz/xyzw` from a run-time view record instead of a static descriptor. `--heap-view SLOT_WORD TABLE_OFFSET COUNT BUFFER_BYTES` selects it. It is slice 2 of item A of #2022 and builds on the format decoder of [descriptor-format buffer loads](#descriptor-format-buffer-loads). It excludes `--load-format-constant`: the format now comes from the record.
Expand Down
142 changes: 142 additions & 0 deletions tests/compute_heap_store_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"""A gfx1013 formatted store selects the byte range of a fixed u0 through a run-time view record."""
from pathlib import Path
import struct
import subprocess
import sys
import tempfile

import compute_store_check as base


GROUP = (4, 1, 1)
WORDS = 320
TABLE_BYTE = 256
UINT4 = 0x0104BFAC # gfx10 format 75, identity XYZW selectors and RESOURCE_LEVEL set
FLOAT4 = 0x0104DFAC
STORE = "buffer_store_format_xyzw v[10:13], v8, s[20:23], 0 idxen offset:4"
PROGRAM = [
"s_mov_b32 s12, s7", "s_mov_b32 s13, 0", "s_load_dwordx4 s[20:23], s[12:13], 0x30",
"s_load_dwordx4 s[16:19], s[12:13], 0x40", "v_lshl_add_u32 v8, s11, 2, v0",
"s_waitcnt lgkmcnt(0)", "s_buffer_load_dwordx4 s[24:27], s[16:19], null", "s_waitcnt lgkmcnt(0)",
"v_mov_b32_e32 v10, v8", "v_mov_b32_e32 v11, 0x12345678", "v_mov_b32_e32 v12, 0x80000001",
"v_mov_b32_e32 v13, 0x3f800001", STORE, "s_endpgm",
]
# V# words 0..3 and live state, then the expected *word addresses* of the four component stores.
# The addresses are literal to keep the reference independent of the generated address calculation.
CASES = (
("four records", (12, 24 << 16, 4, UINT4, 1), (4, 10, 16, 22)),
("second base and short record count", (116, 32 << 16, 2, UINT4, 1), (30, 38)),
("released view", (12, 24 << 16, 4, UINT4, 2), ()),
("last complete texel in u0", (492, 20 << 16, 4, UINT4, 1), (124,)),
("partial texel at end of u0", (496, 20 << 16, 4, UINT4, 1), ()),
("wrong four-channel format", (12, 24 << 16, 4, FLOAT4, 1), ()),
("offset plus texel wider than stride", (12, 16 << 16, 4, UINT4, 1), ()),
("misaligned base", (14, 24 << 16, 4, UINT4, 1), ()),
("misaligned stride", (12, 22 << 16, 4, UINT4, 1), ()),
("unsupported high address", (12, (24 << 16) | 1, 4, UINT4, 1), ()),
("base past the declared u0 extent", (640, 24 << 16, 4, UINT4, 1), ()),
("live slot beyond declared count", (12, 24 << 16, 4, UINT4, 1), ()),
)
VIEW = (0, TABLE_BYTE, len(CASES) - 1, WORDS * 4, 512)
BINDING = dict(table_reg=7, descriptor_offset=0x30, constant_descriptor=0x40, source_descriptor=0x50, group_reg=11)


def lower(program=PROGRAM, **options):
return base.aot.lower(program, GROUP, **(BINDING | dict(heap_store_view=VIEW) | options))


def controls():
assert base.aot.descriptor_format_word(75) == UINT4
# Pin the translator call here. draw() exercises the generated guards against actual UAV contents.
assert "store_heap_uint4(params[0].x, tid.x, 4u, uint4(tid.x," in lower()
refuses = base.rejects
refuses("Unsupported formatted buffer store target or address mode", lower, heap_store_view=None)
refuses("Invalid heap store view binding", lower, stride=24)
refuses("Invalid heap store view binding", lower, heap_view=VIEW)
refuses("Invalid heap view binding", lower, source_descriptor=None)
refuses("Invalid heap view binding", lower, heap_store_view=(0, TABLE_BYTE, 11, TABLE_BYTE + 32, 512))
refuses("Invalid heap store view output size", lower, heap_store_view=(*VIEW[:4], 511))
refuses("Heap store view requires exactly one formatted UAV store", lower,
PROGRAM[:-1] + [STORE.replace("offset:4", "offset:24"), "s_endpgm"])
refuses("Heap store view slot constant is not ready", lower, PROGRAM[:7] + PROGRAM[8:])
refuses("Heap store view requires buffer_store_format_xyzw", lower,
base.variant(PROGRAM, (STORE, STORE.replace("xyzw v[10:13]", "xy v[10:11]"))))
refuses("Unsupported formatted buffer store target or address mode", lower,
base.variant(PROGRAM, (STORE, STORE.replace(" idxen", " offen"))))
refuses("Unverified raw UAV store", lower, base.variant(PROGRAM, (STORE, STORE.replace("s[20:23]", "s[16:19]"))))
refuses("Heap store view needs a formatted store indexed by dispatch thread ID", lower,
base.variant(PROGRAM, (STORE, STORE.replace(", v8,", ", v12,"))))


def verify_binary(directory, code, library):
decoded = base.aot.labelled(base.disassemble(code, library, offsets=True, cpu=b"gfx1013"))
assert lower(decoded) == lower()
container, output = directory / "store.dxbc", directory / "store.hlsl"
container.write_bytes(base.store_container(code, GROUP))
subprocess.run([sys.executable, "-B", base.aot.__file__, container, "--output", output, "--llvm", library,
*base.binding_cli(BINDING), "--heap-store-view", *map(str, VIEW)], check=True)
assert output.read_text(encoding="ascii") == lower()


def draw(directory, compiler, renderer, backend):
source = lower()
table = [0] * WORDS
for slot, (_, record, _) in enumerate(CASES):
start = TABLE_BYTE // 4 + slot * 8
table[start:start + 5] = record
hlsl, cso = directory / "store.hlsl", directory / "store.cso"

def compile_shader(text):
hlsl.write_text(text, encoding="ascii")
subprocess.run([compiler, "-T", "cs_6_0", "-E", "main", "-Fo", cso, hlsl], check=True)

def run(slot):
result = [base.SENTINEL] * WORDS
for thread, start in enumerate(CASES[slot][2]):
result[start:start + 4] = [thread, 0x12345678, 0x80000001, 0x3F800001]
case = directory / "store.case"
case.write_bytes(struct.pack("<321I", 1, *result) + struct.pack("<16I", slot, *([0] * 15))
+ struct.pack("<320I", *table))
return subprocess.run([renderer, backend, "--compute-store-case", cso, case], capture_output=True, text=True)

compile_shader(source)
for slot, (label, _, _) in enumerate(CASES):
result = run(slot)
if result.returncode == 77 and backend == "hardware":
return 77
assert result.returncode == 0, (label, result.stderr)
mutations = (
("view.x + index * stride + offset", "index * stride + offset", 0),
(" || index >= view.z", "", 1),
("uint stride = view.y >> 16u;", "uint stride = 24u;", 1),
("const uint bytes = 512u;", "const uint bytes = 1280u;", 4),
("if (index > (bytes - view.x - offset - 16u) / stride) return;", "", 3),
(f"view.w != {UINT4:#x}u || ", "", 5),
("!= 1u) return;", "== 0u) return;", 2),
(f"slot >= {VIEW[2]}u", f"slot > {VIEW[2]}u", VIEW[2]),
)
for old, new, slot in mutations:
assert source.count(old) == 1, old
compile_shader(source.replace(old, new))
result = run(slot)
assert result.returncode == 1 and "Compute readback differs" in result.stderr, (old, result.stderr)
print(f"{backend}: {len(CASES)} heap-store cases and {len(mutations)} shader mutations checked")
return 0


if __name__ == "__main__":
controls()
mode, *args = sys.argv[1:] or ["controls"]
if mode == "controls" and not args:
print("heap-store controls passed")
elif mode in ("binary", "draw") and len(args) == 3:
with tempfile.TemporaryDirectory() as tmp:
directory = Path(tmp)
if mode == "draw":
sys.exit(draw(directory, *args))
assembler, objcopy, library = args
code = base.assemble(directory, assembler, objcopy, PROGRAM, cpu="gfx1013")
verify_binary(directory, code, library)
else:
sys.exit("usage: compute_heap_store_check.py controls | binary <llvm-mc> <llvm-objcopy> <libLLVM> "
"| draw <dxc> <offscreen_check> <backend>")
Loading
Loading