Use allocation size returned by image memory requirements for font image (Fixes #217)

This commit is contained in:
saschawillems 2016-08-22 12:57:40 +02:00
parent a104110b30
commit 81fc142053
2 changed files with 3 additions and 2 deletions

View file

@ -197,7 +197,7 @@ public:
VkMemoryRequirements memReqs;
VkMemoryAllocateInfo allocInfo = vkTools::initializers::memoryAllocateInfo();
vkGetImageMemoryRequirements(vulkanDevice->logicalDevice, image, &memReqs);
allocInfo.allocationSize = STB_FONT_WIDTH * STB_NUM_CHARS;
allocInfo.allocationSize = memReqs.size;
allocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VK_CHECK_RESULT(vkAllocateMemory(vulkanDevice->logicalDevice, &allocInfo, nullptr, &imageMemory));
VK_CHECK_RESULT(vkBindImageMemory(vulkanDevice->logicalDevice, image, imageMemory, 0));
@ -212,7 +212,7 @@ public:
allocInfo.allocationSize));
stagingBuffer.map();
memcpy(stagingBuffer.mapped, &font24pixels[0][0], STB_FONT_WIDTH * STB_FONT_HEIGHT);
memcpy(stagingBuffer.mapped, &font24pixels[0][0], STB_FONT_WIDTH * STB_FONT_HEIGHT); // Only one channel, so data size = W * H (*R8)
stagingBuffer.unmap();
// Copy to image

View file

@ -234,6 +234,7 @@ public:
uint8_t *data;
VK_CHECK_RESULT(vkMapMemory(vulkanDevice->logicalDevice, stagingBuffer.memory, 0, allocInfo.allocationSize, 0, (void **)&data));
// Size of the font texture is WIDTH * HEIGHT * 1 byte (only one channel)
memcpy(data, &font24pixels[0][0], STB_FONT_WIDTH * STB_FONT_HEIGHT);
vkUnmapMemory(vulkanDevice->logicalDevice, stagingBuffer.memory);