def writeBasicTypes(api, filename): def gen(): for line in indentLines([ "#define %s\t(static_cast<%s>\t(%s))" % (name, type, value) for name, type, value in api.definitions ]): yield line yield "" for line in genHandlesSrc(api.handles): yield line yield "" for enum in api.enums: for line in genEnumSrc(enum): yield line yield "" for bitfield in api.bitfields: for line in genBitfieldSrc(bitfield): yield line yield "" for line in indentLines([ "VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES ]): yield line writeInlFile(filename, INL_HEADER, gen())
def writeInitFunctionPointers (api, filename, functionTypes, cond = None): def makeInitFunctionPointers (): for function in api.functions: if function.getType() in functionTypes and (cond == None or cond(function)): yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name) writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
def writeInitFunctionPointers (api, filename, functionTypes, cond = None): def makeInitFunctionPointers (): for function in api.functions: if function.getType() in functionTypes and (cond == None or cond(function)): yield "m_vk.%s\t= (%s)\tGET_PROC_ADDR(\"%s\");" % (getInterfaceName(function), getFunctionTypeName(function), function.name) writeInlFile(filename, INL_HEADER, indentLines(makeInitFunctionPointers()))
def writeStrUtilProto(api, filename): def makeStrUtilProto(): for line in indentLines([ "const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums ]): yield line yield "" 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 ]): yield line yield "" 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 ]): yield line yield "" for line in indentLines([ "tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields ]): yield line yield "" for line in indentLines([ "std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes ]): yield line writeInlFile(filename, INL_HEADER, makeStrUtilProto())
def writeFunctionPtrTypes(api, filename): def genTypes(): for function in api.functions: yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % ( function.returnType, getFunctionTypeName(function), argListToStr(function.arguments)) writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
def writeInterfaceDecl (api, filename, functionTypes, concrete): def genProtos (): postfix = "" if concrete else " = 0" for function in api.functions: if function.getType() in functionTypes: yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix) writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
def writeVulkanCHeader (src, filename): def gen (): dst = re.sub(r'(#include "[^\s,\n}]+")', '', src) for old_type, new_type in TYPE_SUBSTITUTIONS: dst = dst.replace(old_type, new_type) yield dst writeInlFile(filename, INL_HEADER, gen())
def writeCompositeTypes (api, filename): def gen (): for type in api.compositeTypes: for line in genCompositeTypeSrc(type): yield line yield "" writeInlFile(filename, INL_HEADER, gen())
def writeInterfaceDecl (api, filename, functionTypes, concrete): def genProtos (): postfix = "" if concrete else " = 0" for function in api.functions: if function.getType() in functionTypes: yield "virtual %s\t%s\t(%s) const%s;" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments), postfix) writeInlFile(filename, INL_HEADER, indentLines(genProtos()))
def writeCompositeTypes (api, filename): def gen (): for type in api.compositeTypes: for line in genCompositeTypeSrc(type): yield line yield "" writeInlFile(filename, INL_HEADER, gen())
def writeVulkanCHeader (src, filename): def gen (): dst = src.replace('#include "vk_platform.h"','') for old_type, new_type in TYPE_SUBSTITUTIONS: dst = dst.replace(old_type, new_type) yield dst writeInlFile(filename, INL_HEADER, gen())
def writeRefUtilProto (api, filename): functions = getConstructorFunctions(api) def makeRefUtilProto (): unindented = [] 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]): yield line writeInlFile(filename, INL_HEADER, makeRefUtilProto())
def writeFunctionPointers(api, filename, functionTypes): writeInlFile( filename, INL_HEADER, indentLines([ "%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes ]))
def writeRefUtilProto (api, filename): functions = getConstructorFunctions(api) def makeRefUtilProto (): unindented = [] 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]): yield line writeInlFile(filename, INL_HEADER, makeRefUtilProto())
def writeStructTraitsImpl (api, filename): def gen (): for type in api.compositeTypes: if type.getClassName() == "struct" and type.members[0].name == "sType": yield "template<> VkStructureType getStructureType<%s> (void)" % type.name yield "{" yield "\treturn VK_STRUCTURE_TYPE_%s;" % typeNameToEnumValue(type.name) yield "}" yield "" writeInlFile(filename, INL_HEADER, gen())
def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className): def makeFuncPtrInterfaceImpl (): for function in api.functions: if function.getType() in functionTypes: yield "" yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments)) yield "{" yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments)) yield "}" writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
def writeFuncPtrInterfaceImpl (api, filename, functionTypes, className): def makeFuncPtrInterfaceImpl (): for function in api.functions: if function.getType() in functionTypes: yield "" yield "%s %s::%s (%s) const" % (function.returnType, className, getInterfaceName(function), argListToStr(function.arguments)) yield "{" yield " %sm_vk.%s(%s);" % ("return " if function.returnType != "void" else "", getInterfaceName(function), ", ".join(a.name for a in function.arguments)) yield "}" writeInlFile(filename, INL_HEADER, makeFuncPtrInterfaceImpl())
def writeHandleType (api, filename): def gen (): yield "enum HandleType" yield "{" yield "\t%s = 0," % api.handles[0].getHandleType() for handle in api.handles[1:]: yield "\t%s," % handle.getHandleType() yield "\tHANDLE_TYPE_LAST" yield "};" yield "" writeInlFile(filename, INL_HEADER, gen())
def writeHandleType (api, filename): def gen (): yield "enum HandleType" yield "{" yield "\t%s = 0," % api.handles[0].getHandleType() for handle in api.handles[1:]: yield "\t%s," % handle.getHandleType() yield "\tHANDLE_TYPE_LAST" yield "};" yield "" writeInlFile(filename, INL_HEADER, gen())
def writeVulkanCHeader(src, filename): def gen(): dst = re.sub(r'(#include "[^\s,\n}]+")', '', src) # Amber is compiled using C++11 but under MSVC __cplusplus macro # is incorrectly recognized and this triggers invalid definition dst = dst.replace('VK_NULL_HANDLE ((void*)0)', 'VK_NULL_HANDLE 0') for old_type, new_type in TYPE_SUBSTITUTIONS: dst = dst.replace(old_type, new_type) yield dst writeInlFile(filename, INL_HEADER, gen())
def writeStructTraitsImpl(api, filename): def gen(): for type in api.compositeTypes: if type.getClassName( ) == "struct" and type.members[0].name == "sType": yield "template<> VkStructureType getStructureType<%s> (void)" % type.name yield "{" yield "\treturn VK_STRUCTURE_TYPE_%s;" % typeNameToEnumValue( type.name) yield "}" yield "" writeInlFile(filename, INL_HEADER, gen())
def writeRefUtilImpl(api, filename): functions = getConstructorFunctions(api) def makeRefUtilImpl(): yield "namespace refdetails" yield "{" yield "" for function in api.functions: if function.getType() == Function.TYPE_DEVICE \ and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \ and not function.name == "vkDestroyDevice": objectType = function.arguments[-2].type yield "template<>" yield "void Deleter<%s>::operator() (%s obj) const" % ( objectType, objectType) yield "{" yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % ( getInterfaceName(function)) yield "}" yield "" yield "} // refdetails" yield "" for function in functions: if function.type == Function.TYPE_DEVICE: dtorObj = "device" elif function.type == Function.TYPE_INSTANCE: if function.name == "createDevice": dtorObj = "object" else: dtorObj = "instance" else: dtorObj = "object" yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments)) yield "{" yield "\t%s object = 0;" % function.objectType yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join( [a.name for a in function.arguments] + ["&object"])) yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % ( function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name])) yield "}" yield "" writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
def writeTypeUtil(api, filename): # Structs filled by API queries are not often used in test code QUERY_RESULT_TYPES = set([ "VkPhysicalDeviceFeatures", "VkPhysicalDeviceLimits", "VkFormatProperties", "VkImageFormatProperties", "VkPhysicalDeviceSparseProperties", "VkQueueFamilyProperties", "VkMemoryType", "VkMemoryHeap", ]) COMPOSITE_TYPES = set([t.name for t in api.compositeTypes]) def isSimpleStruct(type): def hasArrayMember(type): for member in type.members: if "[" in member.name: return True return False def hasCompositeMember(type): for member in type.members: if member.type in COMPOSITE_TYPES: return True return False return type.typeClass == CompositeType.CLASS_STRUCT and \ type.members[0].type != "VkStructureType" and \ not type.name in QUERY_RESULT_TYPES and \ not hasArrayMember(type) and \ not hasCompositeMember(type) def gen(): for type in api.compositeTypes: if not isSimpleStruct(type): continue yield "" yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members)) yield "{" yield "\t%s res;" % type.name for line in indentLines( ["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]): yield line yield "\treturn res;" yield "}" writeInlFile(filename, INL_HEADER, gen())
def writeTypeUtil (api, filename): # Structs filled by API queries are not often used in test code QUERY_RESULT_TYPES = set([ "VkPhysicalDeviceFeatures", "VkPhysicalDeviceLimits", "VkFormatProperties", "VkImageFormatProperties", "VkPhysicalDeviceSparseProperties", "VkQueueFamilyProperties", "VkMemoryType", "VkMemoryHeap", ]) COMPOSITE_TYPES = set([t.name for t in api.compositeTypes]) def isSimpleStruct (type): def hasArrayMember (type): for member in type.members: if "[" in member.name: return True return False def hasCompositeMember (type): for member in type.members: if member.type in COMPOSITE_TYPES: return True return False return type.typeClass == CompositeType.CLASS_STRUCT and \ type.members[0].type != "VkStructureType" and \ not type.name in QUERY_RESULT_TYPES and \ not hasArrayMember(type) and \ not hasCompositeMember(type) def gen (): for type in api.compositeTypes: if not isSimpleStruct(type): continue yield "" yield "inline %s make%s (%s)" % (type.name, type.name[2:], argListToStr(type.members)) yield "{" yield "\t%s res;" % type.name for line in indentLines(["\tres.%s\t= %s;" % (m.name, m.name) for m in type.members]): yield line yield "\treturn res;" yield "}" writeInlFile(filename, INL_HEADER, gen())
def writeStrUtilProto (api, filename): def makeStrUtilProto (): for line in indentLines(["const char*\tget%sName\t(%s value);" % (enum.name[2:], enum.name) for enum in api.enums]): yield line yield "" 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]): yield line yield "" 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]): yield line yield "" for line in indentLines(["tcu::Format::Bitfield<32>\tget%sStr\t(%s value);" % (bitfield.name[2:], bitfield.name) for bitfield in api.bitfields]): yield line yield "" for line in indentLines(["std::ostream&\toperator<<\t(std::ostream& s, const %s& value);" % (s.name) for s in api.compositeTypes]): yield line writeInlFile(filename, INL_HEADER, makeStrUtilProto())
def writeRefUtilImpl (api, filename): functions = getConstructorFunctions(api) def makeRefUtilImpl (): yield "namespace refdetails" yield "{" yield "" for function in api.functions: if function.getType() == Function.TYPE_DEVICE \ and (function.name[:9] == "vkDestroy" or function.name == "vkFreeMemory") \ and not function.name == "vkDestroyDevice": objectType = function.arguments[-2].type yield "template<>" yield "void Deleter<%s>::operator() (%s obj) const" % (objectType, objectType) yield "{" yield "\tm_deviceIface->%s(m_device, obj, m_allocator);" % (getInterfaceName(function)) yield "}" yield "" yield "} // refdetails" yield "" for function in functions: if function.type == Function.TYPE_DEVICE: dtorObj = "device" elif function.type == Function.TYPE_INSTANCE: if function.name == "createDevice": dtorObj = "object" else: dtorObj = "instance" else: dtorObj = "object" yield "Move<%s> %s (%s)" % (function.objectType, function.name, argListToStr([function.iface] + function.arguments)) yield "{" yield "\t%s object = 0;" % function.objectType yield "\tVK_CHECK(vk.%s(%s));" % (function.name, ", ".join([a.name for a in function.arguments] + ["&object"])) yield "\treturn Move<%s>(check<%s>(object), Deleter<%s>(%s));" % (function.objectType, function.objectType, function.objectType, ", ".join(["vk", dtorObj, function.arguments[-1].name])) yield "}" yield "" writeInlFile(filename, INL_HEADER, makeRefUtilImpl())
def writeBasicTypes (api, filename): def gen (): for line in indentLines(["#define %s\t(static_cast<%s>\t(%s))" % (name, type, value) for name, type, value in api.definitions]): yield line yield "" for line in genHandlesSrc(api.handles): yield line yield "" for enum in api.enums: for line in genEnumSrc(enum): yield line yield "" for bitfield in api.bitfields: for line in genBitfieldSrc(bitfield): yield line yield "" for line in indentLines(["VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES]): yield line writeInlFile(filename, INL_HEADER, gen())
def writeBasicTypes (api, filename): def gen (): for line in indentLines(["enum { %s\t= %s\t};" % define for define in api.definitions]): yield line yield "" for line in genHandlesSrc(api.handles): yield line yield "" for enum in api.enums: for line in genEnumSrc(enum): yield line yield "" for bitfield in api.bitfields: for line in genBitfieldSrc(bitfield): yield line yield "" for line in indentLines(["VK_DEFINE_PLATFORM_TYPE(%s,\t%s);" % (s, c) for n, s, c in PLATFORM_TYPES]): yield line writeInlFile(filename, INL_HEADER, gen())
def writeNullDriverImpl (api, filename): def genNullDriverImpl (): specialFuncNames = [ "vkCreateGraphicsPipelines", "vkCreateComputePipelines", "vkGetInstanceProcAddr", "vkGetDeviceProcAddr", "vkEnumeratePhysicalDevices", "vkGetPhysicalDeviceFeatures", "vkGetPhysicalDeviceProperties", "vkGetPhysicalDeviceQueueFamilyProperties", "vkGetPhysicalDeviceMemoryProperties", "vkGetPhysicalDeviceFormatProperties", "vkGetPhysicalDeviceImageFormatProperties", "vkGetDeviceQueue", "vkGetBufferMemoryRequirements", "vkGetImageMemoryRequirements", "vkMapMemory", "vkAllocateDescriptorSets", "vkFreeDescriptorSets", "vkResetDescriptorPool", "vkAllocateCommandBuffers", "vkFreeCommandBuffers", "vkCreateDisplayModeKHR", "vkCreateSharedSwapchainsKHR", ] specialFuncs = [f for f in api.functions if f.name in specialFuncNames] createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs] destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs] dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs] def getHandle (name): for handle in api.handles: if handle.name == name: return handle raise Exception("No such handle: %s" % name) for function in createFuncs: objectType = function.arguments[-1].type.replace("*", "").strip() argsStr = ", ".join([a.name for a in function.arguments[:-1]]) yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments)) yield "{" yield "\tDE_UNREF(%s);" % function.arguments[-2].name if getHandle(objectType).type == Handle.TYPE_NONDISP: yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr) else: yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr) yield "}" yield "" for function in destroyFuncs: objectArg = function.arguments[-2] yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments)) yield "{" for arg in function.arguments[:-2]: yield "\tDE_UNREF(%s);" % arg.name if getHandle(objectArg.type).type == Handle.TYPE_NONDISP: yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name) else: yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name) yield "}" yield "" for function in dummyFuncs: yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments)) yield "{" for arg in function.arguments: yield "\tDE_UNREF(%s);" % arg.name if function.returnType != "void": yield "\treturn VK_SUCCESS;" yield "}" yield "" def genFuncEntryTable (type, name): funcs = [f for f in api.functions if f.getType() == type] yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name yield "{" for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]): yield line yield "};" yield "" # Func tables for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"): yield line for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"): yield line for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"): yield line writeInlFile(filename, INL_HEADER, genNullDriverImpl())
def writeStrUtilImpl (api, filename): def makeStrUtilImpl (): for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]): yield line yield "" yield "namespace %s" % PLATFORM_TYPE_NAMESPACE yield "{" 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): yield line yield "}" for enum in api.enums: yield "" yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name) yield "{" yield "\tswitch (value)" yield "\t{" for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]): yield line yield "\t}" yield "}" for bitfield in api.bitfields: yield "" yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name) yield "{" if len(bitfield.values) > 0: yield "\tstatic const tcu::Format::BitDesc s_desc[] =" yield "\t{" for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]): yield line yield "\t};" yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));" else: yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);" yield "}" bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields]) for type in api.compositeTypes: yield "" yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name yield "{" yield "\ts << \"%s = {\\n\";" % type.name for member in type.members: memberName = member.name valFmt = None newLine = "" if member.type in bitfieldTypeNames: valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name) elif member.type == "const char*" or member.type == "char*": valFmt = "getCharPtrStr(value.%s)" % member.name elif '[' in member.name: baseName = member.name[:member.name.find('[')] if baseName in ["extensionName", "deviceName", "layerName", "description"]: valFmt = "(const char*)value.%s" % baseName elif member.type == 'char' or member.type == 'deUint8': newLine = "'\\n' << " 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) else: if baseName == "memoryTypes" or baseName == "memoryHeaps": endIter = "DE_ARRAY_BEGIN(value.%s) + value.%sCount" % (baseName, baseName[:-1]) else: endIter = "DE_ARRAY_END(value.%s)" % baseName newLine = "'\\n' << " valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)" % (baseName, endIter) memberName = baseName else: valFmt = "value.%s" % member.name yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';" yield "\ts << '}';" yield "\treturn s;" yield "}" writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
def writeFunctionPtrTypes (api, filename): def genTypes (): for function in api.functions: yield "typedef VKAPI_ATTR %s\t(VKAPI_CALL* %s)\t(%s);" % (function.returnType, getFunctionTypeName(function), argListToStr(function.arguments)) writeInlFile(filename, INL_HEADER, indentLines(genTypes()))
def writeFunctionPointers (api, filename, functionTypes): writeInlFile(filename, INL_HEADER, indentLines(["%s\t%s;" % (getFunctionTypeName(function), getInterfaceName(function)) for function in api.functions if function.getType() in functionTypes]))
def writeStrUtilImpl (api, filename): def makeStrUtilImpl (): for line in indentLines(["template<> const char*\tgetTypeName<%s>\t(void) { return \"%s\";\t}" % (handle.name, handle.name) for handle in api.handles]): yield line yield "" yield "namespace %s" % PLATFORM_TYPE_NAMESPACE yield "{" 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): yield line yield "}" for enum in api.enums: yield "" yield "const char* get%sName (%s value)" % (enum.name[2:], enum.name) yield "{" yield "\tswitch (value)" yield "\t{" for line in indentLines(["\t\tcase %s:\treturn \"%s\";" % (n, n) for n, v in enum.values] + ["\t\tdefault:\treturn DE_NULL;"]): yield line yield "\t}" yield "}" for bitfield in api.bitfields: yield "" yield "tcu::Format::Bitfield<32> get%sStr (%s value)" % (bitfield.name[2:], bitfield.name) yield "{" if len(bitfield.values) > 0: yield "\tstatic const tcu::Format::BitDesc s_desc[] =" yield "\t{" for line in indentLines(["\t\ttcu::Format::BitDesc(%s,\t\"%s\")," % (n, n) for n, v in bitfield.values]): yield line yield "\t};" yield "\treturn tcu::Format::Bitfield<32>(value, DE_ARRAY_BEGIN(s_desc), DE_ARRAY_END(s_desc));" else: yield "\treturn tcu::Format::Bitfield<32>(value, DE_NULL, DE_NULL);" yield "}" bitfieldTypeNames = set([bitfield.name for bitfield in api.bitfields]) for type in api.compositeTypes: yield "" yield "std::ostream& operator<< (std::ostream& s, const %s& value)" % type.name yield "{" yield "\ts << \"%s = {\\n\";" % type.name for member in type.members: memberName = member.name valFmt = None newLine = "" if member.type in bitfieldTypeNames: valFmt = "get%sStr(value.%s)" % (member.type[2:], member.name) elif member.type == "const char*" or member.type == "char*": valFmt = "getCharPtrStr(value.%s)" % member.name elif '[' in member.name: baseName = member.name[:member.name.find('[')] if baseName in ["extensionName", "deviceName", "layerName", "description"]: valFmt = "(const char*)value.%s" % baseName elif member.type == 'char' or member.type == 'deUint8': newLine = "'\\n' << " 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) else: if baseName == "memoryTypes" or baseName == "memoryHeaps": endIter = "DE_ARRAY_BEGIN(value.%s) + value.%sCount" % (baseName, baseName[:-1]) else: endIter = "DE_ARRAY_END(value.%s)" % baseName newLine = "'\\n' << " valFmt = "tcu::formatArray(DE_ARRAY_BEGIN(value.%s), %s)" % (baseName, endIter) memberName = baseName else: valFmt = "value.%s" % member.name yield ("\ts << \"\\t%s = \" << " % memberName) + newLine + valFmt + " << '\\n';" yield "\ts << '}';" yield "\treturn s;" yield "}" writeInlFile(filename, INL_HEADER, makeStrUtilImpl())
def writeNullDriverImpl (api, filename): def genNullDriverImpl (): specialFuncNames = [ "vkCreateGraphicsPipelines", "vkCreateComputePipelines", "vkGetInstanceProcAddr", "vkGetDeviceProcAddr", "vkEnumeratePhysicalDevices", "vkGetPhysicalDeviceFeatures", "vkGetPhysicalDeviceProperties", "vkGetPhysicalDeviceQueueFamilyProperties", "vkGetPhysicalDeviceMemoryProperties", "vkGetPhysicalDeviceFormatProperties", "vkGetPhysicalDeviceImageFormatProperties", "vkGetDeviceQueue", "vkGetBufferMemoryRequirements", "vkGetImageMemoryRequirements", "vkMapMemory", "vkAllocateDescriptorSets", "vkFreeDescriptorSets", "vkResetDescriptorPool", "vkAllocateCommandBuffers", "vkFreeCommandBuffers", "vkCreateDisplayModeKHR", "vkCreateSharedSwapchainsKHR", ] specialFuncs = [f for f in api.functions if f.name in specialFuncNames] createFuncs = [f for f in api.functions if (f.name[:8] == "vkCreate" or f.name == "vkAllocateMemory") and not f in specialFuncs] destroyFuncs = [f for f in api.functions if (f.name[:9] == "vkDestroy" or f.name == "vkFreeMemory") and not f in specialFuncs] dummyFuncs = [f for f in api.functions if f not in specialFuncs + createFuncs + destroyFuncs] def getHandle (name): for handle in api.handles: if handle.name == name: return handle raise Exception("No such handle: %s" % name) for function in createFuncs: objectType = function.arguments[-1].type.replace("*", "").strip() argsStr = ", ".join([a.name for a in function.arguments[:-1]]) yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments)) yield "{" yield "\tDE_UNREF(%s);" % function.arguments[-2].name if getHandle(objectType).type == Handle.TYPE_NONDISP: yield "\tVK_NULL_RETURN((*%s = allocateNonDispHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr) else: yield "\tVK_NULL_RETURN((*%s = allocateHandle<%s, %s>(%s)));" % (function.arguments[-1].name, objectType[2:], objectType, argsStr) yield "}" yield "" for function in destroyFuncs: objectArg = function.arguments[-2] yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments)) yield "{" for arg in function.arguments[:-2]: yield "\tDE_UNREF(%s);" % arg.name if getHandle(objectArg.type).type == Handle.TYPE_NONDISP: yield "\tfreeNonDispHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name) else: yield "\tfreeHandle<%s, %s>(%s, %s);" % (objectArg.type[2:], objectArg.type, objectArg.name, function.arguments[-1].name) yield "}" yield "" for function in dummyFuncs: yield "VKAPI_ATTR %s VKAPI_CALL %s (%s)" % (function.returnType, getInterfaceName(function), argListToStr(function.arguments)) yield "{" for arg in function.arguments: yield "\tDE_UNREF(%s);" % arg.name if function.returnType != "void": yield "\treturn VK_SUCCESS;" yield "}" yield "" def genFuncEntryTable (type, name): funcs = [f for f in api.functions if f.getType() == type] yield "static const tcu::StaticFunctionLibrary::Entry %s[] =" % name yield "{" for line in indentLines(["\tVK_NULL_FUNC_ENTRY(%s,\t%s)," % (function.name, getInterfaceName(function)) for function in funcs]): yield line yield "};" yield "" # Func tables for line in genFuncEntryTable(Function.TYPE_PLATFORM, "s_platformFunctions"): yield line for line in genFuncEntryTable(Function.TYPE_INSTANCE, "s_instanceFunctions"): yield line for line in genFuncEntryTable(Function.TYPE_DEVICE, "s_deviceFunctions"): yield line writeInlFile(filename, INL_HEADER, genNullDriverImpl())