startup: keep gfx1013 non-fused multiply-add rounding in gfx2hlsl #1761

Merged
Jess-Doit merged 2 commits from upstream-pr/1768 into main 2026-11-24 18:49:39 +00:00
Jess-Doit commented 2026-11-24 18:16:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T18:16:26Z.


Refs #1728

Change

Lower gfx1013 v_mad_f32, v_mac_f32, v_madmk_f32, v_madak_f32 and
v_mad_legacy_f32 with separate precise product and sum steps. Flush
binary32 denormals at the inputs and after each step. Apply the flush mask
as integer bits so FXC preserves negative zero. The legacy form retains
zero times anything as zero. Bump the startup shader cache revision so
cached bytecode with the previous lowering gets retranslated on request.
The existing HLSL for v_fma_f32 and v_fmac_f32 does not guarantee a fused result.

Verification

Tested f7b7297d034651397a0294d64eecf66e2380bb8e from
9ffb85294fc99addb3df670904783435938019f7. Windows 10 22H2 build 19045.6456,
Windows SDK 10.0.26100.0, DXC 1.9.2602.17 and FXC 10.0.26100.9457.

The source-built gfx1013 programs decode through the startup translator.
An exact rational Python model supplies the binary32 comparison words.
DXC uses raw UAV input and readback at cs_6_0 and at cs_6_2 -denorm preserve.
FXC draws the translated pair at vs_5_1/ps_5_1. The readback includes a
flushed negative sum (80000000) and the legacy result of zero times
infinity plus one (3f800000).

Adapter Driver Reference in each profile Plain-expression control No-flush control
GTX 1060 6GB 32.0.15.6094 20/20 words 40000003 for 4 forms, 40000002 for legacy Product and addend 00c00000 for all five
In-box WARP 10.0.19041.5794 20/20 words 40000002 for all five Product and addend 00c00000 for all five

The rounding reference is 40000002. The single-rounding reference is
40000003. The text control rejects plain arithmetic even when the
compiler and driver produce the separate-rounding word.
Removing the flushes changes the product and addend cases from
00800000 to 00c00000 on both adapters. That control requests SM 6.2
and has its own capability gate. Both adapters reported zero D3D12
debug-layer errors and warnings.

Debug and Release each passed all 20 selected tests with zero failures
and zero skips. The selection includes the new fixture, the existing
startup translator tests, the pixel AOT MAD checks in
pixel_aot_blend_scalar, the legacy MAC and MAD64 tests, and the docs link
check. LLVM 15.0.7 and 23.1.6 both reproduced the recorded fixture words.
Newer LLVM can fill unused VOP3 fields differently in other forms.

. .\tools\dev.ps1
$env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0'
$env:XBOX2WINDOWS_ADAPTER = '1060'
$env:X2W_D3D12_DEBUG = '1'
$intake = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path
$filter = '^(startup_gfx2hlsl_.*|pixel_aot_(blend_scalar|mac_legacy|mad64)_(warp|hardware)|docs_links)$'
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset "-DINTAKE_PYTHON=$intake"
    cmake --build --preset $preset --target offscreen_check d3d12_xs_shim -j 2
    ctest --preset $preset --no-tests=error -j 1 -R $filter -V
}
& $intake -B tests/startup_gfx2hlsl_mad_check.py
& $intake -B tests/startup_gfx2hlsl_mad_check.py binary llvm-mc-15

After merging main at a4d17cf5 (25fbf27b), an independent rerun on the same host passed 18/18 in Debug and in Release with zero skips: ctest --preset <preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_|startup_flat_param|docs_links$)', which covers the five new startup_gfx2hlsl_mad_* tests on both adapters.

AI-assisted (Codex, driven with Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588457844 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1768). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T18:16:26Z. --- Refs #1728 ### Change Lower gfx1013 `v_mad_f32`, `v_mac_f32`, `v_madmk_f32`, `v_madak_f32` and `v_mad_legacy_f32` with separate `precise` product and sum steps. Flush binary32 denormals at the inputs and after each step. Apply the flush mask as integer bits so FXC preserves negative zero. The legacy form retains zero times anything as zero. Bump the startup shader cache revision so cached bytecode with the previous lowering gets retranslated on request. The existing HLSL for `v_fma_f32` and `v_fmac_f32` does not guarantee a fused result. ### Verification Tested `f7b7297d034651397a0294d64eecf66e2380bb8e` from `9ffb85294fc99addb3df670904783435938019f7`. Windows 10 22H2 build 19045.6456, Windows SDK 10.0.26100.0, DXC 1.9.2602.17 and FXC 10.0.26100.9457. The source-built gfx1013 programs decode through the startup translator. An exact rational Python model supplies the binary32 comparison words. DXC uses raw UAV input and readback at `cs_6_0` and at `cs_6_2 -denorm preserve`. FXC draws the translated pair at `vs_5_1`/`ps_5_1`. The readback includes a flushed negative sum (`80000000`) and the legacy result of zero times infinity plus one (`3f800000`). | Adapter | Driver | Reference in each profile | Plain-expression control | No-flush control | |---|---|---|---|---| | GTX 1060 6GB | 32.0.15.6094 | 20/20 words | `40000003` for 4 forms, `40000002` for legacy | Product and addend `00c00000` for all five | | In-box WARP | 10.0.19041.5794 | 20/20 words | `40000002` for all five | Product and addend `00c00000` for all five | The rounding reference is `40000002`. The single-rounding reference is `40000003`. The text control rejects plain arithmetic even when the compiler and driver produce the separate-rounding word. Removing the flushes changes the product and addend cases from `00800000` to `00c00000` on both adapters. That control requests SM 6.2 and has its own capability gate. Both adapters reported zero D3D12 debug-layer errors and warnings. Debug and Release each passed all 20 selected tests with zero failures and zero skips. The selection includes the new fixture, the existing startup translator tests, the pixel AOT MAD checks in `pixel_aot_blend_scalar`, the legacy MAC and MAD64 tests, and the docs link check. LLVM 15.0.7 and 23.1.6 both reproduced the recorded fixture words. Newer LLVM can fill unused VOP3 fields differently in other forms. ```powershell . .\tools\dev.ps1 $env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0' $env:XBOX2WINDOWS_ADAPTER = '1060' $env:X2W_D3D12_DEBUG = '1' $intake = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path $filter = '^(startup_gfx2hlsl_.*|pixel_aot_(blend_scalar|mac_legacy|mad64)_(warp|hardware)|docs_links)$' foreach ($preset in 'dev', 'release') { cmake --preset $preset "-DINTAKE_PYTHON=$intake" cmake --build --preset $preset --target offscreen_check d3d12_xs_shim -j 2 ctest --preset $preset --no-tests=error -j 1 -R $filter -V } & $intake -B tests/startup_gfx2hlsl_mad_check.py & $intake -B tests/startup_gfx2hlsl_mad_check.py binary llvm-mc-15 ``` After merging main at `a4d17cf5` (`25fbf27b`), an independent rerun on the same host passed 18/18 in Debug and in Release with zero skips: `ctest --preset <preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_|startup_flat_param|docs_links$)'`, which covers the five new `startup_gfx2hlsl_mad_*` tests on both adapters. AI-assisted (Codex, driven with Claude Code).
upstream-sync closed this pull request 2026-11-24 19:01:24 +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!1761
No description provided.