AGC: storing a resident linear color target after every draw keeps PPSA14363's PS1 games at about 10 fps; without it they run at 60 #9217

Closed
opened 2026-10-21 15:28:14 +00:00 by thuanquang · 5 comments
thuanquang commented 2026-10-21 15:28:14 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T15:28:14Z.


What

PPSA14363 (METAL GEAR SOLID Master Collection Vol. 1) runs its PS1 games through its own emulator. That emulator draws into three linear 3072x2048 R8G8B8A8 color targets of 24 MiB each, with up to about 80 draws per frame.

  • On main these targets have no host import, so every draw into them is synchronous. #9188 and #9202 make that path cheaper.
  • With an import, #6892 gives them a resident image, but stores the whole target back to guest memory after every draw.

That per-draw store keeps the PS1 intro at about 10 fps. Without it the same content runs at the display's 60 Hz.

Measured

RX 6700 XT, AMD Windows driver 32.0.21045.5002. Local builds on main 865166414f with local switches, which are not PRs. One run each. The table gives guest flips per second on the same content, aligned by guest flip count (the title advances one frame per flip):

guest flips main import, store after every draw import, no per-draw store import, no per-draw store, APS5_STORE_AT_LABEL=1
3000 to 3300 21.4 57.1 58.9 58.9
3300 to 3600 18.2 46.8 58.8 59.0
3600 to 3900 10.7 36.6 58.7 59.0
3900 to 4200 - 10.6 42.3 58.6
4200 to 5000 - - 36.6 58.5
5000 to 7000 - - 46.8 59.0
7000 to 9000 - - - 58.9
  • import: the draw path calls HostImportFor instead of ExistingHostImportFor for a linear target, which is #1191's case.
  • no per-draw store: keepRecordedDraw skips its FlushPending(..., "linear target").
  • Store after every draw. Per 10 s, 3000 to 3160 write-backs of the whole target (72 to 76 GB), and 2950 to 3120 pending-write syncs before them (7.9 to 8.2 s waited).
  • Without the per-draw store, the intro's frames look right over about 9900 flips: titles, subtitles, scene changes.
  • With APS5_STORE_AT_LABEL=1, the [storage] line lists no write-backs in those windows. The targets were apparently never stored back, and the title did not need them in guest memory. Its presents come from the resident images.
  • Without it, there were 50 to 80 idle write-backs per 10 s and 36 to 48 flips/s in the later scenes. I have not traced why the label flush stored nothing.
  • A - means the run did not reach those flips in its 150 or 180 s.

Question

#6892 stores linear targets after every draw so that CPU readers which bypass the flush hook still see the results. Its test reads guest memory with memcpy after WaitIdle. Tiled resident targets keep their results on the GPU until something reads them.

For linear targets, would keeping the results pending be acceptable? They would be stored by the existing access paths, waits, flips and idle stores, with #8246's changed-bytes merge. Or is there a cheaper rule that keeps CPU readers safe, such as storing at the labels and EOP events a guest waits on?

Related: #1191 (the import-creating case), #8246 (changed-bytes store-back, #8152), #9188, #9202.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5963482498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9217). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-21T15:28:14Z. --- ### What PPSA14363 (METAL GEAR SOLID Master Collection Vol. 1) runs its PS1 games through its own emulator. That emulator draws into three linear 3072x2048 R8G8B8A8 color targets of 24 MiB each, with up to about 80 draws per frame. - On `main` these targets have no host import, so every draw into them is synchronous. #9188 and #9202 make that path cheaper. - With an import, #6892 gives them a resident image, but stores the whole target back to guest memory after every draw. That per-draw store keeps the PS1 intro at about 10 fps. Without it the same content runs at the display's 60 Hz. ### Measured RX 6700 XT, AMD Windows driver 32.0.21045.5002. Local builds on `main` `865166414f` with local switches, which are not PRs. One run each. The table gives guest flips per second on the same content, aligned by guest flip count (the title advances one frame per flip): | guest flips | `main` | import, store after every draw | import, no per-draw store | import, no per-draw store, `APS5_STORE_AT_LABEL=1` | |---|---|---|---|---| | 3000 to 3300 | 21.4 | 57.1 | 58.9 | 58.9 | | 3300 to 3600 | 18.2 | 46.8 | 58.8 | 59.0 | | 3600 to 3900 | 10.7 | 36.6 | 58.7 | 59.0 | | 3900 to 4200 | - | 10.6 | 42.3 | 58.6 | | 4200 to 5000 | - | - | 36.6 | 58.5 | | 5000 to 7000 | - | - | 46.8 | 59.0 | | 7000 to 9000 | - | - | - | 58.9 | - **import:** the draw path calls `HostImportFor` instead of `ExistingHostImportFor` for a linear target, which is #1191's case. - **no per-draw store:** `keepRecordedDraw` skips its `FlushPending(..., "linear target")`. - **Store after every draw.** Per 10 s, 3000 to 3160 write-backs of the whole target (72 to 76 GB), and 2950 to 3120 pending-write syncs before them (7.9 to 8.2 s waited). - **Without the per-draw store**, the intro's frames look right over about 9900 flips: titles, subtitles, scene changes. - **With `APS5_STORE_AT_LABEL=1`**, the `[storage]` line lists no write-backs in those windows. The targets were apparently never stored back, and the title did not need them in guest memory. Its presents come from the resident images. - **Without it**, there were 50 to 80 idle write-backs per 10 s and 36 to 48 flips/s in the later scenes. I have not traced why the label flush stored nothing. - A `-` means the run did not reach those flips in its 150 or 180 s. ### Question #6892 stores linear targets after every draw so that CPU readers which bypass the flush hook still see the results. Its test reads guest memory with `memcpy` after `WaitIdle`. Tiled resident targets keep their results on the GPU until something reads them. For linear targets, would keeping the results pending be acceptable? They would be stored by the existing access paths, waits, flips and idle stores, with #8246's changed-bytes merge. Or is there a cheaper rule that keeps CPU readers safe, such as storing at the labels and EOP events a guest waits on? Related: #1191 (the import-creating case), #8246 (changed-bytes store-back, #8152), #9188, #9202.
thuanquang commented 2026-10-21 16:56:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T16:56:06Z.


Traced the open point from above, why APS5_STORE_AT_LABEL=1 stored nothing. I ran the same switches with APS5_TRACE_FLUSH=1 for 150 s into the PS1 section.

  • No labels in the PS1 command streams. The [packets] lines show, per 10 s:

    • DRAW_INDEX_AUTO and DRAW_INDEX_2
    • flip
    • SET_*_REG and SET_*_REG_INDIRECT
    • EVENT_WRITE and ACQUIRE_MEM (1186 to 1482 each)
    • NOP

    There is no RELEASE_MEM, WRITE_DATA or EOP packet, so WriteLabelOnGpu never runs. This guest syncs with the GPU through flips only.

  • What was stored in those 150 s. 26 [flush] lines in total:

    • 22 idle flushes, each of one of two other 8.4 MiB images;
    • 4 write-backs of the linear targets.
  • The earlier run without APS5_STORE_AT_LABEL. It had 50 to 80 idle write-backs per 10 s in its later scenes, many of them these 24 MiB targets, and ran slower there. With the same switches and no labels, the variable cannot have changed anything. So that difference came from when the GPU went idle, not from a store rule.

For the rule asked above, this means:

  • Storing pending linear results at labels costs nothing in this title.
  • Storing them at every flip would be up to 3 x 24 MiB per flip, close to the per-draw cost at 60 Hz.

This title never reads the targets with the CPU: its frames stay right with no store at all. A title that reads a linear target after a flip without a label would need more than a label rule.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321628529 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9217#issuecomment-6321628529). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-21T16:56:06Z. --- Traced the open point from above, why `APS5_STORE_AT_LABEL=1` stored nothing. I ran the same switches with `APS5_TRACE_FLUSH=1` for 150 s into the PS1 section. - **No labels in the PS1 command streams.** The `[packets]` lines show, per 10 s: - `DRAW_INDEX_AUTO` and `DRAW_INDEX_2` - `flip` - `SET_*_REG` and `SET_*_REG_INDIRECT` - `EVENT_WRITE` and `ACQUIRE_MEM` (1186 to 1482 each) - `NOP` There is no `RELEASE_MEM`, `WRITE_DATA` or EOP packet, so `WriteLabelOnGpu` never runs. This guest syncs with the GPU through flips only. - **What was stored in those 150 s.** 26 `[flush]` lines in total: - 22 `idle` flushes, each of one of two other 8.4 MiB images; - 4 write-backs of the linear targets. - **The earlier run without `APS5_STORE_AT_LABEL`.** It had 50 to 80 idle write-backs per 10 s in its later scenes, many of them these 24 MiB targets, and ran slower there. With the same switches and no labels, the variable cannot have changed anything. So that difference came from when the GPU went idle, not from a store rule. For the rule asked above, this means: - Storing pending linear results at labels costs nothing in this title. - Storing them at every flip would be up to 3 x 24 MiB per flip, close to the per-draw cost at 60 Hz. This title never reads the targets with the CPU: its frames stay right with no store at all. A title that reads a linear target after a flip without a label would need more than a label rule.
thuanquang commented 2026-10-21 18:27:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T18:27:25Z.


