Merge pull request #95 from boykopovar/fix/tests-agc-main

Fix/tests agc main
For tests:
- `agc_driver`
- `agc_driver_flip`
- `agc_driver_pm4`

Fixed dispatch error propagation and updated checks for asynchronous suspend points and memory synchronization. All 54 tests pass with these changes, restoring a passing test suite on `main` after merge.
This commit is contained in:
boykopovar
2026-09-28 19:39:59 +03:00
committed by GitHub
3 changed files with 39 additions and 28 deletions
@@ -5957,11 +5957,11 @@ private:
CaptureTrace::Log("flip frame=%llu submission=%llu offset=%zu batch=%llu unsignaled=%llu", static_cast<unsigned long long>(frameSerial), static_cast<unsigned long long>(submission.serial), cursor, static_cast<unsigned long long>(batchesAtFlip), static_cast<unsigned long long>(unsignaledAtFlip));
submission.flips.at(cursor)->GpuReady(frame);
} else if (opcode == 0x15) {
timed(&WorkerProfile::dispatchMs, [&] { tolerate("dispatch", [&] { dispatch(queue, packet, submission); }); });
timed(&WorkerProfile::dispatchMs, [&] { dispatch(queue, packet, submission); });
Graphics::Recorder::CountRecordedWork();
finishDispatchPacket(false);
} else if (opcode == 0x16) {
timed(&WorkerProfile::dispatchMs, [&] { tolerate("indirect dispatch", [&] { dispatchIndirect(queue, packet, submission); }); });
timed(&WorkerProfile::dispatchMs, [&] { dispatchIndirect(queue, packet, submission); });
Graphics::Recorder::CountRecordedWork();
finishDispatchPacket(true);
} else if (opcode == 0x3c || opcode == 0x93) {
@@ -6166,15 +6166,8 @@ private:
submission = Submission{};
} catch (...) {
const auto error = std::current_exception();
try {
std::rethrow_exception(error);
} catch (const std::exception& reason) {
std::fprintf(stderr, "[gpu] worker failed: %s\n", reason.what());
} catch (...) {
std::fprintf(stderr, "[gpu] worker failed with a non-standard exception\n");
}
std::fflush(stderr);
std::terminate();
ReportFailure(error);
for (const auto& [offset, flip] : submission.flips) flip->Fail(error);
}
}
};
+25 -9
View File
@@ -41,6 +41,21 @@ struct State {
AgcDriver::FlipInfo last{};
};
class FlipRelease final {
public:
explicit FlipRelease(std::shared_ptr<State> state) : state(std::move(state)) {}
~FlipRelease() { Release(); }
void Release() {
{
std::lock_guard lock(state->mutex);
state->block = false;
}
state->changed.notify_all();
}
private:
std::shared_ptr<State> state;
};
class Request final : public AgcDriver::IFlipRequest {
public:
explicit Request(std::shared_ptr<State> value) : state(std::move(value)) { ++state->alive; }
@@ -104,24 +119,23 @@ void testFlipAndBoundary() {
output->state->block = true;
output->state->checkSelfWait = true;
}
std::future<void> boundary;
FlipRelease release(output->state);
submitFlip();
{
std::unique_lock lock(output->state->mutex);
check(output->state->changed.wait_for(lock, std::chrono::seconds(5), [&] { return output->state->entered; }), "worker did not reach flip");
check(output->state->last.argument == -0x123456789abcdefLL && output->state->last.index == -2, "decoded flip arguments changed");
}
auto boundary = std::async(std::launch::async, [] { AgcDriverSuspendPoint_nid_postfix(); });
check(boundary.wait_for(std::chrono::milliseconds(30)) == std::future_status::timeout, "suspend completed before preceding work");
boundary = std::async(std::launch::async, [] { AgcDriverSuspendPoint_nid_postfix(); });
check(boundary.wait_for(std::chrono::seconds(5)) == std::future_status::ready, "suspend blocked on preceding work");
boundary.get();
check(output->state->ready == 0, "blocked flip completed before release");
AgcDriverUnregisterVideoOutput_nid_postfix(7, output);
auto replacement = std::make_shared<Output>();
AgcDriverRegisterVideoOutput_nid_postfix(7, replacement);
submitFlip();
{
std::lock_guard lock(output->state->mutex);
output->state->block = false;
}
output->state->changed.notify_all();
boundary.get();
release.Release();
AgcDriverWaitIdle_nid_postfix();
check(output->state->ready == 1 && replacement->state->ready == 1, "registration lifetime or FIFO was lost");
check(output->state->failed == 0, "successful request failed");
@@ -140,6 +154,7 @@ void testFlipAndBoundary() {
for (auto& producer : producers) producer.join();
for (auto error : errors) if (error) std::rethrow_exception(error);
AgcDriverSuspendPoint_nid_postfix();
AgcDriverWaitIdle_nid_postfix();
check(replacement->state->ready == 201, "concurrent submissions were lost");
AgcDriverUnregisterVideoOutput_nid_postfix(7, replacement);
}
@@ -151,10 +166,11 @@ void testFailure() {
submitFlip();
std::array<std::string, 4> messages;
std::vector<std::thread> waiters;
for (auto& message : messages) waiters.emplace_back([&message] { message = expectFailure([] { AgcDriverSuspendPoint_nid_postfix(); }); });
for (auto& message : messages) waiters.emplace_back([&message] { message = expectFailure([] { AgcDriverWaitIdle_nid_postfix(); }); });
for (auto& waiter : waiters) waiter.join();
for (auto& message : messages) check(message == "intentional flip failure", "asynchronous failure was lost");
check(expectFailure([] { AgcDriverWaitIdle_nid_postfix(); }) == messages[0], "idle lost flip failure");
check(expectFailure([] { AgcDriverSuspendPoint_nid_postfix(); }) == messages[0], "suspend lost flip failure");
check(expectFailure([] { submitFlip(); }) == messages[0], "submit lost flip failure");
check(output->state->ready == 0 && output->state->failed == 1, "failed flip was completed successfully");
AgcDriverUnregisterVideoOutput_nid_postfix(7, output);
+10 -8
View File
@@ -1,6 +1,5 @@
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include "prx/libSceAgcDriver/Execution/include/MemoryAccessScope.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver.hpp"
#include "prx/libSceAgcDriver/Submit/include/Dcb.hpp"
#include "prx/libc/include/Shutdown.hpp"
@@ -308,13 +307,16 @@ void testMemorySynchronization() {
std::uint32_t destination = 0;
bool read = false;
bool written = false;
} memory;
};
static MemoryState memory;
memory = {};
AgcDriver::QueueState state;
const auto resolve = [](void* context, std::uint64_t address, std::size_t bytes, bool writable) {
auto& memory = *static_cast<MemoryState*>(context);
struct FlushHookReset {
~FlushHookReset() { AgcDriver::GuestMemory::SetFlushHook(nullptr); }
} reset;
const auto resolve = [](std::uint64_t address, std::size_t bytes) {
check(bytes == sizeof(std::uint32_t), "memory transfer resolved an unrelated range");
if (writable) {
check(address == reinterpret_cast<std::uintptr_t>(&memory.destination), "memory transfer resolved an unrelated destination");
if (address == reinterpret_cast<std::uintptr_t>(&memory.destination)) {
memory.written = true;
} else {
check(address == reinterpret_cast<std::uintptr_t>(&memory.source), "memory transfer resolved an unrelated source");
@@ -322,7 +324,7 @@ void testMemorySynchronization() {
memory.read = true;
}
};
const AgcDriver::GuestMemory::MemoryAccessScope scope(&memory, resolve);
AgcDriver::GuestMemory::SetFlushHook(resolve);
execute(state, makePacket(0x37, {0x100, low(&memory.destination), high(&memory.destination), 17}));
check(memory.written && !memory.read && memory.destination == 17, "WRITE_DATA did not synchronize its destination");
for (const auto opcode : {0x40u, 0x50u}) {
@@ -333,7 +335,7 @@ void testMemorySynchronization() {
execute(state, packet);
check(memory.read && memory.written && memory.destination == 42, "memory copy used stale data before range synchronization");
}
const AgcDriver::GuestMemory::MemoryAccessScope rejecting(&memory, [](void*, std::uint64_t, std::size_t, bool) {
AgcDriver::GuestMemory::SetFlushHook([](std::uint64_t, std::size_t) {
throw std::runtime_error("range synchronization failed");
});
expectFailure([&] { execute(state, makePacket(0x37, {0x100, low(&memory.destination), high(&memory.destination), 99})); }, "range synchronization failed");