Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions core/kyty/graphics/host_gpu/renderer/pipeline/pipelineCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 38 additions & 3 deletions core/kyty/graphics/host_gpu/renderer/pipeline/pipelineManifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> dropped {0};
uint64_t build_ns = 0;
uint64_t pipeline_ns = 0;
Expand Down Expand Up @@ -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<const uint32_t> code) {
auto& cache = *static_cast<PipelineCache*>(userdata);
auto& state = *cache.m_manifest;
Expand Down Expand Up @@ -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<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now() - start)
.count());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions core/kyty/graphics/host_gpu/renderer/renderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion core/libs/prx/libSceAgcDriver/KytyShim/src/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <exception>
Expand Down Expand Up @@ -377,7 +378,11 @@ extern "C" std::size_t AgcDriverAwaitedWaits_nid_postfix(AgcDriver::AwaitedWait*
}

extern "C" void AgcDriverWaitForPipelineJournal_nid_postfix() {
static_cast<void>(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();
}

Expand Down
13 changes: 12 additions & 1 deletion core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +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 $<TARGET_FILE:agc_frame_replay>)
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")
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
$<TARGET_FILE:agc_frame_replay> --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
Expand Down Expand Up @@ -815,12 +821,17 @@ 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_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:$<TARGET_FILE_DIR:libSceAgcDriver>")
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:$<TARGET_FILE_DIR:libSceAgcDriver>")
endif()
endif()
endif()

Expand Down
Loading
Loading