From 2f2c19b4ecc2078e858210799940846f4b8eb1af Mon Sep 17 00:00:00 2001 From: Piers Daniell Date: Wed, 4 Feb 2026 14:39:46 -0700 Subject: [PATCH 1/4] Draft: const-ref based inline helper functions --- appendices/boilerplate.adoc | 26 ++++++++++++ scripts/generator.py | 82 +++++++++++++++++++++++++++++++++++++ xml/vk.xml | 29 +++++++++++-- 3 files changed, 133 insertions(+), 4 deletions(-) diff --git a/appendices/boilerplate.adoc b/appendices/boilerplate.adoc index 9ed552bef..c464bb5b8 100644 --- a/appendices/boilerplate.adoc +++ b/appendices/boilerplate.adoc @@ -312,6 +312,32 @@ endif::VKSC_VERSION_1_0[] ==== Vulkan Helper Macros +[open,refpage='VK_CPP11_FEATURES',desc='Define set to 1 if C++11 features are available',type='defines'] +-- +dname:VK_CPP11_FEATURES defines an object-like macro that indicates whether C++11 +features are enabled and can be used by the application. + +include::{generated}/api/defines/VK_CPP11_FEATURES.adoc[] + +By default the dname:VK_CPP11_FEATURES macro is '1' if the module is +compiled with a '__cplusplus' value of '201103L' or larger, or '0' otherwise. +C++11 features can be disabled by the application by defining the VK_CPP11_FEATURES macro +to '0'. +-- + +[open,refpage='VK_CPP20_FEATURES',desc='Define set to 1 if C++11 features are available',type='defines'] +-- +dname:VK_CPP20_FEATURES defines an object-like macro that indicates whether C++11 +features are enabled and can be used by the application. + +include::{generated}/api/defines/VK_CPP20_FEATURES.adoc[] + +By default the dname:VK_CPP20_FEATURES macro is '1' if the module is +compiled with a '__cplusplus' value of '202002L' or larger, or '0' otherwise. +C++11 features can be disabled by the application by defining the VK_CPP20_FEATURES macro +to '0'. +-- + [open,refpage='VK_CPP11_DEFAULT',desc='Function macro to allow optional C++11 default member initializers',type='defines'] -- dname:VK_CPP11_DEFAULT defines a function macro to allow optional structure default diff --git a/scripts/generator.py b/scripts/generator.py index f4f1f88d7..adc9dcd90 100644 --- a/scripts/generator.py +++ b/scripts/generator.py @@ -1394,6 +1394,88 @@ def makeCDecls(self, cmd): indentdecl += ');' else: indentdecl = '(void);' + + # Create C++ variants of the function + params = cmd.findall('param') + doCppOverloads = False + cppOverloads = '' + if len(params) > 0: + cppOverloads += '\n' + cppOverloads += '\n' + cppOverloads += '#if VK_CPP20_FEATURES\n' + cppOverloads += 'extern "C++" inline ' + proto = cmd.find('proto') + for elem in proto: + cppOverloads += f'{elem.text}{noneStr(elem.tail)}' + cppOverloads += '(' + paramnames = [] + #for param in params: + index = 0 + while index < len(params): + param = params[index] + paramtype = param.find('type') + paramname = param.find('name') + if noneStr(param.text).strip() == 'const' and noneStr(paramtype.tail).strip() == '*' and paramtype.text != 'void' and noneStr(param.attrib.get('optional')) != 'true' and param.attrib.get('len') == None: + paramnames.append('const ' + paramtype.text + '& ' + paramname.text) + doCppOverloads = True + elif paramtype.text == 'uint32_t' and paramname.text.endswith('Count') and paramtype.tail.strip() != '*': + foundSpan = False + while index + 1 < len(params): + if params[index + 1].attrib.get('len') == paramname.text and noneStr(params[index + 1].text).strip() == 'const' and params[index + 1].find('type').tail.strip() == '*' and noneStr(params[index + 1].attrib.get('optional')) != 'true': + doCppOverloads = True + foundSpan = True + paramnames.append('const std::span<' + params[index + 1].find('type').text + '>& ' + params[index + 1].find('name').text) + index += 1 + else: + break + if not foundSpan: + paramnames.append(noneStr(param.text) + paramtype.text + paramtype.tail + paramname.text) + elif paramtype.text == 'VkAllocationCallbacks': + doCppOverloads = True + else: + paramnames.append(noneStr(param.text) + paramtype.text + paramtype.tail + paramname.text + noneStr(paramname.tail)) + index += 1 + + cppOverloads += ', '.join(paramnames) + cppOverloads += ')\n' + cppOverloads += '{\n' + cppOverloads += f' return {proto.find('name').text}(' + paramnames = [] + index = 0 + while index < len(params): + param = params[index] + paramtype = param.find('type') + paramname = param.find('name') + if noneStr(param.text).strip() == 'const' and noneStr(paramtype.tail).strip() == '*' and paramtype.text != 'void' and noneStr(param.attrib.get('optional')) != 'true' and param.attrib.get('len') == None: + paramnames.append('&' + paramname.text) + elif paramtype.text == 'uint32_t' and paramname.text.endswith('Count') and paramtype.tail.strip() != '*': + spans = [] + startIndex = index + 1 + while index + 1 < len(params): + if params[index + 1].attrib.get('len') == paramname.text and noneStr(params[index + 1].text).strip() == 'const' and params[index + 1].find('type').tail.strip() == '*' and noneStr(params[index + 1].attrib.get('optional')) != 'true': + spans.append(params[index + 1].find('name').text + '.data()') + index += 1 + else: + break + if len(spans) > 0: + paramnames.append('uint32_t(' + params[startIndex].find('name').text + '.size())') + for span in spans: + paramnames.append(span) + else: + paramnames.append(paramname.text) + elif paramtype.text == 'VkAllocationCallbacks': + paramnames.append('nullptr') + else: + paramnames.append(paramname.text) + index += 1 + cppOverloads += ', '.join(paramnames) + cppOverloads += ');\n' + cppOverloads += '}\n' + cppOverloads += '#endif' + + if doCppOverloads and not isfuncpointer: + indentdecl += cppOverloads + # Non-indented parameters paramdecl = '(' if n > 0: diff --git a/xml/vk.xml b/xml/vk.xml index bfddbfa1f..7bd47b1d8 100755 --- a/xml/vk.xml +++ b/xml/vk.xml @@ -204,10 +204,29 @@ branch of the member gitlab server. #define VK_USE_64_BIT_PTR_DEFINES 0 #endif #endif + + +#ifndef VK_CPP11_FEATURES + #if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)) + #define VK_CPP11_FEATURES 1 + #else + #define VK_CPP11_FEATURES 0 + #endif +#endif + + +#ifndef VK_CPP20_FEATURES + #if (defined(__cplusplus) && (__cplusplus >= 202002L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L)) + #define VK_CPP20_FEATURES 1 + #else + #define VK_CPP20_FEATURES 0 + #endif +#endif + #ifndef VK_DEFINE_NON_DISPATCHABLE_HANDLE #if (VK_USE_64_BIT_PTR_DEFINES==1) - #if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)) + #if VK_CPP11_FEATURES #define VK_NULL_HANDLE nullptr #else #define VK_NULL_HANDLE ((void*)0) @@ -236,9 +255,9 @@ branch of the member gitlab server. #endif #endif - + #ifndef VK_CPP11_DEFAULT - #if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)) + #if VK_CPP11_FEATURES #define VK_CPP11_DEFAULT(value) { value } #else #define VK_CPP11_DEFAULT(value) @@ -18505,10 +18524,12 @@ endif::VK_KHR_internally_synchronized_queues[] + + - + From 4d67b1307aa8681faaab44e1189cbeb06ed03dbb Mon Sep 17 00:00:00 2001 From: Piers Daniell Date: Thu, 5 Feb 2026 10:00:09 -0700 Subject: [PATCH 2/4] Tweak to the span parameter to allow temporary array parameters This tweak allows C++20 apps do use temporary arrays as parameters like `vkResetFences(device, {{fence}});`. When C++26 (P2447R4) becomes available apps will be able to do `vkResetFences(device, {fence});` to make it slightly nicer. --- scripts/generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generator.py b/scripts/generator.py index adc9dcd90..97ec5a708 100644 --- a/scripts/generator.py +++ b/scripts/generator.py @@ -1424,7 +1424,7 @@ def makeCDecls(self, cmd): if params[index + 1].attrib.get('len') == paramname.text and noneStr(params[index + 1].text).strip() == 'const' and params[index + 1].find('type').tail.strip() == '*' and noneStr(params[index + 1].attrib.get('optional')) != 'true': doCppOverloads = True foundSpan = True - paramnames.append('const std::span<' + params[index + 1].find('type').text + '>& ' + params[index + 1].find('name').text) + paramnames.append('std::span ' + params[index + 1].find('name').text) index += 1 else: break From 85e8c6241bb67c07f71a763c61586bd6703c97ad Mon Sep 17 00:00:00 2001 From: Piers Daniell Date: Thu, 5 Feb 2026 15:04:09 -0700 Subject: [PATCH 3/4] Fix some CI failures --- build_tests/expectations/all-1.0.html | 18 +++++++++++++++-- build_tests/expectations/all.html | 27 ++++++++++++++++++++++--- build_tests/expectations/copy2-1.0.html | 9 ++++++++- build_tests/expectations/core.html | 9 ++++++++- build_tests/expectations/hic-1.0.html | 18 +++++++++++++++-- build_tests/expectations/hic.html | 27 ++++++++++++++++++++++--- 6 files changed, 96 insertions(+), 12 deletions(-) diff --git a/build_tests/expectations/all-1.0.html b/build_tests/expectations/all-1.0.html index 41b77223d..d1f936f6d 100644 --- a/build_tests/expectations/all-1.0.html +++ b/build_tests/expectations/all-1.0.html @@ -163,7 +163,14 @@

