1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
7 # Copyright (c) 2015 Google Inc.
9 # Permission is hereby granted, free of charge, to any person obtaining a
10 # copy of this software and/or associated documentation files (the
11 # "Materials"), to deal in the Materials without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Materials, and to
14 # permit persons to whom the Materials are furnished to do so, subject to
15 # the following conditions:
17 # The above copyright notice(s) and this permission notice shall be
18 # included in all copies or substantial portions of the Materials.
20 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
28 #-------------------------------------------------------------------------
34 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
36 from build.common import DEQP_DIR
37 from khr_util.format import indentLines, writeInlFile
39 VULKAN_DIR = os.path.join(os.path.dirname(__file__), "framework", "vulkan")
42 /* WARNING: This is auto-generated file. Do not modify, since changes will
43 * be lost! Modify the generating script instead.
47 PLATFORM_FUNCTIONS = [
49 "vkGetInstanceProcAddr",
50 "vkEnumerateInstanceExtensionProperties",
51 "vkEnumerateInstanceLayerProperties",
53 INSTANCE_FUNCTIONS = [
55 "vkEnumeratePhysicalDevices",
56 "vkGetPhysicalDeviceFeatures",
57 "vkGetPhysicalDeviceFormatProperties",
58 "vkGetPhysicalDeviceImageFormatProperties",
59 "vkGetPhysicalDeviceLimits",
60 "vkGetPhysicalDeviceProperties",
61 "vkGetPhysicalDeviceQueueFamilyProperties",
62 "vkGetPhysicalDeviceMemoryProperties",
63 "vkEnumerateDeviceExtensionProperties",
64 "vkEnumerateDeviceLayerProperties",
66 "vkGetDeviceProcAddr",
71 "VK_MAX_PHYSICAL_DEVICE_NAME_SIZE",
72 "VK_MAX_EXTENSION_NAME_SIZE",
74 "VK_MAX_MEMORY_TYPES",
75 "VK_MAX_MEMORY_HEAPS",
76 "VK_MAX_DESCRIPTION_SIZE",
77 "VK_ATTACHMENT_UNUSED",
84 def __init__ (self, type, name):
88 def getHandleType (self):
89 name = re.sub(r'([a-z])([A-Z])', r'\1_\2', self.name)
90 return "HANDLE_TYPE_" + name[3:].upper()
93 def __init__ (self, name, values):
98 def __init__ (self, name, values):
103 def __init__ (self, type, name, arraySize = None):
106 self.arraySize = arraySize
112 def __init__ (self, typeClass, name, members):
113 self.typeClass = typeClass
115 self.members = members
117 def getClassName (self):
118 names = {CompositeType.CLASS_STRUCT: 'struct', CompositeType.CLASS_UNION: 'union'}
119 return names[self.typeClass]
122 TYPE_PLATFORM = 0 # Not bound to anything
123 TYPE_INSTANCE = 1 # Bound to VkInstance
124 TYPE_DEVICE = 2 # Bound to VkDevice
126 def __init__ (self, name, returnType, arguments):
128 self.returnType = returnType
129 self.arguments = arguments
132 if self.name in PLATFORM_FUNCTIONS:
133 return Function.TYPE_PLATFORM
134 elif self.name in INSTANCE_FUNCTIONS:
135 return Function.TYPE_INSTANCE
137 return Function.TYPE_DEVICE
140 def __init__ (self, definitions, handles, enums, bitfields, compositeTypes, functions):
141 self.definitions = definitions
142 self.handles = handles
144 self.bitfields = bitfields
145 self.compositeTypes = compositeTypes
146 self.functions = functions
148 def readFile (filename):
149 with open(filename, 'rb') as f:
152 IDENT_PTRN = r'[a-zA-Z_][a-zA-Z0-9_]*'
153 TYPE_PTRN = r'[a-zA-Z_][a-zA-Z0-9_ \t*]*'
155 def endswith (s, postfix):
156 return len(s) >= len(postfix) and s[len(s)-len(postfix):] == postfix
158 def fixupEnumValues (values):
160 for name, value in values:
161 if endswith(name, "_BEGIN_RANGE") or endswith(name, "_END_RANGE"):
163 fixed.append((name, value))
166 def fixupType (type):
168 ("uint8_t", "deUint8"),
169 ("uint16_t", "deUint16"),
170 ("uint32_t", "deUint32"),
171 ("uint64_t", "deUint64"),
172 ("int8_t", "deInt8"),
173 ("int16_t", "deInt16"),
174 ("int32_t", "deInt32"),
175 ("int64_t", "deInt64"),
176 ("bool32_t", "deUint32"),
177 ("size_t", "deUintptr"),
180 for src, dst in replacements:
181 type = type.replace(src, dst)
185 def fixupFunction (function):
186 fixedArgs = [Variable(fixupType(a.type), a.name, a.arraySize) for a in function.arguments]
187 fixedReturnType = fixupType(function.returnType)
189 return Function(function.name, fixedReturnType, fixedArgs)
191 def getInterfaceName (function):
192 assert function.name[:2] == "vk"
193 return function.name[2].lower() + function.name[3:]
195 def getFunctionTypeName (function):
196 assert function.name[:2] == "vk"
197 return function.name[2:] + "Func"
199 def getBitEnumNameForBitfield (bitfieldName):
200 if bitfieldName[-3:] == "KHR":
202 bitfieldName = bitfieldName[:-3]
206 assert bitfieldName[-1] == "s"
207 return bitfieldName[:-1] + "Bits" + postfix
209 def getBitfieldNameForBitEnum (bitEnumName):
210 if bitEnumName[-3:] == "KHR":
212 bitEnumName = bitEnumName[:-3]
216 assert bitEnumName[-4:] == "Bits"
217 return bitEnumName[:-4] + "s" + postfix
219 def parsePreprocDefinedValue (src, name):
220 definition = re.search(r'#\s*define\s+' + name + r'\s+([^\n]+)\n', src)
221 if definition is None:
222 raise Exception("No such definition: %s" % name)
223 value = definition.group(1).strip()
225 if value == "UINT32_MAX":
230 def parseEnum (name, src):
231 keyValuePtrn = '(' + IDENT_PTRN + r')\s*=\s*([^\s,}]+)\s*[,}]'
232 matches = re.findall(keyValuePtrn, src)
234 return Enum(name, fixupEnumValues(matches))
236 # \note Parses raw enums, some are mapped to bitfields later
237 def parseEnums (src):
238 matches = re.findall(r'typedef enum(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
241 for enumname, contents, typename in matches:
242 enums.append(parseEnum(typename, contents))
246 def parseCompositeType (type, name, src):
247 # \todo [pyry] Array support is currently a hack (size coupled with name)
248 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r'(\[[^\]]+\])*)\s*;'
249 matches = re.findall(typeNamePtrn, src)
250 members = [Variable(fixupType(t.strip()), n.strip()) for t, n, a in matches]
252 return CompositeType(type, name, members)
254 def parseCompositeTypes (src):
255 typeMap = { 'struct': CompositeType.CLASS_STRUCT, 'union': CompositeType.CLASS_UNION }
256 matches = re.findall(r'typedef (struct|union)(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
259 for type, structname, contents, typename in matches:
260 if typename[-3:] == "KHR":
261 continue # \todo [2016-01-05 pyry] Figure out how to handle platform-specific types
263 types.append(parseCompositeType(typeMap[type], typename, contents))
267 def parseHandles (src):
268 matches = re.findall(r'VK_DEFINE(_NON_DISPATCHABLE|)_HANDLE\((' + IDENT_PTRN + r')\)[ \t]*[\n\r]', src)
270 typeMap = {'': Handle.TYPE_DISP, '_NON_DISPATCHABLE': Handle.TYPE_NONDISP}
272 for type, name in matches:
273 handle = Handle(typeMap[type], name)
274 handles.append(handle)
278 def parseArgList (src):
279 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r')(\[[^\]]+\])?'
282 for rawArg in src.split(','):
283 m = re.search(typeNamePtrn, rawArg)
284 args.append(Variable(m.group(1).strip(), m.group(2).strip(), m.group(3)))
288 def parseFunctions (src):
289 ptrn = r'VKAPI_ATTR\s+(' + TYPE_PTRN + ')VKAPI_CALL\s+(' + IDENT_PTRN + r')\s*\(([^)]*)\)\s*;'
290 matches = re.findall(ptrn, src)
293 for returnType, name, argList in matches:
294 if name[-3:] == "KHR":
295 continue # \todo [2015-11-16 pyry] Figure out how to handle platform-specific extension functions
297 functions.append(Function(name.strip(), returnType.strip(), parseArgList(argList)))
299 return [fixupFunction(f) for f in functions]
301 def parseBitfieldNames (src):
302 ptrn = r'typedef\s+VkFlags\s(' + IDENT_PTRN + r')\s*;'
303 matches = re.findall(ptrn, src)
308 definitions = [(name, parsePreprocDefinedValue(src, name)) for name in DEFINITIONS]
309 rawEnums = parseEnums(src)
310 bitfieldNames = parseBitfieldNames(src)
313 bitfieldEnums = set([getBitEnumNameForBitfield(n) for n in bitfieldNames])
315 for enum in rawEnums:
316 if enum.name in bitfieldEnums:
317 bitfields.append(Bitfield(getBitfieldNameForBitEnum(enum.name), enum.values))
321 for bitfieldName in bitfieldNames:
322 if not bitfieldName in [bitfield.name for bitfield in bitfields]:
324 bitfields.append(Bitfield(bitfieldName, []))
327 definitions = definitions,
328 handles = parseHandles(src),
330 bitfields = bitfields,
331 compositeTypes = parseCompositeTypes(src),
332 functions = parseFunctions(src))
334 def writeHandleType (api, filename):
336 yield "enum HandleType"
338 yield "\t%s = 0," % api.handles[0].getHandleType()
339 for handle in api.handles[1:]:
340 yield "\t%s," % handle.getHandleType()
341 yield "\tHANDLE_TYPE_LAST"
345 writeInlFile(filename, INL_HEADER, gen())
347 def getEnumValuePrefix (enum):
348 prefix = enum.name[0]
349 for i in range(1, len(enum.name)):
350 if enum.name[i].isupper():
352 prefix += enum.name[i].upper()
355 def parseInt (value):
356 if value[:2] == "0x":
357 return int(value, 16)
359 return int(value, 10)
361 def areEnumValuesLinear (enum):
363 for name, value in enum.values:
364 if parseInt(value) != curIndex:
369 def genEnumSrc (enum):
370 yield "enum %s" % enum.name
373 for line in indentLines(["\t%s\t= %s," % v for v in enum.values]):
376 if areEnumValuesLinear(enum):
378 yield "\t%s_LAST" % getEnumValuePrefix(enum)
382 def genBitfieldSrc (bitfield):
383 if len(bitfield.values) > 0:
384 yield "enum %s" % getBitEnumNameForBitfield(bitfield.name)
386 for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]):
390 yield "typedef deUint32 %s;" % bitfield.name
392 def genCompositeTypeSrc (type):
393 yield "%s %s" % (type.getClassName(), type.name)
395 for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]):
399 def genHandlesSrc (handles):
400 def genLines (handles):
401 for handle in handles:
402 if handle.type == Handle.TYPE_DISP:
403 yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
404 elif handle.type == Handle.TYPE_NONDISP:
405 yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
407 for line in indentLines(genLines(handles)):
410 def writeBasicTypes (api, filename):
412 for line in indentLines(["enum { %s\t= %s\t};" % define for define in api.definitions]):
415 for line in genHandlesSrc(api.handles):
418 for enum in api.enums:
419 for line in genEnumSrc(enum):
422 for bitfield in api.bitfields:
423 for line in genBitfieldSrc(bitfield):
427 writeInlFile(filename, INL_HEADER, gen())
429 def writeCompositeTypes (api, filename):
431 for type in api.compositeTypes:
432 for line in genCompositeTypeSrc(type):
436 writeInlFile(filename, INL_HEADER, gen())
438 def argListToStr (args):
439 return ", ".join("%s %s%s" % (v.type, v.name, v.arraySize if v.arraySize != None else "") for v in args)
441 def writeInterfaceDecl (api, filename, functionTypes, concrete):
443 postfix = "" if concrete else " = 0"
444 for function in api.functions:
445 if function.getType() in functionTypes:
446 yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix)
448 writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
450 def writeFunctionPtrTypes (api, filename):
452 for function in api.functions:
453 yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments))
455 writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
457 def writeFunctionPointers (api, filename, functionTypes):
458 writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
460 def writeInitFunctionPointers (api, filename, functionTypes):
461 def makeInitFunctionPointers ():
462 for function in api.functions:
463 if function.getType() in functionTypes:
464 yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name)
466 writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
468 def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className):
469 def makeFuncPtrInterfaceImpl ():
470 for function in api.functions:
471 if function.getType() in functionTypes:
473 yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments))
475 yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments))
478 writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
480 def writeStrUtilProto (api, filename):
481 def makeStrUtilProto ():
482 for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]):
485 for line in indentLines(["inline tcu::Format::Enum<%s>\tget%sStr\t(%s value)\t{ return tcu::Format::Enum<%s>(get%sName, value);\t}" % (e.name, e.name[2:], e.name, e.name, e.name[2:]) for e in api.enums]):
488 for line in indentLines(["inline std::ostream&\toperator<<\t(std::ostream& s, %s value)\t{ return s << get%sStr(value);\t}" % (e.name, e.name[2:]) for e in api.enums]):
491 for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]):
494 for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]):
497 writeInlFile(filename, INL_HEADER, makeStrUtilProto())
499 def writeStrUtilImpl (api, filename):
500 def makeStrUtilImpl ():
501 for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]):
504 for enum in api.enums:
506 yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name)
508 yield "\tswitch (value)"
510 for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]):
515 for bitfield in api.bitfields:
517 yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name)
520 if len(bitfield.values) > 0:
521 yield "\tstatic const tcu::Format::BitDesc s_desc[] ="
523 for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]):
526 yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));"
528 yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);"
532 bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
534 for type in api.compositeTypes:
536 yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name
538 yield "\ts << \"%s = {\\n\";" % type.name
539 for member in type.members:
540 memberName = member.name
543 if member.type in bitfieldTypeNames:
544 valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name)
545 elif member.type == "const char*" or member.type == "char*":
546 valFmt = "getCharPtrStr(value.%s)" % member.name
547 elif '[' in member.name:
548 baseName = member.name[:member.name.find('[')]
549 if baseName in ["extensionName", "deviceName", "layerName", "description"]:
550 valFmt = "(const char*)value.%s" % baseName
551 elif member.type == 'char' or member.type == 'deUint8':
552 newLine = "'\\n' << "
553 valFmt = "tcu::formatArray(tcu::Format::HexIterator<%s>(DE_ARRAY_BEGIN(value.%s)), tcu::Format::HexIterator<%s>(DE_ARRAY_END(value.%s)))" % (member.type, baseName, member.type, baseName)
555 newLine = "'\\n' << "
556 valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), DE_ARRAY_END(value.%s))" % (baseName, baseName)
557 memberName = baseName
559 valFmt = "value.%s" % member.name
560 yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';"
566 writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
568 class ConstructorFunction:
569 def __init__ (self, type, name, objectType, iface, arguments):
572 self.objectType = objectType
574 self.arguments = arguments
576 def getConstructorFunctions (api):
578 for function in api.functions:
579 if (function.name[:8] == "vkCreate" or function.name == "vkAllocateMemory") and not "count" in [a.name for a in function.arguments]:
580 # \todo [pyry] Rather hacky
582 if function.getType() == Function.TYPE_PLATFORM:
583 iface = Variable("const PlatformInterface&", "vk")
584 elif function.getType() == Function.TYPE_INSTANCE:
585 iface = Variable("const InstanceInterface&", "vk")
587 iface = Variable("const DeviceInterface&", "vk")
589 assert function.arguments[-2].type == "const VkAllocationCallbacks*"
591 objectType = function.arguments[-1].type.replace("*", "").strip()
592 arguments = function.arguments[:-1]
593 funcs.append(ConstructorFunction(function.getType(), getInterfaceName(function), objectType, iface, arguments))
596 def writeRefUtilProto (api, filename):
597 functions = getConstructorFunctions(api)
599 def makeRefUtilProto ():
601 for line in indentLines(["Move<%s>\t%s\t(%s = DE_NULL);" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments)) for function in functions]):
604 writeInlFile(filename, INL_HEADER, makeRefUtilProto())
606 def writeRefUtilImpl (api, filename):
607 functions = getConstructorFunctions(api)
609 def makeRefUtilImpl ():
610 yield "namespace refdetails"
614 for function in api.functions:
615 if function.getType() == Function.TYPE_DEVICE \
616 and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \
617 and not function.name == "vkDestroyDevice":
618 objectType = function.arguments[-2].type
620 yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType)
622 yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function))
626 yield "} // refdetails"
629 for function in functions:
630 dtorObj = "device" if function.type == Function.TYPE_DEVICE else "object"
632 yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments))
634 yield "\t%s object = 0;" % function.objectType
635 yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"]))
636 yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name]))
640 writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
642 def writeNullDriverImpl (api, filename):
643 def genNullDriverImpl ():
645 "vkCreateGraphicsPipelines",
646 "vkCreateComputePipelines",
647 "vkGetInstanceProcAddr",
648 "vkGetDeviceProcAddr",
649 "vkEnumeratePhysicalDevices",
650 "vkGetPhysicalDeviceProperties",
651 "vkGetPhysicalDeviceQueueFamilyProperties",
652 "vkGetPhysicalDeviceMemoryProperties",
653 "vkGetPhysicalDeviceFormatProperties",
654 "vkGetBufferMemoryRequirements",
655 "vkGetImageMemoryRequirements",
657 "vkAllocateDescriptorSets",
658 "vkFreeDescriptorSets",
659 "vkResetDescriptorPool",
660 "vkAllocateCommandBuffers",
661 "vkFreeCommandBuffers"
663 specialFuncs = [f for f in api.functions if f.name in specialFuncNames]
664 createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs]
665 destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs]
666 dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs]
668 def getHandle (name):
669 for handle in api.handles:
670 if handle.name == name:
672 raise Exception("No such handle: %s" % name)
674 for function in createFuncs:
675 objectType = function.arguments[-1].type.replace("*", "").strip()
676 argsStr = ", ".join([a.name for a in function.arguments[:-1]])
678 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
680 yield "\tDE_UNREF(%s);" % function.arguments[-2].name
682 if getHandle(objectType).type == Handle.TYPE_NONDISP:
683 yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
685 yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
690 for function in destroyFuncs:
691 objectArg = function.arguments[-2]
693 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
695 for arg in function.arguments[:-2]:
696 yield "\tDE_UNREF(%s);" % arg.name
698 if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
699 yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
701 yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
706 for function in dummyFuncs:
707 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
709 for arg in function.arguments:
710 yield "\tDE_UNREF(%s);" % arg.name
711 if function.returnType != "void":
712 yield "\treturn VK_SUCCESS;"
716 def genFuncEntryTable (type, name):
717 funcs = [f for f in api.functions if f.getType() == type]
719 yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name
721 for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]):
727 for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"):
730 for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"):
733 for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"):
737 writeInlFile(filename, INL_HEADER, genNullDriverImpl())
739 def writeTypeUtil (api, filename):
740 # Structs filled by API queries are not often used in test code
741 QUERY_RESULT_TYPES = set([
742 "VkPhysicalDeviceFeatures",
743 "VkPhysicalDeviceLimits",
744 "VkFormatProperties",
745 "VkImageFormatProperties",
746 "VkPhysicalDeviceSparseProperties",
747 "VkQueueFamilyProperties",
751 COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
753 def isSimpleStruct (type):
754 def hasArrayMember (type):
755 for member in type.members:
756 if "[" in member.name:
760 def hasCompositeMember (type):
761 for member in type.members:
762 if member.type in COMPOSITE_TYPES:
766 return type.typeClass == CompositeType.CLASS_STRUCT and \
767 type.members[0].type != "VkStructureType" and \
768 not type.name in QUERY_RESULT_TYPES and \
769 not hasArrayMember(type) and \
770 not hasCompositeMember(type)
773 for type in api.compositeTypes:
774 if not isSimpleStruct(type):
778 yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
780 yield "\t%s res;" % type.name
781 for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
783 yield "\treturn res;"
786 writeInlFile(filename, INL_HEADER, gen())
788 if __name__ == "__main__":
789 src = readFile(sys.argv[1])
791 platformFuncs = set([Function.TYPE_PLATFORM])
792 instanceFuncs = set([Function.TYPE_INSTANCE])
793 deviceFuncs = set([Function.TYPE_DEVICE])
795 writeHandleType (api, os.path.join(VULKAN_DIR, "vkHandleType.inl"))
796 writeBasicTypes (api, os.path.join(VULKAN_DIR, "vkBasicTypes.inl"))
797 writeCompositeTypes (api, os.path.join(VULKAN_DIR, "vkStructTypes.inl"))
798 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualPlatformInterface.inl"), functionTypes = platformFuncs, concrete = False)
799 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = False)
800 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = False)
801 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcretePlatformInterface.inl"), functionTypes = platformFuncs, concrete = True)
802 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = True)
803 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = True)
804 writeFunctionPtrTypes (api, os.path.join(VULKAN_DIR, "vkFunctionPointerTypes.inl"))
805 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
806 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
807 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
808 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
809 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
810 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
811 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkPlatformDriverImpl.inl"), functionTypes = platformFuncs, className = "PlatformDriver")
812 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkInstanceDriverImpl.inl"), functionTypes = instanceFuncs, className = "InstanceDriver")
813 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkDeviceDriverImpl.inl"), functionTypes = deviceFuncs, className = "DeviceDriver")
814 writeStrUtilProto (api, os.path.join(VULKAN_DIR, "vkStrUtil.inl"))
815 writeStrUtilImpl (api, os.path.join(VULKAN_DIR, "vkStrUtilImpl.inl"))
816 writeRefUtilProto (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
817 writeRefUtilImpl (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
818 writeNullDriverImpl (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
819 writeTypeUtil (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))