vulkan: cache depthStencilFormat

This commit is contained in:
niki
2023-02-12 14:52:30 +01:00
parent dc6e080d18
commit 4f321d69e7
2 changed files with 7 additions and 8 deletions
+6 -8
View File
@@ -1448,6 +1448,7 @@ void Graphics::pickPhysicalDevice()
deviceApiVersion = properties.apiVersion; deviceApiVersion = properties.apiVersion;
msaaSamples = getMsaaCount(requestedMsaa); msaaSamples = getMsaaCount(requestedMsaa);
depthStencilFormat = findDepthFormat();
} }
bool Graphics::checkDeviceExtensionSupport(VkPhysicalDevice device) bool Graphics::checkDeviceExtensionSupport(VkPhysicalDevice device)
@@ -2181,7 +2182,6 @@ VkRenderPass Graphics::createRenderPass(RenderPassConfiguration &configuration)
return renderPass; return renderPass;
} }
VkRenderPass Graphics::getRenderPass(RenderPassConfiguration &configuration) VkRenderPass Graphics::getRenderPass(RenderPassConfiguration &configuration)
{ {
VkRenderPass renderPass; VkRenderPass renderPass;
@@ -2362,7 +2362,7 @@ void Graphics::setDefaultRenderPass()
RenderPassConfiguration renderPassConfiguration{}; RenderPassConfiguration renderPassConfiguration{};
renderPassConfiguration.colorAttachments.push_back({ swapChainImageFormat, VK_ATTACHMENT_LOAD_OP_LOAD, msaaSamples }); renderPassConfiguration.colorAttachments.push_back({ swapChainImageFormat, VK_ATTACHMENT_LOAD_OP_LOAD, msaaSamples });
renderPassConfiguration.staticData.depthStencilAttachment = { findDepthFormat(), VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_LOAD_OP_LOAD, msaaSamples }; renderPassConfiguration.staticData.depthStencilAttachment = { depthStencilFormat, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_LOAD_OP_LOAD, msaaSamples };
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT) if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
renderPassConfiguration.staticData.resolve = false; renderPassConfiguration.staticData.resolve = false;
else else
@@ -2384,8 +2384,8 @@ void Graphics::setDefaultRenderPass()
framebufferConfiguration.staticData.resolveView = swapChainImageViews.at(imageIndex); framebufferConfiguration.staticData.resolveView = swapChainImageViews.at(imageIndex);
} }
renderPassState.renderPassConfiguration = renderPassConfiguration; renderPassState.renderPassConfiguration = std::move(renderPassConfiguration);
renderPassState.framebufferConfiguration = framebufferConfiguration; renderPassState.framebufferConfiguration = std::move(framebufferConfiguration);
if (renderPassState.windowClearRequested) if (renderPassState.windowClearRequested)
clear(renderPassState.mainWindowClearColorValue, renderPassState.mainWindowClearStencilValue, renderPassState.mainWindowClearDepthValue); clear(renderPassState.mainWindowClearColorValue, renderPassState.mainWindowClearStencilValue, renderPassState.mainWindowClearDepthValue);
@@ -2890,12 +2890,10 @@ VkFormat Graphics::findDepthFormat()
void Graphics::createDepthResources() void Graphics::createDepthResources()
{ {
VkFormat depthAttachment = findDepthFormat();
VkImageCreateInfo imageInfo{}; VkImageCreateInfo imageInfo{};
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_2D; imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = depthAttachment; imageInfo.format = depthStencilFormat;
imageInfo.extent.width = swapChainExtent.width; imageInfo.extent.width = swapChainExtent.width;
imageInfo.extent.height = swapChainExtent.height; imageInfo.extent.height = swapChainExtent.height;
imageInfo.extent.depth = 1; imageInfo.extent.depth = 1;
@@ -2918,7 +2916,7 @@ void Graphics::createDepthResources()
imageViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; imageViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
imageViewInfo.image = depthImage; imageViewInfo.image = depthImage;
imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
imageViewInfo.format = depthAttachment; imageViewInfo.format = depthStencilFormat;
imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
+1
View File
@@ -402,6 +402,7 @@ private:
Matrix4 displayRotation; Matrix4 displayRotation;
std::vector<VkImage> swapChainImages; std::vector<VkImage> swapChainImages;
VkFormat swapChainImageFormat = VK_FORMAT_UNDEFINED; VkFormat swapChainImageFormat = VK_FORMAT_UNDEFINED;
VkFormat depthStencilFormat = VK_FORMAT_UNDEFINED;
VkExtent2D swapChainExtent = VkExtent2D(); VkExtent2D swapChainExtent = VkExtent2D();
std::vector<VkImageView> swapChainImageViews; std::vector<VkImageView> swapChainImageViews;
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT; VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;