translator: keep integer words in flat parameters #1262

Manually merged
github merged 4 commits from gh-pr/1262/head into gh-pr/1262/base 2026-11-26 22:53:21 +00:00
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 06:02 UTC · original
Jess-Doit:translator/flat-param-bits → main · +415 −11 · 11 files · 4 commits · merged 2026-11-24 07:23 UTC

Change

Refs #1259. This is the flat-parameter half; colour exports stay open there.

tools/startup/gfx2hlsl.py copied a flat parameter as nointerpolation float4 fparam<n>, set to o.param<n> after the float export, and v_interp_mov_f32 read it back with asuint. The --pending path compiles with FXC vs_5_1/ps_5_1. FXC folds asfloat() of a constant and flushes binary32 denormal patterns to 0, so constant integer words such as 1, 2 or 0x80000001 reached the pixel stage as 0.

Now:

  • Vertex stage: every exp param<n> also writes o.fparam<n> = uint4(<the exported registers>), with no float conversion. A compr export writes the bits of its unpacked halves. hlsl_vs() drops that line for attributes the pixel stage reads only interpolated, so those get no flat copy, as before.
  • Interface: nointerpolation uint4 fparam<n> : FPARAM<n> in both stages. The rectangle-list fourth corner still copies the first vertex's flat words.
  • Pixel stage: v_interp_mov_f32 reads i.fparam<n>.<c> directly.

Interpolated parameters (v_interp_p1/p2) are unchanged.

Fixture

tests/startup_flat_param_check.py uses a source-built gfx1013 pair, recorded as words and as assembly:

  • Vertex stage: places a full-screen triangle from the vertex index and exports the constant words 1, 2, 0x7fc00001 and 0x80000001 to param0. As binary32 these are three denormals and a NaN with a payload.
  • Pixel stage: reads the words with v_interp_mov_f32 ... p0, attr0.x..w and exports them to mrt0.

Controls (no arguments):

  • the uint4 copy in both stages, written from v6–v9, with no U() on the read;
  • the rectangle-list corner copy;
  • a pixel stage that reads attr0.x only through v_interp_p1/p2 gets no fparam0 in either stage.

binary <llvm-mc>: the three sources reassemble to the recorded words. This is added to the gfx1013 CI job.

draw: offscreen_check --startup-flat-param (tests/startup_flat_param.cpp) draws one pixel with the translated pair into R32G32B32A32_FLOAT and compares the four words. It runs with FXC 5_1 when available and with DXC 6_0:

Pair Must read
translated pair 00000001,00000002,7fc00001,80000001
float4 flat copy as before this PR, run-time words the same (the interface keeps the bits)
float4 flat copy as before this PR, constant words, FXC 00000000,00000000,7fc00001,00000000 (the negative control)
the same, DXC reported only: DXC keeps constant denormals

The run-time words are word + ((vid >> 31) << 23). A plain + (vid >> 31) is not enough: FXC finds that 1 + (vid >> 31) is always a denormal and flushes it anyway.

Verification

Tested 588e8777 (on 48b31812) on Windows 10 22H2 19045.6456 with a GTX 1060 6 GB (10de:1c03, driver 32.0.15.6094) and in-box WARP (1414:008c, 10.0.19041.5794), using FXC and DXC from Windows SDK 10.0.26100.0. The D3D12 debug layer was enabled and reported 0 errors and 0 warnings on every draw.

. .\tools\dev.ps1
$env:XBOX2WINDOWS_ADAPTER = '1060'
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset
    cmake --build --preset $preset --target offscreen_check d3d12_xs_shim startup_stream_consumer xmem_shim -j 2
    ctest --preset $preset --no-tests=error -R '^(startup_flat_param_|startup_sampler_heap_|startup_stream_|startup_r8_uint)' -V
}
python -B tests/startup_flat_param_check.py binary <llvm-mc>

Debug and Release each passed all 13 selected tests, with no skips: startup_flat_param_{controls,warp,hardware}, and the existing translated-shader tests startup_sampler_heap_*, startup_stream_{request,draw}_* and startup_r8_uint_*.

In the first run the two flat-parameter draws failed because of the fixture itself: its vertex stage put all three vertices at one point, so nothing was drawn. After that fix, which changed only the test script, startup_flat_param_* was run again in both configurations and passed 3/3. The other 11 tests passed in the first run, with the same build. Flat-parameter output, the same on both adapters and in both configurations:

