From f4b1ceedf13c036f0a2f85fc796fb1e79fbb233d Mon Sep 17 00:00:00 2001 From: JackP Date: Fri, 10 Oct 2025 21:01:58 -0700 Subject: [PATCH 1/3] Use aggregate initialization --- en/06_Texture_mapping/00_Images.adoc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/en/06_Texture_mapping/00_Images.adoc b/en/06_Texture_mapping/00_Images.adoc index 516437fb..6e7a77df 100644 --- a/en/06_Texture_mapping/00_Images.adoc +++ b/en/06_Texture_mapping/00_Images.adoc @@ -153,7 +153,9 @@ The parameters for an image are specified in a `VkImageCreateInfo` struct: [,c++] ---- -vk::ImageCreateInfo imageInfo( {}, vk::ImageType::e2D, format, {width, height, 1}, 1, 1, vk::SampleCountFlagBits::e1, tiling, usage, vk::SharingMode::eExclusive, 0); +vk::ImageCreateInfo imageInfo{ .imageType = vk::ImageType::e2D, .format = format, + .extent = {width, height, 1}, .mipLevels = 1, .arrayLayers = 1, .samples = vk::SampleCountFlagBits::e1, + .tiling = tiling, .usage = usage, .sharingMode = vk::SharingMode::eExclusive}; ---- The image type, specified in the `imageType` field, tells Vulkan with what kind of coordinate system the texels in the image are going to be addressed. @@ -227,12 +229,16 @@ Create the function and move the image object creation and memory allocation to [,c++] ---- void createImage(uint32_t width, uint32_t height, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags usage, vk::MemoryPropertyFlags properties, vk::raii::Image& image, vk::raii::DeviceMemory& imageMemory) { - vk::ImageCreateInfo imageInfo( {}, vk::ImageType::e2D, format, {width, height, 1}, 1, 1, vk::SampleCountFlagBits::e1, tiling, usage, vk::SharingMode::eExclusive, 0); + vk::ImageCreateInfo imageInfo{ .imageType = vk::ImageType::e2D, .format = format, + .extent = {width, height, 1}, .mipLevels = 1, .arrayLayers = 1, + .samples = vk::SampleCountFlagBits::e1, .tiling = tiling, + .usage = usage, .sharingMode = vk::SharingMode::eExclusive }; image = vk::raii::Image( device, imageInfo ); vk::MemoryRequirements memRequirements = image.getMemoryRequirements(); - vk::MemoryAllocateInfo allocInfo( memRequirements.size, findMemoryType(memRequirements.memoryTypeBits, properties) ); + vk::MemoryAllocateInfo allocInfo{ .allocationSize = memRequirements.size, + .memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties) }; imageMemory = vk::raii::DeviceMemory( device, allocInfo ); image.bindMemory(imageMemory, 0); } From 033c51fc473496d57495ca0663f47b9ed603dd4f Mon Sep 17 00:00:00 2001 From: JackP Date: Sat, 11 Oct 2025 11:23:24 -0700 Subject: [PATCH 2/3] Use aggregate initialization to match demo code and the rest of the tutorial. Modify text to explain the aggregate initialization. --- en/06_Texture_mapping/00_Images.adoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/en/06_Texture_mapping/00_Images.adoc b/en/06_Texture_mapping/00_Images.adoc index 6e7a77df..ce752092 100644 --- a/en/06_Texture_mapping/00_Images.adoc +++ b/en/06_Texture_mapping/00_Images.adoc @@ -292,10 +292,10 @@ The function we're going to write now involves recording and executing a command [,c++] ---- vk::raii::CommandBuffer beginSingleTimeCommands() { - vk::CommandBufferAllocateInfo allocInfo(commandPool, vk::CommandBufferLevel::ePrimary, 1); + vk::CommandBufferAllocateInfo allocInfo{ .commandPool = commandPool, .level = vk::CommandBufferLevel::ePrimary, .commandBufferCount = 1 }; vk::raii::CommandBuffer commandBuffer = std::move(device.allocateCommandBuffers(allocInfo).front()); - vk::CommandBufferBeginInfo beginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit ); + vk::CommandBufferBeginInfo beginInfo{ .flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit }; commandBuffer.begin(beginInfo); return commandBuffer; @@ -304,7 +304,7 @@ vk::raii::CommandBuffer beginSingleTimeCommands() { void endSingleTimeCommands(vk::raii::CommandBuffer& commandBuffer) { commandBuffer.end(); - vk::SubmitInfo submitInfo( {}, {}, {*commandBuffer}); + vk::SubmitInfo submitInfo{ .commandBufferCount = 1, .pCommandBuffers = &*commandBuffer }; graphicsQueue.submit(submitInfo, nullptr); graphicsQueue.waitIdle(); } @@ -340,13 +340,12 @@ There is an equivalent _buffer memory barrier_ to do this for buffers. [,c++] ---- -vk::ImageMemoryBarrier barrier( {}, {}, oldLayout, newLayout, {}, {}, image, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } ); +vk::ImageMemoryBarrier barrier{ .oldLayout = oldLayout, .newLayout = newLayout, .image = image, .subresourceRange = { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } }; ---- - -The first two fields specify layout transition. +`oldLayout` and `newLayout` specify the the layout transition. It is possible to use `VK_IMAGE_LAYOUT_UNDEFINED` as `oldLayout` if you don't care about the existing contents of the image. -If you are using the barrier to transfer queue family ownership, then these two fields should be the indices of the queue families. +If you are using the barrier to transfer queue family ownership, then `oldLayout` and `newLayout` fields should be the indices of the queue families. They must be set to `VK_QUEUE_FAMILY_IGNORED` if you don't want to do this (not the default value!). The `image` and `subresourceRange` specify the image that is affected and the specific part of the image. @@ -394,7 +393,8 @@ This happens through `VkBufferImageCopy` structs: [,c++] ---- -vk::BufferImageCopy region( 0, 0, 0, { vk::ImageAspectFlagBits::eColor, 0, 0, 1 }, {0, 0, 0}, {width, height, 1}); +vk::BufferImageCopy region{ .bufferOffset = 0, .bufferRowLength = 0, .bufferImageHeight = 0, + .imageSubresource = { vk::ImageAspectFlagBits::eColor, 0, 0, 1 }, .imageOffset = {0, 0, 0}, .imageExtent = {width, height, 1} }; ---- Most of these fields are self-explanatory. From 8c01b457548bce606244a63b189017de8f0a3954 Mon Sep 17 00:00:00 2001 From: JackP Date: Sat, 11 Oct 2025 11:27:11 -0700 Subject: [PATCH 3/3] Reduced indentation --- en/06_Texture_mapping/00_Images.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/en/06_Texture_mapping/00_Images.adoc b/en/06_Texture_mapping/00_Images.adoc index ce752092..51d67175 100644 --- a/en/06_Texture_mapping/00_Images.adoc +++ b/en/06_Texture_mapping/00_Images.adoc @@ -230,9 +230,9 @@ Create the function and move the image object creation and memory allocation to ---- void createImage(uint32_t width, uint32_t height, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags usage, vk::MemoryPropertyFlags properties, vk::raii::Image& image, vk::raii::DeviceMemory& imageMemory) { vk::ImageCreateInfo imageInfo{ .imageType = vk::ImageType::e2D, .format = format, - .extent = {width, height, 1}, .mipLevels = 1, .arrayLayers = 1, - .samples = vk::SampleCountFlagBits::e1, .tiling = tiling, - .usage = usage, .sharingMode = vk::SharingMode::eExclusive }; + .extent = {width, height, 1}, .mipLevels = 1, .arrayLayers = 1, + .samples = vk::SampleCountFlagBits::e1, .tiling = tiling, + .usage = usage, .sharingMode = vk::SharingMode::eExclusive }; image = vk::raii::Image( device, imageInfo );