40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
|
|
#include "iwa/device_memory.hpp"
|
|
|
|
#include "iwa/device.hpp"
|
|
|
|
namespace iwa
|
|
{
|
|
DeviceMemory::DeviceMemory(ObjectPtr<Device> owner, const DeviceMemoryAllocationArgs& args) : super_t(std::move(owner))
|
|
{
|
|
mHandle = getOwner()->getVkHandle().allocateMemory(vk::MemoryAllocateInfo
|
|
{
|
|
.allocationSize = args.allocationSize,
|
|
.memoryTypeIndex = args.memoryTypeIndex
|
|
});
|
|
}
|
|
|
|
DeviceMemory::~DeviceMemory() noexcept
|
|
{
|
|
IWA_DELETE_DEVICE_OBJECT(getOwner(), mHandle, freeMemory);
|
|
}
|
|
|
|
std::optional<std::uint32_t> findMemoryType(Device& device, const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags properties)
|
|
{
|
|
const vk::PhysicalDeviceMemoryProperties& memoryProperties = device.getDeviceInfo().memoryProperties;
|
|
|
|
for (std::uint32_t idx = 0; idx < memoryProperties.memoryTypeCount; ++idx)
|
|
{
|
|
if ((requirements.memoryTypeBits & (1 << idx)) == 0) {
|
|
continue; // not suitable for this buffer
|
|
}
|
|
if ((memoryProperties.memoryTypes[idx].propertyFlags & properties) != properties) {
|
|
continue; // does not fulfill required properties
|
|
}
|
|
return idx;
|
|
}
|
|
|
|
return std::nullopt;
|
|
}
|
|
} // namespace iwa
|