Created
April 3, 2022 04:31
-
-
Save yknishidate/9c63688e393c81a00fd5090190fc03a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create images | |
std::vector<vk::Image> images = ...; | |
// gather information | |
uint32_t memoryTypeBits = ~0; // 0b11111111... | |
vk::DeviceSize totalSize = 0; | |
std::vector<vk::DeviceSize> offsets; | |
for (auto&& image : images) { | |
offsets.push_back(totalSize); | |
auto requirements = device->getImageMemoryRequirements(image); | |
memoryTypeBits &= requirements.memoryTypeBits; | |
totalSize += requirements.size; | |
} | |
// find memory type index | |
uint32_t memoryTypeIndex = findMemoryTypeIndex(physicalDevice, memoryTypeBits, vk::MemoryPropertyFlagBits::eDeviceLocal); | |
// allocate memory | |
vk::MemoryAllocateInfo memoryAllocateInfo; | |
memoryAllocateInfo.setAllocationSize(totalSize); | |
memoryAllocateInfo.setMemoryTypeIndex(memoryTypeIndex); | |
vk::DeviceMemory memory = device->allocateMemory(memoryAllocateInfo); | |
// bind memory | |
for (int index = 0; index < images.size(); index++) { | |
device.bindImageMemory(images[index], memory, offsets[index]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment