Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
378ac61
fix(libSceConvertKeycode): ignore the state bit 0x4000000 RE Engine t…
simonbronk Oct 14, 2026
9d95549
fix(libc): ignore the space and + flags for unsigned printf conversions
wachi35676 Oct 13, 2026
e671332
fix(libc): keep lgamma finite for subnormal arguments on Windows
wachi35676 Oct 13, 2026
e9c9890
fix(agc): bind a V# past the range limit by the memory behind it
Meh7an Oct 14, 2026
3da081a
fix(libkernel): drop undefined protection bits in sceKernelMprotect
simonbronk Oct 14, 2026
ce074f9
docs(debt): note the protection bits sceKernelMprotect drops
simonbronk Oct 14, 2026
7ffb671
fix(relinker): guard against address underflow in encoded unwind poin…
fogydes Oct 14, 2026
e692264
fix(relinker): limit relative unwind pointer overflow check to signed…
fogydes Oct 14, 2026
65ba674
test(relinker): cover negative wrapped pointer rejection with matchin…
fogydes Oct 15, 2026
47f7118
fix(agc): sample a depth surface's stencil plane through an R8_UNORM …
moong15 Oct 14, 2026
02a1b77
Merge pull request #5770 from simonbronk/fix/kernel-mprotect-undefine…
adriadam10 Oct 15, 2026
0029e62
Merge pull request #5773 from fogydes/fix/relinker-eh-frame-unwind-ad…
adriadam10 Oct 15, 2026
da85abc
Merge pull request #5774 from wachi35676/fix/libc-printf-unsigned-sig…
adriadam10 Oct 15, 2026
ec1193d
Merge pull request #5775 from wachi35676/fix/libc-lgamma-tiny-arguments
adriadam10 Oct 15, 2026
e2bcee6
Merge pull request #5776 from simonbronk/fix/convert-keycode-state-bit
adriadam10 Oct 15, 2026
2cefed5
Merge pull request #5778 from meh7an/fix/agc-buffer-range-limit-by-ma…
adriadam10 Oct 15, 2026
fa9365c
Merge pull request #5781 from moong15/fix/agc-sample-stencil-as-unorm
adriadam10 Oct 15, 2026
e0a32c3
perf(agc): copy small draw snapshots into a bump arena
mitul72 Oct 15, 2026
2fa32a8
perf(agc): pass the device's graphics context to draws by reference
mitul72 Oct 14, 2026
20893d2
perf(agc): publish draw keys, parameters and prechecks ahead of queue 0
mitul72 Oct 14, 2026
d5a8d33
perf(agc): compile uncached draws ahead of queue 0
mitul72 Oct 14, 2026
85cbfed
perf(agc): prepare the draw state of entries compiled ahead
mitul72 Oct 15, 2026
c4d6043
perf(agc): test validated runs against the pending images' index
mitul72 Oct 15, 2026
d4c8c35
test(agc): exercise ordered snapshot reuse with watched inputs
JJenkx Oct 15, 2026
7f96c6b
fix(agc): retain prepared draws through pipelined commits
JJenkx Oct 15, 2026
6807038
fix(agc): preserve speculative captures and retire before deferred co…
JJenkx Oct 15, 2026
70c31e2
fix(agc): drain queued code writes before raw shader reads
JJenkx Oct 15, 2026
fb79a57
test(agc): isolate draw-ahead queued table ordering
JJenkx Oct 15, 2026
9d25132
perf(agc): data-only draw hits compare only the user words a stage reads
Raghav314 Oct 14, 2026
8dc3e2d
fix(agc): pass device capabilities into draw-ahead decoding
JJenkx Oct 15, 2026
1277e50
test(agc): cover user-word masks on stages compiled ahead
JJenkx Oct 15, 2026
8a6bc51
test(agc): admit the serial draw key before testing data-only hits
JJenkx Oct 15, 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
28 changes: 27 additions & 1 deletion core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ set(agcDriverSources
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Dispatch/VariantValidation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Draw/Draw.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Draw/DrawProgramTrace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Draw/DrawAhead.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Draw/DrawCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Draw/DrawCacheStatistics.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Draw/DrawCapture.cpp
Expand Down Expand Up @@ -1134,6 +1135,10 @@ if(BUILD_TESTING)
set_tests_properties(agc_draw_snapshot_cap PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME agc_draw_snapshot_epoch COMMAND agc_driver_recorder_tests --draw-snapshot-epoch-only)
set_tests_properties(agc_draw_snapshot_epoch PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME agc_draw_snapshots COMMAND agc_driver_recorder_tests --draw-snapshots-only)
set_tests_properties(agc_draw_snapshots PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME agc_draw_snapshots_no_collect_memo COMMAND agc_driver_recorder_tests --draw-snapshots-only)
set_tests_properties(agc_draw_snapshots_no_collect_memo PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "APS5_NO_COLLECT_MEMO=1")
add_test(NAME agc_multisample_guest_access COMMAND agc_driver_recorder_tests --multisample-only)
set_tests_properties(agc_multisample_guest_access PROPERTIES SKIP_RETURN_CODE 77)
add_test(NAME agc_draw_inputs_in_place COMMAND agc_driver_recorder_tests --draw-inputs-in-place-only)
Expand All @@ -1154,7 +1159,7 @@ if(BUILD_TESTING)
add_test(NAME agc_metadata_pass COMMAND agc_driver_recorder_tests --metadata-pass-only)
set_tests_properties(agc_metadata_pass PROPERTIES SKIP_RETURN_CODE 77)
if(WIN32)
set_tests_properties(agc_recorder_read_list agc_host_import_unmap agc_parked_import_unmap agc_host_import_retirement agc_sparse_run_import agc_sparse_run_import_copied agc_unit_shadow agc_descriptor_pool_recycling agc_draw_snapshot_cap agc_draw_snapshot_epoch agc_multisample_guest_access agc_draw_inputs_in_place agc_resident_present agc_slice_dirty agc_queued_write_groups agc_metadata_pass agc_tiled_resolve PROPERTIES ENVIRONMENT_MODIFICATION
set_tests_properties(agc_recorder_read_list agc_host_import_unmap agc_parked_import_unmap agc_host_import_retirement agc_sparse_run_import agc_sparse_run_import_copied agc_unit_shadow agc_descriptor_pool_recycling agc_draw_snapshot_cap agc_draw_snapshot_epoch agc_draw_snapshots agc_draw_snapshots_no_collect_memo agc_multisample_guest_access agc_draw_inputs_in_place agc_resident_present agc_slice_dirty agc_queued_write_groups agc_metadata_pass agc_tiled_resolve PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
add_test(NAME agc_host_import_second_mapping COMMAND agc_driver_recorder_tests --host-import-second-mapping-only)
set_tests_properties(agc_host_import_second_mapping PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT_MODIFICATION
Expand Down Expand Up @@ -1688,6 +1693,8 @@ if(BUILD_TESTING)
set_tests_properties(agc_driver_draw_cache_reuse_inline PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_PIPELINED_DRAWS=0;APS5_VERIFY_DRAW_RECIPE=1;APS5_VERIFY_REGISTER_KEYS=1" SKIP_RETURN_CODE 77)
set_tests_properties(agc_driver_draw_cache_reuse agc_driver_draw_cache_reuse_off agc_driver_draw_cache_reuse_verify agc_driver_draw_cache_reuse_inline PROPERTIES FAIL_REGULAR_EXPRESSION "FATAL:")
set_property(TEST agc_driver_draw_cache_reuse agc_driver_draw_cache_reuse_off APPEND PROPERTY ENVIRONMENT "APS5_VERIFY_DRAW_RECIPE=1" "APS5_VERIFY_REGISTER_KEYS=1")
add_test(NAME agc_driver_draw_data_hit_user_words_verify COMMAND agc_driver_draw_data_hit_user_words_tests)
set_tests_properties(agc_driver_draw_data_hit_user_words_verify PROPERTIES ENVIRONMENT "APS5_VERIFY_DRAW_DATA_HITS=1" SKIP_RETURN_CODE 77)
if(WIN32)
set_tests_properties(agc_driver_draw_cache_reuse_off agc_driver_draw_cache_reuse_verify agc_driver_draw_cache_reuse_inline PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
Expand All @@ -1699,6 +1706,25 @@ if(BUILD_TESTING)
set_tests_properties(agc_driver_stencil_replay_no_gpl PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test(NAME agc_driver_draw_ahead_user_words COMMAND agc_driver_draw_ahead_tests user-words)
add_test(NAME agc_driver_draw_ahead_user_words_verify COMMAND agc_driver_draw_ahead_tests user-words)
set_tests_properties(agc_driver_draw_ahead_user_words agc_driver_draw_ahead_user_words_verify PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
set_property(TEST agc_driver_draw_ahead_user_words_verify APPEND PROPERTY ENVIRONMENT "APS5_VERIFY_DRAW_DATA_HITS=1")
if(WIN32)
set_tests_properties(agc_driver_draw_ahead_user_words agc_driver_draw_ahead_user_words_verify PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test(NAME agc_driver_draw_ahead_queued_table COMMAND agc_driver_draw_ahead_tests queued-table)
set_tests_properties(agc_driver_draw_ahead_queued_table PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_PIPELINED_DRAWS=8" SKIP_RETURN_CODE 77 TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_test(NAME agc_driver_draw_ahead_inline COMMAND agc_driver_draw_ahead_tests)
set_tests_properties(agc_driver_draw_ahead_inline PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_PIPELINED_DRAWS=0" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_test(NAME agc_driver_draw_ahead_verify COMMAND agc_driver_draw_ahead_tests)
set_tests_properties(agc_driver_draw_ahead_verify PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_VERIFY_DRAW_ENTRIES=1" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_test(NAME agc_driver_draw_ahead_small_cache COMMAND agc_driver_draw_ahead_tests small-cache)
set_tests_properties(agc_driver_draw_ahead_small_cache PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_DRAW_CACHE_ENTRIES=2" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
if(WIN32)
set_tests_properties(agc_driver_draw_ahead_queued_table agc_driver_draw_ahead_inline agc_driver_draw_ahead_verify agc_driver_draw_ahead_small_cache PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()

foreach(agcTest IN ITEMS agc_spirv_narrow_constant_store_tests agc_spirv13_image_tests agc_spirv_optimizer_tests agc_driver_constant_store_tests)
if(NOT TARGET ${agcTest})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct DispatchVariant {
std::uint32_t flatBinding = NoFlatBinding;

std::uint32_t pushOffset = 0;
std::uint64_t userDataMask = ~std::uint64_t{0};
std::shared_ptr<const ShaderRecompiler::ShaderVertexStageInfo> vertexInfo;

std::shared_ptr<ShaderMemory> memory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#ifndef CORE_LIBS_PRX_LIBSCEAGCDRIVER_EXECUTION_INCLUDE_DRIVER_DRAW_DRAWAHEAD_HPP
#define CORE_LIBS_PRX_LIBSCEAGCDRIVER_EXECUTION_INCLUDE_DRIVER_DRAW_DRAWAHEAD_HPP

#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Queues/Submission.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
#include "prx/libSceAgcDriver/Execution/include/QueueState.hpp"
#include <atomic>
#include <condition_variable>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <span>
#include <stop_token>
#include <string>
#include <thread>
#include <vector>

namespace AgcDriver::DriverDetail {

class Driver;

enum class DrawPrecheckOutcome : std::uint8_t { Proceed, Nothing, Rejected, MetadataPass };

DrawPrecheckOutcome PrecheckDrawState(const QueueState& queue, const Pm4::DrawParameters& drawParameters, bool primitiveListRestart, std::string& rejected);
bool TraceIndirectDraws();

struct PublishedDraw {
struct RegisterCheck {
Graphics::RegisterBank bank = Graphics::RegisterBank::Context;
std::uint32_t offset = 0;
bool present = false;
std::uint32_t value = 0;
};
std::size_t offset = 0;
bool certain = false;
DrawPrecheckOutcome precheck = DrawPrecheckOutcome::Rejected;
std::uint64_t key = 0;
std::uint64_t shape = 0;
std::uint64_t deviceSerial = 0;
Pm4::DrawParameters parameters{};
std::uint64_t indexBase = 0;
std::uint32_t indexType = 0;
std::uint32_t instanceCount = 0;
std::vector<RegisterCheck> checks;
};

class DrawScan {
public:
static constexpr std::size_t MaxRegisterChecks = 64;
struct Draw {
std::size_t offset;
std::span<const std::uint32_t> packet;
const QueueState& state;
bool certain;
};
DrawScan(std::span<const std::uint32_t> commands, const std::map<std::size_t, std::vector<std::uint32_t>>& registerLists, const std::map<std::size_t, std::size_t>& conditionalEnds, QueueState& state);
bool Next(const std::function<bool(const Draw&)>& draw);
void Capture(std::vector<PublishedDraw::RegisterCheck>& checks) const;
static bool Matches(const PublishedDraw& record, const QueueState& queue);

private:
void write(Graphics::RegisterBank bank, std::uint32_t offset, bool maybe);
void clearContext();
void track(std::span<const std::uint32_t> packet, std::uint32_t opcode, bool maybe, const std::vector<std::uint32_t>* pairs);

std::span<const std::uint32_t> commands;
const std::map<std::size_t, std::vector<std::uint32_t>>& registerLists;
const std::map<std::size_t, std::size_t>& conditionalEnds;
QueueState& state;
std::size_t cursor = 0;
std::size_t maybeUntil = 0;
std::set<std::pair<Graphics::RegisterBank, std::uint32_t>> divergent;
std::set<std::pair<Graphics::RegisterBank, std::uint32_t>> saved;
bool lost = false;
};

struct DrawAheadCounters {
std::uint64_t published = 0;
std::uint64_t used = 0;
std::uint64_t compiled = 0;
std::uint64_t dropped = 0;
};

class DrawAhead {
public:
class Speculation final : public GuestMemory::ISpeculativeReadGate {
public:
Speculation(DrawAhead& owner, std::uint64_t serial, std::size_t offset, bool compile);
void Enter() override;
void Leave() override;
bool Passed() const;
bool Commit(const std::function<void()>& action);

private:
DrawAhead& owner;
std::uint64_t serial;
std::size_t offset;
bool compile;
};

DrawAhead(Driver& driver, std::size_t workers);
~DrawAhead();
DrawAhead(const DrawAhead&) = delete;
DrawAhead& operator=(const DrawAhead&) = delete;

static void SetPinnedReadHook(void (*hook)(bool compile));
static void SetCompileAhead(bool enabled);
static std::size_t Workers();
static bool HasDirectDraws(std::span<const std::uint32_t> commands);
static bool CompilesAhead(const Graphics::State& state, const Pm4::DrawParameters& parameters);
void Post(const Submission& submission, const QueueState& state);
void Progress(std::uint64_t serial, std::size_t cursor);
void Skip(std::uint64_t serial, std::size_t end);
void Retire(std::uint64_t serial);
const PublishedDraw* Find(const Submission& submission, std::span<const std::uint32_t> packet, const QueueState& queue, std::uint64_t deviceSerial);

private:
struct Publication {
std::uint64_t serial = 0;
const std::uint32_t* commands = nullptr;
const ShaderRegistry* shaders = nullptr;
std::unique_ptr<PublishedDraw[]> records;
std::size_t capacity = 0;
std::atomic<std::size_t> published{0};
std::size_t readCursor = 0;
};

struct Scan {
std::uint64_t serial = 0;
std::vector<std::uint32_t> commands;
std::map<std::size_t, std::vector<std::uint32_t>> registerLists;
std::map<std::size_t, std::size_t> conditionalEnds;
std::shared_ptr<const ShaderRegistry> shaders;
std::unique_ptr<QueueState> state;
std::shared_ptr<Publication> publication;
};

struct Job {
std::uint64_t serial = 0;
std::size_t offset = 0;
std::uint64_t key = 0;
std::uint64_t shape = 0;
std::shared_ptr<const DrawDecode> decode;
Pm4::DrawParameters parameters{};
std::shared_ptr<VulkanDevice> device;
};

bool passed(std::uint64_t serial, std::size_t offset);
bool pin(std::uint64_t serial, std::size_t offset);
void unpin(std::uint64_t serial, std::size_t offset);
void pass(std::uint64_t serial, std::size_t end);
void scanLoop(std::stop_token token);
void workLoop(std::stop_token token);
void scan(Scan& work, std::stop_token token);
void queueJob(Job job);

Driver& driver;
std::size_t workerCount;
std::mutex mutex;
std::condition_variable_any scansReady;
std::condition_variable_any jobsReady;
std::deque<Scan> scans;
bool scanning = false;
std::deque<Job> jobs;
std::mutex gateMutex;
std::condition_variable gateLeft;
std::uint64_t passedSerial = 0;
std::size_t passedEnd = 0;
std::vector<std::pair<std::uint64_t, std::size_t>> pinned;
std::shared_ptr<Publication> current;
std::vector<std::jthread> threads;
};
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

#include "prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hpp"
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
#include "prx/libSceAgcDriver/Graphics/include/ShaderInputState.hpp"
#include <array>
#include <atomic>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <list>
#include <memory>
#include <optional>
#include <span>
#include <vector>
#include "prx/libc/include/general/AtomicSharedPtr.hpp"

Expand Down Expand Up @@ -60,14 +63,23 @@ struct DrawRecipeRecord {
bool Expired() const;
};

struct PreparedDrawRecord {
std::vector<std::weak_ptr<const DispatchVariant>> stages;
std::size_t shaders = 0;
std::shared_ptr<const Graphics::PreparedDraw> prepared;
const Graphics::PreparedDraw* For(const std::vector<std::shared_ptr<DispatchVariant>>& variants, std::size_t shaderCount) const;
};

struct DrawEntry {

std::shared_ptr<const DrawDecode> decode;
std::shared_ptr<const PreparedDrawRecord> prepared;

std::vector<std::vector<std::shared_ptr<DispatchVariant>>> stages;

AtomicSharedPtr<const std::vector<DrawRecipeRecord>> recipes;
std::uint64_t touched = 0;
bool probation = false;
std::list<std::uint64_t>::iterator order;
std::uint64_t shape = 0;
};
Expand Down Expand Up @@ -118,9 +130,12 @@ struct StageCapture {
std::vector<ShaderRecompiler::MemoryRegion> regions;
std::uint64_t forgetSerial = 0;
std::uint32_t pushOffset = 0;
std::uint64_t userDataMask = ~std::uint64_t{0};
};

bool DecodeProgramsCurrent(const DrawDecode& decode, const ShaderRegistry& registry);
ShaderRecompiler::RecompileRequest DrawStageRequest(const DrawProgram& program, const Graphics::State& graphics, const ShaderRecompiler::ShaderPixelStageInfo& pixel, const std::optional<ShaderRecompiler::ShaderVertexStageInfo>& vertexInfo, std::span<const ShaderRecompiler::MemoryRegion> memory, std::span<const ShaderRecompiler::LinkedProgram> linked, const Pm4::DrawParameters& drawParameters, const ShaderRecompiler::SpirvTarget& target, std::uint32_t pushOffset);
std::shared_ptr<DispatchVariant> DrawStageVariant(const DrawProgram& program, const StageCapture& capture, const std::optional<ShaderRecompiler::ShaderVertexStageInfo>& vertexInfo, std::span<const Graphics::DecodeRead> decodeReads);

}

Expand Down
Loading