From e835b256375689807e7facd30b810ee2f783a742 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 26 Apr 2024 21:47:51 +0200 Subject: [PATCH] Fix wired Vulkan validation cache errors on Linux #2201 #1825 --- Source/Engine/GraphicsDevice/Vulkan/Config.h | 8 ++++++++ .../Vulkan/GPUDeviceVulkan.Layers.cpp | 6 +++--- .../GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp | 16 ++++++++-------- .../GraphicsDevice/Vulkan/GPUDeviceVulkan.h | 8 +++----- .../GraphicsDevice/Vulkan/GPUShaderVulkan.cpp | 2 +- .../GraphicsDevice/Vulkan/IncludeVulkanHeaders.h | 1 + .../Vulkan/Linux/LinuxVulkanPlatform.h | 3 +++ 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Source/Engine/GraphicsDevice/Vulkan/Config.h b/Source/Engine/GraphicsDevice/Vulkan/Config.h index d31cb9a06..16a19030e 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Config.h +++ b/Source/Engine/GraphicsDevice/Vulkan/Config.h @@ -33,6 +33,14 @@ #define VULKAN_USE_DEBUG_LAYER GPU_ENABLE_DIAGNOSTICS #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 #define VULKAN_USE_QUERIES 1 #endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp index 9b590cb16..c8ee2ccd9 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp @@ -39,7 +39,7 @@ static const char* GInstanceExtensions[] = VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, #endif -#if VK_EXT_validation_cache +#if VULKAN_USE_VALIDATION_CACHE VK_EXT_VALIDATION_CACHE_EXTENSION_NAME, #endif #if defined(VK_KHR_display) && 0 @@ -57,7 +57,7 @@ static const char* GDeviceExtensions[] = #if VK_KHR_maintenance1 VK_KHR_MAINTENANCE1_EXTENSION_NAME, #endif -#if VK_EXT_validation_cache +#if VULKAN_USE_VALIDATION_CACHE VK_EXT_VALIDATION_CACHE_EXTENSION_NAME, #endif #if VK_KHR_sampler_mirror_clamp_to_edge @@ -582,7 +582,7 @@ void GPUDeviceVulkan::ParseOptionalDeviceExtensions(const Array& de OptionalDeviceExtensions.HasKHRMaintenance2 = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_MAINTENANCE2_EXTENSION_NAME); #endif 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); #endif } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index 565037e47..febeb22a1 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -1439,7 +1439,7 @@ bool GPUDeviceVulkan::SavePipelineCache() return File::WriteAllBytes(path, data); } -#if VK_EXT_validation_cache +#if VULKAN_USE_VALIDATION_CACHE void GetValidationCachePath(String& path) { @@ -1900,7 +1900,7 @@ bool GPUDeviceVulkan::Init() const VkResult result = vkCreatePipelineCache(Device, &pipelineCacheCreateInfo, nullptr, &PipelineCache); LOG_VULKAN_RESULT(result); } -#if VK_EXT_validation_cache +#if VULKAN_USE_VALIDATION_CACHE if (OptionalDeviceExtensions.HasEXTValidationCache && vkCreateValidationCacheEXT && vkDestroyValidationCacheEXT) { Array data; @@ -1915,16 +1915,16 @@ bool GPUDeviceVulkan::Init() int32* dataPtr = (int32*)data.Get(); if (*dataPtr > 0) { - dataPtr++; - const int32 version = *dataPtr++; - const int32 versionExpected = VK_PIPELINE_CACHE_HEADER_VERSION_ONE; - if (version == versionExpected) + const int32 cacheSize = *dataPtr++; + const int32 cacheVersion = *dataPtr++; + const int32 cacheVersionExpected = VK_PIPELINE_CACHE_HEADER_VERSION_ONE; + if (cacheVersion == cacheVersionExpected) { dataPtr += VK_UUID_SIZE / sizeof(int32); } 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(); } } @@ -2003,7 +2003,7 @@ void GPUDeviceVulkan::Dispose() vkDestroyPipelineCache(Device, PipelineCache, nullptr); PipelineCache = VK_NULL_HANDLE; } -#if VK_EXT_validation_cache +#if VULKAN_USE_VALIDATION_CACHE if (ValidationCache != VK_NULL_HANDLE) { if (SaveValidationCache()) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h index a77744766..ee08b3eee 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h @@ -400,7 +400,9 @@ public: uint32 HasKHRMaintenance1 : 1; uint32 HasKHRMaintenance2 : 1; uint32 HasMirrorClampToEdge : 1; +#if VULKAN_USE_VALIDATION_CACHE uint32 HasEXTValidationCache : 1; +#endif }; static void GetInstanceLayersAndExtensions(Array& outInstanceExtensions, Array& outInstanceLayers, bool& outDebugUtils); @@ -496,13 +498,11 @@ public: /// VkPipelineCache PipelineCache = VK_NULL_HANDLE; -#if VK_EXT_validation_cache - +#if VULKAN_USE_VALIDATION_CACHE /// /// The optional validation cache. /// VkValidationCacheEXT ValidationCache = VK_NULL_HANDLE; - #endif /// @@ -584,12 +584,10 @@ public: bool SavePipelineCache(); #if VK_EXT_validation_cache - /// /// Saves the validation cache. /// bool SaveValidationCache(); - #endif private: diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.cpp index b62324529..854500527 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.cpp @@ -116,7 +116,7 @@ GPUShaderProgram* GPUShaderVulkan::CreateGPUShaderProgram(ShaderStage type, cons RenderToolsVulkan::ZeroStruct(createInfo, VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); createInfo.codeSize = (size_t)spirv.Length(); createInfo.pCode = (const uint32_t*)spirv.Get(); -#if VK_EXT_validation_cache +#if VULKAN_USE_VALIDATION_CACHE VkShaderModuleValidationCacheCreateInfoEXT validationInfo; if (_device->ValidationCache != VK_NULL_HANDLE) { diff --git a/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h b/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h index e01e980d7..887e5f89d 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h +++ b/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h @@ -14,6 +14,7 @@ #include #undef VK_EXT_debug_utils #undef VK_EXT_validation_cache +#define VULKAN_USE_VALIDATION_CACHE 0 #pragma clang diagnostic ignored "-Wpointer-bool-conversion" #pragma clang diagnostic ignored "-Wtautological-pointer-compare" diff --git a/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h b/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h index 3c8ee101e..a0e95cb2f 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h +++ b/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h @@ -9,6 +9,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 +// Prevent wierd error 'Invalid VkValidationCacheEXT Object' +#define VULKAN_USE_VALIDATION_CACHE 0 + /// /// The implementation for the Vulkan API support for Linux platform. ///