Renderer: Handle more depthstencil formats (as Depth24Stencil8 may not be supported everywhere)
This commit is contained in:
@@ -163,15 +163,23 @@ namespace Nz
|
||||
m_depthStencilFormat = VK_FORMAT_D16_UNORM;
|
||||
break;
|
||||
|
||||
case PixelFormat::Depth16Stencil8:
|
||||
m_depthStencilFormat = VK_FORMAT_D16_UNORM_S8_UINT;
|
||||
break;
|
||||
|
||||
case PixelFormat::Depth24:
|
||||
case PixelFormat::Depth24Stencil8:
|
||||
m_depthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
break;
|
||||
|
||||
case PixelFormat::Depth32:
|
||||
case PixelFormat::Depth32F:
|
||||
m_depthStencilFormat = VK_FORMAT_D32_SFLOAT;
|
||||
break;
|
||||
|
||||
case PixelFormat::Depth32FStencil8:
|
||||
m_depthStencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
break;
|
||||
|
||||
case PixelFormat::Stencil1:
|
||||
case PixelFormat::Stencil4:
|
||||
case PixelFormat::Stencil8:
|
||||
@@ -336,6 +344,14 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
PixelFormat format = FromVulkan(m_depthStencilFormat).value();
|
||||
|
||||
VkImageAspectFlags aspectMask;
|
||||
if (PixelFormatInfo::GetContent(format) == PixelFormatContent::DepthStencil)
|
||||
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
else
|
||||
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
@@ -350,7 +366,7 @@ namespace Nz
|
||||
VK_COMPONENT_SWIZZLE_A // VkComponentSwizzle .a;
|
||||
},
|
||||
{ // VkImageSubresourceRange subresourceRange;
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, // VkImageAspectFlags .aspectMask;
|
||||
aspectMask, // VkImageAspectFlags .aspectMask;
|
||||
0, // uint32_t .baseMipLevel;
|
||||
1, // uint32_t .levelCount;
|
||||
0, // uint32_t .baseArrayLayer;
|
||||
|
||||
@@ -83,4 +83,35 @@ namespace Nz
|
||||
{
|
||||
return std::make_shared<VulkanTextureSampler>(*this, params);
|
||||
}
|
||||
|
||||
bool VulkanDevice::IsTextureFormatSupported(PixelFormat format, TextureUsage usage) const
|
||||
{
|
||||
VkFormatFeatureFlags flags = 0;
|
||||
switch (usage)
|
||||
{
|
||||
case TextureUsage::ColorAttachment:
|
||||
flags = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
|
||||
break;
|
||||
|
||||
case TextureUsage::DepthStencilAttachment:
|
||||
flags = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
break;
|
||||
|
||||
case TextureUsage::InputAttachment:
|
||||
case TextureUsage::ShaderSampling:
|
||||
flags = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
|
||||
break;
|
||||
|
||||
case TextureUsage::TransferSource:
|
||||
flags = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT;
|
||||
break;
|
||||
|
||||
case TextureUsage::TransferDestination:
|
||||
flags = VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
VkFormatProperties formatProperties = GetInstance().GetPhysicalDeviceFormatProperties(GetPhysicalDevice(), ToVulkan(format));
|
||||
return formatProperties.optimalTilingFeatures & flags; //< Assume optimal tiling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,6 +263,22 @@ namespace Nz
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelFormat::Depth16:
|
||||
{
|
||||
createImage.format = VK_FORMAT_D16_UNORM;
|
||||
createImageView.format = createImage.format;
|
||||
createImageView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelFormat::Depth16Stencil8:
|
||||
{
|
||||
createImage.format = VK_FORMAT_D16_UNORM_S8_UINT;
|
||||
createImageView.format = createImage.format;
|
||||
createImageView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelFormat::Depth24Stencil8:
|
||||
{
|
||||
createImage.format = VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
@@ -271,6 +287,22 @@ namespace Nz
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelFormat::Depth32F:
|
||||
{
|
||||
createImage.format = VK_FORMAT_D32_SFLOAT;
|
||||
createImageView.format = createImage.format;
|
||||
createImageView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelFormat::Depth32FStencil8:
|
||||
{
|
||||
createImage.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
createImageView.format = createImage.format;
|
||||
createImageView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
case PixelFormat::L8:
|
||||
{
|
||||
createImage.format = VK_FORMAT_R8_UNORM;
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Instance::EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* devices)
|
||||
bool Instance::EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* devices) const
|
||||
{
|
||||
NazaraAssert(devices, "Invalid device vector");
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Instance::GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector<VkExtensionProperties>* extensionProperties)
|
||||
bool Instance::GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector<VkExtensionProperties>* extensionProperties) const
|
||||
{
|
||||
NazaraAssert(extensionProperties, "Invalid extension properties vector");
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties)
|
||||
bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties) const
|
||||
{
|
||||
NazaraAssert(queueFamilyProperties, "Invalid family properties vector");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user