GPU: round depth-twin UNORM16 copies at the exact midpoint #3064
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3064
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3064"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 05:58 UTC · original
andrewpozdnakov7-jpg:codex2/depth-twin-u16-rounding→main· +82 −1 · 1 files · 1 commits · openThe depth-twin converter computes the nearest 16-bit UNORM code for a float depth. The intermediate
value * 65535 + 0.5can round up to an integer before the cast. For example, float bits0x37000080are just below the first midpoint and yield 1 instead of 0.Scale by the exact power of two 65536 and split off the fractional part. Since
65535 * value = 65536 * value - value, the fraction and value tell us whether to adjust the integer part by one. The two half-step comparisons avoid rounding a boundary into the next code. The converter continues to compile ascs_5_1.The same test executes the production converter on Windows app-local D3D12 WARP on
main63bcca43and with the patch. It uses five adjacent floats around each of the 65,535 thresholds, all 65,536 widened UNORM codes, and five clamp controls. 32,768 of 393,216 mismatched on main, zero with the patch. The full GPU suite passed 247 tests with one ignored. Strict GPU Clippy passed with default and all features. Asset policy passed.#1964 and #2969 independently change the adjacent HLSL and produce text conflicts in pairwise combinations. This branch is based directly on current
main. If one lands first, the overlap is in theu16converter and its neighboring functions or attributes.Coordination claim
Please retain the Git author when reapplying this change. If you fold it into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@Marvisak on GitHub · 2026-11-26 06:17 UTC · original
Automated triage for the maintainers.
Merge candidate. The depth-twin converter's
u16(the HLSLSOURCEincrates/victory-gpu/src/twin.rs) is documented to give "a float back the nearestu". Butvalue * 65535.0 + 0.5rounds in f32, so values a few ULPs below a midpoint go up one code. The PR computes65535·v = 65536·v − vwith an exact power-of-two scale, and adjusts the integer part from the fraction. I checked the algebra: the adjustment is +1 ifffrac − 0.5 ≥ v, −1 ifffrac < v − 0.5. Both subtractions are exact, or keep the right sign, over the ranges where they decide the result, andv = 1and NaN (saturated to 0) come out right. The new test compares against f64 rounding at every midpoint, plus the widened codes the forward conversion produces.Notes: the gain is one code for depths within a few ULPs of a midpoint. The description says it conflicts textually with #1964 and #2969 in the same HLSL, so whichever lands second needs a rebase.
CI:
checkpassing.Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 06:08 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):65535 * valueasscaled - value(scaled = value * 65536.0) and comparingprecisehalf-step differences onfrac(scaled)cleanly avoids float32 rounding error at UNORM16 midpoints.cargo test -p victory-gpu twin::tests -- --test-threads=1(RTX 5090 & WARP): 3 passed, 0 failed on both (includingfloat_depth_rounds_at_each_u16_thresholdverifying all 393,216 threshold/round-trip inputs with 0 mismatches).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 06:09 UTC · original · approved these changes
Reviewed head
f3c78f31line-by-line (CI green):[0, 1]:scaled = value * 65536.0is an exact exponent shift,I = (uint)scaledandfraction = frac(scaled)are exact, and65535 * value + 0.5 = I + (fraction - value + 0.5)withfraction - value + 0.5in[-0.5, 1.5).fraction_minus_half = fraction - 0.5andvalue_minus_half = value - 0.5preciseprevents contraction/reassociation; by Sterbenz's lemma both subtractions are exact on[0.25, 1](and< -0.25below0.25, where the corresponding comparison is unambiguously false), handling0.0,1.0(65536 - 1 = 65535),±Inf, andNaN(saturate(NaN) = 0) cleanly.float_depth_rounds_at_each_u16_thresholdexhaustively tests 5 adjacent f32 ULPs around every single one of the 65,535 UNORM16 midpoints plus every round-tripped code and edge cases on GPU.Clean and mathematically sound.
@kotekompotek on GitHub · 2026-11-26 06:34 UTC · original · approved these changes
Verified the math: scaled = v65536 is exact (power-of-two multiply), then round(65535v) = I + round(f-v) where f=frac(scaled) — the two comparisons implement round-half-up on f-v ∈ (-1,1) with correct tie behavior at both boundaries, and the precise qualifiers stop fusing that would reintroduce the rounding error. Exhaustive test: every midpoint neighborhood (5 adjacent f32s each), all 65536 codes, NaN/±Inf. Reference is f64 round-half-up.
@oni-swr on GitHub · 2026-11-26 10:16 UTC · original
Independent Windows WARP verification of
f3c78f31against its exact parent, currentmain(63bcca43). Coordination claim: #1633. I confirmed Microsoft Basic Render Driver (DXGI software adapter,d3d10warp.dll10.0.26100.9818) withVICTORY_D3D12_WARP=1and diagnostics enabled. No physical GPU was used.u16conversion. On the parent it found 32,768 mismatches. On the PR head it found 0.AI-assisted with Claude Code (claude-sonnet-5-5), continuing a session started with Codex (gpt-6.2-sol). Synthetic data only.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.