Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
34a5bf2
fix(agc): leave GPU-stored words out of frame capture deltas
chitters2004 Oct 28, 2026
4fbc6aa
test(agc): shut down replay fixtures before static teardown
JJenkx Oct 29, 2026
fe5edc7
fix(agc): capture CPU stores after write-watch coverage is lost
JJenkx Oct 29, 2026
7297b72
test(agc): reset the shared capture fixture's block before mapping it…
chitters2004 Oct 29, 2026
c184a96
Merge #12567 (79d7617af2) into fix/agc-capture-gpu-stores
chitters2004 Oct 29, 2026
1e21d6c
Merge commit '6e7549264f' into fix/agc-capture-gpu-stores
chitters2004 Oct 31, 2026
0e3d922
Merge commit '1126a888d9' into fix/agc-capture-gpu-stores
chitters2004 Oct 31, 2026
3585255
Merge remote-tracking branch 'origin/main' into port-12568
chitters2004 Nov 1, 2026
00d1d66
Merge remote-tracking branch 'origin/main' into capture port
chitters2004 Nov 1, 2026
78c7140
fix(agc): keep a frame capture's shader deltas inside its recorded ra…
thuanquang Nov 1, 2026
4a6daa3
test(agc): release the shader hole reservation before committing its …
chitters2004 Nov 2, 2026
41da7a8
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 2, 2026
137e2d7
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 2, 2026
b3b438c
Merge commit '4f64f81ef7b4bca975b4b9f3dfd15dfff56f716f' into HEAD
oneandonlydean Nov 2, 2026
2b39d2a
Merge commit 'a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8' into HEAD
oneandonlydean Nov 2, 2026
a62a695
fix(agc): forget a frame capture's hashes of bytes another delta rewrote
thuanquang Nov 3, 2026
f21b604
Merge main 4f41f4c375 into fix/agc-capture-gpu-stores
chitters2004 Nov 3, 2026
da47027
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 4, 2026
2f87914
Merge remote-tracking branch 'origin/main' into fix/agc-capture-gpu-s…
chitters2004 Nov 5, 2026
7b53884
Merge remote-tracking branch 'origin/main' into fix/agc-capture-gpu-s…
chitters2004 Nov 6, 2026
17889e3
Merge remote-tracking branch 'origin/main' into fix/agc-capture-gpu-s…
chitters2004 Nov 8, 2026
8649da1
Merge remote-tracking branch 'origin/main' into fix/agc-capture-gpu-s…
chitters2004 Nov 9, 2026
8e0d485
fix(agc): collect each capture delta span in one call
chitters2004 Nov 9, 2026
4ef7534
fix(agc): reapply a capture delta once the replay parks where the cap…
chitters2004 Nov 9, 2026
9e52511
chore(agc): merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 9, 2026
3ddbd84
test(agc): restore testParkedRewindReplays dropped by the main merge
chitters2004 Nov 9, 2026
a78ad15
chore(agc): merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 10, 2026
f3170d9
chore(agc): merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 10, 2026
6a2e3c1
test(agc): replay a CPU store over work an idle capture delta releases
thuanquang Nov 4, 2026
f8de2a2
test(agc): replay a CPU store a capture read while a queue waited on …
thuanquang Nov 11, 2026
7cf4242
chore(agc): merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 11, 2026
591073f
fix(agc): record the compare of each wait a capture delta was read pa…
thuanquang Nov 11, 2026
e264114
fix(agc): drop a duplicate flush in restoreGroup and update the captu…
chitters2004 Nov 11, 2026
8fe56be
chore(agc): take thuanquang's parked-wait compare (replay/12568-park-…
chitters2004 Nov 11, 2026
e0df5b7
chore(agc): merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 11, 2026
1243812
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 13, 2026
7d87265
fix(agc): store an unchanged frame capture delta once
chitters2004 Nov 14, 2026
8711199
fix(agc): compare a shared capture delta byte for byte
chitters2004 Nov 14, 2026
cf368d9
test(agc): demote the shared section fixture on Windows
chitters2004 Nov 14, 2026
f9dd5dc
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 14, 2026
4cd4bc3
chore: merge main
oneandonlydean Nov 15, 2026
258c3a6
fix(agc): leave GPU-stored words out of a shader delta's host pages
chitters2004 Nov 14, 2026
14f9558
docs(agc): state what stays open for pages that leave the write watch
chitters2004 Nov 14, 2026
34da67b
test(agc): store beside a DMA copy held in flight at a memory delta
chitters2004 Nov 15, 2026
a6a5324
Merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 16, 2026
4ee175a
test(agc): hold the GPU mutex while the held-copy test polls the reco…
chitters2004 Nov 16, 2026
c9ebb0b
test(agc): wait for a compute label before comparing the GPU store copy
chitters2004 Nov 16, 2026
a18b257
fix(agc): track GPU stores to part of a word in frame capture deltas
chitters2004 Nov 16, 2026
63183c5
fix(agc): forget a merged unwatched block's hash on a store into its …
chitters2004 Nov 17, 2026
b11664a
Merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 17, 2026
ae77c65
fix(agc): match unaligned buffer fills from their own start in captur…
chitters2004 Nov 17, 2026
b71905e
fix(agc): wait for queued GPU work only before a delta that reads memory
chitters2004 Nov 17, 2026
90a93a3
Merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 17, 2026
946d0f4
perf(agc): compare repeated capture deltas against cached bytes outsi…
chitters2004 Nov 17, 2026
a63e23c
fix(agc): merge overlapping readable ranges before the shader delta l…
chitters2004 Nov 17, 2026
f4b1efb
build(agc): name xxHash as a header-only dependency of the frame capture
chitters2004 Nov 17, 2026
c161bdb
test(agc): replay a range mapped again at the same address and then r…
chitters2004 Nov 17, 2026
f51ab73
perf(agc): keep the most recently used capture deltas and never read …
chitters2004 Nov 18, 2026
036df61
Merge main into fix/agc-capture-gpu-stores
chitters2004 Nov 19, 2026
ea64032
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 21, 2026
4e6dc22
test(agc): drop the trailing spaces the main merge left on three last…
chitters2004 Nov 21, 2026
a2542fe
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 26, 2026
7c63d55
docs(agc): keep the frame capture GPU store debt entry under the leng…
chitters2004 Nov 26, 2026
d690d21
test(agc): write the rewind test's parked waits in the version 3 call…
chitters2004 Nov 26, 2026
a2fb33c
Merge branch 'main' into fix/agc-capture-gpu-stores
chitters2004 Nov 26, 2026
fc1058b
fix(agc): forget the compared copy of pages the driver stores to outs…
chitters2004 Nov 26, 2026
c067760
fix(agc): keep the calls format of a capture the filter rewrites
chitters2004 Nov 26, 2026
ede4fd9
fix(agc): seed every page of an unaligned unwatched range in a frame …
chitters2004 Nov 26, 2026
2a30e13
fix(agc): compare host shader pages a captured range covers only in part
chitters2004 Nov 26, 2026
7fea7c4
docs(agc): say the frame replay refuses memory outside the captured r…
chitters2004 Nov 26, 2026
a0e4fb8
test(agc): check only the evictions the concurrent capture writers mu…
chitters2004 Nov 26, 2026
bffde0b
test(agc): check the replay keeps the title's word beside a half-stor…
chitters2004 Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions core/libs/prx/libSceAgcDriver/Execution/include/FrameCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <span>
Expand Down Expand Up @@ -79,13 +81,24 @@ class FrameCaptureWriter {
static constexpr std::string_view CallsName = "calls.bin";
static constexpr std::string_view MemoryName = "memory.bin";
static constexpr std::string_view HeaderName = "capture.json";
static constexpr std::string_view CallsMagic = "aps5-frame-calls 2\n";
static constexpr std::string_view CallsMagic = "aps5-frame-calls 3\n";
static constexpr std::string_view CallsMagicV2 = "aps5-frame-calls 2\n";
static constexpr std::string_view CallsMagicV1 = "aps5-frame-calls 1\n";
static constexpr std::string_view MemoryMagic = "aps5-frame-memory 1\n";
static constexpr std::string_view MemoryMagic = "aps5-frame-memory 2\n";
static constexpr std::string_view MemoryMagicV1 = "aps5-frame-memory 1\n";
static constexpr std::size_t BlockBytes = 64u * 1024u;
static constexpr std::size_t ChunkBytes = 4u * 1024u * 1024u;
static constexpr std::uint64_t CachedDeltaBytes = 512u * 1024u * 1024u;

explicit FrameCaptureWriter(const std::filesystem::path& directory, int level = 1);
struct DeltaCosts {
std::uint64_t compared = 0;
std::uint64_t evicted = 0;
double compareSeconds = 0;
};

static constexpr std::uint32_t CallsVersion = 3;

explicit FrameCaptureWriter(const std::filesystem::path& directory, int level = 1, std::uint64_t cacheBudget = CachedDeltaBytes, std::uint32_t callsVersion = CallsVersion);
FrameCaptureWriter(const FrameCaptureWriter&) = delete;
FrameCaptureWriter& operator=(const FrameCaptureWriter&) = delete;

Expand All @@ -98,11 +111,22 @@ class FrameCaptureWriter {

std::uint64_t RawBytes() const;
std::uint64_t StoredBytes() const;
std::uint64_t SharedBytes() const;
DeltaCosts Costs() const;
const std::filesystem::path& Directory() const;

private:
void writeChunk(const FrameMemoryChunk& chunk, std::span<const std::byte> payload);
using DeltaKey = std::pair<std::uint64_t, std::uint64_t>;
struct DeltaPayload {
std::uint64_t offset = 0;
std::uint64_t compressedBytes = 0;
std::shared_ptr<const std::vector<std::byte>> bytes;
std::list<DeltaKey>::iterator use;
};

std::uint64_t writeChunk(const FrameMemoryChunk& chunk, std::span<const std::byte> payload, std::uint64_t sharedOffset = 0);
std::vector<std::byte> compress(std::span<const std::byte> bytes) const;
void cacheDelta(const DeltaKey& key, std::uint64_t offset, std::uint64_t compressedBytes, std::shared_ptr<const std::vector<std::byte>> bytes);

std::filesystem::path directory;
int level;
Expand All @@ -111,6 +135,13 @@ class FrameCaptureWriter {
std::ofstream memory;
std::uint64_t rawBytes = 0;
std::uint64_t storedBytes = 0;
std::uint64_t sharedBytes = 0;
std::uint64_t cacheBudget = CachedDeltaBytes;
std::uint64_t cachedBytes = 0;
DeltaCosts costs;
std::uint64_t memoryOffset = 0;
std::map<DeltaKey, DeltaPayload> deltaPayloads;
std::list<DeltaKey> deltaUses;
bool finished = false;
};

Expand Down Expand Up @@ -139,7 +170,7 @@ class FrameCaptureReader {
std::vector<FrameCall> calls;
std::vector<FrameMemoryChunk> chunks;
std::string header;
std::uint32_t version = 2;
std::uint32_t version = 3;
bool truncated = false;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "prx/libSceAgcDriver/Execution/include/VideoOutput.hpp"
#include "SceShaders.hpp"
#include "SceTypes.hpp"
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cstdint>
Expand Down Expand Up @@ -44,7 +46,46 @@ class FrameRecorder {
void Suspend(const std::function<void()>& accept);
void PresentBuffer(const DisplayBuffer& buffer);
void FrameBoundary();
static void NoteGpuStore(std::uint64_t address, std::span<const std::byte> bytes) {
if (notingGpuStores.load(std::memory_order_relaxed)) Active()->noteGpuStore(address, bytes);
}
static void NoteGpuFill(std::uint64_t address, std::uint64_t bytes, const std::array<std::uint32_t, 4>& pattern) {
if (notingGpuStores.load(std::memory_order_relaxed)) Active()->noteGpuFill(address, bytes, pattern);
}
void RewindTailFlips(std::uint64_t flips);
static void MergeOverlappingBlocks(std::vector<std::pair<std::uint64_t, std::uint64_t>>& blocks);
struct CapturedSpans {
std::map<std::uint64_t, std::uint64_t> spans;
void Add(std::uint64_t begin, std::uint64_t end);
template <typename Visit> void Covering(std::uint64_t begin, std::uint64_t end, const Visit& visit) const {
auto span = spans.upper_bound(begin);
if (span != spans.begin()) --span;
for (; span != spans.end() && span->first < end; ++span) {
const auto first = std::max(begin, span->first);
const auto stop = std::min(end, span->second);
if (first < stop) visit(first, stop);
}
}
};
struct GpuStores {
struct FillRun {
std::uint64_t origin = 0;
std::uint64_t end = 0;
std::array<std::uint32_t, 4> pattern{};
std::uint32_t At(std::uint64_t word) const;
};
struct StoredWord {
std::uint32_t value = 0;
std::uint8_t known = 0;
};
static constexpr std::size_t WordLimit = 64u * 1024u;
std::map<std::uint64_t, StoredWord> words;
std::map<std::uint64_t, FillRun> fills;
void Store(std::uint64_t address, std::span<const std::byte> bytes);
void Fill(std::uint64_t address, std::uint64_t bytes, const std::array<std::uint32_t, 4>& pattern);
void Forget(std::uint64_t begin, std::uint64_t end);
std::uint64_t KeepTitleWords(std::uint64_t address, std::span<const std::byte> bytes, std::vector<std::pair<std::size_t, std::size_t>>& runs, bool zero);
};
static void SetStartIdleWaitForTest(std::function<bool()> wait);

private:
Expand All @@ -61,6 +102,7 @@ class FrameRecorder {
};

FrameRecorder(std::filesystem::path directory, std::filesystem::path trigger, std::uint64_t atBoundary, std::uint64_t frames);

struct Span {
std::uint64_t address = 0;
std::uint64_t bytes = 0;
Expand All @@ -73,20 +115,26 @@ class FrameRecorder {
void emitDelta();
static void collectShaderPages(std::span<const Shader* const> shaders, std::set<std::uint64_t>& blocks, std::set<std::uint64_t>& hostPages);
void emitShaderDelta(std::span<const Shader* const> shaders);
void writeDelta(std::span<Span> spans, std::span<const std::uint64_t> hostPages, std::span<const Range> added = {});
void writeDelta(std::span<Span> spans, std::span<const std::pair<std::uint64_t, std::uint64_t>> hostSpans, std::span<const Range> added = {});
void frameBoundaryLocked();
bool triggered();
void start();
void finish();
void snapshot(const Range& range);
void readGuest(std::uint64_t address, std::span<std::byte> bytes);
void noteGpuStore(std::uint64_t address, std::span<const std::byte> bytes);
void noteGpuFill(std::uint64_t address, std::uint64_t bytes, const std::array<std::uint32_t, 4>& pattern);
void endGpuStores();
void keepTitleWords(std::uint64_t address, std::span<const std::byte> bytes, std::vector<std::pair<std::size_t, std::size_t>>& runs, bool zero);
void writeReferenceFrames();
bool abandonIfDiskLow();
void stop(const char* reason);
std::string header() const;
std::vector<Range> committedRanges();
std::vector<Range> newRanges();
std::uint64_t blockSince(std::uint64_t block) const;
static bool collectsDeltas(const Range& range);
static void seedUnwatchedPages(std::uint64_t address, std::span<const std::byte> bytes);

std::filesystem::path directory;
std::filesystem::path trigger;
Expand All @@ -101,6 +149,10 @@ class FrameRecorder {
std::vector<Range> ranges;
std::map<std::uint64_t, std::uint64_t> shaderMarks;
std::map<std::uint64_t, std::uint64_t> hostPageHashes;
inline static std::atomic<bool> notingGpuStores{false};
std::mutex gpuStoresMutex;
GpuStores gpuStores;
std::uint64_t gpuStoreBytes = 0;
std::mutex displayMutex;
std::map<std::uint64_t, DisplayBuffer> displayBuffers;
std::uint64_t ordinal = 0;
Expand All @@ -118,6 +170,8 @@ class FrameRecorder {
inline static std::function<bool()> startIdleWaitForTest;
std::uint64_t unreadableBytes = 0;
std::uint64_t hostOnlySampleBytes = 0;
std::uint64_t unwatchedChangedBytes = 0;
double unwatchedCompareSeconds = 0;
std::uint64_t allocationsGeneration = 0;
std::uint64_t lateRanges = 0;
std::vector<std::string> warnings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void SetOwnStoreCompare(bool compare);
void SetLeftWatchCompare(bool compare);
void SeedComparedPages(std::uint64_t address, std::span<const std::byte> bytes);
void UpdateComparedPages(std::uint64_t address, std::span<const std::byte> bytes);
void ForgetComparedPages(std::uint64_t address, std::size_t bytes);
void ChangedComparedPages(std::uint64_t address, std::size_t bytes, std::vector<std::pair<std::uint64_t, std::uint64_t>>& changed);
void SetComparedDecisionHookForTest(void (*hook)());
bool StoredOver(std::uint64_t address, std::size_t bytes, std::uint64_t generation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "prx/libSceAgcDriver/Execution/include/Driver/Diagnostics.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Memory/DwordPatternFill.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hpp"
#include "prx/libSceAgcDriver/Execution/include/FrameRecorder.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include <algorithm>
#include "prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp"
Expand Down Expand Up @@ -430,6 +431,7 @@ void Driver::storeBufferFill(std::uint32_t queueId, std::uint64_t base, std::siz
for (std::size_t done = 0; done < bytes; done += chunk) GuestMemory::Write(base + done, std::span<const std::byte>(block).first(std::min(chunk, bytes - done)), 16);
phase(FillCpu);
}
FrameRecorder::NoteGpuFill(base, bytes, pattern);
if (noteMetadata && uniform) {
Graphics::NoteDepthMetadataFill(base, bytes, pattern[0]);
Graphics::NoteColorMetadataFill(base, bytes, pattern[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/DeferredLabels.hpp"
#include "prx/libSceAgcDriver/Execution/include/FrameRecorder.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include "prx/libkernel/Time/include/SleepWake.hpp"
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
Expand Down Expand Up @@ -341,7 +342,9 @@ void Driver::dumpSampleCounters(std::uint64_t address, std::uint32_t blocks) {
for (std::uint64_t db = 0; db < Pm4::SampleDumpBlocks; ++db) {
if (((blocks >> db) & 1u) == 0) continue;
const std::uint64_t value = ready | (db == first ? samples : 0u);
GuestMemory::Write(address + db * Pm4::SampleDumpStride, std::as_bytes(std::span(&value, 1)).first(Pm4::SampleDumpBlockBytes), 8);
const auto bytes = std::as_bytes(std::span(&value, 1)).first(Pm4::SampleDumpBlockBytes);
GuestMemory::Write(address + db * Pm4::SampleDumpStride, bytes, 8);
FrameRecorder::NoteGpuStore(address + db * Pm4::SampleDumpStride, bytes);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
#include "prx/libSceAgcDriver/Execution/include/FrameRecorder.hpp"
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
#include "prx/libSceAgcDriver/Execution/include/Mutex.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
Expand All @@ -10,6 +11,7 @@
namespace AgcDriver::DriverDetail {

void Driver::noteLabelStore(std::uint64_t address, std::span<const std::byte> bytes, std::uint64_t stamp, std::uint32_t queue, bool ordered) {
FrameRecorder::NoteGpuStore(address, bytes);
if (!KeepsLabelStore(address, bytes.size())) return;
const auto generation = GuestMemory::TrackerGeneration();
std::lock_guard lock(labelStoresMutex);
Expand Down
Loading
Loading