2022-03-19 03:14:55 -04:00
|
|
|
#include "ge_vulkan_features.hpp"
|
|
|
|
|
|
|
|
#include "ge_vulkan_driver.hpp"
|
2022-03-20 01:35:22 -04:00
|
|
|
#include "ge_vulkan_shader_manager.hpp"
|
2022-03-19 03:14:55 -04:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "../source/Irrlicht/os.h"
|
|
|
|
|
|
|
|
namespace GE
|
|
|
|
{
|
|
|
|
namespace GEVulkanFeatures
|
|
|
|
{
|
|
|
|
// ============================================================================
|
2022-03-20 01:35:22 -04:00
|
|
|
bool g_supports_bind_textures_at_once = false;
|
2022-03-19 03:14:55 -04:00
|
|
|
// https://chunkstories.xyz/blog/a-note-on-descriptor-indexing
|
|
|
|
bool g_supports_descriptor_indexing = false;
|
|
|
|
bool g_supports_non_uniform_indexing = false;
|
|
|
|
bool g_supports_partially_bound = false;
|
|
|
|
} // GEVulkanFeatures
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
void GEVulkanFeatures::init(GEVulkanDriver* vk)
|
|
|
|
{
|
2022-03-20 01:35:22 -04:00
|
|
|
g_supports_bind_textures_at_once = true;
|
|
|
|
VkPhysicalDeviceLimits limit = vk->getPhysicalDeviceProperties().limits;
|
|
|
|
// https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxDescriptorSetSamplers&platform=all
|
|
|
|
// https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxDescriptorSetSampledImages&platform=all
|
|
|
|
// https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxPerStageDescriptorSamplers&platform=all
|
|
|
|
// https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxPerStageDescriptorSampledImages&platform=all
|
|
|
|
// We decide 256 (GEVulkanShaderManager::getSamplerSize()) based on those infos
|
|
|
|
if (limit.maxDescriptorSetSamplers < GEVulkanShaderManager::getSamplerSize())
|
|
|
|
g_supports_bind_textures_at_once = false;
|
|
|
|
if (limit.maxDescriptorSetSampledImages < GEVulkanShaderManager::getSamplerSize())
|
|
|
|
g_supports_bind_textures_at_once = false;
|
|
|
|
if (limit.maxPerStageDescriptorSamplers < GEVulkanShaderManager::getSamplerSize())
|
|
|
|
g_supports_bind_textures_at_once = false;
|
|
|
|
if (limit.maxPerStageDescriptorSampledImages < GEVulkanShaderManager::getSamplerSize())
|
|
|
|
g_supports_bind_textures_at_once = false;
|
|
|
|
if (vk->getPhysicalDeviceFeatures().shaderSampledImageArrayDynamicIndexing == VK_FALSE)
|
|
|
|
g_supports_bind_textures_at_once = false;
|
|
|
|
|
2022-03-19 03:14:55 -04:00
|
|
|
uint32_t extension_count;
|
|
|
|
vkEnumerateDeviceExtensionProperties(vk->getPhysicalDevice(), NULL,
|
|
|
|
&extension_count, NULL);
|
|
|
|
std::vector<VkExtensionProperties> extensions(extension_count);
|
|
|
|
vkEnumerateDeviceExtensionProperties(vk->getPhysicalDevice(), NULL,
|
|
|
|
&extension_count, &extensions[0]);
|
|
|
|
|
|
|
|
for (VkExtensionProperties& prop : extensions)
|
|
|
|
{
|
|
|
|
if (std::string(prop.extensionName) == "VK_EXT_descriptor_indexing")
|
|
|
|
g_supports_descriptor_indexing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPhysicalDeviceFeatures2 supported_features = {};
|
|
|
|
supported_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
|
|
|
VkPhysicalDeviceDescriptorIndexingFeatures descriptor_indexing_features = {};
|
|
|
|
descriptor_indexing_features.sType =
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES;
|
|
|
|
supported_features.pNext = &descriptor_indexing_features;
|
|
|
|
|
2022-04-02 21:55:17 -04:00
|
|
|
if (vk->getPhysicalDeviceProperties().apiVersion < VK_API_VERSION_1_1 ||
|
|
|
|
!vkGetPhysicalDeviceFeatures2)
|
2022-03-19 03:14:55 -04:00
|
|
|
return;
|
|
|
|
vkGetPhysicalDeviceFeatures2(vk->getPhysicalDevice(), &supported_features);
|
|
|
|
if (supported_features.sType !=
|
|
|
|
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_supports_non_uniform_indexing = (descriptor_indexing_features
|
|
|
|
.shaderSampledImageArrayNonUniformIndexing == VK_TRUE);
|
|
|
|
g_supports_partially_bound = (descriptor_indexing_features
|
|
|
|
.descriptorBindingPartiallyBound == VK_TRUE);
|
|
|
|
} // init
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void GEVulkanFeatures::printStats()
|
|
|
|
{
|
2022-03-20 01:35:22 -04:00
|
|
|
os::Printer::log(
|
|
|
|
"Vulkan can bind textures at once in shader",
|
|
|
|
g_supports_bind_textures_at_once ? "true" : "false");
|
2022-03-19 03:14:55 -04:00
|
|
|
os::Printer::log(
|
|
|
|
"Vulkan supports VK_EXT_descriptor_indexing",
|
|
|
|
g_supports_descriptor_indexing ? "true" : "false");
|
|
|
|
os::Printer::log(
|
|
|
|
"Vulkan descriptor indexes can be dynamically non-uniform",
|
|
|
|
g_supports_non_uniform_indexing ? "true" : "false");
|
|
|
|
os::Printer::log(
|
|
|
|
"Vulkan descriptor can be partially bound",
|
|
|
|
g_supports_partially_bound ? "true" : "false");
|
|
|
|
} // printStats
|
|
|
|
|
2022-03-20 01:35:22 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool GEVulkanFeatures::supportsBindTexturesAtOnce()
|
|
|
|
{
|
|
|
|
return g_supports_bind_textures_at_once;
|
|
|
|
} // supportsBindTexturesAtOnce
|
|
|
|
|
2022-03-19 03:14:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool GEVulkanFeatures::supportsDescriptorIndexing()
|
|
|
|
{
|
|
|
|
return g_supports_descriptor_indexing;
|
|
|
|
} // supportsDescriptorIndexing
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool GEVulkanFeatures::supportsNonUniformIndexing()
|
|
|
|
{
|
|
|
|
return g_supports_non_uniform_indexing;
|
|
|
|
} // supportsNonUniformIndexing
|
|
|
|
|
2022-03-19 04:09:32 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool GEVulkanFeatures::supportsDifferentTexturePerDraw()
|
|
|
|
{
|
2022-03-20 01:35:22 -04:00
|
|
|
return g_supports_bind_textures_at_once &&
|
|
|
|
g_supports_descriptor_indexing && g_supports_non_uniform_indexing;
|
2022-03-19 04:09:32 -04:00
|
|
|
} // supportsDifferentTexturePerDraw
|
|
|
|
|
2022-03-19 03:14:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool GEVulkanFeatures::supportsPartiallyBound()
|
|
|
|
{
|
|
|
|
return g_supports_partially_bound;
|
|
|
|
} // supportsPartiallyBound
|
|
|
|
|
|
|
|
}
|