mirror of
https://github.com/love2d/love.git
synced 2026-08-21 21:15:09 +02:00
vulkan: add support for custom depth/stencil tex
This commit is contained in:
@@ -240,6 +240,11 @@ void Graphics::present(void *screenshotCallbackdata)
|
|||||||
if (!isActive())
|
if (!isActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (isRenderTargetActive())
|
||||||
|
throw love::Exception("present cannot be called while a render target is active.");
|
||||||
|
|
||||||
|
deprecations.draw(this);
|
||||||
|
|
||||||
submitGpuCommands(true);
|
submitGpuCommands(true);
|
||||||
|
|
||||||
VkPresentInfoKHR presentInfo{};
|
VkPresentInfoKHR presentInfo{};
|
||||||
@@ -266,6 +271,13 @@ void Graphics::present(void *screenshotCallbackdata)
|
|||||||
else if (result != VK_SUCCESS)
|
else if (result != VK_SUCCESS)
|
||||||
throw love::Exception("failed to present swap chain image");
|
throw love::Exception("failed to present swap chain image");
|
||||||
|
|
||||||
|
drawCalls = 0;
|
||||||
|
renderTargetSwitchCount = 0;
|
||||||
|
drawCallsBatched = 0;
|
||||||
|
|
||||||
|
updatePendingReadbacks();
|
||||||
|
updateTemporaryResources();
|
||||||
|
|
||||||
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
|
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||||
|
|
||||||
beginFrame();
|
beginFrame();
|
||||||
@@ -720,7 +732,7 @@ bool Graphics::dispatch(int x, int y, int z)
|
|||||||
|
|
||||||
vkCmdBindPipeline(commandBuffers.at(currentFrame), VK_PIPELINE_BIND_POINT_COMPUTE, computeShader->getComputePipeline());
|
vkCmdBindPipeline(commandBuffers.at(currentFrame), VK_PIPELINE_BIND_POINT_COMPUTE, computeShader->getComputePipeline());
|
||||||
|
|
||||||
computeShader->cmdPushDescriptorSets(commandBuffers.at(currentFrame), currentFrame, VK_PIPELINE_BIND_POINT_COMPUTE);
|
computeShader->cmdPushDescriptorSets(commandBuffers.at(currentFrame), static_cast<uint32_t>(currentFrame), VK_PIPELINE_BIND_POINT_COMPUTE);
|
||||||
|
|
||||||
vkCmdDispatch(commandBuffers.at(currentFrame), static_cast<uint32_t>(x), static_cast<uint32_t>(y), static_cast<uint32_t>(z));
|
vkCmdDispatch(commandBuffers.at(currentFrame), static_cast<uint32_t>(x), static_cast<uint32_t>(y), static_cast<uint32_t>(z));
|
||||||
|
|
||||||
@@ -1475,8 +1487,8 @@ VkPresentModeKHR Graphics::chooseSwapPresentMode(const std::vector<VkPresentMode
|
|||||||
{
|
{
|
||||||
int vsync = Vulkan::getVsync();
|
int vsync = Vulkan::getVsync();
|
||||||
|
|
||||||
auto begin = availablePresentModes.begin();
|
const auto begin = availablePresentModes.begin();
|
||||||
auto end = availablePresentModes.end();
|
const auto end = availablePresentModes.end();
|
||||||
|
|
||||||
switch (vsync) {
|
switch (vsync) {
|
||||||
case -1:
|
case -1:
|
||||||
|
|||||||
@@ -425,6 +425,12 @@ const Shader::UniformInfo* Shader::getUniformInfo(BuiltinUniform builtin) const
|
|||||||
return builtinUniformInfo[builtin];
|
return builtinUniformInfo[builtin];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shader::updateUniform(const UniformInfo* info, int count)
|
||||||
|
{
|
||||||
|
if (current == this)
|
||||||
|
Graphics::flushBatchedDrawsGlobal();
|
||||||
|
}
|
||||||
|
|
||||||
void Shader::sendTextures(const UniformInfo *info, graphics::Texture **textures, int count)
|
void Shader::sendTextures(const UniformInfo *info, graphics::Texture **textures, int count)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < count; i++)
|
for (unsigned i = 0; i < count; i++)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// LÖVE
|
// LÖVE
|
||||||
#include <graphics/Shader.h>
|
#include "graphics/Shader.h"
|
||||||
#include <graphics/vulkan/ShaderStage.h>
|
#include "graphics/vulkan/ShaderStage.h"
|
||||||
#include "Vulkan.h"
|
#include "Vulkan.h"
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
@@ -56,10 +56,7 @@ public:
|
|||||||
const UniformInfo *getUniformInfo(const std::string &name) const override;
|
const UniformInfo *getUniformInfo(const std::string &name) const override;
|
||||||
const UniformInfo *getUniformInfo(BuiltinUniform builtin) const override;
|
const UniformInfo *getUniformInfo(BuiltinUniform builtin) const override;
|
||||||
|
|
||||||
// Not needed right now, since the logic that links the values of the uniforms to the shader is done in cmdPushDescriptorSets
|
void updateUniform(const UniformInfo *info, int count) override;
|
||||||
// which gets called from the vulkan::Graphics class whenever a draw call happens.
|
|
||||||
// I'll have to reevaluate the use of this function in the future though.
|
|
||||||
void updateUniform(const UniformInfo* info, int count) override {}
|
|
||||||
|
|
||||||
void sendTextures(const UniformInfo *info, graphics::Texture **textures, int count) override;
|
void sendTextures(const UniformInfo *info, graphics::Texture **textures, int count) override;
|
||||||
void sendBuffers(const UniformInfo *info, love::graphics::Buffer **buffers, int count) override {}
|
void sendBuffers(const UniformInfo *info, love::graphics::Buffer **buffers, int count) override {}
|
||||||
|
|||||||
@@ -79,7 +79,11 @@ bool Texture::loadVolatile()
|
|||||||
|
|
||||||
auto commandBuffer = vgfx->getCommandBufferForDataTransfer();
|
auto commandBuffer = vgfx->getCommandBufferForDataTransfer();
|
||||||
|
|
||||||
if (computeWrite)
|
if (isPixelFormatDepthStencil(format))
|
||||||
|
imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
else if (isPixelFormatDepth(format))
|
||||||
|
imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
|
||||||
|
else if (computeWrite)
|
||||||
imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||||
else
|
else
|
||||||
imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
@@ -200,29 +204,54 @@ void Texture::clear()
|
|||||||
{
|
{
|
||||||
auto commandBuffer = vgfx->getCommandBufferForDataTransfer();
|
auto commandBuffer = vgfx->getCommandBufferForDataTransfer();
|
||||||
|
|
||||||
auto clearColor = getClearValue();
|
|
||||||
|
|
||||||
VkImageSubresourceRange range{};
|
VkImageSubresourceRange range{};
|
||||||
|
if (isPixelFormatDepthStencil(format))
|
||||||
|
range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
|
else if (isPixelFormatDepth(format))
|
||||||
|
range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||||
|
else
|
||||||
range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
range.baseMipLevel = 0;
|
range.baseMipLevel = 0;
|
||||||
range.levelCount = VK_REMAINING_MIP_LEVELS;
|
range.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||||
range.baseArrayLayer = 0;
|
range.baseArrayLayer = 0;
|
||||||
range.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
range.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||||
|
|
||||||
if (imageLayout != VK_IMAGE_LAYOUT_GENERAL)
|
if (imageLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||||
{
|
{
|
||||||
Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage,
|
Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage,
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||||
0, range.levelCount, 0, range.layerCount);
|
0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS);
|
||||||
|
|
||||||
|
auto clearColor = getClearValue();
|
||||||
|
|
||||||
vkCmdClearColorImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
|
vkCmdClearColorImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
|
||||||
|
|
||||||
Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage,
|
Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage,
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||||
0, range.levelCount, 0, range.layerCount);
|
0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS);
|
||||||
|
}
|
||||||
|
else if (imageLayout == VK_IMAGE_LAYOUT_GENERAL)
|
||||||
|
{
|
||||||
|
auto clearColor = getClearValue();
|
||||||
|
|
||||||
|
vkCmdClearColorImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &range);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vkCmdClearColorImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &range);
|
{
|
||||||
|
Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage,
|
||||||
|
imageLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||||
|
0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS);
|
||||||
|
|
||||||
|
VkClearDepthStencilValue depthStencilColor{};
|
||||||
|
depthStencilColor.depth = 0.0f;
|
||||||
|
depthStencilColor.stencil = 0;
|
||||||
|
|
||||||
|
vkCmdClearDepthStencilImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencilColor, 1, &range);
|
||||||
|
|
||||||
|
Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage,
|
||||||
|
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, imageLayout,
|
||||||
|
0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkClearColorValue Texture::getClearValue()
|
VkClearColorValue Texture::getClearValue()
|
||||||
|
|||||||
@@ -789,6 +789,33 @@ void Vulkan::cmdTransitionImageLayout(VkCommandBuffer commandBuffer, VkImage ima
|
|||||||
sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||||
destinationStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT;
|
destinationStage = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||||
}
|
}
|
||||||
|
else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED &&
|
||||||
|
(newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || newLayout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL))
|
||||||
|
{
|
||||||
|
barrier.srcAccessMask = 0;
|
||||||
|
barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||||
|
|
||||||
|
sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||||
|
destinationStage = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||||
|
}
|
||||||
|
else if ((oldLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || oldLayout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) &&
|
||||||
|
newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL)
|
||||||
|
{
|
||||||
|
barrier.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||||
|
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
|
|
||||||
|
sourceStage = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||||
|
destinationStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||||
|
}
|
||||||
|
else if (oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL &&
|
||||||
|
(newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || newLayout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL))
|
||||||
|
{
|
||||||
|
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
|
barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||||
|
|
||||||
|
sourceStage = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||||
|
destinationStage = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw std::invalid_argument("unsupported layout transition!");
|
throw std::invalid_argument("unsupported layout transition!");
|
||||||
|
|
||||||
@@ -801,6 +828,7 @@ void Vulkan::cmdTransitionImageLayout(VkCommandBuffer commandBuffer, VkImage ima
|
|||||||
1, &barrier
|
1, &barrier
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // vulkan
|
} // vulkan
|
||||||
} // graphics
|
} // graphics
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
Reference in New Issue
Block a user