Shaders: honor directed rounding in v_pk_mul_f16 #3811

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/3811 into main
andrewpozdnakov7-jpg commented 2026-11-28 23:51:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:51:39Z.


v_pk_mul_f16 now rounds each 16-bit product in the active half-precision mode. It reuses the exact-product narrowing from #3804. This branch includes that scalar prerequisite. The final commit covers packed multiplication and its regression.

The regression checks 529 input rows for each of four rounding modes and two operand selections. The second selection exchanges one input's halves and applies different negations. On 386cc0f, each directed mode mismatched 189 of 1,058 packed words per software invocation. After the fix, all 8,464 packed words matched the CPU reference on two app-local Microsoft WARP invocations. The scalar multiply test, existing FP16 controls, 33 lowerer tests, both strict Clippy configurations and the asset policy passed.

The specification describes the half rounding modes and the two packed products. AMD RDNA 2 ISA, sections 6.4 and 12.10

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5545783184 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3811). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:51:39Z. --- `v_pk_mul_f16` now rounds each 16-bit product in the active half-precision mode. It reuses the exact-product narrowing from [#3804](https://github.com/Marvisak/VIctory/pull/3804). This branch includes that scalar prerequisite. The final commit covers packed multiplication and its regression. The regression checks 529 input rows for each of four rounding modes and two operand selections. The second selection exchanges one input's halves and applies different negations. On `386cc0f`, each directed mode mismatched 189 of 1,058 packed words per software invocation. After the fix, all 8,464 packed words matched the CPU reference on two app-local Microsoft WARP invocations. The scalar multiply test, existing FP16 controls, 33 lowerer tests, both strict Clippy configurations and the asset policy passed. The specification describes the half rounding modes and the two packed products. [AMD RDNA 2 ISA, sections 6.4 and 12.10](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 23:55:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:55:02Z.


Windows CI passed on 535a68d, including both Clippy configurations and workspace tests. The packed multiply regression matched 8,464 result words on the two local WARP invocations. It covers both ordinary packed operands and independent half selection and sign changes.

The next step is maintainer review alongside the scalar prerequisite #3804. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247748217 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3811#issuecomment-7247748217). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:55:02Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46203612699/job/141161133450) passed on `535a68d`, including both Clippy configurations and workspace tests. The packed multiply regression matched 8,464 result words on the two local WARP invocations. It covers both ordinary packed operands and independent half selection and sign changes. The next step is maintainer review alongside the scalar prerequisite #3804. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-29 00:22:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-29T00:22:18Z.


I combined #3811 at 535a68d with the #3803/#3804 comparison at 9248dba and #3807 at afadaa9. The three inputs keep their original Git history. The merge retains all four regressions and shares one directed narrowing path for the two conversions and both scalar and packed multiplication. The packed path continues to round after half selection, sign changes and saturation.

On ecb7a6b, WARP 1.0.22 with Agility 1.620.2 matched all result words across two software-device invocations:

Regression Matched readbacks
Packed FP16 multiplication, four modes and two operand variants 8,464
Scalar FP16 multiplication, four modes 4,232
FP32-to-FP16 conversion, modes 1 and 2 200
Signed and unsigned 16-bit integer conversions, all input codes and four modes 1,048,576

The existing FP32-to-FP16 modes 0 and 3 control, all 33 lowerer tests, both strict shader Clippy configurations and the asset policy also passed. The combined lower.rs is 522,828 bytes. A physical GPU run of this integration is pending.

Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the integration into another commit. Comparison branch

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7248065747 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3811#issuecomment-7248065747). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-29T00:22:18Z. --- I combined #3811 at `535a68d` with the #3803/#3804 comparison at `9248dba` and #3807 at `afadaa9`. The three inputs keep their original Git history. The merge retains all four regressions and shares one directed narrowing path for the two conversions and both scalar and packed multiplication. The packed path continues to round after half selection, sign changes and saturation. On `ecb7a6b`, WARP 1.0.22 with Agility 1.620.2 matched all result words across two software-device invocations: | Regression | Matched readbacks | | --- | ---: | | Packed FP16 multiplication, four modes and two operand variants | 8,464 | | Scalar FP16 multiplication, four modes | 4,232 | | FP32-to-FP16 conversion, modes 1 and 2 | 200 | | Signed and unsigned 16-bit integer conversions, all input codes and four modes | 1,048,576 | The existing FP32-to-FP16 modes 0 and 3 control, all 33 lowerer tests, both strict shader Clippy configurations and the asset policy also passed. The combined `lower.rs` is 522,828 bytes. A physical GPU run of this integration is pending. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the integration into another commit. [Comparison branch](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/3811-fp16-directed-integration) AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-29 00:24:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-29T00:24:38Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3811 at head 535a68ded604e606e0c11d1f9fad2bd287ce9d32; this PR stacks on #3804, so its single-commit parent/base is 386cc0fcc55351a2d8722f0a0ceef7c20423d185.
  • I replayed only the distinct new test: cargo test --locked -p victory-shader --lib -- emit::semantics_tests::packed_f16_multiply_honors_round_mode --exact --test-threads=1 --quiet → 1 passed, 0 failed, 306 filtered, exit 0. The other added test (f16_multiply_honors_round_mode) duplicates the one already verified independently in #3804, so I did not replay it here.
  • git grep -F for packed_f16_multiply_honors_round_mode on the parent returned no match (test is new); git diff --check HEAD^ HEAD clean (2 files, +43/-6 relative to its parent).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only shader IR test, synthetic inputs). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7248093304 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3811#issuecomment-7248093304). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-29T00:24:38Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3811 at head `535a68ded604e606e0c11d1f9fad2bd287ce9d32`; this PR stacks on #3804, so its single-commit parent/base is `386cc0fcc55351a2d8722f0a0ceef7c20423d185`. - I replayed only the distinct new test: `cargo test --locked -p victory-shader --lib -- emit::semantics_tests::packed_f16_multiply_honors_round_mode --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 306 filtered, exit 0. The other added test (`f16_multiply_honors_round_mode`) duplicates the one already verified independently in #3804, so I did not replay it here. - `git grep -F` for `packed_f16_multiply_honors_round_mode` on the parent returned no match (test is new); `git diff --check HEAD^ HEAD` clean (2 files, +43/-6 relative to its parent). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally. - GPU/driver: N/A (CPU-only shader IR test, synthetic inputs). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
