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_H = os.path.join(os.path.dirname(__file__), "src", "vulkan.h.in")
33 VULKAN_DIR = os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan")
36 /* WARNING: This is auto-generated file. Do not modify, since changes will
37 * be lost! Modify the generating script instead.
41 PLATFORM_FUNCTIONS = [
43 "vkGetInstanceProcAddr",
44 "vkEnumerateInstanceExtensionProperties",
45 "vkEnumerateInstanceLayerProperties",
47 INSTANCE_FUNCTIONS = [
49 "vkEnumeratePhysicalDevices",
50 "vkGetPhysicalDeviceFeatures",
51 "vkGetPhysicalDeviceFormatProperties",
52 "vkGetPhysicalDeviceImageFormatProperties",
53 "vkGetPhysicalDeviceSparseImageFormatProperties",
54 "vkGetPhysicalDeviceLimits",
55 "vkGetPhysicalDeviceProperties",
56 "vkGetPhysicalDeviceQueueFamilyProperties",
57 "vkGetPhysicalDeviceMemoryProperties",
58 "vkEnumerateDeviceExtensionProperties",
59 "vkEnumerateDeviceLayerProperties",
61 "vkGetDeviceProcAddr",
64 "vkDestroySurfaceKHR",
65 "vkGetPhysicalDeviceSurfaceSupportKHR",
66 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
67 "vkGetPhysicalDeviceSurfaceFormatsKHR",
68 "vkGetPhysicalDeviceSurfacePresentModesKHR",
71 "vkGetPhysicalDeviceDisplayPropertiesKHR",
72 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR",
73 "vkGetDisplayPlaneSupportedDisplaysKHR",
74 "vkGetDisplayModePropertiesKHR",
75 "vkCreateDisplayModeKHR",
76 "vkGetDisplayPlaneCapabilitiesKHR",
77 "vkCreateDisplayPlaneSurfaceKHR",
80 "vkCreateXlibSurfaceKHR",
81 "vkGetPhysicalDeviceXlibPresentationSupportKHR",
84 "vkCreateXcbSurfaceKHR",
85 "vkGetPhysicalDeviceXcbPresentationSupportKHR",
87 # VK_KHR_wayland_surface
88 "vkCreateWaylandSurfaceKHR",
89 "vkGetPhysicalDeviceWaylandPresentationSupportKHR",
92 "vkCreateMirSurfaceKHR",
93 "vkGetPhysicalDeviceMirPresentationSupportKHR",
95 # VK_KHR_android_surface
96 "vkCreateAndroidSurfaceKHR",
98 # VK_KHR_win32_surface
99 "vkCreateWin32SurfaceKHR",
100 "vkGetPhysicalDeviceWin32PresentationSupportKHR",
102 # VK_KHR_get_physical_device_properties2
103 "vkGetPhysicalDeviceFeatures2KHR",
104 "vkGetPhysicalDeviceProperties2KHR",
105 "vkGetPhysicalDeviceFormatProperties2KHR",
106 "vkGetPhysicalDeviceQueueFamilyProperties2KHR",
107 "vkGetPhysicalDeviceImageFormatProperties2KHR",
108 "vkGetPhysicalDeviceMemoryProperties2KHR",
109 "vkGetPhysicalDeviceSparseImageFormatProperties2KHR",
111 # VK_EXT_debug_report
112 "vkCreateDebugReportCallbackEXT",
113 "vkDestroyDebugReportCallbackEXT",
114 "vkDebugReportMessageEXT",
116 # VK_NV_external_memory_capabilities
117 "vkGetPhysicalDeviceExternalImageFormatPropertiesNV"
121 ("VK_API_VERSION", "deUint32"),
122 ("VK_MAX_PHYSICAL_DEVICE_NAME_SIZE", "size_t"),
123 ("VK_MAX_EXTENSION_NAME_SIZE", "size_t"),
124 ("VK_UUID_SIZE", "size_t"),
125 ("VK_MAX_MEMORY_TYPES", "size_t"),
126 ("VK_MAX_MEMORY_HEAPS", "size_t"),
127 ("VK_MAX_DESCRIPTION_SIZE", "size_t"),
128 ("VK_ATTACHMENT_UNUSED", "deUint32"),
129 ("VK_SUBPASS_EXTERNAL", "deUint32"),
130 ("VK_QUEUE_FAMILY_IGNORED", "deUint32"),
131 ("VK_REMAINING_MIP_LEVELS", "deUint32"),
132 ("VK_REMAINING_ARRAY_LAYERS", "deUint32"),
133 ("VK_WHOLE_SIZE", "vk::VkDeviceSize"),
134 ("VK_TRUE", "vk::VkBool32"),
135 ("VK_FALSE", "vk::VkBool32"),
139 # VK_KHR_xlib_surface
140 ("Display*", "XlibDisplayPtr", "void*"),
141 ("Window", "XlibWindow", "deUintptr",),
142 ("VisualID", "XlibVisualID", "deUint32"),
145 ("xcb_connection_t*", "XcbConnectionPtr", "void*"),
146 ("xcb_window_t", "XcbWindow", "deUintptr"),
147 ("xcb_visualid_t", "XcbVisualid", "deUint32"),
149 # VK_KHR_wayland_surface
150 ("struct wl_display*", "WaylandDisplayPtr", "void*"),
151 ("struct wl_surface*", "WaylandSurfacePtr", "void*"),
154 ("MirConnection*", "MirConnectionPtr", "void*"),
155 ("MirSurface*", "MirSurfacePtr", "void*"),
157 # VK_KHR_android_surface
158 ("ANativeWindow*", "AndroidNativeWindowPtr", "void*"),
160 # VK_KHR_win32_surface
161 ("HINSTANCE", "Win32InstanceHandle", "void*"),
162 ("HWND", "Win32WindowHandle", "void*"),
163 ("HANDLE", "Win32Handle", "void*"),
164 ("const SECURITY_ATTRIBUTES*", "Win32SecurityAttributesPtr", "const void*"),
166 PLATFORM_TYPE_NAMESPACE = "pt"
167 TYPE_SUBSTITUTIONS = [
168 ("uint8_t", "deUint8"),
169 ("uint16_t", "deUint16"),
170 ("uint32_t", "deUint32"),
171 ("uint64_t", "deUint64"),
172 ("int8_t", "deInt8"),
173 ("int16_t", "deInt16"),
174 ("int32_t", "deInt32"),
175 ("int64_t", "deInt64"),
176 ("bool32_t", "deUint32"),
177 ("size_t", "deUintptr"),
180 ("DWORD", "deUint32"),
181 ("HANDLE*", PLATFORM_TYPE_NAMESPACE + "::" + "Win32Handle*")
184 EXTENSION_POSTFIXES = ["KHR", "EXT", "NV", "NVX", "KHX"]
190 def __init__ (self, type, name):
194 def getHandleType (self):
195 name = re.sub(r'([a-z])([A-Z])', r'\1_\2', self.name)
196 return "HANDLE_TYPE_" + name[3:].upper()
199 def __init__ (self, name, values):
204 def __init__ (self, name, values):
209 def __init__ (self, type, name, arraySize = None):
212 self.arraySize = arraySize
218 def __init__ (self, typeClass, name, members):
219 self.typeClass = typeClass
221 self.members = members
223 def getClassName (self):
224 names = {CompositeType.CLASS_STRUCT: 'struct', CompositeType.CLASS_UNION: 'union'}
225 return names[self.typeClass]
228 TYPE_PLATFORM = 0 # Not bound to anything
229 TYPE_INSTANCE = 1 # Bound to VkInstance
230 TYPE_DEVICE = 2 # Bound to VkDevice
232 def __init__ (self, name, returnType, arguments):
234 self.returnType = returnType
235 self.arguments = arguments
238 if self.name in PLATFORM_FUNCTIONS:
239 return Function.TYPE_PLATFORM
240 elif self.name in INSTANCE_FUNCTIONS:
241 return Function.TYPE_INSTANCE
243 return Function.TYPE_DEVICE
246 def __init__ (self, definitions, handles, enums, bitfields, compositeTypes, functions):
247 self.definitions = definitions
248 self.handles = handles
250 self.bitfields = bitfields
251 self.compositeTypes = compositeTypes
252 self.functions = functions
254 def readFile (filename):
255 with open(filename, 'rb') as f:
258 IDENT_PTRN = r'[a-zA-Z_][a-zA-Z0-9_]*'
259 TYPE_PTRN = r'[a-zA-Z_][a-zA-Z0-9_ \t*]*'
261 def fixupEnumValues (values):
263 for name, value in values:
264 if "_BEGIN_RANGE" in name or "_END_RANGE" in name:
266 fixed.append((name, value))
269 def fixupType (type):
270 for platformType, substitute, compat in PLATFORM_TYPES:
271 if type == platformType:
272 return PLATFORM_TYPE_NAMESPACE + "::" + substitute
274 for src, dst in TYPE_SUBSTITUTIONS:
275 type = type.replace(src, dst)
279 def fixupFunction (function):
280 fixedArgs = [Variable(fixupType(a.type), a.name, a.arraySize) for a in function.arguments]
281 fixedReturnType = fixupType(function.returnType)
283 return Function(function.name, fixedReturnType, fixedArgs)
285 def getInterfaceName (function):
286 assert function.name[:2] == "vk"
287 return function.name[2].lower() + function.name[3:]
289 def getFunctionTypeName (function):
290 assert function.name[:2] == "vk"
291 return function.name[2:] + "Func"
293 def endsWith (str, postfix):
294 return str[-len(postfix):] == postfix
296 def splitNameExtPostfix (name):
297 knownExtPostfixes = EXTENSION_POSTFIXES
298 for postfix in knownExtPostfixes:
299 if endsWith(name, postfix):
300 return (name[:-len(postfix)], postfix)
303 def getBitEnumNameForBitfield (bitfieldName):
304 bitfieldName, postfix = splitNameExtPostfix(bitfieldName)
306 assert bitfieldName[-1] == "s"
307 return bitfieldName[:-1] + "Bits" + postfix
309 def getBitfieldNameForBitEnum (bitEnumName):
310 bitEnumName, postfix = splitNameExtPostfix(bitEnumName)
312 assert bitEnumName[-4:] == "Bits"
313 return bitEnumName[:-4] + "s" + postfix
315 def parsePreprocDefinedValue (src, name):
316 definition = re.search(r'#\s*define\s+' + name + r'\s+([^\n]+)\n', src)
317 if definition is None:
318 raise Exception("No such definition: %s" % name)
319 value = definition.group(1).strip()
321 if value == "UINT32_MAX":
326 def parseEnum (name, src):
327 keyValuePtrn = '(' + IDENT_PTRN + r')\s*=\s*([^\s,}]+)\s*[,}]'
328 matches = re.findall(keyValuePtrn, src)
330 return Enum(name, fixupEnumValues(matches))
332 # \note Parses raw enums, some are mapped to bitfields later
333 def parseEnums (src):
334 matches = re.findall(r'typedef enum(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
337 for enumname, contents, typename in matches:
338 enums.append(parseEnum(typename, contents))
342 def parseCompositeType (type, name, src):
343 # \todo [pyry] Array support is currently a hack (size coupled with name)
344 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r'(\[[^\]]+\])*)\s*;'
345 matches = re.findall(typeNamePtrn, src)
346 members = [Variable(fixupType(t.strip()), n.strip()) for t, n, a in matches]
348 return CompositeType(type, name, members)
350 def parseCompositeTypes (src):
351 typeMap = { 'struct': CompositeType.CLASS_STRUCT, 'union': CompositeType.CLASS_UNION }
352 matches = re.findall(r'typedef (struct|union)(\s*' + IDENT_PTRN + r')?\s*{([^}]*)}\s*(' + IDENT_PTRN + r')\s*;', src)
355 for type, structname, contents, typename in matches:
356 types.append(parseCompositeType(typeMap[type], typename, contents))
360 def parseHandles (src):
361 matches = re.findall(r'VK_DEFINE(_NON_DISPATCHABLE|)_HANDLE\((' + IDENT_PTRN + r')\)[ \t]*[\n\r]', src)
363 typeMap = {'': Handle.TYPE_DISP, '_NON_DISPATCHABLE': Handle.TYPE_NONDISP}
365 for type, name in matches:
366 handle = Handle(typeMap[type], name)
367 handles.append(handle)
371 def parseArgList (src):
372 typeNamePtrn = r'(' + TYPE_PTRN + ')(\s' + IDENT_PTRN + r')(\[[^\]]+\])?'
375 for rawArg in src.split(','):
376 m = re.search(typeNamePtrn, rawArg)
377 args.append(Variable(m.group(1).strip(), m.group(2).strip(), m.group(3)))
381 def parseFunctions (src):
382 ptrn = r'VKAPI_ATTR\s+(' + TYPE_PTRN + ')VKAPI_CALL\s+(' + IDENT_PTRN + r')\s*\(([^)]*)\)\s*;'
383 matches = re.findall(ptrn, src)
386 for returnType, name, argList in matches:
387 functions.append(Function(name.strip(), returnType.strip(), parseArgList(argList)))
389 return [fixupFunction(f) for f in functions]
391 def parseBitfieldNames (src):
392 ptrn = r'typedef\s+VkFlags\s(' + IDENT_PTRN + r')\s*;'
393 matches = re.findall(ptrn, src)
398 definitions = [(name, type, parsePreprocDefinedValue(src, name)) for name, type in DEFINITIONS]
399 rawEnums = parseEnums(src)
400 bitfieldNames = parseBitfieldNames(src)
403 bitfieldEnums = set([getBitEnumNameForBitfield(n) for n in bitfieldNames])
405 for enum in rawEnums:
406 if enum.name in bitfieldEnums:
407 bitfields.append(Bitfield(getBitfieldNameForBitEnum(enum.name), enum.values))
411 for bitfieldName in bitfieldNames:
412 if not bitfieldName in [bitfield.name for bitfield in bitfields]:
414 bitfields.append(Bitfield(bitfieldName, []))
417 definitions = definitions,
418 handles = parseHandles(src),
420 bitfields = bitfields,
421 compositeTypes = parseCompositeTypes(src),
422 functions = parseFunctions(src))
424 def writeHandleType (api, filename):
426 yield "enum HandleType"
428 yield "\t%s = 0," % api.handles[0].getHandleType()
429 for handle in api.handles[1:]:
430 yield "\t%s," % handle.getHandleType()
431 yield "\tHANDLE_TYPE_LAST"
435 writeInlFile(filename, INL_HEADER, gen())
437 def getEnumValuePrefix (enum):
438 prefix = enum.name[0]
439 for i in range(1, len(enum.name)):
440 if enum.name[i].isupper() and not enum.name[i-1].isupper():
442 prefix += enum.name[i].upper()
445 def parseInt (value):
446 if value[:2] == "0x":
447 return int(value, 16)
449 return int(value, 10)
451 def areEnumValuesLinear (enum):
453 for name, value in enum.values:
454 if parseInt(value) != curIndex:
459 def genEnumSrc (enum):
460 yield "enum %s" % enum.name
463 for line in indentLines(["\t%s\t= %s," % v for v in enum.values]):
466 if areEnumValuesLinear(enum):
468 yield "\t%s_LAST" % getEnumValuePrefix(enum)
472 def genBitfieldSrc (bitfield):
473 if len(bitfield.values) > 0:
474 yield "enum %s" % getBitEnumNameForBitfield(bitfield.name)
476 for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]):
480 yield "typedef deUint32 %s;" % bitfield.name
482 def genCompositeTypeSrc (type):
483 yield "%s %s" % (type.getClassName(), type.name)
485 for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]):
489 def genHandlesSrc (handles):
490 def genLines (handles):
491 for handle in handles:
492 if handle.type == Handle.TYPE_DISP:
493 yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
494 elif handle.type == Handle.TYPE_NONDISP:
495 yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType())
497 for line in indentLines(genLines(handles)):
500 def writeBasicTypes (api, filename):
502 for line in indentLines(["#define %s\t(static_cast<%s>\t(%s))" % (name, type, value) for name, type, value in api.definitions]):
505 for line in genHandlesSrc(api.handles):
508 for enum in api.enums:
509 for line in genEnumSrc(enum):
512 for bitfield in api.bitfields:
513 for line in genBitfieldSrc(bitfield):
516 for line in indentLines(["VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES]):
519 writeInlFile(filename, INL_HEADER, gen())
521 def writeCompositeTypes (api, filename):
523 for type in api.compositeTypes:
524 for line in genCompositeTypeSrc(type):
528 writeInlFile(filename, INL_HEADER, gen())
530 def argListToStr (args):
531 return ", ".join("%s %s%s" % (v.type, v.name, v.arraySize if v.arraySize != None else "") for v in args)
533 def writeInterfaceDecl (api, filename, functionTypes, concrete):
535 postfix = "" if concrete else " = 0"
536 for function in api.functions:
537 if function.getType() in functionTypes:
538 yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix)
540 writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
542 def writeFunctionPtrTypes (api, filename):
544 for function in api.functions:
545 yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments))
547 writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
549 def writeFunctionPointers (api, filename, functionTypes):
550 writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
552 def writeInitFunctionPointers (api, filename, functionTypes, cond = None):
553 def makeInitFunctionPointers ():
554 for function in api.functions:
555 if function.getType() in functionTypes and (cond == None or cond(function)):
556 yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name)
558 writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
560 def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className):
561 def makeFuncPtrInterfaceImpl ():
562 for function in api.functions:
563 if function.getType() in functionTypes:
565 yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments))
567 yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments))
570 writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
572 def writeStrUtilProto (api, filename):
573 def makeStrUtilProto ():
574 for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]):
577 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]):
580 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]):
583 for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]):
586 for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]):
589 writeInlFile(filename, INL_HEADER, makeStrUtilProto())
591 def writeStrUtilImpl (api, filename):
592 def makeStrUtilImpl ():
593 for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]):
597 yield "namespace %s" % PLATFORM_TYPE_NAMESPACE
600 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):
605 for enum in api.enums:
607 yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name)
609 yield "\tswitch (value)"
611 for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]):
616 for bitfield in api.bitfields:
618 yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name)
621 if len(bitfield.values) > 0:
622 yield "\tstatic const tcu::Format::BitDesc s_desc[] ="
624 for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]):
627 yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));"
629 yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);"
633 bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields])
635 for type in api.compositeTypes:
637 yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name
639 yield "\ts << \"%s = {\\n\";" % type.name
640 for member in type.members:
641 memberName = member.name
644 if member.type in bitfieldTypeNames:
645 valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name)
646 elif member.type == "const char*" or member.type == "char*":
647 valFmt = "getCharPtrStr(value.%s)" % member.name
648 elif '[' in member.name:
649 baseName = member.name[:member.name.find('[')]
650 if baseName in ["extensionName", "deviceName", "layerName", "description"]:
651 valFmt = "(const char*)value.%s" % baseName
652 elif member.type == 'char' or member.type == 'deUint8':
653 newLine = "'\\n' << "
654 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)
656 if baseName == "memoryTypes" or baseName == "memoryHeaps":
657 endIter = "DE_ARRAY_BEGIN(value.%s) + value.%sCount" % (baseName, baseName[:-1])
659 endIter = "DE_ARRAY_END(value.%s)" % baseName
660 newLine = "'\\n' << "
661 valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)" % (baseName, endIter)
662 memberName = baseName
664 valFmt = "value.%s" % member.name
665 yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';"
671 writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
673 class ConstructorFunction:
674 def __init__ (self, type, name, objectType, iface, arguments):
677 self.objectType = objectType
679 self.arguments = arguments
681 def getConstructorFunctions (api):
683 for function in api.functions:
684 if (function.name[:8] == "vkCreate" or function.name == "vkAllocateMemory") and not "createInfoCount" in [a.name for a in function.arguments]:
685 if function.name == "vkCreateDisplayModeKHR":
686 continue # No way to delete display modes (bug?)
688 # \todo [pyry] Rather hacky
690 if function.getType() == Function.TYPE_PLATFORM:
691 iface = Variable("const PlatformInterface&", "vk")
692 elif function.getType() == Function.TYPE_INSTANCE:
693 iface = Variable("const InstanceInterface&", "vk")
695 iface = Variable("const DeviceInterface&", "vk")
697 assert function.arguments[-2].type == "const VkAllocationCallbacks*"
699 objectType = function.arguments[-1].type.replace("*", "").strip()
700 arguments = function.arguments[:-1]
701 funcs.append(ConstructorFunction(function.getType(), getInterfaceName(function), objectType, iface, arguments))
704 def writeRefUtilProto (api, filename):
705 functions = getConstructorFunctions(api)
707 def makeRefUtilProto ():
709 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]):
712 writeInlFile(filename, INL_HEADER, makeRefUtilProto())
714 def writeRefUtilImpl (api, filename):
715 functions = getConstructorFunctions(api)
717 def makeRefUtilImpl ():
718 yield "namespace refdetails"
722 for function in api.functions:
723 if function.getType() == Function.TYPE_DEVICE \
724 and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \
725 and not function.name == "vkDestroyDevice":
726 objectType = function.arguments[-2].type
728 yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType)
730 yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function))
734 yield "} // refdetails"
737 for function in functions:
738 if function.type == Function.TYPE_DEVICE:
740 elif function.type == Function.TYPE_INSTANCE:
741 if function.name == "createDevice":
748 yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments))
750 yield "\t%s object = 0;" % function.objectType
751 yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"]))
752 yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name]))
756 writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
758 def writeNullDriverImpl (api, filename):
759 def genNullDriverImpl ():
761 "vkCreateGraphicsPipelines",
762 "vkCreateComputePipelines",
763 "vkGetInstanceProcAddr",
764 "vkGetDeviceProcAddr",
765 "vkEnumeratePhysicalDevices",
766 "vkGetPhysicalDeviceFeatures",
767 "vkGetPhysicalDeviceProperties",
768 "vkGetPhysicalDeviceQueueFamilyProperties",
769 "vkGetPhysicalDeviceMemoryProperties",
770 "vkGetPhysicalDeviceFormatProperties",
771 "vkGetPhysicalDeviceImageFormatProperties",
773 "vkGetBufferMemoryRequirements",
774 "vkGetImageMemoryRequirements",
776 "vkAllocateDescriptorSets",
777 "vkFreeDescriptorSets",
778 "vkResetDescriptorPool",
779 "vkAllocateCommandBuffers",
780 "vkFreeCommandBuffers",
781 "vkCreateDisplayModeKHR",
782 "vkCreateSharedSwapchainsKHR",
784 specialFuncs = [f for f in api.functions if f.name in specialFuncNames]
785 createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs]
786 destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs]
787 dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs]
789 def getHandle (name):
790 for handle in api.handles:
791 if handle.name == name:
793 raise Exception("No such handle: %s" % name)
795 for function in createFuncs:
796 objectType = function.arguments[-1].type.replace("*", "").strip()
797 argsStr = ", ".join([a.name for a in function.arguments[:-1]])
799 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
801 yield "\tDE_UNREF(%s);" % function.arguments[-2].name
803 if getHandle(objectType).type == Handle.TYPE_NONDISP:
804 yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
806 yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr)
811 for function in destroyFuncs:
812 objectArg = function.arguments[-2]
814 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
816 for arg in function.arguments[:-2]:
817 yield "\tDE_UNREF(%s);" % arg.name
819 if getHandle(objectArg.type).type == Handle.TYPE_NONDISP:
820 yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
822 yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name)
827 for function in dummyFuncs:
828 yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments))
830 for arg in function.arguments:
831 yield "\tDE_UNREF(%s);" % arg.name
832 if function.returnType != "void":
833 yield "\treturn VK_SUCCESS;"
837 def genFuncEntryTable (type, name):
838 funcs = [f for f in api.functions if f.getType() == type]
840 yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name
842 for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]):
848 for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"):
851 for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"):
854 for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"):
858 writeInlFile(filename, INL_HEADER, genNullDriverImpl())
860 def writeTypeUtil (api, filename):
861 # Structs filled by API queries are not often used in test code
862 QUERY_RESULT_TYPES = set([
863 "VkPhysicalDeviceFeatures",
864 "VkPhysicalDeviceLimits",
865 "VkFormatProperties",
866 "VkImageFormatProperties",
867 "VkPhysicalDeviceSparseProperties",
868 "VkQueueFamilyProperties",
872 COMPOSITE_TYPES = set([t.name for t in api.compositeTypes])
874 def isSimpleStruct (type):
875 def hasArrayMember (type):
876 for member in type.members:
877 if "[" in member.name:
881 def hasCompositeMember (type):
882 for member in type.members:
883 if member.type in COMPOSITE_TYPES:
887 return type.typeClass == CompositeType.CLASS_STRUCT and \
888 type.members[0].type != "VkStructureType" and \
889 not type.name in QUERY_RESULT_TYPES and \
890 not hasArrayMember(type) and \
891 not hasCompositeMember(type)
894 for type in api.compositeTypes:
895 if not isSimpleStruct(type):
899 yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members))
901 yield "\t%s res;" % type.name
902 for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]):
904 yield "\treturn res;"
907 writeInlFile(filename, INL_HEADER, gen())
909 if __name__ == "__main__":
910 src = readFile(VULKAN_H)
912 platformFuncs = set([Function.TYPE_PLATFORM])
913 instanceFuncs = set([Function.TYPE_INSTANCE])
914 deviceFuncs = set([Function.TYPE_DEVICE])
916 writeHandleType (api, os.path.join(VULKAN_DIR, "vkHandleType.inl"))
917 writeBasicTypes (api, os.path.join(VULKAN_DIR, "vkBasicTypes.inl"))
918 writeCompositeTypes (api, os.path.join(VULKAN_DIR, "vkStructTypes.inl"))
919 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualPlatformInterface.inl"), functionTypes = platformFuncs, concrete = False)
920 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = False)
921 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkVirtualDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = False)
922 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcretePlatformInterface.inl"), functionTypes = platformFuncs, concrete = True)
923 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteInstanceInterface.inl"), functionTypes = instanceFuncs, concrete = True)
924 writeInterfaceDecl (api, os.path.join(VULKAN_DIR, "vkConcreteDeviceInterface.inl"), functionTypes = deviceFuncs, concrete = True)
925 writeFunctionPtrTypes (api, os.path.join(VULKAN_DIR, "vkFunctionPointerTypes.inl"))
926 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkPlatformFunctionPointers.inl"), functionTypes = platformFuncs)
927 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
928 writeFunctionPointers (api, os.path.join(VULKAN_DIR, "vkDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
929 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitPlatformFunctionPointers.inl"), functionTypes = platformFuncs, cond = lambda f: f.name != "vkGetInstanceProcAddr")
930 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitInstanceFunctionPointers.inl"), functionTypes = instanceFuncs)
931 writeInitFunctionPointers (api, os.path.join(VULKAN_DIR, "vkInitDeviceFunctionPointers.inl"), functionTypes = deviceFuncs)
932 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkPlatformDriverImpl.inl"), functionTypes = platformFuncs, className = "PlatformDriver")
933 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkInstanceDriverImpl.inl"), functionTypes = instanceFuncs, className = "InstanceDriver")
934 writeFuncPtrInterfaceImpl (api, os.path.join(VULKAN_DIR, "vkDeviceDriverImpl.inl"), functionTypes = deviceFuncs, className = "DeviceDriver")
935 writeStrUtilProto (api, os.path.join(VULKAN_DIR, "vkStrUtil.inl"))
936 writeStrUtilImpl (api, os.path.join(VULKAN_DIR, "vkStrUtilImpl.inl"))
937 writeRefUtilProto (api, os.path.join(VULKAN_DIR, "vkRefUtil.inl"))
938 writeRefUtilImpl (api, os.path.join(VULKAN_DIR, "vkRefUtilImpl.inl"))
939 writeNullDriverImpl (api, os.path.join(VULKAN_DIR, "vkNullDriverImpl.inl"))
940 writeTypeUtil (api, os.path.join(VULKAN_DIR, "vkTypeUtil.inl"))