util/disk_cache: Implement disk_cache_get_function_identifier for Windows

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17208>
This commit is contained in:
Jesse Natalie 2022-06-23 07:31:10 -07:00 committed by Marge Bot
parent 9d7d1c0637
commit 2dcbe87271
2 changed files with 47 additions and 4 deletions

View File

@ -34,6 +34,7 @@
#include <stdbool.h>
#include <sys/stat.h>
#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)

View File

@ -21,7 +21,6 @@
* IN THE SOFTWARE.
*/
#ifdef ENABLE_SHADER_CACHE
#include <assert.h>
#include <inttypes.h>
@ -30,17 +29,59 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#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;
uint32_t uncompressed_size;
};
#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 */
@ -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"