Browse Source

Vk: fetching of supported device features.

This is what I needed BigEnumSet for -- good thing I didn't even try to
have 128-bit enums because I'm now at 110 values and it's still far from
complete. Next step is enabling those features when creating a device,
which should hopefully be a lot less code, reusing most of what was
here.
pull/491/head
Vladimír Vondruš 5 years ago
parent
commit
1ee2b40c53
  1. 47
      doc/vulkan-mapping.dox
  2. 2
      doc/vulkan-support.dox
  3. 4
      src/Magnum/Vk/CMakeLists.txt
  4. 63
      src/Magnum/Vk/DeviceFeatures.cpp
  5. 1032
      src/Magnum/Vk/DeviceFeatures.h
  6. 97
      src/Magnum/Vk/DeviceProperties.cpp
  7. 89
      src/Magnum/Vk/DeviceProperties.h
  8. 61
      src/Magnum/Vk/Implementation/DeviceFeatures.h
  9. 186
      src/Magnum/Vk/Implementation/deviceFeatureMapping.hpp
  10. 2
      src/Magnum/Vk/Test/CMakeLists.txt
  11. 110
      src/Magnum/Vk/Test/DeviceFeaturesTest.cpp
  12. 71
      src/Magnum/Vk/Test/DevicePropertiesVkTest.cpp
  13. 2
      src/Magnum/Vk/Vk.h

47
doc/vulkan-mapping.dox

