startup-runtime: FXC flushes constant integer bits in gfx2hlsl flat parameters and colour exports #1252

Closed
opened 2026-11-24 05:52:49 +00:00 by Jess-Doit · 3 comments
Jess-Doit commented 2026-11-24 05:52:49 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T05:52:49Z.


What happens

tools/startup/gfx2hlsl.py keeps shader registers as uint and converts to float at the stage interface:

  • a vertex exp param becomes o.param<n> = float4(F(v..));
  • a flat copy o.fparam<n> = o.param<n> feeds v_interp_mov_f32, which reads U(i.fparam<n>.c);
  • a pixel exp mrt becomes o.mrt<n> = float4(F(v..)).

translate_to() (the --pending path the stand-in loads) compiles those stages with FXC vs_5_1 / ps_5_1. When the register holds a constant, FXC folds asfloat(<literal>) at compile time and flushes binary32 denormal patterns to 0. Integer bit patterns such as 1, 2 or 0x80000001 are denormals as floats, so they are lost before the shader runs.

Source-built repro on local HEAD (Windows 10 22H2 19045.6456, FXC and DXC from Windows SDK 10.0.26100.0):

  1. A gfx1013 vertex stage moves 1, 2, 0x7fc00001 and 0x80000001 into v6–v9 and exports them with exp param0.
  2. A pixel stage reads them back with v_interp_mov_f32 ... p0, attr0.x..w and exports them to mrt0.

The FXC listing of the translated vertex stage is mov o0.xyzw, l(0,0,0x7fc00001,0) for both param0 and fparam0. A translated pixel stage that exports the same constants directly compiles to mov o0.xyzw, l(0,0,0x7fc00001,1.000000).

A one-pixel draw into R32G32B32A32_FLOAT reads back the following on the in-box WARP (10.0.19041.5794) and on a GTX 1060 (32.0.15.6094), with the debug layer on and 0 errors or warnings:

Pair Readback
DXC vs_6_0 / ps_6_0 00000001,00000002,7fc00001,80000001 (exact)
FXC vs_5_1 / ps_5_1, constants 00000000,00000000,7fc00001,00000000
FXC, the same values computed at run time (+ (SV_VertexID >> 31)) exact

So the hardware and the flat interface keep the bits. The loss is FXC's constant folding. /Od keeps them too, but it turns off all FXC optimisation.