Gameplay numbers with the same local switches as the last column above (import created, no per-draw store, APS5_STORE_AT_LABEL=1, on main 865166414f, with stop 1 bypassed locally; #9115 fixes it).

MGS1 gameplay at the Dock, about 110 s of it:

  • 600 presents in every 10 s window.
  • Frame time p50 16.7 ms, p99 17.1 to 17.4 ms, max 17.3 to 18.0 ms per window.
  • The frame dumps look right. They end as gameplay starts, with the radar and the opening credits on screen.

One run, RX 6700 XT, APS5_TRACE_SUMMARY_EVERY=10 only (no profiler).

So in this title the two things these switches stand for take MGS1 gameplay to 60 fps: an import for the linear targets (#1191's case) and no store of them after every draw. #9188 and #9202 only make the synchronous path cheaper. With both, the PS1 intro reaches 35 to 58 flips/s on equal content.

For comparison, main b00235dda0 + #9115 + #9188 + #9202, with none of the switches, same machine, one run of 420 s. It did not reach gameplay in that time:

  • The PS1 opening ran at 7 to 39 presents per second.
  • The first codec call held 19: 194 presents per 10 s, frame p50 69 ms, Driver.Packet about 41 ms per present.
  • Frames rendered correctly.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323460437 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9217#issuecomment-6323460437). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-21T18:27:25Z. --- Gameplay numbers with the same local switches as the last column above (import created, no per-draw store, `APS5_STORE_AT_LABEL=1`, on `main` `865166414f`, with stop 1 bypassed locally; #9115 fixes it). MGS1 gameplay at the Dock, about 110 s of it: - 600 presents in every 10 s window. - Frame time p50 16.7 ms, p99 17.1 to 17.4 ms, max 17.3 to 18.0 ms per window. - The frame dumps look right. They end as gameplay starts, with the radar and the opening credits on screen. One run, RX 6700 XT, `APS5_TRACE_SUMMARY_EVERY=10` only (no profiler). So in this title the two things these switches stand for take MGS1 gameplay to 60 fps: an import for the linear targets (#1191's case) and no store of them after every draw. #9188 and #9202 only make the synchronous path cheaper. With both, the PS1 intro reaches 35 to 58 flips/s on equal content. For comparison, `main` `b00235dda0` + #9115 + #9188 + #9202, with none of the switches, same machine, one run of 420 s. It did not reach gameplay in that time: - The PS1 opening ran at 7 to 39 presents per second. - The first codec call held 19: 194 presents per 10 s, frame p50 69 ms, `Driver.Packet` about 41 ms per present. - Frames rendered correctly.
MarcZX10 commented 2026-10-22 04:16:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:16:31Z.


The added trace evidence resolves why APS5_STORE_AT_LABEL=1 made no difference here: there are no label/EOP packets in this title’s command stream, and the observed speed difference tracks idle-flush timing. I would keep the normal resident-linear-target visibility guarantee for now. This title’s lack of CPU reads during the measured route does not establish that all titles avoid reading the same guest memory, and the existing issue/PR chain (#6892/#8246) specifically protects CPU writes/read visibility around resident draws. A label-only policy would still leave a title that reads the target after a flip without a label observing stale bytes. The present evidence supports optimizing the synchronous path (#9188/#9202) and recording this title-specific behavior, but not removing the general store boundary absent an access-path proof or a general synchronization contract plus regression coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332557448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9217#issuecomment-6332557448). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:16:31Z. --- The added trace evidence resolves why `APS5_STORE_AT_LABEL=1` made no difference here: there are no label/EOP packets in this title’s command stream, and the observed speed difference tracks idle-flush timing. I would keep the normal resident-linear-target visibility guarantee for now. This title’s lack of CPU reads during the measured route does not establish that all titles avoid reading the same guest memory, and the existing issue/PR chain (#6892/#8246) specifically protects CPU writes/read visibility around resident draws. A label-only policy would still leave a title that reads the target after a flip without a label observing stale bytes. The present evidence supports optimizing the synchronous path (#9188/#9202) and recording this title-specific behavior, but not removing the general store boundary absent an access-path proof or a general synchronization contract plus regression coverage.
thuanquang commented 2026-10-22 05:15:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-22T05:15:52Z.


Thanks. Here is a proposal for the "general synchronization contract plus regression coverage" you mention. It would let the per-draw store go without falling back to a label-only policy.

Contract. A resident linear color target written by recorded draws is stored to guest memory before each point where the guest can first observe that those draws completed:

  • Flips: both FlipPacketHeader flips and RELEASE_MEM-attached EOP flips. The store is recorded before the flip's SubmitRecorded, so the flip's EOP interrupt follows it.
  • Labels and EOP interrupts: labels through #6948's StoreReadbackBeforeLabel, plus the interrupt-only RELEASE_MEM branch of commitLabel, which #6948 does not hook yet.
  • Drains and VulkanDevice::WaitIdle.
  • As today: the idle store, the driver's access hooks and eviction.

A title that reads the target after a flip without a label then sees the flip's results, which is the case you raised. The only thing it stops seeing early is a read with no signal at all, and on a console that read races the GPU too.

Bytes. Each store copies only the union of the draws' scissors since the last store: per-row spans at the guest pitch, GPU-direct into the import. A store does not wait for the same image's previous store under #6364's check.

Tests. Where the guarantee depends on the queue worker, the tests go through AgcDriver::Submit, and all of them read with raw memcpy or volatile loads:

  • agc_driver_linear_target_resident stays unchanged; it is covered by the WaitIdle store.
  • CnRJay's case: a host-imported block explicitly taken out of the watch, a draw, a flip, then a WAIT_REG_MEM gate so no idle store can run. CPU loads must see the draw. It fails with the per-draw loop deleted and no flip store.
  • The same with a label, with an interrupt-only EOP, with a drain, and with APS5_SYNC_FLIP=1.
  • #8152's reproducer, ported from #8246's LinearTargetCpuWrites with credit, on a watched and an unwatched block: CPU stores outside the drawn rectangle survive.
  • Pending until a completion point: after each draw the image is pending and nothing has been submitted; after WaitIdle it is stored.

#8246. The two could split by ownership:

  • This change owns when the store happens and the bytes outside the drawn rectangle.
  • #8246 keeps the byte-exact merge inside the rectangle, with its memory bounded, for example by one baseline per target as adriadam10 suggested.

Would that work for you?

Import creation (#1191's case) stays a separate PR on top, together with its author.

What it changes for PPSA14363. Main plus #9188, #9202, #9373 and #9602 leaves the PS1 codec at about 19 fps, and the stutter is audible. In a local capture of the title's sceAudioOut stream, 50 to 81 % of its 256-frame buffers repeat the previous buffer there: the title's audio thread re-sends its last buffer while its PS1 emulator is behind. With the local switches at 60 fps it is 0.0 to 0.2 %.

If this sounds acceptable, I'll implement it on top of #6948 and post the numbers there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333318801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9217#issuecomment-6333318801). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-22T05:15:52Z. --- Thanks. Here is a proposal for the "general synchronization contract plus regression coverage" you mention. It would let the per-draw store go without falling back to a label-only policy. **Contract.** A resident linear color target written by recorded draws is stored to guest memory before each point where the guest can first observe that those draws completed: - **Flips:** both `FlipPacketHeader` flips and RELEASE_MEM-attached EOP flips. The store is recorded before the flip's `SubmitRecorded`, so the flip's EOP interrupt follows it. - **Labels and EOP interrupts:** labels through #6948's `StoreReadbackBeforeLabel`, plus the interrupt-only RELEASE_MEM branch of `commitLabel`, which #6948 does not hook yet. - **Drains and `VulkanDevice::WaitIdle`.** - **As today:** the idle store, the driver's access hooks and eviction. A title that reads the target after a flip without a label then sees the flip's results, which is the case you raised. The only thing it stops seeing early is a read with no signal at all, and on a console that read races the GPU too. **Bytes.** Each store copies only the union of the draws' scissors since the last store: per-row spans at the guest pitch, GPU-direct into the import. A store does not wait for the same image's previous store under #6364's check. **Tests.** Where the guarantee depends on the queue worker, the tests go through `AgcDriver::Submit`, and all of them read with raw memcpy or volatile loads: - `agc_driver_linear_target_resident` stays unchanged; it is covered by the WaitIdle store. - CnRJay's case: a host-imported block explicitly taken out of the watch, a draw, a flip, then a WAIT_REG_MEM gate so no idle store can run. CPU loads must see the draw. It fails with the per-draw loop deleted and no flip store. - The same with a label, with an interrupt-only EOP, with a drain, and with `APS5_SYNC_FLIP=1`. - #8152's reproducer, ported from #8246's `LinearTargetCpuWrites` with credit, on a watched and an unwatched block: CPU stores outside the drawn rectangle survive. - Pending until a completion point: after each draw the image is pending and nothing has been submitted; after WaitIdle it is stored. **#8246.** The two could split by ownership: - This change owns when the store happens and the bytes outside the drawn rectangle. - #8246 keeps the byte-exact merge inside the rectangle, with its memory bounded, for example by one baseline per target as adriadam10 suggested. Would that work for you? **Import creation** (#1191's case) stays a separate PR on top, together with its author. **What it changes for PPSA14363.** Main plus #9188, #9202, #9373 and #9602 leaves the PS1 codec at about 19 fps, and the stutter is audible. In a local capture of the title's sceAudioOut stream, 50 to 81 % of its 256-frame buffers repeat the previous buffer there: the title's audio thread re-sends its last buffer while its PS1 emulator is behind. With the local switches at 60 fps it is 0.0 to 0.2 %. If this sounds acceptable, I'll implement it on top of #6948 and post the numbers there.
thuanquang commented 2026-10-22 08:29:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-22T08:29:33Z.


@MarcZX10 the contract proposed above is now #9685, with its tests: completion points through AgcDriver::Submit with the queue held by a WAIT_REG_MEM, #8152's CPU stores after Draw (ported from #8246 with credit), CPU stores outside the drawn rectangle, and a target pending until WaitIdle. On PPSA14363, with the targets resident (#1191's import case, local), MGS1's PS1 opening goes from 158-168 presents per 10 s with the per-draw store to 591-600.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336338251 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9217#issuecomment-6336338251). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-22T08:29:33Z. --- @MarcZX10 the contract proposed above is now #9685, with its tests: completion points through `AgcDriver::Submit` with the queue held by a `WAIT_REG_MEM`, #8152's CPU stores after `Draw` (ported from #8246 with credit), CPU stores outside the drawn rectangle, and a target pending until `WaitIdle`. On PPSA14363, with the targets resident (#1191's import case, local), MGS1's PS1 opening goes from 158-168 presents per 10 s with the per-draw store to 591-600.
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#9217
No description provided.