21 VkDeviceSize size = 0;
23 std::vector<VkDeviceSize> offsetBuffers(
_buffers.size());
24 for (uint32_t i = 0; i <
_buffers.size(); ++i) {
31 offsetBuffers[i] = size;
35 std::vector<VkDeviceSize> offsetImages(
_images.size());
36 for (uint32_t i = 0; i <
_images.size(); ++i) {
43 offsetImages[i] = size;
48 const VkMemoryAllocateInfo createInfo{
49 VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
56 VkDeviceMemory vkDeviceMemory{VK_NULL_HANDLE};
57 VkResult result = vkAllocateMemory(static_cast<VkDevice>(
_device), &createInfo,
nullptr, &vkDeviceMemory);
60 *returnResult = result;
63 if (result != VK_SUCCESS) {
70 for (uint32_t i = 0; i <
_buffers.size(); ++i) {
71 _buffers[i]->bindMemory(deviceMemory, offsetBuffers[i]);
75 for (uint32_t i = 0; i <
_images.size(); ++i) {
76 _images[i]->bindMemory(deviceMemory, offsetImages[i]);
83 std::unique_ptr<API::DeviceMemory> buffer = std::make_unique<API::DeviceMemory>();
84 return build(*buffer, returnResult) ? std::move(buffer) :
nullptr;
112 for (uint32_t i = 0; i < physicalDeviceInfo->
memoryProperties.memoryTypeCount; i++) {
113 if (memoryTypeBits & (1 << i)) {
114 const VkMemoryType& type = physicalDeviceInfo->
memoryProperties.memoryTypes[i];
116 if (type.propertyFlags & requiredFlags) {
VkPhysicalDeviceMemoryProperties memoryProperties
std::vector< API::Image * > _images
bool build(API::DeviceMemory &instance, VkResult *returnResult=nullptr)
const Renderer::Requirements requirements
const VkMemoryRequirements & getRequirements() const
const API::Device & _device
const VkMemoryRequirements & getRequirements() const
const PhysicalDeviceInfo * getPhysicalDeviceInfo() const
static uint32_t findMemoryType(const API::Device &device, uint32_t memoryTypeBits, VkMemoryPropertyFlags requiredFlags)
bool addBuffer(API::Buffer &buffer)
bool addImage(API::Image &image)
VkMemoryPropertyFlags _memoryFlags
std::vector< API::Buffer * > _buffers
DeviceMemory(const API::Device &deviceMemory)