Repository navigation
fix(shader): pair an optional body exit with a copied skip-target tail - #18379
oneandonlydean merged 6 commits into
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
@kaiffeetasse thanks for picking this up so fast. I ran it against the logged request for 0x11d01d0900:
The rest of the shape, from the issue: the copies exit through the AI-assisted. |
|
Windows check of head
AI-assisted: yes. |
|
Hardware datapoint on NVIDIA GeForce RTX 3070 (driver 617.42), Windows 11, MinGW build — the same GPU class as the original report. Built
One caveat on end-to-end: our local PPSA03671 capture ( |
|
Head is now
Order in Measured on this head ( What I could not check here is the request itself: no NVIDIA GPU, and AI-assisted: yes. |
|
@kaiffeetasse reran the request against
The final refusal is the AI-assisted. |
The optional-body rule refused every body block that ends in a return and exports, so one structurizer copy of the skip target's tail made the mask proof reject a pixel shader it can prove. Pair a body block with a skip-reachable block of the same non-degenerate pc range and compare the pair instruction by instruction: same opcodes, same export records, and operands and conditional terminators related by inactiveEquals. A body exit only keeps its exports when its whole copied tail pairs; a discard, a differing pc range or a swapped branch polarity still refuses.
…ed operands The pairing required one body instruction per skip instruction, so a tail whose skip block starts with phis was refused, and an operand recomputed in each copy never compared equal. Skip the leading phis of both lists, resolve a skip phi through its incoming value for the predecessor the copy stands for, and relate recomputed values structurally when the opcode is lane-local, side-effect free and every operand relates under a depth limit.
… lanes A copied export tail can read the same lane's own bit from mask words built differently on each side: the body ballots the lanes less the inactive ones, while the skip side ands that ballot with the cleared-lane ballot or with the exec mask, so the words never compare equal and the pair was refused. Relate two words when they agree on the lanes that are active: a word cleared on the active lanes relates to another word cleared there, and an and with a word that is set on those lanes is transparent. The same relation now also covers two own-bit reads whose words come from different ballots of the same lanes.
fd189fb to
d43ef8d
Compare
|
@mrfelek both shapes are implemented rather than argued with; head is now
Measured on
What it does not do: the word relation is pattern-based on the active-lane identities above, not a general mask-equivalence proof. If a further refusal remains, the block numbers plus which of the two sides is the AI-assisted. |
|
@kaiffeetasse reran against The root pair's phis are fixed: b13↔b18 now takes b17 and gets past 0x1a8. To find what's left, I patched a local copy until the proof went through. These patches are only probes, not proposals. The refusals, in order:
With all five, both copied exits (b15, b22) pair and the outer branch at 0x7c..0x94 is proven. The next refusal is the inner branch at 0x94..0x9c (b4 → b5, merge b6):
I stopped there. AI-assisted. |
…asks and empty skip blocks The skip-side tail can reach its exit through a phi that lives in a block the copy was entered from, through an empty forwarding block with no body-side counterpart, or compare mask words whose cleared lanes are an own-bit read of the predicate's ballot rather than Not(predicate) itself. Relate skip phis by the predecessor each skip block was entered with, step over blocks that carry only phis and a branch, strip the new cleared-lane shapes, compare immediates of any type by their bits, and let ballot arguments resolve through recomputed copies up to a depth of 24.
|
@mrfelek head is
Tests: Still refused, as you predicted: the inner branch at 0x94..0x9c — the merge phi AI-assisted: yes. |
|
@kaiffeetasse reran
On your question 3: yes, there is such a path.
AI-assisted. |
|
@kaiffeetasse, I read the diff of Three things need an answer before this can pass:
The 27 new tests are IR fixtures with no execution comparison, and none has the shape of 0x11d01d0900, which is why they pass while the real shader fails. A fixture for that shape would help. |
|
@mrfelek @oneandonlydean head is
What that means for 0x11d01d0900: at the any-lane test 0x1b0 the two ballot arguments are On the widening: every rule this PR adds is an additional accept. Measured at AI-assisted: yes. |
|
@kaiffeetasse thanks for fixing the touched ordering and the per path skipEntries; both look right on b6f6fbd. One thing still blocks me in the exact ballot check (StencilReplay.cpp 769-773 and 811-815). With exactBallots set, two different ballot arguments are accepted when relatedLanes holds and both are zero on inactive lanes. relatedLanes can succeed through inactiveEquals, and zeroOnInactiveLanes is also about inactive lanes, so nothing compares the two arguments on active lanes. For example And(p, Not(And(p, Q1))) and And(p, Not(And(p, Q2))) pass with Q1 != Q2, and their ballots differ on active lanes. That is the 0x11d01d0900 shape, so a false accept would replay a shader whose stencil values differ. Could you make the exact path require the arguments to match on active lanes too (or fall back to sameValue only), and add a negative fixture where the two ballot arguments differ only on an active lane? Two smaller points: inactiveEquals at line 801 still runs before the exact check, so it can accept first; and touched (line 884) is still shared across paths, so a pair reached on a second path is not checked against that path's phis. |
|
@oneandonlydean all three points are in, head is
Fixture for (1) is in the same shape as the existing Measured at AI-assisted: yes. |
|
@kaiffeetasse @oneandonlydean reran Where it fails. That is the only comparison that goes through the exact path. With predicate
Why the zero test can't pass for this shape. The skip argument is not zero where the predicate is false. On that path What does hold, worked out by hand from the IR and not checked by code.
So the property that would accept this shader is "the arguments agree on predicate-false lanes" plus "the skip is only reached with the predicate false on every lane". That is weaker than "zero on inactive lanes and equal on active lanes". Whether it is sound depends on whether the replay can reach this tail by the skip side with predicate lanes active. You wrote that it can run the body with lanes the skip left out; I haven't checked what that means for the skip side here. AI-assisted. |
|
@mrfelek the open question you ended on is answerable from the driver, and it does not go the way your three bullets need. The replay does not re-run the original wave and then pick a path; it re-runs the draw as single triangles, once per candidate reference: That is what the zero test buys. The failing comparison is the tail's own inner branch ( So "arguments agree on predicate-false lanes plus the skip is only reached when no lane has the predicate" is not enough once the wave is re-formed; the skip premise is about the original wave, and the replay never executes that wave. The rule stays as it is. One thing I cannot tell from your dump: whether the 0x1b0 branch is an AI-assisted. |
|
@kaiffeetasse thanks, that answers it. I checked the per-triangle replay ( On your question, from the logged request:
So I agree the rule stays, and 0x11d01d0900 stays refused through this path: the two arguments aren't zero outside AI-assisted. |
What
The optional-body rule of the stencil replay mask proof (
MaskReplaySafety::optionalBody) refused every body block that ends in a return and exports. The structurizer can copy the skip target's export tail into the body, so a provably replay-safe shader was refused withstencil reference export emulation requires a replay-safe pixel shader with late tests: PPSA03671, pixel shader 0x11d01d0900, issue #18335.A body exit now keeps its exports when its whole copied tail pairs with a skip-reachable block of the same non-degenerate
startPc/endPcrange:SetAttributeguards and conditional terminator conditions related bysameValue,inactiveEquals, or — for a value recomputed in each copy — by a structural match: same opcode, type, flags and operand count, no side effects, lane-local only (no ballot, wave mask, lane permute/read/write, shared memory or sampler opcode), every operand related under a depth limit of 24.Not(predicate)are related when the cleared side is zero on every lane the predicate is zero on: the predicate itself, anandwith such a side, or an own-bit read of a ballot of those lanes.SetAttribute ..., falsematches a separately builtfalseinstead of only U32 immediates comparing.A discard, a differing or degenerate pc range, a differing opcode, a swapped polarity, a phi that differs on active lanes for the paired predecessor, a cleared side that is not zero on inactive lanes and a chain deeper than the limit still refuse, and the merge-phi rule is untouched.
The patch applies cleanly on
main. The shape is only reachable once #18322 admits the first-lane read that stops the proof earlier today, so this depends on #18322.This head adds the review round of @mrfelek and @oneandonlydean:
sccdecision over a ballot has to agree on all lanes, and a relation that holds only on the active ones cannot decide it.any lane leftbranch over two ballot words (positive when both arguments are zero on inactive lanes, negative when they differ on an inactive lane and are not zero there).This head (
80ef6a8ad9) closes the soundness gap @oneandonlydean found in that exact check:equalOnActiveLanesstrips a conjunction factor that is literally the predicate from both sides (on the lanes the predicate selects,and(p, x)isx), and then demands a full structural match of what is left; the two arguments must additionally still be provably zero on the inactive lanes, so the ballots agree on every lane.and(p, Not(and(p, Q1)))againstand(p, Not(and(p, Q2)))withQ1 != Q2is refused now; it was accepted before this head.inactiveEqualsno longer decides anything on the exact path. It is an inactive-lane relation by construction, and it ran before the exact ballot check, so it could accept a wave-wide decision on slack the decision does not have. The same holds for theexclusionLanesstrip of a Bool, which is only an equality on the lanes the predicate does not select; both are skipped when the comparison is exact. Only exact relations remain there:sameValue, the strict ballot rule above, anandwith a word that is set on every lane, an own-bit read whose mask words satisfy the strict rule, the skip-side phi resolution, and the structural match.touchedis keyed by path. An entry that was recorded while walking one path no longer answers for the same block pair reached on another: the map stores the skip block and the entry predecessor of that pairing, and a second visit needs both to match, so a pair reached twice through different predecessors is not waved through on the first path's phis.any lane leftbranch whose two ballot arguments are both zero on inactive lanes and differ only on an active lane, i.e. exactly the counterexample. It is refused at this head and accepted atb6f6fbd469.Tested
Linux 6.8.0-51, Intel UHD 630 (i915, Mesa). The new cases are CPU-only IR fixtures, no device involved.
agc_masked_select(ctest --test-dir build-libs -R '^agc_masked_select$'), heada3c026161c: 1/1 passed in 0.04 s, 150 cases; the head below carries 156.build-relinker(-DANYPS5_RELINKER_ONLY=ON) rebuilds and links with the change;check_conventions.py --base origin/mainreportsAll conventions checks passed.d43ef8dc18sStencilReplay.cppand this test file, exactly four positive cases fail (exit 1) — a phi in an earlier skip block, an own-bit mask whose cleared side is an own-bit read of the predicate's ballot, a dead export guard that is a separately builtfalse, and a ballot argument that is a deep recomputed copy — and every negative case still refuses. With the change all cases pass (exit 0).followSkipreturns its argument) makes the earlier-skip-block phi case fail, so that case does not pass through the other four rules.ed43b0376b, reported by @JJenkx:agc_masked_selectpassed 3 of 3 runs withANYPS5_REQUIRE_VULKAN=1(merged onto1ceea3c46d) and 3 of 3 with Vulkan hidden (merged ontoabcb5369ff).main62bd7dd61e+ fix(shader-recompiler): admit first-lane reads of wave-uniform values in stencil replay #18322 + this PR, reported by @akkadbakkad89: 1/1 passed; with the previousStencilReplay.cppand this test file the two positive cases that existing then failed (exit 1).mainand ond43ef8dc18(the previous head of this branch), both withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest --test-dir build-libs -R stencil -V: 15/15 pass in both runs. Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS. Both logs contain the same 12 validation lines, onlyVUID-vkCmdDraw-None-07629, so the change adds no newVUID-error. The last commit extends the same rule set and was re-run asagc_masked_selectabove; a fullbuild-libscannot be rebuilt in this environment (3rdparty/libpsl/list/public_suffix_list.datis missing), so the GPU-side set was not re-measured ata3c026161c.b6f6fbd469: the file holds 156 cases,ctest --test-dir build-libs -R '^agc_masked_select$'reports100% tests passed, 0 tests failed out of 1in 0.26 s, andctest -R stencilreports100% tests passed, 0 tests failed out of 15in 9.15 s.a3c026161csStencilReplay.cppand this test file, exactly three cases fail (exit 1) — the skipped-target forwarding case, the two-predecessor case, and the negativeany lane leftcase, which the previous head accepted. Every other case, including all 150 that existed before, decides the same. With the change all 156 pass (exit 0).80ef6a8ad9(this head): 157 cases,ctest --test-dir build-libs -R '^agc_masked_select$'reports100% tests passed, 0 tests failed out of 1in 0.31 s;ctest --test-dir build-libs -R stencilreports100% tests passed, 0 tests failed out of 15in 10.31 s;build-relinker(-DANYPS5_RELINKER_ONLY=ON) builds and links;check_conventions.py --base origin/mainreportsAll conventions checks passed.80ef6a8ad9: withb6f6fbd469sStencilReplay.cppand this test file, exactly one case fails (exit 1) — the new active-lane negative, which the previous head accepted — and the other 156 cases decide the same as before. With the change the binary exits 0. So the new rules are load-bearing and cost no previous accept.pr_overlap: cannot confirm overlap with PR 7689: core/shader/recompiler/StencilReplay.cpp/overlap check failed closed. Same as at the previous heads and manually bounded: fix(shader): defer guarded fragment V# type faults #7689 has exactly one hunk in that file,@@ -848,8 +848,13 @@inStencilReferenceDefinedForKeptInvocations, a free function outsideMaskReplaySafety; this branch touches main lines up to 735 and none ofStencilReferenceDefinedForKeptInvocations/DeferredBufferFaultsOnly(git diff origin/main...HEAD -- StencilReplay.cpp | grep -c= 0).git merge-tree --write-tree origin/main HEADat this head: exit 0, so the branch still applies on today'smainwithout a rebase.sameValue(any type,ImmediateU64), a unifiedexclusionLanesthat also strips a side provably zero on inactive lanes, the ballot and mask-word-in-ballot relations, and the depth limit of 24 on the mask-word chain instead of 8. No rule onmainwas removed and none of the added predicates can turn a comparison that held onmaininto a refusal, so a shader that compiled before still does. The narrowings only remove accepts this PR itself introduced: the wave-wide ballot rule ata3c026161c, and at80ef6a8ad9the active-lane requirement plus the exact path no longer consulting the inactive-lane relations. Nothing here changes a decision relative tomain.d43ef8dc18) and the Windows data points, both quoted above at their own heads.80ef6a8ad9is that candidate.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)