Under Proton, mad() can be split into a multiply and an add, so wg_div / pd_div3 are 1 ULP off (upstream fix proposed)

未关闭
#150 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
15/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp

调研方向

The payload names build_dx12.py, which strips precise marks from the division shaders, and clean/dx12/README.md, which documents the Windows driver's fused mad() behaviour. It also names native_helpers color_divide and native_direct_test check as the ULP measurements. The root cause and the proposed fix live upstream in dxil-spirv#365, so no change in this repository is clearly requested; confirm with the maintainer what, if anything, belongs here before starting.

由索引模型根据 Issue 内容生成。

描述

area: linux area: runtime

Under Proton, WrongGPU's exact arithmetic is not exact everywhere. The cause is in the D3D12-to-Vulkan translation, not in WrongGPU, and a fix is proposed upstream: HansKristian-Work/dxil-spirv#365. This issue records what we found, for reference.

What happens

dxil-spirv translates mad() (DXIL FMad) to a SPIR-V Fma. It marks the Fma NoContraction only when the FMad carries dx.precise. Without that mark, RADV's compiler (ACO) may split the Fma into a multiply and an add. In wg_div, mad(-bs, y, 1.0f) became s_mul_f32 + s_sub_f32, and the remainder steps became v_mul_f32 + v_sub_f32. AMD's Windows driver keeps every non-precise mad() fused (clean/dx12/README.md), and wg_div and pd_div3 depend on that.

Measured on an RX 9070 XT (RADV) under GE-Proton 11-11, with vkd3d-proton 5b1089c8 + dxil-spirv#362:

  • native_helpers color_divide against IEEE division (NumPy): 44,010 of 1,802,240 results 1 ULP off (51 of 110 divisors).
  • native_direct_test check: the direct and staged routes differ by 1 in post.history from frame 3 (reset frame, exposure mode 0, pre-exposure 1.375).

In game, a difference this size is not visible. It matters for bit-exact comparisons run under Proton.

Fixes

  1. Upstream, dxil-spirv#365: every FMad's Fma gets NoContraction. With it, color_divide has 0 wrong results and the two routes give the same bits on all 8 frames. A timing A/B of Model M's frame showed +0.18%, inside the noise. In Cyberpunk, RR's frame time did not change. It reaches players once a vkd3d-proton with it ships in Proton.
  2. Interim, no rebuild: vkd3d-proton's shader quirk. Create a text file with this line:
    0000000000000000-ffffffffffffffff FORCE_NOCONTRACT_MATH
    
    Then start the game with VKD3D_SHADER_QUIRKS=<path to that file> %command%. color_divide then also has 0 wrong results; Model M's frame A/B was +0.52%, inside the noise. Note that this applies to every shader in the game, not only WrongGPU's. I have not measured what it costs the game's own rendering.

Not a fix: precise

Marking the divisions' mad() calls precise would give dxil-spirv the dx.precise mark it needs. But build_dx12.py removes these marks on purpose, because AMD's Windows driver splits a precise mad(). Keeping them would trade the Proton problem for the same problem on Windows, so the fix belongs in the translation layer.

🤖 Generated with Claude Code

主要语言
C++
星标
12
派生
2
平均合并
3 小时 10 分钟
30 天内合并 PR
171

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

phantoslayer21/wronggpu 的其他 Issue

查看 phantoslayer21/wronggpu 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。