parent
1647082260
commit
f5919fc988
3 changed files with 33 additions and 18 deletions
|
|
@ -522,24 +522,8 @@ void VulkanExampleBase::initVulkan(bool enableValidation)
|
||||||
// Get the graphics queue
|
// Get the graphics queue
|
||||||
vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue);
|
vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue);
|
||||||
|
|
||||||
// Find supported depth format
|
VkBool32 validDepthFormat = vkTools::getSupportedDepthFormat(physicalDevice, &depthFormat);
|
||||||
// We prefer 24 bits of depth and 8 bits of stencil, but that may not be supported by all implementations
|
assert(validDepthFormat);
|
||||||
std::vector<VkFormat> depthFormats = { VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D16_UNORM };
|
|
||||||
bool depthFormatFound = false;
|
|
||||||
for (auto& format : depthFormats)
|
|
||||||
{
|
|
||||||
VkFormatProperties formatProps;
|
|
||||||
vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProps);
|
|
||||||
// Format must support depth stencil attachment for optimal tiling
|
|
||||||
if (formatProps.optimalTilingFeatures && VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
||||||
{
|
|
||||||
depthFormat = format;
|
|
||||||
depthFormatFound = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(depthFormatFound);
|
|
||||||
|
|
||||||
swapChain.init(instance, physicalDevice, device);
|
swapChain.init(instance, physicalDevice, device);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,33 @@ namespace vkTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat *depthFormat)
|
||||||
|
{
|
||||||
|
// Since all depth formats may be optional, we need to find a suitable depth format to use
|
||||||
|
// Start with the highest precision packed format
|
||||||
|
std::vector<VkFormat> depthFormats = {
|
||||||
|
VK_FORMAT_D32_SFLOAT_S8_UINT,
|
||||||
|
VK_FORMAT_D32_SFLOAT,
|
||||||
|
VK_FORMAT_D24_UNORM_S8_UINT,
|
||||||
|
VK_FORMAT_D16_UNORM_S8_UINT,
|
||||||
|
VK_FORMAT_D16_UNORM
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto& format : depthFormats)
|
||||||
|
{
|
||||||
|
VkFormatProperties formatProps;
|
||||||
|
vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProps);
|
||||||
|
// Format must support depth stencil attachment for optimal tiling
|
||||||
|
if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||||
|
{
|
||||||
|
*depthFormat = format;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Create an image memory barrier for changing the layout of
|
// Create an image memory barrier for changing the layout of
|
||||||
// an image and put it into an active command buffer
|
// an image and put it into an active command buffer
|
||||||
// See chapter 11.4 "Image Layout" for details
|
// See chapter 11.4 "Image Layout" for details
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ namespace vkTools
|
||||||
// Return string representation of a vulkan error string
|
// Return string representation of a vulkan error string
|
||||||
std::string errorString(VkResult errorCode);
|
std::string errorString(VkResult errorCode);
|
||||||
|
|
||||||
|
// Selected a suitable supported depth format starting with 32 bit down to 16 bit
|
||||||
|
// Returns false if none of the depth formats in the list is supported by the device
|
||||||
|
VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat *depthFormat);
|
||||||
|
|
||||||
// Put an image memory barrier for setting an image layout into the given command buffer
|
// Put an image memory barrier for setting an image layout into the given command buffer
|
||||||
void setImageLayout(
|
void setImageLayout(
|
||||||
VkCommandBuffer cmdbuffer,
|
VkCommandBuffer cmdbuffer,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue