Translate scalar zero-bit counts #3566

Closed
github-bot wants to merge 2 commits from github-bot/gh-3566 into main AGit
Owner

@⁠xiepeixuan on GitHub · 2026-11-30 01:09 UTC · original
xiepeixuan:auto/shader-scalar-zero-count → main · +72 −3 · 3 files · 2 commits · closed without merging

Refs #1138 (overlap map) and #3389 (a separate scalar-opcode fix). No issue is claimed as fixed.

What it changes

AMD RDNA 2 ISA §12.3, opcodes 13 and 14, gives the same rule over 32 and 64 source bits: “D += (S0[i] == 0 ? 1 : 0)”; “SCC = (D != 0).”

The decoder and SSA already handle these instructions, but a live result is refused by the emitter. Reuse the existing DXIL Countbits lowering, which counts ones, and subtract from the source width. The 64-bit form counts both dwords and adds the counts before subtracting. Both forms set SCC from the resulting zero-bit count.

Uses audit: decoding, operand widths, SSA effects and folded-wave rewriting are unchanged; the existing split of a 64-bit count now has a working 32-bit lowering. The already-supported ones counts and first-set-bit op still emit the same instructions. BCNT1-specific lane-mask paths are not widened by this change. The translator source fingerprint covers this change; no cache-key policy or settings change. Cost before optimisation: one Countbits plus one subtraction for a 32-bit source; two Countbits, one add and one subtraction for a 64-bit source; one nonzero comparison for live SCC. No new branch or 64-bit DXIL integer capability. No production code was ported. The portable test scaffolding follows xiepeixuan's #3389.

Expected effect on NVIDIA

Tier A: shader refusal. A shader with a live scalar zero-bit count (for example, when handling a packed mask or using SCC to choose a path) now lowers. A draw or dispatch using that shader can otherwise be dropped, including on NVIDIA hosts. The refusal and repair are confirmed in a standalone synthetic shader; no specific game scene or frequency was measured.

How it was tested

  • GPU and profile: none for the regression; synthetic unit tests only. Wave32 and Wave64 both exercise the 32- and 64-bit operand forms, with all-zero/all-one/mixed inputs, including a zero in only the upper or lower dword. s_addc_u32 makes SCC observable.
  • Before: scalar_zero_bit_counts_update_scc on main 41adb55167fa plus the test alone failed with Wave32: Unsupported { offset: 40, what: "s_bcnt0_i32_b32" } (cargo exit 101). Unmodified Linux crate suite: 295 passed, 0 failed, 2 ignored. Baseline CI.
  • After: regression exit 0 on Linux and Windows at exact commit 58a5d021b22e119698e941ff5c7524221828c031. Linux crate suite: 296 passed, 0 failed, 2 ignored. Linux CI.
  • Windows cargo check --workspace --locked: exit 0 on both pristine main and the exact fix. Unfiltered crate: 457 → 458 passed, 5 failed, 9 ignored, with the same failing test names. After excluding only the baseline failures: 458 passed, 0 failed, 9 ignored. Both strict Clippy modes have the same pre-existing errors. Windows comparison.
  • cargo test passed for the changed crate: yes on Linux and on Windows after excluding only the confirmed baseline failures. Production-only rollback in a separate checkout restored the original file hash and the original exit-101 failure. Rollback CI.

Checked for overlap

  • Searched 900 all-state PRs and all 679 open PRs by title, body and changed files. Read #1138, reviewed 82 open diffs listing the production file, and read the matching function/evaluator hunks in #831, #1972, #2165, #2220, #2676, #3389, #3501. #3389 now covers conditional moves, not zero-bit counts. #3402 and #388 discuss the existing ones-count mask path. Repeated the check immediately before opening.
  • Opened as a draft early so others know this is being worked on (README: 'Opening a draft pull request early works too'). Contribution guidance.

AI-assisted (Codex). Not run in the game.

**@⁠xiepeixuan** on GitHub · 2026-11-30 01:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3566) `xiepeixuan:auto/shader-scalar-zero-count` → `main` · +72 −3 · 3 files · 2 commits · closed without merging Refs #1138 (overlap map) and #3389 (a separate scalar-opcode fix). No issue is claimed as fixed. ## What it changes [AMD RDNA 2 ISA §12.3](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content#page=120), opcodes 13 and 14, gives the same rule over 32 and 64 source bits: “D += (S0[i] == 0 ? 1 : 0)”; “SCC = (D != 0).” The decoder and SSA already handle these instructions, but a live result is refused by the emitter. Reuse the existing [DXIL Countbits](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst) lowering, which counts ones, and subtract from the source width. The 64-bit form counts both dwords and adds the counts before subtracting. Both forms set SCC from the resulting zero-bit count. Uses audit: decoding, operand widths, SSA effects and folded-wave rewriting are unchanged; the existing split of a 64-bit count now has a working 32-bit lowering. The already-supported ones counts and first-set-bit op still emit the same instructions. BCNT1-specific lane-mask paths are not widened by this change. The translator source fingerprint covers this change; no cache-key policy or settings change. Cost before optimisation: one Countbits plus one subtraction for a 32-bit source; two Countbits, one add and one subtraction for a 64-bit source; one nonzero comparison for live SCC. No new branch or 64-bit DXIL integer capability. No production code was ported. The portable test scaffolding follows xiepeixuan's #3389. ## Expected effect on NVIDIA **Tier A: shader refusal.** A shader with a live scalar zero-bit count (for example, when handling a packed mask or using SCC to choose a path) now lowers. A draw or dispatch using that shader can otherwise be dropped, including on NVIDIA hosts. The refusal and repair are confirmed in a standalone synthetic shader; no specific game scene or frequency was measured. ## How it was tested - GPU and profile: none for the regression; synthetic unit tests only. Wave32 and Wave64 both exercise the 32- and 64-bit operand forms, with all-zero/all-one/mixed inputs, including a zero in only the upper or lower dword. `s_addc_u32` makes SCC observable. - Before: `scalar_zero_bit_counts_update_scc` on main `41adb55167fa` plus the test alone failed with `Wave32: Unsupported { offset: 40, what: "s_bcnt0_i32_b32" }` (cargo exit 101). Unmodified Linux crate suite: 295 passed, 0 failed, 2 ignored. [Baseline CI](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46332119107/job/141564114891). - After: regression exit 0 on Linux and Windows at exact commit `58a5d021b22e119698e941ff5c7524221828c031`. Linux crate suite: 296 passed, 0 failed, 2 ignored. [Linux CI](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46332389310/job/141564945431). - Windows `cargo check --workspace --locked`: exit 0 on both pristine main and the exact fix. Unfiltered crate: 457 → 458 passed, 5 failed, 9 ignored, with the same failing test names. After excluding only the baseline failures: 458 passed, 0 failed, 9 ignored. Both strict Clippy modes have the same pre-existing errors. [Windows comparison](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46332389310/job/141564945466). - `cargo test` passed for the changed crate: yes on Linux and on Windows after excluding only the confirmed baseline failures. Production-only rollback in a separate checkout restored the original file hash and the original exit-101 failure. [Rollback CI](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46332389310/job/141564945183). ## Checked for overlap - [x] Searched 900 all-state PRs and all 679 open PRs by title, body and changed files. Read [#1138](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/issues/1138), reviewed 82 open diffs listing the production file, and read the matching function/evaluator hunks in #831, #1972, #2165, #2220, #2676, #3389, #3501. #3389 now covers conditional moves, not zero-bit counts. #3402 and #388 discuss the existing ones-count mask path. Repeated the check immediately before opening. - Opened as a draft early so others know this is being worked on (README: 'Opening a draft pull request early works too'). [Contribution guidance](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/d4599073159082b0eba33c711ab25e2977ef3458/README.md). AI-assisted (Codex). Not run in the game.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:14:25 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:51 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3566#issuecomment-7321671372) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
github-bot closed this pull request 2026-12-01 18:58:19 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3566
No description provided.