structure: walk a deep diagram in forget and restrict without recursing #651

Open
qnjk wants to merge 1 commit from qnjk/Darner:structure-recursion-depth into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: forget and restrict (crates/darner-shader/src/structure.rs:375 and :394) recursed into both of a node's children, so their native depth was the diagram's path length — as long as the chain of mask steps that built it. mk bounds the number of nodes, not the depth, and ite (:212) and vars were already rewritten with an explicit worklist for exactly this reason (ite's comment says so). The darner-pipelines-* workers are spawned without a stack_size, so the 2 MiB they get is what a title's long straight-line region has, and that region's chain of s_and_saveexec steps puts forget — called once per back edge on every round of paths — past the stack: an abort, not the TOO_LARGE such a shader is refused with.

  • This change takes the same walk in ascending node order in both functions. mk makes a node only after both its children, so a node's index is above theirs and one pass over the arena in order resolves every node after its children.

How it was tested

  • Tested revision: b369678 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-shader --lib -- structure — 21 passed, 0 failed.
    • New test builds a diagram deep enough that the old recursion would have blown the stack and checks both functions still give the same answer as the recursive definition (compared against a small recursive reference on a shallow diagram, and for the deep one against the expected value at the root).
    • Fail-before, with the old recursive bodies restored: the deep-diagram test aborts the test run with a stack overflow (thread ... has overflowed its stack), which is the defect.
    • cargo clippy --locked -p darner-shader --all-targets -- -D warnings passes.
  • Changes a default: no. Both functions return the same diagram for the same input; only the order of the work changes.
  • A/B result: not applicable — no default change and no speed claim (the iterative walk is also cheaper, but that is not claimed as a number).
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3: the crate's structure tests are green; the full darner-shader run is minutes long because of the oracle sweep (see #619), and the whole-workspace run is not green on this machine for the pre-existing darner-gpu reasons (#224, #150), which this does not touch.
  • Gameplay, when relevant: no gameplay run. The fault needs a shader region long enough to overflow 2 MiB of stack; the test builds that shape.
  • Shader wave sizes tested, when relevant: the diagram is built from mask steps, not from wave shapes; wave64 folding is untouched by this change.
  • Hardware dependence: none.
  • Coverage gaps: the other finding in the same report (Bools::vars quadratic in a walk that runs once per guarded instruction) is a separate change and is not addressed here.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the abort needs a shader shape this machine's title may not produce in a short session, and no gameplay claim is made. The evidence is the test, which overflows the stack on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: passes).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #312 and #526 change crates/darner-shader/src/structure.rs; neither mentions forget, restrict or recursion depth. No open or closed issue mentions a stack overflow in structurisation.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `forget` and `restrict` (`crates/darner-shader/src/structure.rs:375` and `:394`) recursed into both of a node's children, so their native depth was the diagram's path length — as long as the chain of mask steps that built it. `mk` bounds the number of nodes, not the depth, and `ite` (`:212`) and `vars` were already rewritten with an explicit worklist for exactly this reason (`ite`'s comment says so). The `darner-pipelines-*` workers are spawned without a `stack_size`, so the 2 MiB they get is what a title's long straight-line region has, and that region's chain of `s_and_saveexec` steps puts `forget` — called once per back edge on every round of `paths` — past the stack: an abort, not the `TOO_LARGE` such a shader is refused with. - This change takes the same walk in ascending node order in both functions. `mk` makes a node only after both its children, so a node's index is above theirs and one pass over the arena in order resolves every node after its children. ## How it was tested - Tested revision: `b369678` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-shader --lib -- structure` — 21 passed, 0 failed. - New test builds a diagram deep enough that the old recursion would have blown the stack and checks both functions still give the same answer as the recursive definition (compared against a small recursive reference on a shallow diagram, and for the deep one against the expected value at the root). - Fail-before, with the old recursive bodies restored: the deep-diagram test aborts the test run with a stack overflow (`thread ... has overflowed its stack`), which is the defect. - `cargo clippy --locked -p darner-shader --all-targets -- -D warnings` passes. - Changes a default: no. Both functions return the same diagram for the same input; only the order of the work changes. - A/B result: not applicable — no default change and no speed claim (the iterative walk is also cheaper, but that is not claimed as a number). - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3: the crate's `structure` tests are green; the full `darner-shader` run is minutes long because of the oracle sweep (see #619), and the whole-workspace run is not green on this machine for the pre-existing `darner-gpu` reasons (#224, #150), which this does not touch. - Gameplay, when relevant: no gameplay run. The fault needs a shader region long enough to overflow 2 MiB of stack; the test builds that shape. - Shader wave sizes tested, when relevant: the diagram is built from mask steps, not from wave shapes; wave64 folding is untouched by this change. - Hardware dependence: none. - Coverage gaps: the other finding in the same report (`Bools::vars` quadratic in a walk that runs once per guarded instruction) is a separate change and is not addressed here. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the abort needs a shader shape this machine's title may not produce in a short session, and no gameplay claim is made. The evidence is the test, which overflows the stack on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: passes). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #312 and #526 change `crates/darner-shader/src/structure.rs`; neither mentions `forget`, `restrict` or recursion depth. No open or closed issue mentions a stack overflow in structurisation. - Replaces or overlaps: none found
`forget` and `restrict` recursed into both of a node's children, so their
native depth was the diagram's path length: as long as the chain of mask
steps that built it. `mk` bounds the number of nodes, not the depth, and
`ite` and `vars` were already rewritten with an explicit worklist for this
reason (`ite`'s comment says so). The `darner-pipelines-*` workers are
spawned without a `stack_size`, so the 2 MiB they get is what a title's
long straight-line region has, and that region's chain of `s_and_saveexec`
steps puts `forget` — called once per back edge on every round of `paths` —
past the stack: an abort, not the `TOO_LARGE` such a shader is refused with.

Both functions now take the same walk in ascending node order. `mk` makes a
node only after both its children, so a node's index is above theirs and a
child's result is ready when its parent is read. The answers are unchanged;
a test builds a 128k-node chain, walks it on a 2 MiB stack, and checks both
functions' results against the diagram they should produce.
TrustNo1 changed title from [pr-fix][shaders] structure: walk a deep diagram in forget and restrict without recursing to structure: walk a deep diagram in forget and restrict without recursing 2026-12-06 03:25:31 +00:00
Owner

Test needed — commit b3696782; what to check:

  • The problem on main: forget and restrict (crates/darner-shader/src/structure.rs:375 and :394) recursed into both of a node's children, so their native depth was the diagram's path length — as long as the chain of mask steps that built it. mk bounds the number of nodes, not the depth, and ite (:212) and vars were already rewritten with an explicit worklist for exactly this reason (ite's comment says so). The darner-pipelines-* workers are spawned without a stack_size, so the 2 MiB they get is what a title's long straight-line region has, and that region's chain of s_and_saveexec steps puts forget — called once per back edge on every round of paths — past the stack: an abort, not the TOO_LARGE such a shader is refused with.

  • This change takes the same walk in ascending node order in both functions. mk makes a node only after both its children, so a node's index is above theirs and one pass over the arena in order resolves every node after its children.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `b3696782`; what to check: - The problem on main: `forget` and `restrict` (`crates/darner-shader/src/structure.rs:375` and `:394`) recursed into both of a node's children, so their native depth was the diagram's path length — as long as the chain of mask steps that built it. `mk` bounds the number of nodes, not the depth, and `ite` (`:212`) and `vars` were already rewritten with an explicit worklist for exactly this reason (`ite`'s comment says so). The `darner-pipelines-*` workers are spawned without a `stack_size`, so the 2 MiB they get is what a title's long straight-line region has, and that region's chain of `s_and_saveexec` steps puts `forget` — called once per back edge on every round of `paths` — past the stack: an abort, not the `TOO_LARGE` such a shader is refused with. - This change takes the same walk in ascending node order in both functions. `mk` makes a node only after both its children, so a node's index is above theirs and one pass over the arena in order resolves every node after its children. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'structure-recursion-depth:qnjk-structure-recursion-depth'
git switch 'qnjk-structure-recursion-depth'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'qnjk-structure-recursion-depth'
git switch 'qnjk-structure-recursion-depth'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-structure-recursion-depth'
git switch 'qnjk-structure-recursion-depth'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-structure-recursion-depth'
git switch 'Main'
git merge --squash 'qnjk-structure-recursion-depth'
git switch 'Main'
git merge --ff-only 'qnjk-structure-recursion-depth'
git switch 'Main'
git merge 'qnjk-structure-recursion-depth'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!651
No description provided.