Skip to content
Snippets Groups Projects
Commit 963ea98a authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard
Browse files

vkd3d-common: Add a Windows implementation of vkd3d_set_thread_name().

parent 0ef04659
No related branches found
No related tags found
1 merge request!39vkd3d-common: Add a Windows implementation of vkd3d_set_thread_name().
Pipeline #3352 skipped
......@@ -179,6 +179,7 @@ libvkd3d_common_la_SOURCES = \
libs/vkd3d-common/error.c \
libs/vkd3d-common/memory.c \
libs/vkd3d-common/utf8.c
libvkd3d_common_la_LIBADD = @PTHREAD_LIBS@
lib_LTLIBRARIES = libvkd3d-shader.la libvkd3d.la libvkd3d-utils.la
......
......@@ -115,5 +115,6 @@ struct vkd3d_debug_option
bool vkd3d_debug_list_has_member(const char *string, const char *member);
uint64_t vkd3d_parse_debug_options(const char *string,
const struct vkd3d_debug_option *options, unsigned int option_count);
void vkd3d_set_thread_name(const char *name);
#endif /* __VKD3D_DEBUG_H */
......@@ -16,6 +16,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifdef _WIN32
# define _WIN32_WINNT 0x0600 /* For InitOnceExecuteOnce(). */
#endif
#include "vkd3d_debug.h"
#include <assert.h>
......@@ -27,6 +31,11 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
#include "vkd3d_memory.h"
#define VKD3D_DEBUG_BUFFER_COUNT 64
#define VKD3D_DEBUG_BUFFER_SIZE 512
......@@ -369,3 +378,49 @@ uint64_t vkd3d_parse_debug_options(const char *string,
return flags;
}
#ifdef _WIN32
static HRESULT (WINAPI *pfn_SetThreadDescription)(HANDLE, const WCHAR *);
static BOOL WINAPI resolve_SetThreadDescription(INIT_ONCE *once, void *param, void **context)
{
HMODULE kernelbase;
if (!(kernelbase = LoadLibraryA("kernelbase.dll")))
return TRUE;
if (!(pfn_SetThreadDescription = (void *)GetProcAddress(kernelbase, "SetThreadDescription")))
FreeLibrary(kernelbase);
return TRUE;
}
#endif
void vkd3d_set_thread_name(const char *name)
{
#ifdef _WIN32
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
WCHAR *wname;
int ret;
InitOnceExecuteOnce(&init_once, resolve_SetThreadDescription, NULL, NULL);
if (!pfn_SetThreadDescription)
return;
if ((ret = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0)) <= 0)
return;
if (!(wname = vkd3d_malloc(ret * sizeof(*wname))))
return;
if ((ret = MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, ret)) > 0)
pfn_SetThreadDescription(GetCurrentThread(), wname);
vkd3d_free(wname);
#elif defined(HAVE_PTHREAD_SETNAME_NP_2)
pthread_setname_np(pthread_self(), name);
#elif defined(HAVE_PTHREAD_SETNAME_NP_1)
pthread_setname_np(name);
#endif
}
......@@ -1685,15 +1685,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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment