feat(windows): name presenter and queue worker threads

This commit is contained in:
MarcZX100 committed 2026-10-14 14:02:27 +00:00
1 parent f3a826ba5c
commit 445db4d013
4 files changed
+66

No files matched your search

@@ -2,6 +2,7 @@
#include "prx/libSceAgcDriver/Execution/include/Driver/Queues/WorkerAffinity.hpp"
#include "prx/libSceAgcDriver/Execution/include/TracyZone.hpp"
#include "prx/libc/include/CpuTopology.hpp"
#include "prx/libc/include/general/ThreadName.hpp"
#include <cstdlib>
namespace AgcDriver::DriverDetail {
@@ -22,6 +23,10 @@ std::uint64_t WorkerAffinityMask() {
void PinWorkerThread(const char* role) {
TracyZone::NameThread(role);
#ifdef _WIN32
const HRESULT nameResult = ThreadName::SetCurrent(role);
if (FAILED(nameResult)) std::fprintf(stderr, "[thread-name] could not name %s (0x%08lx)\n", role, static_cast<unsigned long>(nameResult));
#endif
const auto mask = WorkerAffinityMask();
if (mask == 0) return;
static std::once_flag summary;
+3
View File
@@ -619,6 +619,9 @@ if(BUILD_TESTING)
if(WIN32)
set_tests_properties(log_macros PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
add_test_executable(thread_name_tests ${LIBS_INCLUDE_DIR}/tests/ThreadName.cpp)
target_include_directories(thread_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
add_test(NAME thread_name COMMAND thread_name_tests)
endif()
add_test_executable(guest_heap_report_for_game_tests ${LIBS_INCLUDE_DIR}/tests/GuestHeapReportForGame.cpp)
@@ -0,0 +1,41 @@
#ifndef CORE_LIBS_PRX_LIBC_INCLUDE_GENERAL_THREADNAME_HPP
#define CORE_LIBS_PRX_LIBC_INCLUDE_GENERAL_THREADNAME_HPP
#ifdef _WIN32
#include <cstddef>
#include <cstring>
#include <windows.h>
namespace ThreadName {
template<typename TFunction>
inline TFunction Resolve(const char* name) {
TFunction function = nullptr;
const auto kernel = GetModuleHandleW(L"Kernel32.dll");
if (kernel == nullptr) return function;
const FARPROC address = GetProcAddress(kernel, name);
static_assert(sizeof(function) == sizeof(address));
std::memcpy(&function, &address, sizeof(function));
return function;
}
inline HRESULT SetCurrent(const char* name) {
if (name == nullptr) return E_INVALIDARG;
wchar_t wideName[64];
std::size_t length = 0;
while (name[length] != '\0' && length < (sizeof(wideName) / sizeof(wideName[0])) - 1) {
wideName[length] = static_cast<unsigned char>(name[length]);
++length;
}
if (name[length] != '\0') return E_INVALIDARG;
wideName[length] = L'\0';
using SetThreadDescriptionFunction = HRESULT(WINAPI*)(HANDLE, PCWSTR);
const auto setThreadDescription = Resolve<SetThreadDescriptionFunction>("SetThreadDescription");
if (setThreadDescription == nullptr) return S_FALSE;
return setThreadDescription(GetCurrentThread(), wideName);
}
}
#endif
#endif
+17
View File
@@ -0,0 +1,17 @@
#include "prx/libc/include/general/ThreadName.hpp"
#include <string>
int main() {
constexpr const char* name = "AnyPS5 queue worker 0x2a";
const HRESULT set = ThreadName::SetCurrent(name);
if (set == S_FALSE) return 0;
if (FAILED(set)) return 1;
using GetThreadDescriptionFunction = HRESULT(WINAPI*)(HANDLE, PWSTR*);
const auto getThreadDescription = ThreadName::Resolve<GetThreadDescriptionFunction>("GetThreadDescription");
if (getThreadDescription == nullptr) return 0;
PWSTR description = nullptr;
if (FAILED(getThreadDescription(GetCurrentThread(), &description))) return 2;
const bool matches = description != nullptr && std::wstring(description) == L"AnyPS5 queue worker 0x2a";
if (description != nullptr) LocalFree(description);
return matches ? 0 : 3;
}