Skip to content

Commit 8645b5e

Browse files
authored
Merge pull request #231 from zeux/devt-abi
Generate padding fields in VolkDeviceTable to preserve ABI
2 parents e3e9ea8 + 8ad76a2 commit 8645b5e

File tree

3 files changed

+336
-0
lines changed

3 files changed

+336
-0
lines changed

generate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import urllib
88
import xml.etree.ElementTree as etree
99
import urllib.request
10+
import zlib
1011

1112
cmdversions = {
1213
"vkCmdSetDiscardRectangleEnableEXT": 2,
@@ -157,12 +158,17 @@ def cdepends(key):
157158
for key in block_keys:
158159
blocks[key] = ''
159160

161+
devp = {}
162+
160163
for (group, cmdnames) in command_groups.items():
161164
ifdef = '#if ' + group + '\n'
162165

163166
for key in block_keys:
164167
blocks[key] += ifdef
165168

169+
devt = 0
170+
devo = len(blocks['DEVICE_TABLE'])
171+
166172
for name in sorted(cmdnames):
167173
cmd = commands[name]
168174
type = cmd.findtext('param[1]/type')
@@ -176,6 +182,7 @@ def cdepends(key):
176182
blocks['LOAD_DEVICE'] += '\t' + name + ' = (PFN_' + name + ')load(context, "' + name + '");\n'
177183
blocks['DEVICE_TABLE'] += '\tPFN_' + name + ' ' + name + ';\n'
178184
blocks['LOAD_DEVICE_TABLE'] += '\ttable->' + name + ' = (PFN_' + name + ')load(context, "' + name + '");\n'
185+
devt += 1
179186
elif is_descendant_type(types, type, 'VkInstance'):
180187
blocks['LOAD_INSTANCE'] += '\t' + name + ' = (PFN_' + name + ')load(context, "' + name + '");\n'
181188
elif type != '':
@@ -187,6 +194,14 @@ def cdepends(key):
187194
for key in block_keys:
188195
if blocks[key].endswith(ifdef):
189196
blocks[key] = blocks[key][:-len(ifdef)]
197+
elif key == 'DEVICE_TABLE':
198+
devh = zlib.crc32(blocks[key][devo:].encode())
199+
assert(devh not in devp)
200+
devp[devh] = True
201+
202+
blocks[key] += '#else\n'
203+
blocks[key] += f'\tPFN_vkVoidFunction padding_{devh:x}[{devt}];\n'
204+
blocks[key] += '#endif /* ' + group + ' */\n'
190205
else:
191206
blocks[key] += '#endif /* ' + group + ' */\n'
192207

volk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# include <stdlib.h>
2222
#endif
2323

24+
#include <string.h>
25+
2426
#ifdef __cplusplus
2527
extern "C" {
2628
#endif
@@ -188,6 +190,7 @@ VkDevice volkGetLoadedDevice(void)
188190

189191
void volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device)
190192
{
193+
memset(table, 0, sizeof(*table));
191194
volkGenLoadDeviceTable(table, device, vkGetDeviceProcAddrStub);
192195
}
193196

0 commit comments

Comments
 (0)