2.1. Lo
// Provided by VK_KHR_copy_commands2
 void vkCmdCopyBufferToImage2KHR(
     VkCommandBuffer                             commandBuffer,
-    const VkCopyBufferToImageInfo2*             pCopyBufferToImageInfo);
+ const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2KHR(commandBuffer, &pCopyBufferToImageInfo); +} +#endif
@@ -673,7 +680,14 @@

3. Host Image Copy

// Provided by VK_EXT_host_image_copy
 VkResult vkCopyMemoryToImageEXT(
     VkDevice                                    device,
-    const VkCopyMemoryToImageInfo*              pCopyMemoryToImageInfo);
+ const VkCopyMemoryToImageInfo* pCopyMemoryToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline VkResult vkCopyMemoryToImageEXT(VkDevice device, const VkCopyMemoryToImageInfo& pCopyMemoryToImageInfo) +{ + return vkCopyMemoryToImageEXT(device, &pCopyMemoryToImageInfo); +} +#endif
diff --git a/build_tests/expectations/all.html b/build_tests/expectations/all.html index 0330c313d..3a5d7f4a0 100644 --- a/build_tests/expectations/all.html +++ b/build_tests/expectations/all.html @@ -163,7 +163,14 @@

2.1. Lo
// Provided by VK_VERSION_1_3
 void vkCmdCopyBufferToImage2(
     VkCommandBuffer                             commandBuffer,
-    const VkCopyBufferToImageInfo2*             pCopyBufferToImageInfo);
+ const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

@@ -172,7 +179,14 @@

2.1. Lo // Equivalent to vkCmdCopyBufferToImage2 void vkCmdCopyBufferToImage2KHR( VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2KHR(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

@@ -706,7 +720,14 @@

3. Host Image Copy

// Equivalent to vkCopyMemoryToImage VkResult vkCopyMemoryToImageEXT( VkDevice device, - const VkCopyMemoryToImageInfo* pCopyMemoryToImageInfo); + const VkCopyMemoryToImageInfo* pCopyMemoryToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline VkResult vkCopyMemoryToImageEXT(VkDevice device, const VkCopyMemoryToImageInfo& pCopyMemoryToImageInfo) +{ + return vkCopyMemoryToImageEXT(device, &pCopyMemoryToImageInfo); +} +#endif
diff --git a/build_tests/expectations/copy2-1.0.html b/build_tests/expectations/copy2-1.0.html index f6823db3c..6197a993b 100644 --- a/build_tests/expectations/copy2-1.0.html +++ b/build_tests/expectations/copy2-1.0.html @@ -161,7 +161,14 @@

2.1. Lo
// Provided by VK_KHR_copy_commands2
 void vkCmdCopyBufferToImage2KHR(
     VkCommandBuffer                             commandBuffer,
-    const VkCopyBufferToImageInfo2*             pCopyBufferToImageInfo);
+ const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2KHR(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

diff --git a/build_tests/expectations/core.html b/build_tests/expectations/core.html index 56e453f62..4fbefca4f 100644 --- a/build_tests/expectations/core.html +++ b/build_tests/expectations/core.html @@ -161,7 +161,14 @@

2.1. Lo
// Provided by VK_VERSION_1_3
 void vkCmdCopyBufferToImage2(
     VkCommandBuffer                             commandBuffer,
-    const VkCopyBufferToImageInfo2*             pCopyBufferToImageInfo);
+ const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

diff --git a/build_tests/expectations/hic-1.0.html b/build_tests/expectations/hic-1.0.html index f27ecfe66..1e446008a 100644 --- a/build_tests/expectations/hic-1.0.html +++ b/build_tests/expectations/hic-1.0.html @@ -163,7 +163,14 @@

2.1. Lo
// Provided by VK_KHR_copy_commands2
 void vkCmdCopyBufferToImage2KHR(
     VkCommandBuffer                             commandBuffer,
-    const VkCopyBufferToImageInfo2*             pCopyBufferToImageInfo);
+ const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2KHR(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

@@ -631,7 +638,14 @@

3. Host Image Copy

// Provided by VK_EXT_host_image_copy
 VkResult vkCopyMemoryToImageEXT(
     VkDevice                                    device,
-    const VkCopyMemoryToImageInfo*              pCopyMemoryToImageInfo);
+ const VkCopyMemoryToImageInfo* pCopyMemoryToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline VkResult vkCopyMemoryToImageEXT(VkDevice device, const VkCopyMemoryToImageInfo& pCopyMemoryToImageInfo) +{ + return vkCopyMemoryToImageEXT(device, &pCopyMemoryToImageInfo); +} +#endif
diff --git a/build_tests/expectations/hic.html b/build_tests/expectations/hic.html index 2cc8db13e..89e77d6df 100644 --- a/build_tests/expectations/hic.html +++ b/build_tests/expectations/hic.html @@ -163,7 +163,14 @@

2.1. Lo
// Provided by VK_VERSION_1_3
 void vkCmdCopyBufferToImage2(
     VkCommandBuffer                             commandBuffer,
-    const VkCopyBufferToImageInfo2*             pCopyBufferToImageInfo);
+ const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

@@ -172,7 +179,14 @@

2.1. Lo // Equivalent to vkCmdCopyBufferToImage2 void vkCmdCopyBufferToImage2KHR( VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline void vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, const VkCopyBufferToImageInfo2& pCopyBufferToImageInfo) +{ + return vkCmdCopyBufferToImage2KHR(commandBuffer, &pCopyBufferToImageInfo); +} +#endif

@@ -669,7 +683,14 @@

3. Host Image Copy

// Equivalent to vkCopyMemoryToImage VkResult vkCopyMemoryToImageEXT( VkDevice device, - const VkCopyMemoryToImageInfo* pCopyMemoryToImageInfo); + const VkCopyMemoryToImageInfo* pCopyMemoryToImageInfo); + +#if VK_CPP20_FEATURES +extern "C++" inline VkResult vkCopyMemoryToImageEXT(VkDevice device, const VkCopyMemoryToImageInfo& pCopyMemoryToImageInfo) +{ + return vkCopyMemoryToImageEXT(device, &pCopyMemoryToImageInfo); +} +#endif
From 5302103f2539cf19fb1170d3035dacaec6882fbc Mon Sep 17 00:00:00 2001 From: Piers Daniell Date: Thu, 5 Feb 2026 15:08:29 -0700 Subject: [PATCH 4/4] Fix vulkan-hpp CI --- tests/hpptest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/hpptest.cpp b/tests/hpptest.cpp index 084df93b8..c67997b5e 100644 --- a/tests/hpptest.cpp +++ b/tests/hpptest.cpp @@ -1,6 +1,8 @@ // Copyright 2019-2026 The Khronos Group Inc. // SPDX-License-Identifier: Apache-2.0 +#include + #include #include #include