passerbyyhx commented 2026-12-01 14:03:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-12-01T14:03:13Z.


The standalone packed change now has a physical NVIDIA comparison. On an RTX 4090 Laptop and WARP at 535a68de, all 4,232 packed words per adapter matched the CPU model across four rounding modes, two operand selections and 529 input rows. On the immediate scalar-fixed parent 386cc0fc, rounding toward +∞ gave 90 + 99 mismatches across the two selections and rounding toward −∞ gave 99 + 90 on each adapter. Nearest-even and toward-zero matched on both revisions. The physical device and WARP agreed in every case, including the parent's incorrect outputs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7313617484 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3811#issuecomment-7313617484). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-12-01T14:03:13Z. --- The standalone packed change now has a physical NVIDIA comparison. On an RTX 4090 Laptop and WARP at `535a68de`, all 4,232 packed words per adapter matched the CPU model across four rounding modes, two operand selections and 529 input rows. On the immediate scalar-fixed parent `386cc0fc`, rounding toward +∞ gave 90 + 99 mismatches across the two selections and rounding toward −∞ gave 99 + 90 on each adapter. Nearest-even and toward-zero matched on both revisions. The physical device and WARP agreed in every case, including the parent's incorrect outputs.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3811:upstream-pr/3811'
git switch 'upstream-pr/3811'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3811'
git switch 'upstream-pr/3811'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3811'
git switch 'upstream-pr/3811'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3811'
git switch 'main'
git merge --squash 'upstream-pr/3811'
git switch 'main'
git merge --ff-only 'upstream-pr/3811'
git switch 'main'
git merge 'upstream-pr/3811'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3811
No description provided.