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
def gen (registry): noExtIface = getInterface(registry, 'egl', VERSION) extOnlyIface = getExtOnlyIface(registry, 'egl', EXTENSIONS) defaultIface = getDefaultInterface() defines = imap(commandAliasDefinition, defaultIface.commands) prototypes = imap(commandWrapperDeclaration, defaultIface.commands) src = indentLines(chain(defines, prototypes)) writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwApi.inl"), src) writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwEnumsC.inl"), indentLines(map(enumDefinitionC, defaultIface.enums))) genCommandList(noExtIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImpl.inl") genCommandList(extOnlyIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImplExt.inl")
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
def gen(registry): noExtIface = getInterface(registry, 'egl', VERSION) extOnlyIface = getExtOnlyIface(registry, 'egl', EXTENSIONS) defaultIface = getDefaultInterface() defines = imap(commandAliasDefinition, defaultIface.commands) prototypes = imap(commandWrapperDeclaration, defaultIface.commands) src = indentLines(chain(defines, prototypes)) writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwApi.inl"), src) writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwEnumsC.inl"), indentLines(map(enumDefinitionC, defaultIface.enums))) genCommandList(noExtIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImpl.inl") genCommandList(extOnlyIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImplExt.inl")
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 genCompositeTypeSrc(type): yield "%s %s" % (type.getClassName(), type.name) yield "{" for line in indentLines( ["\t%s\t%s;" % (m.type, m.name) for m in type.members]): yield line yield "};"
def gen (iface): enumGroups = addValuePrefix(ENUM_GROUPS, "EGL_") bitfieldGroups = addValuePrefix(BITFIELD_GROUPS, "EGL_") prototypeFile = os.path.join(EGL_DIR, "egluStrUtilPrototypes.inl") implFile = os.path.join(EGL_DIR, "egluStrUtil.inl") writeInlFile(prototypeFile, indentLines(genStrUtilProtos(iface, enumGroups, bitfieldGroups))) writeInlFile(implFile, genStrUtilImpls(iface, enumGroups, bitfieldGroups))
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 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
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 gen (iface): enumGroups = addValuePrefix(ENUM_GROUPS, "EGL_") bitfieldGroups = addValuePrefix(BITFIELD_GROUPS, "EGL_") prototypeFile = os.path.join(EGL_DIR, "egluStrUtilPrototypes.inl") implFile = os.path.join(EGL_DIR, "egluStrUtil.inl") writeInlFile(prototypeFile, indentLines(genStrUtilProtos(iface, enumGroups, bitfieldGroups))) writeInlFile(implFile, genStrUtilImpls(iface, enumGroups, bitfieldGroups))
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 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
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
def genBitfieldSrc (bitfield): if len(bitfield.values) > 0: yield "enum %s" % getBitEnumNameForBitfield(bitfield.name) yield "{" for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]): yield line yield "};" yield "typedef deUint32 %s;" % bitfield.name
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
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 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 ""
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 ""
def genBitfieldSrc (bitfield): if len(bitfield.values) > 0: yield "enum %s" % getBitEnumNameForBitfield(bitfield.name) yield "{" for line in indentLines(["\t%s\t= %s," % v for v in bitfield.values]): yield line yield "};" yield "typedef deUint32 %s;" % bitfield.name
def genHandlesSrc (handles): def genLines (handles): for handle in handles: if handle.type == Handle.TYPE_DISP: yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType()) elif handle.type == Handle.TYPE_NONDISP: yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType()) for line in indentLines(genLines(handles)): yield line
def genHandlesSrc (handles): def genLines (handles): for handle in handles: if handle.type == Handle.TYPE_DISP: yield "VK_DEFINE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType()) elif handle.type == Handle.TYPE_NONDISP: yield "VK_DEFINE_NON_DISPATCHABLE_HANDLE\t(%s,\t%s);" % (handle.name, handle.getHandleType()) for line in indentLines(genLines(handles)): yield line
def genEnumSrc (enum): yield "enum %s" % enum.name yield "{" for line in indentLines(["\t%s\t= %s," % v for v in enum.values]): yield line if areEnumValuesLinear(enum): yield "" yield "\t%s_LAST" % getEnumValuePrefix(enum) yield "};"
def genEnumSrc (enum): yield "enum %s" % enum.name yield "{" for line in indentLines(["\t%s\t= %s," % v for v in enum.values]): yield line if areEnumValuesLinear(enum): yield "" yield "\t%s_LAST" % getEnumValuePrefix(enum) yield "};"
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 "}"
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 "}"
def genSetEnumUtilImpl(groupName, groupQueries, allEnums): yield "" yield "int get%sNumArgs (int pname)" % groupName yield "{" yield "\tswitch(pname)" yield "\t{" def genCases(): for enumName, enumQueryNumOutputs in groupQueries: if enumName in allEnums: yield "case %s:\treturn %s;" % (enumName, enumQueryNumOutputs) else: print("Warning: %s not defined, skipping" % enumName) yield "default:\treturn 1;" for caseLine in indentLines(genCases()): yield "\t\t" + caseLine yield "\t}" yield "}"
def makeExtensionList (extensions): for name, iface in extensions: for line in makeFunctionList(name, iface): yield line yield "" yield "static const struct" yield "{" yield "\tconst char*\t\t\tname;" yield "\tconst int\t\t\tnumFunctions;" yield "\tconst char* const*\tfunctions;" yield "} s_extensions[] =" yield "{" entries = [] for name, iface in extensions: entries.append("\t{ \"%s\",\tDE_LENGTH_OF_ARRAY(s_%s),\ts_%s\t}," % (name, name, name)) for line in indentLines(entries): yield line yield "};"
def makeExtensionList (extensions): for name, iface in extensions: for line in makeFunctionList(name, iface): yield line yield "" yield "static const struct" yield "{" yield "\tconst char*\t\t\tname;" yield "\tconst int\t\t\tnumFunctions;" yield "\tconst char* const*\tfunctions;" yield "} s_extensions[] =" yield "{" entries = [] for name, iface in extensions: entries.append("\t{ \"%s\",\tDE_LENGTH_OF_ARRAY(s_%s),\ts_%s\t}," % (name, name, name)) for line in indentLines(entries): yield line yield "};"
def genBitfieldStrImpl(groupName, values, definitions): if allValuesUndefined(definitions, values): return yield "" yield "tcu::Format::Bitfield<16> get%sStr (int value)" % groupName yield "{" yield "\tstatic const tcu::Format::BitDesc s_desc[] =" yield "\t{" def genFields(): for value in values: if isValueDefined(definitions, value): yield "tcu::Format::BitDesc(%s,\t\"%s\")," % (value, value) else: print("Warning: %s not defined, skipping" % value) for fieldLine in indentLines(genFields()): yield "\t\t" + fieldLine yield "\t};" yield "\treturn tcu::Format::Bitfield<16>(value, &s_desc[0], &s_desc[DE_LENGTH_OF_ARRAY(s_desc)]);" yield "}"
def genEnumStrImpl(groupName, values, definitions): if allValuesUndefined(definitions, values): return yield "" yield "const char* get%sName (int value)" % groupName yield "{" yield "\tswitch (value)" yield "\t{" def genCases(): for value in values: if isValueDefined(definitions, value): yield "case %s:\treturn \"%s\";" % (value, value) else: print("Warning: %s not defined, skipping" % value) yield "default:\treturn DE_NULL;" for caseLine in indentLines(genCases()): yield "\t\t" + caseLine yield "\t}" yield "}"
def gen (iface): writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwEnums.inl"), indentLines(map(enumDefinition, iface.enums)))
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 "}"
def genCompositeTypeSrc (type): yield "%s %s" % (type.getClassName(), type.name) yield "{" for line in indentLines(["\t%s\t%s;" % (m.type, m.name) for m in type.members]): yield line yield "};"
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 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
def gen (iface): writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwEnums.inl"), indentLines(map(enumDefinition, iface.enums)))
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 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 "}"