Only set stencil aspect on image view if depth format has stencil component
Fixes #529
This commit is contained in:
parent
49ee3469b6
commit
6e14084bdd
1 changed files with 33 additions and 39 deletions
|
|
@ -2007,49 +2007,43 @@ void VulkanExampleBase::createCommandPool()
|
||||||
|
|
||||||
void VulkanExampleBase::setupDepthStencil()
|
void VulkanExampleBase::setupDepthStencil()
|
||||||
{
|
{
|
||||||
VkImageCreateInfo image = {};
|
VkImageCreateInfo imageCI{};
|
||||||
image.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
image.pNext = NULL;
|
imageCI.imageType = VK_IMAGE_TYPE_2D;
|
||||||
image.imageType = VK_IMAGE_TYPE_2D;
|
imageCI.format = depthFormat;
|
||||||
image.format = depthFormat;
|
imageCI.extent = { width, height, 1 };
|
||||||
image.extent = { width, height, 1 };
|
imageCI.mipLevels = 1;
|
||||||
image.mipLevels = 1;
|
imageCI.arrayLayers = 1;
|
||||||
image.arrayLayers = 1;
|
imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
image.samples = VK_SAMPLE_COUNT_1_BIT;
|
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
image.tiling = VK_IMAGE_TILING_OPTIMAL;
|
imageCI.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||||
image.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
|
||||||
image.flags = 0;
|
|
||||||
|
|
||||||
VkMemoryAllocateInfo mem_alloc = {};
|
VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &depthStencil.image));
|
||||||
mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
VkMemoryRequirements memReqs{};
|
||||||
mem_alloc.pNext = NULL;
|
|
||||||
mem_alloc.allocationSize = 0;
|
|
||||||
mem_alloc.memoryTypeIndex = 0;
|
|
||||||
|
|
||||||
VkImageViewCreateInfo depthStencilView = {};
|
|
||||||
depthStencilView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
||||||
depthStencilView.pNext = NULL;
|
|
||||||
depthStencilView.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
depthStencilView.format = depthFormat;
|
|
||||||
depthStencilView.flags = 0;
|
|
||||||
depthStencilView.subresourceRange = {};
|
|
||||||
depthStencilView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
||||||
depthStencilView.subresourceRange.baseMipLevel = 0;
|
|
||||||
depthStencilView.subresourceRange.levelCount = 1;
|
|
||||||
depthStencilView.subresourceRange.baseArrayLayer = 0;
|
|
||||||
depthStencilView.subresourceRange.layerCount = 1;
|
|
||||||
|
|
||||||
VkMemoryRequirements memReqs;
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateImage(device, &image, nullptr, &depthStencil.image));
|
|
||||||
vkGetImageMemoryRequirements(device, depthStencil.image, &memReqs);
|
vkGetImageMemoryRequirements(device, depthStencil.image, &memReqs);
|
||||||
mem_alloc.allocationSize = memReqs.size;
|
|
||||||
mem_alloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
VkMemoryAllocateInfo memAllloc{};
|
||||||
VK_CHECK_RESULT(vkAllocateMemory(device, &mem_alloc, nullptr, &depthStencil.mem));
|
memAllloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
|
memAllloc.allocationSize = memReqs.size;
|
||||||
|
memAllloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
|
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllloc, nullptr, &depthStencil.mem));
|
||||||
VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0));
|
VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0));
|
||||||
|
|
||||||
depthStencilView.image = depthStencil.image;
|
VkImageViewCreateInfo imageViewCI{};
|
||||||
VK_CHECK_RESULT(vkCreateImageView(device, &depthStencilView, nullptr, &depthStencil.view));
|
imageViewCI.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
|
imageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
imageViewCI.image = depthStencil.image;
|
||||||
|
imageViewCI.format = depthFormat;
|
||||||
|
imageViewCI.subresourceRange.baseMipLevel = 0;
|
||||||
|
imageViewCI.subresourceRange.levelCount = 1;
|
||||||
|
imageViewCI.subresourceRange.baseArrayLayer = 0;
|
||||||
|
imageViewCI.subresourceRange.layerCount = 1;
|
||||||
|
imageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||||
|
// Stencil aspect should only be set on depth + stencil formats (VK_FORMAT_D16_UNORM_S8_UINT..VK_FORMAT_D32_SFLOAT_S8_UINT
|
||||||
|
if (depthFormat >= VK_FORMAT_D16_UNORM_S8_UINT) {
|
||||||
|
imageViewCI.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
|
}
|
||||||
|
VK_CHECK_RESULT(vkCreateImageView(device, &imageViewCI, nullptr, &depthStencil.view));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanExampleBase::setupFrameBuffer()
|
void VulkanExampleBase::setupFrameBuffer()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue