From 494aca00b6068297cee442347a2e3bdbbfffcd37 Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Fri, 3 Jul 2015 10:34:49 -0600 Subject: loader: Rename loader_platform.h -> vk_loader_platform.h --- loader/CMakeLists.txt | 2 +- loader/debug_report.h | 2 +- loader/loader.c | 2 +- loader/loader_platform.h | 395 -------------------------------------------- loader/table_ops.h | 2 +- loader/trampoline.c | 2 +- loader/vk_loader_platform.h | 395 ++++++++++++++++++++++++++++++++++++++++++++ loader/wsi_lunarg.c | 2 +- 8 files changed, 401 insertions(+), 401 deletions(-) delete mode 100644 loader/loader_platform.h create mode 100644 loader/vk_loader_platform.h (limited to 'loader') diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt index c48f29b0..4b7ebc29 100644 --- a/loader/CMakeLists.txt +++ b/loader/CMakeLists.txt @@ -14,7 +14,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") set(LOADER_SRCS loader.c loader.h - loader_platform.h + vk_loader_platform.h trampoline.c wsi_lunarg.c wsi_lunarg.h diff --git a/loader/debug_report.h b/loader/debug_report.h index 4c8551cc..5d6fd92a 100644 --- a/loader/debug_report.h +++ b/loader/debug_report.h @@ -26,7 +26,7 @@ * Courtney Goeltzenleuchter */ -#include "loader_platform.h" +#include "vk_loader_platform.h" #include "loader.h" #include "vk_debug_report_lunarg.h" diff --git a/loader/loader.c b/loader/loader.c index d59df6c3..a82b1c4d 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -40,7 +40,7 @@ #else // WIN32 #include #endif // WIN32 -#include "loader_platform.h" +#include "vk_loader_platform.h" #include "loader.h" #include "wsi_lunarg.h" #include "gpa_helper.h" diff --git a/loader/loader_platform.h b/loader/loader_platform.h deleted file mode 100644 index 693a3dcf..00000000 --- a/loader/loader_platform.h +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Vulkan - * - * Copyright (C) 2015 LunarG, Inc. - * Copyright 2014 Valve Software - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Jon Ashburn - * Ian Elliott - */ - -#ifndef LOADER_PLATFORM_H -#define LOADER_PLATFORM_H - -#if defined(__linux__) -/* Linux-specific common code: */ - -// Headers: -//#define _GNU_SOURCE 1 -// TBD: Are the contents of the following file used? -#include -// Note: The following file is for dynamic loading: -#include -#include -#include -#include - -// VK Library Filenames, Paths, etc.: -#define PATH_SEPERATOR ':' -#define DIRECTORY_SYMBOL '/' - -// TODO: Need to handle different Linux distros -#define DEFAULT_VK_DRIVERS_INFO "/usr/share/vulkan/icd.d:/etc/vulkan/icd.d" -#define DEFAULT_VK_DRIVERS_PATH "/usr/lib/i386-linux-gnu/vulkan/icd:/usr/lib/x86_64-linux-gnu/vulkan/icd" -#define LAYERS_PATH_ENV "LIBVK_LAYERS_PATH" -#define LAYER_NAMES_ENV "LIBVK_LAYER_NAMES" -#define VK_LAYER_LIBRARY_PREFIX "libVKLayer" -#define VK_LAYER_LIBRARY_PREFIX_LEN 10 -#define VK_LIBRARY_SUFFIX ".so" -#define VK_LIBRARY_SUFFIX_LEN 3 -#ifndef DEFAULT_VK_LAYERS_PATH -// TODO: Are these good default locations? -#define DEFAULT_VK_LAYERS_PATH ".:/usr/lib/i386-linux-gnu/vk:/usr/lib/x86_64-linux-gnu/vk" -#endif - -// C99: -#define PRINTF_SIZE_T_SPECIFIER "%zu" - -// File IO -static inline bool loader_platform_file_exists(const char *path) -{ - if (access(path, F_OK)) - return false; - else - return true; -} - -// Dynamic Loading of libraries: -typedef void * loader_platform_dl_handle; -static inline loader_platform_dl_handle loader_platform_open_library(const char* libPath) -{ - return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL); -} -static inline char * loader_platform_open_library_error(const char* libPath) -{ - return dlerror(); -} -static inline void loader_platform_close_library(loader_platform_dl_handle library) -{ - dlclose(library); -} -static inline void * loader_platform_get_proc_address(loader_platform_dl_handle library, - const char *name) -{ - assert(library); - assert(name); - return dlsym(library, name); -} -static inline char * loader_platform_get_proc_address_error(const char *name) -{ - return dlerror(); -} - -// Threads: -typedef pthread_t loader_platform_thread; -#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ - pthread_once_t var = PTHREAD_ONCE_INIT; -#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ - pthread_once_t var; -static inline void loader_platform_thread_once(void *ctl, void (* func) (void)) -{ - assert(func != NULL); - assert(ctl != NULL); - pthread_once((pthread_once_t *) ctl, func); -} - -// Thread IDs: -typedef pthread_t loader_platform_thread_id; -static inline loader_platform_thread_id loader_platform_get_thread_id() -{ - return pthread_self(); -} - -// Thread mutex: -typedef pthread_mutex_t loader_platform_thread_mutex; -static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) -{ - pthread_mutex_init(pMutex, NULL); -} -static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) -{ - pthread_mutex_lock(pMutex); -} -static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) -{ - pthread_mutex_unlock(pMutex); -} -static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) -{ - pthread_mutex_destroy(pMutex); -} -typedef pthread_cond_t loader_platform_thread_cond; -static inline void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) -{ - pthread_cond_init(pCond, NULL); -} -static inline void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) -{ - pthread_cond_wait(pCond, pMutex); -} -static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) -{ - pthread_cond_broadcast(pCond); -} - - -#elif defined(_WIN32) // defined(__linux__) -/* Windows-specific common code: */ - -// Headers: -#include -#include -#include -#include -#include -#include -#ifdef __cplusplus -#include -#include -using namespace std; -#endif // __cplusplus - -// VK Library Filenames, Paths, etc.: -#define PATH_SEPERATOR ';' -#define DIRECTORY_SYMBOL '\\' -#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE -#define DEFAULT_VK_DRIVERS_INFO "SOFTWARE\\Khronos\\Vulkan\\Drivers" -// TODO: Are these the correct paths -#define DEFAULT_VK_DRIVERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" -// TODO/TBD: Is this an appropriate prefix for Windows? -#define LAYERS_PATH_REGISTRY_VALUE "VK_LAYERS_PATH" -#define LAYER_NAMES_REGISTRY_VALUE "VK_LAYER_NAMES" -#define LAYERS_PATH_ENV "VK_LAYERS_PATH" -#define LAYER_NAMES_ENV "VK_LAYER_NAMES" -// TODO/TBD: Is this an appropriate suffix for Windows? -#define VK_LAYER_LIBRARY_PREFIX "VKLayer" -#define VK_LAYER_LIBRARY_PREFIX_LEN 7 -#define VK_LIBRARY_SUFFIX ".dll" -#define VK_LIBRARY_SUFFIX_LEN 4 -#ifndef DEFAULT_VK_LAYERS_PATH -// TODO: Is this a good default location? -#define DEFAULT_VK_LAYERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" -#endif // DEFAULT_VK_LAYERS_PATH - -// C99: -// Microsoft didn't implement C99 in Visual Studio; but started adding it with -// VS2013. However, VS2013 still didn't have snprintf(). The following is a -// work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the -// "CMakeLists.txt" file). -#define snprintf _snprintf -#define PRINTF_SIZE_T_SPECIFIER "%Iu" - -// Microsoft doesn't implement alloca, instead we have _alloca -#define alloca _alloca - -// Microsoft also doesn't have basename(). Paths are different on Windows, and -// so this is just a temporary solution in order to get us compiling, so that we -// can test some scenarios, and develop the correct solution for Windows. - // TODO: Develop a better, permanent solution for Windows, to replace this - // temporary code: -static char *basename(char *pathname) -{ - char *current, *next; - -// TODO/TBD: Do we need to deal with the Windows's ":" character? - -#define DIRECTORY_SYMBOL_CHAR '\\' - for (current = pathname; *current != '\0'; current = next) { - next = strchr(current, DIRECTORY_SYMBOL_CHAR); - if (next == NULL) { - // No more DIRECTORY_SYMBOL_CHAR's so return p: - return current; - } else { - // Point one character past the DIRECTORY_SYMBOL_CHAR: - next++; - } - } - // We shouldn't get to here, but this makes the compiler happy: - return current; -} - -// File IO -static bool loader_platform_file_exists(const char *path) -{ - if ((_access(path, 0)) == -1) - return false; - else - return true; -} - -// Dynamic Loading: -typedef HMODULE loader_platform_dl_handle; -static loader_platform_dl_handle loader_platform_open_library(const char* libPath) -{ - return LoadLibrary(libPath); -} -static char * loader_platform_open_library_error(const char* libPath) -{ - static char errorMsg[120]; - snprintf(errorMsg, 119, "Failed to open dynamic library \"%s\"", libPath); - return errorMsg; -} -static void loader_platform_close_library(loader_platform_dl_handle library) -{ - FreeLibrary(library); -} -static void * loader_platform_get_proc_address(loader_platform_dl_handle library, - const char *name) -{ - assert(library); - assert(name); - return GetProcAddress(library, name); -} -static char * loader_platform_get_proc_address_error(const char *name) -{ - static char errorMsg[120]; - snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name); - return errorMsg; -} - -// Threads: -typedef HANDLE loader_platform_thread; -#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ - INIT_ONCE var = INIT_ONCE_STATIC_INIT; -#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ - INIT_ONCE var; -static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) -{ - void (*func)(void) = (void (*)(void))Parameter; - func(); - return TRUE; -} - -static void loader_platform_thread_once(void *ctl, void (* func) (void)) -{ - assert(func != NULL); - assert(ctl != NULL); - InitOnceExecuteOnce((PINIT_ONCE) ctl, InitFuncWrapper, func, NULL); -} - -// Thread IDs: -typedef DWORD loader_platform_thread_id; -static loader_platform_thread_id loader_platform_get_thread_id() -{ - return GetCurrentThreadId(); -} - -// Thread mutex: -typedef CRITICAL_SECTION loader_platform_thread_mutex; -static void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) -{ - InitializeCriticalSection(pMutex); -} -static void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) -{ - EnterCriticalSection(pMutex); -} -static void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) -{ - LeaveCriticalSection(pMutex); -} -static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) -{ - DeleteCriticalSection(pMutex); -} -typedef CONDITION_VARIABLE loader_platform_thread_cond; -static void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) -{ - InitializeConditionVariable(pCond); -} -static void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) -{ - SleepConditionVariableCS(pCond, pMutex, INFINITE); -} -static void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) -{ - WakeAllConditionVariable(pCond); -} - -// Windows Registry: -char *loader_get_registry_string(const HKEY hive, - const LPCTSTR sub_key, - const char *value); - -#else // defined(_WIN32) - -#error The "loader_platform.h" file must be modified for this OS. - -// NOTE: In order to support another OS, an #elif needs to be added (above the -// "#else // defined(_WIN32)") for that OS, and OS-specific versions of the -// contents of this file must be created. - -// NOTE: Other OS-specific changes are also needed for this OS. Search for -// files with "WIN32" in it, as a quick way to find files that must be changed. - -#endif // defined(_WIN32) - -#else /* LOADER_PLATFORM_H */ -#ifndef LOADER_PLATFORM_H_TEMP -#define LOADER_PLATFORM_H_TEMP - -// NOTE: The following are hopefully-temporary macros to ensure that people -// don't forget to use the loader_platform_*() functions above: - -#if defined(__linux__) -/* Linux-specific common code: */ - -// Dynamic Loading: -#define dlopen PLEASE USE THE loader_platform_open_library() FUNCTION -#define dlerror PLEASE DO NOT USE THE dlerror() FUNCTION DIRECTLY -#define dlclose PLEASE USE THE loader_platform_close_library() FUNCTION -#define dlsym PLEASE USE THE loader_platform_get_proc_address() FUNCTION - -// Threads: -#define pthread_once PLEASE USE THE loader_platform_thread_once() FUNCTION -#define pthread_self PLEASE USE THE loader_platform_get_thread_id() FUNCTION - -// Thread mutex: -#define pthread_mutex_init PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION -#define pthread_mutex_lock PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION -#define pthread_mutex_unlock PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION -#define pthread_mutex_destroy PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION - - -#elif defined(_WIN32) // defined(__linux__) -/* Windows-specific common code: */ - -// Dynamic Loading: -//#define LoadLibrary PLEASE USE THE loader_platform_open_library() FUNCTION -#define FreeLibrary PLEASE USE THE loader_platform_close_library() FUNCTION -#define GetProcAddress PLEASE USE THE loader_platform_get_proc_address() FUNCTION - -// Threads: -#define InitOnceExecuteOnce PLEASE USE THE loader_platform_thread_once() FUNCTION -#define GetCurrentThreadId PLEASE USE THE loader_platform_get_thread_id() FUNCTION - -// Thread mutex: -#define InitializeCriticalSection PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION -#define EnterCriticalSection PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION -#define LeaveCriticalSection PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION -#define DeleteCriticalSection PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION - - -#endif // defined(_WIN32) -#endif /* LOADER_PLATFORM_H_TEMP */ -#endif /* LOADER_PLATFORM_H */ diff --git a/loader/table_ops.h b/loader/table_ops.h index 84f03396..d65fd30c 100644 --- a/loader/table_ops.h +++ b/loader/table_ops.h @@ -26,7 +26,7 @@ #include #include #include "loader.h" -#include "loader_platform.h" +#include "vk_loader_platform.h" static inline void loader_init_device_dispatch_table(VkLayerDispatchTable *table, PFN_vkGetDeviceProcAddr gpa, diff --git a/loader/trampoline.c b/loader/trampoline.c index f2239ff0..80c43c06 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -24,7 +24,7 @@ #include #include -#include "loader_platform.h" +#include "vk_loader_platform.h" #include "loader.h" #include "debug_report.h" diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h new file mode 100644 index 00000000..693a3dcf --- /dev/null +++ b/loader/vk_loader_platform.h @@ -0,0 +1,395 @@ +/* + * Vulkan + * + * Copyright (C) 2015 LunarG, Inc. + * Copyright 2014 Valve Software + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Jon Ashburn + * Ian Elliott + */ + +#ifndef LOADER_PLATFORM_H +#define LOADER_PLATFORM_H + +#if defined(__linux__) +/* Linux-specific common code: */ + +// Headers: +//#define _GNU_SOURCE 1 +// TBD: Are the contents of the following file used? +#include +// Note: The following file is for dynamic loading: +#include +#include +#include +#include + +// VK Library Filenames, Paths, etc.: +#define PATH_SEPERATOR ':' +#define DIRECTORY_SYMBOL '/' + +// TODO: Need to handle different Linux distros +#define DEFAULT_VK_DRIVERS_INFO "/usr/share/vulkan/icd.d:/etc/vulkan/icd.d" +#define DEFAULT_VK_DRIVERS_PATH "/usr/lib/i386-linux-gnu/vulkan/icd:/usr/lib/x86_64-linux-gnu/vulkan/icd" +#define LAYERS_PATH_ENV "LIBVK_LAYERS_PATH" +#define LAYER_NAMES_ENV "LIBVK_LAYER_NAMES" +#define VK_LAYER_LIBRARY_PREFIX "libVKLayer" +#define VK_LAYER_LIBRARY_PREFIX_LEN 10 +#define VK_LIBRARY_SUFFIX ".so" +#define VK_LIBRARY_SUFFIX_LEN 3 +#ifndef DEFAULT_VK_LAYERS_PATH +// TODO: Are these good default locations? +#define DEFAULT_VK_LAYERS_PATH ".:/usr/lib/i386-linux-gnu/vk:/usr/lib/x86_64-linux-gnu/vk" +#endif + +// C99: +#define PRINTF_SIZE_T_SPECIFIER "%zu" + +// File IO +static inline bool loader_platform_file_exists(const char *path) +{ + if (access(path, F_OK)) + return false; + else + return true; +} + +// Dynamic Loading of libraries: +typedef void * loader_platform_dl_handle; +static inline loader_platform_dl_handle loader_platform_open_library(const char* libPath) +{ + return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL); +} +static inline char * loader_platform_open_library_error(const char* libPath) +{ + return dlerror(); +} +static inline void loader_platform_close_library(loader_platform_dl_handle library) +{ + dlclose(library); +} +static inline void * loader_platform_get_proc_address(loader_platform_dl_handle library, + const char *name) +{ + assert(library); + assert(name); + return dlsym(library, name); +} +static inline char * loader_platform_get_proc_address_error(const char *name) +{ + return dlerror(); +} + +// Threads: +typedef pthread_t loader_platform_thread; +#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ + pthread_once_t var = PTHREAD_ONCE_INIT; +#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ + pthread_once_t var; +static inline void loader_platform_thread_once(void *ctl, void (* func) (void)) +{ + assert(func != NULL); + assert(ctl != NULL); + pthread_once((pthread_once_t *) ctl, func); +} + +// Thread IDs: +typedef pthread_t loader_platform_thread_id; +static inline loader_platform_thread_id loader_platform_get_thread_id() +{ + return pthread_self(); +} + +// Thread mutex: +typedef pthread_mutex_t loader_platform_thread_mutex; +static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) +{ + pthread_mutex_init(pMutex, NULL); +} +static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) +{ + pthread_mutex_lock(pMutex); +} +static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) +{ + pthread_mutex_unlock(pMutex); +} +static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) +{ + pthread_mutex_destroy(pMutex); +} +typedef pthread_cond_t loader_platform_thread_cond; +static inline void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) +{ + pthread_cond_init(pCond, NULL); +} +static inline void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) +{ + pthread_cond_wait(pCond, pMutex); +} +static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) +{ + pthread_cond_broadcast(pCond); +} + + +#elif defined(_WIN32) // defined(__linux__) +/* Windows-specific common code: */ + +// Headers: +#include +#include +#include +#include +#include +#include +#ifdef __cplusplus +#include +#include +using namespace std; +#endif // __cplusplus + +// VK Library Filenames, Paths, etc.: +#define PATH_SEPERATOR ';' +#define DIRECTORY_SYMBOL '\\' +#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE +#define DEFAULT_VK_DRIVERS_INFO "SOFTWARE\\Khronos\\Vulkan\\Drivers" +// TODO: Are these the correct paths +#define DEFAULT_VK_DRIVERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" +// TODO/TBD: Is this an appropriate prefix for Windows? +#define LAYERS_PATH_REGISTRY_VALUE "VK_LAYERS_PATH" +#define LAYER_NAMES_REGISTRY_VALUE "VK_LAYER_NAMES" +#define LAYERS_PATH_ENV "VK_LAYERS_PATH" +#define LAYER_NAMES_ENV "VK_LAYER_NAMES" +// TODO/TBD: Is this an appropriate suffix for Windows? +#define VK_LAYER_LIBRARY_PREFIX "VKLayer" +#define VK_LAYER_LIBRARY_PREFIX_LEN 7 +#define VK_LIBRARY_SUFFIX ".dll" +#define VK_LIBRARY_SUFFIX_LEN 4 +#ifndef DEFAULT_VK_LAYERS_PATH +// TODO: Is this a good default location? +#define DEFAULT_VK_LAYERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" +#endif // DEFAULT_VK_LAYERS_PATH + +// C99: +// Microsoft didn't implement C99 in Visual Studio; but started adding it with +// VS2013. However, VS2013 still didn't have snprintf(). The following is a +// work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the +// "CMakeLists.txt" file). +#define snprintf _snprintf +#define PRINTF_SIZE_T_SPECIFIER "%Iu" + +// Microsoft doesn't implement alloca, instead we have _alloca +#define alloca _alloca + +// Microsoft also doesn't have basename(). Paths are different on Windows, and +// so this is just a temporary solution in order to get us compiling, so that we +// can test some scenarios, and develop the correct solution for Windows. + // TODO: Develop a better, permanent solution for Windows, to replace this + // temporary code: +static char *basename(char *pathname) +{ + char *current, *next; + +// TODO/TBD: Do we need to deal with the Windows's ":" character? + +#define DIRECTORY_SYMBOL_CHAR '\\' + for (current = pathname; *current != '\0'; current = next) { + next = strchr(current, DIRECTORY_SYMBOL_CHAR); + if (next == NULL) { + // No more DIRECTORY_SYMBOL_CHAR's so return p: + return current; + } else { + // Point one character past the DIRECTORY_SYMBOL_CHAR: + next++; + } + } + // We shouldn't get to here, but this makes the compiler happy: + return current; +} + +// File IO +static bool loader_platform_file_exists(const char *path) +{ + if ((_access(path, 0)) == -1) + return false; + else + return true; +} + +// Dynamic Loading: +typedef HMODULE loader_platform_dl_handle; +static loader_platform_dl_handle loader_platform_open_library(const char* libPath) +{ + return LoadLibrary(libPath); +} +static char * loader_platform_open_library_error(const char* libPath) +{ + static char errorMsg[120]; + snprintf(errorMsg, 119, "Failed to open dynamic library \"%s\"", libPath); + return errorMsg; +} +static void loader_platform_close_library(loader_platform_dl_handle library) +{ + FreeLibrary(library); +} +static void * loader_platform_get_proc_address(loader_platform_dl_handle library, + const char *name) +{ + assert(library); + assert(name); + return GetProcAddress(library, name); +} +static char * loader_platform_get_proc_address_error(const char *name) +{ + static char errorMsg[120]; + snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name); + return errorMsg; +} + +// Threads: +typedef HANDLE loader_platform_thread; +#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ + INIT_ONCE var = INIT_ONCE_STATIC_INIT; +#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ + INIT_ONCE var; +static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) +{ + void (*func)(void) = (void (*)(void))Parameter; + func(); + return TRUE; +} + +static void loader_platform_thread_once(void *ctl, void (* func) (void)) +{ + assert(func != NULL); + assert(ctl != NULL); + InitOnceExecuteOnce((PINIT_ONCE) ctl, InitFuncWrapper, func, NULL); +} + +// Thread IDs: +typedef DWORD loader_platform_thread_id; +static loader_platform_thread_id loader_platform_get_thread_id() +{ + return GetCurrentThreadId(); +} + +// Thread mutex: +typedef CRITICAL_SECTION loader_platform_thread_mutex; +static void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) +{ + InitializeCriticalSection(pMutex); +} +static void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) +{ + EnterCriticalSection(pMutex); +} +static void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) +{ + LeaveCriticalSection(pMutex); +} +static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) +{ + DeleteCriticalSection(pMutex); +} +typedef CONDITION_VARIABLE loader_platform_thread_cond; +static void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) +{ + InitializeConditionVariable(pCond); +} +static void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) +{ + SleepConditionVariableCS(pCond, pMutex, INFINITE); +} +static void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) +{ + WakeAllConditionVariable(pCond); +} + +// Windows Registry: +char *loader_get_registry_string(const HKEY hive, + const LPCTSTR sub_key, + const char *value); + +#else // defined(_WIN32) + +#error The "loader_platform.h" file must be modified for this OS. + +// NOTE: In order to support another OS, an #elif needs to be added (above the +// "#else // defined(_WIN32)") for that OS, and OS-specific versions of the +// contents of this file must be created. + +// NOTE: Other OS-specific changes are also needed for this OS. Search for +// files with "WIN32" in it, as a quick way to find files that must be changed. + +#endif // defined(_WIN32) + +#else /* LOADER_PLATFORM_H */ +#ifndef LOADER_PLATFORM_H_TEMP +#define LOADER_PLATFORM_H_TEMP + +// NOTE: The following are hopefully-temporary macros to ensure that people +// don't forget to use the loader_platform_*() functions above: + +#if defined(__linux__) +/* Linux-specific common code: */ + +// Dynamic Loading: +#define dlopen PLEASE USE THE loader_platform_open_library() FUNCTION +#define dlerror PLEASE DO NOT USE THE dlerror() FUNCTION DIRECTLY +#define dlclose PLEASE USE THE loader_platform_close_library() FUNCTION +#define dlsym PLEASE USE THE loader_platform_get_proc_address() FUNCTION + +// Threads: +#define pthread_once PLEASE USE THE loader_platform_thread_once() FUNCTION +#define pthread_self PLEASE USE THE loader_platform_get_thread_id() FUNCTION + +// Thread mutex: +#define pthread_mutex_init PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION +#define pthread_mutex_lock PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION +#define pthread_mutex_unlock PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION +#define pthread_mutex_destroy PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION + + +#elif defined(_WIN32) // defined(__linux__) +/* Windows-specific common code: */ + +// Dynamic Loading: +//#define LoadLibrary PLEASE USE THE loader_platform_open_library() FUNCTION +#define FreeLibrary PLEASE USE THE loader_platform_close_library() FUNCTION +#define GetProcAddress PLEASE USE THE loader_platform_get_proc_address() FUNCTION + +// Threads: +#define InitOnceExecuteOnce PLEASE USE THE loader_platform_thread_once() FUNCTION +#define GetCurrentThreadId PLEASE USE THE loader_platform_get_thread_id() FUNCTION + +// Thread mutex: +#define InitializeCriticalSection PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION +#define EnterCriticalSection PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION +#define LeaveCriticalSection PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION +#define DeleteCriticalSection PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION + + +#endif // defined(_WIN32) +#endif /* LOADER_PLATFORM_H_TEMP */ +#endif /* LOADER_PLATFORM_H */ diff --git a/loader/wsi_lunarg.c b/loader/wsi_lunarg.c index 77d0788e..ad7aa22c 100644 --- a/loader/wsi_lunarg.c +++ b/loader/wsi_lunarg.c @@ -27,7 +27,7 @@ */ #include -#include "loader_platform.h" +#include "vk_loader_platform.h" #include "loader.h" #include "wsi_lunarg.h" -- cgit v1.2.3