From: Jesse Natalie Date: Thu, 23 Jun 2022 14:31:10 +0000 (-0700) Subject: util/disk_cache: Implement disk_cache_get_function_identifier for Windows X-Git-Tag: upstream/22.3.5~6873 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2dcbe87271bea04d4572063f28af33bca32e12f1;p=platform%2Fupstream%2Fmesa.git util/disk_cache: Implement disk_cache_get_function_identifier for Windows Reviewed-by: Boris Brezillon Part-of: --- diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h index 978e1de..e76e136 100644 --- a/src/util/disk_cache.h +++ b/src/util/disk_cache.h @@ -34,6 +34,7 @@ #include #include #include "util/mesa-sha1.h" +#include "util/detect_os.h" #ifdef __cplusplus extern "C" { @@ -133,6 +134,9 @@ disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx) return false; return true; } +#elif DETECT_OS_WINDOWS +bool +disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx); #else static inline bool disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx) diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index c28853d..a1d6032 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -21,7 +21,6 @@ * IN THE SOFTWARE. */ -#ifdef ENABLE_SHADER_CACHE #include #include @@ -30,11 +29,12 @@ #include #include #include -#include #include #include "util/compress.h" #include "util/crc32.h" +#include "util/disk_cache.h" +#include "util/disk_cache_os.h" struct cache_entry_file_data { uint32_t crc32; @@ -42,6 +42,47 @@ struct cache_entry_file_data { }; #if DETECT_OS_WINDOWS + +bool +disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx) +{ + HMODULE mod = NULL; + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCWSTR)ptr, + &mod); + if (!mod) + return false; + + WCHAR filename[MAX_PATH]; + DWORD filename_length = GetModuleFileNameW(mod, filename, ARRAY_SIZE(filename)); + + if (filename_length == 0 || filename_length == ARRAY_SIZE(filename)) + return false; + + HANDLE mod_as_file = CreateFileW( + filename, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (mod_as_file == INVALID_HANDLE_VALUE) + return false; + + FILETIME time; + bool ret = GetFileTime(mod_as_file, NULL, NULL, &time); + if (ret) + _mesa_sha1_update(ctx, &time, sizeof(time)); + CloseHandle(mod_as_file); + return ret; +} + +#endif + +#ifdef ENABLE_SHADER_CACHE + +#if DETECT_OS_WINDOWS /* TODO: implement disk cache support on windows */ #else @@ -60,8 +101,6 @@ struct cache_entry_file_data { #include "util/blob.h" #include "util/crc32.h" #include "util/debug.h" -#include "util/disk_cache.h" -#include "util/disk_cache_os.h" #include "util/ralloc.h" #include "util/rand_xor.h"