@ -205,7 +205,7 @@ Vulkan function | Matching API
@fn_vk{GetPhysicalDeviceExternalBufferProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@fn_vk{GetPhysicalDeviceExternalFenceProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@fn_vk{GetPhysicalDeviceExternalSemaphoreProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@fn_vk{GetPhysicalDeviceFeatures}, \n @fn_vk{GetPhysicalDeviceFeatures2} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@fn_vk{GetPhysicalDeviceFeatures}, \n @fn_vk{GetPhysicalDeviceFeatures2} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceProperties::features()
@fn_vk{GetPhysicalDeviceFormatProperties}, \n @fn_vk{GetPhysicalDeviceFormatProperties2} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@fn_vk{GetPhysicalDeviceImageFormatProperties}, \n @fn_vk{GetPhysicalDeviceImageFormatProperties2} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@fn_vk{GetPhysicalDeviceMemoryProperties}, \n @fn_vk{GetPhysicalDeviceMemoryProperties2} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceProperties::memoryProperties()
@ -499,56 +499,55 @@ Vulkan structure | Matching API
Vulkan structure | Matching API
--------------------------------------- | ------------
@type_vk{PhysicalDevice8bitStorageFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDevice16bitStorageFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceBufferDeviceAddressFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDevice8bitStorageFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDevice16bitStorageFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceBufferDeviceAddressFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceDepthStencilResolveProperties} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceDescriptorIndexingFeatures} @m_class{m-label m-flat m-success} **EXT, 1.2** | |
@type_vk{PhysicalDeviceDescriptorIndexingFeatures} @m_class{m-label m-flat m-success} **EXT, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceDescriptorIndexingProperties} @m_class{m-label m-flat m-success} **EXT, 1.2** | |
@type_vk{PhysicalDeviceDriverProperties} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceExternalBufferInfo} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceExternalFenceInfo} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceExternalImageFormatInfo} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceExternalSemaphoreInfo} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceFeatures}, \n @type_vk{PhysicalDeviceFeatures2} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceFloat16Int8Features} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceFeatures}, \n @type_vk{PhysicalDeviceFeatures2} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceFloatControlsProperties} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceGroupProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceHostQueryResetFeatures} @m_class{m-label m-flat m-success} **EXT, 1.2** | |
@type_vk{PhysicalDeviceHostQueryResetFeatures} @m_class{m-label m-flat m-success} **EXT, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceIDProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceImageFormatInfo2} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceImagelessFramebufferFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceIndexTypeUint8FeaturesEXT} @m_class{m-label m-flat m-warning} **EXT** | |
@type_vk{PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT} @m_class{m-label m-flat m-warning} **EXT** | |
@type_vk{PhysicalDeviceImagelessFramebufferFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceIndexTypeUint8FeaturesEXT} @m_class{m-label m-flat m-warning} **EXT** | @ref DeviceFeatures
@type_vk{PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT} @m_class{m-label m-flat m-warning} **EXT** | @ref DeviceFeatures
@type_vk{PhysicalDeviceLimits} | |
@type_vk{PhysicalDeviceMaintenance3Properties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceMemoryProperties}, \n @type_vk{PhysicalDeviceMemoryProperties2} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceProperties
@type_vk{PhysicalDeviceMultiviewFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceMultiviewFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceMultiviewProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDevicePointClippingProperties} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceProperties}, \n @type_vk{PhysicalDeviceProperties2} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceProperties
@type_vk{PhysicalDeviceProtectedMemoryFeatures} @m_class{m-label m-flat m-success} **1.1** | |
@type_vk{PhysicalDeviceProtectedMemoryFeatures} @m_class{m-label m-flat m-success} **1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceProtectedMemoryProperties} @m_class{m-label m-flat m-success} **1.1** | |
@type_vk{PhysicalDeviceSamplerFilterMinmaxProperties} @m_class{m-label m-flat m-success} **EXT, 1.2** | |
@type_vk{PhysicalDeviceSamplerYcbcrConversionFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceSeparateDepthStencilLayoutsFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceScalarBlockLayoutFeatures} @m_class{m-label m-flat m-success} **EXT, 1.2** | |
@type_vk{PhysicalDeviceShaderAtomicInt64Features} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceShaderDrawParametersFeatures} @m_class{m-label m-flat m-success} **1.1** | |
@type_vk{PhysicalDeviceShaderFloat16Int8Features} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceShaderSubgroupExtendedTypesFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceSamplerYcbcrConversionFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceSeparateDepthStencilLayoutsFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceScalarBlockLayoutFeatures} @m_class{m-label m-flat m-success} **EXT, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceShaderAtomicInt64Features} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceShaderDrawParametersFeatures} @m_class{m-label m-flat m-success} **1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceShaderFloat16Int8Features} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceShaderSubgroupExtendedTypesFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceSparseImageFormatInfo2} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceSparseProperties} | |
@type_vk{PhysicalDeviceSubgroupProperties} @m_class{m-label m-flat m-success} **1.1** | |
@type_vk{PhysicalDeviceTimelineSemaphoreFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceTimelineSemaphoreFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceTimelineSemaphoreProperties} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceUniformBufferStandardLayoutFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceVariablePointersFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | |
@type_vk{PhysicalDeviceUniformBufferStandardLayoutFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PhysicalDeviceVariablePointersFeatures} @m_class{m-label m-flat m-success} **KHR, 1.1** | @ref DeviceFeatures
@type_vk{PhysicalDeviceVulkan11Features} @m_class{m-label m-flat m-success} **1.2** | ignored for compatibility reasons
@type_vk{PhysicalDeviceVulkan11Properties} @m_class{m-label m-flat m-success} **1.2** | ignored for compatibility reasons
@type_vk{PhysicalDeviceVulkan12Features} @m_class{m-label m-flat m-success} **1.2** | ignored for compatibility reasons
@type_vk{PhysicalDeviceVulkan12Properties} @m_class{m-label m-flat m-success} **1.2** | ignored for compatibility reasons
@type_vk{PhysicalDeviceVulkanMemoryModelFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | |
@type_vk{PhysicalDeviceVulkanMemoryModelFeatures} @m_class{m-label m-flat m-success} **KHR, 1.2** | @ref DeviceFeatures
@type_vk{PipelineCacheCreateInfo} | |
@type_vk{PipelineColorBlendAttachmentState} | |
@type_vk{PipelineColorBlendStateCreateInfo} | |

2
doc/vulkan-support.dox

@ -55,7 +55,7 @@ See the @ref vulkan-mapping page for a list of already implemented functions.
Extension | Status
--------------------------------------------------- | ------
@vk_extension{KHR,multiview} | |
@vk_extension{KHR,get_physical_device_properties2} @m_class{m-label m-info} **instance** | device, memory and queue properties only
@vk_extension{KHR,get_physical_device_properties2} @m_class{m-label m-info} **instance** | device, feature, memory and queue properties only
@vk_extension{KHR,device_group} | |
@vk_extension{KHR,shader_draw_parameters} | |
@vk_extension{KHR,maintenance1} | |

4
src/Magnum/Vk/CMakeLists.txt

@ -44,6 +44,7 @@ set(MagnumVk_GracefulAssert_SRCS
Buffer.cpp
Device.cpp
DeviceProperties.cpp
DeviceFeatures.cpp
Enums.cpp
ExtensionProperties.cpp
Image.cpp
@ -60,6 +61,7 @@ set(MagnumVk_HEADERS
CommandPoolCreateInfo.h
Device.h
DeviceCreateInfo.h
DeviceFeatures.h
DeviceProperties.h
Enums.h
Extensions.h
@ -88,10 +90,12 @@ set(MagnumVk_HEADERS
set(MagnumVk_PRIVATE_HEADERS
Implementation/Arguments.h
Implementation/DeviceFeatures.h
Implementation/DeviceState.h
Implementation/InstanceState.h
Implementation/compressedPixelFormatMapping.hpp
Implementation/deviceFeatureMapping.hpp
Implementation/pixelFormatMapping.hpp
Implementation/structureHelpers.h
Implementation/vertexFormatMapping.hpp)

63
src/Magnum/Vk/DeviceFeatures.cpp

@ -0,0 +1,63 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "DeviceFeatures.h"
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/BigEnumSet.hpp>
namespace Magnum { namespace Vk {
namespace {
#ifndef DOXYGEN_GENERATING_OUTPUT /* It gets *really* confused */
constexpr const char* FeatureNames[] {
#define _c(value, field) #value,
#define _cver(value, field, suffix, version) _c(value, field)
#define _cext(value, field, suffix, extension) _c(value, field)
#include "Magnum/Vk/Implementation/deviceFeatureMapping.hpp"
#undef _c
#undef _cver
#undef _cext
};
#endif
}
Debug& operator<<(Debug& debug, const DeviceFeature value) {
debug << "Vk::DeviceFeature" << Debug::nospace;
if(UnsignedInt(value) < Containers::arraySize(FeatureNames)) {
return debug << "::" << Debug::nospace << FeatureNames[UnsignedInt(value)];
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const DeviceFeatures& value) {
return Containers::bigEnumSetDebugOutput(debug, value, "Vk::DeviceFeatures{}");
}
}}

1032
src/Magnum/Vk/DeviceFeatures.h

File diff suppressed because it is too large Load Diff

97
src/Magnum/Vk/DeviceProperties.cpp

@ -35,6 +35,7 @@
#include "Magnum/Math/Functions.h"
#include "Magnum/Vk/Assert.h"
#include "Magnum/Vk/DeviceFeatures.h"
#include "Magnum/Vk/ExtensionProperties.h"
#include "Magnum/Vk/Extensions.h"
#include "Magnum/Vk/Instance.h"
@ -42,6 +43,7 @@
#include "Magnum/Vk/Memory.h"
#include "Magnum/Vk/Version.h"
#include "Magnum/Vk/Implementation/Arguments.h"
#include "Magnum/Vk/Implementation/DeviceFeatures.h"
#include "Magnum/Vk/Implementation/InstanceState.h"
#include "Magnum/Vk/Implementation/structureHelpers.h"
@ -56,6 +58,7 @@ struct DeviceProperties::State {
Containers::Optional<ExtensionProperties> extensions;
void(*getPropertiesImplementation)(DeviceProperties&, VkPhysicalDeviceProperties2&);
void(*getFeaturesImplementation)(DeviceProperties&, VkPhysicalDeviceFeatures2&);
void(*getQueueFamilyPropertiesImplementation)(DeviceProperties&, UnsignedInt&, VkQueueFamilyProperties2*);
void(*getMemoryPropertiesImplementation)(DeviceProperties&, VkPhysicalDeviceMemoryProperties2&);
@ -63,6 +66,11 @@ struct DeviceProperties::State {
VkPhysicalDeviceDriverProperties driverProperties{};
VkPhysicalDeviceMemoryProperties2 memoryProperties{};
Containers::Array<VkQueueFamilyProperties2> queueFamilyProperties;
/* Not storing (a chain of) VkPhysicalDeviceFeatures structures, because
those are >32x larger than necessary and extremely annoying to operate
with. Using a big enum set instead. */
DeviceFeatures features;
};
DeviceProperties::State::State(Instance& instance, const VkPhysicalDevice handle) {
@ -117,14 +125,17 @@ DeviceProperties::State::State(Instance& instance, const VkPhysicalDevice handle
/* Have to check both the instance and device version, see above */
if(instance.isVersionSupported(Version::Vk11) && Version(properties.properties.apiVersion) >= Version::Vk11) {
getPropertiesImplementation = &DeviceProperties::getPropertiesImplementation11;
getFeaturesImplementation = &DeviceProperties::getFeaturesImplementation11;
getQueueFamilyPropertiesImplementation = &DeviceProperties::getQueueFamilyPropertiesImplementation11;
getMemoryPropertiesImplementation = &DeviceProperties::getMemoryPropertiesImplementation11;
} else if(instance.isExtensionEnabled<Extensions::KHR::get_physical_device_properties2>()) {
getPropertiesImplementation = &DeviceProperties::getPropertiesImplementationKHR;
getFeaturesImplementation = &DeviceProperties::getFeaturesImplementationKHR;
getQueueFamilyPropertiesImplementation = &DeviceProperties::getQueueFamilyPropertiesImplementationKHR;
getMemoryPropertiesImplementation = &DeviceProperties::getMemoryPropertiesImplementationKHR;
} else {
getPropertiesImplementation = DeviceProperties::getPropertiesImplementationDefault;
getFeaturesImplementation = &DeviceProperties::getFeaturesImplementationDefault;
getQueueFamilyPropertiesImplementation = &DeviceProperties::getQueueFamilyPropertiesImplementationDefault;
getMemoryPropertiesImplementation = &DeviceProperties::getMemoryPropertiesImplementationDefault;
}
@ -214,6 +225,18 @@ void DeviceProperties::getPropertiesImplementation11(DeviceProperties& self, VkP
return (**self._instance).GetPhysicalDeviceProperties2(self._handle, &properties);
}
void DeviceProperties::getFeaturesImplementationDefault(DeviceProperties& self, VkPhysicalDeviceFeatures2& features) {
return (**self._instance).GetPhysicalDeviceFeatures(self._handle, &features.features);
}
void DeviceProperties::getFeaturesImplementationKHR(DeviceProperties& self, VkPhysicalDeviceFeatures2& features) {
return (**self._instance).GetPhysicalDeviceFeatures2KHR(self._handle, &features);
}
void DeviceProperties::getFeaturesImplementation11(DeviceProperties& self, VkPhysicalDeviceFeatures2& features) {
return (**self._instance).GetPhysicalDeviceFeatures2(self._handle, &features);
}
ExtensionProperties DeviceProperties::enumerateExtensionProperties(Containers::ArrayView<const Containers::StringView> layers) {
return InstanceExtensionProperties{layers, [](void* state, const char* const layer, UnsignedInt* count, VkExtensionProperties* properties) {
auto& deviceProperties = *static_cast<DeviceProperties*>(state);
@ -236,6 +259,80 @@ template<class E> bool DeviceProperties::isOrVersionSupportedInternal() {
return extensionPropertiesInternal().isSupported<E>();
}
const DeviceFeatures& DeviceProperties::features() {
if(!_state) _state.emplace(*_instance, _handle);
/* If a device doesn't support *any* feature, this will be fetched always.
That's rather rare though. */
if(!_state->features) {
VkPhysicalDeviceFeatures2 features2{};
Implementation::DeviceFeatures features{};
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
Containers::Reference<void*> next = features2.pNext;
/* Fetch extra features, if supported */
if(isVersionSupported(Version::Vk11))
Implementation::structureConnect(next, features.protectedMemory, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::multiview>())
Implementation::structureConnect(next, features.multiview, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::shader_draw_parameters>())
Implementation::structureConnect(next, features.shaderDrawParameters, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES);
if(isOrVersionSupportedInternal<Extensions::EXT::texture_compression_astc_hdr>())
Implementation::structureConnect(next, features.textureCompressionAstcHdr, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXTURE_COMPRESSION_ASTC_HDR_FEATURES_EXT);
if(isOrVersionSupportedInternal<Extensions::KHR::shader_float16_int8>())
Implementation::structureConnect(next, features.shaderFloat16Int8, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::_16bit_storage>())
Implementation::structureConnect(next, features._16BitStorage, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::imageless_framebuffer>())
Implementation::structureConnect(next, features.imagelessFramebuffer, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::variable_pointers>())
Implementation::structureConnect(next, features.variablePointers, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::sampler_ycbcr_conversion>())
Implementation::structureConnect(next, features.samplerYcbcrConversion, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES);
if(isOrVersionSupportedInternal<Extensions::EXT::descriptor_indexing>())
Implementation::structureConnect(next, features.descriptorIndexing, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::shader_subgroup_extended_types>())
Implementation::structureConnect(next, features.shaderSubgroupExtendedTypes, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::_8bit_storage>())
Implementation::structureConnect(next, features._8BitStorage, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::shader_atomic_int64>())
Implementation::structureConnect(next, features.shaderAtomicInt64, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::timeline_semaphore>())
Implementation::structureConnect(next, features.timelineSemaphore, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::vulkan_memory_model>())
Implementation::structureConnect(next, features.vulkanMemoryModel, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES);
if(isOrVersionSupportedInternal<Extensions::EXT::scalar_block_layout>())
Implementation::structureConnect(next, features.scalarBlockLayout, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::separate_depth_stencil_layouts>())
Implementation::structureConnect(next, features.separateDepthStencilLayouts, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::uniform_buffer_standard_layout>())
Implementation::structureConnect(next, features.uniformBufferStandardLayout, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES);
if(isOrVersionSupportedInternal<Extensions::KHR::buffer_device_address>())
Implementation::structureConnect(next, features.bufferDeviceAddress, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES);
if(isOrVersionSupportedInternal<Extensions::EXT::host_query_reset>())
Implementation::structureConnect(next, features.hostQueryReset, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES);
if(isOrVersionSupportedInternal<Extensions::EXT::index_type_uint8>())
Implementation::structureConnect(next, features.indexTypeUint8, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT);
_state->getFeaturesImplementation(*this, features2);
#define _c(value, field) \
if(features2.features.field) \
_state->features |= DeviceFeature::value;
#define _cver(value, field, suffix, version) \
if(features.suffix.field) \
_state->features |= DeviceFeature::value;
#define _cext _cver
#include "Magnum/Vk/Implementation/deviceFeatureMapping.hpp"
#undef _c
#undef _cver
#undef _cext
}
return _state->features;
}
Containers::ArrayView<const VkQueueFamilyProperties2> DeviceProperties::queueFamilyProperties() {
if(!_state) _state.emplace(*_instance, _handle);

89
src/Magnum/Vk/DeviceProperties.h

@ -246,9 +246,9 @@ MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, MemoryHeapFlags value);
@m_since_latest
Wraps a @type_vk_keyword{PhysicalDevice} along with its (lazy-populated)
properties. See the @ref Vk-Device-creation "Device creation docs" for an
example of using this class for enumerating available devices and picking one
of them.
properties and features. See the @ref Vk-Device-creation "Device creation docs"
for an example of using this class for enumerating available devices and
picking one of them.
@see @ref pickDevice(), @ref enumerateDevices()
*/
class MAGNUM_VK_EXPORT DeviceProperties {
@ -410,6 +410,85 @@ class MAGNUM_VK_EXPORT DeviceProperties {
/** @overload */
ExtensionProperties enumerateExtensionProperties(std::initializer_list<Containers::StringView> layers);
/**
* @brief Device features
*
* Populated lazily on first request, extracting the booleans into a
* more compact set of @ref DeviceFeature values. If Vulkan 1.1 is not
* supported and the @vk_extension{KHR,get_physical_device_properties2}
* extension is not enabled on the originating instance, only the
* Vulkan 1.0 subset of device features is queried. Otherwise:
*
* - If Vulkan 1.1 is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceProtectedMemoryFeatures}
* - If Vulkan 1.1 or the @vk_extension{KHR,multiview} extension is
* supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceMultiviewFeatures}
* - If Vulkan 1.1 or the @vk_extension{KHR,shader_draw_parameters}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceShaderDrawParametersFeatures}
* - If the @vk_extension{EXT,texture_compression_astc_hdr}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT}
* - If Vulkan 1.2 or the @vk_extension{KHR,shader_float16_int8}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceShaderFloat16Int8Features}
* - If Vulkan 1.1 or the @vk_extension{KHR,16bit_storage} extension
* is supported by the device, the `pNext` chain contains
* @type_vk_keyword{PhysicalDevice16BitStorageFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,imageless_framebuffer}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceImagelessFramebufferFeatures}
* - If Vulkan 1.1 or the @vk_extension{KHR,variable_pointers}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceVariablePointersFeatures}
* - If Vulkan 1.1 or the @vk_extension{KHR,sampler_ycbcr_conversion}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceSamplerYcbcrConversionFeatures}
* - If Vulkan 1.2 or the @vk_extension{EXT,descriptor_indexing}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceDescriptorIndexingFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,shader_subgroup_extended_types}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceShaderSubgroupExtendedTypesFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,8bit_storage} extension is
* supported by the device, the `pNext` chain contains
* @type_vk_keyword{PhysicalDevice8BitStorageFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,shader_atomic_int64}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceShaderAtomicInt64Features}
* - If Vulkan 1.2 or the @vk_extension{KHR,timeline_semaphore}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceTimelineSemaphoreFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,vulkan_memory_model}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceVulkanMemoryModelFeatures}
* - If Vulkan 1.2 or the @vk_extension{EXT,scalar_block_layout}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceScalarBlockLayoutFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,separate_depth_stencil_layouts}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceSeparateDepthStencilLayoutsFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,uniform_buffer_standard_layout}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceUniformBufferStandardLayoutFeatures}
* - If Vulkan 1.2 or the @vk_extension{KHR,buffer_device_address}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceBufferDeviceAddressFeatures}
* - If Vulkan 1.2 or the @vk_extension{EXT,host_query_reset}
* extension is supported by the device, the `pNext` chain
* contains @type_vk_keyword{PhysicalDeviceHostQueryResetFeatures}
* - If the @vk_extension{EXT,index_type_uint8} extension is
* supported by the device, the `pNext` chain contains
* @type_vk_keyword{PhysicalDeviceIndexTypeUint8FeaturesEXT}
*
* @see @fn_vk_keyword{GetPhysicalDeviceFeatures2},
* @fn_vk_keyword{GetPhysicalDeviceFeatures},
* @type_vk_keyword{PhysicalDeviceFeatures2},
* @type_vk_keyword{PhysicalDeviceFeatures}
*/
const DeviceFeatures& features();
/**
* @brief Queue family properties
*
@ -640,6 +719,10 @@ class MAGNUM_VK_EXPORT DeviceProperties {
MAGNUM_VK_LOCAL static void getPropertiesImplementationKHR(DeviceProperties& self, VkPhysicalDeviceProperties2& properties);
MAGNUM_VK_LOCAL static void getPropertiesImplementation11(DeviceProperties& self, VkPhysicalDeviceProperties2& properties);
MAGNUM_VK_LOCAL static void getFeaturesImplementationDefault(DeviceProperties& self, VkPhysicalDeviceFeatures2& features);
MAGNUM_VK_LOCAL static void getFeaturesImplementationKHR(DeviceProperties& self, VkPhysicalDeviceFeatures2& features);
MAGNUM_VK_LOCAL static void getFeaturesImplementation11(DeviceProperties& self, VkPhysicalDeviceFeatures2& features);
MAGNUM_VK_LOCAL static void getQueueFamilyPropertiesImplementationDefault(DeviceProperties& self, UnsignedInt& count, VkQueueFamilyProperties2* properties);
MAGNUM_VK_LOCAL static void getQueueFamilyPropertiesImplementationKHR(DeviceProperties& self, UnsignedInt& count, VkQueueFamilyProperties2* properties);
MAGNUM_VK_LOCAL static void getQueueFamilyPropertiesImplementation11(DeviceProperties& self, UnsignedInt& count, VkQueueFamilyProperties2* properties);

61
src/Magnum/Vk/Implementation/DeviceFeatures.h

@ -0,0 +1,61 @@
#ifndef Magnum_Vk_Implementation_DeviceFeatures_h
#define Magnum_Vk_Implementation_DeviceFeatures_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/Vk/Vulkan.h"
namespace Magnum { namespace Vk { namespace Implementation {
/* Everything except the top-level VkPhysicalDeviceFeatures2 structure, which
is treated differently when querying and enabling the features. Used by
DeviceProperties.cpp. */
struct DeviceFeatures {
VkPhysicalDeviceProtectedMemoryFeatures protectedMemory;
VkPhysicalDeviceMultiviewFeatures multiview;
VkPhysicalDeviceShaderDrawParametersFeatures shaderDrawParameters;
VkPhysicalDeviceTextureCompressionASTCHDRFeaturesEXT textureCompressionAstcHdr;
VkPhysicalDeviceShaderFloat16Int8Features shaderFloat16Int8;
VkPhysicalDevice16BitStorageFeatures _16BitStorage;
VkPhysicalDeviceImagelessFramebufferFeatures imagelessFramebuffer;
VkPhysicalDeviceVariablePointersFeatures variablePointers;
VkPhysicalDeviceSamplerYcbcrConversionFeatures samplerYcbcrConversion;
VkPhysicalDeviceDescriptorIndexingFeatures descriptorIndexing;
VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures shaderSubgroupExtendedTypes;
VkPhysicalDevice8BitStorageFeatures _8BitStorage;
VkPhysicalDeviceShaderAtomicInt64Features shaderAtomicInt64;
VkPhysicalDeviceTimelineSemaphoreFeatures timelineSemaphore;
VkPhysicalDeviceVulkanMemoryModelFeatures vulkanMemoryModel;
VkPhysicalDeviceScalarBlockLayoutFeatures scalarBlockLayout;
VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures separateDepthStencilLayouts;
VkPhysicalDeviceUniformBufferStandardLayoutFeatures uniformBufferStandardLayout;
VkPhysicalDeviceBufferDeviceAddressFeatures bufferDeviceAddress;
VkPhysicalDeviceHostQueryResetFeatures hostQueryReset;
VkPhysicalDeviceIndexTypeUint8FeaturesEXT indexTypeUint8;
};
}}}
#endif

186
src/Magnum/Vk/Implementation/deviceFeatureMapping.hpp

@ -0,0 +1,186 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/* See Magnum/Vk/Device.cpp, Magnum/Vk/DeviceFeatures.cpp,
Magnum/Vk/DeviceProperties.cpp and Magnum/Vk/vk-info.cpp for actual usage
which explains what each parameter represents. Needs the _c(), _cver() and
_cext() macros defined, for core, version-dependent and extension-dependent
features respectively:
_c(value, field)
_cver(value, field, suffix, version)
_cext(value, field, suffix, extension)
*/
#ifdef _c
_c(RobustBufferAccess, robustBufferAccess)
_c(FullDrawIndexUint32, fullDrawIndexUint32)
_c(ImageCubeArray, imageCubeArray)
_c(IndependentBlend, independentBlend)
_c(GeometryShader, geometryShader)
_c(TessellationShader, tessellationShader)
_c(SampleRateShading, sampleRateShading)
_c(DualSrcBlend, dualSrcBlend)
_c(LogicOp, logicOp)
_c(MultiDrawIndirect, multiDrawIndirect)
_c(DrawIndirectFirstInstance, drawIndirectFirstInstance)
_c(DepthClamp, depthClamp)
_c(DepthBiasClamp, depthBiasClamp)
_c(FillModeNonSolid, fillModeNonSolid)
_c(DepthBounds, depthBounds)
_c(WideLines, wideLines)
_c(LargePoints, largePoints)
_c(AlphaToOne, alphaToOne)
_c(MultiViewport, multiViewport)
_c(SamplerAnisotropy, samplerAnisotropy)
_c(TextureCompressionEtc2, textureCompressionETC2)
_c(TextureCompressionAstcLdr, textureCompressionASTC_LDR)
_c(TextureCompressionBc, textureCompressionBC)
_c(OcclusionQueryPrecise, occlusionQueryPrecise)
_c(PipelineStatisticsQuery, pipelineStatisticsQuery)
_c(VertexPipelineStoresAndAtomics, vertexPipelineStoresAndAtomics)
_c(FragmentStoresAndAtomics, fragmentStoresAndAtomics)
_c(ShaderTessellationAndGeometryPointSize, shaderTessellationAndGeometryPointSize)
_c(ShaderImageGatherExtended, shaderImageGatherExtended)
_c(ShaderStorageImageExtendedFormats, shaderStorageImageExtendedFormats)
_c(ShaderStorageImageMultisample, shaderStorageImageMultisample)
_c(ShaderStorageImageReadWithoutFormat, shaderStorageImageReadWithoutFormat)
_c(ShaderStorageImageWriteWithoutFormat, shaderStorageImageWriteWithoutFormat)
_c(ShaderUniformBufferArrayDynamicIndexing, shaderUniformBufferArrayDynamicIndexing)
_c(ShaderSampledImageArrayDynamicIndexing, shaderSampledImageArrayDynamicIndexing)
_c(ShaderStorageBufferArrayDynamicIndexing, shaderStorageBufferArrayDynamicIndexing)
_c(ShaderStorageImageArrayDynamicIndexing, shaderStorageImageArrayDynamicIndexing)
_c(ShaderClipDistance, shaderClipDistance)
_c(ShaderCullDistance, shaderCullDistance)
_c(ShaderFloat64, shaderFloat64)
_c(ShaderInt64, shaderInt64)
_c(ShaderInt16, shaderInt16)
_c(ShaderResourceResidency, shaderResourceResidency)
_c(ShaderResourceMinLod, shaderResourceMinLod)
_c(SparseBinding, sparseBinding)
_c(SparseResidencyBuffer, sparseResidencyBuffer)
_c(SparseResidencyImage2D, sparseResidencyImage2D)
_c(SparseResidencyImage3D, sparseResidencyImage3D)
_c(SparseResidency2Samples, sparseResidency2Samples)
_c(SparseResidency4Samples, sparseResidency4Samples)
_c(SparseResidency8Samples, sparseResidency8Samples)
_c(SparseResidency16Samples, sparseResidency16Samples)
_c(SparseResidencyAliased, sparseResidencyAliased)
_c(VariableMultisampleRate, variableMultisampleRate)
_c(InheritedQueries, inheritedQueries)
_cver(ProtectedMemory, protectedMemory, protectedMemory, Vk11)
#define _ce(value, field) _cext(value, field, multiview, KHR::multiview)
_ce(Multiview, multiview)
_ce(MultiviewGeometryShader, multiviewGeometryShader)
_ce(MultiviewTessellationShader, multiviewTessellationShader)
#undef _ce
_cext(ShaderDrawParameters, shaderDrawParameters, shaderDrawParameters, KHR::shader_draw_parameters)
_cext(TextureCompressionAstcHdr, textureCompressionASTC_HDR, textureCompressionAstcHdr, EXT::texture_compression_astc_hdr)
#define _ce(value, field) _cext(value, field, shaderFloat16Int8, KHR::shader_float16_int8)
_ce(ShaderFloat16, shaderFloat16)
_ce(ShaderInt8, shaderInt8)
#undef _ce
#define _ce(value, field) _cext(value, field, _16BitStorage, KHR::_16bit_storage)
_ce(StorageBuffer16BitAccess, storageBuffer16BitAccess)
_ce(UniformAndStorageBuffer16BitAccess, uniformAndStorageBuffer16BitAccess)
_ce(StoragePushConstant16, storagePushConstant16)
_ce(StorageInputOutput16, storageInputOutput16)
#undef _ce
_cext(ImagelessFramebuffer, imagelessFramebuffer, imagelessFramebuffer, KHR::imageless_framebuffer)
#define _ce(value, field) _cext(value, field, variablePointers, KHR::variable_pointers)
_ce(VariablePointersStorageBuffer, variablePointersStorageBuffer)
_ce(VariablePointers, variablePointers)
#undef _ce
_cext(SamplerYcbcrConversion, samplerYcbcrConversion, samplerYcbcrConversion, KHR::sampler_ycbcr_conversion)
#define _ce(value, field) _cext(value, field, descriptorIndexing, EXT::descriptor_indexing)
_ce(ShaderInputAttachmentArrayDynamicIndexing, shaderInputAttachmentArrayDynamicIndexing)
_ce(ShaderUniformTexelBufferArrayDynamicIndexing, shaderUniformTexelBufferArrayDynamicIndexing)
_ce(ShaderStorageTexelBufferArrayDynamicIndexing, shaderStorageTexelBufferArrayDynamicIndexing)
_ce(ShaderUniformBufferArrayNonUniformIndexing, shaderUniformBufferArrayNonUniformIndexing)
_ce(ShaderSampledImageArrayNonUniformIndexing, shaderSampledImageArrayNonUniformIndexing)
_ce(ShaderStorageBufferArrayNonUniformIndexing, shaderStorageBufferArrayNonUniformIndexing)
_ce(ShaderStorageImageArrayNonUniformIndexing, shaderStorageImageArrayNonUniformIndexing)
_ce(ShaderInputAttachmentArrayNonUniformIndexing, shaderInputAttachmentArrayNonUniformIndexing)
_ce(ShaderUniformTexelBufferArrayNonUniformIndexing, shaderUniformTexelBufferArrayNonUniformIndexing)
_ce(ShaderStorageTexelBufferArrayNonUniformIndexing, shaderStorageTexelBufferArrayNonUniformIndexing)
_ce(DescriptorBindingUniformBufferUpdateAfterBind, descriptorBindingUniformBufferUpdateAfterBind)
_ce(DescriptorBindingSampledImageUpdateAfterBind, descriptorBindingSampledImageUpdateAfterBind)
_ce(DescriptorBindingStorageImageUpdateAfterBind, descriptorBindingStorageImageUpdateAfterBind)
_ce(DescriptorBindingStorageBufferUpdateAfterBind, descriptorBindingStorageBufferUpdateAfterBind)
_ce(DescriptorBindingUniformTexelBufferUpdateAfterBind, descriptorBindingUniformTexelBufferUpdateAfterBind)
_ce(DescriptorBindingStorageTexelBufferUpdateAfterBind, descriptorBindingStorageTexelBufferUpdateAfterBind)
_ce(DescriptorBindingUpdateUnusedWhilePending, descriptorBindingUpdateUnusedWhilePending)
_ce(DescriptorBindingPartiallyBound, descriptorBindingPartiallyBound)
_ce(DescriptorBindingVariableDescriptorCount, descriptorBindingVariableDescriptorCount)
_ce(RuntimeDescriptorArray, runtimeDescriptorArray)
#undef _ce
_cext(ShaderSubgroupExtendedTypes, shaderSubgroupExtendedTypes, shaderSubgroupExtendedTypes, KHR::shader_subgroup_extended_types)
#define _ce(value, field) _cext(value, field, _8BitStorage, KHR::_8bit_storage)
_ce(StorageBuffer8BitAccess, storageBuffer8BitAccess)
_ce(UniformAndStorageBuffer8BitAccess, uniformAndStorageBuffer8BitAccess)
_ce(StoragePushConstant8, storagePushConstant8)
#undef _ce
#define _ce(value, field) _cext(value, field, shaderAtomicInt64, KHR::shader_atomic_int64)
_ce(ShaderBufferInt64Atomics, shaderBufferInt64Atomics)
_ce(ShaderSharedInt64Atomics, shaderSharedInt64Atomics)
#undef _ce
_cext(TimelineSemaphore, timelineSemaphore, timelineSemaphore, KHR::timeline_semaphore)
#define _ce(value, field) _cext(value, field, vulkanMemoryModel, KHR::vulkan_memory_model)
_ce(VulkanMemoryModel, vulkanMemoryModel)
_ce(VulkanMemoryModelDeviceScope, vulkanMemoryModelDeviceScope)
_ce(VulkanMemoryModelAvailabilityVisibilityChains,vulkanMemoryModelAvailabilityVisibilityChains)
#undef _ce
_cext(ScalarBlockLayout, scalarBlockLayout, scalarBlockLayout, EXT::scalar_block_layout)
_cext(SeparateDepthStencilLayouts, separateDepthStencilLayouts, separateDepthStencilLayouts, KHR::separate_depth_stencil_layouts)
_cext(UniformBufferStandardLayout, uniformBufferStandardLayout, uniformBufferStandardLayout, KHR::uniform_buffer_standard_layout)
#define _ce(value, field) _cext(value, field, bufferDeviceAddress, KHR::buffer_device_address)
_ce(BufferDeviceAddress, bufferDeviceAddress)
_ce(BufferDeviceAddressCaptureReplay, bufferDeviceAddressCaptureReplay)
_ce(BufferDeviceAddressMultiDevice, bufferDeviceAddressMultiDevice)
#undef _ce
_cext(HostQueryReset, hostQueryReset, hostQueryReset, EXT::host_query_reset)
_cext(IndexTypeUint8, indexTypeUint8, indexTypeUint8, EXT::index_type_uint8)
#endif

2
src/Magnum/Vk/Test/CMakeLists.txt

@ -29,6 +29,7 @@ corrade_add_test(VkCommandBufferTest CommandBufferTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkCommandPoolTest CommandPoolTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkDeviceTest DeviceTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkDevicePropertiesTest DevicePropertiesTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkDeviceFeaturesTest DeviceFeaturesTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkEnumsTest EnumsTest.cpp LIBRARIES MagnumVkTestLib)
corrade_add_test(VkExtensionsTest ExtensionsTest.cpp LIBRARIES MagnumVk)
corrade_add_test(VkExtensionPropertiesTest ExtensionPropertiesTest.cpp LIBRARIES MagnumVk)
@ -115,6 +116,7 @@ set_target_properties(
VkCommandBufferTest
VkCommandPoolTest
VkDeviceTest
VkDeviceFeaturesTest
VkDevicePropertiesTest
VkEnumsTest
VkExtensionsTest

110
src/Magnum/Vk/Test/DeviceFeaturesTest.cpp

@ -0,0 +1,110 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#include "Magnum/Vk/DeviceFeatures.h"
namespace Magnum { namespace Vk { namespace Test { namespace {
struct DeviceFeaturesTest: TestSuite::Tester {
explicit DeviceFeaturesTest();
void mapping();
void debugFeature();
void debugFeatures();
};
DeviceFeaturesTest::DeviceFeaturesTest() {
addTests({&DeviceFeaturesTest::mapping,
&DeviceFeaturesTest::debugFeature,
&DeviceFeaturesTest::debugFeatures});
}
void DeviceFeaturesTest::mapping() {
UnsignedInt firstUnhandled = 0xff;
UnsignedInt nextHandled = 0;
for(UnsignedInt i = 0; i <= 0xff; ++i) {
CORRADE_ITERATION(i);
const auto feature = DeviceFeature(i);
/* Each case verifies:
- that the entries are ordered by number by comparing a function to
expected result (so insertion here is done in proper place)
- that there was no gap (unhandled value inside the range)
- that the Debug output is equivalent to the name */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(feature) {
#define _c(value, field) \
case DeviceFeature::value: { \
std::ostringstream out; \
Debug{&out, Debug::Flag::NoNewlineAtTheEnd} << DeviceFeature::value; \
CORRADE_COMPARE(out.str(), "Vk::DeviceFeature::" #value); \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xff); \
++nextHandled; \
continue; \
}
#define _cver(value, field, suffix, version) _c(value, field)
#define _cext(value, field, suffix, extension) _c(value, field)
#include "Magnum/Vk/Implementation/deviceFeatureMapping.hpp"
#undef _c
#undef _cver
#undef _cext
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end
of the enum range (which is okay) or some value might be unhandled
here */
firstUnhandled = i;
}
CORRADE_COMPARE(firstUnhandled, 0xff);
}
void DeviceFeaturesTest::debugFeature() {
std::ostringstream out;
Debug{&out} << DeviceFeature::FullDrawIndexUint32 << DeviceFeature::VulkanMemoryModel << DeviceFeature(0xab);
CORRADE_COMPARE(out.str(), "Vk::DeviceFeature::FullDrawIndexUint32 Vk::DeviceFeature::VulkanMemoryModel Vk::DeviceFeature(0xab)\n");
}
void DeviceFeaturesTest::debugFeatures() {
std::ostringstream out;
Debug{&out} << (DeviceFeature::FullDrawIndexUint32|DeviceFeature::VulkanMemoryModel|DeviceFeature(0xab)|DeviceFeature(0xcc)) << DeviceFeatures{};
CORRADE_COMPARE(out.str(), "Vk::DeviceFeature::FullDrawIndexUint32|Vk::DeviceFeature::VulkanMemoryModel|Vk::DeviceFeature(0xab)|Vk::DeviceFeature(0xcc) Vk::DeviceFeatures{}\n");
}
}}}}
CORRADE_TEST_MAIN(Magnum::Vk::Test::DeviceFeaturesTest)

71
src/Magnum/Vk/Test/DevicePropertiesVkTest.cpp

@ -32,6 +32,8 @@
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>
#include "Magnum/Math/Functions.h"
#include "Magnum/Vk/DeviceFeatures.h"
#include "Magnum/Vk/DeviceProperties.h"
#include "Magnum/Vk/Extensions.h"
#include "Magnum/Vk/ExtensionProperties.h"
@ -63,6 +65,10 @@ struct DevicePropertiesVkTest: VulkanTester {
void driverProperties();
void features();
void featureExpectedSupported();
void featureExpectedUnsupported();
void queueFamilies();
void queueFamiliesOutOfRange();
void queueFamiliesPick();
@ -111,6 +117,10 @@ DevicePropertiesVkTest::DevicePropertiesVkTest(): VulkanTester{NoCreate} {
&DevicePropertiesVkTest::driverProperties,
&DevicePropertiesVkTest::features,
&DevicePropertiesVkTest::featureExpectedSupported,
&DevicePropertiesVkTest::featureExpectedUnsupported,
&DevicePropertiesVkTest::queueFamilies,
&DevicePropertiesVkTest::queueFamiliesOutOfRange,
&DevicePropertiesVkTest::queueFamiliesPick,
@ -210,6 +220,67 @@ void DevicePropertiesVkTest::driverProperties() {
}
}
void DevicePropertiesVkTest::features() {
Containers::Optional<DeviceProperties> device = tryPickDevice(instance());
CORRADE_VERIFY(device);
std::size_t popcount = 0;
for(std::size_t i = 0; i != DeviceFeatures::Size; ++i) {
popcount += Math::popcount(device->features().data()[i]);
}
Debug{} << "Available feature count:" << popcount;
CORRADE_VERIFY(popcount);
/* These (and others) are guaranteed to be always present by the spec, so
verify our sanity with those. If not, then we have something shitty in
our implementation. */
CORRADE_VERIFY(device->features() & DeviceFeature::RobustBufferAccess);
/* These are from additional structures, which can be queried only if both
instance and device have 1.1 or if KHR_get_physical_driver_properties2
is enabled on the instance. */
if(instance().isVersionSupported(Version::Vk11) || instance().isExtensionEnabled<Extensions::KHR::get_physical_device_properties2>()) {
if(device->isVersionSupported(Version::Vk11))
CORRADE_VERIFY(device->features() & DeviceFeature::Multiview);
if(device->isVersionSupported(Version::Vk12)) {
CORRADE_VERIFY(device->features() & DeviceFeature::UniformBufferStandardLayout);
CORRADE_VERIFY(device->features() & DeviceFeature::ImagelessFramebuffer);
CORRADE_VERIFY(device->features() & DeviceFeature::SeparateDepthStencilLayouts);
CORRADE_VERIFY(device->features() & DeviceFeature::HostQueryReset);
CORRADE_VERIFY(device->features() & DeviceFeature::TimelineSemaphore);
CORRADE_VERIFY(device->features() & DeviceFeature::ShaderSubgroupExtendedTypes);
}
}
}
void DevicePropertiesVkTest::featureExpectedSupported() {
Containers::Optional<DeviceProperties> device = tryPickDevice(instance());
CORRADE_VERIFY(device);
if((!instance().isVersionSupported(Version::Vk11) || !device->isVersionSupported(Version::Vk11)) && !instance().isExtensionEnabled<Extensions::KHR::get_physical_device_properties2>())
CORRADE_SKIP("Neither Vulkan 1.1 nor KHR_get_physical_device_properties2 is supported, can't test");
if(!device->enumerateExtensionProperties().isSupported<Extensions::KHR::sampler_ycbcr_conversion>())
CORRADE_SKIP("VK_KHR_sampler_ycbcr_conversion not supported, can't test.");
CORRADE_VERIFY(device->features() & DeviceFeature::SamplerYcbcrConversion);
}
void DevicePropertiesVkTest::featureExpectedUnsupported() {
Containers::Optional<DeviceProperties> device = tryPickDevice(instance());
CORRADE_VERIFY(device);
if(!((instance().isVersionSupported(Version::Vk11) && device->isVersionSupported(Version::Vk11)) || instance().isExtensionEnabled<Extensions::KHR::get_physical_device_properties2>()))
CORRADE_SKIP("Vulkan 1.1 or KHR_get_physical_device_properties2 not present, can't test.");
if(device->enumerateExtensionProperties().isSupported<Extensions::EXT::texture_compression_astc_hdr>())
CORRADE_SKIP("VK_EXT_texture_compression_astc_hdr supported, can't test.");
CORRADE_VERIFY(!(device->features() & DeviceFeature::TextureCompressionAstcHdr));
}
void DevicePropertiesVkTest::enumerateExtensions() {
Containers::Array<DeviceProperties> devices = enumerateDevices(instance());
CORRADE_VERIFY(!devices.empty());

2
src/Magnum/Vk/Vk.h

@ -43,6 +43,8 @@ class CommandPool;
class CommandPoolCreateInfo;
class Device;
class DeviceCreateInfo;
enum class DeviceFeature: UnsignedShort;
typedef Containers::BigEnumSet<DeviceFeature, 4> DeviceFeatures;
class DeviceProperties;
enum class DeviceType: Int;
class Extension;

Loading…
Cancel
Save