Skip to content

shader_diff: keep integer operands clean when all scratch registers are float-tainted - #3189

Open
frnandoooo wants to merge 1 commit into
ItsNotRexed:mainfrom
frnandoooo:fix/shader-diff-clean-operands
Open

frnandoooo wants to merge 1 commit into
ItsNotRexed:mainfrom
frnandoooo:fix/shader-diff-clean-operands

Conversation

@frnandoooo

Copy link
Copy Markdown
Contributor

generate_program(random.Random(3179), 150) emits v_add_nc_u32 v13, v9, v10 at body line 70 after all eight scratch registers have been written by floating-point operations. The empty-clean-pool fallback then selects potentially oracle-specific NaN payload bits as integer operands, violating the harness's documented invariant and permitting false differential mismatches.

When an integer operation has no clean sources, emit a literal-zero move to its destination before selecting its operands. Float operations retain their existing source selection. The last-writer report still points to the actual generated operation. This adds one move only at the exhausted-pool boundary; generated programs that reach that boundary can change.

Tests check that no integer instruction reads a float-tainted value, seed 3179 actually exercises recovery, last-writer indices remain correct, and generation is deterministic. Seeds 1 and 99 provide additional invariant coverage.

Claim: #3047 (comment) (new TEST item; ID pending).
Separate from open #2412, which makes the scalar copy observable; this PR changes operand selection earlier in the generator and does not depend on that PR.

Validation on Windows, Python 3.14, pytest 9.2.0:

  • python -m pytest tests/test_shader_diff.py -q: 15 passed.
  • Negative control with upstream tools/shader_diff.py: seed 3179 fails at the unsafe integer add; seeds 1 and 99 pass. Restoring the fix passes all three.
  • python -I tools/shader_diff.py --self-test: canaries pass.
  • python -m unittest discover -s tests/semantic -q: 4,142 tests run, OK (4 skipped), 464 seconds.
  • Python compileall, python -I make_game.py --help, and git diff --check: pass.

No game files, LLVM, or GPU used. This is a test-generator fix, not a translator semantic change. The reproduced evidence is an operand-taint invariant violation; we do not claim to have measured a real GPU false mismatch.

AI-assisted with Codex (reproduction, implementation, tests) and Claude Code (independent static patch review). Claude found no blockers; its test-comment clarification was incorporated. Its review did not execute tests and is not maintainer approval.

@tupacfan04

Copy link
Copy Markdown
Contributor

Sound, approve after a trivial rebase.

pytest tests/test_shader_diff.py 15 passed, compileall clean, and the fix is still needed on current main (pool = SCRATCH if name in _FLOAT_OPS or not clean else clean), with the patch auto-merging cleanly into tools/shader_diff.py. Negative control: base tools/shader_diff.py fails at seed 3179 (tests/test_shader_diff.py:36), and a property scan over 400 seeds found 0 tainted integer reads.

One conflict: tests/test_shader_diff.py:52 keeps the old test_program_generation_is_deterministic, which main superseded in 8b20b950 with a parametrized rewrite; drop it. A simulated merge with that resolution gives 20 passed.

Approve. AI-assisted review, no game files, no GPU.

@frnandoooo

Copy link
Copy Markdown
Contributor Author

Rebased onto current main, keeping the upstream parametrized determinism/scalar-observability tests and adding our taint regressions alongside them. The obsolete determinism test is removed. Validation: tests/test_shader_diff.py 20 passed; shader_diff --self-test canaries pass; git diff --check clean. Thanks for the independent review.

@frnandoooo
frnandoooo force-pushed the fix/shader-diff-clean-operands branch from 05382a7 to ef8ddab Compare November 23, 2026 13:54
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