Skip to content

Shaders: a uniform branch can pick between immediate samplers - #223

Merged
pablogonz12 merged 2 commits into
mainfrom
int/dxrest-sampler
Nov 25, 2026
Merged

pablogonz12 merged 2 commits into
mainfrom
int/dxrest-sampler

Conversation

@pablogonz12

@pablogonz12 pablogonz12 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Shaders: a uniform branch can pick between immediate samplers

Port of the shader half of DexNom's ddb73326 (author kept; the blending half of that commit is separate and already in main).

Two different immediate samplers (say wrap in one arm, clamp in the other) that
reach one image_* through a phi were treated as "an untracked sampler", or as
a single static binding. Lower::image now samples once per constant with the
original derivatives, selects the texel on the same edge that supplied the
console's sampler, and otherwise falls back to the single tracked sampler
(image_with_sampler, which the old body became).

Test: lower.rs::a_uniform_branch_can_choose_between_immediate_samplers builds
hand-written instruction words for s_cmp_eq_u32 + s_cbranch_scc1 around two
s_mov_b32 sampler writes, followed by image_sample_lz, and asserts both
sampler words (0x00000000 and 0x00000092) reach the module.

Gates

  • cargo test -p victory-shader: 199 passed, 0 failed (3 ignored).
  • cargo xwin clippy --workspace --all-targets -- -D warnings: clean.
  • offline-check, 751 world programs: 751/751 translated, 751 pipelines.
  • offline-check, victory-run 2,912: 2,909 ok, the same 3 known dxil-spirv
    converter crashes; 0 of 2,912 programs' DXIL changed — no program in these
    dumps takes this path, so the fix only affects programs that do (off-dump).
  • cargo xtask policy: 258 files ok; no title names.

Off switch: none — the change only replaces a refusal (or a wrong sampler) with
the console's choice.

Not tested in a game run.

Summary by CodeRabbit

  • Bug Fixes
    • Improved shader image sampling when a conditional branch selects between different samplers. Sampling now uses the sampler from the reachable branch when the other branch cannot be reached, and correctly selects between results when both branches are reachable.

DexNom and others added 2 commits November 25, 2026 23:45
Ported from DexNom's ddb73326 (shader half; the blending half is its own PR).

(cherry picked from commit ddb73326b58f6baafce0d0b7d9d2ce30e66a7b44)

Co-authored-by: DexNom <29156494+DexNom@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Sampler phi lowering

Layer / File(s) Summary
Handle sampler phis during image lowering
crates/victory-shader/src/emit/lower.rs
Lower::image uses the reachable sampler when the other predecessor is unreachable. When both edges are reachable, it lowers the image operation with each sampler and selects between the results. The helper accepts an explicit sampler source. A test checks that both immediate sampler constants appear in the emitted shader.

Possibly related PRs

Suggested reviewers: uiliannn, fxceless

Change: Bug fix

Merge Risk: Minimal · up to 96188

This change lets shader lowering handle a uniform branch that selects between two constant samplers. Other sampler cases keep their existing behavior. No merge-blocking issue was found. A loop-header sampler choice is still unsupported, as it was before this change, and the path has not been tested in a game run.

Security architecture risk: Low · up to 96188

The change keeps texture access on the existing path, but it can reach a fixed sampler limit sooner. It is not confirmed that shaders at that limit fail cleanly.

Retained concerns

  • Low · reliability · inferred: One newly accepted instruction can register two distinct static samplers, bringing forward a pre-existing capacity limit. Registration uses an unchecked index into a 64-bit comparison mask. If an out-of-range index reaches that code, shader compilation can fail without returning the normal lowering error; whether an earlier limit prevents this or the caller contains the failure remains unverified.
Security review details

Security Blast Radius

  • inferred — The new branch can emit two sampling variants per qualifying instruction against the same texture. The inspected path does not establish new resource authority or a new external entrypoint.

Trust Boundaries and Controls

  • observed — Only decoded sample, gather, and level-of-detail query instructions receive a sampler operand. Resource analysis tracks that operand separately from the texture, so ordinary image stores and atomics do not enter the two-sampler path.

Hardening Proposals

  • proposed — Enforce the supported sampler capacity before registering a new binding, or store comparison metadata per binding. Verify that exceeding any supported limit returns a recoverable shader error.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7ca69ed4-aec9-427d-bf6c-6deeead80c2c
Commits

Reviewing files that changed from the base of the PR and between 6319223 and 96188ab.

Files selected for processing: 1

  • crates/victory-shader/src/emit/lower.rs

Limit details: You’ve used all 10 included reviews currently available.

@pablogonz12
pablogonz12 merged commit cffc291 into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants