From: Brendan Shanks bshanks@codeweavers.com
--- libs/vkd3d/device.c | 9 +++++++++ libs/vkd3d/vkd3d_private.h | 10 +--------- 2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 1c29bdc1..4018a5c1 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -4479,6 +4479,15 @@ HRESULT vkd3d_join_thread(struct vkd3d_instance *instance, union vkd3d_thread_ha return hr; }
+void vkd3d_set_thread_name(const char *name) +{ +#if defined(HAVE_PTHREAD_SETNAME_NP_2) + pthread_setname_np(pthread_self(), name); +#elif defined(HAVE_PTHREAD_SETNAME_NP_1) + pthread_setname_np(name); +#endif +} + IUnknown *vkd3d_get_device_parent(ID3D12Device *device) { struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index c9b70d9c..5bacb109 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -330,6 +330,7 @@ static inline int vkd3d_cond_destroy(struct vkd3d_cond *cond) HRESULT vkd3d_create_thread(struct vkd3d_instance *instance, PFN_vkd3d_thread thread_main, void *data, union vkd3d_thread_handle *thread); HRESULT vkd3d_join_thread(struct vkd3d_instance *instance, union vkd3d_thread_handle *thread); +void vkd3d_set_thread_name(const char *name);
struct vkd3d_waiting_fence { @@ -1685,15 +1686,6 @@ extern const char vkd3d_build[];
bool vkd3d_get_program_name(char program_name[PATH_MAX]);
-static inline void vkd3d_set_thread_name(const char *name) -{ -#if defined(HAVE_PTHREAD_SETNAME_NP_2) - pthread_setname_np(pthread_self(), name); -#elif defined(HAVE_PTHREAD_SETNAME_NP_1) - pthread_setname_np(name); -#endif -} - VkResult vkd3d_set_vk_object_name_utf8(struct d3d12_device *device, uint64_t vk_object, VkDebugReportObjectTypeEXT vk_object_type, const char *name); HRESULT vkd3d_set_vk_object_name(struct d3d12_device *device, uint64_t vk_object,
From: Brendan Shanks bshanks@codeweavers.com
--- libs/vkd3d/device.c | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 4018a5c1..0058c6b7 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -4479,9 +4479,53 @@ HRESULT vkd3d_join_thread(struct vkd3d_instance *instance, union vkd3d_thread_ha return hr; }
+#ifdef _WIN32 +static BOOL SetThreadDescription_resolved = FALSE; +static HMODULE kernelbase = NULL; +static HRESULT (WINAPI *my_SetThreadDescription)(HANDLE, PCWSTR) = NULL; + +static void resolve_SetThreadDescription(void) +{ + kernelbase = LoadLibraryA("kernelbase.dll"); + if (!kernelbase) + return; + + my_SetThreadDescription = (HRESULT (WINAPI *)(HANDLE, PCWSTR)) GetProcAddress(kernelbase, "SetThreadDescription"); + if (!my_SetThreadDescription) + { + FreeLibrary(kernelbase); + kernelbase = NULL; + } +} +#endif + void vkd3d_set_thread_name(const char *name) { -#if defined(HAVE_PTHREAD_SETNAME_NP_2) +#ifdef _WIN32 + int ret; + WCHAR *nameW; + + if (!SetThreadDescription_resolved) + { + SetThreadDescription_resolved = TRUE; + resolve_SetThreadDescription(); + } + + if (!my_SetThreadDescription) + return; + + ret = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0); + + nameW = vkd3d_malloc(ret * sizeof(WCHAR)); + if (!nameW) + return; + + ret = MultiByteToWideChar(CP_UTF8, 0, name, -1, nameW, ret); + if (ret) + my_SetThreadDescription(GetCurrentThread(), nameW); + + vkd3d_free(nameW); +#elif defined(HAVE_PTHREAD_SETNAME_NP_2) pthread_setname_np(pthread_self(), name); #elif defined(HAVE_PTHREAD_SETNAME_NP_1) pthread_setname_np(name);
I haven't looked at this in much detail, pending the upcoming vkd3d-1.5 release. I did however notice that there are some tabs in resolve_SetThreadDescription(). We may also want to consider moving this to include/private/vkd3d_common.h and libs/vkd3d-common/, which is where most of this kind of platform specific code lives.
How do you feel about [this version](/uploads/0ed0cbc80210d7f224734dcb94048377/vkd3d_set_thread_name.diff)?
Thanks, I gave that a try and it looks good to me
I guess that's already fixed in !39.
This merge request was closed by Giovanni Mascellani.