fxc translated pair: 00000001,00000002,7fc00001,80000001
fxc float4 flat copy, run-time words: 00000001,00000002,7fc00001,80000001
fxc float4 flat copy, constant words: fails as expected, reads 00000000,00000000,7fc00001,00000000
dxc translated pair: 00000001,00000002,7fc00001,80000001
dxc float4 flat copy, run-time words: 00000001,00000002,7fc00001,80000001
dxc float4 flat copy, constant words: exact

The binary check passed with a local LLVM 23.1.6 llvm-mc. CI runs it with LLVM 15.

AI-assisted (Claude Code).

**@⁠Jess-Doit** on GitHub · 2026-11-24 06:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1262) `Jess-Doit:translator/flat-param-bits` → `main` · +415 −11 · 11 files · 4 commits · merged 2026-11-24 07:23 UTC ## Change Refs #1259. This is the flat-parameter half; colour exports stay open there. `tools/startup/gfx2hlsl.py` copied a flat parameter as `nointerpolation float4 fparam<n>`, set to `o.param<n>` after the float export, and `v_interp_mov_f32` read it back with `asuint`. The `--pending` path compiles with FXC `vs_5_1`/`ps_5_1`. FXC folds `asfloat()` of a constant and flushes binary32 denormal patterns to 0, so constant integer words such as 1, 2 or `0x80000001` reached the pixel stage as 0. Now: - **Vertex stage:** every `exp param<n>` also writes `o.fparam<n> = uint4(<the exported registers>)`, with no float conversion. A `compr` export writes the bits of its unpacked halves. `hlsl_vs()` drops that line for attributes the pixel stage reads only interpolated, so those get no flat copy, as before. - **Interface:** `nointerpolation uint4 fparam<n> : FPARAM<n>` in both stages. The rectangle-list fourth corner still copies the first vertex's flat words. - **Pixel stage:** `v_interp_mov_f32` reads `i.fparam<n>.<c>` directly. Interpolated parameters (`v_interp_p1`/`p2`) are unchanged. ## Fixture `tests/startup_flat_param_check.py` uses a source-built gfx1013 pair, recorded as words and as assembly: - **Vertex stage:** places a full-screen triangle from the vertex index and exports the constant words `1`, `2`, `0x7fc00001` and `0x80000001` to `param0`. As binary32 these are three denormals and a NaN with a payload. - **Pixel stage:** reads the words with `v_interp_mov_f32 ... p0, attr0.x..w` and exports them to `mrt0`. **Controls (no arguments):** - the uint4 copy in both stages, written from `v6`–`v9`, with no `U()` on the read; - the rectangle-list corner copy; - a pixel stage that reads `attr0.x` only through `v_interp_p1`/`p2` gets no `fparam0` in either stage. **`binary <llvm-mc>`:** the three sources reassemble to the recorded words. This is added to the gfx1013 CI job. **`draw`:** `offscreen_check --startup-flat-param` (`tests/startup_flat_param.cpp`) draws one pixel with the translated pair into `R32G32B32A32_FLOAT` and compares the four words. It runs with FXC `5_1` when available and with DXC `6_0`: | Pair | Must read | |---|---| | translated pair | `00000001,00000002,7fc00001,80000001` | | float4 flat copy as before this PR, run-time words | the same (the interface keeps the bits) | | float4 flat copy as before this PR, constant words, FXC | `00000000,00000000,7fc00001,00000000` (the negative control) | | the same, DXC | reported only: DXC keeps constant denormals | The run-time words are `word + ((vid >> 31) << 23)`. A plain `+ (vid >> 31)` is not enough: FXC finds that `1 + (vid >> 31)` is always a denormal and flushes it anyway. ## Verification Tested `588e8777` (on `48b31812`) on Windows 10 22H2 `19045.6456` with a GTX 1060 6 GB (`10de:1c03`, driver `32.0.15.6094`) and in-box WARP (`1414:008c`, `10.0.19041.5794`), using FXC and DXC from Windows SDK `10.0.26100.0`. The D3D12 debug layer was enabled and reported 0 errors and 0 warnings on every draw. ```powershell . .\tools\dev.ps1 $env:XBOX2WINDOWS_ADAPTER = '1060' foreach ($preset in 'dev', 'release') { cmake --preset $preset cmake --build --preset $preset --target offscreen_check d3d12_xs_shim startup_stream_consumer xmem_shim -j 2 ctest --preset $preset --no-tests=error -R '^(startup_flat_param_|startup_sampler_heap_|startup_stream_|startup_r8_uint)' -V } python -B tests/startup_flat_param_check.py binary <llvm-mc> ``` Debug and Release each passed all 13 selected tests, with no skips: `startup_flat_param_{controls,warp,hardware}`, and the existing translated-shader tests `startup_sampler_heap_*`, `startup_stream_{request,draw}_*` and `startup_r8_uint_*`. In the first run the two flat-parameter draws failed because of the fixture itself: its vertex stage put all three vertices at one point, so nothing was drawn. After that fix, which changed only the test script, `startup_flat_param_*` was run again in both configurations and passed 3/3. The other 11 tests passed in the first run, with the same build. Flat-parameter output, the same on both adapters and in both configurations: ```text fxc translated pair: 00000001,00000002,7fc00001,80000001 fxc float4 flat copy, run-time words: 00000001,00000002,7fc00001,80000001 fxc float4 flat copy, constant words: fails as expected, reads 00000000,00000000,7fc00001,00000000 dxc translated pair: 00000001,00000002,7fc00001,80000001 dxc float4 flat copy, run-time words: 00000001,00000002,7fc00001,80000001 dxc float4 flat copy, constant words: exact ``` The binary check passed with a local LLVM 23.1.6 `llvm-mc`. CI runs it with LLVM 15. AI-assisted (Claude Code).
gfx2hlsl copied flat parameters as float4 from the float export and read
them back with asuint. FXC folds asfloat() of a constant and flushes
binary32 denormal patterns, so constant integer words such as 1 or 2
reached v_interp_mov_f32 as 0 on the --pending path. The flat copy is
now a nointerpolation uint4 written from the exported registers.

