Shaders: find the normalized load rounding shift with one bit scan #2893
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!2893
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2893"
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?
@Ingenioeren on GitHub · 2026-11-25 23:16 UTC · original
Ingenioeren:perf/unorm-rounding-firstbithi→main· +53 −8 · 3 files · 1 commits · openWhat changed
Use a DXIL
FirstbitHiscan to compute the rounding shift inLower::exact_norm. The previous sequence emitted seven comparisons, seven selects, and seven adds to count the powers of two reached by the runtime quotient. Setting bit 24 for the scan preserves the minimum shift of one. Higher bits still determine the shift up to eight, and the original quotient still goes into rounding. DXIL specificationEmitted DXIL
A synthetic GFX10 compute shader reads the 11-bit channel of a packed
10_11_11_UNORMbuffer at runtime and stores the resulting float bits.The whole function is 18 instructions smaller (23.1%). The regression counts live instructions selected for serialization. A DXC disassembly of both containers confirmed the counts.
How tested
cargo test --locked --offline -p victory-shader an_11_bit_unorm_load_has_a_short_rounding_sequence -- --nocaptureon the upstream emitter with the regression applied failed as expected. It reported 78 instructions against the budget of 60.cargo test --locked --offline -p victory-shader 11_bit -- --nocapturepassed both new tests. The rounding test checked 20 codes on hardware and WARP against an f64 reference rounded to f32.dxc -dumpbinon the two containers confirmed 78 instructions before and 60 after in the temporary synthetic DXIL containers.dxc -O3 -T cs_6_6retained six unsigned comparisons and emitted zero bit scans when compiling an equivalent synthetic HLSL version of the original shift calculation.cargo test --locked --offline -p victory-shaderreported 302 passed, 2 failed, and 3 ignored. Both failures reproduced on upstream842b0cbwith the same localdxil.dllPipeline State Validation rejection. They wereemit::rect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order.cargo test --locked --offline -p victory-shader --test resource_trackingreported 3 passed and 1 ignored.cargo test --locked --offline -p victory-shader --doccompleted with 0 doctests.cargo clippy --locked --offline -p victory-shader --all-targetspassed without warnings.cargo run --locked --offline -p xtask -- policy --stagedpassed for all three staged files.gh pr list --repo Marvisak/VIctory --state open --search '"UNORM" "FirstbitHi"'and searches forexact_normandnorm_quotientfound no matching change. Related proposals cover a separate normalized-conversion algorithm and single rounding for normalized d16 loads. PR #1112 PR #1940Scope of measurement
Verification used synthetic shaders. Hardware GPU time, driver-generated instruction counts, pipeline compilation time, and game behavior were unmeasured. No game files or assets were used.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
github-bot referenced this pull request2026-11-26 06:26:53 +00:00
@Marvisak on GitHub · 2026-11-26 04:28 UTC · original
Automated triage for the maintainers.
Merge candidate. This replaces the seven compare/select/add steps in
Lower::exact_norm(emit/lower.rs) with one DXIL FirstbitHi (op 33, as thes_flbit_i32_b32lowering uses). With bit 24 forced on,8 - leadingequalsbitpos - 23for bit lengths 25 to 32 and 1 below, matching the old bounds of 1 and 8, and rounding still uses the original quotient. The new test checks 11-bit UNORM codes against an f64 reference.CI: passing.
Generated by Claude Code
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.