diff --git a/include/nbl/system/CColoredStdoutLoggerWin32.h b/include/nbl/system/CColoredStdoutLoggerWin32.h index 6f3bbd1eb..f6a9be188 100644 --- a/include/nbl/system/CColoredStdoutLoggerWin32.h +++ b/include/nbl/system/CColoredStdoutLoggerWin32.h @@ -10,6 +10,7 @@ class NBL_API2 CColoredStdoutLoggerWin32 : public IThreadsafeLogger { void* m_native_console; + protected: void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override; inline int getConsoleColor(E_LOG_LEVEL level) diff --git a/include/nbl/video/ILogicalDevice.h b/include/nbl/video/ILogicalDevice.h index 276ed7450..62dfe67e9 100644 --- a/include/nbl/video/ILogicalDevice.h +++ b/include/nbl/video/ILogicalDevice.h @@ -45,6 +45,9 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe }; + virtual IDeviceMemoryBacked::SDeviceMemoryRequirements getMemoryRequirementsForBuffer(const IGPUBuffer*) const = 0; + virtual IDeviceMemoryBacked::SDeviceMemoryRequirements getMemoryRequirementsForImage(const IGPUImage*) const = 0; + //! Basic getters inline const IPhysicalDevice* getPhysicalDevice() const { return m_physicalDevice; } diff --git a/src/nbl/video/CVulkanLogicalDevice.cpp b/src/nbl/video/CVulkanLogicalDevice.cpp index cc96eb6e5..203910ec9 100644 --- a/src/nbl/video/CVulkanLogicalDevice.cpp +++ b/src/nbl/video/CVulkanLogicalDevice.cpp @@ -54,6 +54,42 @@ m_vkdev(vkdev), m_devf(vkdev), m_deferred_op_mempool(NODES_PER_BLOCK_DEFERRED_OP } } +template +static IDeviceMemoryBacked::SDeviceMemoryRequirements getMemoryRequirements_impl(const CVulkanLogicalDevice* device, const T* resource) +{ + constexpr bool IsImage = std::is_same_v; + + const std::conditional_t vk_memoryRequirementsInfo = { + IsImage ? VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2 : VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,nullptr,resource->getInternalObject() + }; + + VkMemoryDedicatedRequirements vk_dedicatedMemoryRequirements = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,nullptr }; + VkMemoryRequirements2 vk_memoryRequirements = { VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,&vk_dedicatedMemoryRequirements }; + const auto& vk = device->getFunctionTable()->vk; + if constexpr (IsImage) + vk.vkGetImageMemoryRequirements2(device->getInternalObject(), &vk_memoryRequirementsInfo, &vk_memoryRequirements); + else + vk.vkGetBufferMemoryRequirements2(device->getInternalObject(), &vk_memoryRequirementsInfo, &vk_memoryRequirements); + + IDeviceMemoryBacked::SDeviceMemoryRequirements memoryReqs = {}; + memoryReqs.size = vk_memoryRequirements.memoryRequirements.size; + memoryReqs.memoryTypeBits = vk_memoryRequirements.memoryRequirements.memoryTypeBits; + memoryReqs.alignmentLog2 = std::log2(vk_memoryRequirements.memoryRequirements.alignment); + memoryReqs.prefersDedicatedAllocation = vk_dedicatedMemoryRequirements.prefersDedicatedAllocation; + memoryReqs.requiresDedicatedAllocation = vk_dedicatedMemoryRequirements.requiresDedicatedAllocation; + return memoryReqs; +} + +IDeviceMemoryBacked::SDeviceMemoryRequirements CVulkanLogicalDevice::getMemoryRequirementsForBuffer(const IGPUBuffer* buf) const +{ + return getMemoryRequirements_impl(this, static_cast(buf)); +} + +IDeviceMemoryBacked::SDeviceMemoryRequirements CVulkanLogicalDevice::getMemoryRequirementsForImage(const IGPUImage* img) const +{ + return getMemoryRequirements_impl(this, static_cast(img)); +} + core::smart_refctd_ptr CVulkanLogicalDevice::createSemaphore(const uint64_t initialValue) { diff --git a/src/nbl/video/CVulkanLogicalDevice.h b/src/nbl/video/CVulkanLogicalDevice.h index 410efe5d8..c8030cae6 100644 --- a/src/nbl/video/CVulkanLogicalDevice.h +++ b/src/nbl/video/CVulkanLogicalDevice.h @@ -46,6 +46,9 @@ class CVulkanLogicalDevice final : public ILogicalDevice CVulkanLogicalDevice(core::smart_refctd_ptr&& api, renderdoc_api_t* const rdoc, const IPhysicalDevice* const physicalDevice, const VkDevice vkdev, const SCreationParams& params); + IDeviceMemoryBacked::SDeviceMemoryRequirements getMemoryRequirementsForBuffer(const IGPUBuffer*) const override; + IDeviceMemoryBacked::SDeviceMemoryRequirements getMemoryRequirementsForImage(const IGPUImage*) const override; + // sync stuff core::smart_refctd_ptr createSemaphore(const uint64_t initialValue) override; ISemaphore::WAIT_RESULT waitForSemaphores(const std::span infos, const bool waitAll, const uint64_t timeout) override;