- fall back to linear if tiling is not supported by the device

This commit is contained in:
Magnus Norddahl 2019-03-04 13:51:58 +01:00
parent 9861642fcc
commit 0a6d77a861
3 changed files with 26 additions and 3 deletions

View file

@ -42,6 +42,14 @@ void VkRenderPassManager::BeginFrame()
builder.setFormat(VK_FORMAT_D24_UNORM_S8_UINT);
builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
if (!builder.isFormatSupported(fb->device))
{
builder.setLinearTiling();
if (!builder.isFormatSupported(fb->device))
{
I_FatalError("This device does not support VK_FORMAT_D24_UNORM_S8_UINT.");
}
}
SceneDepthStencil = builder.create(fb->device);
ImageViewBuilder viewbuilder;

View file

@ -43,6 +43,8 @@ public:
void setUsage(VkImageUsageFlags imageUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY, VmaAllocationCreateFlags allocFlags = 0);
void setLinearTiling();
bool isFormatSupported(VulkanDevice *device);
std::unique_ptr<VulkanImage> create(VulkanDevice *device);
private:
@ -356,6 +358,20 @@ inline void ImageBuilder::setUsage(VkImageUsageFlags usage, VmaMemoryUsage memor
allocInfo.flags = allocFlags;
}
inline bool ImageBuilder::isFormatSupported(VulkanDevice *device)
{
VkImageFormatProperties properties = { };
VkResult result = vkGetPhysicalDeviceImageFormatProperties(device->physicalDevice, imageInfo.format, imageInfo.imageType, imageInfo.tiling, imageInfo.usage, imageInfo.flags, &properties);
if (result != VK_SUCCESS) return false;
if (imageInfo.extent.width > properties.maxExtent.width) return false;
if (imageInfo.extent.height > properties.maxExtent.height) return false;
if (imageInfo.extent.depth > properties.maxExtent.depth) return false;
if (imageInfo.mipLevels > properties.maxMipLevels) return false;
if (imageInfo.arrayLayers > properties.maxArrayLayers) return false;
if ((imageInfo.samples & properties.sampleCounts) != imageInfo.samples) return false;
return true;
}
inline std::unique_ptr<VulkanImage> ImageBuilder::create(VulkanDevice *device)
{
VkImage image;
@ -715,7 +731,6 @@ inline GraphicsPipelineBuilder::GraphicsPipelineBuilder()
colorBlending.blendConstants[2] = 0.0f;
colorBlending.blendConstants[3] = 0.0f;
VkPipelineDynamicStateCreateInfo dynamicState = {};
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
}

View file

@ -48,6 +48,8 @@ public:
VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures;
VkPhysicalDevice physicalDevice = {};
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
private:
@ -67,8 +69,6 @@ private:
VkInstance instance = nullptr;
VkSurfaceKHR surface = 0;
VkPhysicalDevice physicalDevice = {};
VkQueue presentQueue = nullptr;
VulkanDevice(const VulkanDevice &) = delete;