Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cd42e61
fix(shader): serve ds_ordered_count in wave launch order
ZSWolt Oct 22, 2026
af3c0c1
fix(shader): keep ds_ordered_count order across waves that time out
ZSWolt Oct 29, 2026
3cea7d4
fix(shader): reset the ordered-append turn only for programs that order
ZSWolt Oct 29, 2026
7bdeb14
Merge remote-tracking branch 'origin/main' into fix/recompiler-ordere…
ZSWolt Oct 30, 2026
7a3a37d
Merge remote-tracking branch 'origin/main' into fix/recompiler-ordere…
ZSWolt Nov 2, 2026
5332c91
fix(shader): keep guest GDS bounds off the ordered-append metadata
ZSWolt Nov 2, 2026
304e19c
Merge remote-tracking branch 'origin/main' into fix/recompiler-ordere…
ZSWolt Nov 2, 2026
f30287c
test(agc): report a late-started first row in the split ordered-appen…
ZSWolt Nov 3, 2026
c9fe574
test(agc): keep the order-independent split checks on a late-started …
ZSWolt Nov 3, 2026
b337c54
docs(debt): name the split checks a late row 0 skips
ZSWolt Nov 3, 2026
ace6406
docs(debt): keep the ordering entry within 1000 characters
ZSWolt Nov 3, 2026
818557b
Merge main 4f41f4c375 into #12944 (ace6406bc7)
oneandonlydean Nov 3, 2026
390b05a
Merge main 086c0686c8 into #12944 (818557b1c1)
ZSWolt Nov 3, 2026
22c1254
Merge main 5b1d381d5a into #12944 (390b05a599)
ZSWolt Nov 4, 2026
13c089e
Merge main b11c7bf84f into #12944 (22c12543e6)
ZSWolt Nov 4, 2026
850614c
Merge main 4d513cadcc into #12944 (13c089ea9a)
ZSWolt Nov 5, 2026
c95587e
Merge main ea07ec82d3 into #12944 (850614c013)
ZSWolt Nov 5, 2026
3f6d916
Merge main cefc546c86 into #12944 (c95587e63b)
ZSWolt Nov 6, 2026
d643d2a
Merge main dd7c8de5de into #12944 (3f6d916dd5)
ZSWolt Nov 8, 2026
b9710b2
Merge main 9bce44ce3b into #12944 (d643d2a6a3)
ZSWolt Nov 11, 2026
fff351f
fix(agc): size the shared GDS allocation and its host import in whole…
ZSWolt Nov 13, 2026
9d2d569
Merge main 2cebbe43ee into #12944 (fff351f764)
ZSWolt Nov 14, 2026
294347f
chore: merge main into ds_ordered_count wave order
oneandonlydean Nov 19, 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
5 changes: 5 additions & 0 deletions core/libs/prx/libSceAgcDriver/Execution/include/Pm4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "prx/libSceAgcDriver/Execution/include/QueueState.hpp"
#include "prx/libSceAgcDriver/Execution/include/Pm4Opcodes.hpp"
#include "RuntimeAbi.hpp"
#include <cstddef>
#include <vector>
#include <optional>
Expand All @@ -13,6 +14,10 @@
namespace AgcDriver::Pm4 {

constexpr std::size_t GdsBytes = 0x10000;
constexpr std::size_t GdsOrderedTurnOffset = GdsBytes;
constexpr std::size_t GdsOrderedTimeoutsOffset = GdsBytes + sizeof(std::uint32_t);
constexpr std::size_t GdsBindingBytes = GdsBytes + ShaderRecompiler::RuntimeAbi::GdsMetadataDwords * sizeof(std::uint32_t);
constexpr std::size_t GdsAllocationBytes = (GdsBindingBytes + 0xffffu) & ~std::size_t{0xffffu};
std::uint64_t GdsAddress();
void RequestImportableGds(bool requested);
bool ImportableGdsRequested();
Expand Down
6 changes: 3 additions & 3 deletions core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ std::uint64_t GdsAddress() {
const char* const anonymousSharedMemory = reinterpret_cast<const char*>(1);
if (ImportableGdsRequested() && std::getenv("APS5_NO_SHARED_GDS") == nullptr) {
if (const int descriptor = shm_open_nid_postfix(anonymousSharedMemory, OpenReadWrite, 0600); descriptor >= 0) {
void* shared = ftruncate_nid_postfix(descriptor, GdsBytes) == 0 ? mmap_nid_postfix(nullptr, GdsBytes, ReadWrite, Shared, descriptor, 0) : nullptr;
void* shared = ftruncate_nid_postfix(descriptor, GdsAllocationBytes) == 0 ? mmap_nid_postfix(nullptr, GdsAllocationBytes, ReadWrite, Shared, descriptor, 0) : nullptr;
close_nid_postfix(descriptor);
if (shared != nullptr && shared != reinterpret_cast<void*>(static_cast<std::uintptr_t>(-1))) {
std::memset(shared, 0, GdsBytes);
std::memset(shared, 0, GdsAllocationBytes);
gdsShared.store(true, std::memory_order_release);
gdsImportable.store(true, std::memory_order_release);
return reinterpret_cast<std::uint64_t>(shared);
}
}
}
void* mapped = mmap_nid_postfix(nullptr, GdsBytes, ReadWrite, PrivateAnonymous, -1, 0);
void* mapped = mmap_nid_postfix(nullptr, GdsAllocationBytes, ReadWrite, PrivateAnonymous, -1, 0);
if (mapped == nullptr || mapped == reinterpret_cast<void*>(static_cast<std::uintptr_t>(-1))) throw std::runtime_error("cannot allocate the global data share");
return reinterpret_cast<std::uint64_t>(mapped);
}();
Expand Down
11 changes: 10 additions & 1 deletion core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window, bool compileOnly) :
std::ranges::fill(state->emptyBuffer->Bytes(), std::byte{0});
state->oversizedBuffer = std::make_unique<Graphics::Buffer>(graphicsContext(), Graphics::EmptyBufferBytes, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
std::ranges::fill(state->oversizedBuffer->Bytes(), std::byte{0});
if (!compileOnly && Pm4::GdsImportable() && Graphics::HostImportFor(graphicsContext(), Pm4::GdsAddress(), Pm4::GdsBytes, Graphics::ImportRequester::Map) == nullptr) Pm4::RejectGdsImport();
if (!compileOnly && Pm4::GdsImportable() && Graphics::HostImportFor(graphicsContext(), Pm4::GdsAddress(), Pm4::GdsAllocationBytes, Graphics::ImportRequester::Map) == nullptr) Pm4::RejectGdsImport();
if (!state->imageInt64Atomics || !state->bufferInt64Atomics) {
state->atomicLockTable = std::make_unique<Graphics::Buffer>(graphicsContext(), ShaderRecompiler::RuntimeAbi::AtomicLockCount * sizeof(std::uint32_t), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
const auto words = state->atomicLockTable->Bytes();
Expand Down Expand Up @@ -6050,6 +6050,14 @@ void VulkanDevice::recordDispatch(RecordedDispatch& record) {
if (record.pushStages != 0) {
context.Resolved(&Graphics::DeviceFunctions::cmdPushConstants, "vkCmdPushConstants")(commands, record.objects->layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, Graphics::ComputePushConstantBytes, record.pushBytes->data());
}
const auto orderedTurn = record.shader->program->orderedAppend ? std::optional(resources.guestFillTarget(Pm4::GdsAddress() + Pm4::GdsOrderedTurnOffset, sizeof(std::uint32_t))) : std::nullopt;
const auto resetOrderedTurn = [&] {
if (!orderedTurn.has_value()) return;
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
context.Resolved(&Graphics::DeviceFunctions::cmdFillBuffer, "vkCmdFillBuffer")(commands, orderedTurn->buffer, orderedTurn->offset, orderedTurn->range, 0u);
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
};
resetOrderedTurn();
static const bool reportingDispatch = LibcRunReportEnabled_nid_no_patch();
if (reportingDispatch) recorder.NoteGuestWork(commands);
const auto gpuTiming = recorder.BeginGpuTiming(record.programAddress != 0 ? record.programAddress : record.shader->program->variantId);
Expand Down Expand Up @@ -6122,6 +6130,7 @@ void VulkanDevice::recordDispatch(RecordedDispatch& record) {
if (!firstChunk) {
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
context.BindComputePipeline(commands, splitComputePipeline(context, *record.shader->program, *record.objects, {xBase, yBase, zBase}));
resetOrderedTurn();
}
firstChunk = false;
dispatchChunk(commands, std::min(limit[0], record.x - xBase), std::min(limit[1], record.y - yBase), std::min(limit[2], record.z - zBase));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class GuestBufferMemory {
// element the shader updates atomically (DescriptorBinding::bufferAtomic), staged in device
// memory whatever its size (see AllowDeviceStaging).
void AddWritable(std::uint64_t address, std::size_t bytes, bool atomic = false, bool swept = false);
void AddFillTarget(std::uint64_t address, std::size_t bytes);
void AddReadable(std::uint64_t address, std::size_t bytes);
// Device-local staging of written and atomic elements inside host imports (see
// GuestBufferMemory.cpp): allowed only for a build whose every use records its work and then
Expand Down Expand Up @@ -415,6 +416,7 @@ class GuestBufferMemory {
void UploadPrepare(bool addressable);
void UploadFinish(bool addressable, std::optional<std::pair<std::uint64_t, std::size_t>> htileClear = std::nullopt);
VkDescriptorBufferInfo Descriptor(std::uint64_t address, std::size_t bytes, std::uint32_t& adjustment) const;
VkDescriptorBufferInfo FillTarget(std::uint64_t address, std::size_t bytes) const;
static std::uint64_t ViewBytes(std::uint64_t bytes, std::uint32_t adjustment);
std::vector<ShaderRecompiler::BdaAbi::Range> AddressRanges() const;
// The BDA table of the cached address space when it serves this upload alone (an address-based
Expand Down Expand Up @@ -648,6 +650,7 @@ class GuestBufferMemory {
bool regionsSorted = false;
bool regionsOverlap = false;
std::vector<std::pair<std::uint64_t, std::uint64_t>> writes;
std::vector<std::pair<std::uint64_t, std::uint64_t>> fillTargets;
std::vector<std::pair<std::uint64_t, std::uint64_t>> reads;
std::vector<std::pair<std::uint64_t, std::uint64_t>> readsOverBase;
std::vector<std::pair<std::uint64_t, std::uint64_t>> servedInsideBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class ShaderResources {
void CopyBacksAfterRun(std::shared_ptr<ShaderResources> self) { afterRunSelf = std::move(self); }
void RunAccesses(std::vector<std::array<std::uint64_t, 3>>& out) const;
bool HoldsLease() const { return guestMemory.HoldsLease(); }
VkDescriptorBufferInfo guestFillTarget(std::uint64_t address, std::size_t bytes) const { return guestMemory.FillTarget(address, bytes); }
bool SpaceReuse() const { return spaceReuse; }
static bool SpaceReuseDisabled();
bool BdaReadOnly() const { return usesBda && bdaReadOnly; }
Expand Down
16 changes: 15 additions & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5940,6 +5940,10 @@ void GuestBufferMemory::AddWritable(std::uint64_t address, std::size_t bytes, bo
writes.emplace_back(address, address + bytes);
}

void GuestBufferMemory::AddFillTarget(std::uint64_t address, std::size_t bytes) {
fillTargets.emplace_back(address, address + bytes);
}

void GuestBufferMemory::AddReadable(std::uint64_t address, std::size_t bytes) {
// Not in `writes`: no reference copy (copyRegion), no write-back, no pending-write note, no
// direct-write mark, and UploadPrepare copies it without the device lock. A written descriptor
Expand Down Expand Up @@ -7026,7 +7030,8 @@ void GuestBufferMemory::UploadFinish(bool addressable, std::optional<std::pair<s
void GuestBufferMemory::copyRegion(Region& region, bool addressable) {
static const bool profile = std::getenv("APS5_PROFILE_DRAW") != nullptr;
const auto bytes = region.end - region.begin;
const auto usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | (addressable ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0u);
const bool fillable = std::any_of(fillTargets.begin(), fillTargets.end(), [&](const auto& range) { return range.first < region.end && region.begin < range.second; });
const auto usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | (fillable ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0u) | (addressable ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0u);
std::uint64_t readBytes = 0;
bool inImport = false;
if (profile && context.hostImportAlignment != 0) {
Expand Down Expand Up @@ -7543,6 +7548,15 @@ VkDescriptorBufferInfo GuestBufferMemory::Descriptor(std::uint64_t address, std:
return {handle, offset - adjustment, range};
}

VkDescriptorBufferInfo GuestBufferMemory::FillTarget(std::uint64_t address, std::size_t bytes) const {
const auto* found = owner(address, address + bytes);
Require(found != nullptr && std::any_of(fillTargets.begin(), fillTargets.end(), [&](const auto& range) { return range.first <= address && address + bytes <= range.second; }), "guest fill target was not added before the upload");
Require(found->mirror == nullptr, "a guest fill target served by an image mirror is not implemented");
std::uint32_t adjustment = 0;
const auto info = Descriptor(address, bytes, adjustment);
return {info.buffer, info.offset + adjustment, bytes};
}

std::uint64_t GuestBufferMemory::ViewBytes(std::uint64_t bytes, std::uint32_t adjustment) {
if (adjustment % 4 == 0) return bytes + adjustment;
const auto dwords = adjustment / 4 + bytes / 4 + (adjustment % 4 + bytes % 4 + 3) / 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2575,9 +2575,10 @@ void ShaderResources::buildPrepare(std::span<const CompiledShader> shaders, cons
} else if (binding.role == ShaderRecompiler::DescriptorRole::Gds) {
Require(binding.count == 1 && binding.guestDescriptor.empty(), "invalid GDS descriptor contract");
const auto gds = Pm4::GdsAddress();
guestMemory.AddWritable(gds, Pm4::GdsBytes, true);
guestMemory.AddWritable(gds, Pm4::GdsBindingBytes, true);
guestMemory.AddFillTarget(gds + Pm4::GdsOrderedTurnOffset, sizeof(std::uint32_t));
item.allocations.push_back(allocations.size());
allocations.push_back({gds, Pm4::GdsBytes, true, nullptr, ShaderRecompiler::DescriptorRole::ShaderData, true});
allocations.push_back({gds, Pm4::GdsBindingBytes, true, nullptr, ShaderRecompiler::DescriptorRole::ShaderData, true});
} else {
Require(binding.count == 1, "shader data and flattened SRT descriptors must not be arrays");
Require(!binding.guestDescriptor.empty(), "empty shader data descriptor");
Expand Down
3 changes: 2 additions & 1 deletion core/libs/prx/libSceAgcDriver/tests/GuardedMemoryLoads.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define SPV_ENABLE_UTILITY_CODE
#include <spirv/unified1/spirv.hpp>
#undef SPV_ENABLE_UTILITY_CODE
#include "RuntimeAbi.hpp"
#include "IntermediateRepresentation/IrProgram.hpp"
#include "Optimization/ShaderStageInputInfo.hpp"
#include "SpirvBackend/SpirvEmitter.hpp"
Expand Down Expand Up @@ -262,7 +263,7 @@ class AccessTrace {
case spv::OpLogicalNot: return !argument(3);
case spv::OpArrayLength:
require(isGuestPointer(instruction[3]), "unknown array length in access fixture");
return rootName(instruction[3]) == "scratch_pool" ? PoolDwords : 16;
return rootName(instruction[3]) == "scratch_pool" ? PoolDwords : rootName(instruction[3]) == "gds" ? 16 + RuntimeAbi::GdsMetadataDwords : 16;
case spv::OpUDiv: return argument(3) / argument(4);
case spv::OpAtomicIDecrement: return 0;
case spv::OpLoad:
Expand Down
13 changes: 13 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/Pm4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,19 @@ int main(int argc, char** argv) {
std::puts("PM4 asynchronous memory failure propagated to idle, suspend, submit and shutdown");
return 0;
}
if (argc == 2 && std::string(argv[1]) == "shared-gds-pages") {
AgcDriver::Pm4::RequestImportableGds(true);
const auto gds = AgcDriver::Pm4::GdsAddress();
if (!AgcDriver::Pm4::GdsShared()) {
std::puts("shared memory is unavailable, so the shared GDS mapping is not checked");
return 77;
}
constexpr std::size_t unit = 0x10000;
const auto covered = (AgcDriver::Pm4::GdsBindingBytes + unit - 1) & ~(unit - 1);
check(AgcDriver::GuestMemory::Accessible(reinterpret_cast<const void*>(gds), covered, true), "the shared GDS mapping does not cover the whole 64 KiB unit that holds its binding, so a host import of it runs past the end of its file");
std::puts("PM4 shared GDS pages test passed");
return 0;
}
if (argc == 2 && std::string(argv[1]) == "priority-refused") {
testRefusedWorkerPriority();
std::puts("PM4 refused queue worker priority propagated to idle and shutdown");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if(BUILD_TESTING)
add_test(NAME agc_driver_gds_append_consume_copied COMMAND agc_driver_gds_append_consume_tests)
set_tests_properties(agc_driver_gds_append_consume_copied PROPERTIES TIMEOUT 60 ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_NO_HOST_IMPORT=1;APS5_NO_SHARED_GDS=1" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
if(WIN32)
set_tests_properties(agc_driver_gds_append_consume_copied PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ if(BUILD_TESTING)
endif()
add_test(NAME agc_driver_pm4_failure COMMAND agc_driver_pm4_tests failure)
set_tests_properties(agc_driver_pm4_failure PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 TIMEOUT 30)
add_test(NAME agc_driver_pm4_shared_gds_pages COMMAND agc_driver_pm4_tests shared-gds-pages)
set_tests_properties(agc_driver_pm4_shared_gds_pages PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 TIMEOUT 30)
set(pm4RingCases "ring|APS5_PM4_RING=4" "ring-empty|APS5_PM4_RING=16" "ring-disabled|APS5_PM4_RING=0" "ring-invalid|APS5_PM4_RING=4x" "ring-report|APS5_PM4_RING=2" "stall-watchdog|APS5_STALL_WATCHDOG_SECS=1"
"stall-watchdog-invalid|APS5_STALL_WATCHDOG_SECS=1x" "stall-watchdog-rewind|APS5_STALL_WATCHDOG_SECS=1" "stall-watchdog-order|APS5_STALL_WATCHDOG_SECS=1" "stall-clock|APS5_STALL_WATCHDOG_SECS=1"
"stall-prompt-invalid|ANYPS5_STALL_PROMPT=2" "stall-prompt-off|APS5_STALL_WATCHDOG_SECS=1" "stall-prompt-zero|APS5_STALL_WATCHDOG_SECS=1,ANYPS5_STALL_PROMPT=0" "stall-prompt-rearm|APS5_STALL_WATCHDOG_SECS=1,ANYPS5_STALL_PROMPT=1" "stall-prompt-real|APS5_STALL_WATCHDOG_SECS=1,ANYPS5_STALL_PROMPT=1" "stall-prompt-reentry|APS5_STALL_WATCHDOG_SECS=1,ANYPS5_STALL_PROMPT=1" "stall-prompt-quit|APS5_STALL_WATCHDOG_SECS=1,ANYPS5_STALL_PROMPT=1"
Expand Down
Loading
Loading