2019-10-28 14:36:21 +00:00
|
|
|
// Copyright(c) 2019, 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 Samples : SurfaceCapabilities
|
|
|
|
// Get surface capabilities.
|
|
|
|
|
|
|
|
#include "../utils/utils.hpp"
|
2020-04-12 19:49:12 +00:00
|
|
|
|
2019-10-28 14:36:21 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2022-07-26 09:13:43 +00:00
|
|
|
#include <vulkan/vulkan_to_string.hpp>
|
2019-10-28 14:36:21 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
static char const * AppName = "SurfaceCapabilities";
|
|
|
|
static char const * EngineName = "Vulkan.hpp";
|
2019-10-28 14:36:21 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
void cout( vk::SurfaceCapabilitiesKHR const & surfaceCapabilities )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2022-07-25 15:11:30 +00:00
|
|
|
std::cout << std::string( "\t" ) << "Capabilities:\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "currentExtent = " << surfaceCapabilities.currentExtent.width << " x "
|
|
|
|
<< surfaceCapabilities.currentExtent.height << "\n";
|
2022-07-26 09:13:43 +00:00
|
|
|
std::cout << std::string( "\t\t" ) << "currentTransform = " << vk::to_string( surfaceCapabilities.currentTransform ) << "\n";
|
2022-07-25 15:11:30 +00:00
|
|
|
std::cout << std::string( "\t\t" ) << "maxImageArrayLayers = " << surfaceCapabilities.maxImageArrayLayers << "\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "maxImageCount = " << surfaceCapabilities.maxImageCount << "\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x "
|
|
|
|
<< surfaceCapabilities.maxImageExtent.height << "\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "minImageCount = " << surfaceCapabilities.minImageCount << "\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x "
|
|
|
|
<< surfaceCapabilities.minImageExtent.height << "\n";
|
2022-07-26 09:13:43 +00:00
|
|
|
std::cout << std::string( "\t\t" ) << "supportedCompositeAlpha = " << vk::to_string( surfaceCapabilities.supportedCompositeAlpha ) << "\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "supportedTransforms = " << vk::to_string( surfaceCapabilities.supportedTransforms ) << "\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "supportedUsageFlags = " << vk::to_string( surfaceCapabilities.supportedUsageFlags ) << "\n";
|
2019-10-28 14:36:21 +00:00
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
int main( int /*argc*/, char ** /*argv*/ )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// need to initialize the dynamic dispatcher before the very first vulkan call
|
2020-04-12 19:49:12 +00:00
|
|
|
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
|
|
|
static vk::DynamicLoader dl;
|
2022-02-28 09:11:04 +00:00
|
|
|
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
2020-04-12 19:49:12 +00:00
|
|
|
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
2019-10-28 14:36:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
std::vector<vk::ExtensionProperties> instanceExtensionProperties = vk::enumerateInstanceExtensionProperties();
|
2022-02-28 09:11:04 +00:00
|
|
|
auto propertyIterator =
|
|
|
|
std::find_if( instanceExtensionProperties.begin(),
|
|
|
|
instanceExtensionProperties.end(),
|
|
|
|
[]( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0; } );
|
2021-02-17 09:49:59 +00:00
|
|
|
bool supportsGetSurfaceCapabilities2 = ( propertyIterator != instanceExtensionProperties.end() );
|
2019-10-28 14:36:21 +00:00
|
|
|
|
|
|
|
std::vector<std::string> extensions = vk::su::getInstanceExtensions();
|
2020-04-12 19:49:12 +00:00
|
|
|
if ( supportsGetSurfaceCapabilities2 )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2020-04-12 19:49:12 +00:00
|
|
|
extensions.push_back( VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME );
|
2019-10-28 14:36:21 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 09:49:59 +00:00
|
|
|
vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, extensions );
|
2020-04-12 19:49:12 +00:00
|
|
|
#if !defined( NDEBUG )
|
2022-02-28 09:11:04 +00:00
|
|
|
vk::DebugUtilsMessengerEXT debugUtilsMessenger = instance.createDebugUtilsMessengerEXT( vk::su::makeDebugUtilsMessengerCreateInfoEXT() );
|
2019-10-28 14:36:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// enumerate the physicalDevices
|
2021-02-17 09:49:59 +00:00
|
|
|
std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();
|
2019-10-28 14:36:21 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
2019-10-28 14:36:21 +00:00
|
|
|
|
|
|
|
/* VULKAN_KEY_START */
|
|
|
|
|
|
|
|
std::cout << std::boolalpha;
|
2020-04-12 19:49:12 +00:00
|
|
|
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
|
|
|
// some properties are only valid, if a corresponding extension is available!
|
2022-02-28 09:11:04 +00:00
|
|
|
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
|
2019-10-28 14:36:21 +00:00
|
|
|
|
|
|
|
std::cout << "PhysicalDevice " << i << "\n";
|
2020-04-12 19:49:12 +00:00
|
|
|
if ( supportsGetSurfaceCapabilities2 )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2022-02-28 09:11:04 +00:00
|
|
|
auto surfaceCapabilities2 = physicalDevices[i]
|
|
|
|
.getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR,
|
|
|
|
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
|
|
|
|
vk::SharedPresentSurfaceCapabilitiesKHR,
|
|
|
|
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
|
|
|
|
vk::SurfaceProtectedCapabilitiesKHR>( surfaceData.surface );
|
|
|
|
|
|
|
|
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities = surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
|
2020-04-12 19:49:12 +00:00
|
|
|
cout( surfaceCapabilities );
|
|
|
|
|
|
|
|
if ( vk::su::contains( extensionProperties, "VK_AMD_display_native_hdr" ) )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::DisplayNativeHdrSurfaceCapabilitiesAMD displayNativeHdrSurfaceCapabilities =
|
|
|
|
surfaceCapabilities2.get<vk::DisplayNativeHdrSurfaceCapabilitiesAMD>();
|
2022-07-25 15:11:30 +00:00
|
|
|
std::cout << std::string( "\t" ) << "DisplayNativeHdrSurfaceCapabilitiesAMD:\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "localDimmingSupport = " << !!displayNativeHdrSurfaceCapabilities.localDimmingSupport << "\n";
|
2019-10-28 14:36:21 +00:00
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
if ( vk::su::contains( extensionProperties, "VK_KHR_shared_presentable_image" ) )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2022-02-28 09:11:04 +00:00
|
|
|
vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities = surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
|
2022-07-25 15:11:30 +00:00
|
|
|
std::cout << std::string( "\t" ) << "SharedPresentSurfaceCapabilitiesKHR:\n";
|
|
|
|
std::cout << std::string( "\t\t" )
|
2022-07-26 09:13:43 +00:00
|
|
|
<< "sharedPresentSupportedUsageFlags = " << vk::to_string( sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags ) << "\n";
|
2019-10-28 14:36:21 +00:00
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
if ( vk::su::contains( extensionProperties, "VK_EXT_full_screen_exclusive" ) )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::SurfaceCapabilitiesFullScreenExclusiveEXT surfaceCapabilitiesFullScreenExclusive =
|
|
|
|
surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>();
|
2022-07-25 15:11:30 +00:00
|
|
|
std::cout << std::string( "\t" ) << "SurfaceCapabilitiesFullScreenExclusiveEXT:\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "fullScreenExclusiveSupported = " << !!surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported
|
|
|
|
<< "\n";
|
2019-10-28 14:36:21 +00:00
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
if ( vk::su::contains( extensionProperties, "VK_KHR_surface_protected_capabilities" ) )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2022-02-28 09:11:04 +00:00
|
|
|
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
|
2022-07-25 15:11:30 +00:00
|
|
|
std::cout << std::string( "\t" ) << "SurfaceProtectedCapabilitiesKHR:\n";
|
|
|
|
std::cout << std::string( "\t\t" ) << "supportsProtected = " << !!surfaceProtectedCapabilities.supportsProtected << "\n";
|
2019-10-28 14:36:21 +00:00
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-28 09:11:04 +00:00
|
|
|
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevices[i].getSurfaceCapabilitiesKHR( surfaceData.surface );
|
2020-04-12 19:49:12 +00:00
|
|
|
cout( surfaceCapabilities );
|
2019-10-28 14:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VULKAN_KEY_END */
|
2021-02-17 09:49:59 +00:00
|
|
|
|
|
|
|
instance.destroySurfaceKHR( surfaceData.surface );
|
2021-05-25 14:14:56 +00:00
|
|
|
#if !defined( NDEBUG )
|
2021-02-17 09:49:59 +00:00
|
|
|
instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
|
2021-05-25 14:14:56 +00:00
|
|
|
#endif
|
2021-02-17 09:49:59 +00:00
|
|
|
instance.destroy();
|
2019-10-28 14:36:21 +00:00
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( vk::SystemError & err )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
|
|
|
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2019-10-28 14:36:21 +00:00
|
|
|
}
|
2020-07-08 08:58:37 +00:00
|
|
|
catch ( std::exception & err )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
2020-07-08 08:58:37 +00:00
|
|
|
std::cout << "std::exception: " << err.what() << std::endl;
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2019-10-28 14:36:21 +00:00
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( ... )
|
2019-10-28 14:36:21 +00:00
|
|
|
{
|
|
|
|
std::cout << "unknown error\n";
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2019-10-28 14:36:21 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|