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",
108 ("VK_API_VERSION", "deUint32"),
109 ("VK_MAX_PHYSICAL_DEVICE_NAME_SIZE", "size_t"),
110 ("VK_MAX_EXTENSION_NAME_SIZE", "size_t"),
111 ("VK_UUID_SIZE", "size_t"),
112 ("VK_MAX_MEMORY_TYPES", "size_t"),
113 ("VK_MAX_MEMORY_HEAPS", "size_t"),
114 ("VK_MAX_DESCRIPTION_SIZE", "size_t"),
115 ("VK_ATTACHMENT_UNUSED", "deUint32"),
116 ("VK_SUBPASS_EXTERNAL", "deUint32"),
117 ("VK_QUEUE_FAMILY_IGNORED", "deUint32"),
118 ("VK_REMAINING_MIP_LEVELS", "deUint32"),
119 ("VK_REMAINING_ARRAY_LAYERS", "deUint32"),
120 ("VK_WHOLE_SIZE", "vk::VkDeviceSize"),
121 ("VK_TRUE", "vk::VkBool32"),
122 ("VK_FALSE", "vk::VkBool32"),
126 # VK_KHR_xlib_surface
127 ("Display*", "XlibDisplayPtr", "void*"),
128 ("Window", "XlibWindow", "deUintptr",),
129 ("VisualID", "XlibVisualID", "deUint32"),
132 ("xcb_connection_t*", "XcbConnectionPtr", "void*"),
133 ("xcb_window_t", "XcbWindow", "deUintptr"),
134 ("xcb_visualid_t", "XcbVisualid", "deUint32"),
136 # VK_KHR_wayland_surface
137 ("struct wl_display*", "WaylandDisplayPtr", "void*"),
138 ("struct wl_surface*", "WaylandSurfacePtr", "void*"),
141 ("MirConnection*", "MirConnectionPtr", "void*"),
142 ("MirSurface*", "MirSurfacePtr", "void*"),
144 # VK_KHR_android_surface
145 ("ANativeWindow*", "AndroidNativeWindowPtr", "void*"),
147 # VK_KHR_win32_surface
148 ("HINSTANCE", "Win32InstanceHandle", "void*"),
149 ("HWND", "Win32WindowHandle", "void*")
151 PLATFORM_TYPE_NAMESPACE = "pt"
157 def __init__ (self, type, name):
161 def getHandleType (self):
162 name = re.sub(r'([a-z])([A-Z])', r'\1_\2', self.name)
163 return "HANDLE_TYPE_" + name[3:].upper()
166 def __init__ (self, name, values):
171 def __init__ (self, name, values):
176 def __init__ (self, type, name, arraySize = None):
179 self.arraySize = arraySize
185 def __init__ (self, typeClass, name, members):
186 self.typeClass = typeClass
188 self.members = members
190 def getClassName (self):
191 names = {CompositeType.CLASS_STRUCT: 'struct', CompositeType.CLASS_UNION: 'union'}
192 return names[self.typeClass]
195 TYPE_PLATFORM = 0 # Not bound to anything
196 TYPE_INSTANCE = 1 # Bound to VkInstance
197 TYPE_DEVICE = 2 # Bound to VkDevice
199 def __init__ (self, name, returnType, arguments):
201 self.returnType = returnType
202 self.arguments = arguments
205 if self.name in PLATFORM_FUNCTIONS:
206 return Function.TYPE_PLATFORM
207 elif self.name in INSTANCE_FUNCTIONS:
208 return Function.TYPE_INSTANCE
210 return Function.TYPE_DEVICE
213 def __init__ (self, definitions, handles, enums, bitfields, compositeTypes, functions):
214 self.definitions = definitions
215 self.handles = handles
217 self.bitfields = bitfields
218 self.compositeTypes = compositeTypes
219 self.functions = functions
221 def readFile (filename):
222 with open(filename, 'rb') as f:
225 IDENT_PTRN = r'[a-zA-Z_][a-zA-Z0-9_]*'
226 TYPE_PTRN = r'[a-zA-Z_][a-zA-Z0-9_ \t*]*'
228 def fixupEnumValues (values):
230 for name, value in values:
231 if "_BEGIN_RANGE" in name or "_END_RANGE" in name:
233 fixed.append((name, value))
236 def fixupType (type):
237 for platformType, substitute, compat in PLATFORM_TYPES:
238 if type == platformType:
239 return PLATFORM_TYPE_NAMESPACE + "::" + substitute
242 ("uint8_t", "deUint8"),
243 ("uint16_t", "deUint16"),
244 ("uint32_t", "deUint32"),
245 ("uint64_t", "deUint64"),
246 ("int8_t", "deInt8"),
247 ("int16_t", "deInt16"),
248 ("int32_t", "deInt32"),
249 ("int64_t", "deInt64"),
250 ("bool32_t", "deUint32"),
251 ("size_t", "deUintptr"),
254 for src, dst in replacements:
255 type = type.replace(src, dst)
259 def fixupFunction (function):
260 fixedArgs = [Variable(fixupType(a.type), a.name, a.arraySize) for a in function.arguments]
261 fixedReturnType = fixupType(function.returnType)
263 return Function(function.name, fixedReturnType, fixedArgs)
265 def getInterfaceName (function):
266 assert function.name[:2] == "vk"
267 return function.name[2].lower() + function.name[3:]
269 def getFunctionTypeName (function):
270 assert function.name[:2] == "vk"
271 return function.name[2:] + "Func"
273 def endsWith (str, postfix):
274 return str[-len(postfix):] == postfix
276 def splitNameExtPostfix (name):
277 knownExtPostfixes = ["KHR", "EXT"]
278 for postfix in knownExtPostfixes:
279 if endsWith(name, postfix):
280 return (name[:-len(postfix)], postfix)
283 def getBitEnumNameForBitfield (bitfieldName):
284 bitfieldName, postfix = splitNameExtPostfix(bitfieldName)
286 assert bitfieldName[-1] == "s"
287 return bitfieldName[:-1] + "Bits" + postfix
289 def getBitfieldNameForBitEnum (bitEnumName):
290 bitEnumName, postfix = splitNameExtPostfix(bitEnumName)
292 assert bitEnumName[-4:] == "Bits"
293 return bitEnumName[:-4] + "s" + postfix
295 def parsePreprocDefinedValue (src, name):
296 definition = re.search(r'#\s*define\s+' + name + r'\s+([^\n]+)\n', src)
297 if definition is None:
298 raise Exception("No such definition: %s" % name)
299 value = definition.group(1).strip()
301 if value == "UINT32_MAX":
306 def parseEnum (name, src):
307 keyValuePtrn = '(' + IDENT_PTRN + r')\s*=\s*([^\s,}]+)\s*[,}]'
308 matches = re.findall(keyValuePtrn, src)
310 return Enum(name, fixupEnumValues(matches))
312 # \note Parses raw enums, some are mapped to bitfields later
313 def parseEnums (src):
314 matches = re.findall(r'typedef enum(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
317 for enumname, contents, typename in matches:
318 enums.append(parseEnum(typename, contents))
322 def parseCompositeType (type, name, src):
323 # \todo [pyry] Array support is currently a hack (size coupled with name)
324 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r'(\[[^\]]+\])*)\s*;'
325 matches = re.findall(typeNamePtrn, src)
326 members = [Variable(fixupType(t.strip()), n.strip()) for t, n, a in matches]
328 return CompositeType(type, name, members)
330 def parseCompositeTypes (src):
331 typeMap = { 'struct': CompositeType.CLASS_STRUCT, 'union': CompositeType.CLASS_UNION }
332 matches = re.findall(r'typedef (struct|union)(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
335 for type, structname, contents, typename in matches:
336 types.append(parseCompositeType(typeMap[type], typename, contents))
340 def parseHandles (src):
341 matches = re.findall(r'VK_DEFINE(_NON_DISPATCHABLE|)_HANDLE\((' + IDENT_PTRN + r')\)[ \t]*[\n\r]', src)
343 typeMap = {'': Handle.TYPE_DISP, '_NON_DISPATCHABLE': Handle.TYPE_NONDISP}
345 for type, name in matches:
346 handle = Handle(typeMap[type], name)
347 handles.append(handle)
351 def parseArgList (src):
352 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r')(\[[^\]]+\])?'
355 for rawArg in src.split(','):
356 m = re.search(typeNamePtrn, rawArg)
357 args.append(Variable(m.group(1).strip(), m.group(2).strip(), m.group(3)))
361 def parseFunctions (src):
362 ptrn = r'VKAPI_ATTR\s+(' + TYPE_PTRN + ')VKAPI_CALL\s+(' + IDENT_PTRN + r')\s*\(([^)]*)\)\s*;'
363 matches = re.findall(ptrn, src)
366 for returnType, name, argList in matches:
367 functions.append(Function(name.strip(), returnType.strip(), parseArgList(argList)))
369 return [fixupFunction(f) for f in functions]
371 def parseBitfieldNames (src):
372 ptrn = r'typedef\s+VkFlags\s(' + IDENT_PTRN + r')\s*;'
373 matches = re.findall(ptrn, src)
378 definitions = [(name, type, parsePreprocDefinedValue(src, name)) for name, type in DEFINITIONS]
379 rawEnums = parseEnums(src)
380 bitfieldNames = parseBitfieldNames(src)
383 bitfieldEnums = set([getBitEnumNameForBitfield(n) for n in bitfieldNames])
385 for enum in rawEnums:
386 if enum.name in bitfieldEnums:
387 bitfields.append(Bitfield(getBitfieldNameForBitEnum(enum.name), enum.values))
391 for bitfieldName in bitfieldNames:
392 if not bitfieldName in [bitfield.name for bitfield in bitfields]:
394 bitfields.append(Bitfield(bitfieldName, []))
397 definitions = definitions,
398 handles = parseHandles(src),
400 bitfields = bitfields,
401 compositeTypes = parseCompositeTypes(src),
402 functions = parseFunctions(src))
404 def writeHandleType (api, filename):
406 yield "enum HandleType"
408 yield "\t%s = 0," % api.handles[0].getHandleType()
409 for handle in api.handles[1:]:
410 yield "\t%s," % handle.getHandleType()
411 yield "\tHANDLE_TYPE_LAST"
415 writeInlFile(filename, INL_HEADER, gen())
417 def getEnumValuePrefix (enum):
418 prefix = enum.name[0]
419 for i in range(1, len(enum.name)):
420 if enum.name[i].isupper() and not enum.name[i-1].isupper():
422 prefix += enum.name[i].upper()
425 def parseInt (value):
426 if value[:2] == "0x":
427 return int(value, 16)
429 return int(value, 10)
431 def areEnumValuesLinear (enum):
433 for name, value in enum.values:
434 if parseInt(value) != curIndex:
439 def genEnumSrc (enum):
440 yield "enum %s" % enum.name
443 for line in indentLines(["\t%s\t= %s," % v for v in enum.values]):
446 if areEnumValuesLinear(enum):
448 yield "\t%s_LAST" % getEnumValuePrefix(enum)
452 def genBitfieldSrc (bitfield):
453 if len(bitfield.values) > 0:
454 yield "enum %s" % getBitEnumNameForBitfield(bitfield.name)
456 for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]):
460 yield "typedef deUint32 %s;" % bitfield.name
462 def genCompositeTypeSrc (type):
463 yield "%s %s" % (type.getClassName(), type.name)
465 for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]):
469 def genHandlesSrc (handles):
470 def genLines (handles):
471 for handle in handles:
472 if handle.type == Handle.TYPE_DISP:
473 yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
474 elif handle.type == Handle.TYPE_NONDISP:
475 yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
477 for line in indentLines(genLines(handles)):
480 def writeBasicTypes (api, filename):
482 for line in indentLines(["#define %s\t(static_cast<%s>\t(%s))" % (name, type, value) for name, type, value in api.definitions]):
485 for line in genHandlesSrc(api.handles):
488 for enum in api.enums:
489 for line in genEnumSrc(enum):
492 for bitfield in api.bitfields:
493 for line in genBitfieldSrc(bitfield):
496 for line in indentLines(["VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES]):
499 writeInlFile(filename, INL_HEADER, gen())
501 def writeCompositeTypes (api, filename):
503 for type in api.compositeTypes:
504 for line in genCompositeTypeSrc(type):
508 writeInlFile(filename, INL_HEADER, gen())
510 def argListToStr (args):
511 return ", ".join("%s %s%s" % (v.type, v.name, v.arraySize if v.arraySize != None else "") for v in args)
513 def writeInterfaceDecl (api, filename, functionTypes, concrete):
515 postfix = "" if concrete else " = 0"
516 for function in api.functions:
517 if function.getType() in functionTypes:
518 yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix)
520 writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
522 def writeFunctionPtrTypes (api, filename):
524 for function in api.functions:
525 yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments))
527 writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
529 def writeFunctionPointers (api, filename, functionTypes):
530 writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
532 def writeInitFunctionPointers (api, filename, functionTypes):
533 def makeInitFunctionPointers ():
534 for function in api.functions:
535 if function.getType() in functionTypes:
536 yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name)
538 writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
540 def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className):
541 def makeFuncPtrInterfaceImpl ():
542 for function in api.functions:
543 if function.getType() in functionTypes:
545 yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments))
547 yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments))
550 writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
552 def writeStrUtilProto (api, filename):
553 def makeStrUtilProto ():
554 for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]):
557 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]):
560 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]):
563 for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]):
566 for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]):
569 writeInlFile(filename, INL_HEADER, makeStrUtilProto())
571 def writeStrUtilImpl (api, filename):
572 def makeStrUtilImpl ():
573 for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]):
577 yield "namespace %s" % PLATFORM_TYPE_NAMESPACE
580 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):
585 for enum in api.enums:
587 yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name)
589 yield "\tswitch (value)"
591 for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]):
596 for bitfield in api.bitfields:
598 yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name)
601 if len(bitfield.values) > 0:
602 yield "\tstatic const tcu::Format::BitDesc s_desc[] ="
604 for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]):
607 yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));"
609 yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);"
613 bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
615 for type in api.compositeTypes:
617 yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name
619 yield "\ts << \"%s = {\\n\";" % type.name
620 for member in type.members:
621 memberName = member.name
624 if member.type in bitfieldTypeNames:
625 valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name)
626 elif member.type == "const char*" or member.type == "char*":
627 valFmt = "getCharPtrStr(value.%s)" % member.name
628 elif '[' in member.name:
629 baseName = member.name[:member.name.find('[')]
630 if baseName in ["extensionName", "deviceName", "layerName", "description"]:
631 valFmt = "(const char*)value.%s" % baseName
632 elif member.type == 'char' or member.type == 'deUint8':
633 newLine = "'\\n' << "
634 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)
636 if baseName == "memoryTypes" or baseName == "memoryHeaps":
637 endIter = "DE_ARRAY_BEGIN(value.%s) + value.%sCount" % (baseName, baseName[:-1])
639 endIter = "DE_ARRAY_END(value.%s)" % baseName
640 newLine = "'\\n' << "
641 valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)" % (baseName, endIter)
642 memberName = baseName
644 valFmt = "value.%s" % member.name
645 yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';"
651 writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
653 class ConstructorFunction:
654 def __init__ (self, type, name, objectType, iface, arguments):
657 self.objectType = objectType
659 self.arguments = arguments
661 def getConstructorFunctions (api):
663 for function in api.functions:
664 if (function.name[:8] == "vkCreate" or function.name == "vkAllocateMemory") and not "count" in [a.name for a in function.arguments]:
665 if function.name == "vkCreateDisplayModeKHR":
666 continue # No way to delete display modes (bug?)
668 # \todo [pyry] Rather hacky
670 if function.getType() == Function.TYPE_PLATFORM:
671 iface = Variable("const PlatformInterface&", "vk")
672 elif function.getType() == Function.TYPE_INSTANCE:
673 iface = Variable("const InstanceInterface&", "vk")
675 iface = Variable("const DeviceInterface&", "vk")
677 assert function.arguments[-2].type == "const VkAllocationCallbacks*"
679 objectType = function.arguments[-1].type.replace("*", "").strip()
680 arguments = function.arguments[:-1]
681 funcs.append(ConstructorFunction(function.getType(), getInterfaceName(function), objectType, iface, arguments))
684 def writeRefUtilProto (api, filename):
685 functions = getConstructorFunctions(api)
687 def makeRefUtilProto ():
689 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]):
692 writeInlFile(filename, INL_HEADER, makeRefUtilProto())
694 def writeRefUtilImpl (api, filename):
695 functions = getConstructorFunctions(api)
697 def makeRefUtilImpl ():
698 yield "namespace refdetails"
702 for function in api.functions:
703 if function.getType() == Function.TYPE_DEVICE \
704 and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \
705 and not function.name == "vkDestroyDevice":
706 objectType = function.arguments[-2].type
708 yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType)
710 yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function))
714 yield "} // refdetails"
717 for function in functions:
718 if function.type == Function.TYPE_DEVICE:
720 elif function.type == Function.TYPE_INSTANCE:
721 if function.name == "createDevice":
728 yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments))
730 yield "\t%s object = 0;" % function.objectType
731 yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"]))
732 yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name]))
736 writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
738 def writeNullDriverImpl (api, filename):
739 def genNullDriverImpl ():
741 "vkCreateGraphicsPipelines",
742 "vkCreateComputePipelines",
743 "vkGetInstanceProcAddr",
744 "vkGetDeviceProcAddr",
745 "vkEnumeratePhysicalDevices",
746 "vkGetPhysicalDeviceFeatures",
747 "vkGetPhysicalDeviceProperties",
748 "vkGetPhysicalDeviceQueueFamilyProperties",
749 "vkGetPhysicalDeviceMemoryProperties",
750 "vkGetPhysicalDeviceFormatProperties",
751 "vkGetPhysicalDeviceImageFormatProperties",
753 "vkGetBufferMemoryRequirements",
754 "vkGetImageMemoryRequirements",
756 "vkAllocateDescriptorSets",
757 "vkFreeDescriptorSets",
758 "vkResetDescriptorPool",
759 "vkAllocateCommandBuffers",
760 "vkFreeCommandBuffers",
761 "vkCreateDisplayModeKHR",
762 "vkCreateSharedSwapchainsKHR",
764 specialFuncs = [f for f in api.functions if f.name in specialFuncNames]
765 createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs]
766 destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs]
767 dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs]
769 def getHandle (name):
770 for handle in api.handles:
771 if handle.name == name:
773 raise Exception("No such handle: %s" % name)
775 for function in createFuncs:
776 objectType = function.arguments[-1].type.replace("*", "").strip()
777 argsStr = ", ".join([a.name for a in function.arguments[:-1]])
779 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
781 yield "\tDE_UNREF(%s);" % function.arguments[-2].name
783 if getHandle(objectType).type == Handle.TYPE_NONDISP:
784 yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
786 yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
791 for function in destroyFuncs:
792 objectArg = function.arguments[-2]
794 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
796 for arg in function.arguments[:-2]:
797 yield "\tDE_UNREF(%s);" % arg.name
799 if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
800 yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
802 yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
807 for function in dummyFuncs:
808 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
810 for arg in function.arguments:
811 yield "\tDE_UNREF(%s);" % arg.name
812 if function.returnType != "void":
813 yield "\treturn VK_SUCCESS;"
817 def genFuncEntryTable (type, name):
818 funcs = [f for f in api.functions if f.getType() == type]
820 yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name
822 for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]):
828 for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"):
831 for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"):
834 for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"):
838 writeInlFile(filename, INL_HEADER, genNullDriverImpl())
840 def writeTypeUtil (api, filename):
841 # Structs filled by API queries are not often used in test code
842 QUERY_RESULT_TYPES = set([
843 "VkPhysicalDeviceFeatures",
844 "VkPhysicalDeviceLimits",
845 "VkFormatProperties",
846 "VkImageFormatProperties",
847 "VkPhysicalDeviceSparseProperties",
848 "VkQueueFamilyProperties",
852 COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
854 def isSimpleStruct (type):
855 def hasArrayMember (type):
856 for member in type.members:
857 if "[" in member.name:
861 def hasCompositeMember (type):
862 for member in type.members:
863 if member.type in COMPOSITE_TYPES:
867 return type.typeClass == CompositeType.CLASS_STRUCT and \
868 type.members[0].type != "VkStructureType" and \
869 not type.name in QUERY_RESULT_TYPES and \
870 not hasArrayMember(type) and \
871 not hasCompositeMember(type)
874 for type in api.compositeTypes:
875 if not isSimpleStruct(type):
879 yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
881 yield "\t%s res;" % type.name
882 for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
884 yield "\treturn res;"
887 writeInlFile(filename, INL_HEADER, gen())
889 if __name__ == "__main__":
890 src = readFile(sys.argv[1])
892 platformFuncs = set([Function.TYPE_PLATFORM])
893 instanceFuncs = set([Function.TYPE_INSTANCE])
894 deviceFuncs = set([Function.TYPE_DEVICE])
896 writeHandleType (api, os.path.join(VULKAN_DIR, "vkHandleType.inl"))
897 writeBasicTypes (api, os.path.join(VULKAN_DIR, "vkBasicTypes.inl"))
898 writeCompositeTypes (api, os.path.join(VULKAN_DIR, "vkStructTypes.inl"))
899 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualPlatformInterface.inl"), functionTypes = platformFuncs, concrete = False)
900 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = False)
901 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = False)
902 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcretePlatformInterface.inl"), functionTypes = platformFuncs, concrete = True)
903 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = True)
904 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = True)
905 writeFunctionPtrTypes (api, os.path.join(VULKAN_DIR, "vkFunctionPointerTypes.inl"))
906 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
907 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
908 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
909 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
910 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
911 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
912 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkPlatformDriverImpl.inl"), functionTypes = platformFuncs, className = "PlatformDriver")
913 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkInstanceDriverImpl.inl"), functionTypes = instanceFuncs, className = "InstanceDriver")
914 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkDeviceDriverImpl.inl"), functionTypes = deviceFuncs, className = "DeviceDriver")
915 writeStrUtilProto (api, os.path.join(VULKAN_DIR, "vkStrUtil.inl"))
916 writeStrUtilImpl (api, os.path.join(VULKAN_DIR, "vkStrUtilImpl.inl"))
917 writeRefUtilProto (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
918 writeRefUtilImpl (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
919 writeNullDriverImpl (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
920 writeTypeUtil (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))