Skip to content

Fix the black world from the loop-cap barrier refusal and two merge slips - #506

Merged
pragyaangaur merged 6 commits into
mainfrom
fix-cap-barriers-opt-in
Nov 27, 2026
Merged

pragyaangaur merged 6 commits into
mainfrom
fix-cap-barriers-opt-in

Conversation

@pragyaangaur

@pragyaangaur pragyaangaur commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Issue #497 (4TheDoctor, M3 Max) and hackgods (M5 Pro) bisected a black world on main to #408: its rule refuses 15 to 37 compute shaders (the tile-list, lighting, temporal anti-aliasing and average luminance programs) because a lane may leave at a capped loop's iteration limit while the others wait at an s_barrier. Keeping those barriers, as before #408, draws the world on both Macs without hangs in their runs. This makes the refusal opt-in with VICTORY_CAP_BARRIERS=1 (documented in docs/macos.md), and the shader cache key follows the switch.

Two slips from the same round of merges are fixed too. #435 or #440 made halves_tests build on every host, but it uses the Windows-only validator, so cargo test -p victory-shader did not build on a Mac. It is Windows-only again. And #406 made the legacy multiply-add fused, as RDNA 2 decodes v_mad_legacy_f32 and v_mac_legacy_f32, but the reference model in semantics_tests still composed a multiply and an add, so arithmetic_matches_the_hardware failed on any machine with a hardware GPU (CI has none, so it stayed green). The model now follows the fused rule, and the test passes under Wine with D3DMetal.

Checks: native workspace tests, clippy for both feature sets on the Windows target, the asset policy, and the victory-shader tests under Wine.

A third slip from #440 is fixed here as well, found by hackgods and the #435 rebase: with the predication on, a v_writelane_b32 into a lane that the block leaves inactive was lost in the merge after the block (the lane read 0 where the console reads the written value), and nothing in CI notices because the test that shows it needs a hardware GPU. Such a write is now refused in a predicated block, and the whole-wave retry of #435 takes the program, which gives the console's value again.

