diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index a9339f84e..e6b40695f 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -40,14 +40,15 @@ void VkRenderPassManager::BeginFrame() builder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); SceneColor = builder.create(fb->device); - builder.setFormat(VK_FORMAT_D24_UNORM_S8_UINT); + builder.setFormat(SceneDepthStencilFormat); builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); if (!builder.isFormatSupported(fb->device)) { - builder.setLinearTiling(); + SceneDepthStencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; + builder.setFormat(SceneDepthStencilFormat); if (!builder.isFormatSupported(fb->device)) { - I_FatalError("This device does not support VK_FORMAT_D24_UNORM_S8_UINT."); + I_FatalError("This device does not support any of the required depth stencil image formats."); } } SceneDepthStencil = builder.create(fb->device); @@ -180,7 +181,7 @@ void VkRenderPassSetup::CreateRenderPass(const VkRenderPassKey &key) RenderPassBuilder builder; builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); if (key.DepthTest || key.DepthWrite || key.StencilTest) - builder.addDepthStencilAttachment(false, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + builder.addDepthStencilAttachment(false, GetVulkanFrameBuffer()->GetRenderPassManager()->SceneDepthStencilFormat, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); builder.addSubpass(); builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); if (key.DepthTest || key.DepthWrite || key.StencilTest) diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index acdfb5257..66cdd57be 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -80,6 +80,8 @@ public: std::unique_ptr SceneDepthStencilView; std::unique_ptr SceneDepthView; + VkFormat SceneDepthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; + std::unique_ptr DynamicSet; std::vector VertexFormats; diff --git a/src/rendering/vulkan/system/vk_builders.h b/src/rendering/vulkan/system/vk_builders.h index 0b73a3a0a..c69285d99 100644 --- a/src/rendering/vulkan/system/vk_builders.h +++ b/src/rendering/vulkan/system/vk_builders.h @@ -254,7 +254,7 @@ public: void addRgba16fAttachment(bool clear, VkImageLayout layout) { addColorAttachment(clear, VK_FORMAT_R16G16B16A16_SFLOAT, layout); } void addColorAttachment(bool clear, VkFormat format, VkImageLayout layout); - void addDepthStencilAttachment(bool clear, VkImageLayout layout); + void addDepthStencilAttachment(bool clear, VkFormat format, VkImageLayout layout); void addExternalSubpassDependency(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask); @@ -1000,10 +1000,10 @@ inline void RenderPassBuilder::addColorAttachment(bool clear, VkFormat format, V renderPassInfo.attachmentCount = (uint32_t)attachments.size(); } -inline void RenderPassBuilder::addDepthStencilAttachment(bool clear, VkImageLayout layout) +inline void RenderPassBuilder::addDepthStencilAttachment(bool clear, VkFormat format, VkImageLayout layout) { VkAttachmentDescription depthAttachment = {}; - depthAttachment.format = VK_FORMAT_D24_UNORM_S8_UINT; + depthAttachment.format = format; depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT; depthAttachment.loadOp = clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE/*VK_ATTACHMENT_STORE_OP_DONT_CARE*/;