Fix wired Vulkan validation cache errors on Linux

#2201 #1825
This commit is contained in:
Wojtek Figat
2024-04-26 21:47:51 +02:00
parent c5520f2777
commit e835b25637
7 changed files with 27 additions and 17 deletions

View File

@@ -33,6 +33,14 @@
#define VULKAN_USE_DEBUG_LAYER GPU_ENABLE_DIAGNOSTICS #define VULKAN_USE_DEBUG_LAYER GPU_ENABLE_DIAGNOSTICS
#define VULKAN_USE_DEBUG_DATA (GPU_ENABLE_DIAGNOSTICS && COMPILE_WITH_DEV_ENV) #define VULKAN_USE_DEBUG_DATA (GPU_ENABLE_DIAGNOSTICS && COMPILE_WITH_DEV_ENV)
#ifndef VULKAN_USE_VALIDATION_CACHE
#ifdef VK_EXT_validation_cache
#define VULKAN_USE_VALIDATION_CACHE VK_EXT_validation_cache
#else
#define VULKAN_USE_VALIDATION_CACHE 0
#endif
#endif
#ifndef VULKAN_USE_QUERIES #ifndef VULKAN_USE_QUERIES
#define VULKAN_USE_QUERIES 1 #define VULKAN_USE_QUERIES 1
#endif #endif

View File

@@ -39,7 +39,7 @@ static const char* GInstanceExtensions[] =
VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME,
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
#endif #endif
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
VK_EXT_VALIDATION_CACHE_EXTENSION_NAME, VK_EXT_VALIDATION_CACHE_EXTENSION_NAME,
#endif #endif
#if defined(VK_KHR_display) && 0 #if defined(VK_KHR_display) && 0
@@ -57,7 +57,7 @@ static const char* GDeviceExtensions[] =
#if VK_KHR_maintenance1 #if VK_KHR_maintenance1
VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_MAINTENANCE1_EXTENSION_NAME,
#endif #endif
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
VK_EXT_VALIDATION_CACHE_EXTENSION_NAME, VK_EXT_VALIDATION_CACHE_EXTENSION_NAME,
#endif #endif
#if VK_KHR_sampler_mirror_clamp_to_edge #if VK_KHR_sampler_mirror_clamp_to_edge
@@ -582,7 +582,7 @@ void GPUDeviceVulkan::ParseOptionalDeviceExtensions(const Array<const char*>& de
OptionalDeviceExtensions.HasKHRMaintenance2 = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_MAINTENANCE2_EXTENSION_NAME); OptionalDeviceExtensions.HasKHRMaintenance2 = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_MAINTENANCE2_EXTENSION_NAME);
#endif #endif
OptionalDeviceExtensions.HasMirrorClampToEdge = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME); OptionalDeviceExtensions.HasMirrorClampToEdge = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME);
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
OptionalDeviceExtensions.HasEXTValidationCache = RenderToolsVulkan::HasExtension(deviceExtensions, VK_EXT_VALIDATION_CACHE_EXTENSION_NAME); OptionalDeviceExtensions.HasEXTValidationCache = RenderToolsVulkan::HasExtension(deviceExtensions, VK_EXT_VALIDATION_CACHE_EXTENSION_NAME);
#endif #endif
} }

View File

@@ -1439,7 +1439,7 @@ bool GPUDeviceVulkan::SavePipelineCache()
return File::WriteAllBytes(path, data); return File::WriteAllBytes(path, data);
} }
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
void GetValidationCachePath(String& path) void GetValidationCachePath(String& path)
{ {
@@ -1900,7 +1900,7 @@ bool GPUDeviceVulkan::Init()
const VkResult result = vkCreatePipelineCache(Device, &pipelineCacheCreateInfo, nullptr, &PipelineCache); const VkResult result = vkCreatePipelineCache(Device, &pipelineCacheCreateInfo, nullptr, &PipelineCache);
LOG_VULKAN_RESULT(result); LOG_VULKAN_RESULT(result);
} }
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
if (OptionalDeviceExtensions.HasEXTValidationCache && vkCreateValidationCacheEXT && vkDestroyValidationCacheEXT) if (OptionalDeviceExtensions.HasEXTValidationCache && vkCreateValidationCacheEXT && vkDestroyValidationCacheEXT)
{ {
Array<uint8> data; Array<uint8> data;
@@ -1915,16 +1915,16 @@ bool GPUDeviceVulkan::Init()
int32* dataPtr = (int32*)data.Get(); int32* dataPtr = (int32*)data.Get();
if (*dataPtr > 0) if (*dataPtr > 0)
{ {
dataPtr++; const int32 cacheSize = *dataPtr++;
const int32 version = *dataPtr++; const int32 cacheVersion = *dataPtr++;
const int32 versionExpected = VK_PIPELINE_CACHE_HEADER_VERSION_ONE; const int32 cacheVersionExpected = VK_PIPELINE_CACHE_HEADER_VERSION_ONE;
if (version == versionExpected) if (cacheVersion == cacheVersionExpected)
{ {
dataPtr += VK_UUID_SIZE / sizeof(int32); dataPtr += VK_UUID_SIZE / sizeof(int32);
} }
else else
{ {
LOG(Warning, "Bad validation cache file, version: {0}, expected: {1}", version, versionExpected); LOG(Warning, "Bad validation cache file, version: {0}, expected: {1}", cacheVersion, cacheVersionExpected);
data.Clear(); data.Clear();
} }
} }
@@ -2003,7 +2003,7 @@ void GPUDeviceVulkan::Dispose()
vkDestroyPipelineCache(Device, PipelineCache, nullptr); vkDestroyPipelineCache(Device, PipelineCache, nullptr);
PipelineCache = VK_NULL_HANDLE; PipelineCache = VK_NULL_HANDLE;
} }
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
if (ValidationCache != VK_NULL_HANDLE) if (ValidationCache != VK_NULL_HANDLE)
{ {
if (SaveValidationCache()) if (SaveValidationCache())

View File

@@ -400,7 +400,9 @@ public:
uint32 HasKHRMaintenance1 : 1; uint32 HasKHRMaintenance1 : 1;
uint32 HasKHRMaintenance2 : 1; uint32 HasKHRMaintenance2 : 1;
uint32 HasMirrorClampToEdge : 1; uint32 HasMirrorClampToEdge : 1;
#if VULKAN_USE_VALIDATION_CACHE
uint32 HasEXTValidationCache : 1; uint32 HasEXTValidationCache : 1;
#endif
}; };
static void GetInstanceLayersAndExtensions(Array<const char*>& outInstanceExtensions, Array<const char*>& outInstanceLayers, bool& outDebugUtils); static void GetInstanceLayersAndExtensions(Array<const char*>& outInstanceExtensions, Array<const char*>& outInstanceLayers, bool& outDebugUtils);
@@ -496,13 +498,11 @@ public:
/// </summary> /// </summary>
VkPipelineCache PipelineCache = VK_NULL_HANDLE; VkPipelineCache PipelineCache = VK_NULL_HANDLE;
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
/// <summary> /// <summary>
/// The optional validation cache. /// The optional validation cache.
/// </summary> /// </summary>
VkValidationCacheEXT ValidationCache = VK_NULL_HANDLE; VkValidationCacheEXT ValidationCache = VK_NULL_HANDLE;
#endif #endif
/// <summary> /// <summary>
@@ -584,12 +584,10 @@ public:
bool SavePipelineCache(); bool SavePipelineCache();
#if VK_EXT_validation_cache #if VK_EXT_validation_cache
/// <summary> /// <summary>
/// Saves the validation cache. /// Saves the validation cache.
/// </summary> /// </summary>
bool SaveValidationCache(); bool SaveValidationCache();
#endif #endif
private: private:

View File

@@ -116,7 +116,7 @@ GPUShaderProgram* GPUShaderVulkan::CreateGPUShaderProgram(ShaderStage type, cons
RenderToolsVulkan::ZeroStruct(createInfo, VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); RenderToolsVulkan::ZeroStruct(createInfo, VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
createInfo.codeSize = (size_t)spirv.Length(); createInfo.codeSize = (size_t)spirv.Length();
createInfo.pCode = (const uint32_t*)spirv.Get(); createInfo.pCode = (const uint32_t*)spirv.Get();
#if VK_EXT_validation_cache #if VULKAN_USE_VALIDATION_CACHE
VkShaderModuleValidationCacheCreateInfoEXT validationInfo; VkShaderModuleValidationCacheCreateInfoEXT validationInfo;
if (_device->ValidationCache != VK_NULL_HANDLE) if (_device->ValidationCache != VK_NULL_HANDLE)
{ {

View File

@@ -14,6 +14,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#undef VK_EXT_debug_utils #undef VK_EXT_debug_utils
#undef VK_EXT_validation_cache #undef VK_EXT_validation_cache
#define VULKAN_USE_VALIDATION_CACHE 0
#pragma clang diagnostic ignored "-Wpointer-bool-conversion" #pragma clang diagnostic ignored "-Wpointer-bool-conversion"
#pragma clang diagnostic ignored "-Wtautological-pointer-compare" #pragma clang diagnostic ignored "-Wtautological-pointer-compare"

View File

@@ -9,6 +9,9 @@
// Support more backbuffers in case driver decides to use more (https://gitlab.freedesktop.org/apinheiro/mesa/-/issues/9) // Support more backbuffers in case driver decides to use more (https://gitlab.freedesktop.org/apinheiro/mesa/-/issues/9)
#define VULKAN_BACK_BUFFERS_COUNT_MAX 8 #define VULKAN_BACK_BUFFERS_COUNT_MAX 8
// Prevent wierd error 'Invalid VkValidationCacheEXT Object'
#define VULKAN_USE_VALIDATION_CACHE 0
/// <summary> /// <summary>
/// The implementation for the Vulkan API support for Linux platform. /// The implementation for the Vulkan API support for Linux platform.
/// </summary> /// </summary>