1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
#!/usr/bin/env python
#
# Copyright (c) 2013-2016 The Khronos Group Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, time, pdb, string, cProfile
from reg import *
from generator import write, CGeneratorOptions, COutputGenerator, DocGeneratorOptions, DocOutputGenerator, PyOutputGenerator, ValidityOutputGenerator, HostSynchronizationOutputGenerator, ThreadGeneratorOptions, ThreadOutputGenerator
from generator import ParamCheckerGeneratorOptions, ParamCheckerOutputGenerator
# debug - start header generation in debugger
# dump - dump registry after loading
# profile - enable Python profiling
# protect - whether to use #ifndef protections
# registry <filename> - use specified XML registry instead of gl.xml
# target - string name of target header, or all targets if None
# timeit - time length of registry loading & header generation
# validate - validate return & parameter group tags against <group>
debug = False
dump = False
profile = False
protect = True
target = None
timeit = False
validate= False
# Default input / log files
errFilename = None
diagFilename = 'diag.txt'
regFilename = 'vk.xml'
outDir = '.'
if __name__ == '__main__':
i = 1
while (i < len(sys.argv)):
arg = sys.argv[i]
i = i + 1
if (arg == '-debug'):
write('Enabling debug (-debug)', file=sys.stderr)
debug = True
elif (arg == '-dump'):
write('Enabling dump (-dump)', file=sys.stderr)
dump = True
elif (arg == '-noprotect'):
write('Disabling inclusion protection in output headers', file=sys.stderr)
protect = False
elif (arg == '-profile'):
write('Enabling profiling (-profile)', file=sys.stderr)
profile = True
elif (arg == '-registry'):
regFilename = sys.argv[i]
i = i+1
write('Using registry ', regFilename, file=sys.stderr)
elif (arg == '-time'):
write('Enabling timing (-time)', file=sys.stderr)
timeit = True
elif (arg == '-validate'):
write('Enabling group validation (-validate)', file=sys.stderr)
validate = True
elif (arg == '-outdir'):
outDir = sys.argv[i]
i = i+1
write('Using output directory ', outDir, file=sys.stderr)
elif (arg[0:1] == '-'):
write('Unrecognized argument:', arg, file=sys.stderr)
exit(1)
else:
target = arg
write('Using target', target, file=sys.stderr)
# Simple timer functions
startTime = None
def startTimer():
global startTime
startTime = time.clock()
def endTimer(msg):
global startTime
endTime = time.clock()
if (timeit):
write(msg, endTime - startTime)
startTime = None
# Load & parse registry
reg = Registry()
startTimer()
tree = etree.parse(regFilename)
endTimer('Time to make ElementTree =')
startTimer()
reg.loadElementTree(tree)
endTimer('Time to parse ElementTree =')
if (validate):
reg.validateGroups()
if (dump):
write('***************************************')
write('Performing Registry dump to regdump.txt')
write('***************************************')
reg.dumpReg(filehandle = open('regdump.txt','w'))
# Turn a list of strings into a regexp string matching exactly those strings
def makeREstring(list):
return '^(' + '|'.join(list) + ')$'
# Descriptive names for various regexp patterns used to select
# versions and extensions
allVersions = allExtensions = '.*'
noVersions = noExtensions = None
# Copyright text prefixing all headers (list of strings).
prefixStrings = [
'/*',
'** Copyright (c) 2015-2016 The Khronos Group Inc.',
'**',
'** Licensed under the Apache License, Version 2.0 (the "License");',
'** you may not use this file except in compliance with the License.',
'** You may obtain a copy of the License at',
'**',
'** http://www.apache.org/licenses/LICENSE-2.0',
'**',
'** Unless required by applicable law or agreed to in writing, software',
'** distributed under the License is distributed on an "AS IS" BASIS,',
'** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
'** See the License for the specific language governing permissions and',
'** limitations under the License.',
'*/',
''
]
# Text specific to Vulkan headers
vkPrefixStrings = [
'/*',
'** This header is generated from the Khronos Vulkan XML API Registry.',
'**',
'*/',
''
]
# Defaults for generating re-inclusion protection wrappers (or not)
protectFile = protect
protectFeature = protect
protectProto = protect
buildList = [
# Vulkan 1.0 - header for core API + extensions.
# To generate just the core API,
# change to 'defaultExtensions = None' below.
[ COutputGenerator,
CGeneratorOptions(
filename = 'include/vulkan/vulkan.h',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = 'vulkan',
addExtensions = None,
removeExtensions = None,
prefixText = prefixStrings + vkPrefixStrings,
genFuncPointers = True,
protectFile = protectFile,
protectFeature = False,
protectProto = '#ifndef',
protectProtoStr = 'VK_NO_PROTOTYPES',
apicall = 'VKAPI_ATTR ',
apientry = 'VKAPI_CALL ',
apientryp = 'VKAPI_PTR *',
alignFuncParam = 48)
],
# Vulkan 1.0 draft - API include files for spec and ref pages
# Overwrites include subdirectories in spec source tree
# The generated include files do not include the calling convention
# macros (apientry etc.), unlike the header files.
# Because the 1.0 core branch includes ref pages for extensions,
# all the extension interfaces need to be generated, even though
# none are used by the core spec itself.
[ DocOutputGenerator,
DocGeneratorOptions(
filename = 'vulkan-docs',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = None,
addExtensions =
makeREstring([
'VK_KHR_sampler_mirror_clamp_to_edge',
]),
removeExtensions =
makeREstring([
]),
prefixText = prefixStrings + vkPrefixStrings,
apicall = '',
apientry = '',
apientryp = '*',
genDirectory = '../../doc/specs/vulkan',
alignFuncParam = 48,
expandEnumerants = False)
],
# Vulkan 1.0 draft - API names to validate man/api spec includes & links
[ PyOutputGenerator,
DocGeneratorOptions(
filename = '../../doc/specs/vulkan/vkapi.py',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = None,
addExtensions =
makeREstring([
'VK_KHR_sampler_mirror_clamp_to_edge',
]),
removeExtensions =
makeREstring([
]))
],
# Vulkan 1.0 draft - core API validity files for spec
# Overwrites validity subdirectories in spec source tree
[ ValidityOutputGenerator,
DocGeneratorOptions(
filename = 'validity',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = None,
addExtensions =
makeREstring([
'VK_KHR_sampler_mirror_clamp_to_edge',
]),
removeExtensions =
makeREstring([
]),
genDirectory = '../../doc/specs/vulkan')
],
# Vulkan 1.0 draft - core API host sync table files for spec
# Overwrites subdirectory in spec source tree
[ HostSynchronizationOutputGenerator,
DocGeneratorOptions(
filename = 'hostsynctable',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = None,
addExtensions =
makeREstring([
'VK_KHR_sampler_mirror_clamp_to_edge',
]),
removeExtensions =
makeREstring([
]),
genDirectory = '../../doc/specs/vulkan')
],
# Vulkan 1.0 draft - thread checking layer
[ ThreadOutputGenerator,
ThreadGeneratorOptions(
filename = 'thread_check.h',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = 'vulkan',
addExtensions = None,
removeExtensions = None,
prefixText = prefixStrings + vkPrefixStrings,
genFuncPointers = True,
protectFile = protectFile,
protectFeature = False,
protectProto = True,
protectProtoStr = 'VK_PROTOTYPES',
apicall = 'VKAPI_ATTR ',
apientry = 'VKAPI_CALL ',
apientryp = 'VKAPI_PTR *',
alignFuncParam = 48,
genDirectory = outDir)
],
[ ParamCheckerOutputGenerator,
ParamCheckerGeneratorOptions(
filename = 'parameter_validation.h',
apiname = 'vulkan',
profile = None,
versions = allVersions,
emitversions = allVersions,
defaultExtensions = 'vulkan',
addExtensions = None,
removeExtensions = None,
prefixText = prefixStrings + vkPrefixStrings,
genFuncPointers = True,
protectFile = protectFile,
protectFeature = False,
protectProto = None,
protectProtoStr = 'VK_NO_PROTOTYPES',
apicall = 'VKAPI_ATTR ',
apientry = 'VKAPI_CALL ',
apientryp = 'VKAPI_PTR *',
alignFuncParam = 48,
genDirectory = outDir)
],
None
]
# create error/warning & diagnostic files
if (errFilename):
errWarn = open(errFilename,'w')
else:
errWarn = sys.stderr
diag = open(diagFilename, 'w')
# check that output directory exists
if (not os.path.isdir(outDir)):
write('Output directory does not exist: ', outDir)
raise
def genHeaders():
# Loop over targets, building each
generated = 0
for item in buildList:
if (item == None):
break
createGenerator = item[0]
genOpts = item[1]
if (target and target != genOpts.filename):
# write('*** Skipping', genOpts.filename)
continue
write('*** Building', genOpts.filename)
generated = generated + 1
startTimer()
gen = createGenerator(errFile=errWarn,
warnFile=errWarn,
diagFile=diag)
reg.setGenerator(gen)
reg.apiGen(genOpts)
write('** Generated', genOpts.filename)
endTimer('Time to generate ' + genOpts.filename + ' =')
if (target and generated == 0):
write('Failed to generate target:', target)
if (debug):
pdb.run('genHeaders()')
elif (profile):
import cProfile, pstats
cProfile.run('genHeaders()', 'profile.txt')
p = pstats.Stats('profile.txt')
p.strip_dirs().sort_stats('time').print_stats(50)
else:
genHeaders()
|