Skip to content

Commit 39110eb

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 39110eb

File tree

9 files changed

+696
-115
lines changed

9 files changed

+696
-115
lines changed
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: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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, environ
30+
31+
import Globals
32+
33+
headers = [
34+
( "vulkan_core", "" ),
35+
( "vulkan_beta", "VK_ENABLE_BETA_EXTENSIONS" ),
36+
( "vulkan_win32", "VK_USE_PLATFORM_WIN32_KHR" ),
37+
( "vulkan_wayland", "VK_USE_PLATFORM_WAYLAND_KHR" ),
38+
( "vulkan_xlib", "VK_USE_PLATFORM_XLIB_KHR" ),
39+
( "vulkan_xlib_xrandr", "VK_USE_PLATFORM_XLIB_XRANDR_EXT" )
40+
]
41+
42+
def CreateFiles( files ):
43+
for file in files:
44+
open( file, "w", encoding = "utf-8" )
45+
46+
def DeleteFiles( files ):
47+
for file in files:
48+
remove( file )
49+
50+
vulkanLoaderPath = "../../src/engine/renderer-vulkan/VulkanLoader/"
51+
vulkanGraphicsCorePath = "../../src/engine/renderer-vulkan/GraphicsCore/"
52+
53+
tmpFiles = ( "FunctionDecls.h", "FunctionLoaderInstance.cpp", "FunctionLoaderDevice.cpp", "FunctionStore.cpp",
54+
"FeaturesConfig.h", "FeaturesConfigGet", "FeaturesConfigCreate", "FeaturesConfigCreateDevice", "FeaturesConfigMap",
55+
"FeaturesConfigMain.h", "FeaturesConfigGetMain", "FeaturesConfigCreateMain", "FeaturesConfigCreateDeviceMain", "FeaturesConfigMapMain",
56+
"prev" )
57+
58+
CreateFiles( tmpFiles )
59+
60+
with open( "../../LICENSE-DAEMON-VULKAN.txt", "r" ) as inp:
61+
license = "/*\n" + inp.read() + "\n*/\n\n"
62+
63+
with open( "Vulkan.h", mode = "r", encoding = "utf-8", newline = "\n" ) as inp:
64+
with open( "FunctionDecls.h", mode = "w", encoding = "utf-8", newline = "\n" ) as out:
65+
out.write( inp.read() )
66+
67+
68+
for header in headers:
69+
environ["DAEMON_VULKAN_HEADER_DEFINE"] = header[1]
70+
71+
system( "python genvk.py -o " + vulkanLoaderPath + "vulkan -apiname vulkan " + header[0] + ".h" )
72+
73+
74+
with open( "FunctionDecls.h", "r" ) as inp:
75+
with open( vulkanLoaderPath + "Vulkan.h", mode = "w", encoding = "utf-8", newline = "" ) as out:
76+
out.write( license )
77+
out.write( inp.read() )
78+
out.write( "\n\n#endif // VULKAN_LOADER_H" )
79+
80+
with open( "VulkanLoadFunctions.cpp", mode = "r", encoding = "utf-8", newline = "\n" ) as inp:
81+
functionLoadStart = inp.read()
82+
83+
with open( "FunctionLoaderInstance.cpp", "r" ) as inp:
84+
with open( "FunctionLoaderDevice.cpp", "r" ) as inp2:
85+
with open( vulkanLoaderPath + "VulkanLoadFunctions.cpp", mode = "w", encoding = "utf-8", newline = "" ) as out:
86+
out.write( license )
87+
out.write( functionLoadStart )
88+
out.write( "\n\nvoid VulkanLoadInstanceFunctions( VkInstance instance ) {\n" )
89+
out.write( inp.read() )
90+
out.write( "}\n\n" )
91+
out.write( "void VulkanLoadDeviceFunctions( VkDevice device ) {\n" )
92+
out.write( inp2.read() )
93+
out.write( "}" )
94+
95+
with open( "FunctionStore.cpp", "r" ) as inp:
96+
with open( vulkanLoaderPath + "Vulkan.cpp", mode = "w", encoding = "utf-8", newline = "" ) as out:
97+
out.write( license )
98+
out.write( "// Auto-generated, do not modify\n\n" )
99+
out.write( "#include \"Vulkan.h\"" )
100+
out.write( inp.read() )
101+
102+
with open( "FeaturesConfig.cpp", mode = "r", encoding = "utf-8", newline = "" ) as inp:
103+
featuresConfigStart = inp.read()
104+
105+
with open( "FeaturesConfigGet", mode = "r" ) as inpGet:
106+
with open( "FeaturesConfigCreate", mode = "r" ) as inpCreate:
107+
with open( "FeaturesConfigGetMain", mode = "r" ) as inpGetMain:
108+
with open( "FeaturesConfigCreateMain", mode = "r" ) as inpCreateMain:
109+
with open( "FeaturesConfigCreateDevice", mode = "r" ) as inpCreateDevice:
110+
with open( "FeaturesConfigCreateDeviceMain", mode = "r" ) as inpCreateDeviceMain:
111+
with open( vulkanGraphicsCorePath + "FeaturesConfig.cpp", mode = "w", encoding = "utf-8", newline = "" ) as out:
112+
out.write( license )
113+
out.write( featuresConfigStart )
114+
out.write( inpGet.read() )
115+
out.write( inpGetMain.read() )
116+
out.write( "\tFeaturesConfig cfg {\n" )
117+
out.write( inpCreate.read() )
118+
out.write( inpCreateMain.read() )
119+
out.write( "int CreateDevice( VkDeviceCreateInfo& deviceInfo, const VkAllocationCallbacks* allocator,\n" )
120+
out.write( " const EngineConfig& engineCfg, const FeaturesConfig& cfg, VkDevice* device ) {\n" )
121+
out.write( "\tconst bool intelWorkaround = std::string( engineCfg.driverName ).find( \"Intel\" ) != std::string::npos;\n\n" )
122+
out.write( inpCreateDevice.read() )
123+
out.write( inpCreateDeviceMain.read() )
124+
125+
with open( "FeaturesConfig.h", mode = "r" ) as inpCfg:
126+
with open( "FeaturesConfigMain.h", mode = "r" ) as inpCfgMain:
127+
with open( vulkanGraphicsCorePath + "FeaturesConfig.h", mode = "w", encoding = "utf-8", newline = "" ) as out:
128+
out.write( license )
129+
out.write( "// Auto-generated, do not modify\n\n" )
130+
out.write( "#ifndef FEATURES_CONFIG_H\n" )
131+
out.write( "#define FEATURES_CONFIG_H\n\n" )
132+
out.write( "#include \"Decls.h\"\n\n" )
133+
out.write( "struct FeaturesConfig {\n" )
134+
out.write( inpCfg.read() )
135+
out.write( inpCfgMain.read() )
136+
out.write( "};\n\n" )
137+
out.write( "FeaturesConfig GetPhysicalDeviceFeatures( const VkPhysicalDevice physicalDevice, const EngineConfig& engineCfg );\n\n" )
138+
out.write( "int CreateDevice( VkDeviceCreateInfo& deviceInfo, const VkAllocationCallbacks* allocator,\n" )
139+
out.write( " const EngineConfig& engineCfg, const FeaturesConfig& cfg, VkDevice* device );\n\n" )
140+
out.write( "#endif // FEATURES_CONFIG_H\n" )
141+
142+
with open( "FeaturesConfigMap", mode = "r" ) as inpMap:
143+
with open( "FeaturesConfigMapMain", mode = "r" ) as inpMapMain:
144+
with open( vulkanGraphicsCorePath + "FeaturesConfigMap.cpp", mode = "w", encoding = "utf-8", newline = "" ) as out:
145+
out.write( license )
146+
out.write( "// Auto-generated, do not modify\n\n" )
147+
out.write( "#include \"FeaturesConfig.h\"\n\n" )
148+
out.write( "#include \"FeaturesConfigMap.h\"\n\n" )
149+
out.write( "std::unordered_map<std::string, FeatureData> featuresConfigMap {\n" )
150+
out.write( inpMap.read() )
151+
out.write( inpMapMain.read().rstrip( "," ) + "};" )
152+
153+
DeleteFiles( tmpFiles )

0 commit comments

Comments
 (0)