From 6eb179628f98e9326a0c8076419c82c5b878a3c2 Mon Sep 17 00:00:00 2001 From: mjnhbg3 <2287071+mjnhbg3@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:27:12 -0500 Subject: [PATCH 1/4] test(kyty): verify prepared variants after restart --- .../renderer/pipeline/pipelineCache.cpp | 5 + .../renderer/pipeline/pipelineCache.h | 2 + .../renderer/pipeline/pipelineManifest.cpp | 41 +++- .../host_gpu/renderer/renderContext.cpp | 1 + .../libSceAgcDriver/KytyShim/src/Replay.cpp | 7 +- .../KytyShim/tests/CMakeLists.txt | 7 +- .../KytyShim/tests/GenericComputeReplay.cpp | 182 +++++++++++++++++- .../prx/libSceAgcDriver/tools/FrameReplay.cpp | 8 +- docs/dev/ENVIRONMENT.md | 2 + tools/lavapipe_skip.txt | 1 + 10 files changed, 240 insertions(+), 16 deletions(-) diff --git a/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp b/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp index f7e582d7681..fb49af67e7e 100644 --- a/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp +++ b/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp @@ -4215,6 +4215,11 @@ PipelineCache::Pipeline& PipelineCache::GetComputePipeline(const ShaderComputeIn if (auto node = m_async_ready_compute.extract(module.id); !node.empty()) { lock.unlock(); auto& ready = m_compute_pipelines.insert(std::move(node)).position->second; +#if defined(ANYPS5_KYTY) + if (ShaderVariantLog()) { + PipelineCacheLog("[kyty-variant] ready-pipeline stage=CS module={:016x}", module.id); + } +#endif NoteUse(ready, stages); return ready; } diff --git a/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.h b/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.h index 1d242fa0f7e..bee53aebff3 100644 --- a/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.h +++ b/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.h @@ -429,6 +429,8 @@ class PipelineCache { ~PipelineCache(); KYTY_CLASS_NO_COPY(PipelineCache); void Save(); + void FlushManifestRecording(); + [[nodiscard]] bool WaitForManifestCompletion(std::chrono::milliseconds timeout) const; struct Pipeline { vk::PipelineLayout pipeline_layout = nullptr; diff --git a/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineManifest.cpp b/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineManifest.cpp index 488b52ad672..ee7ab94dd5d 100644 --- a/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineManifest.cpp +++ b/core/kyty/graphics/host_gpu/renderer/pipeline/pipelineManifest.cpp @@ -228,6 +228,7 @@ struct PipelineCache::ManifestState { uint32_t pipelines_known = 0; uint32_t pipelines_failed = 0; uint32_t compute = 0; + uint32_t compute_failed = 0; std::atomic dropped {0}; uint64_t build_ns = 0; uint64_t pipeline_ns = 0; @@ -812,6 +813,15 @@ void PipelineCache::CloseManifest() { SaveManifestRecording(); } +void PipelineCache::FlushManifestRecording() { + if (m_manifest == nullptr) { + return; + } + auto& state = *m_manifest; + state.saver = {}; + SaveManifestRecording(); +} + void PipelineCache::OnShaderMapped(void* userdata, uint64_t hash, std::span code) { auto& cache = *static_cast(userdata); auto& state = *cache.m_manifest; @@ -2744,7 +2754,7 @@ void PipelineCache::CreateManifestComputePipeline(const ShaderModule& module, bo m_async_pending_compute.erase(module.id); } std::scoped_lock lock(state.mutex); - state.compute += created ? 1u : 0u; + (created ? state.compute : state.compute_failed)++; state.pipeline_ns += static_cast(std::chrono::duration_cast( std::chrono::steady_clock::now() - start) .count()); @@ -2772,6 +2782,31 @@ PipelineCache::ManifestBacklog PipelineCache::GetManifestBacklog() const { return backlog; } +bool PipelineCache::WaitForManifestCompletion(std::chrono::milliseconds timeout) const { + if (!m_manifest_warm || m_manifest == nullptr) { + return false; + } + auto& state = *m_manifest; + const auto deadline = std::chrono::steady_clock::now() + timeout; + std::unique_lock lock(state.mutex); + for (;;) { + const bool complete = !state.scanning.load(std::memory_order_acquire) && + state.module_jobs.empty() && state.pipeline_jobs.empty() && state.running == 0 && + state.built + state.found + state.failed == state.warm_modules.size() && + state.pipelines + state.pipelines_known + state.pipelines_failed == state.warm_pipelines.size() && + std::ranges::all_of(state.missing_code, [](uint8_t missing) { return missing == 0; }); + if (complete) { + return state.failed == 0 && state.pipelines_failed == 0 && state.compute_failed == 0 && + state.dropped.load(std::memory_order_relaxed) == 0; + } + if (state.available.wait_until(lock, std::min(deadline, std::chrono::steady_clock::now() + + std::chrono::milliseconds(10))) == std::cv_status::timeout && + std::chrono::steady_clock::now() >= deadline) { + return false; + } + } +} + void PipelineCache::ManifestProgress(bool force) { auto& state = *m_manifest; std::scoped_lock lock(state.mutex); @@ -2800,12 +2835,12 @@ void PipelineCache::ManifestProgress(bool force) { state.logged_idle = idle; ManifestLog("Pipeline manifest: {} at {:.1f} s: {} modules compiled ({:.0f} ms), {} compiled " "already, {} failed, {} waiting for their shaders; {} pipelines and {} compute " - "pipelines created ({:.0f} ms), {} created already, {} failed; {} records dropped " + "pipelines created ({:.0f} ms), {} created already, {} failed; {} compute failed; {} records dropped " "after a fatal error", idle ? "idle" : "stopped", Seconds(now - state.start), state.built, Milliseconds(state.build_ns), state.found, state.failed, waiting, state.pipelines, state.compute, Milliseconds(state.pipeline_ns), state.pipelines_known, - state.pipelines_failed, state.dropped.load(std::memory_order_relaxed)); + state.pipelines_failed, state.compute_failed, state.dropped.load(std::memory_order_relaxed)); } void PipelineCache::RecordModule(const ProgramKey& key, diff --git a/core/kyty/graphics/host_gpu/renderer/renderContext.cpp b/core/kyty/graphics/host_gpu/renderer/renderContext.cpp index 8e9c24e3475..cecd160ec51 100644 --- a/core/kyty/graphics/host_gpu/renderer/renderContext.cpp +++ b/core/kyty/graphics/host_gpu/renderer/renderContext.cpp @@ -72,6 +72,7 @@ void RenderContext::ShutdownGpu() { m_command_scheduler.DrainPriorityOperations(); m_gpu.reset(); m_video_out = nullptr; + m_pipeline_cache.FlushManifestRecording(); } GuestGpu& RenderContext::GetGpu() const { diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/src/Replay.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/src/Replay.cpp index 16a72888039..af3c02c56f7 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/src/Replay.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/src/Replay.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -377,7 +378,11 @@ extern "C" std::size_t AgcDriverAwaitedWaits_nid_postfix(AgcDriver::AwaitedWait* } extern "C" void AgcDriverWaitForPipelineJournal_nid_postfix() { - static_cast(KytyShim::Entry::Renderer()); + auto& renderer = KytyShim::Entry::Renderer(); + if (std::getenv("APS5_REPLAY_WAIT_MANIFEST") != nullptr && + !renderer.GetPipelineCache().WaitForManifestCompletion(std::chrono::seconds(30))) { + throw std::runtime_error("frame replay: the pipeline manifest did not finish preparing its shaders and pipelines"); + } AgcDriverWaitIdle_nid_postfix(); } diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt index 4d5bdc20d14..64af9c8ed45 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt @@ -743,6 +743,10 @@ set_tests_properties(kyty_shim_generic_compute_replay PROPERTIES TIMEOUT 180 SKI add_test(NAME kyty_shim_generic_compute_replay_wide COMMAND kyty_shim_generic_compute_replay_tests $) set_tests_properties(kyty_shim_generic_compute_replay_wide PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77 ENVIRONMENT "KYTY_GENERIC_COMPUTE_SPECIALIZE=0" PASS_REGULAR_EXPRESSION "kyty_shim_generic_compute_replay_wide: ok") +add_test(NAME kyty_shim_prepared_variant_first_use COMMAND kyty_shim_generic_compute_replay_tests + $ --prepared) +set_tests_properties(kyty_shim_prepared_variant_first_use PROPERTIES TIMEOUT 30 SKIP_RETURN_CODE 77 + PASS_REGULAR_EXPRESSION "kyty_shim_prepared_variant_first_use: ok") add_test_executable(kyty_shim_packed_unorm_blend_tests ${CMAKE_CURRENT_SOURCE_DIR}/PackedUnormBlend.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../src/Log.cpp @@ -815,7 +819,8 @@ set_tests_properties(kyty_shim_cross_queue_recycled_label_own_tick PROPERTIES TI if(WIN32) set_property(TEST kyty_shim_buffer_null_range kyty_shim_uniform_scalar_replay kyty_shim_empty_buffer_replay kyty_shim_empty_buffer_replay_off kyty_shim_bda_load_forms - kyty_shim_generic_compute_replay kyty_shim_generic_compute_replay_wide kyty_shim_bda_submission_sync + kyty_shim_generic_compute_replay kyty_shim_generic_compute_replay_wide + kyty_shim_prepared_variant_first_use kyty_shim_bda_submission_sync kyty_shim_cross_queue_compute_waits_graphics_data kyty_shim_cross_queue_graphics_waits_compute_data kyty_shim_cross_queue_dma_wait kyty_shim_cross_queue_compute_waits_graphics_clock kyty_shim_cross_queue_graphics_waits_compute_clock kyty_shim_cross_queue_recycled_label diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp index a14a5b8fd64..d8949e5ce89 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp @@ -38,6 +38,7 @@ constexpr std::uint32_t Fill = 0xdeadbeefu; constexpr std::string_view BuildLine = "[kyty-variant] build stage=CS"; constexpr std::string_view ServeLine = "[kyty-variant] serve stage=CS"; constexpr std::string_view WidenLine = "[kyty-variant] widen stage=CS"; +constexpr std::string_view ReadyLine = "[kyty-variant] ready-pipeline stage=CS module="; constexpr std::array LoopWords{ 0xf4080600, 0xfa000100, 0x7e080d00, 0x060808f0, 0x100808ff, 0x3c800000, 0x7e0a02f0, 0x340c0084, @@ -63,6 +64,11 @@ constexpr std::array Dispatches{{ {{FloatA, FloatB, FloatA}, 2u}, }}; +constexpr std::array PreparedDispatches{{ + {{FloatA, FloatB, FloatA}, 2u}, + {{FloatA, UintC, FloatA}, 2u}, +}}; + constexpr std::uint32_t Rows = 32; static_assert(Dispatches.size() * RowBytes <= Rows * Width * 4u); @@ -89,9 +95,9 @@ void append(std::vector& words, std::uint32_t opcode, std::initia words.insert(words.end(), payload); } -std::vector dispatchWords() { +std::vector dispatchWords(std::span dispatches) { std::vector words; - for (std::uint32_t row = 0; row < Dispatches.size(); ++row) { + for (std::uint32_t row = 0; row < dispatches.size(); ++row) { const auto table = Tables + row * 0x200u; const auto target = output(row); append(words, 0x76, {0x20c, static_cast(Code >> 8u), static_cast(Code >> 40u)}); @@ -100,7 +106,7 @@ std::vector dispatchWords() { append(words, 0x76, {0x207, Lanes, 1u, 1u}); append(words, 0x76, {0x240, static_cast(table), static_cast(table >> 32u), - Dispatches[row].count, 0u, target[0], target[1], target[2], target[3]}); + dispatches[row].count, 0u, target[0], target[1], target[2], target[3]}); append(words, 0x15, {1u, 1u, 1u, 0x41u}); } return words; @@ -132,17 +138,17 @@ void writeShader(std::span memory) { write(memory, Code, std::span(LoopWords)); } -void makeCapture(const std::filesystem::path& path) { +void makeCapture(const std::filesystem::path& path, std::span dispatches) { using AgcDriver::FrameCallKind; auto memory = std::vector(GuestBytes); - const auto commands = dispatchWords(); + const auto commands = dispatchWords(dispatches); writeShader(memory); write(memory, Commands, std::span(commands)); - for (std::uint32_t row = 0; row < Dispatches.size(); ++row) { + for (std::uint32_t row = 0; row < dispatches.size(); ++row) { const std::array sampler{0x12u, 0u, 0u, 0u}; const auto table = Tables + row * 0x200u; - for (std::uint32_t entry = 0; entry < Dispatches[row].table.size(); ++entry) { - const auto descriptor = tsharp(Dispatches[row].table[entry]); + for (std::uint32_t entry = 0; entry < dispatches[row].table.size(); ++entry) { + const auto descriptor = tsharp(dispatches[row].table[entry]); write(memory, table + entry * 0x20u, std::span(descriptor)); } write(memory, table + 0x100u, std::span(sampler)); @@ -202,13 +208,14 @@ struct Replay { bool completed = false; std::string log; std::string frame; + std::string dump; }; Replay replay(const std::filesystem::path& tool, const std::filesystem::path& root, const char* name, const char* generic, const char* specialize) { const auto directory = root / name; std::filesystem::create_directories(directory); - makeCapture(directory / "capture"); + makeCapture(directory / "capture", Dispatches); const auto log = directory / "replay.log"; const auto frames = directory / "frames"; setVariable("KYTY_GENERIC_COMPUTE_VARIANT", generic); @@ -229,27 +236,182 @@ Replay replay(const std::filesystem::path& tool, const std::filesystem::path& ro return result; } +Replay preparedReplay(const std::filesystem::path& tool, const std::filesystem::path& root, + const char* scenario, const char* phase, std::span dispatches, + bool wait_manifest) { + const auto directory = root / scenario; + const auto run = directory / phase; + std::filesystem::create_directories(directory / "app0" / "sce_sys"); + std::filesystem::create_directories(run); + { + std::ofstream param(directory / "app0" / "sce_sys" / "param.json", std::ios::binary | std::ios::trunc); + param << "{\"titleId\":\"PREP00001\",\"appVersion\":\"01.00\"}\n"; + if (!param) throw std::runtime_error("could not write synthetic title metadata"); + } + makeCapture(run / "capture", dispatches); + const auto log = run / "replay.log"; + const auto frames = run / "frames"; + const auto dump = run / "output.bin"; + const auto command = quote(tool) + " " + quote(run / "capture") + + " --strict --no-synthesize --repeat 1 --cold-pipelines" + + (wait_manifest ? " --wait-manifest" : "") + " --frames " + quote(frames) + + " --dump \"" + std::to_string(Output) + ":" + + std::to_string(Width * Rows * 4u) + ":" + dump.string() + "\"" + + " > " + quote(log) + " 2>&1"; + const auto previous = std::filesystem::current_path(); + std::filesystem::current_path(directory); + std::fflush(nullptr); +#ifdef _WIN32 + const int status = std::system(('"' + command + '"').c_str()); +#else + const int status = std::system(command.c_str()); +#endif + std::filesystem::current_path(previous); + Replay result; + result.log = readFile(log); + result.frame = readFile(frames / "replay-0.bmp"); + result.dump = readFile(dump); + result.completed = status == 0 && !result.frame.empty() && result.dump.size() == Width * Rows * 4u; + return result; +} + std::size_t count(const std::string& text, std::string_view line) { std::size_t found = 0; for (auto at = text.find(line); at != std::string::npos; at = text.find(line, at + line.size())) ++found; return found; } +std::vector readyPipelineIds(const std::string& log) { + std::vector ids; + const std::string_view text(log); + for (auto at = text.find(ReadyLine); at != std::string_view::npos; + at = text.find(ReadyLine, at + ReadyLine.size())) { + const auto start = at + ReadyLine.size(); + if (text.size() - start < 16) return {}; + ids.push_back(text.substr(start, 16)); + } + return ids; +} + void printTail(const std::string& log) { constexpr std::size_t TailBytes = 4000; std::cerr << (log.size() > TailBytes ? log.substr(log.size() - TailBytes) : log) << '\n'; } +std::uint64_t manifestCompute(const std::string& log) { + const auto at = log.rfind("Pipeline manifest: idle at "); + if (at == std::string::npos) return UINT64_MAX; + const auto end = log.find('\n', at); + const auto line = log.substr(at, end == std::string::npos ? end : end - at); + const auto phrase = line.find(" compute pipelines created"); + if (phrase == std::string::npos) return UINT64_MAX; + auto start = phrase; + while (start > 0 && line[start - 1] >= '0' && line[start - 1] <= '9') --start; + if (start == phrase) return UINT64_MAX; + return std::strtoull(line.c_str() + start, nullptr, 10); +} + +bool changedOutput(std::string_view output) { + if (output.size() != RowBytes) return false; + for (std::size_t at = 0; at < output.size(); at += sizeof(std::uint32_t)) { + std::uint32_t value = 0; + std::memcpy(&value, output.data() + at, sizeof(value)); + if (value == Fill) return false; + } + return true; +} + +int prepared(const std::filesystem::path& tool, const std::filesystem::path& root) { + setVariable("KYTY_PIPELINE_MANIFEST", "1"); + setVariable("KYTY_RECORD_PIPELINE_MANIFEST", "1"); + setVariable("KYTY_GENERIC_COMPUTE_VARIANT", "0"); + setVariable("KYTY_GENERIC_COMPUTE_SPECIALIZE", "0"); + setVariable("KYTY_SHADER_VARIANT_LOG", "1"); + setVariable("KYTY_ASYNC_PIPELINES", "0"); + setVariable("KYTY_GPU_PIPELINE", "0"); + setVariable("KYTY_PIPELINE_STALL_LOG_MS", "0"); + setVariable("ANYPS5_NO_SHADER_CACHE", "1"); + const auto require = [&](bool condition, const char* message, const Replay& result) { + if (condition) return; + std::cerr << "prepared replay files: " << root << '\n'; + printTail(result.log); + throw std::runtime_error(message); + }; + const auto seed = preparedReplay(tool, root, "both", "seed", PreparedDispatches, false); + if (!seed.completed) { + std::cerr << "prepared replay files: " << root << '\n'; + printTail(seed.log); + if (std::getenv("ANYPS5_REQUIRE_VULKAN") == nullptr) return 77; + throw std::runtime_error("the two-variant seed replay did not complete"); + } + const auto both_cache = root / "both" / "_PipelineCache"; + const auto cache_file = both_cache / "PREP00001_01.00.kpm"; + const auto code_file = both_cache / "PREP00001_01.00.code"; + require(std::filesystem::is_regular_file(cache_file) && std::filesystem::file_size(cache_file) > 0 && + std::filesystem::is_regular_file(code_file) && std::filesystem::file_size(code_file) > 0, + "the seed did not save a manifest and shader code", seed); + require(readyPipelineIds(seed.log).empty() && changedOutput(std::string_view(seed.dump).substr(0, RowBytes)) && + changedOutput(std::string_view(seed.dump).substr(RowBytes, RowBytes)) && + seed.dump.substr(0, RowBytes) != seed.dump.substr(RowBytes, RowBytes) && + seed.log.find("\"dispatches\":2.0") != std::string::npos, + "the two seed dispatches did not produce distinct output values", seed); + + const auto warm = preparedReplay(tool, root, "both", "warm", PreparedDispatches, true); + const auto warm_ready = readyPipelineIds(warm.log); + require(warm.completed && warm.dump == seed.dump && warm.frame == seed.frame && + warm.log.find("Pipeline manifest: 2 modules, 0 pipelines in ") != std::string::npos && + manifestCompute(warm.log) == 2 && + warm_ready.size() == 2 && warm_ready[0] != warm_ready[1] && + warm.log.find("compute-sync") == std::string::npos && + warm.log.find("compute-wait") == std::string::npos && + warm.log.find("TEMPORARY COMPUTE DISPATCH SKIP") == std::string::npos && + warm.log.find("\"dispatches\":2.0") != std::string::npos && + warm.log.find("\"unfinished\":0") != std::string::npos && + warm.log.find("\"skipped_bytes\":0") != std::string::npos, + "the prepared variants were not both served on first use without a pipeline wait", warm); + + const auto only_a = std::span(PreparedDispatches.data(), 1); + const auto only_b = std::span(PreparedDispatches.data() + 1, 1); + const auto control_seed = preparedReplay(tool, root, "one", "seed", only_a, false); + require(control_seed.completed && readyPipelineIds(control_seed.log).empty() && + control_seed.dump.substr(0, RowBytes) == seed.dump.substr(0, RowBytes) && + control_seed.log.find("\"dispatches\":1.0") != std::string::npos, + "the one-variant control seed did not produce the first expected output", control_seed); + const auto control_file = root / "one" / "_PipelineCache" / "PREP00001_01.00.kpm"; + require(std::filesystem::is_regular_file(control_file) && std::filesystem::file_size(control_file) > 0, + "the one-variant control did not save its manifest", control_seed); + const auto control = preparedReplay(tool, root, "one", "missing", only_b, true); + require(control.completed && readyPipelineIds(control.log).empty() && + control.dump.substr(0, RowBytes) == seed.dump.substr(RowBytes, RowBytes) && + control.log.find("Pipeline manifest: 1 modules, 0 pipelines in ") != std::string::npos && + manifestCompute(control.log) == 1 && + count(control.log, "compute-sync") == 1 && + control.log.find("\"dispatches\":1.0") != std::string::npos && + control.log.find("\"unfinished\":0") != std::string::npos, + "omitting the second variant did not expose its first-use pipeline miss", control); + + if (std::getenv("APS5_REPLAY_KEEP_ARTIFACTS") == nullptr) { + std::filesystem::remove_all(root); + } else { + std::cout << "prepared replay files: " << root << '\n'; + } + std::cout << "kyty_shim_prepared_variant_first_use: ok (2 prepared native hits, 0 waits; omitted variant: 1 compute-sync miss)\n"; + return 0; +} + } int main(int argc, char** argv) { try { - if (argc != 2) throw std::runtime_error("usage: kyty_shim_generic_compute_replay_tests "); + if (argc != 2 && (argc != 3 || std::strcmp(argv[2], "--prepared") != 0)) { + throw std::runtime_error("usage: kyty_shim_generic_compute_replay_tests [--prepared]"); + } const std::filesystem::path tool = argv[1]; const auto root = std::filesystem::temp_directory_path() / ("kyty-generic-compute-replay-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); std::filesystem::create_directories(root); + if (argc == 3) return prepared(tool, root); const bool vulkan_required = std::getenv("ANYPS5_REQUIRE_VULKAN") != nullptr; const char* setting = std::getenv("KYTY_GENERIC_COMPUTE_SPECIALIZE"); const bool specialize = setting == nullptr || std::strcmp(setting, "0") != 0; diff --git a/core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp b/core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp index f5db6501821..35949864546 100644 --- a/core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp +++ b/core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp @@ -93,6 +93,7 @@ struct Options { std::size_t submits = 0; bool traceSerials = false; bool coldPipelines = false; + bool waitManifest = false; }; struct ThreadSample { @@ -1034,7 +1035,7 @@ struct Replay { int usage() { std::fprintf(stderr, "usage: agc_frame_replay [--no-pace] [--pace-timeout-ms ] [--no-release] [--release-after-ms ] [--strict]\n" - " [--repeat ] [--cold-pipelines] [--dump
::]...\n" + " [--repeat ] [--cold-pipelines] [--wait-manifest] [--dump
::]...\n" " replays the driver calls and guest memory that APS5_FRAME_CAPTURE= recorded, through this\n" " build's AGC driver with no title running, and prints one JSON line with the frame times\n" " --no-pace issues calls without waiting for the in-flight depth the title had\n" @@ -1047,6 +1048,7 @@ int usage() { " --repeat replays the frames n times in this process, restoring the snapshot before each pass;\n" " with n > 1 the frame times come from passes 2 to n, after the first warmed the caches\n" " --cold-pipelines starts with an empty Vulkan pipeline cache instead of the title's pipeline cache file\n" + " --wait-manifest waits up to 30 seconds for the saved pipeline manifest to finish preparing\n" " --shaders replays nothing and maps no guest memory; lists each shader registration with its code\n" " address, size and code hash as the snapshot and the captured writes before it hold them,\n" " and how many registrations share that code\n" @@ -1639,10 +1641,13 @@ void configureEnvironment(const Options& options) { #ifdef _WIN32 _putenv_s("APS5_FRAME_CAPTURE", ""); _putenv_s("APS5_HEADLESS_PIPELINE_CACHE", options.coldPipelines ? "" : "1"); + _putenv_s("APS5_REPLAY_WAIT_MANIFEST", options.waitManifest ? "1" : ""); #else unsetenv("APS5_FRAME_CAPTURE"); if (options.coldPipelines) unsetenv("APS5_HEADLESS_PIPELINE_CACHE"); else setenv("APS5_HEADLESS_PIPELINE_CACHE", "1", 1); + if (options.waitManifest) setenv("APS5_REPLAY_WAIT_MANIFEST", "1", 1); + else unsetenv("APS5_REPLAY_WAIT_MANIFEST"); #endif } @@ -1670,6 +1675,7 @@ int main(int argc, char** argv) { if (error != std::errc{} || end != value.data() + value.size() || options.submits == 0) return usage(); } else if (argument == "--trace-serials") options.traceSerials = true; else if (argument == "--cold-pipelines") options.coldPipelines = true; + else if (argument == "--wait-manifest") options.waitManifest = true; else if (argument == "--dump" && index + 1 < argc) options.dumps.push_back(parseDump(argv[++index])); else if (argument == "--frames" && index + 1 < argc) options.frames = argv[++index]; else if (!argument.starts_with("-") && options.directory.empty()) options.directory = argument; diff --git a/docs/dev/ENVIRONMENT.md b/docs/dev/ENVIRONMENT.md index 028c1af711a..12803d7b6c2 100644 --- a/docs/dev/ENVIRONMENT.md +++ b/docs/dev/ENVIRONMENT.md @@ -51,6 +51,8 @@ The code reads environment names through `getenv`, `IsEnvironmentSet`, `kibSetti | `APS5_FRAME_CAPTURE_TRIGGER` | string | `core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp` | | file whose appearance starts recording at the next eligible boundary; a positive count in it replaces the frame count | | `APS5_FRAME_REPLAY_ATTEMPT` | integer | `core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp` | 0 | number of times `agc_frame_replay` has started itself again on Windows because a host region sat in a captured GPU-visible range; set by the replay for the process it starts, which stops relaunching after 8 | | `APS5_HEADLESS_PIPELINE_CACHE` | presence | `core/libs/prx/libSceAgcDriver/KytyShim/src/VideoOut.cpp` | | loads the pipeline cache file on a device without a window too; `agc_frame_replay` sets it by default and clears it with `--cold-pipelines`, including inherited values | +| `APS5_REPLAY_KEEP_ARTIFACTS` | presence | `core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp` | unset | keeps the synthetic prepared-variant replay captures, output and logs in the printed temporary directory after a successful test run; for test diagnostics | +| `APS5_REPLAY_WAIT_MANIFEST` | presence | `core/libs/prx/libSceAgcDriver/KytyShim/src/Replay.cpp` | unset | set by `agc_frame_replay --wait-manifest` to require loaded manifest shaders and pipelines to finish preparing before the first frame | | `APS5_NO_GPU_WRITE_MARK_EXPIRY` | string | `core/libs/prx/libc/include/WindowsPageTrack.hpp` | 0 | with `APS5_ARM_READ_IMPORTS=1`, `1` keeps a 64 KiB block that the AGC driver announced a GPU write into unprotected until it is unmapped, as before the mark could expire; unset, empty or `0` lets the mark expire once every batch opened before the last announcement into the block has finished on the GPU and that announcement is two frames old, which the `[collects]` line of `APS5_PIPELINE_STATS` counts as blocks whose mark expired; any other value fails | | `APS5_SYNC_FLIP` | presence | `core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp` | | makes flips synchronous (no frames in flight) | | `APS5_THREAD_NICE` | integer | `core/libs/prx/libSceAgcDriver/Execution/src/ThreadPriority.cpp` | -10 | nice value the raised queue workers and presenter ask rtkit for (clamped to -20..19) | diff --git a/tools/lavapipe_skip.txt b/tools/lavapipe_skip.txt index 77bbd5a0e84..cc7f26476c3 100644 --- a/tools/lavapipe_skip.txt +++ b/tools/lavapipe_skip.txt @@ -7,6 +7,7 @@ kyty_shim_empty_buffer_replay_off same device requirement as kyty_shim_depth_tar kyty_shim_wave64_cross_lane same device requirement as kyty_shim_depth_target_alias, and it exercises 64-wide cross-lane operations kyty_shim_generic_compute_replay same device requirement as kyty_shim_depth_target_alias kyty_shim_generic_compute_replay_wide same device requirement as kyty_shim_depth_target_alias +kyty_shim_prepared_variant_first_use same device requirement as kyty_shim_depth_target_alias kyty_shim_bda_submission_sync same device requirement as kyty_shim_depth_target_alias kyty_shim_bda_load_forms same device requirement as kyty_shim_depth_target_alias kyty_shim_cross_queue_compute_waits_graphics_data same device requirement as kyty_shim_depth_target_alias From f29b66c9995cac79017297068022e2a150cd64bb Mon Sep 17 00:00:00 2001 From: mjnhbg3 <2287071+mjnhbg3@users.noreply.github.com> Date: Thu, 26 Nov 2026 13:04:53 -0500 Subject: [PATCH 2/4] test(kyty): distinguish Vulkan skips from replay failures --- .../KytyShim/tests/CMakeLists.txt | 2 +- .../KytyShim/tests/GenericComputeReplay.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt index 64af9c8ed45..6b335e76152 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt @@ -745,7 +745,7 @@ set_tests_properties(kyty_shim_generic_compute_replay_wide PROPERTIES TIMEOUT 18 ENVIRONMENT "KYTY_GENERIC_COMPUTE_SPECIALIZE=0" PASS_REGULAR_EXPRESSION "kyty_shim_generic_compute_replay_wide: ok") add_test(NAME kyty_shim_prepared_variant_first_use COMMAND kyty_shim_generic_compute_replay_tests $ --prepared) -set_tests_properties(kyty_shim_prepared_variant_first_use PROPERTIES TIMEOUT 30 SKIP_RETURN_CODE 77 +set_tests_properties(kyty_shim_prepared_variant_first_use PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 PASS_REGULAR_EXPRESSION "kyty_shim_prepared_variant_first_use: ok") add_test_executable(kyty_shim_packed_unorm_blend_tests ${CMAKE_CURRENT_SOURCE_DIR}/PackedUnormBlend.cpp diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp index d8949e5ce89..0947d01dd85 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/GenericComputeReplay.cpp @@ -1,5 +1,6 @@ #include "prx/libSceAgcDriver/Execution/include/FrameCapture.hpp" +#include #include #include #include @@ -206,6 +207,7 @@ void setVariable(const char* name, const char* value) { struct Replay { bool completed = false; + int status = 0; std::string log; std::string frame; std::string dump; @@ -230,6 +232,7 @@ Replay replay(const std::filesystem::path& tool, const std::filesystem::path& ro const int status = std::system(command.c_str()); #endif Replay result; + result.status = status; result.log = readFile(log); result.frame = readFile(frames / "replay-0.bmp"); result.completed = status == 0 && !result.frame.empty(); @@ -268,6 +271,7 @@ Replay preparedReplay(const std::filesystem::path& tool, const std::filesystem:: #endif std::filesystem::current_path(previous); Replay result; + result.status = status; result.log = readFile(log); result.frame = readFile(frames / "replay-0.bmp"); result.dump = readFile(dump); @@ -281,6 +285,19 @@ std::size_t count(const std::string& text, std::string_view line) { return found; } +bool vulkanUnavailable(const Replay& result) { + if (result.status == 0) return false; + constexpr std::array diagnostics{ + "Could not find suitable device:", + "kyty presentation: the Vulkan loader offers no window surface extension", + "Unable to find a compatible Vulkan Driver", + "Could not load Vulkan", + " is required, but loader supports only "}; + return std::ranges::any_of(diagnostics, [&result](std::string_view diagnostic) { + return result.log.find(diagnostic) != std::string::npos; + }); +} + std::vector readyPipelineIds(const std::string& log) { std::vector ids; const std::string_view text(log); @@ -341,7 +358,7 @@ int prepared(const std::filesystem::path& tool, const std::filesystem::path& roo if (!seed.completed) { std::cerr << "prepared replay files: " << root << '\n'; printTail(seed.log); - if (std::getenv("ANYPS5_REQUIRE_VULKAN") == nullptr) return 77; + if (std::getenv("ANYPS5_REQUIRE_VULKAN") == nullptr && vulkanUnavailable(seed)) return 77; throw std::runtime_error("the two-variant seed replay did not complete"); } const auto both_cache = root / "both" / "_PipelineCache"; From f317128e706d40ce66b0a16996cc4eb50d47d28f Mon Sep 17 00:00:00 2001 From: mjnhbg3 <2287071+mjnhbg3@users.noreply.github.com> Date: Thu, 26 Nov 2026 13:13:21 -0500 Subject: [PATCH 3/4] ci(kyty): exclude GPU replay from CPU sanitizers --- .github/workflows/anykyty.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/anykyty.yml b/.github/workflows/anykyty.yml index bd3b115ba4a..aee0eb6100f 100644 --- a/.github/workflows/anykyty.yml +++ b/.github/workflows/anykyty.yml @@ -278,7 +278,7 @@ jobs: sanitizer: address env: GPU_TESTS: >- - ^(kyty_shim_(packed_unorm_blend|compute_execution|wave64_cross_lane|empty_buffer_replay|empty_buffer_replay_off|depth_target_alias|frame_capture_round_trip|buffer_null_range|descriptor_tables_draw|merged_hull_draw|image_write_back_alias|buffer_cache_pages))$ + ^(kyty_shim_(packed_unorm_blend|compute_execution|wave64_cross_lane|empty_buffer_replay|empty_buffer_replay_off|depth_target_alias|frame_capture_round_trip|buffer_null_range|descriptor_tables_draw|merged_hull_draw|image_write_back_alias|buffer_cache_pages|prepared_variant_first_use))$ CPU_TESTS: ^(kyty_shim_.*|guest_gpu_fault|guest_host_write_filter|agc_kyty_shaders)$ steps: - uses: actions/checkout@v7 From 5aa3ca65c7a8cfb6c0f86be43a48521477e2bf69 Mon Sep 17 00:00:00 2001 From: mjnhbg3 <2287071+mjnhbg3@users.noreply.github.com> Date: Thu, 26 Nov 2026 13:18:16 -0500 Subject: [PATCH 4/4] test(kyty): register prepared replay outside sanitizer builds --- .github/workflows/anykyty.yml | 2 +- .../KytyShim/tests/CMakeLists.txt | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/anykyty.yml b/.github/workflows/anykyty.yml index aee0eb6100f..bd3b115ba4a 100644 --- a/.github/workflows/anykyty.yml +++ b/.github/workflows/anykyty.yml @@ -278,7 +278,7 @@ jobs: sanitizer: address env: GPU_TESTS: >- - ^(kyty_shim_(packed_unorm_blend|compute_execution|wave64_cross_lane|empty_buffer_replay|empty_buffer_replay_off|depth_target_alias|frame_capture_round_trip|buffer_null_range|descriptor_tables_draw|merged_hull_draw|image_write_back_alias|buffer_cache_pages|prepared_variant_first_use))$ + ^(kyty_shim_(packed_unorm_blend|compute_execution|wave64_cross_lane|empty_buffer_replay|empty_buffer_replay_off|depth_target_alias|frame_capture_round_trip|buffer_null_range|descriptor_tables_draw|merged_hull_draw|image_write_back_alias|buffer_cache_pages))$ CPU_TESTS: ^(kyty_shim_.*|guest_gpu_fault|guest_host_write_filter|agc_kyty_shaders)$ steps: - uses: actions/checkout@v7 diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt index 6b335e76152..50624c18e82 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt @@ -743,10 +743,12 @@ set_tests_properties(kyty_shim_generic_compute_replay PROPERTIES TIMEOUT 180 SKI add_test(NAME kyty_shim_generic_compute_replay_wide COMMAND kyty_shim_generic_compute_replay_tests $) set_tests_properties(kyty_shim_generic_compute_replay_wide PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77 ENVIRONMENT "KYTY_GENERIC_COMPUTE_SPECIALIZE=0" PASS_REGULAR_EXPRESSION "kyty_shim_generic_compute_replay_wide: ok") -add_test(NAME kyty_shim_prepared_variant_first_use COMMAND kyty_shim_generic_compute_replay_tests - $ --prepared) -set_tests_properties(kyty_shim_prepared_variant_first_use PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 - PASS_REGULAR_EXPRESSION "kyty_shim_prepared_variant_first_use: ok") +if(NOT ANYPS5_ENABLE_ASAN AND NOT ANYPS5_ENABLE_TSAN) + add_test(NAME kyty_shim_prepared_variant_first_use COMMAND kyty_shim_generic_compute_replay_tests + $ --prepared) + set_tests_properties(kyty_shim_prepared_variant_first_use PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + PASS_REGULAR_EXPRESSION "kyty_shim_prepared_variant_first_use: ok") +endif() add_test_executable(kyty_shim_packed_unorm_blend_tests ${CMAKE_CURRENT_SOURCE_DIR}/PackedUnormBlend.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../src/Log.cpp @@ -820,12 +822,16 @@ if(WIN32) set_property(TEST kyty_shim_buffer_null_range kyty_shim_uniform_scalar_replay kyty_shim_empty_buffer_replay kyty_shim_empty_buffer_replay_off kyty_shim_bda_load_forms kyty_shim_generic_compute_replay kyty_shim_generic_compute_replay_wide - kyty_shim_prepared_variant_first_use kyty_shim_bda_submission_sync + kyty_shim_bda_submission_sync kyty_shim_cross_queue_compute_waits_graphics_data kyty_shim_cross_queue_graphics_waits_compute_data kyty_shim_cross_queue_dma_wait kyty_shim_cross_queue_compute_waits_graphics_clock kyty_shim_cross_queue_graphics_waits_compute_clock kyty_shim_cross_queue_recycled_label kyty_shim_cross_queue_early_label kyty_shim_cross_queue_recycled_label_own_tick APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") + if(NOT ANYPS5_ENABLE_ASAN AND NOT ANYPS5_ENABLE_TSAN) + set_property(TEST kyty_shim_prepared_variant_first_use APPEND PROPERTY ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() endif() endif()