From 5ebcd32a284a7c2cc79e4a88349d66b392f13d52 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 23 Mar 2019 19:38:45 -0700 Subject: Disabling requested vulkand device features if they are not supported by physical device --- .../include/VulkanUtilities/VulkanPhysicalDevice.h | 1 + .../GraphicsEngineVulkan/src/EngineFactoryVk.cpp | 48 +++++++++++++++------- .../src/RenderDeviceVkImpl.cpp | 7 +--- 3 files changed, 36 insertions(+), 20 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h index df31c2e1..7056268f 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.h @@ -47,6 +47,7 @@ namespace VulkanUtilities static constexpr uint32_t InvalidMemoryTypeIndex = static_cast(-1); uint32_t GetMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties)const; const VkPhysicalDeviceProperties& GetProperties() const {return m_Properties;} + const VkPhysicalDeviceFeatures& GetFeatures() const {return m_Features; } private: VulkanPhysicalDevice(VkPhysicalDevice vkDevice); diff --git a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp index 7f5a4fee..40db1ccf 100644 --- a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp @@ -83,7 +83,7 @@ public: /// the contexts will be written. Immediate context goes at /// position 0. If EngineCI.NumDeferredContexts > 0, /// pointers to the deferred contexts are written afterwards. -void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& EngineCI, +void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& _EngineCI, IRenderDevice** ppDevice, IDeviceContext** ppContexts) { @@ -91,6 +91,8 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En if( !ppDevice || !ppContexts ) return; + EngineVkCreateInfo EngineCI = _EngineCI; + #if 0 for (Uint32 Type = Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; Type < Vk_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++Type) { @@ -125,6 +127,7 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En auto vkDevice = Instance->SelectPhysicalDevice(); auto PhysicalDevice = VulkanUtilities::VulkanPhysicalDevice::Create(vkDevice); + const auto& PhysicalDeviceFeatures = PhysicalDevice->GetFeatures(); // If an implementation exposes any queue family that supports graphics operations, // at least one queue family of at least one physical device exposed by the implementation @@ -151,20 +154,35 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En DeviceCreateInfo.queueCreateInfoCount = 1; DeviceCreateInfo.pQueueCreateInfos = &QueueInfo; VkPhysicalDeviceFeatures DeviceFeatures = {}; - DeviceFeatures.depthBiasClamp = EngineCI.EnabledFeatures.depthBiasClamp ? VK_TRUE : VK_FALSE; - DeviceFeatures.fillModeNonSolid = EngineCI.EnabledFeatures.fillModeNonSolid ? VK_TRUE : VK_FALSE; - DeviceFeatures.depthClamp = EngineCI.EnabledFeatures.depthClamp ? VK_TRUE : VK_FALSE; - DeviceFeatures.independentBlend = EngineCI.EnabledFeatures.independentBlend ? VK_TRUE : VK_FALSE; - DeviceFeatures.samplerAnisotropy = EngineCI.EnabledFeatures.samplerAnisotropy ? VK_TRUE : VK_FALSE; - DeviceFeatures.geometryShader = EngineCI.EnabledFeatures.geometryShader ? VK_TRUE : VK_FALSE; - DeviceFeatures.tessellationShader = EngineCI.EnabledFeatures.tessellationShader ? VK_TRUE : VK_FALSE; - DeviceFeatures.dualSrcBlend = EngineCI.EnabledFeatures.dualSrcBlend ? VK_TRUE : VK_FALSE; - DeviceFeatures.multiViewport = EngineCI.EnabledFeatures.multiViewport ? VK_TRUE : VK_FALSE; - DeviceFeatures.imageCubeArray = EngineCI.EnabledFeatures.imageCubeArray ? VK_TRUE : VK_FALSE; - DeviceFeatures.textureCompressionBC = EngineCI.EnabledFeatures.textureCompressionBC ? VK_TRUE : VK_FALSE; - DeviceFeatures.vertexPipelineStoresAndAtomics = EngineCI.EnabledFeatures.vertexPipelineStoresAndAtomics ? VK_TRUE : VK_FALSE; - DeviceFeatures.fragmentStoresAndAtomics = EngineCI.EnabledFeatures.fragmentStoresAndAtomics ? VK_TRUE : VK_FALSE; - DeviceFeatures.shaderStorageImageExtendedFormats = EngineCI.EnabledFeatures.shaderStorageImageExtendedFormats ? VK_TRUE : VK_FALSE; + +#define ENABLE_FEATURE(Feature)\ + if (EngineCI.EnabledFeatures.Feature)\ + { \ + if (PhysicalDeviceFeatures.Feature) \ + DeviceFeatures.Feature = VK_TRUE; \ + else \ + { \ + LOG_WARNING_MESSAGE("Requested device feature " #Feature " is not supported by the physical device and will be disabled");\ + EngineCI.EnabledFeatures.Feature = false; \ + } \ + } + + ENABLE_FEATURE(depthBiasClamp) + ENABLE_FEATURE(fillModeNonSolid) + ENABLE_FEATURE(depthClamp) + ENABLE_FEATURE(independentBlend) + ENABLE_FEATURE(samplerAnisotropy) + ENABLE_FEATURE(geometryShader) + ENABLE_FEATURE(tessellationShader) + ENABLE_FEATURE(dualSrcBlend) + ENABLE_FEATURE(multiViewport) + ENABLE_FEATURE(imageCubeArray) + ENABLE_FEATURE(textureCompressionBC) + ENABLE_FEATURE(vertexPipelineStoresAndAtomics) + ENABLE_FEATURE(fragmentStoresAndAtomics) + ENABLE_FEATURE(shaderStorageImageExtendedFormats) +#undef ENABLE_FEATURE + DeviceCreateInfo.pEnabledFeatures = &DeviceFeatures; // NULL or a pointer to a VkPhysicalDeviceFeatures structure that contains // boolean indicators of all the features to be enabled. diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 2870b0d4..e31acc55 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -126,11 +126,8 @@ RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters* for(int fmt = 1; fmt < m_TextureFormatsInfo.size(); ++fmt) m_TextureFormatsInfo[fmt].Supported = true; // We will test every format on a specific hardware device -#if PLATFORM_MACOS || PLATFORM_IOS - // MoltenVK does not support geometry shaders and tessellation - m_DeviceCaps.bGeometryShadersSupported = False; - m_DeviceCaps.bTessellationSupported = False; -#endif + m_DeviceCaps.bGeometryShadersSupported = EngineCI.EnabledFeatures.geometryShader; + m_DeviceCaps.bTessellationSupported = EngineCI.EnabledFeatures.tessellationShader; } RenderDeviceVkImpl::~RenderDeviceVkImpl() -- cgit v1.2.3