diff --git a/core/kyty/graphics/host_gpu/renderer/renderContext.cpp b/core/kyty/graphics/host_gpu/renderer/renderContext.cpp index 84e5e30d583..02dc450b3fc 100644 --- a/core/kyty/graphics/host_gpu/renderer/renderContext.cpp +++ b/core/kyty/graphics/host_gpu/renderer/renderContext.cpp @@ -62,17 +62,16 @@ void RenderContext::InitializeGpu(VideoOut::VideoOutDriver* video_out) { } void RenderContext::ShutdownGpu() { - if (m_gpu != nullptr) { - m_gpu->Shutdown(); - m_gpu.reset(); + if (m_gpu == nullptr) { + return; } - if (m_video_out != nullptr) { - if (m_command_scheduler.Active()) { - m_command_scheduler.Finish(); - } - m_command_scheduler.DrainPriorityOperations(); - m_video_out = nullptr; + m_gpu->Shutdown(); + if (m_command_scheduler.Active()) { + m_command_scheduler.Finish(); } + m_command_scheduler.DrainPriorityOperations(); + m_gpu.reset(); + m_video_out = nullptr; } GuestGpu& RenderContext::GetGpu() const { diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt index 9a74c95fe6a..d08f085bb56 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt @@ -157,6 +157,9 @@ if(NOT ANYPS5_KYTY_DLL AND (WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")) set_tests_properties(kyty_shim_buffer_write_coverage PROPERTIES TIMEOUT 25 SKIP_RETURN_CODE 77 ENVIRONMENT "KYTY_GPU_PIPELINE=0;KYTY_COMMAND_MEMORY_IN_PLACE=0" PASS_REGULAR_EXPRESSION "kyty_shim_buffer_write_coverage: ok" FAIL_REGULAR_EXPRESSION "FAILED") + add_test(NAME kyty_shim_renderer_shutdown COMMAND kyty_shim_cross_queue_label_order_tests renderer-shutdown) + set_tests_properties(kyty_shim_renderer_shutdown PROPERTIES TIMEOUT 25 SKIP_RETURN_CODE 77 + PASS_REGULAR_EXPRESSION "kyty_shim_renderer_shutdown: ok" FAIL_REGULAR_EXPRESSION "FAILED") endif() if(NOT ANYPS5_KYTY_DLL) diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrder.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrder.cpp index e68075082dc..7bd7410fd31 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrder.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrder.cpp @@ -2,6 +2,7 @@ #include "common/emulatorConfig.h" #include "common/threads.h" #include "graphics/guest_gpu/command_processor/commandProcessor.h" +#include "graphics/guest_gpu/graphicsRun.h" #include "graphics/guest_gpu/pm4.h" #include "graphics/host_gpu/graphicContext.h" #include "graphics/host_gpu/renderer/cache/bufferCache.h" @@ -15,10 +16,12 @@ #include #include +#include #include #include #include #include +#include #include #include @@ -263,6 +266,45 @@ const char* ProbeBufferWriteCoverage(GraphicContext& graphics) { return ProbeBufferWriteCoverageCase(graphics, true); } +const char* ProbeRendererShutdown(GraphicContext& graphics) { + struct Completion { + std::binary_semaphore host_submit {0}; + bool finishing = false; + bool saw_stopping_gpu = false; + } completion; + RenderContext renderer(graphics); + renderer.InitializeGpu(nullptr); + auto& scheduler = renderer.GetCommandScheduler(); + CommandProcessor processor(renderer, 0); + processor.Reset(); + scheduler.Begin(processor.GetCtx(), processor.GetUcfg(), processor.GetShCtx()); + scheduler.SetSubmitHook([](void* data, Libs::Graphics::CommandBuffer&) { + auto& completion = *static_cast(data); + if (!GuestGpu::IsGpuThread() && !completion.finishing) { + completion.finishing = true; + completion.host_submit.release(); + } + }, &completion); + scheduler.DeferHostOperation([&] { + if (completion.host_submit.try_acquire_for(std::chrono::seconds(5)) && completion.finishing) { + completion.saw_stopping_gpu = renderer.GetGpu().IsStopping(); + } + }, true); + + renderer.ShutdownGpu(); + scheduler.SetSubmitHook(nullptr, nullptr); + if (!completion.finishing) { + completion.host_submit.release(); + scheduler.DrainPriorityOperations(); + return "the renderer did not finish its scheduler during GPU shutdown"; + } + if (!completion.saw_stopping_gpu) { + return "the queued completion did not observe the stopped GPU during shutdown"; + } + renderer.ShutdownGpu(); + return nullptr; +} + int RunProbe(const char* name, const char* (*probe)(GraphicContext&)) { try { Common::InitializeThreads(); @@ -294,3 +336,7 @@ extern "C" int RunKytyCrossQueueLabelOrderTest(bool buffer_write_coverage) { return buffer_write_coverage ? RunProbe("kyty_shim_buffer_write_coverage", ProbeBufferWriteCoverage) : RunProbe("kyty_shim_cross_queue_label_order", ProbeCrossQueueLabelOrder); } + +extern "C" int RunKytyRendererShutdownTest() { + return RunProbe("kyty_shim_renderer_shutdown", ProbeRendererShutdown); +} diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrderMain.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrderMain.cpp index 93bcf902d8f..1c5d7b44a56 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrderMain.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/CrossQueueLabelOrderMain.cpp @@ -1,7 +1,11 @@ #include extern "C" int RunKytyCrossQueueLabelOrderTest(bool buffer_write_coverage); +extern "C" int RunKytyRendererShutdownTest(); int main(int argc, char** argv) { + if (argc == 2 && std::string_view(argv[1]) == "renderer-shutdown") { + return RunKytyRendererShutdownTest(); + } return RunKytyCrossQueueLabelOrderTest(argc == 2 && std::string_view(argv[1]) == "buffer-write-coverage"); } diff --git a/docs/dev/debt/changes/fix-kyty-gpu-shutdown-drain.md b/docs/dev/debt/changes/fix-kyty-gpu-shutdown-drain.md new file mode 100644 index 00000000000..62ff4e33976 --- /dev/null +++ b/docs/dev/debt/changes/fix-kyty-gpu-shutdown-drain.md @@ -0,0 +1,5 @@ +# kyty + +## add Functional + +- [GPU shutdown](../../../core/kyty/graphics/host_gpu/renderer/renderContext.cpp) does not coordinate admission of new guest memory faults with stopping the GPU worker. A fault that needs a new readback can still attempt to use the worker after it stops. Closes when guest fault admission is ordered with GPU shutdown and a watched guest page can be accessed while shutdown runs.