Proper image layout for descriptor image infos (instead of always GENERAL), code cleanup, comments
This commit is contained in:
parent
5485e77d30
commit
251560845c
4 changed files with 25 additions and 20 deletions
|
|
@ -45,7 +45,6 @@ public:
|
|||
VkImageLayout imageLayout;
|
||||
VkDeviceMemory deviceMemory;
|
||||
VkImageView view;
|
||||
VkDescriptorImageInfo descriptor;
|
||||
uint32_t width, height;
|
||||
uint32_t mipLevels;
|
||||
} texture;
|
||||
|
|
@ -474,7 +473,6 @@ public:
|
|||
// are abstracted by image views containing additional
|
||||
// information and sub resource ranges
|
||||
VkImageViewCreateInfo view = vkTools::initializers::imageViewCreateInfo();
|
||||
view.image = VK_NULL_HANDLE;
|
||||
view.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
view.format = format;
|
||||
view.components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
|
||||
|
|
@ -487,13 +485,9 @@ public:
|
|||
// Linear tiling usually won't support mip maps
|
||||
// Only set mip map count if optimal tiling is used
|
||||
view.subresourceRange.levelCount = (useStaging) ? texture.mipLevels : 1;
|
||||
// The view will be based on the texture's image
|
||||
view.image = texture.image;
|
||||
VK_CHECK_RESULT(vkCreateImageView(device, &view, nullptr, &texture.view));
|
||||
|
||||
// Fill image descriptor image info that can be used during the descriptor set setup
|
||||
texture.descriptor.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
texture.descriptor.imageView = texture.view;
|
||||
texture.descriptor.sampler = texture.sampler;
|
||||
}
|
||||
|
||||
// Free all Vulkan resources used a texture object
|
||||
|
|
@ -700,6 +694,12 @@ public:
|
|||
|
||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||
|
||||
// Setup a descriptor image info for the current texture to be used as a combined image sampler
|
||||
VkDescriptorImageInfo textureDescriptor;
|
||||
textureDescriptor.imageView = texture.view; // The image's view (images are never directly accessed by the shader, but rather through views defining subresources)
|
||||
textureDescriptor.sampler = texture.sampler; // The sampler (Telling the pipeline how to sample the texture, including repeat, border, etc.)
|
||||
textureDescriptor.imageLayout = texture.imageLayout; // The current layout of the image (Note: Should always fit the actual use, e.g. shader read)
|
||||
|
||||
std::vector<VkWriteDescriptorSet> writeDescriptorSets =
|
||||
{
|
||||
// Binding 0 : Vertex shader uniform buffer
|
||||
|
|
@ -709,11 +709,12 @@ public:
|
|||
0,
|
||||
&uniformBufferVS.descriptor),
|
||||
// Binding 1 : Fragment shader texture sampler
|
||||
// Fragment shader: layout (binding = 1) uniform sampler2D samplerColor;
|
||||
vkTools::initializers::writeDescriptorSet(
|
||||
descriptorSet,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
1,
|
||||
&texture.descriptor)
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, // The descriptor set will use a combined image sampler (sampler and image could be split)
|
||||
1, // Shader binding point 1
|
||||
&textureDescriptor) // Pointer to the descriptor image for our texture
|
||||
};
|
||||
|
||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
||||
|
|
|
|||
|
|
@ -489,11 +489,11 @@ public:
|
|||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||
|
||||
// Image descriptor for the texture array
|
||||
VkDescriptorImageInfo texArrayDescriptor =
|
||||
VkDescriptorImageInfo textureDescriptor =
|
||||
vkTools::initializers::descriptorImageInfo(
|
||||
textureArray.sampler,
|
||||
textureArray.view,
|
||||
VK_IMAGE_LAYOUT_GENERAL);
|
||||
textureArray.imageLayout);
|
||||
|
||||
std::vector<VkWriteDescriptorSet> writeDescriptorSets =
|
||||
{
|
||||
|
|
@ -508,7 +508,7 @@ public:
|
|||
descriptorSet,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
1,
|
||||
&texArrayDescriptor)
|
||||
&textureDescriptor)
|
||||
};
|
||||
|
||||
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
||||
|
|
|
|||
|
|
@ -470,11 +470,11 @@ public:
|
|||
void setupDescriptorSets()
|
||||
{
|
||||
// Image descriptor for the cube map texture
|
||||
VkDescriptorImageInfo cubeMapDescriptor =
|
||||
VkDescriptorImageInfo textureDescriptor =
|
||||
vkTools::initializers::descriptorImageInfo(
|
||||
cubeMap.sampler,
|
||||
cubeMap.view,
|
||||
VK_IMAGE_LAYOUT_GENERAL);
|
||||
cubeMap.imageLayout);
|
||||
|
||||
VkDescriptorSetAllocateInfo allocInfo =
|
||||
vkTools::initializers::descriptorSetAllocateInfo(
|
||||
|
|
@ -498,7 +498,7 @@ public:
|
|||
descriptorSets.object,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
1,
|
||||
&cubeMapDescriptor)
|
||||
&textureDescriptor)
|
||||
};
|
||||
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
||||
|
||||
|
|
@ -518,7 +518,7 @@ public:
|
|||
descriptorSets.skybox,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
1,
|
||||
&cubeMapDescriptor)
|
||||
&textureDescriptor)
|
||||
};
|
||||
vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -547,12 +547,16 @@ public:
|
|||
&uniformBufferVS.descriptor));
|
||||
|
||||
// Binding 1: Sampled image
|
||||
VkDescriptorImageInfo texDescriptor = vkTools::initializers::descriptorImageInfo(VK_NULL_HANDLE, texture.view, VK_IMAGE_LAYOUT_GENERAL);
|
||||
VkDescriptorImageInfo textureDescriptor =
|
||||
vkTools::initializers::descriptorImageInfo(
|
||||
VK_NULL_HANDLE,
|
||||
texture.view,
|
||||
texture.imageLayout);
|
||||
writeDescriptorSets.push_back(vkTools::initializers::writeDescriptorSet(
|
||||
descriptorSet,
|
||||
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
1,
|
||||
&texDescriptor));
|
||||
&textureDescriptor));
|
||||
|
||||
// Binding 2: Sampler array
|
||||
std::vector<VkDescriptorImageInfo> samplerDescriptors;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue