Skip to content

Commit 1eb7ce6

Browse files
committed
Generate padding fields in VolkDeviceTable to preserve ABI
To avoid issues with ABI compatibility of volk built with different sets of defines, we now generate padding fields for each extension block with the same number of function pointers. This should make sure that the offset of every pointer for any given volk version remains stable, simplifying binary builds.
1 parent e3e9ea8 commit 1eb7ce6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

generate.py

+9
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ def cdepends(key):
157157
for key in block_keys:
158158
blocks[key] = ''
159159

160+
devi = 0
161+
160162
for (group, cmdnames) in command_groups.items():
161163
ifdef = '#if ' + group + '\n'
164+
devt = 0
162165

163166
for key in block_keys:
164167
blocks[key] += ifdef
@@ -176,6 +179,7 @@ def cdepends(key):
176179
blocks['LOAD_DEVICE'] += '\t' + name + ' = (PFN_' + name + ')load(context, "' + name + '");\n'
177180
blocks['DEVICE_TABLE'] += '\tPFN_' + name + ' ' + name + ';\n'
178181
blocks['LOAD_DEVICE_TABLE'] += '\ttable->' + name + ' = (PFN_' + name + ')load(context, "' + name + '");\n'
182+
devt += 1
179183
elif is_descendant_type(types, type, 'VkInstance'):
180184
blocks['LOAD_INSTANCE'] += '\t' + name + ' = (PFN_' + name + ')load(context, "' + name + '");\n'
181185
elif type != '':
@@ -187,6 +191,11 @@ def cdepends(key):
187191
for key in block_keys:
188192
if blocks[key].endswith(ifdef):
189193
blocks[key] = blocks[key][:-len(ifdef)]
194+
elif key == 'DEVICE_TABLE':
195+
devi += 1
196+
blocks[key] += '#else\n'
197+
blocks[key] += '\tPFN_vkVoidFunction padding' + str(devi) + '[' + str(devt) + '];\n'
198+
blocks[key] += '#endif /* ' + group + ' */\n'
190199
else:
191200
blocks[key] += '#endif /* ' + group + ' */\n'
192201

volk.c

+3
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)