优化 MSAA
This commit is contained in:
parent
2f16c0b5e4
commit
d82fc95584
|
|
@ -225,11 +225,34 @@ uint32_t VulkanRenderer::getMaxUsableSampleCount()
|
||||||
VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts &
|
VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts &
|
||||||
physicalDeviceProperties.limits.framebufferDepthSampleCounts;
|
physicalDeviceProperties.limits.framebufferDepthSampleCounts;
|
||||||
|
|
||||||
// Try to use 4x MSAA as a good balance between quality and performance
|
std::cout << "Available MSAA sample counts: ";
|
||||||
if (counts & VK_SAMPLE_COUNT_8_BIT) { return VK_SAMPLE_COUNT_8_BIT; }
|
if (counts & VK_SAMPLE_COUNT_64_BIT) std::cout << "64 ";
|
||||||
if (counts & VK_SAMPLE_COUNT_4_BIT) { return VK_SAMPLE_COUNT_4_BIT; }
|
if (counts & VK_SAMPLE_COUNT_32_BIT) std::cout << "32 ";
|
||||||
if (counts & VK_SAMPLE_COUNT_2_BIT) { return VK_SAMPLE_COUNT_2_BIT; }
|
if (counts & VK_SAMPLE_COUNT_16_BIT) std::cout << "16 ";
|
||||||
|
if (counts & VK_SAMPLE_COUNT_8_BIT) std::cout << "8 ";
|
||||||
|
if (counts & VK_SAMPLE_COUNT_4_BIT) std::cout << "4 ";
|
||||||
|
if (counts & VK_SAMPLE_COUNT_2_BIT) std::cout << "2 ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
// Prefer higher sample counts for better quality
|
||||||
|
if (counts & VK_SAMPLE_COUNT_16_BIT) {
|
||||||
|
std::cout << "Selected: 16x MSAA" << std::endl;
|
||||||
|
return VK_SAMPLE_COUNT_16_BIT;
|
||||||
|
}
|
||||||
|
if (counts & VK_SAMPLE_COUNT_8_BIT) {
|
||||||
|
std::cout << "Selected: 8x MSAA" << std::endl;
|
||||||
|
return VK_SAMPLE_COUNT_8_BIT;
|
||||||
|
}
|
||||||
|
if (counts & VK_SAMPLE_COUNT_4_BIT) {
|
||||||
|
std::cout << "Selected: 4x MSAA" << std::endl;
|
||||||
|
return VK_SAMPLE_COUNT_4_BIT;
|
||||||
|
}
|
||||||
|
if (counts & VK_SAMPLE_COUNT_2_BIT) {
|
||||||
|
std::cout << "Selected: 2x MSAA" << std::endl;
|
||||||
|
return VK_SAMPLE_COUNT_2_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "No MSAA support available" << std::endl;
|
||||||
return VK_SAMPLE_COUNT_1_BIT;
|
return VK_SAMPLE_COUNT_1_BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -935,7 +958,8 @@ bool VulkanRenderer::createBackgroundPipeline()
|
||||||
// Multisampling
|
// Multisampling
|
||||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||||
multisampling.sampleShadingEnable = VK_FALSE;
|
multisampling.sampleShadingEnable = VK_TRUE; // Enable sample shading for better quality
|
||||||
|
multisampling.minSampleShading = 0.5f; // Minimum fraction for sample shading
|
||||||
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
||||||
|
|
||||||
// Color blending
|
// Color blending
|
||||||
|
|
@ -1101,7 +1125,8 @@ bool VulkanRenderer::createGeometryPipeline()
|
||||||
|
|
||||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||||
multisampling.sampleShadingEnable = VK_FALSE;
|
multisampling.sampleShadingEnable = VK_TRUE; // Enable sample shading for better quality
|
||||||
|
multisampling.minSampleShading = 0.5f; // Minimum fraction for sample shading
|
||||||
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
||||||
|
|
||||||
// Enable alpha blending
|
// Enable alpha blending
|
||||||
|
|
@ -1262,7 +1287,8 @@ bool VulkanRenderer::createLinePipeline()
|
||||||
|
|
||||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||||
multisampling.sampleShadingEnable = VK_FALSE;
|
multisampling.sampleShadingEnable = VK_TRUE; // Enable sample shading for smoother lines
|
||||||
|
multisampling.minSampleShading = 0.75f; // Higher quality for lines
|
||||||
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
||||||
|
|
||||||
// Enable alpha blending
|
// Enable alpha blending
|
||||||
|
|
@ -1441,7 +1467,8 @@ bool VulkanRenderer::createTextPipeline()
|
||||||
|
|
||||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||||
multisampling.sampleShadingEnable = VK_FALSE;
|
multisampling.sampleShadingEnable = VK_TRUE; // Enable sample shading for smoother text
|
||||||
|
multisampling.minSampleShading = 1.0f; // Maximum quality for text rendering
|
||||||
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
multisampling.rasterizationSamples = static_cast<VkSampleCountFlagBits>(m_msaaSamples);
|
||||||
|
|
||||||
// Enable alpha blending for text
|
// Enable alpha blending for text
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,25 @@ bool VulkanWidget::createDevice()
|
||||||
queueCreateInfo.queueCount = 1;
|
queueCreateInfo.queueCount = 1;
|
||||||
queueCreateInfo.pQueuePriorities = &queuePriority;
|
queueCreateInfo.pQueuePriorities = &queuePriority;
|
||||||
|
|
||||||
|
// Query supported features first
|
||||||
|
VkPhysicalDeviceFeatures supportedFeatures;
|
||||||
|
vkGetPhysicalDeviceFeatures(m_physicalDevice, &supportedFeatures);
|
||||||
|
|
||||||
VkPhysicalDeviceFeatures deviceFeatures = {};
|
VkPhysicalDeviceFeatures deviceFeatures = {};
|
||||||
|
|
||||||
|
// Enable sample rate shading for better MSAA quality
|
||||||
|
if (supportedFeatures.sampleRateShading) {
|
||||||
|
deviceFeatures.sampleRateShading = VK_TRUE;
|
||||||
|
qDebug() << "Sample rate shading feature enabled";
|
||||||
|
} else {
|
||||||
|
qDebug() << "Sample rate shading not supported by device";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable wide lines if supported (for smoother line rendering)
|
||||||
|
if (supportedFeatures.wideLines) {
|
||||||
|
deviceFeatures.wideLines = VK_TRUE;
|
||||||
|
qDebug() << "Wide lines feature enabled";
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<const char*> deviceExtensions = getRequiredDeviceExtensions();
|
std::vector<const char*> deviceExtensions = getRequiredDeviceExtensions();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue