2018-09-19 11:49:43 +00:00
|
|
|
// Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// VulkanHpp Tests : StructureChain
|
|
|
|
// Compile-test for StructureChains
|
|
|
|
|
2020-09-30 10:00:32 +00:00
|
|
|
// ignore warning 4189: local variable is initialized but not referenced
|
|
|
|
#if defined( _MSC_VER )
|
|
|
|
# pragma warning( disable : 4189 )
|
|
|
|
#elif defined( __GNUC__ )
|
|
|
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
|
|
|
#else
|
|
|
|
// unknow compiler... just ignore the warnings for yourselves ;)
|
|
|
|
#endif
|
|
|
|
|
2019-11-06 15:56:52 +00:00
|
|
|
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
|
|
|
|
2018-09-19 11:49:43 +00:00
|
|
|
#include "vulkan/vulkan.hpp"
|
2020-04-12 19:49:12 +00:00
|
|
|
|
2018-09-19 11:49:43 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
static char const * AppName = "StructureChain";
|
|
|
|
static char const * EngineName = "Vulkan.hpp";
|
2018-09-19 11:49:43 +00:00
|
|
|
|
2020-02-11 14:39:46 +00:00
|
|
|
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
|
|
|
|
|
|
|
|
template <typename T>
|
2020-04-12 19:49:12 +00:00
|
|
|
void unused( T const & )
|
2020-02-11 14:39:46 +00:00
|
|
|
{}
|
2019-11-06 15:56:52 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
int main( int /*argc*/, char ** /*argv*/ )
|
2018-09-19 11:49:43 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::DynamicLoader dl;
|
|
|
|
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
|
|
|
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
|
|
|
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
|
|
|
|
|
|
|
vk::ApplicationInfo appInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
|
|
|
vk::UniqueInstance instance = vk::createInstanceUnique( vk::InstanceCreateInfo( {}, &appInfo ) );
|
|
|
|
VULKAN_HPP_DEFAULT_DISPATCHER.init( *instance );
|
2019-06-25 07:47:27 +00:00
|
|
|
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
2018-09-19 11:49:43 +00:00
|
|
|
|
2018-09-20 13:20:00 +00:00
|
|
|
// some valid StructureChains
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::StructureChain<vk::PhysicalDeviceProperties2> sc0;
|
2020-11-09 08:55:45 +00:00
|
|
|
const vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties> sc1;
|
|
|
|
auto pdp = sc1.get<vk::PhysicalDeviceProperties2>();
|
|
|
|
unused( pdp );
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceMaintenance3Properties> sc2;
|
2018-09-20 13:20:00 +00:00
|
|
|
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDevicePushDescriptorPropertiesKHR> sc3;
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::StructureChain<vk::PhysicalDeviceProperties2,
|
|
|
|
vk::PhysicalDeviceIDProperties,
|
|
|
|
vk::PhysicalDeviceMaintenance3Properties>
|
|
|
|
sc4;
|
|
|
|
vk::StructureChain<vk::PhysicalDeviceProperties2,
|
|
|
|
vk::PhysicalDeviceIDProperties,
|
|
|
|
vk::PhysicalDevicePushDescriptorPropertiesKHR>
|
|
|
|
sc6;
|
|
|
|
vk::StructureChain<vk::PhysicalDeviceProperties2,
|
|
|
|
vk::PhysicalDeviceIDProperties,
|
|
|
|
vk::PhysicalDeviceMaintenance3Properties,
|
|
|
|
vk::PhysicalDevicePushDescriptorPropertiesKHR>
|
|
|
|
sc7;
|
2018-09-20 13:20:00 +00:00
|
|
|
|
2021-01-20 09:33:33 +00:00
|
|
|
// some checks on unmodified chains
|
|
|
|
assert( sc7.isLinked<vk::PhysicalDeviceProperties2>() );
|
|
|
|
assert( sc7.isLinked<vk::PhysicalDeviceMaintenance3Properties>() );
|
|
|
|
|
2019-11-06 15:56:52 +00:00
|
|
|
// some invalid StructureChains
|
2020-05-11 09:52:25 +00:00
|
|
|
// clang-format off
|
|
|
|
//vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties> x;
|
|
|
|
//vk::StructureChain<vk::PhysicalDeviceIDProperties,
|
|
|
|
// vk::PhysicalDeviceMaintenance3Properties,
|
|
|
|
// vk::PhysicalDevicePushDescriptorPropertiesKHR>
|
|
|
|
// x;
|
|
|
|
//vk::StructureChain<vk::PhysicalDeviceIDProperties,
|
|
|
|
// vk::PhysicalDevicePushDescriptorPropertiesKHR,
|
|
|
|
// vk::PhysicalDeviceMaintenance3Properties>
|
|
|
|
// x;
|
|
|
|
//vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceIDProperties> x;
|
|
|
|
//vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceProperties2> x;
|
|
|
|
// clang-format on
|
2018-09-20 13:20:00 +00:00
|
|
|
|
2019-11-28 14:58:15 +00:00
|
|
|
// unlink a struct from a StructureChain
|
|
|
|
sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>();
|
2021-01-20 09:33:33 +00:00
|
|
|
assert( !sc7.isLinked<vk::PhysicalDeviceMaintenance3Properties>() );
|
2019-11-28 14:58:15 +00:00
|
|
|
|
|
|
|
// some invalid unlink calls
|
2020-05-11 09:52:25 +00:00
|
|
|
// clang-format off
|
|
|
|
//sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>(); // assertion fires on trying to unlink some already
|
|
|
|
// // unlinked structure
|
|
|
|
//sc7.unlink<vk::PhysicalDeviceProperties2>();
|
|
|
|
//sc1.unlink<vk::PhysicalDeviceMaintenance3Properties>();
|
|
|
|
// clang-format on
|
2019-11-28 14:58:15 +00:00
|
|
|
|
|
|
|
// re-link a struct
|
|
|
|
sc7.relink<vk::PhysicalDeviceMaintenance3Properties>();
|
2021-01-20 09:33:33 +00:00
|
|
|
assert( sc7.isLinked<vk::PhysicalDeviceMaintenance3Properties>() );
|
2019-11-28 14:58:15 +00:00
|
|
|
|
|
|
|
// invalid re-linking
|
2020-05-11 09:52:25 +00:00
|
|
|
// clang-format off
|
|
|
|
//sc7.relink<vk::PhysicalDeviceProperties2>();
|
|
|
|
//sc1.relink<vk::PhysicalDeviceMaintenance3Properties>();
|
|
|
|
//sc1.relink<vk::PhysicalDeviceIDProperties>(); // assertion fires on trying to relink some structure that hasn't been unlinked
|
|
|
|
// clang-format on
|
2019-11-28 14:58:15 +00:00
|
|
|
|
2018-09-19 11:49:43 +00:00
|
|
|
// simple call, passing structures in
|
|
|
|
vk::PhysicalDeviceFeatures2 pdf;
|
2020-04-12 19:49:12 +00:00
|
|
|
physicalDevice.getFeatures2( &pdf );
|
2018-09-19 11:49:43 +00:00
|
|
|
|
|
|
|
// simple calls, getting structure back
|
2019-06-25 07:47:27 +00:00
|
|
|
vk::PhysicalDeviceFeatures2 a = physicalDevice.getFeatures2();
|
2020-04-12 19:49:12 +00:00
|
|
|
unused( a );
|
2020-02-11 14:39:46 +00:00
|
|
|
|
2018-09-19 11:49:43 +00:00
|
|
|
// complex calls, getting StructureChain back
|
2019-06-25 07:47:27 +00:00
|
|
|
auto c = physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVariablePointerFeatures>();
|
2018-09-19 11:49:43 +00:00
|
|
|
vk::PhysicalDeviceFeatures2 & c0 = c.get<vk::PhysicalDeviceFeatures2>();
|
2020-04-12 19:49:12 +00:00
|
|
|
unused( c0 );
|
2019-03-12 08:32:39 +00:00
|
|
|
|
|
|
|
auto t0 = c.get<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVariablePointerFeatures>();
|
2020-04-12 19:49:12 +00:00
|
|
|
unused( t0 );
|
|
|
|
|
2019-11-06 15:56:52 +00:00
|
|
|
auto d = physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVariablePointerFeatures>();
|
2018-09-19 11:49:43 +00:00
|
|
|
vk::PhysicalDeviceFeatures2 & d0 = d.get<vk::PhysicalDeviceFeatures2>();
|
2020-04-12 19:49:12 +00:00
|
|
|
unused( d0 );
|
2018-09-19 11:49:43 +00:00
|
|
|
vk::PhysicalDeviceVariablePointerFeatures & d1 = d.get<vk::PhysicalDeviceVariablePointerFeatures>();
|
2020-04-12 19:49:12 +00:00
|
|
|
unused( d1 );
|
2019-01-09 10:55:11 +00:00
|
|
|
|
2019-03-12 08:32:39 +00:00
|
|
|
auto t1 = d.get<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVariablePointerFeatures>();
|
2020-04-12 19:49:12 +00:00
|
|
|
unused( t1 );
|
2019-03-12 08:32:39 +00:00
|
|
|
|
2019-01-09 10:55:11 +00:00
|
|
|
using StructureChain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>;
|
2020-04-12 19:49:12 +00:00
|
|
|
using AllocatorType = std::vector<StructureChain>::allocator_type;
|
|
|
|
auto qfd = physicalDevice.getQueueFamilyProperties2<StructureChain, AllocatorType>( VULKAN_HPP_DEFAULT_DISPATCHER );
|
|
|
|
unused( qfd );
|
2020-05-11 09:52:25 +00:00
|
|
|
|
|
|
|
// some tests with structures with allowDuplicate == true
|
|
|
|
// include them as soon as vk.xml has been fixed on attribute "allowduplicate" !
|
|
|
|
#if 0
|
|
|
|
vk::StructureChain<vk::DeviceCreateInfo, vk::DevicePrivateDataCreateInfoEXT, vk::DevicePrivateDataCreateInfoEXT>
|
|
|
|
dci0;
|
|
|
|
auto dci1( dci0 );
|
|
|
|
|
|
|
|
vk::DeviceCreateInfo dci;
|
|
|
|
vk::DevicePrivateDataCreateInfoEXT dpdci0;
|
|
|
|
vk::DevicePrivateDataCreateInfoEXT dpdci1;
|
|
|
|
vk::StructureChain<vk::DeviceCreateInfo, vk::DevicePrivateDataCreateInfoEXT, vk::DevicePrivateDataCreateInfoEXT>
|
|
|
|
dci2( dci, dpdci0, dpdci1 );
|
|
|
|
|
|
|
|
dci2 = dci1;
|
|
|
|
|
|
|
|
auto & dpdci = dci0.get<vk::DevicePrivateDataCreateInfoEXT, 1>();
|
|
|
|
auto const & dpdcic = dci0.get<vk::DevicePrivateDataCreateInfoEXT, 1>();
|
|
|
|
|
|
|
|
dci2.unlink<vk::DevicePrivateDataCreateInfoEXT, 1>();
|
|
|
|
dci2.relink<vk::DevicePrivateDataCreateInfoEXT, 1>();
|
|
|
|
#endif
|
2021-01-21 15:56:14 +00:00
|
|
|
|
|
|
|
vk::StructureChain<vk::InstanceCreateInfo,
|
|
|
|
vk::DebugReportCallbackCreateInfoEXT,
|
|
|
|
vk::ValidationFlagsEXT,
|
|
|
|
vk::ValidationFeaturesEXT,
|
|
|
|
vk::DebugUtilsMessengerCreateInfoEXT>
|
|
|
|
chain;
|
|
|
|
chain.unlink<vk::DebugReportCallbackCreateInfoEXT>();
|
|
|
|
chain.unlink<vk::ValidationFlagsEXT>();
|
|
|
|
chain.unlink<vk::ValidationFeaturesEXT>();
|
|
|
|
chain.unlink<vk::DebugUtilsMessengerCreateInfoEXT>();
|
|
|
|
chain.relink<vk::DebugUtilsMessengerCreateInfoEXT>();
|
2018-09-19 11:49:43 +00:00
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( vk::SystemError const & err )
|
2018-09-19 11:49:43 +00:00
|
|
|
{
|
|
|
|
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2018-09-19 11:49:43 +00:00
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( ... )
|
2018-09-19 11:49:43 +00:00
|
|
|
{
|
|
|
|
std::cout << "unknown error\n";
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2018-09-19 11:49:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|