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",
106 # VK_NV_external_memory_capabilities
107 "vkGetPhysicalDeviceExternalImageFormatPropertiesNV"
111 ("VK_API_VERSION", "deUint32"),
112 ("VK_MAX_PHYSICAL_DEVICE_NAME_SIZE", "size_t"),
113 ("VK_MAX_EXTENSION_NAME_SIZE", "size_t"),
114 ("VK_UUID_SIZE", "size_t"),
115 ("VK_MAX_MEMORY_TYPES", "size_t"),
116 ("VK_MAX_MEMORY_HEAPS", "size_t"),
117 ("VK_MAX_DESCRIPTION_SIZE", "size_t"),
118 ("VK_ATTACHMENT_UNUSED", "deUint32"),
119 ("VK_SUBPASS_EXTERNAL", "deUint32"),
120 ("VK_QUEUE_FAMILY_IGNORED", "deUint32"),
121 ("VK_REMAINING_MIP_LEVELS", "deUint32"),
122 ("VK_REMAINING_ARRAY_LAYERS", "deUint32"),
123 ("VK_WHOLE_SIZE", "vk::VkDeviceSize"),
124 ("VK_TRUE", "vk::VkBool32"),
125 ("VK_FALSE", "vk::VkBool32"),
129 # VK_KHR_xlib_surface
130 ("Display*", "XlibDisplayPtr", "void*"),
131 ("Window", "XlibWindow", "deUintptr",),
132 ("VisualID", "XlibVisualID", "deUint32"),
135 ("xcb_connection_t*", "XcbConnectionPtr", "void*"),
136 ("xcb_window_t", "XcbWindow", "deUintptr"),
137 ("xcb_visualid_t", "XcbVisualid", "deUint32"),
139 # VK_KHR_wayland_surface
140 ("struct wl_display*", "WaylandDisplayPtr", "void*"),
141 ("struct wl_surface*", "WaylandSurfacePtr", "void*"),
144 ("MirConnection*", "MirConnectionPtr", "void*"),
145 ("MirSurface*", "MirSurfacePtr", "void*"),
147 # VK_KHR_android_surface
148 ("ANativeWindow*", "AndroidNativeWindowPtr", "void*"),
150 # VK_KHR_win32_surface
151 ("HINSTANCE", "Win32InstanceHandle", "void*"),
152 ("HWND", "Win32WindowHandle", "void*"),
153 ("HANDLE", "Win32Handle", "void*"),
154 ("const SECURITY_ATTRIBUTES*", "Win32SecurityAttributesPtr", "const void*"),
156 PLATFORM_TYPE_NAMESPACE = "pt"
157 TYPE_SUBSTITUTIONS = [
158 ("uint8_t", "deUint8"),
159 ("uint16_t", "deUint16"),
160 ("uint32_t", "deUint32"),
161 ("uint64_t", "deUint64"),
162 ("int8_t", "deInt8"),
163 ("int16_t", "deInt16"),
164 ("int32_t", "deInt32"),
165 ("int64_t", "deInt64"),
166 ("bool32_t", "deUint32"),
167 ("size_t", "deUintptr"),
170 ("DWORD", "deUint32"),
171 ("HANDLE*", PLATFORM_TYPE_NAMESPACE + "::" + "Win32Handle*")
174 EXTENSION_POSTFIXES = ["KHR", "EXT", "NV"]
180 def __init__ (self, type, name):
184 def getHandleType (self):
185 name = re.sub(r'([a-z])([A-Z])', r'\1_\2', self.name)
186 return "HANDLE_TYPE_" + name[3:].upper()
189 def __init__ (self, name, values):
194 def __init__ (self, name, values):
199 def __init__ (self, type, name, arraySize = None):
202 self.arraySize = arraySize
208 def __init__ (self, typeClass, name, members):
209 self.typeClass = typeClass
211 self.members = members
213 def getClassName (self):
214 names = {CompositeType.CLASS_STRUCT: 'struct', CompositeType.CLASS_UNION: 'union'}
215 return names[self.typeClass]
218 TYPE_PLATFORM = 0 # Not bound to anything
219 TYPE_INSTANCE = 1 # Bound to VkInstance
220 TYPE_DEVICE = 2 # Bound to VkDevice
222 def __init__ (self, name, returnType, arguments):
224 self.returnType = returnType
225 self.arguments = arguments
228 if self.name in PLATFORM_FUNCTIONS:
229 return Function.TYPE_PLATFORM
230 elif self.name in INSTANCE_FUNCTIONS:
231 return Function.TYPE_INSTANCE
233 return Function.TYPE_DEVICE
236 def __init__ (self, definitions, handles, enums, bitfields, compositeTypes, functions):
237 self.definitions = definitions
238 self.handles = handles
240 self.bitfields = bitfields
241 self.compositeTypes = compositeTypes
242 self.functions = functions
244 def readFile (filename):
245 with open(filename, 'rb') as f:
248 IDENT_PTRN = r'[a-zA-Z_][a-zA-Z0-9_]*'
249 TYPE_PTRN = r'[a-zA-Z_][a-zA-Z0-9_ \t*]*'
251 def fixupEnumValues (values):
253 for name, value in values:
254 if "_BEGIN_RANGE" in name or "_END_RANGE" in name:
256 fixed.append((name, value))
259 def fixupType (type):
260 for platformType, substitute, compat in PLATFORM_TYPES:
261 if type == platformType:
262 return PLATFORM_TYPE_NAMESPACE + "::" + substitute
264 for src, dst in TYPE_SUBSTITUTIONS:
265 type = type.replace(src, dst)
269 def fixupFunction (function):
270 fixedArgs = [Variable(fixupType(a.type), a.name, a.arraySize) for a in function.arguments]
271 fixedReturnType = fixupType(function.returnType)
273 return Function(function.name, fixedReturnType, fixedArgs)
275 def getInterfaceName (function):
276 assert function.name[:2] == "vk"
277 return function.name[2].lower() + function.name[3:]
279 def getFunctionTypeName (function):
280 assert function.name[:2] == "vk"
281 return function.name[2:] + "Func"
283 def endsWith (str, postfix):
284 return str[-len(postfix):] == postfix
286 def splitNameExtPostfix (name):
287 knownExtPostfixes = EXTENSION_POSTFIXES
288 for postfix in knownExtPostfixes:
289 if endsWith(name, postfix):
290 return (name[:-len(postfix)], postfix)
293 def getBitEnumNameForBitfield (bitfieldName):
294 bitfieldName, postfix = splitNameExtPostfix(bitfieldName)
296 assert bitfieldName[-1] == "s"
297 return bitfieldName[:-1] + "Bits" + postfix
299 def getBitfieldNameForBitEnum (bitEnumName):
300 bitEnumName, postfix = splitNameExtPostfix(bitEnumName)
302 assert bitEnumName[-4:] == "Bits"
303 return bitEnumName[:-4] + "s" + postfix
305 def parsePreprocDefinedValue (src, name):
306 definition = re.search(r'#\s*define\s+' + name + r'\s+([^\n]+)\n', src)
307 if definition is None:
308 raise Exception("No such definition: %s" % name)
309 value = definition.group(1).strip()
311 if value == "UINT32_MAX":
316 def parseEnum (name, src):
317 keyValuePtrn = '(' + IDENT_PTRN + r')\s*=\s*([^\s,}]+)\s*[,}]'
318 matches = re.findall(keyValuePtrn, src)
320 return Enum(name, fixupEnumValues(matches))
322 # \note Parses raw enums, some are mapped to bitfields later
323 def parseEnums (src):
324 matches = re.findall(r'typedef enum(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
327 for enumname, contents, typename in matches:
328 enums.append(parseEnum(typename, contents))
332 def parseCompositeType (type, name, src):
333 # \todo [pyry] Array support is currently a hack (size coupled with name)
334 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r'(\[[^\]]+\])*)\s*;'
335 matches = re.findall(typeNamePtrn, src)
336 members = [Variable(fixupType(t.strip()), n.strip()) for t, n, a in matches]
338 return CompositeType(type, name, members)
340 def parseCompositeTypes (src):
341 typeMap = { 'struct': CompositeType.CLASS_STRUCT, 'union': CompositeType.CLASS_UNION }
342 matches = re.findall(r'typedef (struct|union)(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
345 for type, structname, contents, typename in matches:
346 types.append(parseCompositeType(typeMap[type], typename, contents))
350 def parseHandles (src):
351 matches = re.findall(r'VK_DEFINE(_NON_DISPATCHABLE|)_HANDLE\((' + IDENT_PTRN + r')\)[ \t]*[\n\r]', src)
353 typeMap = {'': Handle.TYPE_DISP, '_NON_DISPATCHABLE': Handle.TYPE_NONDISP}
355 for type, name in matches:
356 handle = Handle(typeMap[type], name)
357 handles.append(handle)
361 def parseArgList (src):
362 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r')(\[[^\]]+\])?'
365 for rawArg in src.split(','):
366 m = re.search(typeNamePtrn, rawArg)
367 args.append(Variable(m.group(1).strip(), m.group(2).strip(), m.group(3)))
371 def parseFunctions (src):
372 ptrn = r'VKAPI_ATTR\s+(' + TYPE_PTRN + ')VKAPI_CALL\s+(' + IDENT_PTRN + r')\s*\(([^)]*)\)\s*;'
373 matches = re.findall(ptrn, src)
376 for returnType, name, argList in matches:
377 functions.append(Function(name.strip(), returnType.strip(), parseArgList(argList)))
379 return [fixupFunction(f) for f in functions]
381 def parseBitfieldNames (src):
382 ptrn = r'typedef\s+VkFlags\s(' + IDENT_PTRN + r')\s*;'
383 matches = re.findall(ptrn, src)
388 definitions = [(name, type, parsePreprocDefinedValue(src, name)) for name, type in DEFINITIONS]
389 rawEnums = parseEnums(src)
390 bitfieldNames = parseBitfieldNames(src)
393 bitfieldEnums = set([getBitEnumNameForBitfield(n) for n in bitfieldNames])
395 for enum in rawEnums:
396 if enum.name in bitfieldEnums:
397 bitfields.append(Bitfield(getBitfieldNameForBitEnum(enum.name), enum.values))
401 for bitfieldName in bitfieldNames:
402 if not bitfieldName in [bitfield.name for bitfield in bitfields]:
404 bitfields.append(Bitfield(bitfieldName, []))
407 definitions = definitions,
408 handles = parseHandles(src),
410 bitfields = bitfields,
411 compositeTypes = parseCompositeTypes(src),
412 functions = parseFunctions(src))
414 def writeHandleType (api, filename):
416 yield "enum HandleType"
418 yield "\t%s = 0," % api.handles[0].getHandleType()
419 for handle in api.handles[1:]:
420 yield "\t%s," % handle.getHandleType()
421 yield "\tHANDLE_TYPE_LAST"
425 writeInlFile(filename, INL_HEADER, gen())
427 def getEnumValuePrefix (enum):
428 prefix = enum.name[0]
429 for i in range(1, len(enum.name)):
430 if enum.name[i].isupper() and not enum.name[i-1].isupper():
432 prefix += enum.name[i].upper()
435 def parseInt (value):
436 if value[:2] == "0x":
437 return int(value, 16)
439 return int(value, 10)
441 def areEnumValuesLinear (enum):
443 for name, value in enum.values:
444 if parseInt(value) != curIndex:
449 def genEnumSrc (enum):
450 yield "enum %s" % enum.name
453 for line in indentLines(["\t%s\t= %s," % v for v in enum.values]):
456 if areEnumValuesLinear(enum):
458 yield "\t%s_LAST" % getEnumValuePrefix(enum)
462 def genBitfieldSrc (bitfield):
463 if len(bitfield.values) > 0:
464 yield "enum %s" % getBitEnumNameForBitfield(bitfield.name)
466 for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]):
470 yield "typedef deUint32 %s;" % bitfield.name
472 def genCompositeTypeSrc (type):
473 yield "%s %s" % (type.getClassName(), type.name)
475 for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]):
479 def genHandlesSrc (handles):
480 def genLines (handles):
481 for handle in handles:
482 if handle.type == Handle.TYPE_DISP:
483 yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
484 elif handle.type == Handle.TYPE_NONDISP:
485 yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
487 for line in indentLines(genLines(handles)):
490 def writeBasicTypes (api, filename):
492 for line in indentLines(["#define %s\t(static_cast<%s>\t(%s))" % (name, type, value) for name, type, value in api.definitions]):
495 for line in genHandlesSrc(api.handles):
498 for enum in api.enums:
499 for line in genEnumSrc(enum):
502 for bitfield in api.bitfields:
503 for line in genBitfieldSrc(bitfield):
506 for line in indentLines(["VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES]):
509 writeInlFile(filename, INL_HEADER, gen())
511 def writeCompositeTypes (api, filename):
513 for type in api.compositeTypes:
514 for line in genCompositeTypeSrc(type):
518 writeInlFile(filename, INL_HEADER, gen())
520 def argListToStr (args):
521 return ", ".join("%s %s%s" % (v.type, v.name, v.arraySize if v.arraySize != None else "") for v in args)
523 def writeInterfaceDecl (api, filename, functionTypes, concrete):
525 postfix = "" if concrete else " = 0"
526 for function in api.functions:
527 if function.getType() in functionTypes:
528 yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix)
530 writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
532 def writeFunctionPtrTypes (api, filename):
534 for function in api.functions:
535 yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments))
537 writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
539 def writeFunctionPointers (api, filename, functionTypes):
540 writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
542 def writeInitFunctionPointers (api, filename, functionTypes):
543 def makeInitFunctionPointers ():
544 for function in api.functions:
545 if function.getType() in functionTypes:
546 yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name)
548 writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
550 def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className):
551 def makeFuncPtrInterfaceImpl ():
552 for function in api.functions:
553 if function.getType() in functionTypes:
555 yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments))
557 yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments))
560 writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
562 def writeStrUtilProto (api, filename):
563 def makeStrUtilProto ():
564 for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]):
567 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]):
570 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]):
573 for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]):
576 for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]):
579 writeInlFile(filename, INL_HEADER, makeStrUtilProto())
581 def writeStrUtilImpl (api, filename):
582 def makeStrUtilImpl ():
583 for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]):
587 yield "namespace %s" % PLATFORM_TYPE_NAMESPACE
590 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):
595 for enum in api.enums:
597 yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name)
599 yield "\tswitch (value)"
601 for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]):
606 for bitfield in api.bitfields:
608 yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name)
611 if len(bitfield.values) > 0:
612 yield "\tstatic const tcu::Format::BitDesc s_desc[] ="
614 for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]):
617 yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));"
619 yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);"
623 bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
625 for type in api.compositeTypes:
627 yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name
629 yield "\ts << \"%s = {\\n\";" % type.name
630 for member in type.members:
631 memberName = member.name
634 if member.type in bitfieldTypeNames:
635 valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name)
636 elif member.type == "const char*" or member.type == "char*":
637 valFmt = "getCharPtrStr(value.%s)" % member.name
638 elif '[' in member.name:
639 baseName = member.name[:member.name.find('[')]
640 if baseName in ["extensionName", "deviceName", "layerName", "description"]:
641 valFmt = "(const char*)value.%s" % baseName
642 elif member.type == 'char' or member.type == 'deUint8':
643 newLine = "'\\n' << "
644 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)
646 if baseName == "memoryTypes" or baseName == "memoryHeaps":
647 endIter = "DE_ARRAY_BEGIN(value.%s) + value.%sCount" % (baseName, baseName[:-1])
649 endIter = "DE_ARRAY_END(value.%s)" % baseName
650 newLine = "'\\n' << "
651 valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)" % (baseName, endIter)
652 memberName = baseName
654 valFmt = "value.%s" % member.name
655 yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';"
661 writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
663 class ConstructorFunction:
664 def __init__ (self, type, name, objectType, iface, arguments):
667 self.objectType = objectType
669 self.arguments = arguments
671 def getConstructorFunctions (api):
673 for function in api.functions:
674 if (function.name[:8] == "vkCreate" or function.name == "vkAllocateMemory") and not "count" in [a.name for a in function.arguments]:
675 if function.name == "vkCreateDisplayModeKHR":
676 continue # No way to delete display modes (bug?)
678 # \todo [pyry] Rather hacky
680 if function.getType() == Function.TYPE_PLATFORM:
681 iface = Variable("const PlatformInterface&", "vk")
682 elif function.getType() == Function.TYPE_INSTANCE:
683 iface = Variable("const InstanceInterface&", "vk")
685 iface = Variable("const DeviceInterface&", "vk")
687 assert function.arguments[-2].type == "const VkAllocationCallbacks*"
689 objectType = function.arguments[-1].type.replace("*", "").strip()
690 arguments = function.arguments[:-1]
691 funcs.append(ConstructorFunction(function.getType(), getInterfaceName(function), objectType, iface, arguments))
694 def writeRefUtilProto (api, filename):
695 functions = getConstructorFunctions(api)
697 def makeRefUtilProto ():
699 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]):
702 writeInlFile(filename, INL_HEADER, makeRefUtilProto())
704 def writeRefUtilImpl (api, filename):
705 functions = getConstructorFunctions(api)
707 def makeRefUtilImpl ():
708 yield "namespace refdetails"
712 for function in api.functions:
713 if function.getType() == Function.TYPE_DEVICE \
714 and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \
715 and not function.name == "vkDestroyDevice":
716 objectType = function.arguments[-2].type
718 yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType)
720 yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function))
724 yield "} // refdetails"
727 for function in functions:
728 if function.type == Function.TYPE_DEVICE:
730 elif function.type == Function.TYPE_INSTANCE:
731 if function.name == "createDevice":
738 yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments))
740 yield "\t%s object = 0;" % function.objectType
741 yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"]))
742 yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name]))
746 writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
748 def writeNullDriverImpl (api, filename):
749 def genNullDriverImpl ():
751 "vkCreateGraphicsPipelines",
752 "vkCreateComputePipelines",
753 "vkGetInstanceProcAddr",
754 "vkGetDeviceProcAddr",
755 "vkEnumeratePhysicalDevices",
756 "vkGetPhysicalDeviceFeatures",
757 "vkGetPhysicalDeviceProperties",
758 "vkGetPhysicalDeviceQueueFamilyProperties",
759 "vkGetPhysicalDeviceMemoryProperties",
760 "vkGetPhysicalDeviceFormatProperties",
761 "vkGetPhysicalDeviceImageFormatProperties",
763 "vkGetBufferMemoryRequirements",
764 "vkGetImageMemoryRequirements",
766 "vkAllocateDescriptorSets",
767 "vkFreeDescriptorSets",
768 "vkResetDescriptorPool",
769 "vkAllocateCommandBuffers",
770 "vkFreeCommandBuffers",
771 "vkCreateDisplayModeKHR",
772 "vkCreateSharedSwapchainsKHR",
774 specialFuncs = [f for f in api.functions if f.name in specialFuncNames]
775 createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs]
776 destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs]
777 dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs]
779 def getHandle (name):
780 for handle in api.handles:
781 if handle.name == name:
783 raise Exception("No such handle: %s" % name)
785 for function in createFuncs:
786 objectType = function.arguments[-1].type.replace("*", "").strip()
787 argsStr = ", ".join([a.name for a in function.arguments[:-1]])
789 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
791 yield "\tDE_UNREF(%s);" % function.arguments[-2].name
793 if getHandle(objectType).type == Handle.TYPE_NONDISP:
794 yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
796 yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
801 for function in destroyFuncs:
802 objectArg = function.arguments[-2]
804 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
806 for arg in function.arguments[:-2]:
807 yield "\tDE_UNREF(%s);" % arg.name
809 if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
810 yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
812 yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
817 for function in dummyFuncs:
818 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
820 for arg in function.arguments:
821 yield "\tDE_UNREF(%s);" % arg.name
822 if function.returnType != "void":
823 yield "\treturn VK_SUCCESS;"
827 def genFuncEntryTable (type, name):
828 funcs = [f for f in api.functions if f.getType() == type]
830 yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name
832 for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]):
838 for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"):
841 for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"):
844 for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"):
848 writeInlFile(filename, INL_HEADER, genNullDriverImpl())
850 def writeTypeUtil (api, filename):
851 # Structs filled by API queries are not often used in test code
852 QUERY_RESULT_TYPES = set([
853 "VkPhysicalDeviceFeatures",
854 "VkPhysicalDeviceLimits",
855 "VkFormatProperties",
856 "VkImageFormatProperties",
857 "VkPhysicalDeviceSparseProperties",
858 "VkQueueFamilyProperties",
862 COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
864 def isSimpleStruct (type):
865 def hasArrayMember (type):
866 for member in type.members:
867 if "[" in member.name:
871 def hasCompositeMember (type):
872 for member in type.members:
873 if member.type in COMPOSITE_TYPES:
877 return type.typeClass == CompositeType.CLASS_STRUCT and \
878 type.members[0].type != "VkStructureType" and \
879 not type.name in QUERY_RESULT_TYPES and \
880 not hasArrayMember(type) and \
881 not hasCompositeMember(type)
884 for type in api.compositeTypes:
885 if not isSimpleStruct(type):
889 yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
891 yield "\t%s res;" % type.name
892 for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
894 yield "\treturn res;"
897 writeInlFile(filename, INL_HEADER, gen())
899 if __name__ == "__main__":
900 src = readFile(sys.argv[1])
902 platformFuncs = set([Function.TYPE_PLATFORM])
903 instanceFuncs = set([Function.TYPE_INSTANCE])
904 deviceFuncs = set([Function.TYPE_DEVICE])
906 writeHandleType (api, os.path.join(VULKAN_DIR, "vkHandleType.inl"))
907 writeBasicTypes (api, os.path.join(VULKAN_DIR, "vkBasicTypes.inl"))
908 writeCompositeTypes (api, os.path.join(VULKAN_DIR, "vkStructTypes.inl"))
909 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualPlatformInterface.inl"), functionTypes = platformFuncs, concrete = False)
910 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = False)
911 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = False)
912 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcretePlatformInterface.inl"), functionTypes = platformFuncs, concrete = True)
913 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = True)
914 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = True)
915 writeFunctionPtrTypes (api, os.path.join(VULKAN_DIR, "vkFunctionPointerTypes.inl"))
916 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
917 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
918 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
919 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
920 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
921 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
922 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkPlatformDriverImpl.inl"), functionTypes = platformFuncs, className = "PlatformDriver")
923 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkInstanceDriverImpl.inl"), functionTypes = instanceFuncs, className = "InstanceDriver")
924 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkDeviceDriverImpl.inl"), functionTypes = deviceFuncs, className = "DeviceDriver")
925 writeStrUtilProto (api, os.path.join(VULKAN_DIR, "vkStrUtil.inl"))
926 writeStrUtilImpl (api, os.path.join(VULKAN_DIR, "vkStrUtilImpl.inl"))
927 writeRefUtilProto (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
928 writeRefUtilImpl (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
929 writeNullDriverImpl (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
930 writeTypeUtil (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))