1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
7 # Copyright (c) 2015 Google Inc.
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
27 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
29 from build.common import DEQP_DIR
30 from khr_util.format import indentLines, writeInlFile
32 VULKAN_DIR = os.path.join(os.path.dirname(__file__), "framework", "vulkan")
35 /* WARNING: This is auto-generated file. Do not modify, since changes will
36 * be lost! Modify the generating script instead.
40 PLATFORM_FUNCTIONS = [
42 "vkGetInstanceProcAddr",
43 "vkEnumerateInstanceExtensionProperties",
44 "vkEnumerateInstanceLayerProperties",
46 INSTANCE_FUNCTIONS = [
48 "vkEnumeratePhysicalDevices",
49 "vkGetPhysicalDeviceFeatures",
50 "vkGetPhysicalDeviceFormatProperties",
51 "vkGetPhysicalDeviceImageFormatProperties",
52 "vkGetPhysicalDeviceLimits",
53 "vkGetPhysicalDeviceProperties",
54 "vkGetPhysicalDeviceQueueFamilyProperties",
55 "vkGetPhysicalDeviceMemoryProperties",
56 "vkEnumerateDeviceExtensionProperties",
57 "vkEnumerateDeviceLayerProperties",
59 "vkGetDeviceProcAddr",
64 "VK_MAX_PHYSICAL_DEVICE_NAME_SIZE",
65 "VK_MAX_EXTENSION_NAME_SIZE",
67 "VK_MAX_MEMORY_TYPES",
68 "VK_MAX_MEMORY_HEAPS",
69 "VK_MAX_DESCRIPTION_SIZE",
70 "VK_ATTACHMENT_UNUSED",
77 def __init__ (self, type, name):
81 def getHandleType (self):
82 name = re.sub(r'([a-z])([A-Z])', r'\1_\2', self.name)
83 return "HANDLE_TYPE_" + name[3:].upper()
86 def __init__ (self, name, values):
91 def __init__ (self, name, values):
96 def __init__ (self, type, name, arraySize = None):
99 self.arraySize = arraySize
105 def __init__ (self, typeClass, name, members):
106 self.typeClass = typeClass
108 self.members = members
110 def getClassName (self):
111 names = {CompositeType.CLASS_STRUCT: 'struct', CompositeType.CLASS_UNION: 'union'}
112 return names[self.typeClass]
115 TYPE_PLATFORM = 0 # Not bound to anything
116 TYPE_INSTANCE = 1 # Bound to VkInstance
117 TYPE_DEVICE = 2 # Bound to VkDevice
119 def __init__ (self, name, returnType, arguments):
121 self.returnType = returnType
122 self.arguments = arguments
125 if self.name in PLATFORM_FUNCTIONS:
126 return Function.TYPE_PLATFORM
127 elif self.name in INSTANCE_FUNCTIONS:
128 return Function.TYPE_INSTANCE
130 return Function.TYPE_DEVICE
133 def __init__ (self, definitions, handles, enums, bitfields, compositeTypes, functions):
134 self.definitions = definitions
135 self.handles = handles
137 self.bitfields = bitfields
138 self.compositeTypes = compositeTypes
139 self.functions = functions
141 def readFile (filename):
142 with open(filename, 'rb') as f:
145 IDENT_PTRN = r'[a-zA-Z_][a-zA-Z0-9_]*'
146 TYPE_PTRN = r'[a-zA-Z_][a-zA-Z0-9_ \t*]*'
148 def endswith (s, postfix):
149 return len(s) >= len(postfix) and s[len(s)-len(postfix):] == postfix
151 def fixupEnumValues (values):
153 for name, value in values:
154 if endswith(name, "_BEGIN_RANGE") or endswith(name, "_END_RANGE"):
156 fixed.append((name, value))
159 def fixupType (type):
161 ("uint8_t", "deUint8"),
162 ("uint16_t", "deUint16"),
163 ("uint32_t", "deUint32"),
164 ("uint64_t", "deUint64"),
165 ("int8_t", "deInt8"),
166 ("int16_t", "deInt16"),
167 ("int32_t", "deInt32"),
168 ("int64_t", "deInt64"),
169 ("bool32_t", "deUint32"),
170 ("size_t", "deUintptr"),
173 for src, dst in replacements:
174 type = type.replace(src, dst)
178 def fixupFunction (function):
179 fixedArgs = [Variable(fixupType(a.type), a.name, a.arraySize) for a in function.arguments]
180 fixedReturnType = fixupType(function.returnType)
182 return Function(function.name, fixedReturnType, fixedArgs)
184 def getInterfaceName (function):
185 assert function.name[:2] == "vk"
186 return function.name[2].lower() + function.name[3:]
188 def getFunctionTypeName (function):
189 assert function.name[:2] == "vk"
190 return function.name[2:] + "Func"
192 def getBitEnumNameForBitfield (bitfieldName):
193 if bitfieldName[-3:] == "KHR":
195 bitfieldName = bitfieldName[:-3]
199 assert bitfieldName[-1] == "s"
200 return bitfieldName[:-1] + "Bits" + postfix
202 def getBitfieldNameForBitEnum (bitEnumName):
203 if bitEnumName[-3:] == "KHR":
205 bitEnumName = bitEnumName[:-3]
209 assert bitEnumName[-4:] == "Bits"
210 return bitEnumName[:-4] + "s" + postfix
212 def parsePreprocDefinedValue (src, name):
213 definition = re.search(r'#\s*define\s+' + name + r'\s+([^\n]+)\n', src)
214 if definition is None:
215 raise Exception("No such definition: %s" % name)
216 value = definition.group(1).strip()
218 if value == "UINT32_MAX":
223 def parseEnum (name, src):
224 keyValuePtrn = '(' + IDENT_PTRN + r')\s*=\s*([^\s,}]+)\s*[,}]'
225 matches = re.findall(keyValuePtrn, src)
227 return Enum(name, fixupEnumValues(matches))
229 # \note Parses raw enums, some are mapped to bitfields later
230 def parseEnums (src):
231 matches = re.findall(r'typedef enum(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
234 for enumname, contents, typename in matches:
235 enums.append(parseEnum(typename, contents))
239 def parseCompositeType (type, name, src):
240 # \todo [pyry] Array support is currently a hack (size coupled with name)
241 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r'(\[[^\]]+\])*)\s*;'
242 matches = re.findall(typeNamePtrn, src)
243 members = [Variable(fixupType(t.strip()), n.strip()) for t, n, a in matches]
245 return CompositeType(type, name, members)
247 def parseCompositeTypes (src):
248 typeMap = { 'struct': CompositeType.CLASS_STRUCT, 'union': CompositeType.CLASS_UNION }
249 matches = re.findall(r'typedef (struct|union)(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
252 for type, structname, contents, typename in matches:
253 if typename[-3:] == "KHR":
254 continue # \todo [2016-01-05 pyry] Figure out how to handle platform-specific types
256 types.append(parseCompositeType(typeMap[type], typename, contents))
260 def parseHandles (src):
261 matches = re.findall(r'VK_DEFINE(_NON_DISPATCHABLE|)_HANDLE\((' + IDENT_PTRN + r')\)[ \t]*[\n\r]', src)
263 typeMap = {'': Handle.TYPE_DISP, '_NON_DISPATCHABLE': Handle.TYPE_NONDISP}
265 for type, name in matches:
266 handle = Handle(typeMap[type], name)
267 handles.append(handle)
271 def parseArgList (src):
272 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r')(\[[^\]]+\])?'
275 for rawArg in src.split(','):
276 m = re.search(typeNamePtrn, rawArg)
277 args.append(Variable(m.group(1).strip(), m.group(2).strip(), m.group(3)))
281 def parseFunctions (src):
282 ptrn = r'VKAPI_ATTR\s+(' + TYPE_PTRN + ')VKAPI_CALL\s+(' + IDENT_PTRN + r')\s*\(([^)]*)\)\s*;'
283 matches = re.findall(ptrn, src)
286 for returnType, name, argList in matches:
287 if name[-3:] == "KHR":
288 continue # \todo [2015-11-16 pyry] Figure out how to handle platform-specific extension functions
290 functions.append(Function(name.strip(), returnType.strip(), parseArgList(argList)))
292 return [fixupFunction(f) for f in functions]
294 def parseBitfieldNames (src):
295 ptrn = r'typedef\s+VkFlags\s(' + IDENT_PTRN + r')\s*;'
296 matches = re.findall(ptrn, src)
301 definitions = [(name, parsePreprocDefinedValue(src, name)) for name in DEFINITIONS]
302 rawEnums = parseEnums(src)
303 bitfieldNames = parseBitfieldNames(src)
306 bitfieldEnums = set([getBitEnumNameForBitfield(n) for n in bitfieldNames])
308 for enum in rawEnums:
309 if enum.name in bitfieldEnums:
310 bitfields.append(Bitfield(getBitfieldNameForBitEnum(enum.name), enum.values))
314 for bitfieldName in bitfieldNames:
315 if not bitfieldName in [bitfield.name for bitfield in bitfields]:
317 bitfields.append(Bitfield(bitfieldName, []))
320 definitions = definitions,
321 handles = parseHandles(src),
323 bitfields = bitfields,
324 compositeTypes = parseCompositeTypes(src),
325 functions = parseFunctions(src))
327 def writeHandleType (api, filename):
329 yield "enum HandleType"
331 yield "\t%s = 0," % api.handles[0].getHandleType()
332 for handle in api.handles[1:]:
333 yield "\t%s," % handle.getHandleType()
334 yield "\tHANDLE_TYPE_LAST"
338 writeInlFile(filename, INL_HEADER, gen())
340 def getEnumValuePrefix (enum):
341 prefix = enum.name[0]
342 for i in range(1, len(enum.name)):
343 if enum.name[i].isupper():
345 prefix += enum.name[i].upper()
348 def parseInt (value):
349 if value[:2] == "0x":
350 return int(value, 16)
352 return int(value, 10)
354 def areEnumValuesLinear (enum):
356 for name, value in enum.values:
357 if parseInt(value) != curIndex:
362 def genEnumSrc (enum):
363 yield "enum %s" % enum.name
366 for line in indentLines(["\t%s\t= %s," % v for v in enum.values]):
369 if areEnumValuesLinear(enum):
371 yield "\t%s_LAST" % getEnumValuePrefix(enum)
375 def genBitfieldSrc (bitfield):
376 if len(bitfield.values) > 0:
377 yield "enum %s" % getBitEnumNameForBitfield(bitfield.name)
379 for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]):
383 yield "typedef deUint32 %s;" % bitfield.name
385 def genCompositeTypeSrc (type):
386 yield "%s %s" % (type.getClassName(), type.name)
388 for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]):
392 def genHandlesSrc (handles):
393 def genLines (handles):
394 for handle in handles:
395 if handle.type == Handle.TYPE_DISP:
396 yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
397 elif handle.type == Handle.TYPE_NONDISP:
398 yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
400 for line in indentLines(genLines(handles)):
403 def writeBasicTypes (api, filename):
405 for line in indentLines(["enum { %s\t= %s\t};" % define for define in api.definitions]):
408 for line in genHandlesSrc(api.handles):
411 for enum in api.enums:
412 for line in genEnumSrc(enum):
415 for bitfield in api.bitfields:
416 for line in genBitfieldSrc(bitfield):
420 writeInlFile(filename, INL_HEADER, gen())
422 def writeCompositeTypes (api, filename):
424 for type in api.compositeTypes:
425 for line in genCompositeTypeSrc(type):
429 writeInlFile(filename, INL_HEADER, gen())
431 def argListToStr (args):
432 return ", ".join("%s %s%s" % (v.type, v.name, v.arraySize if v.arraySize != None else "") for v in args)
434 def writeInterfaceDecl (api, filename, functionTypes, concrete):
436 postfix = "" if concrete else " = 0"
437 for function in api.functions:
438 if function.getType() in functionTypes:
439 yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix)
441 writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
443 def writeFunctionPtrTypes (api, filename):
445 for function in api.functions:
446 yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments))
448 writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
450 def writeFunctionPointers (api, filename, functionTypes):
451 writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
453 def writeInitFunctionPointers (api, filename, functionTypes):
454 def makeInitFunctionPointers ():
455 for function in api.functions:
456 if function.getType() in functionTypes:
457 yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name)
459 writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
461 def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className):
462 def makeFuncPtrInterfaceImpl ():
463 for function in api.functions:
464 if function.getType() in functionTypes:
466 yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments))
468 yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments))
471 writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
473 def writeStrUtilProto (api, filename):
474 def makeStrUtilProto ():
475 for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]):
478 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]):
481 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]):
484 for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]):
487 for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]):
490 writeInlFile(filename, INL_HEADER, makeStrUtilProto())
492 def writeStrUtilImpl (api, filename):
493 def makeStrUtilImpl ():
494 for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]):
497 for enum in api.enums:
499 yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name)
501 yield "\tswitch (value)"
503 for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]):
508 for bitfield in api.bitfields:
510 yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name)
513 if len(bitfield.values) > 0:
514 yield "\tstatic const tcu::Format::BitDesc s_desc[] ="
516 for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]):
519 yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));"
521 yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);"
525 bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
527 for type in api.compositeTypes:
529 yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name
531 yield "\ts << \"%s = {\\n\";" % type.name
532 for member in type.members:
533 memberName = member.name
536 if member.type in bitfieldTypeNames:
537 valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name)
538 elif member.type == "const char*" or member.type == "char*":
539 valFmt = "getCharPtrStr(value.%s)" % member.name
540 elif '[' in member.name:
541 baseName = member.name[:member.name.find('[')]
542 if baseName in ["extensionName", "deviceName", "layerName", "description"]:
543 valFmt = "(const char*)value.%s" % baseName
544 elif member.type == 'char' or member.type == 'deUint8':
545 newLine = "'\\n' << "
546 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)
548 newLine = "'\\n' << "
549 valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), DE_ARRAY_END(value.%s))" % (baseName, baseName)
550 memberName = baseName
552 valFmt = "value.%s" % member.name
553 yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';"
559 writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
561 class ConstructorFunction:
562 def __init__ (self, type, name, objectType, iface, arguments):
565 self.objectType = objectType
567 self.arguments = arguments
569 def getConstructorFunctions (api):
571 for function in api.functions:
572 if (function.name[:8] == "vkCreate" or function.name == "vkAllocateMemory") and not "count" in [a.name for a in function.arguments]:
573 # \todo [pyry] Rather hacky
575 if function.getType() == Function.TYPE_PLATFORM:
576 iface = Variable("const PlatformInterface&", "vk")
577 elif function.getType() == Function.TYPE_INSTANCE:
578 iface = Variable("const InstanceInterface&", "vk")
580 iface = Variable("const DeviceInterface&", "vk")
582 assert function.arguments[-2].type == "const VkAllocationCallbacks*"
584 objectType = function.arguments[-1].type.replace("*", "").strip()
585 arguments = function.arguments[:-1]
586 funcs.append(ConstructorFunction(function.getType(), getInterfaceName(function), objectType, iface, arguments))
589 def writeRefUtilProto (api, filename):
590 functions = getConstructorFunctions(api)
592 def makeRefUtilProto ():
594 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]):
597 writeInlFile(filename, INL_HEADER, makeRefUtilProto())
599 def writeRefUtilImpl (api, filename):
600 functions = getConstructorFunctions(api)
602 def makeRefUtilImpl ():
603 yield "namespace refdetails"
607 for function in api.functions:
608 if function.getType() == Function.TYPE_DEVICE \
609 and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \
610 and not function.name == "vkDestroyDevice":
611 objectType = function.arguments[-2].type
613 yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType)
615 yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function))
619 yield "} // refdetails"
622 for function in functions:
623 dtorObj = "device" if function.type == Function.TYPE_DEVICE else "object"
625 yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments))
627 yield "\t%s object = 0;" % function.objectType
628 yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"]))
629 yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name]))
633 writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
635 def writeNullDriverImpl (api, filename):
636 def genNullDriverImpl ():
638 "vkCreateGraphicsPipelines",
639 "vkCreateComputePipelines",
640 "vkGetInstanceProcAddr",
641 "vkGetDeviceProcAddr",
642 "vkEnumeratePhysicalDevices",
643 "vkGetPhysicalDeviceProperties",
644 "vkGetPhysicalDeviceQueueFamilyProperties",
645 "vkGetPhysicalDeviceMemoryProperties",
646 "vkGetPhysicalDeviceFormatProperties",
647 "vkGetBufferMemoryRequirements",
648 "vkGetImageMemoryRequirements",
650 "vkAllocateDescriptorSets",
651 "vkFreeDescriptorSets",
652 "vkResetDescriptorPool",
653 "vkAllocateCommandBuffers",
654 "vkFreeCommandBuffers"
656 specialFuncs = [f for f in api.functions if f.name in specialFuncNames]
657 createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs]
658 destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs]
659 dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs]
661 def getHandle (name):
662 for handle in api.handles:
663 if handle.name == name:
665 raise Exception("No such handle: %s" % name)
667 for function in createFuncs:
668 objectType = function.arguments[-1].type.replace("*", "").strip()
669 argsStr = ", ".join([a.name for a in function.arguments[:-1]])
671 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
673 yield "\tDE_UNREF(%s);" % function.arguments[-2].name
675 if getHandle(objectType).type == Handle.TYPE_NONDISP:
676 yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
678 yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
683 for function in destroyFuncs:
684 objectArg = function.arguments[-2]
686 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
688 for arg in function.arguments[:-2]:
689 yield "\tDE_UNREF(%s);" % arg.name
691 if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
692 yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
694 yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
699 for function in dummyFuncs:
700 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
702 for arg in function.arguments:
703 yield "\tDE_UNREF(%s);" % arg.name
704 if function.returnType != "void":
705 yield "\treturn VK_SUCCESS;"
709 def genFuncEntryTable (type, name):
710 funcs = [f for f in api.functions if f.getType() == type]
712 yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name
714 for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]):
720 for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"):
723 for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"):
726 for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"):
730 writeInlFile(filename, INL_HEADER, genNullDriverImpl())
732 def writeTypeUtil (api, filename):
733 # Structs filled by API queries are not often used in test code
734 QUERY_RESULT_TYPES = set([
735 "VkPhysicalDeviceFeatures",
736 "VkPhysicalDeviceLimits",
737 "VkFormatProperties",
738 "VkImageFormatProperties",
739 "VkPhysicalDeviceSparseProperties",
740 "VkQueueFamilyProperties",
744 COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
746 def isSimpleStruct (type):
747 def hasArrayMember (type):
748 for member in type.members:
749 if "[" in member.name:
753 def hasCompositeMember (type):
754 for member in type.members:
755 if member.type in COMPOSITE_TYPES:
759 return type.typeClass == CompositeType.CLASS_STRUCT and \
760 type.members[0].type != "VkStructureType" and \
761 not type.name in QUERY_RESULT_TYPES and \
762 not hasArrayMember(type) and \
763 not hasCompositeMember(type)
766 for type in api.compositeTypes:
767 if not isSimpleStruct(type):
771 yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
773 yield "\t%s res;" % type.name
774 for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
776 yield "\treturn res;"
779 writeInlFile(filename, INL_HEADER, gen())
781 if __name__ == "__main__":
782 src = readFile(sys.argv[1])
784 platformFuncs = set([Function.TYPE_PLATFORM])
785 instanceFuncs = set([Function.TYPE_INSTANCE])
786 deviceFuncs = set([Function.TYPE_DEVICE])
788 writeHandleType (api, os.path.join(VULKAN_DIR, "vkHandleType.inl"))
789 writeBasicTypes (api, os.path.join(VULKAN_DIR, "vkBasicTypes.inl"))
790 writeCompositeTypes (api, os.path.join(VULKAN_DIR, "vkStructTypes.inl"))
791 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualPlatformInterface.inl"), functionTypes = platformFuncs, concrete = False)
792 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = False)
793 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = False)
794 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcretePlatformInterface.inl"), functionTypes = platformFuncs, concrete = True)
795 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = True)
796 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = True)
797 writeFunctionPtrTypes (api, os.path.join(VULKAN_DIR, "vkFunctionPointerTypes.inl"))
798 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
799 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
800 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
801 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
802 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
803 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
804 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkPlatformDriverImpl.inl"), functionTypes = platformFuncs, className = "PlatformDriver")
805 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkInstanceDriverImpl.inl"), functionTypes = instanceFuncs, className = "InstanceDriver")
806 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkDeviceDriverImpl.inl"), functionTypes = deviceFuncs, className = "DeviceDriver")
807 writeStrUtilProto (api, os.path.join(VULKAN_DIR, "vkStrUtil.inl"))
808 writeStrUtilImpl (api, os.path.join(VULKAN_DIR, "vkStrUtilImpl.inl"))
809 writeRefUtilProto (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
810 writeRefUtilImpl (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
811 writeNullDriverImpl (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
812 writeTypeUtil (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))