mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
vulkan: remove default renderpasses & framebuffers
There is little to no performance gain, with a lot of burden to maintenance of the extra path. It's better to unify the code with the other render pass logic.
This commit is contained in:
@@ -156,8 +156,6 @@ void Graphics::clear(OptionalColorD color, OptionalInt stencil, OptionalDouble d
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renderPassState.useConfigurations = true;
|
|
||||||
|
|
||||||
if (color.hasValue)
|
if (color.hasValue)
|
||||||
{
|
{
|
||||||
renderPassState.renderPassConfiguration.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
renderPassState.renderPassConfiguration.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
@@ -245,8 +243,6 @@ void Graphics::clear(const std::vector<OptionalColorD> &colors, OptionalInt sten
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renderPassState.useConfigurations = true;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < colors.size(); i++)
|
for (size_t i = 0; i < colors.size(); i++)
|
||||||
{
|
{
|
||||||
if (colors[i].hasValue)
|
if (colors[i].hasValue)
|
||||||
@@ -280,7 +276,6 @@ void Graphics::discard(const std::vector<bool> &colorbuffers, bool depthstencil)
|
|||||||
if (renderPassState.active)
|
if (renderPassState.active)
|
||||||
endRenderPass();
|
endRenderPass();
|
||||||
|
|
||||||
renderPassState.useConfigurations = true;
|
|
||||||
auto & renderPassConfiguration = renderPassState.renderPassConfiguration;
|
auto & renderPassConfiguration = renderPassState.renderPassConfiguration;
|
||||||
|
|
||||||
for (size_t i = 0; i < colorbuffers.size(); i++)
|
for (size_t i = 0; i < colorbuffers.size(); i++)
|
||||||
@@ -550,8 +545,6 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int
|
|||||||
createColorResources();
|
createColorResources();
|
||||||
createDepthResources();
|
createDepthResources();
|
||||||
transitionColorDepthLayouts = true;
|
transitionColorDepthLayouts = true;
|
||||||
createDefaultRenderPass();
|
|
||||||
createDefaultFramebuffers();
|
|
||||||
createCommandPool();
|
createCommandPool();
|
||||||
createCommandBuffers();
|
createCommandBuffers();
|
||||||
|
|
||||||
@@ -1100,6 +1093,8 @@ bool Graphics::dispatch(love::graphics::Shader *shader, int x, int y, int z)
|
|||||||
|
|
||||||
bool Graphics::dispatch(love::graphics::Shader *shader, love::graphics::Buffer *indirectargs, size_t argsoffset)
|
bool Graphics::dispatch(love::graphics::Shader *shader, love::graphics::Buffer *indirectargs, size_t argsoffset)
|
||||||
{
|
{
|
||||||
|
usedShadersInFrame.insert(computeShader);
|
||||||
|
|
||||||
if (renderPassState.active)
|
if (renderPassState.active)
|
||||||
endRenderPass();
|
endRenderPass();
|
||||||
|
|
||||||
@@ -2027,40 +2022,6 @@ void Graphics::createScreenshotCallbackBuffers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::createDefaultRenderPass()
|
|
||||||
{
|
|
||||||
RenderPassConfiguration renderPassConfiguration{};
|
|
||||||
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 };
|
|
||||||
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
|
||||||
renderPassConfiguration.staticData.resolve = false;
|
|
||||||
else
|
|
||||||
renderPassConfiguration.staticData.resolve = true;
|
|
||||||
defaultRenderPass = createRenderPass(renderPassConfiguration);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Graphics::createDefaultFramebuffers()
|
|
||||||
{
|
|
||||||
defaultFramebuffers.clear();
|
|
||||||
|
|
||||||
for (const auto view : swapChainImageViews)
|
|
||||||
{
|
|
||||||
FramebufferConfiguration configuration{};
|
|
||||||
configuration.staticData.renderPass = defaultRenderPass;
|
|
||||||
configuration.staticData.width = swapChainExtent.width;
|
|
||||||
configuration.staticData.height = swapChainExtent.height;
|
|
||||||
configuration.staticData.depthView = depthImageView;
|
|
||||||
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
|
||||||
configuration.colorViews.push_back(view);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
configuration.colorViews.push_back(colorImageView);
|
|
||||||
configuration.staticData.resolveView = view;
|
|
||||||
}
|
|
||||||
defaultFramebuffers.push_back(createFramebuffer(configuration));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkFramebuffer Graphics::createFramebuffer(FramebufferConfiguration &configuration)
|
VkFramebuffer Graphics::createFramebuffer(FramebufferConfiguration &configuration)
|
||||||
{
|
{
|
||||||
std::vector<VkImageView> attachments;
|
std::vector<VkImageView> attachments;
|
||||||
@@ -2372,15 +2333,14 @@ void Graphics::setDefaultRenderPass()
|
|||||||
renderPassState.clearColors.resize(numClearValues);
|
renderPassState.clearColors.resize(numClearValues);
|
||||||
|
|
||||||
renderPassState.beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
renderPassState.beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
renderPassState.beginInfo.renderPass = defaultRenderPass;
|
renderPassState.beginInfo.renderPass = VK_NULL_HANDLE;
|
||||||
renderPassState.beginInfo.framebuffer = defaultFramebuffers[imageIndex];
|
renderPassState.beginInfo.framebuffer = VK_NULL_HANDLE;
|
||||||
renderPassState.beginInfo.renderArea.offset = { 0, 0 };
|
renderPassState.beginInfo.renderArea.offset = { 0, 0 };
|
||||||
renderPassState.beginInfo.renderArea.extent = swapChainExtent;
|
renderPassState.beginInfo.renderArea.extent = swapChainExtent;
|
||||||
renderPassState.beginInfo.clearValueCount = numClearValues;
|
renderPassState.beginInfo.clearValueCount = numClearValues;
|
||||||
renderPassState.beginInfo.pClearValues = renderPassState.clearColors.data();
|
renderPassState.beginInfo.pClearValues = renderPassState.clearColors.data();
|
||||||
|
|
||||||
renderPassState.isWindow = true;
|
renderPassState.isWindow = true;
|
||||||
renderPassState.useConfigurations = false;
|
|
||||||
renderPassState.pipeline = VK_NULL_HANDLE;
|
renderPassState.pipeline = VK_NULL_HANDLE;
|
||||||
renderPassState.width = static_cast<float>(swapChainExtent.width);
|
renderPassState.width = static_cast<float>(swapChainExtent.width);
|
||||||
renderPassState.height = static_cast<float>(swapChainExtent.height);
|
renderPassState.height = static_cast<float>(swapChainExtent.height);
|
||||||
@@ -2465,7 +2425,6 @@ void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, b
|
|||||||
renderPassState.beginInfo.pClearValues = renderPassState.clearColors.data();
|
renderPassState.beginInfo.pClearValues = renderPassState.clearColors.data();
|
||||||
|
|
||||||
renderPassState.isWindow = false;
|
renderPassState.isWindow = false;
|
||||||
renderPassState.useConfigurations = true;
|
|
||||||
renderPassState.renderPassConfiguration = renderPassConfiguration;
|
renderPassState.renderPassConfiguration = renderPassConfiguration;
|
||||||
renderPassState.framebufferConfiguration = configuration;
|
renderPassState.framebufferConfiguration = configuration;
|
||||||
renderPassState.pipeline = VK_NULL_HANDLE;
|
renderPassState.pipeline = VK_NULL_HANDLE;
|
||||||
@@ -2493,26 +2452,23 @@ void Graphics::startRenderPass()
|
|||||||
|
|
||||||
vkCmdSetViewport(commandBuffers.at(currentFrame), 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffers.at(currentFrame), 0, 1, &viewport);
|
||||||
|
|
||||||
if (renderPassState.useConfigurations)
|
auto &renderPassConfiguration = renderPassState.renderPassConfiguration;
|
||||||
|
VkRenderPass renderPass;
|
||||||
|
auto it = renderPasses.find(renderPassConfiguration);
|
||||||
|
if (it != renderPasses.end())
|
||||||
|
renderPass = it->second;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
auto &renderPassConfiguration = renderPassState.renderPassConfiguration;
|
renderPass = createRenderPass(renderPassConfiguration);
|
||||||
VkRenderPass renderPass;
|
renderPasses[renderPassConfiguration] = renderPass;
|
||||||
auto it = renderPasses.find(renderPassConfiguration);
|
|
||||||
if (it != renderPasses.end())
|
|
||||||
renderPass = it->second;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderPass = createRenderPass(renderPassConfiguration);
|
|
||||||
renderPasses[renderPassConfiguration] = renderPass;
|
|
||||||
}
|
|
||||||
renderPassState.beginInfo.renderPass = renderPass;
|
|
||||||
|
|
||||||
renderPassUsages[renderPass] = true;
|
|
||||||
|
|
||||||
auto &framebufferConfiguration = renderPassState.framebufferConfiguration;
|
|
||||||
framebufferConfiguration.staticData.renderPass = renderPass;
|
|
||||||
renderPassState.beginInfo.framebuffer = getFramebuffer(framebufferConfiguration);
|
|
||||||
}
|
}
|
||||||
|
renderPassState.beginInfo.renderPass = renderPass;
|
||||||
|
|
||||||
|
renderPassUsages[renderPass] = true;
|
||||||
|
|
||||||
|
auto &framebufferConfiguration = renderPassState.framebufferConfiguration;
|
||||||
|
framebufferConfiguration.staticData.renderPass = renderPass;
|
||||||
|
renderPassState.beginInfo.framebuffer = getFramebuffer(framebufferConfiguration);
|
||||||
|
|
||||||
for (const auto &image : renderPassState.transitionImages)
|
for (const auto &image : renderPassState.transitionImages)
|
||||||
Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||||
@@ -3080,9 +3036,6 @@ void Graphics::cleanupSwapChain()
|
|||||||
vmaDestroyBuffer(vmaAllocator, readbackBuffer.buffer, readbackBuffer.allocation);
|
vmaDestroyBuffer(vmaAllocator, readbackBuffer.buffer, readbackBuffer.allocation);
|
||||||
vmaDestroyImage(vmaAllocator, readbackBuffer.image, readbackBuffer.imageAllocation);
|
vmaDestroyImage(vmaAllocator, readbackBuffer.image, readbackBuffer.imageAllocation);
|
||||||
}
|
}
|
||||||
for (const auto &framebuffer : defaultFramebuffers)
|
|
||||||
vkDestroyFramebuffer(device, framebuffer, nullptr);
|
|
||||||
vkDestroyRenderPass(device, defaultRenderPass, nullptr);
|
|
||||||
vkDestroyImageView(device, colorImageView, nullptr);
|
vkDestroyImageView(device, colorImageView, nullptr);
|
||||||
vmaDestroyImage(vmaAllocator, colorImage, colorImageAllocation);
|
vmaDestroyImage(vmaAllocator, colorImage, colorImageAllocation);
|
||||||
vkDestroyImageView(device, depthImageView, nullptr);
|
vkDestroyImageView(device, depthImageView, nullptr);
|
||||||
@@ -3106,8 +3059,6 @@ void Graphics::recreateSwapChain()
|
|||||||
createScreenshotCallbackBuffers();
|
createScreenshotCallbackBuffers();
|
||||||
createColorResources();
|
createColorResources();
|
||||||
createDepthResources();
|
createDepthResources();
|
||||||
createDefaultRenderPass();
|
|
||||||
createDefaultFramebuffers();
|
|
||||||
|
|
||||||
transitionColorDepthLayouts = true;
|
transitionColorDepthLayouts = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ struct RenderpassState
|
|||||||
bool active = false;
|
bool active = false;
|
||||||
VkRenderPassBeginInfo beginInfo{};
|
VkRenderPassBeginInfo beginInfo{};
|
||||||
bool isWindow = false;
|
bool isWindow = false;
|
||||||
bool useConfigurations = false;
|
|
||||||
RenderPassConfiguration renderPassConfiguration{};
|
RenderPassConfiguration renderPassConfiguration{};
|
||||||
FramebufferConfiguration framebufferConfiguration{};
|
FramebufferConfiguration framebufferConfiguration{};
|
||||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||||
@@ -351,8 +350,6 @@ private:
|
|||||||
void createSwapChain();
|
void createSwapChain();
|
||||||
void createImageViews();
|
void createImageViews();
|
||||||
void createScreenshotCallbackBuffers();
|
void createScreenshotCallbackBuffers();
|
||||||
void createDefaultRenderPass();
|
|
||||||
void createDefaultFramebuffers();
|
|
||||||
VkFramebuffer createFramebuffer(FramebufferConfiguration &configuration);
|
VkFramebuffer createFramebuffer(FramebufferConfiguration &configuration);
|
||||||
VkFramebuffer getFramebuffer(FramebufferConfiguration &configuration);
|
VkFramebuffer getFramebuffer(FramebufferConfiguration &configuration);
|
||||||
void createDefaultShaders();
|
void createDefaultShaders();
|
||||||
@@ -416,9 +413,7 @@ private:
|
|||||||
VkImage depthImage = VK_NULL_HANDLE;
|
VkImage depthImage = VK_NULL_HANDLE;
|
||||||
VkImageView depthImageView = VK_NULL_HANDLE;
|
VkImageView depthImageView = VK_NULL_HANDLE;
|
||||||
VmaAllocation depthImageAllocation = VK_NULL_HANDLE;
|
VmaAllocation depthImageAllocation = VK_NULL_HANDLE;
|
||||||
VkRenderPass defaultRenderPass = VK_NULL_HANDLE;
|
|
||||||
VkPipelineCache pipelineCache = VK_NULL_HANDLE;
|
VkPipelineCache pipelineCache = VK_NULL_HANDLE;
|
||||||
std::vector<VkFramebuffer> defaultFramebuffers;
|
|
||||||
std::unordered_map<RenderPassConfiguration, VkRenderPass, RenderPassConfigurationHasher> renderPasses;
|
std::unordered_map<RenderPassConfiguration, VkRenderPass, RenderPassConfigurationHasher> renderPasses;
|
||||||
std::unordered_map<FramebufferConfiguration, VkFramebuffer, FramebufferConfigurationHasher> framebuffers;
|
std::unordered_map<FramebufferConfiguration, VkFramebuffer, FramebufferConfigurationHasher> framebuffers;
|
||||||
std::unordered_map<GraphicsPipelineConfiguration, VkPipeline, GraphicsPipelineConfigurationHasher> graphicsPipelines;
|
std::unordered_map<GraphicsPipelineConfiguration, VkPipeline, GraphicsPipelineConfigurationHasher> graphicsPipelines;
|
||||||
|
|||||||
Reference in New Issue
Block a user