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
32 changes: 31 additions & 1 deletion core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ set(agcDriverSources
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Synchronization/WaitMemory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/Driver/Synchronization/WaitStatistics.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/WorkerSampler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/ThreadPriority.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/GuestMemory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/ShaderMemory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/BdaFeatures.cpp
Expand Down Expand Up @@ -229,6 +230,7 @@ target_link_libraries(libSceAgcDriver PRIVATE
SDL2-static
libc
libkernel
${CMAKE_DL_LIBS}
)

set_target_properties(libSceAgcDriver PROPERTIES CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -319,6 +321,29 @@ if(BUILD_TESTING)
endif()
endif()

add_test_executable(agc_thread_priority_tests EXCLUDE_FROM_ALL
tests/ThreadPriority.cpp
Execution/src/ThreadPriority.cpp
)
target_include_directories(agc_thread_priority_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(agc_thread_priority_tests PRIVATE libc ${CMAKE_DL_LIBS})
set_target_properties(agc_thread_priority_tests PROPERTIES CXX_EXTENSIONS OFF)
configure_windows_unwind(agc_thread_priority_tests)
if(BUILD_TESTING)
set_target_properties(agc_thread_priority_tests PROPERTIES EXCLUDE_FROM_ALL OFF)
add_test(NAME agc_thread_priority COMMAND agc_thread_priority_tests)
if(WIN32)
set_tests_properties(agc_thread_priority PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
else()
foreach(mode rt high)
add_test(NAME agc_thread_priority_refused_${mode} COMMAND agc_thread_priority_tests refused)
set_tests_properties(agc_thread_priority_refused_${mode} PROPERTIES ENVIRONMENT
"APS5_THREAD_PRIORITY=${mode};DBUS_SYSTEM_BUS_ADDRESS=unix:path=/nonexistent/aps5-no-rtkit")
endforeach()
endif()
endif()

add_test_executable(agc_structurizer_tests EXCLUDE_FROM_ALL tests/Structurizer.cpp)
target_link_libraries(agc_structurizer_tests PRIVATE shader_recompiler_agc_driver libc)
set_target_properties(agc_structurizer_tests PROPERTIES CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -811,7 +836,7 @@ target_include_directories(agc_driver_mesh_tests PRIVATE
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
${CMAKE_SOURCE_DIR}/3rdparty/SPIRV-Headers/include
)
target_link_libraries(agc_driver_mesh_tests PRIVATE shader_recompiler_agc_driver SDL2-static libc libkernel)
target_link_libraries(agc_driver_mesh_tests PRIVATE shader_recompiler_agc_driver SDL2-static libc libkernel ${CMAKE_DL_LIBS})
set_target_properties(agc_driver_mesh_tests PROPERTIES CXX_EXTENSIONS OFF)
configure_windows_unwind(agc_driver_mesh_tests)

Expand Down Expand Up @@ -911,6 +936,11 @@ if(BUILD_TESTING)
set_tests_properties(agc_driver_pm4_failure PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
if(NOT WIN32)
add_test(NAME agc_driver_pm4_priority_refused COMMAND agc_driver_pm4_tests priority-refused)
set_tests_properties(agc_driver_pm4_priority_refused PROPERTIES ENVIRONMENT
"ANYPS5_NO_SHADER_CACHE=1;APS5_THREAD_PRIORITY=high;DBUS_SYSTEM_BUS_ADDRESS=unix:path=/nonexistent/aps5-no-rtkit" SKIP_RETURN_CODE 77)
endif()
add_test(NAME agc_driver_flip_compute COMMAND agc_driver_flip_tests compute)
set_tests_properties(agc_driver_flip_compute PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77)
if(WIN32)
Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/Execution/include/Driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void Submit(const Packet* packet, std::uint32_t queue);
}

extern "C" void AgcDriverWaitIdle_nid_postfix();
extern "C" void AgcDriverRaiseWorkerThreadPriority_nid_postfix(const char* role);
extern "C" void AgcDriverLockVulkanLoader_nid_postfix();
extern "C" void AgcDriverUnlockVulkanLoader_nid_postfix();
extern "C" void AgcDriverShutdown_nid_postfix();
Expand Down
34 changes: 34 additions & 0 deletions core/libs/prx/libSceAgcDriver/Execution/include/ThreadPriority.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef CORE_LIBS_PRX_LIBSCEAGCDRIVER_EXECUTION_INCLUDE_THREADPRIORITY_HPP
#define CORE_LIBS_PRX_LIBSCEAGCDRIVER_EXECUTION_INCLUDE_THREADPRIORITY_HPP

#include <cstdint>
#include <optional>
#include <string>

namespace AgcDriver {

enum class ThreadPriorityMode { Off, High, Realtime };

struct RttimeLimit {
std::uint64_t soft = 0;
std::uint64_t hard = 0;
bool operator==(const RttimeLimit&) const = default;
};

struct RtkitLimits {
std::int64_t maxPriority = 0;
std::int64_t maxRttimeUs = 0;
};

struct RealtimePlan {
std::string refusal;
std::optional<RttimeLimit> limit;
};

ThreadPriorityMode ParseThreadPriorityMode(const char* text);
RealtimePlan PlanRealtime(std::uint32_t priority, const std::optional<RtkitLimits>& rtkit, RttimeLimit current, std::uint64_t requestedUs);
void RaiseWorkerThreadPriority(const char* role);

}

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "prx/libSceAgcDriver/Execution/include/ThreadPriority.hpp"
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
#include <mutex>

Expand Down Expand Up @@ -55,6 +56,10 @@ void ReportFailure(std::exception_ptr error) {

}

extern "C" void AgcDriverRaiseWorkerThreadPriority_nid_postfix(const char* role) {
AgcDriver::RaiseWorkerThreadPriority(role);
}

extern "C" void AgcDriverWaitIdle_nid_postfix() try {
AgcDriver::WaitIdle();
} catch (const ProcessShutdown&) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
#include "prx/libSceAgcDriver/Execution/include/ThreadPriority.hpp"
#include <bit>
#include <cstdio>
#include <cstdlib>

namespace AgcDriver::DriverDetail {
Expand Down Expand Up @@ -312,7 +314,17 @@ void Driver::enqueue(Submission submission) {
for (const auto dword : submission.labelWrites) ++worker.unfinishedWrites[dword];
worker.pending.push_back(std::move(submission));
worker.queued.fetch_add(1, std::memory_order_acq_rel);
if (!worker.thread.joinable()) worker.thread = std::thread([this, queue] { run(queue); });
if (!worker.thread.joinable()) worker.thread = std::thread([this, queue] {
char role[32];
std::snprintf(role, sizeof(role), "queue 0x%x worker", queue);
try {
RaiseWorkerThreadPriority(role);
} catch (...) {
ReportFailure(std::current_exception());
return;
}
run(queue);
});
}

void Driver::noteHeldAtSubmit(Submission& submission, std::size_t cursor) {
Expand Down
Loading
Loading