Skip to content

Shaders: descriptors set in a region s_cbranch_execz can skip are traced after it - #2324

Closed
chippy01 wants to merge 1 commit into
Marvisak:mainfrom
chippy01:shaders/descriptor-neither-loaded-nor-built
Closed

chippy01 wants to merge 1 commit into
Marvisak:mainfrom
chippy01:shaders/descriptor-neither-loaded-nor-built

Conversation

@chippy01

Copy link
Copy Markdown

Problem

On main (940d32f) three compute programs are refused at translation with resources: a descriptor neither loaded nor built. They are the last three of that class (#320 brings it from 298 to 3; main is at 3):

program hash refused at
shadowmask:CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard e6ac855a4cddb16d 0x6dc8
alphaResolve:CS_AlphTransmissionPrefilterMip 2da4beb386509b77 0x4d0
indirect_light_probes:CS_Alpha_Schedule aab1b3c7248ee5de 0x140

All three set a descriptor (a table load in two of them, an immediate sampler in the third) inside a region that s_and_saveexec + s_cbranch_execz skips when no lane would run it, and read it after the region ends (s_mov exec, saved). The phi where the region ends joins the region's words with what the skip leaves in the registers (an EXEC save, a lane mask), and tracking refuses the read. CS_Alpha_Schedule also clears the high half of its table address only inside such a region, so after the first refusal it stops at an address into a descriptor heap with an untracked high half.

Why the read is the region's

The structuriser turns s_cbranch_execz into a per-lane branch, which holds for vector work but not for scalar writes: those are the whole wave's. A lane that reaches the region's end without running the region itself reads what another lane's run set. Only a wave none of whose lanes runs the region reads what the skip leaves, and compiled code does not read an EXEC save as a descriptor.

The change (crates/victory-shader/src/resource.rs)

  • phi(): when some predecessor edges fail to trace, past_skip takes the source of the others if every failing edge is the taken edge of an s_cbranch_execz into the join, and the other edges agree on one source whose handle can be made at the join. That means a constant, or a load or built descriptor whose address only reads values that dominate the join. Lowering makes the handle at the access from the load's base and offset registers, so those are what is checked.
  • high_half(): a phi at such a join whose non-skip edges are the expected high half (0 for a table) counts as that high half. A table's heap index only uses the low dword, which is unaffected.
  • Reads that trace today are unchanged: the new paths only run where tracking would otherwise refuse. A region that reloads a descriptor the skip also leaves stays a Phi (test below).

Tests

Five new unit tests in resource::tests, on synthetic code:

  • a_descriptor_loaded_in_a_skippable_region_is_read_after_it
  • a_sampler_set_in_a_skippable_region_is_the_constant_after_it
  • a_table_address_a_skippable_region_completes_is_traced_after_it
  • a_descriptor_a_skippable_region_reloads_is_still_joined (unchanged behaviour)
  • a_descriptor_read_after_a_skip_otherwise_still_fails: an offset computed inside the region, and a skip on a uniform s_cbranch_scc1, are still refused.

The three positive tests fail without the change.

Measurements

Offline victory translate --validate --list over the shader pack, the executable and its DLLs: 25,982 programs. Windows 11, dxil.dll from SDK 10.0.26100. Per #1945 that one prints 1.8 but behaves like 1.7; both runs used it, so the comparison holds.

main 940d32f this PR
programs validated 24,005 24,007
a descriptor neither loaded nor built 3 0

The only outcomes that change, across all 25,982 programs:

program main this PR
CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard refused at 0x6dc8 validated
CS_AlphTransmissionPrefilterMip refused at 0x4d0 validated
CS_Alpha_Schedule refused at 0x140 emitted; the validator's compute-derivative check (Entry function performs some operation that is incompatible with the shader stage), the class #2027 addresses

Checks:

In-game check

On an RTX 3070 Ti (32-lane waves, Windows 11), one run per row, each into the prologue's world from about 1.5 min:

run 2da4beb386509b77 aab1b3c7248ee5de end
main + #1775 does not translate; 2 dispatches a frame dropped does not translate; 1 a frame dropped the title's own breakpoint at +0x5149aec after 11 min (#1232)
+ this PR translates; the driver refuses the pipeline (a wave64 program on a 32-lane host), so still dropped translates; pipeline made, runs every frame (writes its 32x16 target) device hung (0x887A0006) at 7.5 min in draw [vertex cb47fdb3b37b7880, pixel b335d5633b1ed53f]
+ this PR, aab1b3c7248ee5de skipped as above skipped the same draw hangs at 7.3 min

With aab1b3c7248ee5de skipped, the GPU runs exactly the work main does. The same draw then hangs, so the removal is the known hang in that draw (#1968, #452), not something this change makes run. The main run ended on the title's breakpoint before getting there. The third program, e6ac855a4cddb16d, was not requested in these runs.

Not covered

  • Other scalar values such a region sets and the code reads after it (a count read as data, say) still take the per-lane phi in lowering. That is a separate structuriser question.
  • A region source whose address the region computes is still refused: its handle could not be made where the region ends.

AI-assisted; measured on my own machine.

…ced after it

Compiled code sets a descriptor, or the high half of the table address
it loads one through, inside a region that `s_cbranch_execz` skips when
no lane would run it, and reads it after the region. The phi where the
region ends joins the region's words with what the skip leaves in the
registers (an EXEC save, a lane mask), and tracking refused the read
("a descriptor neither loaded nor built", then "an address into a
descriptor heap with an untracked high half").

Scalar writes are the whole wave's: a lane that reaches the end without
running the region reads what another lane's run set, so the per-lane
branch structurisation makes of the skip does not hold for them. Where
every edge that fails to trace is such a skip and the other edges agree,
the read is of the region's source, provided its handle can be made
where the region ends: a constant, or a load or built descriptor whose
address only reads values that dominate that point. A table address's
high half set in such a region counts as set. Reads that trace today
are unchanged. The rule is in the module notes and docs/architecture.md;
a skip's edge holding a descriptor tracking cannot follow is a shortcut.

Offline `translate --validate` over the title's 25,982 programs: the
three "a descriptor neither loaded nor built" refusals are gone; two of
them validate, the third now reaches the validator's compute-derivative
check (the class Marvisak#2027 addresses). No other program's outcome changes.

@catminou4 catminou4 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 locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 149 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — descriptors set in a region s_cbranch_execz can skip, +5 tests and docs.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (worth a look). In crates/victory-shader/src/resource.rs, Tracer::phi now goes through the new past_skip before it gives up: if the only predecessor edges that fail to trace are the taken edges of an s_cbranch_execz into the join, and the other edges agree on one source whose handle can be built at the join, the read takes that source; high_half does the same through past_skip_is. This matches GFX10 behaviour (scalar writes apply to the whole wave, and s_cbranch_execz skips only when EXEC is zero, so the skip edge carries a value the compiled code never reads as a descriptor), and the new paths run only where tracking used to refuse. The negative tests (an offset computed inside the region, a skip on a uniform s_cbranch_scc1) still refuse; the evidence covers the affected programs, an offline validation diff and an in-game run. CI: passing.


Generated by Claude Code

@chippy01

Copy link
Copy Markdown
Author

Superseded by ff47463 and 58b5255 on main, which handle the same three programs by proving that no lane takes the skip edge. On da82e44 the shader census gives what this PR aimed for: CS_AlphTransmissionPrefilterMip and CS_TraceShadowRays_ScreenSpaceOnlyCheckerboard validate, CS_Alpha_Schedule stops at the compute-derivative check (#2027), and no 'a descriptor neither loaded nor built' refusal is left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants