Repository navigation
startup: cap v_fract_f32 at 0x3f7fffff like pixel_aot already does - #2010
Conversation
Ran it, broke it four ways, and checked the arithmetic the description rests onWindows 11 build 26300.9974, device-free: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_fract_check.py
control: a min-form clamp is rejected: ok
control: a cap other than 0x3f7fffff is rejected: ok
PASS exit 0
The second is the one I would have expected to slip: with a strict The two claims in the comment, checked as arithmeticI reimplemented So "a tiny negative input cannot round up to 1.0" is exactly right, and the threshold sits where the description says it does: the boundary is The NaN half also holds: On the asymmetry this PR is really aboutTwo translators lowering the same instruction differently is the kind of divergence that costs days later, and the fix goes toward the older, ScopeThe emitted helper is checked as text plus the two controls; no shader was compiled or run here. Whether adapter VerdictReviewed. Four mutations caught, and the numeric claim holds at the boundary. Notes
|
|
Thanks — the On the origin of the cap, since you flagged it as not measured here: it is not in the ISA. The RDNA 2 guide gives There is no NVIDIA adapter on this machine, so the adapter half of the argument still rests on the two reports in #1741 rather than on anything measurable here. AI-assisted. |
|
Hardware data for the NVIDIA gap, from an RTX 3070 Ti (driver 32.0.16.2101, Windows 11 build 26300.9974, DXC 1.9.2602.17, FXC from SDK 10.0.26100, debug layer on). On top of the #1741 head (8ff3ddd, uncommitted) I copied the
FXC compiles float f = value - floor(value);With it, FXC and DXC both pass on hardware (20 draws, 10 mutated, 0 debug errors), and WARP passes too. On this PR's head (8c99dd3), Not measured: Quadro, AMD and Intel with this variant; NaN, inf and -0 (not in the draws). |
|
The cap fixes already translated shaders. Please bump the startup shader cache revision in both gfx2hlsl.py and d3d12_draw.inl after #1997, and check that the pre-fix key no longer hits. The source-built test currently checks the form of the HLSL. Please run the generated shader with default FXC and DXC on the reported negative input and a regular fractional value, using raw pixel words and the uncapped mutant as a control. If WARP already caps the uncapped input, record that separately. |
|
Measured on the Maxwell card this was missing: with #2010 as it stands, the Quadro still fails on the same input, because FXC removes the cap. Setup:
The reason shows in FXC's own output (
A compare on the bits survives FXC: float fract32(float value) {
float f = frac(value);
return asuint(f) == 0x3f800000u ? asfloat(0x3f7fffffu) : f;
}FXC emits
|
The gfx2hlsl table emitted a bare D3D frac for v_fract_f32, while tools/pixel_aot.py has always lowered the same instruction through fract32, which caps x - floor(x) at 0x3f7fffff because D3D frac has no upper bound and differs between adapters. Two NVIDIA reports fail the draw on the input 0xb0800000 (-2^-30) with 3f800000 where the instruction returns 3f7fffff: an RTX 3070 Ti on 32.0.16.2101 and a Quadro M1000M on 32.0.15.7371. The same draw passes on WARP, on Intel HD Graphics 530 and on the RDNA 4 card used here. The helper is the comparison form, not min, so a NaN stays a NaN. A new check pins the emitted statement of the e32 and e64 forms, the cap in the preamble, and rejects an uncapped frac and a min-form cap. No NVIDIA adapter is available here: the Maxwell and Turing results are not reproduced. What is verified is the emitted text, the pixel_aot rule it now matches, and the adapters that already returned 0x3f7fffff.
…he cache revision FXC treats frac as strictly below 1, so frac(value) >= 1.0f folds to false and the helper compiled to a bare frc: on the Quadro M1000M and the RTX 3070 Ti the cap was gone and v_fract_f32 still read 3f800000 for 0xb0800000. Comparing the encoding survives FXC (frc, ieq, movc), and frac can only reach the cap by rounding to exactly +1.0, so the equality covers the same case. The cap therefore changes translated shaders that are already cached: the revision seed goes to x2w-startup-shader-8 in gfx2hlsl.py and d3d12_draw.inl, and a control asserts both spellings agree and that the -7 seed keys differently.
8c99dd3 to
5eb8812
Compare
|
All three points are on the branch head ( The cap. The cache revision. It goes to The draw. The uncapped control, recorded separately as you asked. On this machine it does not separate the two forms: with the lowering left uncapped, WARP and the RX 9070 XT both read 4/4 AI-assisted; runs executed on the machine above. |
|
Re-ran the new head Setup as before:
Controls exit 0, and |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 5eb8812708e16b82bc74ca2829507b29fc49e2f8 (comment only, no approval).
Verdict: no P1, no P2. Looks correct.
What I checked:
v_fract_f32now lowers tofract32(), defined in the common preamble next toftz32. Same semantics astools/pixel_aot.py:406: the result is capped at0x3f7fffffwhenfracrounds up to 1.0.- The bit comparison (
asuint(f) == 0x3f800000u) is sound.fraccan only reach the cap by returning exactly +1.0. NaN misses the equality and passes through, same aspixel_aot. The comment explains why>= 1.0fis avoided (FXC folds it). - Cache seed
x2w-startup-shader-7to-8insrc/startup_stubs/d3d12_draw.inl:207matches the changed HLSL. The check pins that the old seed gives a different key. - CI on this head: Linux checks, Windows build and gfx1013 fixtures all pass. The
/O2job and the chart job were skipped. Mergeable. Title and body are neutral.
Commands run locally on the PR head (Linux):
python3 -B tests/startup_gfx2hlsl_fract_check.py-> PASSpython3 -B tests/startup_gfx2hlsl_fract_draw_check.py(controls mode) -> PASSpython3 tests/docs_links_check.py-> 18 files, 395 links, OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> clean
Mutations (both reverted afterwards with git checkout -- .):
- Table entry
fract32({0})changed back tofrac({0}): the check exits 1. - Cap condition
== 0x3f800000uchanged to>= 0x3f800001u: the check exits 1 (FAIL).
Both are killed by the new test.
Not run: the startup_gfx2hlsl_fract_draw_warp and _hardware draw tests need a D3D12 device, so I did not run them here. I did not start a Win2025 run. The Windows CI job is green, and the author's draw results come from the PR body.
Nits (non-blocking):
- N1:
tools/pixel_aot.py:406-409still usesf >= 1.0f. The new comment says FXC folds that form to false. Ifpixel_aotgoes through FXC, it may lose the cap on the same adapters. Worth a follow-up issue or check. It is out of scope here. - N2:
CMakeLists.txtcomment says the uncapped pair "must read 0x3f800000". That is accurate, but a pointer to the check file's name would help a future reader. Optional.
AI-assisted; commands listed were executed locally.
|
Thank you for the review, and for killing the mutations on that form. I checked N1, because it decides whether the cap in
So the It is nonetheless a latent trap in exactly the direction you point at: if N2 is fair. I can fold that pointer into this PR as a one-line comment change if you would rather have it here than as a follow-up. AI-assisted. |
stan495
left a comment
There was a problem hiding this comment.
Verified head 5eb88127 on Windows x64 (dev preset, MSVC 19.44.35228.0, SDK 10.0.26100.0, DXC/FXC 10.0.26100.0):
cmake --build --preset dev --target offscreen_check-> succeededctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_fract' -V-> 4/4 passed (startup_gfx2hlsl_fract,startup_gfx2hlsl_fract_draw_controls,startup_gfx2hlsl_fract_draw_warp,startup_gfx2hlsl_fract_draw_hardware)- Both FXC and DXC capped runs read
3f7fffff,3f000000,00000000,3f000000withdebug_layer=enabled,debug_errors=0 debug_warnings=0(and as recorded in the test, both WARP and this hardware adapter also clamp barefrcon the-2^-30input). - Hardware:
AMD Radeon RX 7900 XTX(vendor=1002 device=744c, driver32.0.32029.2010) - WARP:
Microsoft Basic Render Driver(vendor=1414 device=008c, driver10.0.26100.9818)
- Both FXC and DXC capped runs read
Verdict: Approved at 5eb88127.
|
Hardware result for head .\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_fract_draw_hardware$' -VNVIDIA GeForce RTX 3070 Ti (
This adds an NVIDIA Ampere adapter to stan495's AMD run on this head. legacy-code-archaeologist measured Maxwell, WARP and Intel on this head through the #1741 test, not this one. |
|
@thepatrickworld could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
…evision conflicts Main moved the startup shader cache revision to x2w-startup-shader-14 on its own, so this branch's bump lands on 15: the bit comparison of v_fract_f32 is kept as written, and the cache literals, the tests that pin them and the runtime doc follow. CMakeLists keeps main's small_texture_4k_xg tests and this branch's fract tests, both.
|
Merged On the RX 9070 XT (
AI-assisted. |
# Conflicts: # CMakeLists.txt # src/startup_stubs/d3d12_draw.inl # tools/startup/gfx2hlsl.py
# Conflicts: # CMakeLists.txt # src/startup_stubs/d3d12_draw.inl # tools/startup/gfx2hlsl.py
The union resolver truncated the R0Y00#2404 lds_b128 control block (missing PASS_REGULAR_EXPRESSION and endforeach) and registered fma_mix, fract and fract_draw twice after the updated R0Y00#2055/R0Y00#2010 heads. Configure succeeds again; every add_test of the merged PR heads is present once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of head 5a544a3 (own diff identical to the previously reviewed 29d0fe9; only a merge of main was added). Comment review, no approval.
Checked:
v_fract_f32now lowers tofract32({0}); the helper is in the common preamble and compares the encoding (asuint(f) == 0x3f800000u), matching thepixel_aotbehavior and avoiding the FXC fold of a float compare.- Cache revision moved to
x2w-startup-shader-15in gfx2hlsl.py, d3d12_draw.inl and tests/startup_indirect_draw_indexed.cpp. The compute revision (-14cs) is a separate key and is consistent between the two files. - Tests:
startup_gfx2hlsl_fract(text/lowering),startup_gfx2hlsl_fract_draw_controls, andstartup_gfx2hlsl_fract_draw_{warp,hardware}(real D3D12 draw, FXC 5_1 and DXC, readback of the -2^-30 lane). Sibling cache-key test updated to revision 15. - This is a numeric-parity fix reported by hardware runs in #1741; it does not claim a startup advance by itself.
Commands run on Linux:
python3 -B tests/startup_gfx2hlsl_fract_check.py-> PASSpython3 -B tests/startup_gfx2hlsl_buffer_store_check.py-> okpython3 tests/docs_links_check.py-> pass;python3 tests/bidi_controls_check.py-> pass;git diff --check origin/main...HEAD-> clean- Mutation: cap comparison changed to
0x3f800001u-> fract check exits 1. Mutation:fract32({0})reverted tofrac({0})-> fract check exits 1.
Win2025 WARP dev+release on this head follows in a separate receipt.
AI-assisted; commands listed were executed locally.
|
Hardware run and Windows 11 MSVC build at head Environment: Windows 11 Pro build 26300.9974, Debug ( Build: Tests:
The hardware test runs the generated pair with FXC and with DXC, each with the capped helper and with the uncapped control:
The WARP run ( Not covered by this run: this run is NVIDIA only (the PR already lists an AMD run); only the |
|
Win2025 WARP receipt for head 5a544a3 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
|
Heads-up on the startup cache revision: #2467 merged as AI-assisted. |
|
Thanks for flagging the shared cache keys. The current candidate |
- VEC_U held v_mul_i32_i24/v_mad_i32_i24 twice (main's R0Y00#2410 and a local copy); the later local entries hid main's, so its mutation controls saw no change. - s_ff1_i32_b32's compute-entry path read self.kind directly; kind-less probes (startup_gfx2hlsl_scalar_arity) raised AttributeError. - tests/startup_stream_fetch_check.py back to main: its extra sub_co_ci case pinned the text of the local co_ci handler that main's R0Y00#2428 replaced. - startup_resource_retire_title writes its draw translation with the cache revision; this branch is at x2w-startup-shader-15 (R0Y00#2010). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main moved to 16 through R0Y00#2010, so this branch takes 17 and moves the compute key with it (17cs), as MasterDomino asked in R0Y00#2095.
…rce (#2095) * startup: return the minimum of the three on v_med3_f32 with a NaN source * tests: supply the eight entry words the med3 draw fixture declares * Bump the startup shader cache revision to 16 for the med3 lowering * Update the readfirstlane uniformity fixture for the med3_32 helper rename * Bump the startup shader cache revision to 17 for the med3 lowering main moved to 16 through #2010, so this branch takes 17 and moves the compute key with it (17cs), as MasterDomino asked in #2095. --------- Co-authored-by: Panam <panam@thepatrick.world> Co-authored-by: root <root@srv1960403.hstgr.cloud> Co-authored-by: thepatrickworld <patrick@example.com> Co-authored-by: tedin7 <110300616+tedin7@users.noreply.github.com> Co-authored-by: panam <panam@local>
v_fract_f32now lowers through the cappedfract32helper thattools/pixel_aot.pyhas always used, instead of a bare D3Dfrac.The asymmetry. Two translators in this tree lower the same instruction differently:
tools/startup/gfx2hlsl.pyemittedfrac({0})forv_fract_f32with no cap, so the two paths disagreed on the one instruction whose comment in this repository says adapters disagree.What the reports show. Two independent NVIDIA runs fail
startup_gfx2hlsl_float_round_hardwareon the input0xb0800000(-2^-30) in #1741, both withexpected=3f7fffff actual=3f800000: an RTX 3070 Ti on driver32.0.16.2101, and a Quadro M1000M (Maxwell) on32.0.15.7371. The same draw passes on WARP, on an Intel HD Graphics 530 and on the RDNA 4 card used here.What changes. The helper goes into the common preamble next to
ftz32, which already carries aMatch pixel_aotnote, the table entry points at it, and a new check pins the emitted statement of the_e32and_e64forms, the cap in the preamble, and rejects both a barefracand a cap written withmin. The cap is a comparison rather thanminbecause D3Dminreturns its other operand for a NaN, and a NaN input has to stay a NaN. Onlyv_fract_f32changes.On the ISA wording, because it cuts the other way. The RDNA 2 guide gives
D.f = S0.f + -floor(S0.f)forV_FRACT_F32with no cap, and for-2^-30that expression rounds to 1.0 — which is exactly what the Quadro returns. The cap is therefore not read off that formula. It is what D3D'sfrac()produces on WARP, on an Intel Gen9 part and on this RDNA 4 card, and it is what the reference in this tree encodes. The P2 in #1741 asked for the lowering to be fixed rather than for a new draw to fail on an adapter, and suggestedmin(..., 0x3f7fffff); this patch takes the comparison form so that a NaN input stays a NaN. If the console's ownfracis later shown to return 1.0 here, the cap and the reference have to be revisited together — they must agree, and today three of the four implementations we can observe agree on the cap.What is verified here. On an AMD Radeon RX 9070 XT (
1002:7550, driver32.0.32029.2010), the wholegfx2hlslsuite passes with this patch on today'smain: 41 of 41, including the newstartup_gfx2hlsl_fractand the existing translation controls.docs_links_checkandbidi_controls_checkpass.What is not verified, and matters. There is no NVIDIA adapter on this machine. The Maxwell and Turing failures are not reproduced here, and this patch does not demonstrate that they disappear. What is established is narrower: the lowering no longer emits the uncapped
frac, the cap matches the rule the repository already wrote forpixel_aot, and the adapters that were already returning0x3f7fffffkeep doing so. The two reported adapters are what would confirm the fix.The draw that exercises
v_fract_f32is not onmainyet — it arrives with #1741 — so this change is verified at the level of the emitted text and of the existing suite, not by a draw of its own. Rebasing #1741 onto today'smainconflicts in this preamble, because the branch predates theftz32/mad32helpers, so its draws need a rebase before they can run here.AI-assisted.
Why the comparison is on the encoding. FXC treats
fracas strictly below 1, sofrac(value) >= 1.0ffolds to false and the helper compiled to a bare
frc— the cap disappeared on the Quadro M1000M and theRTX 3070 Ti, which still read
3f800000for0xb0800000. Comparing the bits survives FXC (frc,ieq,movc), andfraccan only reach the cap by rounding to exactly+1.0, so the equality covers the samecase while a NaN still misses it and passes through.
Cache revision. The cap changes already-translated shaders, so the seed goes to
x2w-startup-shader-8in
tools/startup/gfx2hlsl.pyandsrc/startup_stubs/d3d12_draw.inl; a control asserts both spellingsagree and that the
-7seed keys differently.The draw.
tests/startup_gfx2hlsl_fract_draw_check.pycompiles the generated pair with FXC (ps_5_1)and DXC (
ps_6_0) and compares raw words on0xb0800000,1.5,0.0and-2.5. The uncapped mutant isrecorded rather than asserted: on this machine WARP and the RX 9070 XT both clamp a bare
frcthemselves andread the capped word anyway, so the control cannot separate the two forms here. The separation is observed on
the NVIDIA reports above, and on the head that carries this form an independent re-run passes on WARP, on the
Quadro M1000M that failed before and on an Intel HD 530, all three reading
3f000000,3effffff,3f7fffff,3f000000for
49742408,3effffff,b0800000,4affffffunder fxc and dxc. Turing remains unmeasured.AI-assisted; runs executed on the machine above.