AGC: pixel shaders that export a stencil reference value abort on devices without VK_EXT_shader_stencil_export (NVIDIA; Demon's Souls, 1080p renderconfig) #4276

Closed
opened 2026-10-12 03:49:15 +00:00 by fisherjoey · 5 comments
fisherjoey commented 2026-10-12 03:49:15 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-12T03:49:15Z.


Demon's Souls (PPSA01341 v1.07, US) aborts during the tutorial level load with:

[videoout] presentation failed: depth export, shader coverage or ordered fragment execution is unsupported (register 0x203 = 0x00000052)
terminate called after throwing an instance of 'std::runtime_error'

Register 0x203 is DB_SHADER_CONTROL. 0x52 sets three bits:

  • bit 1, STENCIL_TEST_VAL_EXPORT_ENABLE: the pixel shader exports a stencil reference value
  • bits 4-5, Z_ORDER = 1 (early Z then late Z)
  • bit 6, KILL_ENABLE

ShaderControlMask in Graphics/src/State.cpp already accepts bits 4 to 6. Bit 1 is the only one it rejects, so this is a draw whose pixel shader writes the stencil reference. There is no stencil export path today: nothing in the driver or the recompiler emits FragStencilRefEXT or enables VK_EXT_shader_stencil_export.

How to reach it: the title only takes this path here when it renders at 1920x1080. Following ponhei9502's note in #1283, I set +r_Wants4K = WantsPerf in copies of the five app0/misc/renderconfig_ps5_*.txt files (a local copy of app0/misc, the dump untouched) and booted through the debug start menu into the tutorial. The abort came at about 1209 s, during level loading, after 157 presented frames. With the default renderconfig (4K) the same build gets to a different stop first (a depth plane sampled as a texture), so I haven't seen this draw at 4K yet.

I don't have the pixel shader address. The check fails while the draw's state is decoded, and the message doesn't name the program. I can add that and report back if it helps.

Setup: Linux, RTX 5070 Ti, NVIDIA 595.91.07. main 7a84b222 with #4049, #758, #4241 and #4265 merged locally (#4265 is the fiber stack fix that gets this far), ANYPS5_ENABLE_SPIRV_TOOLS=ON, APS5_SPIRV_OPT=none.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5808079808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4276). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-12T03:49:15Z. --- Demon's Souls (PPSA01341 v1.07, US) aborts during the tutorial level load with: ``` [videoout] presentation failed: depth export, shader coverage or ordered fragment execution is unsupported (register 0x203 = 0x00000052) terminate called after throwing an instance of 'std::runtime_error' ``` Register 0x203 is DB_SHADER_CONTROL. 0x52 sets three bits: - bit 1, STENCIL_TEST_VAL_EXPORT_ENABLE: the pixel shader exports a stencil reference value - bits 4-5, Z_ORDER = 1 (early Z then late Z) - bit 6, KILL_ENABLE `ShaderControlMask` in `Graphics/src/State.cpp` already accepts bits 4 to 6. Bit 1 is the only one it rejects, so this is a draw whose pixel shader writes the stencil reference. There is no stencil export path today: nothing in the driver or the recompiler emits `FragStencilRefEXT` or enables `VK_EXT_shader_stencil_export`. How to reach it: the title only takes this path here when it renders at 1920x1080. Following ponhei9502's note in #1283, I set `+r_Wants4K = WantsPerf` in copies of the five `app0/misc/renderconfig_ps5_*.txt` files (a local copy of `app0/misc`, the dump untouched) and booted through the debug start menu into the tutorial. The abort came at about 1209 s, during level loading, after 157 presented frames. With the default renderconfig (4K) the same build gets to a different stop first (a depth plane sampled as a texture), so I haven't seen this draw at 4K yet. I don't have the pixel shader address. The check fails while the draw's state is decoded, and the message doesn't name the program. I can add that and report back if it helps. Setup: Linux, RTX 5070 Ti, NVIDIA 595.91.07. `main` 7a84b222 with #4049, #758, #4241 and #4265 merged locally (#4265 is the fiber stack fix that gets this far), `ANYPS5_ENABLE_SPIRV_TOOLS=ON`, `APS5_SPIRV_OPT=none`. AI-assisted: yes
LeandroLP23 commented 2026-10-13 20:16:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-13T20:16:39Z.


Status on main: the stop in this issue's title is gone on devices with VK_EXT_shader_stencil_export. #4355 (merged 2026-10-12, 22d662eda) emits FragStencilRefEXT for pixel shaders with DB_SHADER_CONTROL.STENCIL_TEST_VAL_EXPORT_ENABLE. It says "Refs #4276", so this issue was not closed with it.

On AMD the new test passes: agc_driver_stencil_ref_export passes 5 of 5 (not skipped) at main a0f5916a2. Setup: Windows 11 (26300), Radeon 860M (RDNA 3.5, driver 32.0.13058.8001, which advertises VK_EXT_shader_stencil_export), WinLibs GCC 15.2.0, Release.

What is still open is NVIDIA, whose driver lacks the extension. There the draw stops with a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, which the device lacks. #5304 removes that stop for draws without a stencil test, but Sam-mon7's Demon's Souls draw on the same PR has the stencil test on. It may be clearer to retitle this issue to that NVIDIA case, or to close it in favour of a new one.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154340477 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4276#issuecomment-6154340477). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-13T20:16:39Z. --- Status on `main`: the stop in this issue's title is gone on devices with `VK_EXT_shader_stencil_export`. #4355 (merged 2026-10-12, `22d662eda`) emits `FragStencilRefEXT` for pixel shaders with `DB_SHADER_CONTROL.STENCIL_TEST_VAL_EXPORT_ENABLE`. It says "Refs #4276", so this issue was not closed with it. On AMD the new test passes: `agc_driver_stencil_ref_export` passes 5 of 5 (not skipped) at `main` `a0f5916a2`. Setup: Windows 11 (26300), Radeon 860M (RDNA 3.5, driver 32.0.13058.8001, which advertises `VK_EXT_shader_stencil_export`), WinLibs GCC 15.2.0, Release. What is still open is NVIDIA, whose driver lacks the extension. There the draw stops with `a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, which the device lacks`. #5304 removes that stop for draws without a stencil test, but Sam-mon7's Demon's Souls draw on the same PR has the stencil test on. It may be clearer to retitle this issue to that NVIDIA case, or to close it in favour of a new one. AI-assisted: yes (Claude Code)
fisherjoey commented 2026-10-13 23:01:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-13T23:01:33Z.


@LeandroLP23 thanks, retitled to the NVIDIA case. #4355 covers devices with VK_EXT_shader_stencil_export; the RTX 5070 Ti here doesn't advertise it, so Demon's Souls still stops on this draw. #5304 and #5466 both target that remaining case; I'll test them on Linux NVIDIA with Demon's Souls and post the results here.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157023814 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4276#issuecomment-6157023814). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-13T23:01:33Z. --- @LeandroLP23 thanks, retitled to the NVIDIA case. #4355 covers devices with `VK_EXT_shader_stencil_export`; the RTX 5070 Ti here doesn't advertise it, so Demon's Souls still stops on this draw. #5304 and #5466 both target that remaining case; I'll test them on Linux NVIDIA with Demon's Souls and post the results here. AI-assisted: yes
fisherjoey commented 2026-10-14 01:58:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-14T01:58:11Z.


Results for #5304 and #5466 on Demon's Souls, as promised above. Neither gets the title past this stop on NVIDIA yet.

Setup: Linux, RTX 5070 Ti, NVIDIA 595.91 (no VK_EXT_shader_stencil_export). Demon's Souls PPSA01341 v1.07, 1080p renderconfig, debug direct boot. Base is main 7a0c838ca plus a local merge of #758, which the title needs to reach the level load. ANYPS5_ENABLE_SPIRV_TOOLS=OFF.

build result
main only stops earlier, at t+1185 during the level load: GetImageResource dword 0 (#758's case)
main + #758 t+1471: a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, shader 0x24ab8e200
+ #5304 not run. Every stencil-export draw we logged has the stencil test on (DB_DEPTH_CONTROL 0x007007e7 / 0x007007c7), so its rule doesn't apply
+ #5304 with @Sam-mon7's widening (no face consumes the reference) the first draw passes. t+1301: same error on shader 0x24ab6ae00, a draw that writes the reference (DB_STENCIL_CONTROL 0x00030030, ZPASS REPLACE on both faces, DB_STENCILREFMASK 0x018080ff, write mask 0x80)
+ #5466 (c7595e9fb) t+474: #5466's refusal stencil reference export emulation requires a replay-safe pixel shader with late tests, shader 0x24abb6d00
+ #5466 + the widening the widening takes 0x24abb6d00 out of replay, then the same refusal on 0x24ab57200 (t+561)
+ #5466 with fdfawef324's three #758 adaptations same refusal, shader 0x24ab6dc00

The refused addresses run the same 788-word pixel shader (0x24abb6d00 and 0x24ab57200 are byte-identical). The draws differ only in stencil state: one doesn't consume the reference, so the widening drops its export, and the other writes it. Why #5466 refuses that shader is on #5466.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159181817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4276#issuecomment-6159181817). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-14T01:58:11Z. --- Results for #5304 and #5466 on Demon's Souls, as promised above. Neither gets the title past this stop on NVIDIA yet. Setup: Linux, RTX 5070 Ti, NVIDIA 595.91 (no `VK_EXT_shader_stencil_export`). Demon's Souls PPSA01341 v1.07, 1080p renderconfig, debug direct boot. Base is `main` 7a0c838ca plus a local merge of #758, which the title needs to reach the level load. `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. | build | result | |---|---| | `main` only | stops earlier, at t+1185 during the level load: `GetImageResource dword 0` (#758's case) | | `main` + #758 | t+1471: `a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export`, shader 0x24ab8e200 | | + #5304 | not run. Every stencil-export draw we logged has the stencil test on (`DB_DEPTH_CONTROL` 0x007007e7 / 0x007007c7), so its rule doesn't apply | | + #5304 with @Sam-mon7's widening (no face consumes the reference) | the first draw passes. t+1301: same error on shader 0x24ab6ae00, a draw that writes the reference (`DB_STENCIL_CONTROL` 0x00030030, ZPASS REPLACE on both faces, `DB_STENCILREFMASK` 0x018080ff, write mask 0x80) | | + #5466 (c7595e9fb) | t+474: #5466's refusal `stencil reference export emulation requires a replay-safe pixel shader with late tests`, shader 0x24abb6d00 | | + #5466 + the widening | the widening takes 0x24abb6d00 out of replay, then the same refusal on 0x24ab57200 (t+561) | | + #5466 with fdfawef324's three #758 adaptations | same refusal, shader 0x24ab6dc00 | The refused addresses run the same 788-word pixel shader (0x24abb6d00 and 0x24ab57200 are byte-identical). The draws differ only in stencil state: one doesn't consume the reference, so the widening drops its export, and the other writes it. Why #5466 refuses that shader is on #5466. AI-assisted: yes
simonbronk commented 2026-10-17 08:59:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-17T08:59:11Z.


Another NVIDIA case, from Onimusha: Way of the Sword (PPSA27836) during its first scene load. RTX 5070 (617.42), Windows 11, main 17cfb1f4c + #6762 (STENCIL_OP_VAL_EXPORT with REPLACE_OP, value in MRTZ.Y bits 8-15):

shader 0x2107d4b600 stage 5: ShaderRecompiler::Recompile: stencil reference export emulation requires a proven set of at most 16 values

The draw: DB_SHADER_CONTROL 0x45 (Z export, operation-value export, kill), DB_DEPTH_CONTROL 0x7007e7, DB_STENCIL_CONTROL 0x40040 (REPLACE on depth pass, both faces), DB_STENCILREFMASK write mask 0xff.

#5466's replay can't take this shader even with a larger value limit, for two reasons:

  • The value is either a user-data byte (s4 & 0xff) or comes from a buffer read.
  • The shader has side effects: a global atomic and buffer stores before exp mrtz.

So replaying per value would run those side effects more than once.

An idea for draws like this one, where the only stencil op that uses the reference is REPLACE on depth pass and the stencil test is ALWAYS. I haven't tried it:

  • Run the draw once. Write the 8-bit value plus a "written" flag to an extra R8G8 color attachment instead of FragStencilRef. With ALWAYS, a fragment that passes the depth test is exactly one whose stencil would be replaced, so the last fragment written per pixel is the same one the console keeps.
  • Then set the stencil from that image with a full-screen pass per bit: discard where the flag is clear or the bit is 0, REPLACE with reference 1 << b and write mask 1 << b, after one pass that clears the masked bits where the flag is set.
  • That is 9 cheap passes, and the shader runs only once.

Before anyone writes it: does this match how others see the problem? I'd like to hear from @fdfawef324 (#5466) whether this kind of second path belongs next to the replay or should replace part of it.

AI-assisted: yes (Claude Code); the run and the decoding are mine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232028827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4276#issuecomment-6232028827). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-17T08:59:11Z. --- Another NVIDIA case, from Onimusha: Way of the Sword (PPSA27836) during its first scene load. RTX 5070 (617.42), Windows 11, `main` 17cfb1f4c + #6762 (`STENCIL_OP_VAL_EXPORT` with `REPLACE_OP`, value in MRTZ.Y bits 8-15): ``` shader 0x2107d4b600 stage 5: ShaderRecompiler::Recompile: stencil reference export emulation requires a proven set of at most 16 values ``` The draw: `DB_SHADER_CONTROL` 0x45 (Z export, operation-value export, kill), `DB_DEPTH_CONTROL` 0x7007e7, `DB_STENCIL_CONTROL` 0x40040 (`REPLACE` on depth pass, both faces), `DB_STENCILREFMASK` write mask 0xff. #5466's replay can't take this shader even with a larger value limit, for two reasons: - The value is either a user-data byte (`s4 & 0xff`) or comes from a buffer read. - The shader has side effects: a global atomic and buffer stores before `exp mrtz`. So replaying per value would run those side effects more than once. An idea for draws like this one, where the only stencil op that uses the reference is `REPLACE` on depth pass and the stencil test is `ALWAYS`. I haven't tried it: - Run the draw once. Write the 8-bit value plus a "written" flag to an extra R8G8 color attachment instead of `FragStencilRef`. With `ALWAYS`, a fragment that passes the depth test is exactly one whose stencil would be replaced, so the last fragment written per pixel is the same one the console keeps. - Then set the stencil from that image with a full-screen pass per bit: discard where the flag is clear or the bit is 0, `REPLACE` with reference `1 << b` and write mask `1 << b`, after one pass that clears the masked bits where the flag is set. - That is 9 cheap passes, and the shader runs only once. Before anyone writes it: does this match how others see the problem? I'd like to hear from @fdfawef324 (#5466) whether this kind of second path belongs next to the replay or should replace part of it. AI-assisted: yes (Claude Code); the run and the decoding are mine.
juanpimg commented 2026-10-20 18:24:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by juanpimg on 2026-10-20T18:24:04Z.


While working on the recorder test registrations I ran every flag-scoped mode of the AGC
driver against two devices, and one of them found a case of this. It is not a new symptom,
but it locates the failure and shows why it is invisible today.

Reproduction

The test is agc_driver_stencil_ref_export_unused_tests, in
core/libs/prx/libSceAgcDriver/tests/execution/StencilRefExportUnused.cpp. It takes a
--case argument, and six of its eight cases fail on every device:

--case NVIDIA RTX 4060, driver 615.78.08 Intel Iris Xe, Mesa 26.2.4 ANV
keep 0 0
invert 0 0
compare, back-compare, replace, fail-replace, depth-fail-replace, partial-replace 1 1

The failure message is the test's own:

AGC graphics: a dependent reference without native stencil export was admitted

The two devices differ in the extension, and the test skips on one of them

VK_EXT_shader_stencil_export is present on the Intel device and absent on the NVIDIA one.
The test's keep and invert cases pass on both, and the six dependent cases fail on both.

The reason the Intel run skips rather than fails is in the test's own expectation: it looks
for the refusal

a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, which the device lacks

and on the Intel device the draw is admitted for a different reason, so the expectation does
not hold there either.

Where the refusal and the emulation live

The message the test expects is thrown in
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cpp:380, and it is
reached only on the native path, that is, when state.stencilRefVariable != 0 and
state.stencilReplay is false. state.stencilReplay is set in
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp:425, in the
branch that runs when the device does not have the capability, and that branch emulates the
stencil reference export instead of refusing it.

So on a device without VK_EXT_shader_stencil_export the driver emulates the export, and
the refusal the test expects no longer happens. The emulation has three preconditions of its
own, each with its own message, and none of them fires for these six cases: the draw is
admitted silently.

Whether the emulation is right for a dependent stencil reference, or whether the draw has to
be refused as the test expects, is a question about the console's own behaviour, which I
cannot measure. I did not touch the driver.

Why this is invisible

agc_driver_stencil_ref_export_unused_tests is built, because the AGC execution tests are
globbed from tests/execution/*.cpp, but no ctest entry runs it, and no ctest entry passes
it a --case either. The six cases are therefore never executed by CI, and a local run only
reaches them with the argument by hand.

The registrations I am proposing in #8445 add the two cases that pass, keep and invert,
and leave the six that fail out, so that the coverage grows without a red job.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298074016 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4276#issuecomment-6298074016). Originally posted by [juanpimg](https://github.com/juanpimg) on 2026-10-20T18:24:04Z. --- While working on the recorder test registrations I ran every flag-scoped mode of the AGC driver against two devices, and one of them found a case of this. It is not a new symptom, but it locates the failure and shows why it is invisible today. ## Reproduction The test is `agc_driver_stencil_ref_export_unused_tests`, in `core/libs/prx/libSceAgcDriver/tests/execution/StencilRefExportUnused.cpp`. It takes a `--case` argument, and six of its eight cases fail on every device: | `--case` | NVIDIA RTX 4060, driver 615.78.08 | Intel Iris Xe, Mesa 26.2.4 ANV | |---|---|---| | `keep` | 0 | 0 | | `invert` | 0 | 0 | | `compare`, `back-compare`, `replace`, `fail-replace`, `depth-fail-replace`, `partial-replace` | 1 | 1 | The failure message is the test's own: ``` AGC graphics: a dependent reference without native stencil export was admitted ``` ## The two devices differ in the extension, and the test skips on one of them `VK_EXT_shader_stencil_export` is present on the Intel device and absent on the NVIDIA one. The test's `keep` and `invert` cases pass on both, and the six dependent cases fail on both. The reason the Intel run skips rather than fails is in the test's own expectation: it looks for the refusal ``` a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, which the device lacks ``` and on the Intel device the draw is admitted for a different reason, so the expectation does not hold there either. ## Where the refusal and the emulation live The message the test expects is thrown in `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cpp:380`, and it is reached only on the native path, that is, when `state.stencilRefVariable != 0` **and** `state.stencilReplay` is false. `state.stencilReplay` is set in `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp:425`, in the branch that runs when the device does not have the capability, and that branch emulates the stencil reference export instead of refusing it. So on a device without `VK_EXT_shader_stencil_export` the driver emulates the export, and the refusal the test expects no longer happens. The emulation has three preconditions of its own, each with its own message, and none of them fires for these six cases: the draw is admitted silently. Whether the emulation is right for a dependent stencil reference, or whether the draw has to be refused as the test expects, is a question about the console's own behaviour, which I cannot measure. I did not touch the driver. ## Why this is invisible `agc_driver_stencil_ref_export_unused_tests` is built, because the AGC execution tests are globbed from `tests/execution/*.cpp`, but no ctest entry runs it, and no ctest entry passes it a `--case` either. The six cases are therefore never executed by CI, and a local run only reaches them with the argument by hand. The registrations I am proposing in #8445 add the two cases that pass, `keep` and `invert`, and leave the six that fail out, so that the coverage grows without a red job.
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#4276
No description provided.