Introduce usage of clang-format to format vulkan.hpp and the other sources.

This commit is contained in:
asuessenbach
2020-04-12 21:49:12 +02:00
parent ce9fd81bd9
commit f5e59484a6
68 changed files with 56064 additions and 35586 deletions

View File

@@ -18,98 +18,108 @@
#include "../utils/utils.hpp"
#include "vulkan/vulkan.hpp"
static char const* AppName = "16_Vulkan_1_1";
static char const* EngineName = "Vulkan.hpp";
static char const * AppName = "16_Vulkan_1_1";
static char const * EngineName = "Vulkan.hpp";
int main(int /*argc*/, char ** /*argv*/)
int main( int /*argc*/, char ** /*argv*/ )
{
try
{
/* VULKAN_KEY_START */
// Keep track of the major/minor version we can actually use
uint16_t usingMajorVersion = 1;
uint16_t usingMinorVersion = 0;
uint16_t usingMajorVersion = 1;
uint16_t usingMinorVersion = 0;
std::string usingVersionString = "";
// Set the desired version we want
uint16_t desiredMajorVersion = 1;
uint16_t desiredMinorVersion = 1;
uint32_t desiredVersion = VK_MAKE_VERSION(desiredMajorVersion, desiredMinorVersion, 0);
uint16_t desiredMajorVersion = 1;
uint16_t desiredMinorVersion = 1;
uint32_t desiredVersion = VK_MAKE_VERSION( desiredMajorVersion, desiredMinorVersion, 0 );
std::string desiredVersionString = "";
desiredVersionString += std::to_string(desiredMajorVersion);
desiredVersionString += std::to_string( desiredMajorVersion );
desiredVersionString += ".";
desiredVersionString += std::to_string(desiredMinorVersion);
desiredVersionString += std::to_string( desiredMinorVersion );
#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1)
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize the DipatchLoaderDynamic to use
static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
static vk::DynamicLoader dl;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
#endif
// Determine what API version is available
uint32_t apiVersion = vk::enumerateInstanceVersion();
// Translate the version into major/minor for easier comparison
uint32_t loader_major_version = VK_VERSION_MAJOR(apiVersion);
uint32_t loader_minor_version = VK_VERSION_MINOR(apiVersion);
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version << "\n";
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion );
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version
<< "\n";
// Check current version against what we want to run
if (loader_major_version > desiredMajorVersion ||
(loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion))
if ( loader_major_version > desiredMajorVersion ||
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
{
// Create the instance
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion);
#if !defined(NDEBUG)
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger(instance);
vk::UniqueInstance instance =
vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion );
#if !defined( NDEBUG )
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger( instance );
#endif
// Get the list of physical devices
std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices();
// Go through the list of physical devices and select only those that are capable of running the API version we want.
// Go through the list of physical devices and select only those that are capable of running the API version we
// want.
std::vector<vk::PhysicalDevice> desiredPhysicalDevices;
std::copy_if(physicalDevices.begin(), physicalDevices.end(), std::back_inserter(desiredPhysicalDevices), [desiredVersion](vk::PhysicalDevice const& pd) { return pd.getProperties().apiVersion >= desiredVersion; });
std::copy_if(
physicalDevices.begin(),
physicalDevices.end(),
std::back_inserter( desiredPhysicalDevices ),
[desiredVersion]( vk::PhysicalDevice const & pd ) { return pd.getProperties().apiVersion >= desiredVersion; } );
// If we have something in the desired version physical device list, we're good
if (desiredPhysicalDevices.size() > 0)
if ( desiredPhysicalDevices.size() > 0 )
{
usingMajorVersion = desiredMajorVersion;
usingMinorVersion = desiredMinorVersion;
}
}
usingVersionString += std::to_string(usingMajorVersion);
usingVersionString += std::to_string( usingMajorVersion );
usingVersionString += ".";
usingVersionString += std::to_string(usingMinorVersion);
usingVersionString += std::to_string( usingMinorVersion );
if (usingMinorVersion < desiredMinorVersion)
if ( usingMinorVersion < desiredMinorVersion )
{
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString << " instead of desired version " << desiredVersionString << std::endl;
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString
<< " instead of desired version " << desiredVersionString << std::endl;
}
else
{
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString << std::endl;
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString
<< std::endl;
}
/* VULKAN_KEY_END */
}
catch (vk::SystemError& err)
catch ( vk::SystemError & err )
{
std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1);
exit( -1 );
}
catch (std::runtime_error& err)
catch ( std::runtime_error & err )
{
std::cout << "std::runtime_error: " << err.what() << std::endl;
exit(-1);
exit( -1 );
}
catch (...)
catch ( ... )
{
std::cout << "unknown error\n";
exit(-1);
exit( -1 );
}
return 0;
}