Skip to content
Open
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
17 changes: 8 additions & 9 deletions core/kyty/graphics/host_gpu/renderer/renderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions core/libs/prx/libSceAgcDriver/KytyShim/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,10 +16,12 @@

#include <algorithm>
#include <array>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <semaphore>
#include <span>
#include <stdexcept>

Expand Down Expand Up @@ -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<Completion*>(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();
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <string_view>

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");
}
5 changes: 5 additions & 0 deletions docs/dev/debt/changes/fix-kyty-gpu-shutdown-drain.md
Original file line number Diff line number Diff line change
@@ -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.
Loading