fix(agc): drain the draw pipeline before a vertex table read overtakes a queued write #7691

Merged
Celegans12 merged 5 commits from upstream-pr/7691 into main 2026-10-23 11:18:30 +00:00
Celegans12 commented 2026-10-19 00:02:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T00:02:21Z.


What

Driver::draw decodes a vertex stage's fetch tables (the attribute words and the vertex buffer V#s they name) with GuestMemory::Read in Graphics::DecodeVertexStageInfo. What a draw's shaders read goes through ShaderMemory, whose queryPendingWrite drains queue 0's draw pipeline when the range overlaps a write that is still queued; the decode reads skip that check. With the default depth of 8, a draw can take its vertex buffer V# from a table before a queued item has stored into it, and then fetch from the old buffer.

  • DecodeOrderedVertexStageInfo (DrawDecode.cpp) decodes, and when one of the decode's reads overlaps a queued write, drains the pipeline (DrainReason::Capture, as queryPendingWrite does) and decodes again. Writes the draw finisher still holds count as queued, as in Overlaps.
  • A store that finishes during the decode is no longer queued by the time of that check, so queue 0 counts retired items. Before the decode the helper notes that count and the write ranges queued then. It also drains and decodes again when the count moved and a read overlaps a range that was queued at the start. Off the queue-0 worker, or with an idle queue, it is the old decode.
  • The [draw] pipelined line (APS5_PROFILE_DRAW) counts the drains the decode causes.
  • decodeVertexInfo in Driver::draw uses it at all four call sites.

I found this reading the draw path while profiling Ghost of Yōtei (PPSA26344); I haven't seen a title draw wrong because of it.

Related: #1896 checks reads for its pipelined indirect draws (APS5_PIPELINE_INDIRECT); this covers the default path, on other lines. #7446 compares captured memory before recording, which can't see a write that is still queued.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 0db47b263, configure -DBUILD_TESTING=ON: the touched draw-pipeline, draw-cache and decode tests pass (22/22, --repeat until-fail:3); agc_driver_vertex_table_read_order also with APS5_DRAW_PIPELINE=1.
  • New agc_driver_vertex_table_read_order: stores queued into the buffer and attribute tables drain and are seen, also one that finishes during the decode; a store elsewhere stays queued, and a table a finished item wrote, or a store elsewhere that retires mid-decode, drains nothing. It doesn't link on main; with the drain removed it fails ("the vertex buffer V# was read before the queued store ..."), without the retired-count check too ("the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode").
  • Linux (WSL Ubuntu 24.04, gcc 13.3, lavapipe), CI's Linux configure on the merge with main 0a0ed721: the same tests pass (22/22).
  • Not run on a title with this branch. Our local Yōtei tree has had the same check, written differently, since 2026-10-18; its reference run still matched.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.62, Windows 11; lavapipe (Mesa 25.2.8) on Ubuntu 24.04 (WSL)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4913963990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-19T00:02:21Z. --- ### What `Driver::draw` decodes a vertex stage's fetch tables (the attribute words and the vertex buffer V#s they name) with `GuestMemory::Read` in `Graphics::DecodeVertexStageInfo`. What a draw's shaders read goes through `ShaderMemory`, whose `queryPendingWrite` drains queue 0's draw pipeline when the range overlaps a write that is still queued; the decode reads skip that check. With the default depth of 8, a draw can take its vertex buffer V# from a table before a queued item has stored into it, and then fetch from the old buffer. - `DecodeOrderedVertexStageInfo` (`DrawDecode.cpp`) decodes, and when one of the decode's reads overlaps a queued write, drains the pipeline (`DrainReason::Capture`, as `queryPendingWrite` does) and decodes again. Writes the draw finisher still holds count as queued, as in `Overlaps`. - A store that finishes during the decode is no longer queued by the time of that check, so queue 0 counts retired items. Before the decode the helper notes that count and the write ranges queued then. It also drains and decodes again when the count moved and a read overlaps a range that was queued at the start. Off the queue-0 worker, or with an idle queue, it is the old decode. - The `[draw] pipelined` line (`APS5_PROFILE_DRAW`) counts the drains the decode causes. - `decodeVertexInfo` in `Driver::draw` uses it at all four call sites. I found this reading the draw path while profiling Ghost of Yōtei (PPSA26344); I haven't seen a title draw wrong because of it. Related: #1896 checks reads for its pipelined indirect draws (`APS5_PIPELINE_INDIRECT`); this covers the default path, on other lines. #7446 compares captured memory before recording, which can't see a write that is still queued. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 0db47b263, configure -DBUILD_TESTING=ON: the touched draw-pipeline, draw-cache and decode tests pass (22/22, `--repeat until-fail:3`); `agc_driver_vertex_table_read_order` also with `APS5_DRAW_PIPELINE=1`. - New `agc_driver_vertex_table_read_order`: stores queued into the buffer and attribute tables drain and are seen, also one that finishes during the decode; a store elsewhere stays queued, and a table a finished item wrote, or a store elsewhere that retires mid-decode, drains nothing. It doesn't link on `main`; with the drain removed it fails ("the vertex buffer V# was read before the queued store ..."), without the retired-count check too ("the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode"). - Linux (WSL Ubuntu 24.04, gcc 13.3, lavapipe), CI's Linux configure on the merge with `main` 0a0ed721: the same tests pass (22/22). - Not run on a title with this branch. Our local Yōtei tree has had the same check, written differently, since 2026-10-18; its reference run still matched. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.62, Windows 11; lavapipe (Mesa 25.2.8) on Ubuntu 24.04 (WSL) - [x] AI-assisted: yes
savvaniss commented 2026-10-19 07:43:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T07:43:29Z.


Windows build note: this head 695fa3554 merges into main 6b8228b2b without conflicts, but it no longer compiles there:

core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp:41:147: error: 'const struct AgcDriver::Graphics::DecodeRead' has no member named 'bytes'; did you mean 'Bytes'?

On main, DecodeRead (Graphics/include/ShaderInputState.hpp) has a Bytes() accessor instead of a bytes member, so line 41's read.bytes.size() needs updating for the current main. Because of that I couldn't run agc_driver_vertex_table_read_order on the Intel UHD 770 and AMD RX 9070 XT. I'll rerun it once the head builds on main (WinLibs GCC 15.2.0 r7, Release, Windows 11 Pro 26300).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262253781 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6262253781). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-19T07:43:29Z. --- Windows build note: this head `695fa3554` merges into `main` `6b8228b2b` without conflicts, but it no longer compiles there: ``` core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp:41:147: error: 'const struct AgcDriver::Graphics::DecodeRead' has no member named 'bytes'; did you mean 'Bytes'? ``` On `main`, `DecodeRead` (`Graphics/include/ShaderInputState.hpp`) has a `Bytes()` accessor instead of a `bytes` member, so line 41's `read.bytes.size()` needs updating for the current `main`. Because of that I couldn't run `agc_driver_vertex_table_read_order` on the Intel UHD 770 and AMD RX 9070 XT. I'll rerun it once the head builds on `main` (WinLibs GCC 15.2.0 r7, Release, Windows 11 Pro 26300). AI-assisted: yes (Claude Code)
Celegans12 commented 2026-10-19 22:04:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T22:04:44Z.


Thanks for catching the build break, @savvaniss. DecodeRead lost its bytes member to the Bytes() accessor on main, and @adriadam10 has already rebased the branch and pushed the two-line change (fe5ae13d4) that reads through Bytes() in DrawDecode.cpp and in the test, so I left the branch as it is.

I built that head merged into current main (eaa5c9238) and reran the focused tests: agc_driver_vertex_table_read_order, agc_driver_graphics, the draw-cache reuse tests, the agc_driver_pipelined_* tests and agc_driver_vertex_user_data_tail pass, 15/15 on Windows (RTX 3080 Laptop, driver 610.62) and 15/15 on lavapipe in WSL.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278397724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6278397724). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-19T22:04:44Z. --- Thanks for catching the build break, @savvaniss. `DecodeRead` lost its `bytes` member to the `Bytes()` accessor on `main`, and @adriadam10 has already rebased the branch and pushed the two-line change (fe5ae13d4) that reads through `Bytes()` in `DrawDecode.cpp` and in the test, so I left the branch as it is. I built that head merged into current `main` (eaa5c9238) and reran the focused tests: `agc_driver_vertex_table_read_order`, `agc_driver_graphics`, the draw-cache reuse tests, the `agc_driver_pipelined_*` tests and `agc_driver_vertex_user_data_tail` pass, 15/15 on Windows (RTX 3080 Laptop, driver 610.62) and 15/15 on lavapipe in WSL.
VicRaster commented 2026-10-19 22:25:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by VicRaster on 2026-10-19T22:25:30Z.


Independent review of fe5ae13d41133c094d7b1e71653e9efd7b9ca9f3: I can reproduce a completed queued attribute-table store escaping the post-decode check in DecodeOrderedVertexStageInfo.

The helper decodes before checking Busy/Overlaps. If the earlier writer completes during that decode and is removed from the queue, the helper can return the earlier vertex-buffer selection.

The synthetic test below uses the existing GuestMemory::SetReadGuard facility to force that sequence without changing production code:

  1. An attribute initially selects buffer 0 (0x1000). An earlier FIFO item is held before storing an attribute that selects buffer 1 (0x7000); its declared write range covers the attribute table.
  2. The decoder reads and records the old attribute.
  3. At the following buffer-descriptor read, the guard verifies that the old attribute was captured, releases the queued writer, and waits for its queue item to be removed.
  4. Decoding completes with buffer 0. The subsequent queue check finds the writer already gone and returns 0x1000, although the completed attribute store selects 0x7000.

The writer is an earlier item in the same FIFO, matching the ordering premise of this PR's test. The read guard only controls scheduling; the queued callback performs the attribute write. The atomic release and queue mutex order the reads and write. No timing sleep establishes the interleaving.

Tested on Windows / Ryzen 9 3900X, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, with a fresh build of the AGC runtime and its dependencies from this head. GitHub's merge-test commit f7603664f2224f1b3c2d585baf11519a047bd55d had the same complete source tree (b45dbbbf4f07e4af0fcb02d3b025258641594bb1). Runtime lookup was restricted to the fresh build, supported toolchain and Windows system directories.

Case Result
Existing agc_driver_vertex_table_read_order Passed 3/3, and passed again against the final runtime
New test, --producer-first Passed 3/3: 0x7000
New test, --drain-first Passed 3/3: 0x7000
New test, completion during decode Failed 3/3: 0x1000, expected 0x7000

The drain-first control releases the writer when it observes the default Capture drain request (0x100), so a path that drains before decoding can complete without relying on the speculative-read gate. The test reports which release path occurred. Source/commit conventions also passed for the added file.

This establishes a helper-level ordering failure. I have not reproduced incorrect rendered output or a game regression, and this CPU test does not exercise Vulkan or host imports. The later direct queued path carries materialised stages into commitDraw without rerunning this decoder, but some shaders perform independent runtime descriptor reads, so I am not claiming every draw using these tables is affected.

This is an intentionally failing review reproducer, to adapt alongside the final fix. To reproduce, save the file below as core/libs/prx/libSceAgcDriver/tests/execution/VertexTableReadOrderCompletion.cpp on this head. With the supported Windows build environment already set up:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON "-DANYPS5_AGC_EXECUTION_TESTS=VertexTableReadOrder;VertexTableReadOrderCompletion"
cmake --build build --target agc_driver_vertex_table_read_order_tests agc_driver_vertex_table_read_order_completion_tests --parallel
ctest --test-dir build -R '^agc_driver_vertex_table_read_order$' -V
ctest --test-dir build -R '^agc_driver_vertex_table_read_order_completion$' -V
$env:PATH = (Resolve-Path build/core/libs/libs/unpatched).Path + ';' + $env:PATH
./build/tests/agc_driver_vertex_table_read_order_completion_tests.exe --producer-first
./build/tests/agc_driver_vertex_table_read_order_completion_tests.exe --drain-first

The completion test is expected to fail on this head with a completed earlier attribute store escaped the post-decode overlap check; both controls should pass. The result suggests the ordering proof needs to account for producers that finish during decoding, rather than only those still pending afterward.

VertexTableReadOrderCompletion.cpp
#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include "prx/libSceAgc/Shader/include/ShaderConstants.hpp"
#include "SceShaders.hpp"
#include <array>
#include <atomic>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <memory>
#include <iostream>
#include <span>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>

namespace {

using AgcDriver::DriverDetail::DrawPipeline;

void check(bool condition, const std::string& what) {
    if (!condition) throw std::runtime_error("vertex table read order: " + what);
}

constexpr std::size_t UserDataOffset = 288;
constexpr std::size_t DirectOffset = 352;
constexpr std::size_t SemanticOffset = 384;

alignas(64) std::array<std::uint32_t, 8> BufferTable{0x1000u, 0x20000u, 64u, 0x3000u, 0x7000u, 0x20000u, 32u, 0x3000u};
alignas(64) std::array<std::uint32_t, 1> AttribTable{(0x2cu << 5u) | 1u};
std::vector<std::byte> Header(SemanticOffset + sizeof(ShaderSemantic));

void BuildHeader() {
    std::array<std::uint16_t, ShaderRegs::AGC_DIRECT_RESOURCE_TYPE_COUNT> direct{};
    direct.fill(ShaderRegs::AGC_ILLEGAL_DIRECT_OFFSET);
    direct[static_cast<std::size_t>(ShaderRegs::AgcDirectResourceType::PtrVertexBufferTable)] = 0;
    direct[static_cast<std::size_t>(ShaderRegs::AgcDirectResourceType::PtrVertexAttribDescTable)] = 2;
    std::memcpy(Header.data() + DirectOffset, direct.data(), sizeof(direct));
    ShaderSemantic semantic{};
    semantic.size_in_elements = 1;
    std::memcpy(Header.data() + SemanticOffset, &semantic, sizeof(semantic));
    ShaderUserData userData{};
    userData.direct_resource_offset = reinterpret_cast<std::uint16_t*>(Header.data() + DirectOffset);
    userData.direct_resource_count = ShaderRegs::AGC_DIRECT_RESOURCE_TYPE_COUNT;
    std::memcpy(Header.data() + UserDataOffset, &userData, sizeof(userData));
    Shader shader{};
    shader.user_data = reinterpret_cast<ShaderUserData*>(Header.data() + UserDataOffset);
    shader.input_semantics = reinterpret_cast<ShaderSemantic*>(Header.data() + SemanticOffset);
    shader.num_input_semantics = 1;
    std::memcpy(Header.data(), &shader, sizeof(shader));
}

std::uint64_t Address(const void* data) {
    return static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(data));
}

std::array<std::uint32_t, 4> UserWords() {
    const auto buffer = Address(BufferTable.data());
    const auto attrib = Address(AttribTable.data());
    return {static_cast<std::uint32_t>(buffer), static_cast<std::uint32_t>(buffer >> 32u), static_cast<std::uint32_t>(attrib), static_cast<std::uint32_t>(attrib >> 32u)};
}

ShaderRecompiler::ShaderVertexStageInfo Decode(std::vector<AgcDriver::Graphics::DecodeRead>& reads) {
    const auto userWords = UserWords();
    return AgcDriver::DriverDetail::DecodeOrderedVertexStageInfo(Header, Address(Header.data()), userWords, reads, 0);
}

std::shared_ptr<std::atomic<bool>> releaseProducer;
std::atomic<unsigned> releaseCause{0};
bool producerCompletedDuringDecode = false;
std::vector<AgcDriver::Graphics::DecodeRead>* activeReads = nullptr;

void CompleteProducerAtBufferRead(std::uint64_t address, std::size_t bytes) {
    if (address != Address(BufferTable.data()) || !releaseProducer) return;
    check(bytes == 16 && activeReads != nullptr && activeReads->size() == 1,
          "the gate did not run between the attribute read and its V# read");
    std::uint32_t capturedAttribute = 1;
    std::memcpy(&capturedAttribute, activeReads->front().Bytes().data(), sizeof(capturedAttribute));
    check((capturedAttribute & 31u) == 0 && (AttribTable[0] & 31u) == 0,
          "the producer was not held until after the old attribute was captured");
    releaseCause.store(1, std::memory_order_release);
    releaseProducer->store(true, std::memory_order_release);
    const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
    while (DrawPipeline::QueuedItems() != 0) {
        check(std::chrono::steady_clock::now() < deadline, "the ordered producer did not finish");
        std::this_thread::yield();
    }
    producerCompletedDuringDecode = true;
}

struct ReadGuardScope {
    ReadGuardScope() { AgcDriver::GuestMemory::SetReadGuard(&CompleteProducerAtBufferRead); }
    ~ReadGuardScope() { AgcDriver::GuestMemory::SetReadGuard(nullptr); }
};

}

int main(int argc, char** argv) {
    try {
        const bool producerFirst = argc == 2 && std::string(argv[1]) == "--producer-first";
        const bool drainFirst = argc == 2 && std::string(argv[1]) == "--drain-first";
        check(argc == 1 || producerFirst || drainFirst, "unknown test argument");
        BuildHeader();
        AttribTable[0] = 0x2cu << 5u;
        DrawPipeline::Active() = true;
        std::vector<AgcDriver::Graphics::DecodeRead> reads;
        const auto control = Decode(reads);
        check(control.resourcesNum == 1 && control.resources[0].fields[0] == 0x1000u,
              "the initial attribute did not select the first vertex buffer");
        releaseProducer = std::make_shared<std::atomic<bool>>(false);
        const auto drainBefore = DrawPipeline::DrainRequestsByOpcode(0x100u);
        DrawPipeline::Queue0().Enqueue([release = releaseProducer, drainBefore] {
            const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
            while (!release->load(std::memory_order_acquire)) {
                if (DrawPipeline::DrainRequestsByOpcode(0x100u) != drainBefore) {
                    releaseCause.store(2, std::memory_order_release);
                    break;
                }
                check(std::chrono::steady_clock::now() < deadline, "the producer gate was not released");
                std::this_thread::yield();
            }
            AttribTable[0] = (0x2cu << 5u) | 1u;
        }, {{Address(AttribTable.data()), Address(AttribTable.data()) + sizeof(AttribTable)}});
        check(DrawPipeline::Queue0().Overlaps(Address(AttribTable.data()), sizeof(AttribTable)),
              "the earlier queued producer has no overlapping write range");
        if (producerFirst) {
            releaseCause.store(3, std::memory_order_release);
            releaseProducer->store(true, std::memory_order_release);
            const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
            while (DrawPipeline::QueuedItems() != 0) {
                check(std::chrono::steady_clock::now() < deadline, "the control producer did not finish");
                std::this_thread::yield();
            }
        }
        if (drainFirst) DrawPipeline::Queue0().Drain(DrawPipeline::DrainReason::Capture);
        ShaderRecompiler::ShaderVertexStageInfo info;
        activeReads = &reads;
        {
            ReadGuardScope guard;
            info = Decode(reads);
        }
        check(producerFirst || producerCompletedDuringDecode || releaseCause.load(std::memory_order_acquire) == 2,
              "neither the completion interleaving nor an ordering drain was exercised");
        check(DrawPipeline::QueuedItems() == 0 && (AttribTable[0] & 31u) == 1u,
              "the earlier queued attribute store did not complete");
        std::printf("producer completed; queue empty; decoded V# 0x%x; expected 0x7000\n", info.resources[0].fields[0]);
        std::printf("producer release cause %u (1=read gate, 2=ordering drain, 3=control)\n",
                    releaseCause.load(std::memory_order_acquire));
        DrawPipeline::Active() = false;
        DrawPipeline::Queue0().Stop();
        check(info.resourcesNum == 1 && info.resources[0].fields[0] == 0x7000u,
              "a completed earlier attribute store escaped the post-decode overlap check");
        std::puts("vertex table completion order tests passed");
        return 0;
    } catch (const std::exception& error) {
        AgcDriver::GuestMemory::SetReadGuard(nullptr);
        if (releaseProducer) releaseProducer->store(true, std::memory_order_release);
        DrawPipeline::Active() = false;
        DrawPipeline::Queue0().Stop();
        std::cerr << error.what() << '\n';
        return 1;
    }
}

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278717409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6278717409). Originally posted by [VicRaster](https://github.com/VicRaster) on 2026-10-19T22:25:30Z. --- Independent review of `fe5ae13d41133c094d7b1e71653e9efd7b9ca9f3`: I can reproduce a completed queued attribute-table store escaping the post-decode check in `DecodeOrderedVertexStageInfo`. The helper [decodes before checking Busy/Overlaps](https://github.com/boykopovar/AnyPS5/blob/fe5ae13d41133c094d7b1e71653e9efd7b9ca9f3/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp#L34). If the earlier writer completes during that decode and is removed from the queue, the helper can return the earlier vertex-buffer selection. The synthetic test below uses the existing `GuestMemory::SetReadGuard` facility to force that sequence without changing production code: 1. An attribute initially selects buffer 0 (`0x1000`). An earlier FIFO item is held before storing an attribute that selects buffer 1 (`0x7000`); its declared write range covers the attribute table. 2. The decoder reads and records the old attribute. 3. At the following buffer-descriptor read, the guard verifies that the old attribute was captured, releases the queued writer, and waits for its queue item to be removed. 4. Decoding completes with buffer 0. The subsequent queue check finds the writer already gone and returns `0x1000`, although the completed attribute store selects `0x7000`. The writer is an earlier item in the same FIFO, matching the ordering premise of this PR's test. The read guard only controls scheduling; the queued callback performs the attribute write. The atomic release and queue mutex order the reads and write. No timing sleep establishes the interleaving. Tested on Windows / Ryzen 9 3900X, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, with a fresh build of the AGC runtime and its dependencies from this head. GitHub's merge-test commit `f7603664f2224f1b3c2d585baf11519a047bd55d` had the same complete source tree (`b45dbbbf4f07e4af0fcb02d3b025258641594bb1`). Runtime lookup was restricted to the fresh build, supported toolchain and Windows system directories. | Case | Result | |---|---| | Existing `agc_driver_vertex_table_read_order` | Passed 3/3, and passed again against the final runtime | | New test, `--producer-first` | Passed 3/3: `0x7000` | | New test, `--drain-first` | Passed 3/3: `0x7000` | | New test, completion during decode | Failed 3/3: `0x1000`, expected `0x7000` | The drain-first control releases the writer when it observes the default Capture drain request (`0x100`), so a path that drains before decoding can complete without relying on the speculative-read gate. The test reports which release path occurred. Source/commit conventions also passed for the added file. This establishes a helper-level ordering failure. I have **not** reproduced incorrect rendered output or a game regression, and this CPU test does not exercise Vulkan or host imports. The later direct queued path carries materialised stages into `commitDraw` without rerunning this decoder, but some shaders perform independent runtime descriptor reads, so I am not claiming every draw using these tables is affected. This is an intentionally failing review reproducer, to adapt alongside the final fix. To reproduce, save the file below as `core/libs/prx/libSceAgcDriver/tests/execution/VertexTableReadOrderCompletion.cpp` on this head. With the supported Windows build environment already set up: ```powershell cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON "-DANYPS5_AGC_EXECUTION_TESTS=VertexTableReadOrder;VertexTableReadOrderCompletion" cmake --build build --target agc_driver_vertex_table_read_order_tests agc_driver_vertex_table_read_order_completion_tests --parallel ctest --test-dir build -R '^agc_driver_vertex_table_read_order$' -V ctest --test-dir build -R '^agc_driver_vertex_table_read_order_completion$' -V $env:PATH = (Resolve-Path build/core/libs/libs/unpatched).Path + ';' + $env:PATH ./build/tests/agc_driver_vertex_table_read_order_completion_tests.exe --producer-first ./build/tests/agc_driver_vertex_table_read_order_completion_tests.exe --drain-first ``` The completion test is expected to fail on this head with `a completed earlier attribute store escaped the post-decode overlap check`; both controls should pass. The result suggests the ordering proof needs to account for producers that finish during decoding, rather than only those still pending afterward. <details> <summary>VertexTableReadOrderCompletion.cpp</summary> ```cpp #include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp" #include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hpp" #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp" #include "prx/libSceAgc/Shader/include/ShaderConstants.hpp" #include "SceShaders.hpp" #include <array> #include <atomic> #include <chrono> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstring> #include <memory> #include <iostream> #include <span> #include <stdexcept> #include <string> #include <thread> #include <vector> namespace { using AgcDriver::DriverDetail::DrawPipeline; void check(bool condition, const std::string& what) { if (!condition) throw std::runtime_error("vertex table read order: " + what); } constexpr std::size_t UserDataOffset = 288; constexpr std::size_t DirectOffset = 352; constexpr std::size_t SemanticOffset = 384; alignas(64) std::array<std::uint32_t, 8> BufferTable{0x1000u, 0x20000u, 64u, 0x3000u, 0x7000u, 0x20000u, 32u, 0x3000u}; alignas(64) std::array<std::uint32_t, 1> AttribTable{(0x2cu << 5u) | 1u}; std::vector<std::byte> Header(SemanticOffset + sizeof(ShaderSemantic)); void BuildHeader() { std::array<std::uint16_t, ShaderRegs::AGC_DIRECT_RESOURCE_TYPE_COUNT> direct{}; direct.fill(ShaderRegs::AGC_ILLEGAL_DIRECT_OFFSET); direct[static_cast<std::size_t>(ShaderRegs::AgcDirectResourceType::PtrVertexBufferTable)] = 0; direct[static_cast<std::size_t>(ShaderRegs::AgcDirectResourceType::PtrVertexAttribDescTable)] = 2; std::memcpy(Header.data() + DirectOffset, direct.data(), sizeof(direct)); ShaderSemantic semantic{}; semantic.size_in_elements = 1; std::memcpy(Header.data() + SemanticOffset, &semantic, sizeof(semantic)); ShaderUserData userData{}; userData.direct_resource_offset = reinterpret_cast<std::uint16_t*>(Header.data() + DirectOffset); userData.direct_resource_count = ShaderRegs::AGC_DIRECT_RESOURCE_TYPE_COUNT; std::memcpy(Header.data() + UserDataOffset, &userData, sizeof(userData)); Shader shader{}; shader.user_data = reinterpret_cast<ShaderUserData*>(Header.data() + UserDataOffset); shader.input_semantics = reinterpret_cast<ShaderSemantic*>(Header.data() + SemanticOffset); shader.num_input_semantics = 1; std::memcpy(Header.data(), &shader, sizeof(shader)); } std::uint64_t Address(const void* data) { return static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(data)); } std::array<std::uint32_t, 4> UserWords() { const auto buffer = Address(BufferTable.data()); const auto attrib = Address(AttribTable.data()); return {static_cast<std::uint32_t>(buffer), static_cast<std::uint32_t>(buffer >> 32u), static_cast<std::uint32_t>(attrib), static_cast<std::uint32_t>(attrib >> 32u)}; } ShaderRecompiler::ShaderVertexStageInfo Decode(std::vector<AgcDriver::Graphics::DecodeRead>& reads) { const auto userWords = UserWords(); return AgcDriver::DriverDetail::DecodeOrderedVertexStageInfo(Header, Address(Header.data()), userWords, reads, 0); } std::shared_ptr<std::atomic<bool>> releaseProducer; std::atomic<unsigned> releaseCause{0}; bool producerCompletedDuringDecode = false; std::vector<AgcDriver::Graphics::DecodeRead>* activeReads = nullptr; void CompleteProducerAtBufferRead(std::uint64_t address, std::size_t bytes) { if (address != Address(BufferTable.data()) || !releaseProducer) return; check(bytes == 16 && activeReads != nullptr && activeReads->size() == 1, "the gate did not run between the attribute read and its V# read"); std::uint32_t capturedAttribute = 1; std::memcpy(&capturedAttribute, activeReads->front().Bytes().data(), sizeof(capturedAttribute)); check((capturedAttribute & 31u) == 0 && (AttribTable[0] & 31u) == 0, "the producer was not held until after the old attribute was captured"); releaseCause.store(1, std::memory_order_release); releaseProducer->store(true, std::memory_order_release); const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5); while (DrawPipeline::QueuedItems() != 0) { check(std::chrono::steady_clock::now() < deadline, "the ordered producer did not finish"); std::this_thread::yield(); } producerCompletedDuringDecode = true; } struct ReadGuardScope { ReadGuardScope() { AgcDriver::GuestMemory::SetReadGuard(&CompleteProducerAtBufferRead); } ~ReadGuardScope() { AgcDriver::GuestMemory::SetReadGuard(nullptr); } }; } int main(int argc, char** argv) { try { const bool producerFirst = argc == 2 && std::string(argv[1]) == "--producer-first"; const bool drainFirst = argc == 2 && std::string(argv[1]) == "--drain-first"; check(argc == 1 || producerFirst || drainFirst, "unknown test argument"); BuildHeader(); AttribTable[0] = 0x2cu << 5u; DrawPipeline::Active() = true; std::vector<AgcDriver::Graphics::DecodeRead> reads; const auto control = Decode(reads); check(control.resourcesNum == 1 && control.resources[0].fields[0] == 0x1000u, "the initial attribute did not select the first vertex buffer"); releaseProducer = std::make_shared<std::atomic<bool>>(false); const auto drainBefore = DrawPipeline::DrainRequestsByOpcode(0x100u); DrawPipeline::Queue0().Enqueue([release = releaseProducer, drainBefore] { const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5); while (!release->load(std::memory_order_acquire)) { if (DrawPipeline::DrainRequestsByOpcode(0x100u) != drainBefore) { releaseCause.store(2, std::memory_order_release); break; } check(std::chrono::steady_clock::now() < deadline, "the producer gate was not released"); std::this_thread::yield(); } AttribTable[0] = (0x2cu << 5u) | 1u; }, {{Address(AttribTable.data()), Address(AttribTable.data()) + sizeof(AttribTable)}}); check(DrawPipeline::Queue0().Overlaps(Address(AttribTable.data()), sizeof(AttribTable)), "the earlier queued producer has no overlapping write range"); if (producerFirst) { releaseCause.store(3, std::memory_order_release); releaseProducer->store(true, std::memory_order_release); const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5); while (DrawPipeline::QueuedItems() != 0) { check(std::chrono::steady_clock::now() < deadline, "the control producer did not finish"); std::this_thread::yield(); } } if (drainFirst) DrawPipeline::Queue0().Drain(DrawPipeline::DrainReason::Capture); ShaderRecompiler::ShaderVertexStageInfo info; activeReads = &reads; { ReadGuardScope guard; info = Decode(reads); } check(producerFirst || producerCompletedDuringDecode || releaseCause.load(std::memory_order_acquire) == 2, "neither the completion interleaving nor an ordering drain was exercised"); check(DrawPipeline::QueuedItems() == 0 && (AttribTable[0] & 31u) == 1u, "the earlier queued attribute store did not complete"); std::printf("producer completed; queue empty; decoded V# 0x%x; expected 0x7000\n", info.resources[0].fields[0]); std::printf("producer release cause %u (1=read gate, 2=ordering drain, 3=control)\n", releaseCause.load(std::memory_order_acquire)); DrawPipeline::Active() = false; DrawPipeline::Queue0().Stop(); check(info.resourcesNum == 1 && info.resources[0].fields[0] == 0x7000u, "a completed earlier attribute store escaped the post-decode overlap check"); std::puts("vertex table completion order tests passed"); return 0; } catch (const std::exception& error) { AgcDriver::GuestMemory::SetReadGuard(nullptr); if (releaseProducer) releaseProducer->store(true, std::memory_order_release); DrawPipeline::Active() = false; DrawPipeline::Queue0().Stop(); std::cerr << error.what() << '\n'; return 1; } } ``` </details> AI-assisted: yes.
Celegans12 commented 2026-10-20 00:26:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-20T00:26:09Z.


@embersas, your reproducer was right: the post-decode check only looked at writers that were still queued, so a store that finished between our read and the check got past it. I pushed 837e7d1fa on top of @adriadam10's fe5ae13d4 (no force-push) to close that window.

DecodeOrderedVertexStageInfo now notes whether queue 0 was busy before it decodes. If it was, it still drains when a read overlaps a pending write. Otherwise it reads every recorded attribute word and V# again and keeps the decode only if all the bytes are unchanged. Any difference means a writer finished mid-decode, so it drains and decodes again. A writer that's popped before the overlap check is visible to the reread, because the check takes the same queue mutex the committer pops under. So the window is closed, and unrelated queued work still doesn't cause a drain (the existing "overlaps nothing queued" case still holds).

I put your sequence into agc_driver_vertex_table_read_order as a fourth case instead of adding a second executable. The read guard releases a queued attribute store at the V# read and waits for its item to retire. I also ran your file unchanged against both heads.

Details

Windows 11, RTX 3080 Laptop (driver 610.62), MinGW-w64 GCC 15.2.0, Release, three runs each:

fe5ae13d4 837e7d1fa
your test, completion during decode fails 3/3, 0x1000 (release cause 1) passes 3/3, 0x7000 (release cause 1)
your test, --producer-first passes 3/3 passes 3/3
your test, --drain-first passes 3/3 (cause 2) passes 3/3 (cause 2)
agc_driver_vertex_table_read_order with the new case fails 3/3: "the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode" passes 3/3

On 837e7d1fa merged with main, the 15 focused tests (agc_driver_vertex_table_read_order, agc_driver_graphics, the draw-cache reuse tests, the agc_driver_pipelined_* tests and agc_driver_vertex_user_data_tail) pass with --repeat until-fail:3: on Windows merged with eb7500680, and on lavapipe in WSL (CI's Linux job) merged with 34b1b77a.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6280382267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6280382267). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-20T00:26:09Z. --- @embersas, your reproducer was right: the post-decode check only looked at writers that were still queued, so a store that finished between our read and the check got past it. I pushed 837e7d1fa on top of @adriadam10's fe5ae13d4 (no force-push) to close that window. `DecodeOrderedVertexStageInfo` now notes whether queue 0 was busy before it decodes. If it was, it still drains when a read overlaps a pending write. Otherwise it reads every recorded attribute word and V# again and keeps the decode only if all the bytes are unchanged. Any difference means a writer finished mid-decode, so it drains and decodes again. A writer that's popped before the overlap check is visible to the reread, because the check takes the same queue mutex the committer pops under. So the window is closed, and unrelated queued work still doesn't cause a drain (the existing "overlaps nothing queued" case still holds). I put your sequence into `agc_driver_vertex_table_read_order` as a fourth case instead of adding a second executable. The read guard releases a queued attribute store at the V# read and waits for its item to retire. I also ran your file unchanged against both heads. <details><summary>Details</summary> Windows 11, RTX 3080 Laptop (driver 610.62), MinGW-w64 GCC 15.2.0, Release, three runs each: | | fe5ae13d4 | 837e7d1fa | |---|---|---| | your test, completion during decode | fails 3/3, `0x1000` (release cause 1) | passes 3/3, `0x7000` (release cause 1) | | your test, `--producer-first` | passes 3/3 | passes 3/3 | | your test, `--drain-first` | passes 3/3 (cause 2) | passes 3/3 (cause 2) | | `agc_driver_vertex_table_read_order` with the new case | fails 3/3: "the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode" | passes 3/3 | On 837e7d1fa merged with `main`, the 15 focused tests (`agc_driver_vertex_table_read_order`, `agc_driver_graphics`, the draw-cache reuse tests, the `agc_driver_pipelined_*` tests and `agc_driver_vertex_user_data_tail`) pass with `--repeat until-fail:3`: on Windows merged with eb7500680, and on lavapipe in WSL (CI's Linux job) merged with 34b1b77a. </details>
VicRaster commented 2026-10-20 02:06:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by VicRaster on 2026-10-20T02:06:42Z.


I independently rebuilt and retested fe5ae13d41133c094d7b1e71653e9efd7b9ca9f3 and 837e7d1faa7a5a323c6db6adec4b8b1d3e9ace43 on Windows with the supported WinLibs GCC 15.2.0 r7 toolchain.

The unchanged standalone completion-during-decode reproducer fails 3/3 on the old runtime (0x1000) and passes 3/3 on the fixed runtime (0x7000), with read-gate release cause 1. Both producer-first and Capture-drain-first controls pass 3/3 on both revisions. Your expanded integrated test also fails 3/3 against the old runtime at the new assertion and passes 3/3 on the fixed runtime.

I also tested two input semantics and four recorded reads, using explicit gates: changing the first recorded V# during a later attribute read, and changing the second attribute index during its descriptor read. Both return stale results on the old runtime and pass on the fix. An unrelated held queue item remains queued with zero Capture drain requests.

The queue-mutex publication argument checks out for earlier declared writers in the same queue. I found no further production ordering defect within that contract. These are CPU helper tests, not verification of rendered output, a game improvement or performance. I did not independently repeat the broader Windows/Linux GPU test set.

One optional test-hardening point: the integrated fixture captures stack Gate objects by reference, while the Gate destructor releases without waiting for worker completion and the outer error handler does not stop the queue. Shared gate lifetime and explicit failure cleanup would make exceptional paths safer. This is a source-inspection caveat; no cleanup failure occurred in these runs, and it does not invalidate the successful ordering retest.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281653134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6281653134). Originally posted by [VicRaster](https://github.com/VicRaster) on 2026-10-20T02:06:42Z. --- I independently rebuilt and retested `fe5ae13d41133c094d7b1e71653e9efd7b9ca9f3` and `837e7d1faa7a5a323c6db6adec4b8b1d3e9ace43` on Windows with the supported WinLibs GCC 15.2.0 r7 toolchain. The unchanged standalone completion-during-decode reproducer fails 3/3 on the old runtime (`0x1000`) and passes 3/3 on the fixed runtime (`0x7000`), with read-gate release cause 1. Both producer-first and Capture-drain-first controls pass 3/3 on both revisions. Your expanded integrated test also fails 3/3 against the old runtime at the new assertion and passes 3/3 on the fixed runtime. I also tested two input semantics and four recorded reads, using explicit gates: changing the first recorded V# during a later attribute read, and changing the second attribute index during its descriptor read. Both return stale results on the old runtime and pass on the fix. An unrelated held queue item remains queued with zero Capture drain requests. The queue-mutex publication argument checks out for earlier declared writers in the same queue. I found no further production ordering defect within that contract. These are CPU helper tests, not verification of rendered output, a game improvement or performance. I did not independently repeat the broader Windows/Linux GPU test set. One optional test-hardening point: the integrated fixture captures stack Gate objects by reference, while the Gate destructor releases without waiting for worker completion and the outer error handler does not stop the queue. Shared gate lifetime and explicit failure cleanup would make exceptional paths safer. This is a source-inspection caveat; no cleanup failure occurred in these runs, and it does not invalidate the successful ordering retest. AI-assisted: yes.
Celegans12 commented 2026-10-20 02:55:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-20T02:55:07Z.


@embersas, thanks for rebuilding both heads yourself and for the two extra gate cases (a changed V# during a later attribute read, a changed index during its descriptor read). Those cover ground our own runs didn't.

You were right about the fixture, so I took the hardening as well: 80057705d only touches the test. Hold now returns a shared gate and the queued store keeps its own copy, so nothing in the queue points at a stack object anymore, and Gate no longer releases itself in a destructor. On both the success and the failure path the test clears the read guard, releases every gate it created and stops queue 0, so a failing check doesn't leave a held store behind. The four cases and their assertions are unchanged, and the fix in DrawDecode.cpp is untouched.

With the new fixture, the test still fails 3/3 against fe5ae13d4's DrawDecode.cpp at the completion assertion and passes with 837e7d1fa's. To check the error path, I also added a failing check right after a store is queued as a throwaway local change. The test then exits with 1 in under a second, 3/3, with no hang.

Details

Windows 11, RTX 3080 Laptop (driver 610.62), WinLibs GCC 15.2.0, Release, on 80057705d merged with main c2b0159d6:

  • the 15 focused tests (agc_driver_vertex_table_read_order, agc_driver_graphics, the draw-cache reuse tests, the agc_driver_pipelined_* tests, agc_driver_vertex_user_data_tail) pass with --repeat until-fail:3, plus agc_driver_vertex_table_read_order with until-fail:5 and three direct runs; test registration check ok
  • fe5ae13d4's DrawDecode.cpp swapped in: fails 3/3, "the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode"
  • injected failure with the unrelated store still held: exit 1, 3/3, ~0.25 s per run

Linux (CI's job on lavapipe in WSL), merged with main c942b37c: the same 15 tests pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6282247685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6282247685). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-20T02:55:07Z. --- @embersas, thanks for rebuilding both heads yourself and for the two extra gate cases (a changed V# during a later attribute read, a changed index during its descriptor read). Those cover ground our own runs didn't. You were right about the fixture, so I took the hardening as well: [80057705d](https://github.com/boykopovar/AnyPS5/pull/7691/commits/80057705dfbe7eeff80255b2566ba8863eef8d2d) only touches the test. `Hold` now returns a shared gate and the queued store keeps its own copy, so nothing in the queue points at a stack object anymore, and `Gate` no longer releases itself in a destructor. On both the success and the failure path the test clears the read guard, releases every gate it created and stops queue 0, so a failing check doesn't leave a held store behind. The four cases and their assertions are unchanged, and the fix in `DrawDecode.cpp` is untouched. With the new fixture, the test still fails 3/3 against fe5ae13d4's `DrawDecode.cpp` at the completion assertion and passes with 837e7d1fa's. To check the error path, I also added a failing check right after a store is queued as a throwaway local change. The test then exits with 1 in under a second, 3/3, with no hang. <details><summary>Details</summary> Windows 11, RTX 3080 Laptop (driver 610.62), WinLibs GCC 15.2.0, Release, on 80057705d merged with `main` c2b0159d6: - the 15 focused tests (`agc_driver_vertex_table_read_order`, `agc_driver_graphics`, the draw-cache reuse tests, the `agc_driver_pipelined_*` tests, `agc_driver_vertex_user_data_tail`) pass with `--repeat until-fail:3`, plus `agc_driver_vertex_table_read_order` with `until-fail:5` and three direct runs; test registration check ok - fe5ae13d4's `DrawDecode.cpp` swapped in: fails 3/3, "the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode" - injected failure with the unrelated store still held: exit 1, 3/3, ~0.25 s per run Linux (CI's job on lavapipe in WSL), merged with `main` c942b37c: the same 15 tests pass. </details>
CnRJay commented 2026-10-21 17:42:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:42:55Z.

Review: COMMENTED


The ordering argument is right: the decode reads skip the check that ShaderMemory makes through queryPendingWrite, so a vertex V# can be taken from a table before a queued store lands. The author says no title has drawn wrong because of it, so this is a precaution on the hottest path, and the cost needs to be shown.

  • When queue 0 is busy before the decode (the normal case at depth 8) and nothing queued overlaps, the PR reads the recorded words again and compares them to catch a store that finished during the decode. That is a second read of the vertex tables for every draw issued while the pipeline is busy. The description gives no timing for it. Please post Driver.Draw per packet or the summary lines of main and this PR on Ghost of Yotei (PPSA26344, the title it was found on) or any pipelined title, no APS5_PROFILE_*.
  • The reread isn't needed to know whether a store finished during the decode. If the pipeline keeps a count of retired items, read it before and after the decode and redo the decode only when it moved while the decode's ranges overlapped something that was queued at the start. That is two atomic loads instead of a second decode, and it is exact.
  • The drain on overlap (DrainReason::Capture) is the right action when it happens. How often does it happen? Add the count of drains caused by the decode to the [draw] pipelined line so the cost of the correctness is visible in the title.
  • The test shows the ordering works, and fails with the drain removed and without the reread. It doesn't show that a draw that does not overlap stays queued with no extra wait except in the one case (a store elsewhere). That case is covered; add one where the decode reads a table that a finished item wrote, to show the reread doesn't drain a clean pipeline.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5603820891 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#pullrequestreview-5603820891). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-21T17:42:55Z. **Review:** COMMENTED --- The ordering argument is right: the decode reads skip the check that `ShaderMemory` makes through `queryPendingWrite`, so a vertex V# can be taken from a table before a queued store lands. The author says no title has drawn wrong because of it, so this is a precaution on the hottest path, and the cost needs to be shown. - When queue 0 is busy before the decode (the normal case at depth 8) and nothing queued overlaps, the PR reads the recorded words again and compares them to catch a store that finished during the decode. That is a second read of the vertex tables for every draw issued while the pipeline is busy. The description gives no timing for it. Please post `Driver.Draw` per packet or the summary lines of main and this PR on Ghost of Yotei (PPSA26344, the title it was found on) or any pipelined title, no `APS5_PROFILE_*`. - The reread isn't needed to know whether a store finished during the decode. If the pipeline keeps a count of retired items, read it before and after the decode and redo the decode only when it moved while the decode's ranges overlapped something that was queued at the start. That is two atomic loads instead of a second decode, and it is exact. - The drain on overlap (`DrainReason::Capture`) is the right action when it happens. How often does it happen? Add the count of drains caused by the decode to the `[draw] pipelined` line so the cost of the correctness is visible in the title. - The test shows the ordering works, and fails with the drain removed and without the reread. It doesn't show that a draw that does not overlap stays queued with no extra wait except in the one case (a store elsewhere). That case is covered; add one where the decode reads a table that a *finished* item wrote, to show the reread doesn't drain a clean pipeline.
Celegans12 commented 2026-10-21 21:26:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-21T21:26:05Z.


Thanks, the retired-item count is the better design, and it holds up in the code. I went through the case I was worried about: a store the decode already read that only lands later. That store's item is either still queued when we check, so the overlap drains, or it retired during the decode, so the count moved and the read overlaps a range noted at the start. Either way the decode is redone. It's in 3000d848c.

Before the decode, the helper takes the retired count and the write ranges queued at that moment, under the pipeline mutex. That copy only happens when the queue is busy, and it's a handful of ranges for depth 8. After the decode, one locked check drains and decodes again when a read overlaps a write that is still queued, or when the count moved and a read overlaps a range from the start. The reread is gone. The [draw] pipelined line now ends with "N decode drains".

I added the test you asked for: the decode reads a V# that a finished item stored while the pipeline holds an unrelated item, and nothing drains. There's a second new case where a store elsewhere retires mid-decode and nothing drains either. The existing cases still fail without the fix: 3 of 3 with the retired-count branch removed ("the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode"), and 3 of 3 with no check at all ("the vertex buffer V# was read before the queued store ..."). The 15 focused tests pass on Windows and on the Linux merge.

The Driver.Draw / summary-line timings on Yōtei, main against this PR, are still owed. I'll post them once I can run that pair.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326913050 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7691#issuecomment-6326913050). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-21T21:26:05Z. --- Thanks, the retired-item count is the better design, and it holds up in the code. I went through the case I was worried about: a store the decode already read that only lands later. That store's item is either still queued when we check, so the overlap drains, or it retired during the decode, so the count moved and the read overlaps a range noted at the start. Either way the decode is redone. It's in 3000d848c. Before the decode, the helper takes the retired count and the write ranges queued at that moment, under the pipeline mutex. That copy only happens when the queue is busy, and it's a handful of ranges for depth 8. After the decode, one locked check drains and decodes again when a read overlaps a write that is still queued, or when the count moved and a read overlaps a range from the start. The reread is gone. The `[draw] pipelined` line now ends with "N decode drains". I added the test you asked for: the decode reads a V# that a finished item stored while the pipeline holds an unrelated item, and nothing drains. There's a second new case where a store elsewhere retires mid-decode and nothing drains either. The existing cases still fail without the fix: 3 of 3 with the retired-count branch removed ("the decode kept the vertex buffer of an attribute word that a queued store replaced during the decode"), and 3 of 3 with no check at all ("the vertex buffer V# was read before the queued store ..."). The 15 focused tests pass on Windows and on the Linux merge. The `Driver.Draw` / summary-line timings on Yōtei, main against this PR, are still owed. I'll post them once I can run that pair.
Sign in to join this conversation.
No reviewers
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!7691
No description provided.