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 "vkGetPhysicalDeviceSparseImageFormatProperties",
53 "vkGetPhysicalDeviceLimits",
54 "vkGetPhysicalDeviceProperties",
55 "vkGetPhysicalDeviceQueueFamilyProperties",
56 "vkGetPhysicalDeviceMemoryProperties",
57 "vkEnumerateDeviceExtensionProperties",
58 "vkEnumerateDeviceLayerProperties",
60 "vkGetDeviceProcAddr",
63 "vkDestroySurfaceKHR",
64 "vkGetPhysicalDeviceSurfaceSupportKHR",
65 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
66 "vkGetPhysicalDeviceSurfaceFormatsKHR",
67 "vkGetPhysicalDeviceSurfacePresentModesKHR",
70 "vkGetPhysicalDeviceDisplayPropertiesKHR",
71 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR",
72 "vkGetDisplayPlaneSupportedDisplaysKHR",
73 "vkGetDisplayModePropertiesKHR",
74 "vkCreateDisplayModeKHR",
75 "vkGetDisplayPlaneCapabilitiesKHR",
76 "vkCreateDisplayPlaneSurfaceKHR",
79 "vkCreateXlibSurfaceKHR",
80 "vkGetPhysicalDeviceXlibPresentationSupportKHR",
83 "vkCreateXcbSurfaceKHR",
84 "vkGetPhysicalDeviceXcbPresentationSupportKHR",
86 # VK_KHR_wayland_surface
87 "vkCreateWaylandSurfaceKHR",
88 "vkGetPhysicalDeviceWaylandPresentationSupportKHR",
91 "vkCreateMirSurfaceKHR",
92 "vkGetPhysicalDeviceMirPresentationSupportKHR",
94 # VK_KHR_android_surface
95 "vkCreateAndroidSurfaceKHR",
97 # VK_KHR_win32_surface
98 "vkCreateWin32SurfaceKHR",
99 "vkGetPhysicalDeviceWin32PresentationSupportKHR",
101 # VK_EXT_debug_report
102 "vkCreateDebugReportCallbackEXT",
103 "vkDestroyDebugReportCallbackEXT",
104 "vkDebugReportMessageEXT",
109 "VK_MAX_PHYSICAL_DEVICE_NAME_SIZE",
110 "VK_MAX_EXTENSION_NAME_SIZE",
112 "VK_MAX_MEMORY_TYPES",
113 "VK_MAX_MEMORY_HEAPS",
114 "VK_MAX_DESCRIPTION_SIZE",
115 "VK_ATTACHMENT_UNUSED",
116 "VK_SUBPASS_EXTERNAL"
120 # VK_KHR_xlib_surface
121 ("Display*", "XlibDisplayPtr", "void*"),
122 ("Window", "XlibWindow", "deUintptr",),
123 ("VisualID", "XlibVisualID", "deUint32"),
126 ("xcb_connection_t*", "XcbConnectionPtr", "void*"),
127 ("xcb_window_t", "XcbWindow", "deUintptr"),
128 ("xcb_visualid_t", "XcbVisualid", "deUint32"),
130 # VK_KHR_wayland_surface
131 ("struct wl_display*", "WaylandDisplayPtr", "void*"),
132 ("struct wl_surface*", "WaylandSurfacePtr", "void*"),
135 ("MirConnection*", "MirConnectionPtr", "void*"),
136 ("MirSurface*", "MirSurfacePtr", "void*"),
138 # VK_KHR_android_surface
139 ("ANativeWindow*", "AndroidNativeWindowPtr", "void*"),
141 # VK_KHR_win32_surface
142 ("HINSTANCE", "Win32InstanceHandle", "void*"),
143 ("HWND", "Win32WindowHandle", "void*")
145 PLATFORM_TYPE_NAMESPACE = "pt"
151 def __init__ (self, type, name):
155 def getHandleType (self):
156 name = re.sub(r'([a-z])([A-Z])', r'\1_\2', self.name)
157 return "HANDLE_TYPE_" + name[3:].upper()
160 def __init__ (self, name, values):
165 def __init__ (self, name, values):
170 def __init__ (self, type, name, arraySize = None):
173 self.arraySize = arraySize
179 def __init__ (self, typeClass, name, members):
180 self.typeClass = typeClass
182 self.members = members
184 def getClassName (self):
185 names = {CompositeType.CLASS_STRUCT: 'struct', CompositeType.CLASS_UNION: 'union'}
186 return names[self.typeClass]
189 TYPE_PLATFORM = 0 # Not bound to anything
190 TYPE_INSTANCE = 1 # Bound to VkInstance
191 TYPE_DEVICE = 2 # Bound to VkDevice
193 def __init__ (self, name, returnType, arguments):
195 self.returnType = returnType
196 self.arguments = arguments
199 if self.name in PLATFORM_FUNCTIONS:
200 return Function.TYPE_PLATFORM
201 elif self.name in INSTANCE_FUNCTIONS:
202 return Function.TYPE_INSTANCE
204 return Function.TYPE_DEVICE
207 def __init__ (self, definitions, handles, enums, bitfields, compositeTypes, functions):
208 self.definitions = definitions
209 self.handles = handles
211 self.bitfields = bitfields
212 self.compositeTypes = compositeTypes
213 self.functions = functions
215 def readFile (filename):
216 with open(filename, 'rb') as f:
219 IDENT_PTRN = r'[a-zA-Z_][a-zA-Z0-9_]*'
220 TYPE_PTRN = r'[a-zA-Z_][a-zA-Z0-9_ \t*]*'
222 def endswith (s, postfix):
223 return len(s) >= len(postfix) and s[len(s)-len(postfix):] == postfix
225 def fixupEnumValues (values):
227 for name, value in values:
228 if endswith(name, "_BEGIN_RANGE") or endswith(name, "_END_RANGE"):
230 fixed.append((name, value))
233 def fixupType (type):
234 for platformType, substitute, compat in PLATFORM_TYPES:
235 if type == platformType:
236 return PLATFORM_TYPE_NAMESPACE + "::" + substitute
239 ("uint8_t", "deUint8"),
240 ("uint16_t", "deUint16"),
241 ("uint32_t", "deUint32"),
242 ("uint64_t", "deUint64"),
243 ("int8_t", "deInt8"),
244 ("int16_t", "deInt16"),
245 ("int32_t", "deInt32"),
246 ("int64_t", "deInt64"),
247 ("bool32_t", "deUint32"),
248 ("size_t", "deUintptr"),
251 for src, dst in replacements:
252 type = type.replace(src, dst)
256 def fixupFunction (function):
257 fixedArgs = [Variable(fixupType(a.type), a.name, a.arraySize) for a in function.arguments]
258 fixedReturnType = fixupType(function.returnType)
260 return Function(function.name, fixedReturnType, fixedArgs)
262 def getInterfaceName (function):
263 assert function.name[:2] == "vk"
264 return function.name[2].lower() + function.name[3:]
266 def getFunctionTypeName (function):
267 assert function.name[:2] == "vk"
268 return function.name[2:] + "Func"
270 def endsWith (str, postfix):
271 return str[-len(postfix):] == postfix
273 def splitNameExtPostfix (name):
274 knownExtPostfixes = ["KHR", "EXT"]
275 for postfix in knownExtPostfixes:
276 if endsWith(name, postfix):
277 return (name[:-len(postfix)], postfix)
280 def getBitEnumNameForBitfield (bitfieldName):
281 bitfieldName, postfix = splitNameExtPostfix(bitfieldName)
283 assert bitfieldName[-1] == "s"
284 return bitfieldName[:-1] + "Bits" + postfix
286 def getBitfieldNameForBitEnum (bitEnumName):
287 bitEnumName, postfix = splitNameExtPostfix(bitEnumName)
289 assert bitEnumName[-4:] == "Bits"
290 return bitEnumName[:-4] + "s" + postfix
292 def parsePreprocDefinedValue (src, name):
293 definition = re.search(r'#\s*define\s+' + name + r'\s+([^\n]+)\n', src)
294 if definition is None:
295 raise Exception("No such definition: %s" % name)
296 value = definition.group(1).strip()
298 if value == "UINT32_MAX":
303 def parseEnum (name, src):
304 keyValuePtrn = '(' + IDENT_PTRN + r')\s*=\s*([^\s,}]+)\s*[,}]'
305 matches = re.findall(keyValuePtrn, src)
307 return Enum(name, fixupEnumValues(matches))
309 # \note Parses raw enums, some are mapped to bitfields later
310 def parseEnums (src):
311 matches = re.findall(r'typedef enum(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
314 for enumname, contents, typename in matches:
315 enums.append(parseEnum(typename, contents))
319 def parseCompositeType (type, name, src):
320 # \todo [pyry] Array support is currently a hack (size coupled with name)
321 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r'(\[[^\]]+\])*)\s*;'
322 matches = re.findall(typeNamePtrn, src)
323 members = [Variable(fixupType(t.strip()), n.strip()) for t, n, a in matches]
325 return CompositeType(type, name, members)
327 def parseCompositeTypes (src):
328 typeMap = { 'struct': CompositeType.CLASS_STRUCT, 'union': CompositeType.CLASS_UNION }
329 matches = re.findall(r'typedef (struct|union)(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
332 for type, structname, contents, typename in matches:
333 types.append(parseCompositeType(typeMap[type], typename, contents))
337 def parseHandles (src):
338 matches = re.findall(r'VK_DEFINE(_NON_DISPATCHABLE|)_HANDLE\((' + IDENT_PTRN + r')\)[ \t]*[\n\r]', src)
340 typeMap = {'': Handle.TYPE_DISP, '_NON_DISPATCHABLE': Handle.TYPE_NONDISP}
342 for type, name in matches:
343 handle = Handle(typeMap[type], name)
344 handles.append(handle)
348 def parseArgList (src):
349 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r')(\[[^\]]+\])?'
352 for rawArg in src.split(','):
353 m = re.search(typeNamePtrn, rawArg)
354 args.append(Variable(m.group(1).strip(), m.group(2).strip(), m.group(3)))
358 def parseFunctions (src):
359 ptrn = r'VKAPI_ATTR\s+(' + TYPE_PTRN + ')VKAPI_CALL\s+(' + IDENT_PTRN + r')\s*\(([^)]*)\)\s*;'
360 matches = re.findall(ptrn, src)
363 for returnType, name, argList in matches:
364 functions.append(Function(name.strip(), returnType.strip(), parseArgList(argList)))
366 return [fixupFunction(f) for f in functions]
368 def parseBitfieldNames (src):
369 ptrn = r'typedef\s+VkFlags\s(' + IDENT_PTRN + r')\s*;'
370 matches = re.findall(ptrn, src)
375 definitions = [(name, parsePreprocDefinedValue(src, name)) for name in DEFINITIONS]
376 rawEnums = parseEnums(src)
377 bitfieldNames = parseBitfieldNames(src)
380 bitfieldEnums = set([getBitEnumNameForBitfield(n) for n in bitfieldNames])
382 for enum in rawEnums:
383 if enum.name in bitfieldEnums:
384 bitfields.append(Bitfield(getBitfieldNameForBitEnum(enum.name), enum.values))
388 for bitfieldName in bitfieldNames:
389 if not bitfieldName in [bitfield.name for bitfield in bitfields]:
391 bitfields.append(Bitfield(bitfieldName, []))
394 definitions = definitions,
395 handles = parseHandles(src),
397 bitfields = bitfields,
398 compositeTypes = parseCompositeTypes(src),
399 functions = parseFunctions(src))
401 def writeHandleType (api, filename):
403 yield "enum HandleType"
405 yield "\t%s = 0," % api.handles[0].getHandleType()
406 for handle in api.handles[1:]:
407 yield "\t%s," % handle.getHandleType()
408 yield "\tHANDLE_TYPE_LAST"
412 writeInlFile(filename, INL_HEADER, gen())
414 def getEnumValuePrefix (enum):
415 prefix = enum.name[0]
416 for i in range(1, len(enum.name)):
417 if enum.name[i].isupper() and not enum.name[i-1].isupper():
419 prefix += enum.name[i].upper()
422 def parseInt (value):
423 if value[:2] == "0x":
424 return int(value, 16)
426 return int(value, 10)
428 def areEnumValuesLinear (enum):
430 for name, value in enum.values:
431 if parseInt(value) != curIndex:
436 def genEnumSrc (enum):
437 yield "enum %s" % enum.name
440 for line in indentLines(["\t%s\t= %s," % v for v in enum.values]):
443 if areEnumValuesLinear(enum):
445 yield "\t%s_LAST" % getEnumValuePrefix(enum)
449 def genBitfieldSrc (bitfield):
450 if len(bitfield.values) > 0:
451 yield "enum %s" % getBitEnumNameForBitfield(bitfield.name)
453 for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]):
457 yield "typedef deUint32 %s;" % bitfield.name
459 def genCompositeTypeSrc (type):
460 yield "%s %s" % (type.getClassName(), type.name)
462 for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]):
466 def genHandlesSrc (handles):
467 def genLines (handles):
468 for handle in handles:
469 if handle.type == Handle.TYPE_DISP:
470 yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
471 elif handle.type == Handle.TYPE_NONDISP:
472 yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
474 for line in indentLines(genLines(handles)):
477 def writeBasicTypes (api, filename):
479 for line in indentLines(["enum { %s\t= %s\t};" % define for define in api.definitions]):
482 for line in genHandlesSrc(api.handles):
485 for enum in api.enums:
486 for line in genEnumSrc(enum):
489 for bitfield in api.bitfields:
490 for line in genBitfieldSrc(bitfield):
493 for line in indentLines(["VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES]):
496 writeInlFile(filename, INL_HEADER, gen())
498 def writeCompositeTypes (api, filename):
500 for type in api.compositeTypes:
501 for line in genCompositeTypeSrc(type):
505 writeInlFile(filename, INL_HEADER, gen())
507 def argListToStr (args):
508 return ", ".join("%s %s%s" % (v.type, v.name, v.arraySize if v.arraySize != None else "") for v in args)
510 def writeInterfaceDecl (api, filename, functionTypes, concrete):
512 postfix = "" if concrete else " = 0"
513 for function in api.functions:
514 if function.getType() in functionTypes:
515 yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix)
517 writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
519 def writeFunctionPtrTypes (api, filename):
521 for function in api.functions:
522 yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments))
524 writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
526 def writeFunctionPointers (api, filename, functionTypes):
527 writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
529 def writeInitFunctionPointers (api, filename, functionTypes):
530 def makeInitFunctionPointers ():
531 for function in api.functions:
532 if function.getType() in functionTypes:
533 yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name)
535 writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
537 def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className):
538 def makeFuncPtrInterfaceImpl ():
539 for function in api.functions:
540 if function.getType() in functionTypes:
542 yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments))
544 yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments))
547 writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
549 def writeStrUtilProto (api, filename):
550 def makeStrUtilProto ():
551 for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]):
554 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]):
557 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]):
560 for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]):
563 for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]):
566 writeInlFile(filename, INL_HEADER, makeStrUtilProto())
568 def writeStrUtilImpl (api, filename):
569 def makeStrUtilImpl ():
570 for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]):
574 yield "namespace %s" % PLATFORM_TYPE_NAMESPACE
577 for line in indentLines("std::ostream& operator<< (std::ostream& s, %s\tv) { return s << tcu::toHex(v.internal); }" % s for n, s, c in PLATFORM_TYPES):
582 for enum in api.enums:
584 yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name)
586 yield "\tswitch (value)"
588 for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]):
593 for bitfield in api.bitfields:
595 yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name)
598 if len(bitfield.values) > 0:
599 yield "\tstatic const tcu::Format::BitDesc s_desc[] ="
601 for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]):
604 yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));"
606 yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);"
610 bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
612 for type in api.compositeTypes:
614 yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name
616 yield "\ts << \"%s = {\\n\";" % type.name
617 for member in type.members:
618 memberName = member.name
621 if member.type in bitfieldTypeNames:
622 valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name)
623 elif member.type == "const char*" or member.type == "char*":
624 valFmt = "getCharPtrStr(value.%s)" % member.name
625 elif '[' in member.name:
626 baseName = member.name[:member.name.find('[')]
627 if baseName in ["extensionName", "deviceName", "layerName", "description"]:
628 valFmt = "(const char*)value.%s" % baseName
629 elif member.type == 'char' or member.type == 'deUint8':
630 newLine = "'\\n' << "
631 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)
633 if baseName == "memoryTypes" or baseName == "memoryHeaps":
634 endIter = "DE_ARRAY_BEGIN(value.%s) + value.%sCount" % (baseName, baseName[:-1])
636 endIter = "DE_ARRAY_END(value.%s)" % baseName
637 newLine = "'\\n' << "
638 valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)" % (baseName, endIter)
639 memberName = baseName
641 valFmt = "value.%s" % member.name
642 yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';"
648 writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
650 class ConstructorFunction:
651 def __init__ (self, type, name, objectType, iface, arguments):
654 self.objectType = objectType
656 self.arguments = arguments
658 def getConstructorFunctions (api):
660 for function in api.functions:
661 if (function.name[:8] == "vkCreate" or function.name == "vkAllocateMemory") and not "count" in [a.name for a in function.arguments]:
662 if function.name == "vkCreateDisplayModeKHR":
663 continue # No way to delete display modes (bug?)
665 # \todo [pyry] Rather hacky
667 if function.getType() == Function.TYPE_PLATFORM:
668 iface = Variable("const PlatformInterface&", "vk")
669 elif function.getType() == Function.TYPE_INSTANCE:
670 iface = Variable("const InstanceInterface&", "vk")
672 iface = Variable("const DeviceInterface&", "vk")
674 assert function.arguments[-2].type == "const VkAllocationCallbacks*"
676 objectType = function.arguments[-1].type.replace("*", "").strip()
677 arguments = function.arguments[:-1]
678 funcs.append(ConstructorFunction(function.getType(), getInterfaceName(function), objectType, iface, arguments))
681 def writeRefUtilProto (api, filename):
682 functions = getConstructorFunctions(api)
684 def makeRefUtilProto ():
686 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]):
689 writeInlFile(filename, INL_HEADER, makeRefUtilProto())
691 def writeRefUtilImpl (api, filename):
692 functions = getConstructorFunctions(api)
694 def makeRefUtilImpl ():
695 yield "namespace refdetails"
699 for function in api.functions:
700 if function.getType() == Function.TYPE_DEVICE \
701 and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \
702 and not function.name == "vkDestroyDevice":
703 objectType = function.arguments[-2].type
705 yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType)
707 yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function))
711 yield "} // refdetails"
714 for function in functions:
715 if function.type == Function.TYPE_DEVICE:
717 elif function.type == Function.TYPE_INSTANCE:
718 if function.name == "createDevice":
725 yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments))
727 yield "\t%s object = 0;" % function.objectType
728 yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"]))
729 yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name]))
733 writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
735 def writeNullDriverImpl (api, filename):
736 def genNullDriverImpl ():
738 "vkCreateGraphicsPipelines",
739 "vkCreateComputePipelines",
740 "vkGetInstanceProcAddr",
741 "vkGetDeviceProcAddr",
742 "vkEnumeratePhysicalDevices",
743 "vkGetPhysicalDeviceProperties",
744 "vkGetPhysicalDeviceQueueFamilyProperties",
745 "vkGetPhysicalDeviceMemoryProperties",
746 "vkGetPhysicalDeviceFormatProperties",
747 "vkGetBufferMemoryRequirements",
748 "vkGetImageMemoryRequirements",
750 "vkAllocateDescriptorSets",
751 "vkFreeDescriptorSets",
752 "vkResetDescriptorPool",
753 "vkAllocateCommandBuffers",
754 "vkFreeCommandBuffers",
755 "vkCreateDisplayModeKHR",
756 "vkCreateSharedSwapchainsKHR",
758 specialFuncs = [f for f in api.functions if f.name in specialFuncNames]
759 createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs]
760 destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs]
761 dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs]
763 def getHandle (name):
764 for handle in api.handles:
765 if handle.name == name:
767 raise Exception("No such handle: %s" % name)
769 for function in createFuncs:
770 objectType = function.arguments[-1].type.replace("*", "").strip()
771 argsStr = ", ".join([a.name for a in function.arguments[:-1]])
773 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
775 yield "\tDE_UNREF(%s);" % function.arguments[-2].name
777 if getHandle(objectType).type == Handle.TYPE_NONDISP:
778 yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
780 yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
785 for function in destroyFuncs:
786 objectArg = function.arguments[-2]
788 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
790 for arg in function.arguments[:-2]:
791 yield "\tDE_UNREF(%s);" % arg.name
793 if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
794 yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
796 yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
801 for function in dummyFuncs:
802 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
804 for arg in function.arguments:
805 yield "\tDE_UNREF(%s);" % arg.name
806 if function.returnType != "void":
807 yield "\treturn VK_SUCCESS;"
811 def genFuncEntryTable (type, name):
812 funcs = [f for f in api.functions if f.getType() == type]
814 yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name
816 for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]):
822 for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"):
825 for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"):
828 for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"):
832 writeInlFile(filename, INL_HEADER, genNullDriverImpl())
834 def writeTypeUtil (api, filename):
835 # Structs filled by API queries are not often used in test code
836 QUERY_RESULT_TYPES = set([
837 "VkPhysicalDeviceFeatures",
838 "VkPhysicalDeviceLimits",
839 "VkFormatProperties",
840 "VkImageFormatProperties",
841 "VkPhysicalDeviceSparseProperties",
842 "VkQueueFamilyProperties",
846 COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
848 def isSimpleStruct (type):
849 def hasArrayMember (type):
850 for member in type.members:
851 if "[" in member.name:
855 def hasCompositeMember (type):
856 for member in type.members:
857 if member.type in COMPOSITE_TYPES:
861 return type.typeClass == CompositeType.CLASS_STRUCT and \
862 type.members[0].type != "VkStructureType" and \
863 not type.name in QUERY_RESULT_TYPES and \
864 not hasArrayMember(type) and \
865 not hasCompositeMember(type)
868 for type in api.compositeTypes:
869 if not isSimpleStruct(type):
873 yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
875 yield "\t%s res;" % type.name
876 for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
878 yield "\treturn res;"
881 writeInlFile(filename, INL_HEADER, gen())
883 if __name__ == "__main__":
884 src = readFile(sys.argv[1])
886 platformFuncs = set([Function.TYPE_PLATFORM])
887 instanceFuncs = set([Function.TYPE_INSTANCE])
888 deviceFuncs = set([Function.TYPE_DEVICE])
890 writeHandleType (api, os.path.join(VULKAN_DIR, "vkHandleType.inl"))
891 writeBasicTypes (api, os.path.join(VULKAN_DIR, "vkBasicTypes.inl"))
892 writeCompositeTypes (api, os.path.join(VULKAN_DIR, "vkStructTypes.inl"))
893 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualPlatformInterface.inl"), functionTypes = platformFuncs, concrete = False)
894 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = False)
895 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = False)
896 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcretePlatformInterface.inl"), functionTypes = platformFuncs, concrete = True)
897 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = True)
898 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = True)
899 writeFunctionPtrTypes (api, os.path.join(VULKAN_DIR, "vkFunctionPointerTypes.inl"))
900 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
901 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
902 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
903 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
904 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
905 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
906 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkPlatformDriverImpl.inl"), functionTypes = platformFuncs, className = "PlatformDriver")
907 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkInstanceDriverImpl.inl"), functionTypes = instanceFuncs, className = "InstanceDriver")
908 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkDeviceDriverImpl.inl"), functionTypes = deviceFuncs, className = "DeviceDriver")
909 writeStrUtilProto (api, os.path.join(VULKAN_DIR, "vkStrUtil.inl"))
910 writeStrUtilImpl (api, os.path.join(VULKAN_DIR, "vkStrUtilImpl.inl"))
911 writeRefUtilProto (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
912 writeRefUtilImpl (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
913 writeNullDriverImpl (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
914 writeTypeUtil (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))