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
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ jobs:
tests/startup_gfx2hlsl_bit_alu_check.py \
tests/startup_gfx2hlsl_mad_check.py \
tests/startup_gfx2hlsl_compute_check.py \
tests/startup_compute_translate_check.py \
tests/startup_gfx2hlsl_swap_check.py \
tests/startup_gfx2hlsl_shift64_check.py \
tests/startup_gfx2hlsl_vopc_sdwa_check.py \
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ python3 -m venv out/pe-env
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_operand_count_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_mad_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_compute_check.py
./out/pe-env/bin/python -B tests/startup_compute_translate_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_swap_check.py
./out/pe-env/bin/python -B tests/startup_image_2d_array_check.py
./out/pe-env/bin/python -B tests/startup_image_sample_a16_check.py
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,22 @@ if(EXISTS "${INTAKE_PYTHON}")
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_request_check.py" "$<TARGET_FILE:startup_stream_consumer>" disabled)
set_tests_properties(startup_compute_request_warp startup_compute_request_disabled_control PROPERTIES TIMEOUT 60)
set_tests_properties(startup_compute_request_disabled_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: no compute request")
# Slot 67 request translation: request checks, then stand-in request -> --pending -> DXC -> dispatch; the
# wrong-group control must mismatch.
add_test(NAME startup_compute_translate_requests COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_translate_check.py")
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_compute_translate_e2e_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_translate_check.py" e2e "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" "$<TARGET_FILE:offscreen_check>" ${adapter})
add_test(NAME startup_compute_translate_e2e_wrong_group_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_translate_check.py" e2e "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" "$<TARGET_FILE:offscreen_check>" ${adapter} wrong-group)
set_tests_properties(startup_compute_translate_e2e_${adapter} startup_compute_translate_e2e_wrong_group_${adapter}
PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
set_tests_properties(startup_compute_translate_e2e_wrong_group_${adapter} PROPERTIES
PASS_REGULAR_EXPRESSION "control wrong-group: rejected at word=[0-9]+ ")
endforeach()
foreach(backend IN ITEMS warp hardware)
add_test(NAME startup_stream_draw_${backend} COMMAND "${CMAKE_COMMAND}" -E env "X2W_FXC=${STARTUP_FXC}"
"${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_stream_draw_check.py"
Expand Down
61 changes: 57 additions & 4 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,10 @@ costs no file access, and the writes take their own lock, not the draw lock.
`not written`, with the reason when refused, up to 12 lines per run. The render totals line ends with
`compute requests published <n> (already present <n>, failed <n>, pointer-like blob qwords <n>)`.

**Offline.** `gfx2hlsl.py --pending` and `--watch` take `.c67` as a ready marker. With no compute stage yet,
they record `compute stage not supported` in `<key>.fail`. The request stays in the cache, and a later
`--pending` retries it. `--refusals` reports compute requests in a separate section, so its graphics counts
do not change, and `triage_run.py` puts their `.fail` reasons in a `compute:` class.
**Offline.** `gfx2hlsl.py --pending` and `--watch` take `.c67` as a ready marker and translate the request
(see [Compute pipeline translation](#compute-pipeline-translation)). A refused request stays in the cache, and
a later `--pending` retries it. `--refusals` reports compute requests in a separate section, so its graphics
counts do not change, and `triage_run.py` puts their `.fail` reasons in a `compute:` class.

**Local observation** (a local build of this change ported to an older base; one title, local files only, not
in the repository):
Expand All @@ -667,6 +667,59 @@ after building `startup_stream_consumer`. On WARP:
- A request whose first four parts already exist is completed without rewriting them.
- The control runs without render mode and must print `FAIL: no compute request`.

### Compute pipeline translation

`gfx2hlsl.py --pending` and `--watch` translate a `.c67` request with the compute stage instead of recording
`compute stage not supported`. The request is checked first, and it is refused into `<key>.fail` (with no
cache path in the text) when:
- a part is missing;
- `.desc` is not 96 bytes;
- a part's length disagrees with its size word in `.desc` (code word 6, data word 8, state blocks words 2 and 4);
- the files do not hash to the key in their name;
- the code is empty, is not whole dwords, or has no `s_endpgm`.

The translation is `ComputePipeline(code, root, COMPUTE_PGM_RSRC2, group size)`. Both register values come
from state block A, which must be 28 bytes. The stage writes `<key>.cs.hlsl`, then `<key>.cs.cso` (DXC
`cs_6_0`), then the `stage cs` manifest `<key>.txt` last; a stage refusal goes to `<key>.fail` with the
stage's own reason. A request is done once `<key>.txt` and `<key>.cs.cso` exist. `X2W_FXC=` (empty)
publishes the manifest alone, as for graphics. `<key>.cs.cso` has the same form as the slot 62 results of
#1441 in the same directory. The keys come from different hashes, so the names clash only on a 64-bit
collision. The stand-in does not load the result yet and still creates a placeholder.

The state-block reading is a **hypothesis** from a local observation of 2,689 requests (an earlier local build
of the request change; one title, local files only):
- dword 3 holds the thread-group size X in its low 16 bits and Y in its high 16 bits, and the low 16 bits of
dword 4 hold Z. All 2,689 sizes are within the `numthreads` limits, with 43 distinct sizes.
- dword 6 has the `COMPUTE_PGM_RSRC2` layout. Bits 31:24 are zero, and the thread-ID component count never
exceeds what the group size needs; it covers a Y size above 1 in 2,671 of 2,689. `TG_SIZE_EN` is set in 91,
which the stage refuses.

The stand-in does not decode these values.

Census: one title, local files only.
- Requests: 2,689, published by a local build of the request change that was ported to an older base.
- Re-keying: the requests were re-keyed offline with this `compute_key`. The files are unchanged; only their
names change.
- Result: 8 of 2,689 translate and compile, and `--pending` took 11 s. No request is refused by the request
checks above.
- First refusal per request:
- `buffer_load_format` from the descriptor format: 1,280;
- scalar writes under `s_cbranch_execz`: 541;
- `s_load` with a register offset through the resource heap: 158;
- `image_store`: 110;
- `TG_SIZE_EN`: 91.

Run `python -B tests/startup_compute_translate_check.py` (ctest `startup_compute_translate_requests`, pure
Python) to check the refusals above and the case A manifest. `startup_compute_translate_e2e_<warp|hardware>`
goes end to end on the GPU:
1. the stand-in publishes case A of `startup_gfx2hlsl_compute_check.py`;
2. `--pending` translates it and DXC compiles it;
3. `offscreen_check` dispatches `<key>.cs.cso` and compares all 320 words.

Its `wrong_group` control swaps the group size in the state block and must mismatch. This proves that the
request, translation, bytecode and dispatch fit together. It does not prove the state-block reading, because
the fixture builds the block at the offsets the translator reads.

`run.ps1` prints the first five lines of `<log>.out` and exits with the debugger's exit code: 2 when
the process could not be created, 0 when the debugger finished its report, whatever the process
did. Check with `python3 -B tests/startup_run_ps1_check.py` (ctest `startup_run_ps1`): on Windows it
Expand Down
10 changes: 5 additions & 5 deletions tests/startup_compute_request_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
their limits publish; valid -> refused -> valid publishes exactly the two valid keys;
- parts left by an interrupted earlier write (no .c67) are kept and the next creation completes the request;
- a data qword that names committed memory is counted and still published;
- gfx2hlsl.py --pending records "compute stage not supported" in <key>.fail, and --refusals reports compute
- gfx2hlsl.py --pending records the compute stage's refusal of the 24-byte state block A in <key>.fail, and --refusals reports compute
requests in their own section.
"disabled" is the negative control: without X2W_D3D12_RENDER=1 nothing is published, and the check must print
"FAIL: no compute request".
Expand Down Expand Up @@ -168,19 +168,19 @@ def check(directory, consumer, disabled):

out = subprocess.run([sys.executable, "-B", gfx2hlsl.__file__, "--pending", cache], check=True,
capture_output=True, text=True).stdout
assert f"{key:016x}: unsupported: compute stage not supported" in out, out
assert (cache / ("%016x.fail" % key)).read_text() == "compute stage not supported\n"
assert f"{key:016x}: unsupported: compute state block A is 24 bytes, not 28" in out, out
assert (cache / ("%016x.fail" % key)).read_text() == "compute state block A is 24 bytes, not 28\n"
assert not (cache / ("%016x.txt" % key)).exists()
assert all((cache / file).read_bytes() == data for file, data in files.items()), "the offline pass changed the request"
report = gfx2hlsl.refusals_report(cache)
assert report["per_request"]["examined"] == 0, report["per_request"]
assert report["compute"] == dict(examined=3, no_refusal=0, reasons=[
dict(reason="compute stage not supported", containing=3, first=3)]), report["compute"]
dict(reason="compute state block A is 24 bytes, not 28", containing=3, first=3)]), report["compute"]

check_boundaries(directory, consumer)
print(f"startup_compute_request: PASS on WARP (request {key:016x}: exact files, length-framed runtime key, "
"published once across two creations and two processes, refusals and limits, interrupted write completed, "
"offline 'compute stage not supported' recorded)")
"offline refusal recorded)")
return 0


Expand Down
9 changes: 5 additions & 4 deletions tests/startup_compute_request_offline_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
each part preceded by its u64 length, in the order code, data, root, desc, state A, state B) and a literal.
- A cache directory with one synthetic request (req_<key>.{desc,sa,sb,data,root,c67}) is found by
request_keys(compute=True) and pending_keys, but not by the graphics request_keys; gfx2hlsl.py --pending
records "compute stage not supported" in <key>.fail and writes no manifest; --refusals --json reports it in
records the compute stage's refusal of its 24-byte state block A in <key>.fail and writes no manifest; --refusals --json reports it in
the compute section only.
"""
import json
Expand All @@ -18,6 +18,7 @@
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools' / 'startup'))
import gfx2hlsl as G # noqa: E402

REASON = 'compute state block A is 24 bytes, not 28' # the compute stage refuses the synthetic block
CODE = struct.pack('<2I', 0x7e020280, 0xbf810000)
DATA = struct.pack('<2Q', 0xfedcba9876543210, 0xffff00001111008c)
ROOT = b'RTS0 synthetic root'
Expand Down Expand Up @@ -51,14 +52,14 @@ def main():
assert G.pending_keys(str(cache), skip_failed=False) == [key]
out = subprocess.run([sys.executable, '-B', G.__file__, '--pending', str(cache)], check=True,
capture_output=True, text=True, env=dict(os.environ, X2W_TRANSLATE_JOBS='1')).stdout
assert out == '%016x: unsupported: compute stage not supported\n' % key, out
assert (cache / ('%016x.fail' % key)).read_text() == 'compute stage not supported\n'
assert out == '%016x: unsupported: %s\n' % (key, REASON), out
assert (cache / ('%016x.fail' % key)).read_text() == REASON + '\n'
assert not (cache / ('%016x.txt' % key)).exists()
report = json.loads(subprocess.run([sys.executable, '-B', G.__file__, '--refusals', str(cache), '--json'],
check=True, capture_output=True, text=True).stdout)
assert report['per_request']['examined'] == 0, report['per_request']
assert report['compute'] == dict(examined=1, no_refusal=0, reasons=[
dict(reason='compute stage not supported', containing=1, first=1)]), report['compute']
dict(reason=REASON, containing=1, first=1)]), report['compute']
print('compute request offline: key vector, request_keys/pending_keys, --pending record and --refusals '
'compute section pass')

Expand Down
Loading
Loading