From d0817c4c0ae67a5e0c7243eb80eec46107863f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 10 Jan 2024 12:10:20 +0100 Subject: [PATCH] Vulkan: Fix trying to compare uninitialized parts of packed descriptors Found by Valgrind. Other minor cleanup, too. --- Common/GPU/Vulkan/VulkanLoader.cpp | 4 +++- Common/GPU/Vulkan/VulkanRenderManager.h | 6 +++++- Common/Render/ManagedTexture.cpp | 2 +- GPU/Vulkan/DrawEngineVulkan.cpp | 12 ++++++------ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanLoader.cpp b/Common/GPU/Vulkan/VulkanLoader.cpp index aaac2c037f..3717aad209 100644 --- a/Common/GPU/Vulkan/VulkanLoader.cpp +++ b/Common/GPU/Vulkan/VulkanLoader.cpp @@ -318,12 +318,14 @@ static VulkanLibraryHandle VulkanLoadLibrary(const char *logname) { (std::string(tempDir.c_str()) + "/").c_str(),g_nativeLibDir.c_str(), (std::string(driverPath.c_str()) + "/").c_str(),driverLibName.c_str(), (std::string(fileRedirectDir.c_str()) + "/").c_str(),nullptr); + if (!lib) { + ERROR_LOG(G3D, "Failed to load custom driver"); + } } } #endif if (!lib) { - ERROR_LOG(G3D, "Failed to load custom driver"); for (int i = 0; i < ARRAY_SIZE(so_names); i++) { lib = dlopen(so_names[i], RTLD_NOW | RTLD_LOCAL); if (lib) { diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 9dbb450d0c..571ad35e7a 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -202,9 +202,13 @@ struct PackedDescriptor { } image; struct { VkBuffer buffer; - uint32_t offset; uint32_t range; + uint32_t offset; } buffer; + struct { + VkBuffer buffer; + uint64_t range; // write range and a zero offset in one operation with this. + } buffer_zero_offset; }; }; diff --git a/Common/Render/ManagedTexture.cpp b/Common/Render/ManagedTexture.cpp index 6f410a133d..ccf93a9bde 100644 --- a/Common/Render/ManagedTexture.cpp +++ b/Common/Render/ManagedTexture.cpp @@ -32,8 +32,8 @@ public: size_t fileSize; uint8_t *buffer = g_VFS.ReadFile(filename_.c_str(), &fileSize); if (!buffer) { - filename_.clear(); ERROR_LOG(IO, "Failed to read file '%s'", filename_.c_str()); + filename_.clear(); *state_ = ManagedTexture::LoadState::FAILED; return; } diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 95f4f99b6a..8ce2ad533a 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -332,12 +332,12 @@ void DrawEngineVulkan::DoFlush() { descriptors[1].image.sampler = samplerSecondaryNearest_; descriptors[2].image.view = boundDepal_; descriptors[2].image.sampler = (boundDepal_ && boundDepalSmoothed_) ? samplerSecondaryLinear_ : samplerSecondaryNearest_; - descriptors[3].buffer.buffer = baseBuf; - descriptors[3].buffer.range = sizeof(UB_VS_FS_Base); - descriptors[4].buffer.buffer = lightBuf; - descriptors[4].buffer.range = sizeof(UB_VS_Lights); - descriptors[5].buffer.buffer = boneBuf; - descriptors[5].buffer.range = sizeof(UB_VS_Bones); + descriptors[3].buffer_zero_offset.buffer = baseBuf; + descriptors[3].buffer_zero_offset.range = sizeof(UB_VS_FS_Base); + descriptors[4].buffer_zero_offset.buffer = lightBuf; + descriptors[4].buffer_zero_offset.range = sizeof(UB_VS_Lights); + descriptors[5].buffer_zero_offset.buffer = boneBuf; + descriptors[5].buffer_zero_offset.range = sizeof(UB_VS_Bones); if (tess) { const VkDescriptorBufferInfo *bufInfo = tessDataTransferVulkan->GetBufferInfo(); for (int j = 0; j < 3; j++) {