Skip to content

Commit dd53e27

Browse files
committed
Update VulkanHeaders generator
- generate sType as with default value - add a script to generate all the headers we need along with function loading - use sized enums - fix bitwidth, don't load funcpointer - generate FeaturesConfigMap, FeaturesConfig and the loader for it - skip useless shit extension features
1 parent 6e9a777 commit dd53e27

File tree

10 files changed

+794
-117
lines changed

10 files changed

+794
-117
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
=============================================================================
3+
Daemon-Vulkan BSD Source Code
4+
Copyright (c) 2025-2026 Reaper
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Reaper nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL REAPER BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
=============================================================================
29+
*/
30+
// Auto-generated, do not modify
31+
32+
#include "Vulkan.h"
33+
34+
#include "GraphicsCoreStore.h"
35+
36+
#include "EngineConfig.h"
37+
38+
#include "FeaturesConfig.h"
39+
40+
FeaturesConfig GetPhysicalDeviceFeatures( const VkPhysicalDevice physicalDevice, const EngineConfig& engineCfg ) {
41+
const bool intelWorkaround = std::string( engineCfg.driverName ).find( "Intel" ) != std::string::npos;
42+

libs/VulkanHeaders/GenerateAll.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# =============================================================================
2+
# Daemon-Vulkan BSD Source Code
3+
# Copyright (c) 2025-2026 Reaper
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# * Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the Reaper nor the
14+
# names of its contributors may be used to endorse or promote products
15+
# derived from this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
18+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
# DISCLAIMED. IN NO EVENT SHALL REAPER BE LIABLE FOR ANY
21+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
# =============================================================================
28+
29+
from os import system, remove
30+
31+
headers = [
32+
( "vulkan_core", "w", "" ),
33+
( "vulkan_beta", "a", "VK_ENABLE_BETA_EXTENSIONS" ),
34+
( "vulkan_win32", "a", "VK_USE_PLATFORM_WIN32_KHR" ),
35+
( "vulkan_wayland", "a", "VK_USE_PLATFORM_WAYLAND_KHR" ),
36+
( "vulkan_xlib", "a", "VK_USE_PLATFORM_XLIB_KHR" ),
37+
( "vulkan_xlib_xrandr", "a", "VK_USE_PLATFORM_XLIB_XRANDR_EXT" )
38+
]
39+
40+
with open( "FunctionDecls.h", "w", encoding = 'utf-8' ) as f:
41+
with open( "FunctionLoaderInstance.cpp", "w", encoding = 'utf-8' ) as f1:
42+
with open( "FunctionLoaderDevice.cpp", "w", encoding = 'utf-8' ) as f2:
43+
print( "" )
44+
45+
for header in headers:
46+
if header[2]:
47+
define = " -define " + header[2]
48+
else:
49+
define = ""
50+
system( "python genvk.py -o ../../../src/engine/renderer-vulkan/VulkanLoader/vulkan -apiname vulkan -mode " + header[1] + define + " " + header[0] + ".h" )
51+
52+
with open( "FunctionDecls.h", "r" ) as inp:
53+
with open( "../../../src/engine/renderer-vulkan/VulkanLoader/Vulkan.h", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
54+
out.write( inp.read() )
55+
out.write( '#endif // VULKAN_LOADER_H' )
56+
57+
with open( 'VulkanLoadFunctions.cpp', mode = 'r', encoding = 'utf-8', newline = '\n' ) as inp:
58+
functionLoadStart = inp.read()
59+
60+
with open( "FunctionLoaderInstance.cpp", "r" ) as inp:
61+
with open( "FunctionLoaderDevice.cpp", "r" ) as inp2:
62+
with open( "../../../src/engine/renderer-vulkan/VulkanLoader/VulkanLoadFunctions.cpp", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
63+
out.write( functionLoadStart )
64+
out.write( '\n\nvoid VulkanLoadInstanceFunctions( VkInstance instance ) {\n' )
65+
out.write( inp.read() )
66+
out.write( '}\n\n' )
67+
out.write( 'void VulkanLoadDeviceFunctions( VkDevice device ) {\n' )
68+
out.write( inp2.read() )
69+
out.write( '}' )
70+
71+
with open( 'FeaturesConfig.cpp', mode = 'r', encoding = 'utf-8', newline = '' ) as inp:
72+
featuresConfigStart = inp.read()
73+
74+
with open( "FeaturesConfigGet", mode = 'r' ) as inpGet:
75+
with open( "FeaturesConfigCreate", mode = 'r' ) as inpCreate:
76+
with open( "FeaturesConfigGetMain", mode = 'r' ) as inpGetMain:
77+
with open( "FeaturesConfigCreateMain", mode = 'r' ) as inpCreateMain:
78+
with open( "FeaturesConfigCreateDevice", mode = 'r' ) as inpCreateDevice:
79+
with open( "FeaturesConfigCreateDeviceMain", mode = 'r' ) as inpCreateDeviceMain:
80+
with open( "../../../src/engine/renderer-vulkan/GraphicsCore/FeaturesConfig.cpp", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
81+
out.write( featuresConfigStart )
82+
out.write( inpGet.read() )
83+
out.write( inpGetMain.read() )
84+
out.write( "\tFeaturesConfig cfg {\n" )
85+
out.write( inpCreate.read() )
86+
out.write( inpCreateMain.read() )
87+
out.write( "int CreateDevice( VkDeviceCreateInfo& deviceInfo, const VkAllocationCallbacks* allocator,\n" )
88+
out.write( " const EngineConfig& engineCfg, const FeaturesConfig& cfg, VkDevice* device ) {\n" )
89+
out.write( "\tconst bool intelWorkaround = std::string( engineCfg.driverName ).find( \"Intel\" ) != std::string::npos;\n\n" )
90+
out.write( inpCreateDevice.read() )
91+
out.write( inpCreateDeviceMain.read() )
92+
93+
with open( "FeaturesConfig.h", mode = 'r' ) as inpCfg:
94+
with open( "FeaturesConfigMain.h", mode = 'r' ) as inpCfgMain:
95+
with open( "../../../src/engine/renderer-vulkan/GraphicsCore/FeaturesConfig.h", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
96+
out.write( "// Auto-generated, do not modify\n\n" )
97+
out.write( "#ifndef FEATURES_CONFIG_H\n" )
98+
out.write( "#define FEATURES_CONFIG_H\n\n" )
99+
out.write( "#include \"Decls.h\"\n\n" )
100+
out.write( "struct FeaturesConfig {\n" )
101+
out.write( inpCfg.read() )
102+
out.write( inpCfgMain.read() )
103+
out.write( "};\n\n" )
104+
out.write( "FeaturesConfig GetPhysicalDeviceFeatures( const VkPhysicalDevice physicalDevice, const EngineConfig& engineCfg );\n\n" )
105+
out.write( "int CreateDevice( VkDeviceCreateInfo& deviceInfo, const VkAllocationCallbacks* allocator,\n" )
106+
out.write( " const EngineConfig& engineCfg, const FeaturesConfig& cfg, VkDevice* device );\n\n" )
107+
out.write( "#endif // FEATURES_CONFIG_H\n" )
108+
109+
with open( "FeaturesConfigMap", mode = 'r' ) as inpMap:
110+
with open( "FeaturesConfigMapMain", mode = 'r' ) as inpMapMain:
111+
with open( "../../../src/engine/renderer-vulkan/GraphicsCore/FeaturesConfigMap.cpp", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
112+
out.write( "// Auto-generated, do not modify\n\n" )
113+
out.write( "#include \"FeaturesConfig.h\"\n\n" )
114+
out.write( "#include \"FeaturesConfigMap.h\"\n\n" )
115+
out.write( "std::unordered_map<std::string, FeatureData> featuresConfigMap {\n" )
116+
out.write( inpMap.read() )
117+
out.write( inpMapMain.read().rstrip( "," ) + "};" )
118+
119+
remove( "FunctionDecls.h" )
120+
remove( "FunctionLoaderInstance.cpp" )
121+
remove( "FunctionLoaderDevice.cpp" )
122+
remove( "FeaturesConfig.h" )
123+
remove( "FeaturesConfigMain.h" )
124+
remove( "FeaturesConfigGet" )
125+
remove( "FeaturesConfigGetMain" )
126+
remove( "FeaturesConfigCreate" )
127+
remove( "FeaturesConfigCreateMain" )
128+
remove( "FeaturesConfigCreateDevice" )
129+
remove( "FeaturesConfigCreateDeviceMain" )
130+
remove( "FeaturesConfigMap" )
131+
remove( "FeaturesConfigMapMain" )
132+
remove( "prev" )

0 commit comments

Comments
 (0)