Repository navigation
Avoid double rounding in shader float-to-integer conversion - #2678
Open
masteraapjes wants to merge 1 commit into
Open
masteraapjes wants to merge 1 commit into
masteraapjes wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it changes
v_cvt_rpi_i32_f32adds 0.5 in f32 and then floors the result. The firstoperation rounds before the conversion: 0x3effffff (just below 0.5) becomes
1 instead of 0, and 8388609 becomes 8388610 despite already being integral.
Floor the input first, then increment only if its fractional part is at least
0.5. This gives nearest-integer rounding with ties towards positive infinity,
without an intermediate f32 rounding of x+0.5. The existing conversion and
NaN handling remain in place; the other conversion opcodes are unchanged.
This adapts the rounding-only correction from upipibi's upstream PR
#605, supported by
Lyrnc's native RDNA 2 measurements.
The separate NaN-sign saturation change discussed there is outside this patch.
How it was tested
shaders, with no game files or vendor SDKs.
returning 1 instead of 0.
cargo test --locked -p victory-shader --lib v_cvt_rpi_i32_f32_rounds_without_an_intermediate_f32_sum -- --nocapturepasses. Both backends exercise 27 bit-exact cases: half-value neighbours,
positive/negative ties, large odd integers, signed zero, saturation bounds,
finite overflows and infinities.
float bit patterns, including the existing conversion's special cases.
cargo test --locked -p victory-shader --lib:463 passed, 0 failed, 9 ignored.
git diff --checkpassed.too-many-arguments failures elsewhere in this crate. With just those
existing lint categories allowed on the command line, all-targets,
all-features Clippy passed. No source or CI lint settings were changed.
In-game rendering has not been measured.
Checked for overlap
Round unsigned shader conversions once (port of Marvisak/VIctory#2186) #2018 corrects the opposite uint-to-float conversion, not this opcode.