Repository navigation
runtime: Depth24 CPU conversions independent of the thread's rounding mode (RT-D24-CPU-ROUNDEVEN) - #1858
runtime: Depth24 CPU conversions independent of the thread's rounding mode (RT-D24-CPU-ROUNDEVEN)#1858thiefyzheng wants to merge 1 commit into
Conversation
…ad's rounding mode depth24_quantize multiplied in float and rounded with std::nearbyint, and depth24_to_float divided in double and narrowed to float; all three follow the calling thread's rounding mode, while depth24_convert.comp is roundEven of a correctly rounded product and integer arithmetic. Under FE_DOWNWARD or FE_TOWARDZERO 0x1p-23f quantised to 1, not 2, so CPU clears (vulkan_replay.h depth24_clear_value) could disagree with GPU uploads and copies. No fesetround (a library must not change the caller's environment, and fenv access can be compiled out). No existing helper fits (vulkan_replay.h's round_half_even is in a header that includes this one's users and rounds only once), so depth24_detail::round_even is floor/fmod based like it: exact in every mode. The float product is formed exactly in a double (24 x 24 bits), rounded to 24 significant bits by scaling with ldexp and round_even, then rounded to the integer, which is the shader's two roundings. depth24_to_float uses the shader's integer formula, float(m + 1) * 2^(e-47), every step exact. depth24_cpu_test (no GPU, no Vulkan loader; same pattern as clear_color_test) runs the conversions under FE_TONEAREST, FE_DOWNWARD, FE_UPWARD and FE_TOWARDZERO and compares with a float multiply + nearbyint reference run under the default mode, with fixed cases (0x1p-23f -> 2, 0.5f -> 8388608 tie to even). AI-assisted. Checked with g++ -std=c++20 -O2 (also -frounding-math, -ffast-math); not built with MSVC.
|
Tested on Windows 11 (26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, merged onto I also ran an exhaustive check with MSVC Reading the change: AI-assisted (Claude). |
|
@potatoe0100 — thank you; this closes every verification gap the PR body listed. Recording for whoever merges: on Windows/RTX 4060 (NVIDIA 621.14), the CPU test plus all device-side Depth24 tests pass ( The PR is now CPU-verified (g++ and MSVC), GPU-cross-checked on NVIDIA, and exhaustively swept — nothing left except merge. AI-assisted (orchestrator). |
Independent verification — Turing and BlackwellTested the exact merge base and PR head on two NVIDIA architectures under native Windows.
Environment
MSVC 19.44.35230, Ninja Multi-Config, RelWithDebInfo. Validated runs requested core validation, GPU-assisted validation and synchronization validation. ResultsThree initial repetitions per configuration, followed by two additional sets of validated runs. Duplicate checkpoint results were excluded using execution timestamps and SHA-256 hashes of the original CTest logs.
Across 144 unique CTest executions: 108 passed, 36 failed. Results were identical on both GPU architectures. Depth24 conversion resultsEvery execution of
Existing validation failure
The following diagnostics reproduced in every validated execution:
The symptoms match those discussed in #1475. No isolated validation-layer configuration experiment was performed to establish the cause independently. Depth24 rendering
Six internal depth-bias clamp cases per execution were skipped because
ConclusionNo new regressions were observed in the three selected CTest scenarios on either Turing or Blackwell. The existing validation-only failure remains unchanged. The new Synthetic tests only. No game files used. AI-assisted: yes, test automation and result analysis. |
|
@Timon360SB — thank you for the two-architecture sweep. Recording for the merge decision: base and head are behaviorally identical on RTX 5070 (Blackwell) and RTX 2060 SUPER (Turing) across 144 deduplicated validated ctest runs — As you note, this is hardware regression coverage; the rounding-mode invariance itself stands on the CPU receipts (g++ ASan/UBSan corpus + MSVC build & ctest + your earlier /fp:strict sweep is potatoe0100's — the exhaustive cross-arch picture is now: CPU invariance proven, device parity and non-regression proven on NVIDIA across three architectures). Together with @potatoe0100's run, only merge remains. AI-assisted (orchestrator). |
RT-D24-CPU-ROUNDEVEN
Claimed on #1608 (#1608 (comment)). Fixes @cheltyi's finding (#1608 (comment)):
runtime/src/depth24.h's CPU-side Depth24 conversion followed the calling thread's rounding mode (float multiply +std::nearbyint), whiledepth24_convert.compisroundEvenof a correctly rounded product — so a thread with directed rounding (FE_DOWNWARD/FE_TOWARDZERO) quantized0x1p-23fto 1 instead of 2 (~1 integer ULP off, beyond the documented 0.6 ULP tolerance), letting CPU clears (vulkan_replay.hdepth24_clear_value) disagree with GPU uploads/copies.depth24_to_floathad the same environment dependence.What
depth24_detail::round_even: floor/fmod-based ties-to-even, exact in every rounding mode — nofesetround, no fenv dependence, holds under-ffast-math.depth24_quantize: exactdouble(value) * 16777215.0(24×24 bits fit a double), round to 24 significant bits vialdexp+round_even, then round to integer — the shader's two roundings.depth24_to_float: the shader's integer formulaldexp(float(m+1), e-47), every step exact.vulkan_replay.h'sround_half_evenrounds once and lives in a header that includes this one's users).runtime/test/depth24_cpu_test.cpp(ctestdepth24_cpu, no GPU, no Vulkan loader; theclear_color_testpattern): runs both directions under FE_TONEAREST / FE_DOWNWARD / FE_UPWARD / FE_TOWARDZERO against a nearest-mode reference, with fixed cases (0x1p-23f -> 2,0.5f -> 8388608tie-to-even).What was run
-std=c++20 -O2(also-frounding-math): 1,858,324 checks passed across all four rounding modes (all 2^24 codes round-trip in nearest and downward; every third float pattern in [0,1] quantized nearest-vs-towardzero); plus-ffast-math: 0 mismatches. Before the fix the old header fails immediately under FE_DOWNWARD (depth24_quantize(0x1p-23) = 1, expected 2).depth24_cpu_testbuilt andctest -R depth24_cpuPassed (0.67 s).depth24_convert_test,d3d12_depth24_draw) — no Vulkan device here; the CPU/GPU cross-check on hardware would be the remaining confirmation, though both sides now implement the same documented formula.Attribution
AI-assisted (Claude Sonnet 5.5 worker implementation, contributor verification incl. the winvm MSVC build, orchestration).