Shader: merged hull factor writes under a lane-index AND fail the control point 0 proof, then a waterfall loop's ballot is refused (PPSA01317) #17251

Open
opened 2026-11-08 16:17:38 +00:00 by freneza · 0 comments
freneza commented 2026-11-08 16:17:38 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by freneza on 2026-11-08T16:17:38Z.


What happens

A merged hull program stops in tessellation lowering: shader 0x13d1ac0d00 stage 2: ShaderRecompiler::Recompile: tessellation lowering: per-patch tessellation output is not written by control point 0 alone at pc 0x304

Title, test or build step

PPSA01317 01.710.000

AnyPS5 commit

main 4977f64052 with open PRs merged on top (#16644, #9335, #7256, #10049, #9969, #14296, #9457 and #14636), plus local changes that let the title get this far. FirstInvocationOnly and the lane-mask check in TessellationLowering.cpp are unchanged on main d0d11564ca.

System

Bazzite (Linux 7.2.9), RTX 5070 (NVIDIA 615.78.08), built in a Fedora distrobox.

Steps to reproduce

Start the title's first licence test. The hull program is translated when the driving scene loads. Its address changes between runs (0x13cfac0d00, then 0x13d1ac0d00). With APS5_DUMP_SHADERS=1 the .prepare.req capture reproduces both failures below offline with agc_shader_replay --prepare.

Log

[videoout] presentation failed: shader 0x13d1ac0d00 stage 2 (shader_13d1ac0d00.prepare.req): ShaderRecompiler::Recompile: tessellation lowering: per-patch tessellation output is not written by control point 0 alone at pc 0x304
terminate called after throwing an instance of 'std::runtime_error'

What was checked

The failure is the same in three runs. These findings come from the capture and the replay tool.

1. The per-patch write really comes from control point 0 only, but FirstInvocationOnly cannot prove it. The tessellation factors at pc 0x304 are stored under v_cmpx_gt_u32 exec, 1, v11 (pc 0x2bc), where v11 = v_bfe_u32 v1, 8, 5 is the control point ID. In IR, the store's predicate is:

LogicalAnd(
  ULessThan32(laneIndex, 4),
  UGreaterThan32(1, SelectU32(ULessThan32(laneIndex, 4), BitFieldUExtract(rel_ids, 8, 5), 0)))

The SelectU32 condition is the other operand of the same LogicalAnd, so the select is the control point ID whenever the predicate holds. FirstInvocationOnly calls IsInvocation, which evaluates its argument with no predicate. The select is therefore not resolved, and the check fails.

When FirstInvocationOnly recurses into a LogicalAnd, I pass that LogicalAnd as the predicate that IsInvocation evaluates under. This needs four changed lines, and the capture then gets past this check:

-    bool IsInvocation(IrValue* value) {
-        const auto address = Evaluate(value, nullptr);
+    bool IsInvocation(IrValue* value, IrValue* predicate = nullptr) {
+        const auto address = Evaluate(value, predicate);
-bool FirstInvocationOnly(IrValue* raw, AddressEvaluator& evaluator, std::unordered_set<IrValue*>& path) {
+bool FirstInvocationOnly(IrValue* raw, AddressEvaluator& evaluator, std::unordered_set<IrValue*>& path, IrValue* holding = nullptr) {
-    const auto invocation = [&](std::size_t index) { return evaluator.IsInvocation(value->Argument(index)); };
+    const auto invocation = [&](std::size_t index) { return evaluator.IsInvocation(value->Argument(index), holding); };
-            return FirstInvocationOnly(value->Argument(0), evaluator, path) || FirstInvocationOnly(value->Argument(1), evaluator, path);
+            return FirstInvocationOnly(value->Argument(0), evaluator, path, value) || FirstInvocationOnly(value->Argument(1), evaluator, path, value);

This is sound because an operand of a LogicalAnd only matters when the whole LogicalAnd holds. Phi operands are still checked without a holding predicate.

2. Next stop: a waterfall loop. With that change, the replay stops at the hull program uses a lane mask other than its own lane's bit (reported at pc 0x0). The Ballot still in use comes from a waterfall loop at pc 0x258–0x2a0:

  • v_readfirstlane_b32 s3, v6, then v_cmpx_eq_u32 exec, s3, v6;
  • s_mov_b32 m0, s3, then an LDS access;
  • s_xor_b32 s10, s10, exec, s_mov_b32 exec, s10 and a branch back while lanes remain.

The loop runs one LDS access per distinct m0 value among the active lanes. Its remaining-lanes mask is the Ballot, read through CompositeExtractU32x4 and BitwiseOr32 to test whether any lane remains.

Open question: should merged-hull lowering recognise this readfirstlane/cmpx_eq/xor exec loop and turn it into a per-invocation access? The loop's result does not depend on which lane is picked first. If that is the intended direction, I can open a PR for part 1 with a test.

I can share the 14 KiB capture privately with a maintainer who needs it.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6272938649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/17251). Originally posted by [freneza](https://github.com/freneza) on 2026-11-08T16:17:38Z. --- ### What happens A merged hull program stops in tessellation lowering: `shader 0x13d1ac0d00 stage 2: ShaderRecompiler::Recompile: tessellation lowering: per-patch tessellation output is not written by control point 0 alone at pc 0x304` ### Title, test or build step PPSA01317 01.710.000 ### AnyPS5 commit `main` 4977f64052 with open PRs merged on top (#16644, #9335, #7256, #10049, #9969, #14296, #9457 and #14636), plus local changes that let the title get this far. `FirstInvocationOnly` and the lane-mask check in `TessellationLowering.cpp` are unchanged on `main` d0d11564ca. ### System Bazzite (Linux 7.2.9), RTX 5070 (NVIDIA 615.78.08), built in a Fedora distrobox. ### Steps to reproduce Start the title's first licence test. The hull program is translated when the driving scene loads. Its address changes between runs (0x13cfac0d00, then 0x13d1ac0d00). With `APS5_DUMP_SHADERS=1` the `.prepare.req` capture reproduces both failures below offline with `agc_shader_replay --prepare`. ### Log ```text [videoout] presentation failed: shader 0x13d1ac0d00 stage 2 (shader_13d1ac0d00.prepare.req): ShaderRecompiler::Recompile: tessellation lowering: per-patch tessellation output is not written by control point 0 alone at pc 0x304 terminate called after throwing an instance of 'std::runtime_error' ``` ### What was checked The failure is the same in three runs. These findings come from the capture and the replay tool. **1. The per-patch write really comes from control point 0 only, but `FirstInvocationOnly` cannot prove it.** The tessellation factors at pc 0x304 are stored under `v_cmpx_gt_u32 exec, 1, v11` (pc 0x2bc), where `v11 = v_bfe_u32 v1, 8, 5` is the control point ID. In IR, the store's predicate is: ```text LogicalAnd( ULessThan32(laneIndex, 4), UGreaterThan32(1, SelectU32(ULessThan32(laneIndex, 4), BitFieldUExtract(rel_ids, 8, 5), 0))) ``` The `SelectU32` condition is the other operand of the same `LogicalAnd`, so the select is the control point ID whenever the predicate holds. `FirstInvocationOnly` calls `IsInvocation`, which evaluates its argument with no predicate. The select is therefore not resolved, and the check fails. When `FirstInvocationOnly` recurses into a `LogicalAnd`, I pass that `LogicalAnd` as the predicate that `IsInvocation` evaluates under. This needs four changed lines, and the capture then gets past this check: ```diff - bool IsInvocation(IrValue* value) { - const auto address = Evaluate(value, nullptr); + bool IsInvocation(IrValue* value, IrValue* predicate = nullptr) { + const auto address = Evaluate(value, predicate); -bool FirstInvocationOnly(IrValue* raw, AddressEvaluator& evaluator, std::unordered_set<IrValue*>& path) { +bool FirstInvocationOnly(IrValue* raw, AddressEvaluator& evaluator, std::unordered_set<IrValue*>& path, IrValue* holding = nullptr) { - const auto invocation = [&](std::size_t index) { return evaluator.IsInvocation(value->Argument(index)); }; + const auto invocation = [&](std::size_t index) { return evaluator.IsInvocation(value->Argument(index), holding); }; - return FirstInvocationOnly(value->Argument(0), evaluator, path) || FirstInvocationOnly(value->Argument(1), evaluator, path); + return FirstInvocationOnly(value->Argument(0), evaluator, path, value) || FirstInvocationOnly(value->Argument(1), evaluator, path, value); ``` This is sound because an operand of a `LogicalAnd` only matters when the whole `LogicalAnd` holds. Phi operands are still checked without a holding predicate. **2. Next stop: a waterfall loop.** With that change, the replay stops at `the hull program uses a lane mask other than its own lane's bit` (reported at pc 0x0). The `Ballot` still in use comes from a waterfall loop at pc 0x258–0x2a0: - `v_readfirstlane_b32 s3, v6`, then `v_cmpx_eq_u32 exec, s3, v6`; - `s_mov_b32 m0, s3`, then an LDS access; - `s_xor_b32 s10, s10, exec`, `s_mov_b32 exec, s10` and a branch back while lanes remain. The loop runs one LDS access per distinct `m0` value among the active lanes. Its remaining-lanes mask is the `Ballot`, read through `CompositeExtractU32x4` and `BitwiseOr32` to test whether any lane remains. Open question: should merged-hull lowering recognise this `readfirstlane`/`cmpx_eq`/`xor exec` loop and turn it into a per-invocation access? The loop's result does not depend on which lane is picked first. If that is the intended direction, I can open a PR for part 1 with a test. I can share the 14 KiB capture privately with a maintainer who needs it.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#17251
No description provided.