From 6604f5a1d92794e814d062aa13612d0091480ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 17 Jun 2024 14:51:12 +0200 Subject: [PATCH] Make generated headers resistant to missing definition of NOMINMAX for windows builds. (#1906) --- CMakeLists.txt | 2 +- RAII_Samples/05_InitSwapchain/05_InitSwapchain.cpp | 2 +- RAII_Samples/utils/utils.hpp | 4 ++-- VulkanHppGenerator.cpp | 4 ++-- samples/05_InitSwapchain/05_InitSwapchain.cpp | 2 +- samples/utils/utils.cpp | 4 ++-- samples/utils/utils.hpp | 6 +++--- snippets/ArrayWrapper1D.hpp | 2 +- tests/UniqueHandle/UniqueHandle.cpp | 2 +- vulkan/vulkan.hpp | 4 ++-- vulkan/vulkan_structs.hpp | 10 +++++----- vulkan/vulkansc.hpp | 4 ++-- vulkan/vulkansc_structs.hpp | 6 +++--- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7b0367..d5c8d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ function( vulkan_hpp__setup_platform ) cmake_parse_arguments( TARGET "{options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) if( WIN32 ) - target_compile_definitions( ${TARGET_NAME} PUBLIC NOMINMAX VK_USE_PLATFORM_WIN32_KHR ) + target_compile_definitions( ${TARGET_NAME} PUBLIC VK_USE_PLATFORM_WIN32_KHR ) elseif( APPLE ) target_compile_definitions( ${TARGET_NAME} PUBLIC VK_USE_PLATFORM_MACOS_MVK ) elseif( UNIX ) diff --git a/RAII_Samples/05_InitSwapchain/05_InitSwapchain.cpp b/RAII_Samples/05_InitSwapchain/05_InitSwapchain.cpp index ac225e1..15a0bb7 100644 --- a/RAII_Samples/05_InitSwapchain/05_InitSwapchain.cpp +++ b/RAII_Samples/05_InitSwapchain/05_InitSwapchain.cpp @@ -93,7 +93,7 @@ int main( int /*argc*/, char ** /*argv*/ ) vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); vk::Extent2D swapchainExtent; - if ( surfaceCapabilities.currentExtent.width == std::numeric_limits::max() ) + if ( surfaceCapabilities.currentExtent.width == (std::numeric_limits::max)() ) { // If the surface size is undefined, the size is set to the size of the images requested. swapchainExtent.width = vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); diff --git a/RAII_Samples/utils/utils.hpp b/RAII_Samples/utils/utils.hpp index ffac2cd..0d8bbc3 100644 --- a/RAII_Samples/utils/utils.hpp +++ b/RAII_Samples/utils/utils.hpp @@ -342,7 +342,7 @@ namespace vk vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); vk::Extent2D swapchainExtent; - if ( surfaceCapabilities.currentExtent.width == std::numeric_limits::max() ) + if ( surfaceCapabilities.currentExtent.width == (std::numeric_limits::max)() ) { // If the surface size is undefined, the size is set to the size of the images requested. swapchainExtent.width = vk::su::clamp( extent.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); @@ -509,7 +509,7 @@ namespace vk vk::raii::SurfaceKHR const & surface ) { std::vector queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); - assert( queueFamilyProperties.size() < std::numeric_limits::max() ); + assert( queueFamilyProperties.size() < (std::numeric_limits::max)() ); uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( queueFamilyProperties ); if ( physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, surface ) ) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 9501f76..80f83df 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -8220,7 +8220,7 @@ std::string VulkanHppGenerator::generateLenInitializer( if ( !litit->second.front()->arraySizes.empty() ) { assert( litit->second.front()->arraySizes.size() == 1 ); - initializer = "std::min( " + initializer + ", " + litit->second.front()->arraySizes[0] + " )"; + initializer = "(std::min)( " + initializer + ", " + litit->second.front()->arraySizes[0] + " )"; } return initializer; } @@ -11720,7 +11720,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const & struct if ( !member.arraySizes.empty() ) { assert( member.arraySizes.size() == 1 ); - lenValue = "std::min( " + lenValue + ", " + member.arraySizes[0] + " )"; + lenValue = "(std::min)( " + lenValue + ", " + member.arraySizes[0] + " )"; } if ( member.type.isPointer() ) diff --git a/samples/05_InitSwapchain/05_InitSwapchain.cpp b/samples/05_InitSwapchain/05_InitSwapchain.cpp index 1c5479a..e763941 100644 --- a/samples/05_InitSwapchain/05_InitSwapchain.cpp +++ b/samples/05_InitSwapchain/05_InitSwapchain.cpp @@ -96,7 +96,7 @@ int main( int /*argc*/, char ** /*argv*/ ) vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); vk::Extent2D swapchainExtent; - if ( surfaceCapabilities.currentExtent.width == std::numeric_limits::max() ) + if ( surfaceCapabilities.currentExtent.width == (std::numeric_limits::max)() ) { // If the surface size is undefined, the size is set to the size of the images requested. swapchainExtent.width = vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); diff --git a/samples/utils/utils.cpp b/samples/utils/utils.cpp index da885a8..3cc5c6c 100644 --- a/samples/utils/utils.cpp +++ b/samples/utils/utils.cpp @@ -422,7 +422,7 @@ namespace vk std::pair findGraphicsAndPresentQueueFamilyIndex( vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const & surface ) { std::vector queueFamilyProperties = physicalDevice.getQueueFamilyProperties(); - assert( queueFamilyProperties.size() < std::numeric_limits::max() ); + assert( queueFamilyProperties.size() < (std::numeric_limits::max)() ); uint32_t graphicsQueueFamilyIndex = findGraphicsQueueFamilyIndex( queueFamilyProperties ); if ( physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, surface ) ) @@ -806,7 +806,7 @@ namespace vk vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); vk::Extent2D swapchainExtent; - if ( surfaceCapabilities.currentExtent.width == std::numeric_limits::max() ) + if ( surfaceCapabilities.currentExtent.width == (std::numeric_limits::max)() ) { // If the surface size is undefined, the size is set to the size of the images requested. swapchainExtent.width = clamp( extent.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); diff --git a/samples/utils/utils.hpp b/samples/utils/utils.hpp index bd30051..ee03683 100644 --- a/samples/utils/utils.hpp +++ b/samples/utils/utils.hpp @@ -76,10 +76,10 @@ namespace vk VULKAN_HPP_INLINE uint32_t clampSurfaceImageCount( const uint32_t desiredImageCount, const uint32_t minImageCount, const uint32_t maxImageCount ) { - uint32_t imageCount = std::max( desiredImageCount, minImageCount ); + uint32_t imageCount = (std::max)( desiredImageCount, minImageCount ); if ( maxImageCount > 0 ) { - imageCount = std::min( imageCount, maxImageCount ); + imageCount = (std::min)( imageCount, maxImageCount ); } return imageCount; } @@ -355,7 +355,7 @@ namespace vk static_assert( !std::numeric_limits::is_signed, "Only unsigned types supported!" ); static_assert( std::numeric_limits::is_integer, "Only integer types supported!" ); static_assert( !std::numeric_limits::is_signed, "Only unsigned types supported!" ); - assert( value <= std::numeric_limits::max() ); + assert( value <= (std::numeric_limits::max)() ); return static_cast( value ); } diff --git a/snippets/ArrayWrapper1D.hpp b/snippets/ArrayWrapper1D.hpp index 1a9fd43..bb290bd 100644 --- a/snippets/ArrayWrapper1D.hpp +++ b/snippets/ArrayWrapper1D.hpp @@ -60,7 +60,7 @@ public: private: VULKAN_HPP_CONSTEXPR_14 void copy( char const * data, size_t len ) VULKAN_HPP_NOEXCEPT { - size_t n = std::min( N - 1, len ); + size_t n = (std::min)( N - 1, len ); for ( size_t i = 0; i < n; ++i ) { ( *this )[i] = data[i]; diff --git a/tests/UniqueHandle/UniqueHandle.cpp b/tests/UniqueHandle/UniqueHandle.cpp index 9007234..c9b30d5 100644 --- a/tests/UniqueHandle/UniqueHandle.cpp +++ b/tests/UniqueHandle/UniqueHandle.cpp @@ -174,7 +174,7 @@ vk::UniqueSwapchainKHR createSwapchainKHRUnique( vk::PhysicalDevice physicalDevi vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); vk::SurfaceFormatKHR surfaceFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surface ) ); vk::Extent2D swapchainExtent; - if ( surfaceCapabilities.currentExtent.width == std::numeric_limits::max() ) + if ( surfaceCapabilities.currentExtent.width == (std::numeric_limits::max)() ) { // If the surface size is undefined, the size is set to the size of the images requested. swapchainExtent.width = vk::su::clamp( 64, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index ab2e184..03bd5c0 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -149,7 +149,7 @@ namespace VULKAN_HPP_NAMESPACE private: VULKAN_HPP_CONSTEXPR_14 void copy( char const * data, size_t len ) VULKAN_HPP_NOEXCEPT { - size_t n = std::min( N - 1, len ); + size_t n = ( std::min )( N - 1, len ); for ( size_t i = 0; i < n; ++i ) { ( *this )[i] = data[i]; @@ -16853,7 +16853,7 @@ namespace VULKAN_HPP_NAMESPACE m_library = dlopen( "libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL ); } # elif defined( _WIN32 ) - m_library = ::LoadLibraryA( "vulkan-1.dll" ); + m_library = ::LoadLibraryA( "vulkan-1.dll" ); # else # error unsupported platform # endif diff --git a/vulkan/vulkan_structs.hpp b/vulkan/vulkan_structs.hpp index 75b45ef..16d4713 100644 --- a/vulkan/vulkan_structs.hpp +++ b/vulkan/vulkan_structs.hpp @@ -67661,7 +67661,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NAMESPACE::Bool32 subsetAllocation_ = {}, void * pNext_ = nullptr ) : pNext( pNext_ ) - , physicalDeviceCount( std::min( static_cast( physicalDevices_.size() ), VK_MAX_DEVICE_GROUP_SIZE ) ) + , physicalDeviceCount( ( std::min )( static_cast( physicalDevices_.size() ), VK_MAX_DEVICE_GROUP_SIZE ) ) , subsetAllocation( subsetAllocation_ ) { VULKAN_HPP_ASSERT( physicalDevices_.size() < VK_MAX_DEVICE_GROUP_SIZE ); @@ -73118,8 +73118,8 @@ namespace VULKAN_HPP_NAMESPACE # if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) PhysicalDeviceMemoryProperties( VULKAN_HPP_NAMESPACE::ArrayProxy const & memoryTypes_, VULKAN_HPP_NAMESPACE::ArrayProxy const & memoryHeaps_ = {} ) - : memoryTypeCount( std::min( static_cast( memoryTypes_.size() ), VK_MAX_MEMORY_TYPES ) ) - , memoryHeapCount( std::min( static_cast( memoryHeaps_.size() ), VK_MAX_MEMORY_HEAPS ) ) + : memoryTypeCount( ( std::min )( static_cast( memoryTypes_.size() ), VK_MAX_MEMORY_TYPES ) ) + , memoryHeapCount( ( std::min )( static_cast( memoryHeaps_.size() ), VK_MAX_MEMORY_HEAPS ) ) { VULKAN_HPP_ASSERT( memoryTypes_.size() < VK_MAX_MEMORY_TYPES ); memcpy( memoryTypes, memoryTypes_.data(), memoryTypeCount * sizeof( VULKAN_HPP_NAMESPACE::MemoryType ) ); @@ -100492,7 +100492,7 @@ namespace VULKAN_HPP_NAMESPACE # if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) QueueFamilyGlobalPriorityPropertiesKHR( VULKAN_HPP_NAMESPACE::ArrayProxy const & priorities_, void * pNext_ = nullptr ) - : pNext( pNext_ ), priorityCount( std::min( static_cast( priorities_.size() ), VK_MAX_GLOBAL_PRIORITY_SIZE_KHR ) ) + : pNext( pNext_ ), priorityCount( ( std::min )( static_cast( priorities_.size() ), VK_MAX_GLOBAL_PRIORITY_SIZE_KHR ) ) { VULKAN_HPP_ASSERT( priorities_.size() < VK_MAX_GLOBAL_PRIORITY_SIZE_KHR ); memcpy( priorities, priorities_.data(), priorityCount * sizeof( VULKAN_HPP_NAMESPACE::QueueGlobalPriorityKHR ) ); @@ -109942,7 +109942,7 @@ namespace VULKAN_HPP_NAMESPACE # if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) ShaderModuleIdentifierEXT( VULKAN_HPP_NAMESPACE::ArrayProxy const & identifier_, void * pNext_ = nullptr ) - : pNext( pNext_ ), identifierSize( std::min( static_cast( identifier_.size() ), VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT ) ) + : pNext( pNext_ ), identifierSize( ( std::min )( static_cast( identifier_.size() ), VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT ) ) { VULKAN_HPP_ASSERT( identifier_.size() < VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT ); memcpy( identifier, identifier_.data(), identifierSize * sizeof( uint8_t ) ); diff --git a/vulkan/vulkansc.hpp b/vulkan/vulkansc.hpp index 4278fe2..c7dc102 100644 --- a/vulkan/vulkansc.hpp +++ b/vulkan/vulkansc.hpp @@ -149,7 +149,7 @@ namespace VULKAN_HPP_NAMESPACE private: VULKAN_HPP_CONSTEXPR_14 void copy( char const * data, size_t len ) VULKAN_HPP_NOEXCEPT { - size_t n = std::min( N - 1, len ); + size_t n = ( std::min )( N - 1, len ); for ( size_t i = 0; i < n; ++i ) { ( *this )[i] = data[i]; @@ -6985,7 +6985,7 @@ namespace VULKAN_HPP_NAMESPACE m_library = dlopen( "libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL ); } # elif defined( _WIN32 ) - m_library = ::LoadLibraryA( "vulkan-1.dll" ); + m_library = ::LoadLibraryA( "vulkan-1.dll" ); # else # error unsupported platform # endif diff --git a/vulkan/vulkansc_structs.hpp b/vulkan/vulkansc_structs.hpp index 97a9695..95e67da 100644 --- a/vulkan/vulkansc_structs.hpp +++ b/vulkan/vulkansc_structs.hpp @@ -32923,7 +32923,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NAMESPACE::Bool32 subsetAllocation_ = {}, void * pNext_ = nullptr ) : pNext( pNext_ ) - , physicalDeviceCount( std::min( static_cast( physicalDevices_.size() ), VK_MAX_DEVICE_GROUP_SIZE ) ) + , physicalDeviceCount( ( std::min )( static_cast( physicalDevices_.size() ), VK_MAX_DEVICE_GROUP_SIZE ) ) , subsetAllocation( subsetAllocation_ ) { VULKAN_HPP_ASSERT( physicalDevices_.size() < VK_MAX_DEVICE_GROUP_SIZE ); @@ -35080,8 +35080,8 @@ namespace VULKAN_HPP_NAMESPACE # if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) PhysicalDeviceMemoryProperties( VULKAN_HPP_NAMESPACE::ArrayProxy const & memoryTypes_, VULKAN_HPP_NAMESPACE::ArrayProxy const & memoryHeaps_ = {} ) - : memoryTypeCount( std::min( static_cast( memoryTypes_.size() ), VK_MAX_MEMORY_TYPES ) ) - , memoryHeapCount( std::min( static_cast( memoryHeaps_.size() ), VK_MAX_MEMORY_HEAPS ) ) + : memoryTypeCount( ( std::min )( static_cast( memoryTypes_.size() ), VK_MAX_MEMORY_TYPES ) ) + , memoryHeapCount( ( std::min )( static_cast( memoryHeaps_.size() ), VK_MAX_MEMORY_HEAPS ) ) { VULKAN_HPP_ASSERT( memoryTypes_.size() < VK_MAX_MEMORY_TYPES ); memcpy( memoryTypes, memoryTypes_.data(), memoryTypeCount * sizeof( VULKAN_HPP_NAMESPACE::MemoryType ) );