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 @@ -105,6 +105,7 @@ jobs:
(["tests/startup_gfx2hlsl_mad_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_gfx2hlsl_compute_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_gfx2hlsl_calculated_target_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_gfx2hlsl_join_symbols_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_gfx2hlsl_swap_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_gfx2hlsl_shift64_check.py", "binary", "llvm-mc-15"], {}),
(["tests/startup_gfx2hlsl_vopc_sdwa_check.py", "binary", "llvm-mc-15"], {}),
Expand Down Expand Up @@ -222,6 +223,7 @@ jobs:
tests/startup_gfx2hlsl_scalar_m0_check.py \
tests/startup_gfx2hlsl_readfirstlane_uniform_check.py \
tests/startup_gfx2hlsl_loop_constants_check.py \
tests/startup_gfx2hlsl_join_symbols_check.py \
tests/startup_gfx2hlsl_readfirstlane_recompute_check.py \
tests/startup_gfx2hlsl_calculated_target_check.py \
tests/startup_triage_run_check.py \
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ python3 -m venv out/pe-env
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_scalar_m0_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_loop_constants_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_join_symbols_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_sop2_complement_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_sdwa_cvt_check.py
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,20 @@ if(EXISTS "${INTAKE_PYTHON}")
# Startup shader translator: scalar constants are dropped at a branch join that another path writes (loop counters).
add_test(NAME startup_gfx2hlsl_loop_constants COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_loop_constants_check.py")
# Startup shader translator: symbols that are not constants (descriptors, pointers, pairs) at a branch join.
add_test(NAME startup_gfx2hlsl_join_symbols_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_join_symbols_check.py")
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_gfx2hlsl_join_symbols_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_join_symbols_check.py" dispatch "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
add_test(NAME startup_gfx2hlsl_join_symbols_folded_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_join_symbols_check.py" control "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_gfx2hlsl_join_symbols_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
set_tests_properties(startup_gfx2hlsl_join_symbols_folded_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77
PASS_REGULAR_EXPRESSION "control OUTSIDE: 3 in all four channels")
endforeach()
# Startup shader translator: uniform sources of v_readfirstlane_b32 in straight-line code and entry blocks (#1723).
add_test(NAME startup_gfx2hlsl_readfirstlane_uniform COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_readfirstlane_uniform_check.py")
Expand Down
16 changes: 16 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -14067,3 +14067,19 @@ ctest --preset dev --no-tests=error -R '^(cpu_aot_switch_sal|cpu_aot_switch_shif
The [MASM fixture](../tests/cpu/switch_sal.asm) emits explicit `/6` byte sequences (because ML64 assembles the `sal` mnemonic as `/4` `SHL`) across 24 translated functions covering all 12 `SAL` `Code` encodings (`SAL_RM{8,16,32,64}_{1,CL,IMM8}`), register and memory destinations, count-`1` all-16 `SETcc` checks, count->1 10-condition `SETcc` checks, `Jcc`, `CMOVcc`, narrow returns, and nonvolatile/stack-frame operands, plus 11 negative exports. [The differential check](../tests/cpu/switch_sal_check.py) verifies 28,024 `dev` and 28,024 `/O2` comparisons against native execution and the Python reference, four `/O2` mutated-C++ controls (`shift_dir`, `cf_mask`, `of_mask`, `cl_mask`), 11 MASM, 4 unit, and 7 PE-patched rejection controls, and records decoded mnemonics via `iced_x86.Mnemonic` to `FORM_COVERAGE_RECORD`.

Not covered by this experiment: `SAL` outside leaf/switch-lifted functions, and title CPU code execution.

## Non-constant scalar symbols at branch targets in the startup translator

Follow-up to #2279, which drops scalar constants at a join that another path writes, over the textual range between
a branch and its target. Two cases remained wrong in the emitted HLSL:
- A symbol that is not a constant (a descriptor word, a pointer, a 64-bit pair, an unplaced compute user SGPR) was
kept across the join, so a descriptor reloaded on one path was bound for both, and a word overwritten on one path
was read as a register nothing assigned.
- A path that leaves a loop's textual range and comes back changes a constant the textual range does not cover.

The joined registers are now worked out over the basic blocks and their dominators (a proven `s_setpc_b64` is an
edge, and ends its block). A joined register keeps its symbol when every path into the target brings an equal symbol
that names one value (a pointer only if no add touched it), is read at run time when it holds a constant, and refuses a
read before its next write when a path brings a symbol with no run-time value or no definition at all. `startup_gfx2hlsl_join_symbols_check.py` pins the cases; the
`join_symbols_folded_*` tests run the old OUTSIDE statement and must give 3, not 11. Controls are pure Python plus
a pixel dispatch on WARP and hardware; `binary` reassembles the fixture words with LLVM 15.
4 changes: 2 additions & 2 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ The translation is refused when:
- either header has another size;
- the code reads an attribute the table does not list.

The shader cache revision is `x2w-startup-shader-10`. It also invalidates older translations that
could read a stale SCC after an operation on a descriptor word.
The shader cache revision is `x2w-startup-shader-11`. Older translations can carry a stale scalar
symbol across a join or read a stale SCC after an operation on a descriptor word.

The record layouts were checked offline against the signatures of one title's shader archive (local files only, not
in the repository). The counts below apply the translator's own record checks.
Expand Down
4 changes: 2 additions & 2 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Translation* cached_translation(const void* a, std::size_t a_bytes, const void*
{
// Keep pre-fix desktop bytecode and manifests out of this ABI's cache.
// tools/startup/gfx2hlsl.py hashes the same bytes, without a trailing NUL.
constexpr char revision[] = "x2w-startup-shader-10";
constexpr char revision[] = "x2w-startup-shader-11";
const u64 seed = fnv_bytes(revision, sizeof(revision) - 1);
u64 key = fnv_bytes(root_blob.data(), root_blob.size(), fnv_bytes(b, b_bytes, fnv_bytes(a, a_bytes, seed)));
// A stream's input layout (stream_input_layout) feeds the vertex fetch, so it is part of the key.
Expand Down Expand Up @@ -352,7 +352,7 @@ void publish_compute_request(const void* desc)
std::vector<unsigned char> fields(sizeof(words));
words[0] = words[1] = words[3] = words[5] = words[7] = words[9] = words[10] = 0;
std::memcpy(fields.data(), words, sizeof(words));
constexpr char compute_revision[] = "x2w-startup-shader-10cs"; // tools/startup/gfx2hlsl.py compute_key
constexpr char compute_revision[] = "x2w-startup-shader-11cs"; // tools/startup/gfx2hlsl.py compute_key
u64 key = fnv_bytes(compute_revision, sizeof(compute_revision) - 1);
const std::vector<unsigned char>* order[] = {&code, &data, &root_blob, &fields, &state_a, &state_b};
for (const auto* part : order) key = fnv_part(*part, key);
Expand Down
4 changes: 2 additions & 2 deletions tests/startup_compute_request_offline_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
DESC = struct.pack('<12Q', 0, 0, 24, 0, 20, 0, len(CODE), 0, len(DATA), 0, 0, 11)
STATE_A = struct.pack('<3Q', 1, 0x2c, 0xfff0000000000003)
STATE_B = struct.pack('<5I', 0x1234abcd, 0xffff0000, 0, 0, 0)
KEY = 0xbc35a19da8443505 # compute_key of the parts above
KEY = 0xb913358e44798a64 # compute_key of the parts above


def framed_key():
h = 1469598103934665603
for b in b'x2w-startup-shader-10cs':
for b in b'x2w-startup-shader-11cs':
h = ((h ^ b) * 1099511628211) & 0xffffffffffffffff
for part in (CODE, DATA, ROOT, DESC, STATE_A, STATE_B):
for b in struct.pack('<Q', len(part)) + part:
Expand Down
Loading
Loading