mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
vulkan: implement texture msaa
This commit is contained in:
@@ -198,9 +198,8 @@ void Graphics::discard(const std::vector<bool>& colorbuffers, bool depthstencil)
|
||||
else
|
||||
{
|
||||
RenderPassConfiguration renderPassConfiguration{};
|
||||
renderPassConfiguration.colorAttachments.push_back({ swapChainImageFormat, colorbuffers[0] });
|
||||
renderPassConfiguration.staticData.depthAttachment = { findDepthFormat(), depthstencil };
|
||||
renderPassConfiguration.staticData.msaaSamples = msaaSamples;
|
||||
renderPassConfiguration.colorAttachments.push_back({ swapChainImageFormat, colorbuffers[0], msaaSamples });
|
||||
renderPassConfiguration.staticData.depthAttachment = { findDepthFormat(), depthstencil, msaaSamples };
|
||||
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
||||
renderPassConfiguration.staticData.resolve = false;
|
||||
else
|
||||
@@ -1192,7 +1191,7 @@ void Graphics::pickPhysicalDevice()
|
||||
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
|
||||
minUniformBufferOffsetAlignment = properties.limits.minUniformBufferOffsetAlignment;
|
||||
|
||||
getMaxUsableSampleCount();
|
||||
msaaSamples = getMsaaCount(requestedMsaa);
|
||||
}
|
||||
|
||||
bool Graphics::checkDeviceExtensionSupport(VkPhysicalDevice device)
|
||||
@@ -1717,9 +1716,8 @@ void Graphics::createImageViews()
|
||||
void Graphics::createDefaultRenderPass()
|
||||
{
|
||||
RenderPassConfiguration renderPassConfiguration{};
|
||||
renderPassConfiguration.colorAttachments.push_back({ swapChainImageFormat, false });
|
||||
renderPassConfiguration.staticData.msaaSamples = msaaSamples;
|
||||
renderPassConfiguration.staticData.depthAttachment = { findDepthFormat(), false };
|
||||
renderPassConfiguration.colorAttachments.push_back({ swapChainImageFormat, false, msaaSamples });
|
||||
renderPassConfiguration.staticData.depthAttachment = { findDepthFormat(), false, msaaSamples };
|
||||
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
||||
renderPassConfiguration.staticData.resolve = false;
|
||||
else
|
||||
@@ -1824,7 +1822,7 @@ VkRenderPass Graphics::createRenderPass(RenderPassConfiguration &configuration)
|
||||
|
||||
VkAttachmentDescription colorDescription{};
|
||||
colorDescription.format = colorAttachment.format;
|
||||
colorDescription.samples = configuration.staticData.msaaSamples;
|
||||
colorDescription.samples = colorAttachment.msaaSamples;
|
||||
if (colorAttachment.discard)
|
||||
colorDescription.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
else
|
||||
@@ -1849,7 +1847,7 @@ VkRenderPass Graphics::createRenderPass(RenderPassConfiguration &configuration)
|
||||
|
||||
VkAttachmentDescription depthStencilAttachment{};
|
||||
depthStencilAttachment.format = configuration.staticData.depthAttachment.format;
|
||||
depthStencilAttachment.samples = configuration.staticData.msaaSamples;
|
||||
depthStencilAttachment.samples = configuration.staticData.depthAttachment.msaaSamples;
|
||||
if (configuration.staticData.depthAttachment.discard)
|
||||
depthStencilAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
else
|
||||
@@ -2096,11 +2094,17 @@ void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, b
|
||||
// fixme: hasSRGBtexture
|
||||
// fixme: msaaSamples
|
||||
RenderPassConfiguration renderPassConfiguration{};
|
||||
for (const auto &color : rts.colors)
|
||||
renderPassConfiguration.colorAttachments.push_back({ Vulkan::getTextureFormat(color.texture->getPixelFormat()).internalFormat, false });
|
||||
for (const auto& color : rts.colors)
|
||||
renderPassConfiguration.colorAttachments.push_back({
|
||||
Vulkan::getTextureFormat(color.texture->getPixelFormat()).internalFormat,
|
||||
false,
|
||||
dynamic_cast<Texture*>(color.texture)->getMsaaSamples() });
|
||||
if (rts.depthStencil.texture != nullptr)
|
||||
if (rts.depthStencil.texture != nullptr)
|
||||
renderPassConfiguration.staticData.depthAttachment = { Vulkan::getTextureFormat(rts.depthStencil.texture->getPixelFormat()).internalFormat, false };
|
||||
renderPassConfiguration.staticData.depthAttachment = {
|
||||
Vulkan::getTextureFormat(rts.depthStencil.texture->getPixelFormat()).internalFormat,
|
||||
false,
|
||||
dynamic_cast<Texture*>(rts.depthStencil.texture)->getMsaaSamples() };
|
||||
|
||||
FramebufferConfiguration configuration{};
|
||||
|
||||
@@ -2409,7 +2413,7 @@ void Graphics::ensureGraphicsPipelineConfiguration(GraphicsPipelineConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::getMaxUsableSampleCount()
|
||||
VkSampleCountFlagBits Graphics::getMsaaCount(int requestedMsaa) const
|
||||
{
|
||||
VkPhysicalDeviceProperties physicalDeviceProperties;
|
||||
vkGetPhysicalDeviceProperties(physicalDevice, &physicalDeviceProperties);
|
||||
@@ -2417,19 +2421,19 @@ void Graphics::getMaxUsableSampleCount()
|
||||
VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts & physicalDeviceProperties.limits.framebufferDepthSampleCounts;
|
||||
|
||||
if (counts & VK_SAMPLE_COUNT_64_BIT && requestedMsaa >= 64)
|
||||
msaaSamples = VK_SAMPLE_COUNT_64_BIT;
|
||||
return VK_SAMPLE_COUNT_64_BIT;
|
||||
else if (counts & VK_SAMPLE_COUNT_32_BIT && requestedMsaa >= 32)
|
||||
msaaSamples = VK_SAMPLE_COUNT_32_BIT;
|
||||
return VK_SAMPLE_COUNT_32_BIT;
|
||||
else if (counts & VK_SAMPLE_COUNT_16_BIT && requestedMsaa >= 16)
|
||||
msaaSamples = VK_SAMPLE_COUNT_16_BIT;
|
||||
return VK_SAMPLE_COUNT_16_BIT;
|
||||
else if (counts & VK_SAMPLE_COUNT_8_BIT && requestedMsaa >= 8)
|
||||
msaaSamples = VK_SAMPLE_COUNT_8_BIT;
|
||||
return VK_SAMPLE_COUNT_8_BIT;
|
||||
else if (counts & VK_SAMPLE_COUNT_4_BIT && requestedMsaa >= 4)
|
||||
msaaSamples = VK_SAMPLE_COUNT_4_BIT;
|
||||
return VK_SAMPLE_COUNT_4_BIT;
|
||||
else if (counts & VK_SAMPLE_COUNT_2_BIT && requestedMsaa >= 2)
|
||||
msaaSamples = VK_SAMPLE_COUNT_2_BIT;
|
||||
return VK_SAMPLE_COUNT_2_BIT;
|
||||
else
|
||||
msaaSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
return VK_SAMPLE_COUNT_1_BIT;
|
||||
}
|
||||
|
||||
void Graphics::createColorResources()
|
||||
|
||||
@@ -31,10 +31,13 @@ struct RenderPassAttachment
|
||||
{
|
||||
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||
bool discard = true;
|
||||
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
bool operator==(const RenderPassAttachment &attachment) const
|
||||
{
|
||||
return format == attachment.format && discard == attachment.discard;
|
||||
return format == attachment.format &&
|
||||
discard == attachment.discard &&
|
||||
msaaSamples == attachment.msaaSamples;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,7 +47,6 @@ struct RenderPassConfiguration
|
||||
|
||||
struct StaticRenderPassConfiguration
|
||||
{
|
||||
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
RenderPassAttachment depthAttachment;
|
||||
bool resolve = false;
|
||||
} staticData;
|
||||
@@ -290,6 +292,7 @@ public:
|
||||
std::set<Shader*> &getUsedShadersInFrame();
|
||||
graphics::Shader::BuiltinUniformData getCurrentBuiltinUniformData();
|
||||
const OptionalDeviceFeatures &getEnabledOptionalDeviceExtensions() const;
|
||||
VkSampleCountFlagBits getMsaaCount(int requestedMsaa) const;
|
||||
|
||||
protected:
|
||||
graphics::ShaderStage *newShaderStageInternal(ShaderStageType stage, const std::string &cachekey, const std::string &source, bool gles) override;
|
||||
@@ -304,7 +307,6 @@ private:
|
||||
void createVulkanInstance();
|
||||
bool checkValidationSupport();
|
||||
void pickPhysicalDevice();
|
||||
void getMaxUsableSampleCount();
|
||||
int rateDeviceSuitability(VkPhysicalDevice device);
|
||||
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
|
||||
void createLogicalDevice();
|
||||
|
||||
@@ -55,6 +55,8 @@ bool Texture::loadVolatile()
|
||||
layerCount = 6;
|
||||
createFlags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
|
||||
}
|
||||
|
||||
msaaSamples = vgfx->getMsaaCount(requestedMSAA);
|
||||
|
||||
VkImageCreateInfo imageInfo{};
|
||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
@@ -70,7 +72,7 @@ bool Texture::loadVolatile()
|
||||
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
imageInfo.usage = usageFlags;
|
||||
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageInfo.samples = msaaSamples;
|
||||
|
||||
VmaAllocationCreateInfo imageAllocationCreateInfo{};
|
||||
|
||||
@@ -195,9 +197,14 @@ VkImageView Texture::getRenderTargetView(int mip, int layer)
|
||||
return renderTargetImageViews.at(mip).at(layer);
|
||||
}
|
||||
|
||||
VkSampleCountFlagBits Texture::getMsaaSamples() const
|
||||
{
|
||||
return msaaSamples;
|
||||
}
|
||||
|
||||
int Texture::getMSAA() const
|
||||
{
|
||||
return 0;
|
||||
return static_cast<int>(msaaSamples);
|
||||
}
|
||||
|
||||
ptrdiff_t Texture::getHandle() const
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
ptrdiff_t getSamplerHandle() const override;
|
||||
|
||||
VkImageView getRenderTargetView(int mip, int layer);
|
||||
VkSampleCountFlagBits getMsaaSamples() const;
|
||||
|
||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r) override;
|
||||
|
||||
@@ -62,6 +63,7 @@ private:
|
||||
VkSampler textureSampler = VK_NULL_HANDLE;
|
||||
Slices slices;
|
||||
int layerCount = 0;
|
||||
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
};
|
||||
|
||||
} // vulkan
|
||||
|
||||
Reference in New Issue
Block a user