Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMemoryRequirementsForBuffer/Image functions #809

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nbl/system/CColoredStdoutLoggerWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions include/nbl/video/ILogicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
36 changes: 36 additions & 0 deletions src/nbl/video/CVulkanLogicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,42 @@ m_vkdev(vkdev), m_devf(vkdev), m_deferred_op_mempool(NODES_PER_BLOCK_DEFERRED_OP
}
}

template <typename T>
static IDeviceMemoryBacked::SDeviceMemoryRequirements getMemoryRequirements_impl(const CVulkanLogicalDevice* device, const T* resource)
{
constexpr bool IsImage = std::is_same_v<CVulkanImage, T>;

const std::conditional_t<IsImage, VkImageMemoryRequirementsInfo2, VkBufferMemoryRequirementsInfo2> 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<const CVulkanBuffer*>(buf));
}

IDeviceMemoryBacked::SDeviceMemoryRequirements CVulkanLogicalDevice::getMemoryRequirementsForImage(const IGPUImage* img) const
{
return getMemoryRequirements_impl(this, static_cast<const CVulkanImage*>(img));
}


core::smart_refctd_ptr<ISemaphore> CVulkanLogicalDevice::createSemaphore(const uint64_t initialValue)
{
Expand Down
3 changes: 3 additions & 0 deletions src/nbl/video/CVulkanLogicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class CVulkanLogicalDevice final : public ILogicalDevice

CVulkanLogicalDevice(core::smart_refctd_ptr<const IAPIConnection>&& 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<ISemaphore> createSemaphore(const uint64_t initialValue) override;
ISemaphore::WAIT_RESULT waitForSemaphores(const std::span<const ISemaphore::SWaitInfo> infos, const bool waitAll, const uint64_t timeout) override;
Expand Down