Skip to content

Commit c613b0e

Browse files
committed
use designated initializers and use explicit array types
1 parent 017a919 commit c613b0e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

en/06_Texture_mapping/02_Combined_image_sampler.adoc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ We'll simply put it in the binding after the uniform buffer:
2020

2121
[,c++]
2222
----
23-
std::array bindings = {
23+
std::array<vk::DescriptorSetLayoutBinding, 2> bindings = {
2424
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex, nullptr),
2525
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment, nullptr)
2626
};
2727
28-
vk::DescriptorSetLayoutCreateInfo layoutInfo({}, bindings.size(), bindings.data());
28+
vk::DescriptorSetLayoutCreateInfo layoutInfo { .bindingCount = static_cast<uint32_t>(bindings.size()),
29+
.pBindings = bindings.data() };
2930
----
3031

3132
Make sure to set the `stageFlags` to indicate that we intend to use the combined image sampler descriptor in the fragment shader.
@@ -37,11 +38,15 @@ Go to the `createDescriptorPool` function and modify it to include a `VkDescript
3738

3839
[,c++]
3940
----
40-
std::array poolSize {
41+
std::array<vk::DescriptorPoolSize, 2> poolSize {
4142
vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, MAX_FRAMES_IN_FLIGHT),
4243
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, MAX_FRAMES_IN_FLIGHT)
4344
};
44-
vk::DescriptorPoolCreateInfo poolInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, MAX_FRAMES_IN_FLIGHT, poolSize);
45+
46+
vk::DescriptorPoolCreateInfo poolInfo { .flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
47+
.maxSets = MAX_FRAMES_IN_FLIGHT,
48+
.poolSizeCount = static_cast<uint32_t>(poolSize.size()),
49+
.pPoolSizes = poolSize.data() };
4550
----
4651

4752
Inadequate descriptor pools are a good example of a problem that the validation layers will not catch: As of Vulkan 1.1, `vkAllocateDescriptorSets` may fail with the error code `VK_ERROR_POOL_OUT_OF_MEMORY` if the pool is not sufficiently large, but the driver may also try to solve the problem internally.
@@ -70,9 +75,9 @@ This is where the objects from the previous chapter come together.
7075

7176
[,c++]
7277
----
73-
std::array descriptorWrites{
78+
std::array<vk::WriteDescriptorSet, 2> descriptorWrites {
7479
vk::WriteDescriptorSet( descriptorSets[i], 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
75-
vk::WriteDescriptorSet( descriptorSets[i], 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo)
80+
vk::WriteDescriptorSet( descriptorSets[i], 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo )
7681
};
7782
device.updateDescriptorSets(descriptorWrites, {});
7883
----

0 commit comments

Comments
 (0)