@@ -99,7 +99,7 @@ This will leave each level of the texture image in `VK_IMAGE_LAYOUT_TRANSFER_DST
9999We're now going to write the function generates the mipmaps:
100100
101101```c++
102- void generateMipmaps(int32_t texWidth, int32_t texHeight) {
102+ void generateMipmaps(VkImage image, int32_t texWidth, int32_t texHeight, uint32_t mipLevels ) {
103103 VkCommandBuffer commandBuffer = beginSingleTimeCommands();
104104 ...
105105 endSingleTimeCommands(commandBuffer);
@@ -108,11 +108,10 @@ We're now going to write the function generates the mipmaps:
108108
109109Since we can't use ` transitionImageLayout ` , we need to record and submit another ` VkCommandBuffer ` .
110110
111-
112111``` c++
113112 VkImageMemoryBarrier barrier = {};
114113 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
115- barrier.image = textureImage ;
114+ barrier.image = image ;
116115 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
117116 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
118117 barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@@ -170,8 +169,8 @@ Next, we specify the regions that will be used in the blit operation. The source
170169
171170```c++
172171 vkCmdBlitImage(commandBuffer,
173- textureImage , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
174- textureImage , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
172+ image , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
173+ image , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
175174 1, &blit,
176175 VK_FILTER_LINEAR);
177176```
@@ -227,7 +226,11 @@ Before we end the command buffer, we insert one more pipeline barrier. This barr
227226Finally, add the call to `generateMipmaps` in `createTextureImage`:
228227
229228```c++
230- generateMipmaps(texWidth, texHeight);
229+ transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, mipLevels);
230+ copyBufferToImage(stagingBuffer, textureImage, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight));
231+ //transitioned to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL while generating mipmaps
232+ ...
233+ generateMipmaps(textureImage, texWidth, texHeight, mipLevels);
231234```
232235
233236Our texture image's mipmaps are now completely filled.
0 commit comments