This matters for titles because a flat attribute often carries an integer selector or index that the pixel stage compares or branches on. XCL hit the same class of problem, where a flat input that must keep its bits was converted (their #249).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575593223 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1259). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T05:52:49Z. --- ## What happens `tools/startup/gfx2hlsl.py` keeps shader registers as `uint` and converts to float at the stage interface: - a vertex `exp param` becomes `o.param<n> = float4(F(v..))`; - a flat copy `o.fparam<n> = o.param<n>` feeds `v_interp_mov_f32`, which reads `U(i.fparam<n>.c)`; - a pixel `exp mrt` becomes `o.mrt<n> = float4(F(v..))`. `translate_to()` (the `--pending` path the stand-in loads) compiles those stages with FXC `vs_5_1` / `ps_5_1`. When the register holds a constant, FXC folds `asfloat(<literal>)` at compile time and flushes binary32 denormal patterns to 0. Integer bit patterns such as 1, 2 or `0x80000001` are denormals as floats, so they are lost before the shader runs. Source-built repro on local HEAD (Windows 10 22H2 `19045.6456`, FXC and DXC from Windows SDK `10.0.26100.0`): 1. A gfx1013 vertex stage moves `1`, `2`, `0x7fc00001` and `0x80000001` into `v6`–`v9` and exports them with `exp param0`. 2. A pixel stage reads them back with `v_interp_mov_f32 ... p0, attr0.x..w` and exports them to `mrt0`. The FXC listing of the translated vertex stage is `mov o0.xyzw, l(0,0,0x7fc00001,0)` for both `param0` and `fparam0`. A translated pixel stage that exports the same constants directly compiles to `mov o0.xyzw, l(0,0,0x7fc00001,1.000000)`. A one-pixel draw into `R32G32B32A32_FLOAT` reads back the following on the in-box WARP (`10.0.19041.5794`) and on a GTX 1060 (`32.0.15.6094`), with the debug layer on and 0 errors or warnings: | Pair | Readback | |---|---| | DXC `vs_6_0` / `ps_6_0` | `00000001,00000002,7fc00001,80000001` (exact) | | FXC `vs_5_1` / `ps_5_1`, constants | `00000000,00000000,7fc00001,00000000` | | FXC, the same values computed at run time (`+ (SV_VertexID >> 31)`) | exact | So the hardware and the flat interface keep the bits. The loss is FXC's constant folding. `/Od` keeps them too, but it turns off all FXC optimisation. This matters for titles because a flat attribute often carries an integer selector or index that the pixel stage compares or branches on. XCL hit the same class of problem, where a flat input that must keep its bits was converted (their #249).
Jess-Doit commented 2026-11-24 06:50:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T05:52:50Z.


I'll take the flat-parameter half:

  • gfx2hlsl declares flat copies as nointerpolation uint4 fparam<n>;
  • they are written from the exported registers directly, with no F();
  • v_interp_mov_f32 reads them without U().

Check: a source-built vertex/pixel pair, translated and compiled with FXC 5_1 (the --pending path) and with DXC 6_0. It must read back the four patterns exactly on WARP and hardware. Two negative controls:

  • today's float4 flat copy must lose 1, 2 and 0x80000001 under FXC;
  • a run-time-computed control shows the interface itself is exact.

Out of scope: constant integer bits in colour exports (mrt). The right output type depends on the bound render-target format, so that needs its own change. I'll note the measured result there and leave it open.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123361717 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1259#issuecomment-7123361717). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T05:52:50Z. --- I'll take the flat-parameter half: - `gfx2hlsl` declares flat copies as `nointerpolation uint4 fparam<n>`; - they are written from the exported registers directly, with no `F()`; - `v_interp_mov_f32` reads them without `U()`. **Check:** a source-built vertex/pixel pair, translated and compiled with FXC `5_1` (the `--pending` path) and with DXC `6_0`. It must read back the four patterns exactly on WARP and hardware. Two negative controls: - today's `float4` flat copy must lose `1`, `2` and `0x80000001` under FXC; - a run-time-computed control shows the interface itself is exact. **Out of scope:** constant integer bits in colour exports (`mrt`). The right output type depends on the bound render-target format, so that needs its own change. I'll note the measured result there and leave it open. AI-assisted (Claude Code).
Jess-Doit commented 2026-11-24 06:50:30 +00:00 (Migrated from github.com)
Author
Contributor

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


I'll take the colour-export half of #1259. I’ll start with uncompressed exp mrt to R32_UINT and R32_SINT, using the bound RTV formats to select a format-specific shader cache entry. The first check will use the same shader and root across the two integer formats, with an ordinary UNORM output in the same draw.

I’ll compare source-built FXC ps_5_1 and DXC ps_6_0 outputs on the GTX 1060 and Windows 10 in-box WARP. I'll also isolate the raw-binary32 float export in a separate check, using optimized FXC, a run-time operand, and DXC to pin down a workaround. Packed integer exports need their own encoding evidence.

AI-assisted (Codex).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123529033 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1259#issuecomment-7123529033). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T06:03:08Z. --- I'll take the colour-export half of #1259. I’ll start with uncompressed `exp mrt` to `R32_UINT` and `R32_SINT`, using the bound RTV formats to select a format-specific shader cache entry. The first check will use the same shader and root across the two integer formats, with an ordinary UNORM output in the same draw. I’ll compare source-built FXC `ps_5_1` and DXC `ps_6_0` outputs on the GTX 1060 and Windows 10 in-box WARP. I'll also isolate the raw-binary32 float export in a separate check, using optimized FXC, a run-time operand, and DXC to pin down a workaround. Packed integer exports need their own encoding evidence. AI-assisted (Codex).
R0Y00 commented 2026-11-24 08:01:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:44:38Z.


The reported two FXC paths have regression coverage on main. #1262 keeps flat interpolants as integer register words and requests fresh translations for older caches. #1266 checks typed UINT/SINT MRT output and exact binary32 FLOAT words, including rejection of a mismatched cached variant. Release checks passed on RTX 4060 Laptop and WARP with both FXC and DXC. The existing scope for packed integer exports remains separate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125323014 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1259#issuecomment-7125323014). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:44:38Z. --- The reported two FXC paths have regression coverage on main. #1262 keeps flat interpolants as integer register words and requests fresh translations for older caches. #1266 checks typed UINT/SINT MRT output and exact binary32 FLOAT words, including rejection of a mismatched cached variant. Release checks passed on RTX 4060 Laptop and WARP with both FXC and DXC. The existing scope for packed integer exports remains separate.
Sign in to join this conversation.
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#1252
No description provided.