Skip to content

Commit 105639b

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 b11a0e2 commit 105639b

10 files changed

Lines changed: 677 additions & 117 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Auto-generated, do not modify
2+
3+
#include "Vulkan.h"
4+
5+
#include "GraphicsCoreStore.h"
6+
7+
#include "EngineConfig.h"
8+
9+
#include "FeaturesConfig.h"
10+
11+
FeaturesConfig GetPhysicalDeviceFeatures( const VkPhysicalDevice physicalDevice, const EngineConfig& engineCfg ) {
12+
const bool intelWorkaround = std::string( engineCfg.driverName ).find( "Intel" ) != std::string::npos;
13+

libs/VulkanHeaders/GenerateAll.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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( "../../LICENSE-DAEMON-VULKAN.txt", "r" ) as inp:
53+
license = "/*\n" + inp.read() + "\n*/\n\n"
54+
55+
with open( "FunctionDecls.h", "r" ) as inp:
56+
with open( "../../src/engine/renderer-vulkan/VulkanLoader/Vulkan.h", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
57+
out.write( license )
58+
out.write( inp.read() )
59+
out.write( '#endif // VULKAN_LOADER_H' )
60+
61+
with open( 'VulkanLoadFunctions.cpp', mode = 'r', encoding = 'utf-8', newline = '\n' ) as inp:
62+
functionLoadStart = inp.read()
63+
64+
with open( "FunctionLoaderInstance.cpp", "r" ) as inp:
65+
with open( "FunctionLoaderDevice.cpp", "r" ) as inp2:
66+
with open( "../../src/engine/renderer-vulkan/VulkanLoader/VulkanLoadFunctions.cpp", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
67+
out.write( license )
68+
out.write( functionLoadStart )
69+
out.write( '\n\nvoid VulkanLoadInstanceFunctions( VkInstance instance ) {\n' )
70+
out.write( inp.read() )
71+
out.write( '}\n\n' )
72+
out.write( 'void VulkanLoadDeviceFunctions( VkDevice device ) {\n' )
73+
out.write( inp2.read() )
74+
out.write( '}' )
75+
76+
with open( 'FeaturesConfig.cpp', mode = 'r', encoding = 'utf-8', newline = '' ) as inp:
77+
featuresConfigStart = inp.read()
78+
79+
with open( "FeaturesConfigGet", mode = 'r' ) as inpGet:
80+
with open( "FeaturesConfigCreate", mode = 'r' ) as inpCreate:
81+
with open( "FeaturesConfigGetMain", mode = 'r' ) as inpGetMain:
82+
with open( "FeaturesConfigCreateMain", mode = 'r' ) as inpCreateMain:
83+
with open( "FeaturesConfigCreateDevice", mode = 'r' ) as inpCreateDevice:
84+
with open( "FeaturesConfigCreateDeviceMain", mode = 'r' ) as inpCreateDeviceMain:
85+
with open( "../../src/engine/renderer-vulkan/GraphicsCore/FeaturesConfig.cpp", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
86+
out.write( license )
87+
out.write( featuresConfigStart )
88+
out.write( inpGet.read() )
89+
out.write( inpGetMain.read() )
90+
out.write( "\tFeaturesConfig cfg {\n" )
91+
out.write( inpCreate.read() )
92+
out.write( inpCreateMain.read() )
93+
out.write( "int CreateDevice( VkDeviceCreateInfo& deviceInfo, const VkAllocationCallbacks* allocator,\n" )
94+
out.write( " const EngineConfig& engineCfg, const FeaturesConfig& cfg, VkDevice* device ) {\n" )
95+
out.write( "\tconst bool intelWorkaround = std::string( engineCfg.driverName ).find( \"Intel\" ) != std::string::npos;\n\n" )
96+
out.write( inpCreateDevice.read() )
97+
out.write( inpCreateDeviceMain.read() )
98+
99+
with open( "FeaturesConfig.h", mode = 'r' ) as inpCfg:
100+
with open( "FeaturesConfigMain.h", mode = 'r' ) as inpCfgMain:
101+
with open( "../../src/engine/renderer-vulkan/GraphicsCore/FeaturesConfig.h", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
102+
out.write( license )
103+
out.write( "// Auto-generated, do not modify\n\n" )
104+
out.write( "#ifndef FEATURES_CONFIG_H\n" )
105+
out.write( "#define FEATURES_CONFIG_H\n\n" )
106+
out.write( "#include \"Decls.h\"\n\n" )
107+
out.write( "struct FeaturesConfig {\n" )
108+
out.write( inpCfg.read() )
109+
out.write( inpCfgMain.read() )
110+
out.write( "};\n\n" )
111+
out.write( "FeaturesConfig GetPhysicalDeviceFeatures( const VkPhysicalDevice physicalDevice, const EngineConfig& engineCfg );\n\n" )
112+
out.write( "int CreateDevice( VkDeviceCreateInfo& deviceInfo, const VkAllocationCallbacks* allocator,\n" )
113+
out.write( " const EngineConfig& engineCfg, const FeaturesConfig& cfg, VkDevice* device );\n\n" )
114+
out.write( "#endif // FEATURES_CONFIG_H\n" )
115+
116+
with open( "FeaturesConfigMap", mode = 'r' ) as inpMap:
117+
with open( "FeaturesConfigMapMain", mode = 'r' ) as inpMapMain:
118+
with open( "../../src/engine/renderer-vulkan/GraphicsCore/FeaturesConfigMap.cpp", mode = 'w', encoding = 'utf-8', newline = '' ) as out:
119+
out.write( license )
120+
out.write( "// Auto-generated, do not modify\n\n" )
121+
out.write( "#include \"FeaturesConfig.h\"\n\n" )
122+
out.write( "#include \"FeaturesConfigMap.h\"\n\n" )
123+
out.write( "std::unordered_map<std::string, FeatureData> featuresConfigMap {\n" )
124+
out.write( inpMap.read() )
125+
out.write( inpMapMain.read().rstrip( "," ) + "};" )
126+
127+
remove( "FunctionDecls.h" )
128+
remove( "FunctionLoaderInstance.cpp" )
129+
remove( "FunctionLoaderDevice.cpp" )
130+
remove( "FeaturesConfig.h" )
131+
remove( "FeaturesConfigMain.h" )
132+
remove( "FeaturesConfigGet" )
133+
remove( "FeaturesConfigGetMain" )
134+
remove( "FeaturesConfigCreate" )
135+
remove( "FeaturesConfigCreateMain" )
136+
remove( "FeaturesConfigCreateDevice" )
137+
remove( "FeaturesConfigCreateDeviceMain" )
138+
remove( "FeaturesConfigMap" )
139+
remove( "FeaturesConfigMapMain" )
140+
remove( "prev" )

0 commit comments

Comments
 (0)