A source-built vertex and pixel pair checks the words on WARP and
hardware with FXC 5_1 and DXC 6_0. The old float copy is kept as a
control: with constant words FXC flushes them, with run-time words they
are exact.

Refs #1259.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	.github/workflows/windows.yml
#	AGENTS.md
#	CMakeLists.txt
#	docs/startup-runtime.md
#	tests/desktop_gpu.h
#	tests/offscreen_check.cpp
# Conflicts:
#	.github/workflows/windows.yml
#	AGENTS.md
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:53:19 +00:00
github manually merged commit d2f014bec5 into gh-pr/1262/base 2026-11-26 22:53:21 +00:00
Author
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 06:19 UTC · original

Merged current main into the branch as a578b0b8 to clear the conflicts with #1244 and #1258. All six were in registration lists (CI, AGENTS.md, CMake, docs, desktop_gpu.h, offscreen_check.cpp). The diff against main is the same as the original PR, and gfx2hlsl.py merged without conflicts.

Retested a578b0b8 on the same host and adapters as the PR body, with the same build and ctest filter. Debug and Release each passed 13/13, with no skips and 0 debug-layer errors or warnings. The startup_flat_param_* output is unchanged.

**@⁠Jess-Doit** on GitHub · 2026-11-24 06:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1262#issuecomment-7123823655) Merged current main into the branch as `a578b0b8` to clear the conflicts with #1244 and #1258. All six were in registration lists (CI, `AGENTS.md`, CMake, docs, `desktop_gpu.h`, `offscreen_check.cpp`). The diff against `main` is the same as the original PR, and `gfx2hlsl.py` merged without conflicts. Retested `a578b0b8` on the same host and adapters as the PR body, with the same build and `ctest` filter. Debug and Release each passed 13/13, with no skips and 0 debug-layer errors or warnings. The `startup_flat_param_*` output is unchanged.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 06:18 UTC · original · reviewed

Reviewed at commit a578b0b82a873125f3088bd4e572a06771f1a38e.

Verification

Linux

  • git diff --check origin/main...HEAD — clean
  • tests/docs_links_check.py — passed (16 Markdown files, 284 links)
  • tests/bidi_controls_check.py — passed (1067 tracked files)
  • tests/startup_flat_param_check.py — passed (controls + interpolated-only omission)
  • LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so tests/startup_flat_param_check.py binary /usr/bin/llvm-mc-19 — passed (fixture words match llvm-mc)

Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP)

  • Debug (--preset dev):
    • cmake --build --preset dev --target offscreen_check -- -j 6 — built cleanly (23.49s)
    • ctest --preset dev -R '^startup_flat_param_' --parallel 4 --no-tests=error --output-on-failure — 3/3 passed (startup_flat_param_controls 0.17s, startup_flat_param_warp 0.84s, startup_flat_param_hardware 0.85s; total 0.89s)
  • Release /O2 (--preset release):
    • cmake --build --preset release --target offscreen_check -- -j 6 — built cleanly (23.93s)
    • ctest --preset release -R '^startup_flat_param_' --parallel 4 --no-tests=error --output-on-failure — 3/3 passed (startup_flat_param_controls 0.18s, startup_flat_param_warp 0.80s, startup_flat_param_hardware 0.82s; total 0.87s)

Code Review Notes

  • tools/startup/gfx2hlsl.py: Emitting o.fparam<n> = uint4(...) directly from the exported register words (and U(f16tof32(...)) for compr), declaring nointerpolation uint4 fparam<n> : FPARAM<n>, and reading i.fparam<n>.<c> in op_v_interp_mov_f32 cleanly avoids FXC constant-folding asfloat() and flushing binary32 denormal bit patterns to 0.
  • hlsl_vs() filters out o.fparam<n> = lines for attributes not in self.flat, preserving the existing behavior where purely interpolated parameters emit no flat copy.
  • tests/startup_flat_param_check.py + tests/startup_flat_param.cpp: Strong positive and negative controls (including the pre-fix float4 copy with constant words vs. run-time words under FXC 5_1 and DXC 6_0).
**@⁠tedin7** on GitHub · 2026-11-24 06:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1262#pullrequestreview-6034577154) · **reviewed** Reviewed at commit `a578b0b82a873125f3088bd4e572a06771f1a38e`. ### Verification **Linux** - `git diff --check origin/main...HEAD` — clean - `tests/docs_links_check.py` — passed (16 Markdown files, 284 links) - `tests/bidi_controls_check.py` — passed (1067 tracked files) - `tests/startup_flat_param_check.py` — passed (controls + interpolated-only omission) - `LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so tests/startup_flat_param_check.py binary /usr/bin/llvm-mc-19` — passed (`fixture words match llvm-mc`) **Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP)** - **Debug (`--preset dev`)**: - `cmake --build --preset dev --target offscreen_check -- -j 6` — built cleanly (`23.49s`) - `ctest --preset dev -R '^startup_flat_param_' --parallel 4 --no-tests=error --output-on-failure` — **3/3 passed** (`startup_flat_param_controls` `0.17s`, `startup_flat_param_warp` `0.84s`, `startup_flat_param_hardware` `0.85s`; total `0.89s`) - **Release `/O2` (`--preset release`)**: - `cmake --build --preset release --target offscreen_check -- -j 6` — built cleanly (`23.93s`) - `ctest --preset release -R '^startup_flat_param_' --parallel 4 --no-tests=error --output-on-failure` — **3/3 passed** (`startup_flat_param_controls` `0.18s`, `startup_flat_param_warp` `0.80s`, `startup_flat_param_hardware` `0.82s`; total `0.87s`) ### Code Review Notes - `tools/startup/gfx2hlsl.py`: Emitting `o.fparam<n> = uint4(...)` directly from the exported register words (and `U(f16tof32(...))` for `compr`), declaring `nointerpolation uint4 fparam<n> : FPARAM<n>`, and reading `i.fparam<n>.<c>` in `op_v_interp_mov_f32` cleanly avoids FXC constant-folding `asfloat()` and flushing binary32 denormal bit patterns to 0. - `hlsl_vs()` filters out `o.fparam<n> = ` lines for attributes not in `self.flat`, preserving the existing behavior where purely interpolated parameters emit no flat copy. - `tests/startup_flat_param_check.py` + `tests/startup_flat_param.cpp`: Strong positive and negative controls (including the pre-fix `float4` copy with constant words vs. run-time words under FXC 5_1 and DXC 6_0).
This discussion has been locked. Commenting is limited to contributors.
No description provided.