@hackgods hackgods left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 4c87cf7 in-game on the M5 Pro (diagnostics build, same save as #497): the world renders lit (cell, player and yard; mean luma 44–47 at 200, 300 and 400 frames into the world). 34 compute shaders are refused, none of them at the loop cap. Main without this PR drew it white with 47 refused (15 at the cap). Thanks for picking this up.

One gap in the tests. cap_barriers_refused() is hard-coded to true in test builds (mod.rs +487–490), so the default that ships, barriers kept, is never exercised. Inverting the gate at lower.rs:4255 would pass every test. A per-thread override (like with_thread_ticket) plus a test both ways would cover it. Ours is an_s_barrier_after_a_capped_loop_is_kept_unless_the_switch_refuses_it on hackgods@9e68076 (lower/tests.rs), if it's useful.

Minor points:

  • cap_barriers_from doesn't trim, so VICTORY_CAP_BARRIERS=" 1" stays off.
  • shader_cache.rs:677 fails if the tests run with VICTORY_CAP_BARRIERS=1 set.

Prepared with Claude Code.

hackgods added a commit to hackgods/VIctory-macOS that referenced this pull request Nov 27, 2026
DispatchX(x, y, z, flags) with flag 0x20 (the console's dispatch
initiator bit "use thread dimensions") gives thread counts. The host
ignored the flags and ran x * y * z groups, so a ray-tracing structure
builder stage dispatched this way ran up to 64 times its threads and
stored over the structures after its own.

The host now runs the groups that hold the threads (div_ceil by the
program's numthreads, kept in pipeline::Translated). Where the last
group along x is a part of one, the dispatch takes a second form of the
pipeline (pipeline::thread_limited), made on the first such dispatch:
its shader translated again with emit::Options::thread_limits, under a
cache key of its own (bit 9 of translation_build, after pragyaangaur#511's halves
apart and pragyaangaur#506's cap barriers). In that form a compute program of one dimension whose lanes
never wait for each other (no s_barrier, no barriers for narrow host
waves, not in 32-lane halves that pass values, not in literal halves,
whose group must take one path) reads a user-data word,
emit::USER_DISPATCH_THREADS_X, the threads along x that run, and the
lanes past it leave before anything else, so wave counts, first-lane
reads and stores see only the lanes the console starts. The host sets
the word after binding. Every other translation is as before, so
programs no such dispatch reaches keep their DXIL; containers of
one-dimensional compute programs are kept for the second translation
(at most the ~22 MB all compute containers came to in a world run).
The lowering's part is in lower/thread_limits.rs and lower/retry.rs,
so lower.rs stays under the file limit. Each pipeline's first dispatch
counted in threads is logged ("a dispatch counted in threads"), with a
warning where a part of a group runs whole. VICTORY_THREAD_DIMENSIONS=0
takes the counts for groups again.

Ported from DexNom/VIctory bc3cd4b0 (DexNom: the flag, and the lanes
past the count leaving in two builder programs chosen by digest), as
carried in the cool_fox fork's 810efe5 (RyanLockwoood/VIctory-cool_fox-
LockWood). This tree has no builder detection, hence the form made on
demand.

Tests: halves_tests::the_lanes_past_a_count_of_threads_do_not_run
(wave32 and wave64 on the host, counts 0 to 128 over two groups of 64);
halves_tests::only_programs_whose_lanes_never_wait_leave_past_a_count_
of_threads (pragyaangaur#435's whole-wave retry included: a program it takes reads
no count); thread_dispatch_tests::a_dispatch_counted_in_threads_runs_
only_those_threads, from a console container through State::dispatch_x:
threads 70 to 127 write nothing, the pipeline's own translation reads
no count (fails with VICTORY_THREAD_DIMENSIONS=0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hackgods added a commit to hackgods/VIctory-macOS that referenced this pull request Nov 27, 2026
DispatchX(x, y, z, flags) with flag 0x20 (the console's dispatch
initiator bit "use thread dimensions") gives thread counts. The host
ignored the flags and ran x * y * z groups, so a ray-tracing structure
builder stage dispatched this way ran up to 64 times its threads and
stored over the structures after its own.

The host now runs the groups that hold the threads (div_ceil by the
program's numthreads, kept in pipeline::Translated). Where the last
group along x is a part of one, the dispatch takes a second form of the
pipeline (pipeline::thread_limited), made on the first such dispatch:
its shader translated again with emit::Options::thread_limits, under a
cache key of its own (bit 9 of translation_build, after pragyaangaur#511's halves
apart and pragyaangaur#506's cap barriers). In that form a compute program of one dimension whose lanes
never wait for each other (no s_barrier, no barriers for narrow host
waves, not in 32-lane halves that pass values, not in literal halves,
whose group must take one path) reads a user-data word,
emit::USER_DISPATCH_THREADS_X, the threads along x that run, and the
lanes past it leave before anything else, so wave counts, first-lane
reads and stores see only the lanes the console starts. The host sets
the word after binding. Every other translation is as before, so
programs no such dispatch reaches keep their DXIL; containers of
one-dimensional compute programs are kept for the second translation
(at most the ~22 MB all compute containers came to in a world run).
The lowering's part is in lower/thread_limits.rs and lower/retry.rs,
so lower.rs stays under the file limit. Each pipeline's first dispatch
counted in threads is logged ("a dispatch counted in threads"), with a
warning where a part of a group runs whole. VICTORY_THREAD_DIMENSIONS=0
takes the counts for groups again.

Ported from DexNom/VIctory bc3cd4b0 (DexNom: the flag, and the lanes
past the count leaving in two builder programs chosen by digest), as
carried in the cool_fox fork's 810efe5 (RyanLockwoood/VIctory-cool_fox-
LockWood). This tree has no builder detection, hence the form made on
demand.

Tests: halves_tests::the_lanes_past_a_count_of_threads_do_not_run
(wave32 and wave64 on the host, counts 0 to 128 over two groups of 64);
halves_tests::only_programs_whose_lanes_never_wait_leave_past_a_count_
of_threads (pragyaangaur#435's whole-wave retry included: a program it takes reads
no count); thread_dispatch_tests::a_dispatch_counted_in_threads_runs_
only_those_threads, from a console container through State::dispatch_x:
threads 70 to 127 write nothing, the pipeline's own translation reads
no count (fails with VICTORY_THREAD_DIMENSIONS=0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prex-xo pushed a commit to prex-xo/VIctory-macOS that referenced this pull request Nov 27, 2026
- Reject --jobs 0 in both translation modes before starting workers.
- Cover the CLI exit and diagnostic without including title files.
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