translator: keep integer words in flat parameters #1255

Merged
Jess-Doit merged 4 commits from upstream-pr/1262 into main 2026-11-24 07:23:30 +00:00
Jess-Doit commented 2026-11-24 06:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T06:02:42Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575711945 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1262). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T06:02:42Z. --- ## 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).
tedin7 commented 2026-11-24 06:47:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:18:09Z.

Review: COMMENTED


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).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034577154 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1262#pullrequestreview-6034577154). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:18:09Z. **Review:** COMMENTED --- 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).
Jess-Doit commented 2026-11-24 06:50:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T06:19:57Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123823655 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1262#issuecomment-7123823655). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T06:19:57Z. --- 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.
upstream-sync closed this pull request 2026-11-24 08:01:21 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1255
No description provided.