Create image descriptors

With the images created, we will need to fill the descriptor set with sampler image descriptors for use in our shaders. In order to do so, we will need to create a VkSampler, a VkImageView and then update a descriptor set entry with both items. The descriptor set is bound to the command list when rendering, and the created descriptors are indexed using an index in the shader.

VkSampler sampler;
result = vkCreateSampler (
    renderer->device,
    &(VkSamplerCreateInfo){
        .sType                   = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
        .pNext                   = NULL,
        .flags                   = 0,
        .magFilter               = VK_FILTER_LINEAR,
        .minFilter               = VK_FILTER_LINEAR,
        .mipmapMode              = VK_SAMPLER_MIPMAP_MODE_LINEAR,
        .addressModeU            = VK_SAMPLER_ADDRESS_MODE_REPEAT,
        .addressModeV            = VK_SAMPLER_ADDRESS_MODE_REPEAT,
        .addressModeW            = VK_SAMPLER_ADDRESS_MODE_REPEAT,
        .mipLodBias              = 0.0f,
        .anisotropyEnable        = VK_TRUE,
        .maxAnisotropy           = 16.0f,
        .compareEnable           = VK_FALSE,
        .minLod                  = 0.0f,
        .maxLod                  = VK_LOD_CLAMP_NONE,
        .unnormalizedCoordinates = VK_FALSE,
    },
    NULL,
    &sampler
);
if ( result != VK_SUCCESS )
    RETURN_ERROR(-1, "vkCreateSampler failed (0x%08X)", (uint32_t)result);

VkImageView imageView;
result = vkCreateImageView (
    renderer->device,
    &(VkImageViewCreateInfo){
        .sType            = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
        .pNext            = NULL,
        .flags            = 0,
        .image            = image,
        .viewType         = VK_IMAGE_VIEW_TYPE_2D,
        .format           = VK_FORMAT_R8G8B8A8_UNORM,
        //.components       = , // NOTE(Rick): Components all maps to VK_COMPONENT_SWIZZLE_IDENTITY
        .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .levelCount = imageDesc->mipCount, .layerCount = 1 },
    },
    NULL,
    &imageView
);
if ( result != VK_SUCCESS )
    RETURN_ERROR(-1, "vkCreateImageView failed (0x%08X)", (uint32_t)result);

vkUpdateDescriptorSets (
    renderer->device,
    1,
    (VkWriteDescriptorSet[1]){
        [0] = {
            .sType            = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
            .pNext            = NULL,
            .dstSet           = renderer->descriptorSet,
            .dstArrayElement  = i,
            .descriptorCount  = 1,
            .descriptorType   = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
            .pImageInfo       = (VkDescriptorImageInfo[1]){
                [0] = {
                    .sampler     = sampler,
                    .imageView   = imageView,
                    .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
                },
            },
        },
    },
    0,
    NULL
);