From dfca3dd87a84443e3d50b94a48e5b249b37ad709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 25 Sep 2024 23:24:25 +0200 Subject: [PATCH] Work around annoying assert in debug memory allocator on 32-bit Windows --- GPU/Vulkan/ShaderManagerVulkan.cpp | 19 ++++++++++--------- GPU/Vulkan/ShaderManagerVulkan.h | 25 +++++++++++++++---------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index 649bbb5106..9fbd98b895 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -27,6 +27,7 @@ #include "Common/GPU/thin3d.h" #include "Common/Data/Encoding/Utf8.h" #include "Common/TimeUtil.h" +#include "Common/MemoryUtil.h" #include "Common/StringUtils.h" #include "Common/GPU/Vulkan/VulkanContext.h" @@ -213,16 +214,16 @@ ShaderManagerVulkan::ShaderManagerVulkan(Draw::DrawContext *draw) codeBuffer_ = new char[CODE_BUFFER_SIZE]; VulkanContext *vulkan = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT); uboAlignment_ = vulkan->GetPhysicalDeviceProperties().properties.limits.minUniformBufferOffsetAlignment; - memset(&ub_base, 0, sizeof(ub_base)); - memset(&ub_lights, 0, sizeof(ub_lights)); - memset(&ub_bones, 0, sizeof(ub_bones)); - static_assert(sizeof(ub_base) <= 512, "ub_base grew too big"); - static_assert(sizeof(ub_lights) <= 512, "ub_lights grew too big"); - static_assert(sizeof(ub_bones) <= 384, "ub_bones grew too big"); + uniforms_ = (Uniforms *)AllocateAlignedMemory(sizeof(Uniforms), 16); + + static_assert(sizeof(uniforms_->ub_base) <= 512, "ub_base grew too big"); + static_assert(sizeof(uniforms_->ub_lights) <= 512, "ub_lights grew too big"); + static_assert(sizeof(uniforms_->ub_bones) <= 384, "ub_bones grew too big"); } ShaderManagerVulkan::~ShaderManagerVulkan() { + FreeAlignedMemory(uniforms_); Clear(); delete[] codeBuffer_; } @@ -278,11 +279,11 @@ uint64_t ShaderManagerVulkan::UpdateUniforms(bool useBufferedRendering) { uint64_t dirty = gstate_c.GetDirtyUniforms(); if (dirty != 0) { if (dirty & DIRTY_BASE_UNIFORMS) - BaseUpdateUniforms(&ub_base, dirty, false, useBufferedRendering); + BaseUpdateUniforms(&uniforms_->ub_base, dirty, false, useBufferedRendering); if (dirty & DIRTY_LIGHT_UNIFORMS) - LightUpdateUniforms(&ub_lights, dirty); + LightUpdateUniforms(&uniforms_->ub_lights, dirty); if (dirty & DIRTY_BONE_UNIFORMS) - BoneUpdateUniforms(&ub_bones, dirty); + BoneUpdateUniforms(&uniforms_->ub_bones, dirty); } gstate_c.CleanUniforms(); return dirty; diff --git a/GPU/Vulkan/ShaderManagerVulkan.h b/GPU/Vulkan/ShaderManagerVulkan.h index eedd863321..dabe5b7368 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.h +++ b/GPU/Vulkan/ShaderManagerVulkan.h @@ -103,6 +103,13 @@ protected: GShaderID id_; }; +struct Uniforms { + // Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time. + UB_VS_FS_Base ub_base{}; + UB_VS_Lights ub_lights{}; + UB_VS_Bones ub_bones{}; +}; + class ShaderManagerVulkan : public ShaderManagerCommon { public: ShaderManagerVulkan(Draw::DrawContext *draw); @@ -139,15 +146,15 @@ public: bool IsLightDirty() { return true; } bool IsBoneDirty() { return true; } - uint32_t PushBaseBuffer(VulkanPushPool *dest, VkBuffer *buf) { - return dest->Push(&ub_base, sizeof(ub_base), uboAlignment_, buf); + uint32_t PushBaseBuffer(VulkanPushPool *dest, VkBuffer *buf) const { + return dest->Push(&uniforms_->ub_base, sizeof(uniforms_->ub_base), uboAlignment_, buf); } - uint32_t PushLightBuffer(VulkanPushPool *dest, VkBuffer *buf) { - return dest->Push(&ub_lights, sizeof(ub_lights), uboAlignment_, buf); + uint32_t PushLightBuffer(VulkanPushPool *dest, VkBuffer *buf) const { + return dest->Push(&uniforms_->ub_lights, sizeof(uniforms_->ub_lights), uboAlignment_, buf); } // TODO: Only push half the bone buffer if we only have four bones. - uint32_t PushBoneBuffer(VulkanPushPool *dest, VkBuffer *buf) { - return dest->Push(&ub_bones, sizeof(ub_bones), uboAlignment_, buf); + uint32_t PushBoneBuffer(VulkanPushPool *dest, VkBuffer *buf) const { + return dest->Push(&uniforms_->ub_bones, sizeof(uniforms_->ub_bones), uboAlignment_, buf); } static bool LoadCacheFlags(FILE *f, DrawEngineVulkan *drawEngine); @@ -171,10 +178,8 @@ private: char *codeBuffer_; uint64_t uboAlignment_; - // Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time. - UB_VS_FS_Base ub_base; - UB_VS_Lights ub_lights; - UB_VS_Bones ub_bones; + + Uniforms *uniforms_; VulkanFragmentShader *lastFShader_ = nullptr; VulkanVertexShader *lastVShader_ = nullptr;