From 48e0ebab5236a91c99a40318990a0068b77b0941 Mon Sep 17 00:00:00 2001 From: K1ngst0m Date: Sat, 14 Oct 2023 22:50:22 +0800 Subject: [PATCH] vulkan object allocator init --- engine/api/vulkan/descriptorSet.cpp | 4 +- engine/api/vulkan/device.cpp | 46 +++++++------- engine/api/vulkan/instance.cpp | 8 +-- engine/api/vulkan/pipeline.cpp | 2 +- engine/api/vulkan/shader.cpp | 10 +-- engine/api/vulkan/swapChain.cpp | 2 +- engine/api/vulkan/syncPrimitivesPool.cpp | 12 ++-- engine/api/vulkan/vkUtils.cpp | 80 +++++++++++++++++++++++- engine/api/vulkan/vkUtils.h | 6 ++ engine/renderer/api/vulkan/renderer.cpp | 8 +-- 10 files changed, 131 insertions(+), 47 deletions(-) diff --git a/engine/api/vulkan/descriptorSet.cpp b/engine/api/vulkan/descriptorSet.cpp index daac06ff..c249295e 100644 --- a/engine/api/vulkan/descriptorSet.cpp +++ b/engine/api/vulkan/descriptorSet.cpp @@ -42,7 +42,7 @@ DescriptorSetLayout::~DescriptorSetLayout() // Destroy all created pools. for(auto pool : m_pools) { - vkDestroyDescriptorPool(getDevice()->getHandle(), pool, nullptr); + vkDestroyDescriptorPool(getDevice()->getHandle(), pool, vkAllocator()); } } @@ -75,7 +75,7 @@ DescriptorSet* DescriptorSetLayout::allocateSet() createInfo.pNext = &descriptorPoolInlineUniformBlockCreateInfo; } VkDescriptorPool handle = VK_NULL_HANDLE; - auto result = vkCreateDescriptorPool(getDevice()->getHandle(), &createInfo, nullptr, &handle); + auto result = vkCreateDescriptorPool(getDevice()->getHandle(), &createInfo, vkAllocator(), &handle); if(result != VK_SUCCESS) return VK_NULL_HANDLE; diff --git a/engine/api/vulkan/device.cpp b/engine/api/vulkan/device.cpp index 5ba0a496..f77ef652 100644 --- a/engine/api/vulkan/device.cpp +++ b/engine/api/vulkan/device.cpp @@ -1,6 +1,8 @@ #include "device.h" #include "api/gpuResource.h" +const VkAllocationCallbacks* gVkAllocator = aph::vk::vkAllocator(); + namespace aph::vk { @@ -108,7 +110,7 @@ std::unique_ptr Device::Create(const DeviceCreateInfo& createInfo) }; VkDevice handle = VK_NULL_HANDLE; - auto result = vkCreateDevice(physicalDevice->getHandle(), &deviceCreateInfo, nullptr, &handle); + auto result = vkCreateDevice(physicalDevice->getHandle(), &deviceCreateInfo, gVkAllocator, &handle); if(result != VK_SUCCESS) { VK_LOG_ERR("Failed to create device: %s.", vk::utils::errorString(result)); @@ -151,7 +153,7 @@ void Device::Destroy(Device* pDevice) if(pDevice->m_handle) { - pDevice->m_table.vkDestroyDevice(pDevice->m_handle, nullptr); + pDevice->m_table.vkDestroyDevice(pDevice->m_handle, gVkAllocator); } } @@ -168,7 +170,7 @@ VkResult Device::create(const CommandPoolCreateInfo& createInfo, VkCommandPool* } VkCommandPool cmdPool = VK_NULL_HANDLE; - _VR(m_table.vkCreateCommandPool(m_handle, &cmdPoolInfo, nullptr, &cmdPool)); + _VR(m_table.vkCreateCommandPool(m_handle, &cmdPoolInfo, gVkAllocator, &cmdPool)); *ppPool = cmdPool; return VK_SUCCESS; } @@ -199,7 +201,7 @@ VkResult Device::create(const ImageViewCreateInfo& createInfo, ImageView** ppIma memcpy(&info.components, &createInfo.components, sizeof(VkComponentMapping)); VkImageView handle = VK_NULL_HANDLE; - _VR(m_table.vkCreateImageView(getHandle(), &info, nullptr, &handle)); + _VR(m_table.vkCreateImageView(getHandle(), &info, gVkAllocator, &handle)); *ppImageView = new ImageView(createInfo, handle); @@ -216,7 +218,7 @@ VkResult Device::create(const BufferCreateInfo& createInfo, Buffer** ppBuffer) .sharingMode = VK_SHARING_MODE_EXCLUSIVE, }; VkBuffer buffer; - _VR(vkCreateBuffer(getHandle(), &bufferInfo, nullptr, &buffer)); + _VR(vkCreateBuffer(getHandle(), &bufferInfo, gVkAllocator, &buffer)); VkMemoryDedicatedRequirementsKHR dedicatedRequirements = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, @@ -249,14 +251,14 @@ VkResult Device::create(const BufferCreateInfo& createInfo, Buffer** ppBuffer) m_physicalDevice->findMemoryType(createInfo.domain, memRequirements.memoryRequirements.memoryTypeBits), }; - _VR(vkAllocateMemory(getHandle(), &memoryAllocateInfo, nullptr, &memory)); + _VR(vkAllocateMemory(getHandle(), &memoryAllocateInfo, gVkAllocator, &memory)); } else { VkMemoryAllocateInfo allocInfo = init::memoryAllocateInfo( memRequirements.memoryRequirements.size, m_physicalDevice->findMemoryType(createInfo.domain, memRequirements.memoryRequirements.memoryTypeBits)); - _VR(vkAllocateMemory(m_handle, &allocInfo, nullptr, &memory)); + _VR(vkAllocateMemory(m_handle, &allocInfo, gVkAllocator, &memory)); } *ppBuffer = new Buffer(createInfo, buffer, memory); @@ -288,7 +290,7 @@ VkResult Device::create(const ImageCreateInfo& createInfo, Image** ppImage) imageCreateInfo.extent.depth = createInfo.extent.depth; VkImage image; - _VR(m_table.vkCreateImage(m_handle, &imageCreateInfo, nullptr, &image)); + _VR(m_table.vkCreateImage(m_handle, &imageCreateInfo, gVkAllocator, &image)); VkMemoryDedicatedRequirementsKHR dedicatedRequirements = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, @@ -320,7 +322,7 @@ VkResult Device::create(const ImageCreateInfo& createInfo, Image** ppImage) m_physicalDevice->findMemoryType(createInfo.domain, memRequirements.memoryRequirements.memoryTypeBits), }; - _VR(vkAllocateMemory(getHandle(), &memoryAllocateInfo, nullptr, &memory)); + _VR(vkAllocateMemory(getHandle(), &memoryAllocateInfo, gVkAllocator, &memory)); } else { @@ -331,7 +333,7 @@ VkResult Device::create(const ImageCreateInfo& createInfo, Image** ppImage) m_physicalDevice->findMemoryType(createInfo.domain, memRequirements.memoryRequirements.memoryTypeBits), }; - _VR(vkAllocateMemory(m_handle, &allocInfo, nullptr, &memory)); + _VR(vkAllocateMemory(m_handle, &allocInfo, gVkAllocator, &memory)); } *ppImage = new Image(this, createInfo, image, memory); @@ -348,9 +350,9 @@ void Device::destroy(Buffer* pBuffer) { if(pBuffer->getMemory() != VK_NULL_HANDLE) { - vkFreeMemory(m_handle, pBuffer->getMemory(), nullptr); + vkFreeMemory(m_handle, pBuffer->getMemory(), gVkAllocator); } - vkDestroyBuffer(m_handle, pBuffer->getHandle(), nullptr); + vkDestroyBuffer(m_handle, pBuffer->getHandle(), gVkAllocator); delete pBuffer; pBuffer = nullptr; } @@ -359,16 +361,16 @@ void Device::destroy(Image* pImage) { if(pImage->getMemory() != VK_NULL_HANDLE) { - vkFreeMemory(m_handle, pImage->getMemory(), nullptr); + vkFreeMemory(m_handle, pImage->getMemory(), gVkAllocator); } - vkDestroyImage(m_handle, pImage->getHandle(), nullptr); + vkDestroyImage(m_handle, pImage->getHandle(), gVkAllocator); delete pImage; pImage = nullptr; } void Device::destroy(ImageView* pImageView) { - vkDestroyImageView(m_handle, pImageView->getHandle(), nullptr); + vkDestroyImageView(m_handle, pImageView->getHandle(), gVkAllocator); delete pImageView; pImageView = nullptr; } @@ -381,7 +383,7 @@ VkResult Device::create(const SwapChainCreateInfo& createInfo, SwapChain** ppSwa void Device::destroy(SwapChain* pSwapchain) { - vkDestroySwapchainKHR(getHandle(), pSwapchain->getHandle(), nullptr); + vkDestroySwapchainKHR(getHandle(), pSwapchain->getHandle(), gVkAllocator); delete pSwapchain; pSwapchain = nullptr; } @@ -419,7 +421,7 @@ VkCommandPool Device::getCommandPoolWithQueue(Queue* queue) void Device::destroy(VkCommandPool pPool) { - vkDestroyCommandPool(getHandle(), pPool, nullptr); + vkDestroyCommandPool(getHandle(), pPool, gVkAllocator); pPool = nullptr; } @@ -585,7 +587,7 @@ void Device::destroy(Pipeline* pipeline) { auto program = pipeline->getProgram(); delete program; - m_table.vkDestroyPipeline(getHandle(), pipeline->getHandle(), nullptr); + m_table.vkDestroyPipeline(getHandle(), pipeline->getHandle(), gVkAllocator); delete pipeline; pipeline = nullptr; } @@ -598,7 +600,7 @@ VkResult Device::create(const ComputePipelineCreateInfo& createInfo, Pipeline** ci.stage = init::pipelineShaderStageCreateInfo(VK_SHADER_STAGE_COMPUTE_BIT, program->getShader(ShaderStage::CS)->getHandle()); VkPipeline handle = VK_NULL_HANDLE; - _VR(m_table.vkCreateComputePipelines(this->getHandle(), VK_NULL_HANDLE, 1, &ci, nullptr, &handle)); + _VR(m_table.vkCreateComputePipelines(this->getHandle(), VK_NULL_HANDLE, 1, &ci, gVkAllocator, &handle)); *ppPipeline = new Pipeline(this, createInfo, handle, program); return VK_SUCCESS; } @@ -801,7 +803,7 @@ VkResult Device::create(const SamplerCreateInfo& createInfo, Sampler** ppSampler .forceExplicitReconstruction = convertInfo.forceExplicitReconstruction ? VK_TRUE : VK_FALSE, }; - _VR(vkCreateSamplerYcbcrConversion(getHandle(), &vkConvertInfo, nullptr, &ycbcr.conversion)); + _VR(vkCreateSamplerYcbcrConversion(getHandle(), &vkConvertInfo, gVkAllocator, &ycbcr.conversion)); ycbcr.info.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO; ycbcr.info.pNext = nullptr; @@ -810,14 +812,14 @@ VkResult Device::create(const SamplerCreateInfo& createInfo, Sampler** ppSampler ci.pNext = &ycbcr.info; } - _VR(m_table.vkCreateSampler(getHandle(), &ci, nullptr, &sampler)); + _VR(m_table.vkCreateSampler(getHandle(), &ci, gVkAllocator, &sampler)); *ppSampler = new Sampler(this, createInfo, sampler); return VK_SUCCESS; } void Device::destroy(Sampler* pSampler) { - m_table.vkDestroySampler(getHandle(), pSampler->getHandle(), nullptr); + m_table.vkDestroySampler(getHandle(), pSampler->getHandle(), gVkAllocator); delete pSampler; pSampler = nullptr; } diff --git a/engine/api/vulkan/instance.cpp b/engine/api/vulkan/instance.cpp index de529958..83dfb048 100644 --- a/engine/api/vulkan/instance.cpp +++ b/engine/api/vulkan/instance.cpp @@ -114,7 +114,7 @@ VkResult Instance::Create(const InstanceCreateInfo& createInfo, Instance** ppIns #endif VkInstance handle = VK_NULL_HANDLE; - VK_CHECK_RESULT(vkCreateInstance(&instanceCreateInfo, nullptr, &handle)); + VK_CHECK_RESULT(vkCreateInstance(&instanceCreateInfo, vkAllocator(), &handle)); volkLoadInstance(handle); @@ -165,7 +165,7 @@ VkResult Instance::Create(const InstanceCreateInfo& createInfo, Instance** ppIns #if defined(APH_DEBUG) { VK_CHECK_RESULT( - createDebugUtilsMessengerEXT(handle, &createInfo.debugCreateInfo, nullptr, &instance->m_debugMessenger)); + createDebugUtilsMessengerEXT(handle, &createInfo.debugCreateInfo, vkAllocator(), &instance->m_debugMessenger)); } #endif // Return success. @@ -175,8 +175,8 @@ VkResult Instance::Create(const InstanceCreateInfo& createInfo, Instance** ppIns void Instance::Destroy(Instance* pInstance) { #ifdef APH_DEBUG - destroyDebugUtilsMessengerEXT(pInstance->getHandle(), pInstance->m_debugMessenger, nullptr); + destroyDebugUtilsMessengerEXT(pInstance->getHandle(), pInstance->m_debugMessenger, vkAllocator()); #endif - vkDestroyInstance(pInstance->getHandle(), nullptr); + vkDestroyInstance(pInstance->getHandle(), vkAllocator()); } } // namespace aph::vk diff --git a/engine/api/vulkan/pipeline.cpp b/engine/api/vulkan/pipeline.cpp index ae714e7f..8532ee01 100644 --- a/engine/api/vulkan/pipeline.cpp +++ b/engine/api/vulkan/pipeline.cpp @@ -288,7 +288,7 @@ VkResult VulkanPipelineBuilder::build(VkDevice device, VkPipelineCache pipelineC .basePipelineIndex = -1, }; - const auto result = vkCreateGraphicsPipelines(device, pipelineCache, 1, &ci, nullptr, outPipeline); + const auto result = vkCreateGraphicsPipelines(device, pipelineCache, 1, &ci, vkAllocator(), outPipeline); if(result != VK_SUCCESS) { diff --git a/engine/api/vulkan/shader.cpp b/engine/api/vulkan/shader.cpp index 49a0152a..eb465604 100644 --- a/engine/api/vulkan/shader.cpp +++ b/engine/api/vulkan/shader.cpp @@ -180,7 +180,7 @@ static DescriptorSetLayout* createDescriptorSetLayout(Device* m_pDevice, const S DescriptorSetLayout* setLayout{}; { VkDescriptorSetLayout vkSetLayout; - VK_CHECK_RESULT(m_pDevice->getDeviceTable()->vkCreateDescriptorSetLayout(m_pDevice->getHandle(), &info, nullptr, + VK_CHECK_RESULT(m_pDevice->getDeviceTable()->vkCreateDescriptorSetLayout(m_pDevice->getHandle(), &info, vkAllocator(), &vkSetLayout)); setLayout = new DescriptorSetLayout(m_pDevice, info, vkSetLayout); } @@ -207,7 +207,7 @@ std::unique_ptr Shader::Create(Device* pDevice, const std::filesystem::p }; VkShaderModule handle; - VK_CHECK_RESULT(vkCreateShaderModule(pDevice->getHandle(), &createInfo, nullptr, &handle)); + VK_CHECK_RESULT(vkCreateShaderModule(pDevice->getHandle(), &createInfo, vkAllocator(), &handle)); auto instance = std::unique_ptr(new Shader(std::move(spvCode), handle, entrypoint)); return instance; @@ -579,7 +579,7 @@ void ShaderProgram::createPipelineLayout(const ImmutableSamplerBank* samplerBank #endif auto table = m_pDevice->getDeviceTable(); - if(table->vkCreatePipelineLayout(m_pDevice->getHandle(), &info, nullptr, &m_pipeLayout) != VK_SUCCESS) + if(table->vkCreatePipelineLayout(m_pDevice->getHandle(), &info, vkAllocator(), &m_pipeLayout) != VK_SUCCESS) VK_LOG_ERR("Failed to create pipeline layout."); } @@ -587,10 +587,10 @@ ShaderProgram::~ShaderProgram() { for(auto* setLayout : m_pSetLayouts) { - vkDestroyDescriptorSetLayout(m_pDevice->getHandle(), setLayout->getHandle(), nullptr); + vkDestroyDescriptorSetLayout(m_pDevice->getHandle(), setLayout->getHandle(), vkAllocator()); delete setLayout; } - m_pDevice->getDeviceTable()->vkDestroyPipelineLayout(m_pDevice->getHandle(), m_pipeLayout, nullptr); + m_pDevice->getDeviceTable()->vkDestroyPipelineLayout(m_pDevice->getHandle(), m_pipeLayout, vkAllocator()); } VkShaderStageFlags ShaderProgram::getConstantShaderStage(uint32_t offset, uint32_t size) const { diff --git a/engine/api/vulkan/swapChain.cpp b/engine/api/vulkan/swapChain.cpp index 11c83478..a4240af2 100644 --- a/engine/api/vulkan/swapChain.cpp +++ b/engine/api/vulkan/swapChain.cpp @@ -160,7 +160,7 @@ void SwapChain::reCreate() .oldSwapchain = VK_NULL_HANDLE, }; - VK_CHECK_RESULT(vkCreateSwapchainKHR(m_pDevice->getHandle(), &swapChainCreateInfo, nullptr, &getHandle())); + VK_CHECK_RESULT(vkCreateSwapchainKHR(m_pDevice->getHandle(), &swapChainCreateInfo, vk::vkAllocator(), &getHandle())); m_surfaceFormat = swapChainSupport.preferedSurfaceFormat; m_extent = swapChainSupport.preferedExtent; diff --git a/engine/api/vulkan/syncPrimitivesPool.cpp b/engine/api/vulkan/syncPrimitivesPool.cpp index 11975b3b..36cbeee0 100644 --- a/engine/api/vulkan/syncPrimitivesPool.cpp +++ b/engine/api/vulkan/syncPrimitivesPool.cpp @@ -11,14 +11,14 @@ SyncPrimitivesPool::~SyncPrimitivesPool() { // Destroy all created fences. for(auto* fence : m_allFences) - vkDestroyFence(m_device->getHandle(), fence, nullptr); + vkDestroyFence(m_device->getHandle(), fence, vk::vkAllocator()); // Destroy all created semaphores. for(auto* semaphore : m_allSemaphores) - vkDestroySemaphore(m_device->getHandle(), semaphore, nullptr); + vkDestroySemaphore(m_device->getHandle(), semaphore, vk::vkAllocator()); for(auto* semaphore : m_allTimelineSemahpores) - vkDestroySemaphore(m_device->getHandle(), semaphore, nullptr); + vkDestroySemaphore(m_device->getHandle(), semaphore, vk::vkAllocator()); } VkResult SyncPrimitivesPool::acquireFence(VkFence& fence, bool isSignaled) @@ -41,7 +41,7 @@ VkResult SyncPrimitivesPool::acquireFence(VkFence& fence, bool isSignaled) { createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; } - result = vkCreateFence(m_device->getHandle(), &createInfo, nullptr, &fence); + result = vkCreateFence(m_device->getHandle(), &createInfo, vk::vkAllocator(), &fence); if(result == VK_SUCCESS) m_allFences.emplace(fence); } @@ -95,7 +95,7 @@ VkResult SyncPrimitivesPool::acquireSemaphore(uint32_t semaphoreCount, VkSemapho { VkSemaphoreCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - result = vkCreateSemaphore(m_device->getHandle(), &createInfo, nullptr, &pSemaphores[i]); + result = vkCreateSemaphore(m_device->getHandle(), &createInfo, vk::vkAllocator(), &pSemaphores[i]); if(result != VK_SUCCESS) break; @@ -158,7 +158,7 @@ VkResult SyncPrimitivesPool::acquireTimelineSemaphore(uint32_t semaphoreCount, V .pNext = &timelineCreateInfo, .flags = 0, }; - result = vkCreateSemaphore(m_device->getHandle(), &createInfo, nullptr, &pSemaphores[i]); + result = vkCreateSemaphore(m_device->getHandle(), &createInfo, vk::vkAllocator(), &pSemaphores[i]); if(result != VK_SUCCESS) { break; diff --git a/engine/api/vulkan/vkUtils.cpp b/engine/api/vulkan/vkUtils.cpp index cd6d4382..1eabb6dc 100644 --- a/engine/api/vulkan/vkUtils.cpp +++ b/engine/api/vulkan/vkUtils.cpp @@ -101,7 +101,7 @@ std::vector loadGlslFromFile(const std::string& filename) { shaderc::Compiler compiler{}; std::string source; - auto success = aph::utils::readFile(filename, source); + auto success = aph::utils::readFile(filename, source); APH_ASSERT(success); shaderc_shader_kind stage = shaderc_glsl_infer_from_source; switch(getStageFromPath(filename)) @@ -149,7 +149,7 @@ std::vector loadGlslFromFile(const std::string& filename) std::vector loadSpvFromFile(const std::string& filename) { std::string source; - auto success = aph::utils::readFile(filename, source); + auto success = aph::utils::readFile(filename, source); APH_ASSERT(success); uint32_t size = source.size(); std::vector spirv(size / sizeof(uint32_t)); @@ -232,4 +232,80 @@ VkDebugUtilsLabelEXT VkCast(const DebugLabel& label) return vkLabel; } + } // namespace aph::vk::utils + +namespace aph::vk +{ + +#include + +#ifndef _MSC_VER + #include + #define MAX_ALIGN alignof(max_align_t) +#else +/* long double might be 128-bit, but our callers do not need that anyway(?) */ + #include + #define MAX_ALIGN alignof(uint64_t) +#endif + + +static VKAPI_ATTR void* VKAPI_CALL vkDefaultAlloc(void* pUserData, size_t size, size_t alignment, + VkSystemAllocationScope allocationScope) +{ + APH_ASSERT(MAX_ALIGN % alignment == 0); + return malloc(size); +} + +static VKAPI_ATTR void* VKAPI_CALL vkDefaultRealloc(void* pUserData, void* pOriginal, size_t size, size_t alignment, + VkSystemAllocationScope allocationScope) +{ + APH_ASSERT(MAX_ALIGN % alignment == 0); + return realloc(pOriginal, size); +} + +static VKAPI_ATTR void VKAPI_CALL vkDefaultFree(void* pUserData, void* pMemory) +{ + free(pMemory); +} + +// #include "mmgr.h" +static VKAPI_ATTR void* VKAPI_CALL vkMMgrAlloc(void* pUserData, size_t size, size_t alignment, + VkSystemAllocationScope allocationScope) +{ + VK_LOG_DEBUG("vulkan object alloc, size: %z, align: %z", size, alignment); + APH_ASSERT(MAX_ALIGN % alignment == 0); + return malloc(size); +} + +static VKAPI_ATTR void* VKAPI_CALL vkMMgrRealloc(void* pUserData, void* pOriginal, size_t size, size_t alignment, + VkSystemAllocationScope allocationScope) +{ + VK_LOG_DEBUG("vulkan object realloc, size: %z, align: %z", size, alignment); + APH_ASSERT(MAX_ALIGN % alignment == 0); + return realloc(pOriginal, size); +} + +static VKAPI_ATTR void VKAPI_CALL vkMMgrFree(void* pUserData, void* pMemory) +{ + VK_LOG_DEBUG("vulkan object free, addr: %z", (size_t)pMemory); + free(pMemory); +} + +#define MMGR_ALLOC +const VkAllocationCallbacks* vkAllocator() +{ + static const VkAllocationCallbacks allocator = { + #ifdef MMGR_ALLOC + .pfnAllocation = vkMMgrAlloc, + .pfnReallocation = vkMMgrRealloc, + .pfnFree = vkMMgrFree, + #else + .pfnAllocation = vkDefaultAlloc, + .pfnReallocation = vkDefaultRealloc, + .pfnFree = vkDefaultFree, + #endif + }; + return &allocator; +} +} // namespace aph::vk diff --git a/engine/api/vulkan/vkUtils.h b/engine/api/vulkan/vkUtils.h index 934ea54f..c181aa6d 100644 --- a/engine/api/vulkan/vkUtils.h +++ b/engine/api/vulkan/vkUtils.h @@ -70,4 +70,10 @@ constexpr unsigned VULKAN_NUM_SETS_PER_POOL = 16; constexpr unsigned VULKAN_DESCRIPTOR_RING_SIZE = 8; } // namespace aph +namespace aph::vk +{ +const VkAllocationCallbacks* vkAllocator(); +const VkAllocationCallbacks* vkMMgrAllocator(); +} + #endif // VKLUTILS_H_ diff --git a/engine/renderer/api/vulkan/renderer.cpp b/engine/renderer/api/vulkan/renderer.cpp index d2595bdf..fcd9b41d 100644 --- a/engine/renderer/api/vulkan/renderer.cpp +++ b/engine/renderer/api/vulkan/renderer.cpp @@ -168,7 +168,7 @@ Renderer::Renderer(WSI* wsi, const RenderConfig& config) : IRenderer(wsi, config { VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO}; VK_CHECK_RESULT(m_pDevice->getDeviceTable()->vkCreatePipelineCache( - m_pDevice->getHandle(), &pipelineCacheCreateInfo, nullptr, &m_pipelineCache)); + m_pDevice->getHandle(), &pipelineCacheCreateInfo, vkAllocator(), &m_pipelineCache)); } } @@ -329,13 +329,13 @@ Renderer::~Renderer() for(const auto& [_, shaderModule] : shaderModuleCaches) { - vkDestroyShaderModule(m_pDevice->getHandle(), shaderModule->getHandle(), nullptr); + vkDestroyShaderModule(m_pDevice->getHandle(), shaderModule->getHandle(), vk::vkAllocator()); } - vkDestroyPipelineCache(m_pDevice->getHandle(), m_pipelineCache, nullptr); + vkDestroyPipelineCache(m_pDevice->getHandle(), m_pipelineCache, vkAllocator()); m_pDevice->destroy(m_pSwapChain); - vkDestroySurfaceKHR(m_pInstance->getHandle(), m_surface, nullptr); + vkDestroySurfaceKHR(m_pInstance->getHandle(), m_surface, vk::vkAllocator()); Device::Destroy(m_pDevice.get()); Instance::Destroy(m_pInstance); };