From f81dbe0e9da3efb43ec6a2b0318404fc6c9bf52e Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Thu, 9 Mar 2023 09:57:12 -0600 Subject: [PATCH 1/2] Remove obsolete commented code --- def/array_type.go | 39 +------------- def/base_type.go | 1 - def/command_type.go | 85 +++---------------------------- def/define_type.go | 7 --- def/enum_type.go | 2 +- def/enum_value.go | 5 -- def/external_type.go | 1 - def/generic_type.go | 20 -------- def/handle_type.go | 2 - def/internal_type.go | 10 ---- def/name_conversion.go | 1 + def/pointer_type.go | 33 ++---------- def/struct_type.go | 14 ++--- def/union_type.go | 9 ++-- feat/feature.go | 5 +- main.go | 81 ++--------------------------- static_include/static_basetype.go | 3 ++ static_include/static_common.go | 23 --------- 18 files changed, 30 insertions(+), 311 deletions(-) diff --git a/def/array_type.go b/def/array_type.go index ab18d2f..3cbad52 100644 --- a/def/array_type.go +++ b/def/array_type.go @@ -19,9 +19,6 @@ func (t *arrayType) Category() TypeCategory { return CatArray } func (t *arrayType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { return t.resolvedPointsAtType.Resolve(tr, vr) - // is := includeSet{ - // includeTypeNames: , - // } } func (t *arrayType) IsIdenticalPublicAndInternal() bool { @@ -62,37 +59,13 @@ func (t *arrayType) PrintVulkanizeContent(forMember *structMember, preamble io.W fmt.Fprintf(preamble, "copy(rval.%s[:], s.%s)\n", forMember.InternalName(), forMember.PublicName()) structMemberAssignment = "" - } else { - // pre := fmt.Sprintf(sliceTranslationTemplate, - // forMember.InternalName(), t.resolvedPointsAtType.InternalName(), forMember.PublicName(), - // forMember.PublicName(), - // forMember.InternalName(), t.resolvedPointsAtType.TranslateToInternal("v"), - // ) - // fmt.Fprint(preamble, pre) - // structMemberAssignment = "&(sl_" + forMember.InternalName() + "[0])" - // } - // } else { - // if t.resolvedPointsAtType.IsIdenticalPublicAndInternal() { - // structMemberAssignment = fmt.Sprintf("(%s)(s.%s)", t.InternalName(), forMember.PublicName()) - // } else { - // structMemberAssignment = t.resolvedPointsAtType.TranslateToInternal("s." + forMember.PublicName()) - // if t.resolvedPointsAtType.Category() == CatStruct { - // structMemberAssignment = strings.TrimLeft(structMemberAssignment, "*") - // } - // } } + return } func (t *arrayType) PrintGoifyContent(forMember *structMember, preamble, epilogue io.Writer) (structMemberAssignment string) { - structMemberAssignment = "0 /* TODO ARRAY NOT HANDLED */" - - // if t.resolvedPointsAtType.IsIdenticalPublicAndInternal() { - // if this is an array to types that are "IsIdentical..." then just - // copy the array as a block and move on - // fmt.Fprintf(epilogue, t.TranslateToPublic("s."+forMember.InternalName())) if t.resolvedPointsAtType.InternalName() == "byte" { - // fmt.Fprintf(epilogue, "rval.%s = nullTermBytesToString(s.%s[:])\n", forMember.PublicName(), forMember.InternalName()) structMemberAssignment = fmt.Sprintf("nullTermBytesToString(s.%s[:])", forMember.InternalName()) return } @@ -100,15 +73,5 @@ func (t *arrayType) PrintGoifyContent(forMember *structMember, preamble, epilogu fmt.Fprintf(epilogue, "copy(rval.%s[:], s.%s[:])\n", forMember.PublicName(), forMember.InternalName()) structMemberAssignment = "" - // } else { - // structMemberAssignment = t.resolvedPointsAtType.TranslateToPublic("s." + forMember.InternalName()) - // } return } - -// const sliceTranslationTemplate string = ` -// sl_%s := make([]%s, len(s.%s)) -// for i, v := range s.%s { -// sl_%s[i] = %s -// } -// ` diff --git a/def/base_type.go b/def/base_type.go index 23ab0c2..e85d872 100644 --- a/def/base_type.go +++ b/def/base_type.go @@ -48,7 +48,6 @@ func (t *baseType) PrintPublicDeclaration(w io.Writer) { t.PrintDocLink(w) if t.publicTypeNameOverride != "" { return - // fmt.Fprintf(w, "type %s %s\n", t.PublicName(), t.publicTypeNameOverride) } else { fmt.Fprintf(w, "type %s %s\n", t.PublicName(), t.resolvedUnderlyingType.InternalName()) } diff --git a/def/command_type.go b/def/command_type.go index cbe1208..d24a39e 100644 --- a/def/command_type.go +++ b/def/command_type.go @@ -22,14 +22,12 @@ type commandType struct { parameters []*commandParam - bindingParams []*commandParam - returnParams []*commandParam - // identicalInternalExternal bool - // isReturnedOnly bool + bindingParams []*commandParam + returnParams []*commandParam bindingParamCount int } -// Two exceptions to camelCase rules used for function return params +// Exceptions to camelCase rules used for function return params func init() { // rename return params to avoid typenames strcase.ConfigureAcronym("Result", "r") @@ -73,18 +71,12 @@ func (t *commandType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { } } - // if t.publicName == "" { // publicName may already be set by an entry from exceptions.json - // t.publicName = RenameIdentifier(t.registryName) - // } - for _, p := range t.parameters { p.parentCommand = t iset.MergeWith(p.Resolve(tr, vr)) } - // t.identicalInternalExternal = t.determineIdentical() - iset.ResolvedTypes[t.registryName] = t t.isResolved = true @@ -128,19 +120,9 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { fmt.Fprintf(w, "var %s = %s\n\n", t.PublicName(), t.resolvedAliasType.PublicName()) return } - // funcReturnNames, funcReturnTypes := &strings.Builder{}, &strings.Builder{} preamble, epilogue, outputTranslation := &strings.Builder{}, &strings.Builder{}, &strings.Builder{} - // var doubleCallArrayParam *commandParam - // var doubleCallArrayTypeName string - - // var isDoubleCallCommand bool - - // for _, p := range t.bindingParams { - // funcParams = funcParams + ", " + p.publicName + " " + p.resolvedType.PublicName() - // } - funcReturnParams := make([]*commandParam, 0) var trampolineReturns *commandParam funcInputParams := make([]*commandParam, 0) @@ -154,6 +136,7 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { trampolineReturns = retParam } + // Iterative dev process: // Start with a simple output scenario - vkEndCommandBuffer takes a single // input (ignore for the moment) and returns a VkResult // Deal with simple inputs, like handles and primitive/scalar types @@ -167,20 +150,6 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { // - Go return values // - Trampoline parameters, with or without translation - // if p.isDoubleCallArray { - // isDoubleCallCommand = true - // // This gets saved for later printing the calls - // doubleCallArrayParam = p - - // fmt.Fprintf(funcReturnNames, ", %s", p.publicName) - // retSliceType := p.resolvedType.(*pointerType).resolvedPointsAtType - // fmt.Fprintf(funcReturnTypes, "[]%s", retSliceType.PublicName()) - // } else if p.isOutput { - // fmt.Fprintf(funcReturnNames, ", %s", p.publicName) - // fmt.Fprintf(funcReturnTypes, ", %s", p.resolvedType.PublicName()) - // } else { - // fmt.Fprintf(funcParams, ", %s %s", p.publicName, p.resolvedType.PublicName()) - // } if p.resolvedType.Category() == CatPointer { paramTypeAsPointer := p.resolvedType.(*pointerType) @@ -380,8 +349,6 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { stringParts := strings.Split(p.lenSpec, "->") translatedLenMember := stringParts[0] + "." + stringParts[1] - // fmt.Fprintf(preamble, " sl_%s := make([]%s, %s)\n", p.internalName, p.resolvedType.InternalName(), translatedLenMember) - // fmt.Fprintf(preamble, " %s := &sl_%s[0]\n", p.internalName, p.internalName) fmt.Fprintf(preamble, " %s = make(%s, %s)\n", p.publicName, p.resolvedType.PublicName(), translatedLenMember) fmt.Fprintf(preamble, " %s := &%s[0]\n", p.internalName, p.publicName) @@ -537,47 +504,8 @@ func (t *commandType) printTrampolineCall(w io.Writer, trampParams []*commandPar } } -func (t *commandType) PrintInternalDeclaration(w io.Writer) { - - // var preamble, structDecl, epilogue strings.Builder - - // if t.identicalInternalExternal { - // fmt.Fprintf(w, "type %s = %s\n", t.InternalName(), t.PublicName()) - // } else { - // if t.isReturnedOnly { - // fmt.Fprintf(w, "// WARNING - This struct is returned only, which is not yet handled in the binding\n") - // } - // // _vk type declaration - // fmt.Fprintf(w, "type %s struct {\n", t.InternalName()) - // for _, m := range t.members { - // m.PrintInternalDeclaration(w) - // } - - // fmt.Fprintf(w, "}\n") - // } - - // // Vulkanize declaration - // // Set required values, like the stype - // // Expand slices to pointer and length parameters - // // Convert strings, and string arrays - // fmt.Fprintf(&preamble, "func (s *%s) Vulkanize() *%s {\n", t.PublicName(), t.InternalName()) - - // if t.identicalInternalExternal { - // fmt.Fprintf(&structDecl, " rval := %s(*s)\n", t.InternalName()) - // } else { - // fmt.Fprintf(&structDecl, " rval := %s{\n", t.InternalName()) - // for _, m := range t.members { - // m.PrintVulcDeclarationAsssignment(&preamble, &structDecl, &epilogue) - // } - // fmt.Fprintf(&structDecl, " }\n") - // } - // fmt.Fprintf(&epilogue, " return &rval\n") - // fmt.Fprintf(&epilogue, "}\n") - - // fmt.Fprint(w, preamble.String(), structDecl.String(), epilogue.String()) - - // Goify declaration (if applicable?) -} +// There is no internal declaration for commands, this function is empty +func (t *commandType) PrintInternalDeclaration(w io.Writer) {} type commandParam struct { registryName string @@ -658,7 +586,6 @@ func (p *commandParam) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { if p.isConstParam { if p.lenSpec == "" { p.isInput = true - // p.requiresTranslation = !p.resolvedType.IsIdenticalPublicAndInternal() } else if p.lenMemberParam != nil { // if this param is a const pointer with a len specifier that maps to diff --git a/def/define_type.go b/def/define_type.go index 5fe984c..f1757d2 100644 --- a/def/define_type.go +++ b/def/define_type.go @@ -143,13 +143,6 @@ func ReadDefineExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr V tr[entry.RegistryName()] = entry - // exVal.Get("constants").ForEach(func(ck, cv gjson.Result) bool { - // newVal := NewConstantValue(ck.String(), cv.String(), key.String()) - - // vr[newVal.RegistryName()] = newVal - // return true - // }) - return true }) diff --git a/def/enum_type.go b/def/enum_type.go index c512028..b20b1b2 100644 --- a/def/enum_type.go +++ b/def/enum_type.go @@ -49,7 +49,7 @@ func (t *enumType) PrintPublicDeclaration(w io.Writer) { if len(t.values) > 0 { fmt.Fprint(w, "const (\n") for _, v := range t.values { - v.PrintPublicDeclaration(w) // || !v.IsAlias()) + v.PrintPublicDeclaration(w) } fmt.Fprint(w, ")\n\n") } diff --git a/def/enum_value.go b/def/enum_value.go index a6a6a3b..5d823e0 100644 --- a/def/enum_value.go +++ b/def/enum_value.go @@ -76,7 +76,6 @@ func ReadApiConstantsFromXML(doc *xmlquery.Node, externalType TypeDefiner, tr Ty valDef := NewEnumValueFromXML(externalType, node) valDef.isCore = true vr[valDef.RegistryName()] = valDef - // externalType.PushValue(valDef) } } @@ -115,8 +114,6 @@ func ReadEnumValuesFromXML(doc *xmlquery.Node, td TypeDefiner, tr TypeRegistry, // VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_INFO_KHR // To handle this, we're reading the node and then merging with any val def already in the map - // valDef.isCore = valDef.extNumber != 0 - if existing, found := vr[valDef.RegistryName()]; found { existingAsEnum := existing.(*enumValue) if valDef.extNumber == 0 { @@ -243,8 +240,6 @@ func NewUntypedEnumValueFromXML(elt *xmlquery.Node) *extenValue { } rval.comment = elt.SelectAttr("comment") - // rval.underlyingTypeName = "!none" - return &rval } diff --git a/def/external_type.go b/def/external_type.go index d156a0d..d4d1658 100644 --- a/def/external_type.go +++ b/def/external_type.go @@ -116,7 +116,6 @@ func NewOrUpdateExternalValueFromJSON(key, value string, td TypeDefiner, tr Type updatedEntry.isCore = true vr[key] = updatedEntry - // td.PushValue(updatedEntry) } func (t *externalType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { diff --git a/def/generic_type.go b/def/generic_type.go index 0d00260..996c049 100644 --- a/def/generic_type.go +++ b/def/generic_type.go @@ -100,26 +100,6 @@ func (t *genericType) PrintTranslateToInternal(w io.Writer, inputVar, outputVar fmt.Fprintf(w, "%s = %s", outputVar, inputVar) } -// func (t *genericType) PrintConstValues(w io.Writer) { -// switch len(t.values) { -// case 0: -// return -// case 1: -// fmt.Fprintln(w) -// fmt.Fprint(w, "const ") -// t.values[0].PrintPublicDeclaration(w, true) -// fmt.Fprintln(w) -// default: -// fmt.Fprintln(w) -// fmt.Fprintln(w, "const (") -// for _, v := range t.values { -// v.PrintPublicDeclaration(w, !v.IsAlias()) -// } -// fmt.Fprintln(w, ")") -// fmt.Fprintln(w) -// } -// } - func (t *genericType) PrintDocLink(w io.Writer) { fmt.Fprintf(w, "// %s: ", t.PublicName()) if t.comment != "" { diff --git a/def/handle_type.go b/def/handle_type.go index 44fb709..f290732 100644 --- a/def/handle_type.go +++ b/def/handle_type.go @@ -84,8 +84,6 @@ func ReadHandleExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr V newVal.valueString = cv.String() newVal.underlyingTypeName = key.String() - // newVal := NewEnumValue(ck.String(), cv.String(), key.String()) - vr[newVal.RegistryName()] = &newVal return true }) diff --git a/def/internal_type.go b/def/internal_type.go index 5b3cee5..3c87a98 100644 --- a/def/internal_type.go +++ b/def/internal_type.go @@ -44,14 +44,4 @@ func (t *internalType) PrintPublicDeclaration(w io.Writer) { } else { fmt.Fprintf(w, "type %s %s\n", t.PublicName(), t.underlyingType.PublicName()) } - - // sort.Sort(byValue(t.values)) - - // if len(t.values) > 0 { - // fmt.Fprint(w, "const (\n") - // for _, v := range t.values { - // v.PrintPublicDeclaration(w) - // } - // fmt.Fprint(w, ")\n\n") - // } } diff --git a/def/name_conversion.go b/def/name_conversion.go index b467a33..0213ec0 100644 --- a/def/name_conversion.go +++ b/def/name_conversion.go @@ -12,6 +12,7 @@ func trimVk(s string) string { return s } r := trimRx.FindStringSubmatch(s) + // Match References: // r[0] = s // r[1] = pointers // r[2] = Vk, vk, or VK_ diff --git a/def/pointer_type.go b/def/pointer_type.go index f366504..f1875e3 100644 --- a/def/pointer_type.go +++ b/def/pointer_type.go @@ -61,9 +61,6 @@ func (t *pointerType) PublicName() string { func (t *pointerType) InternalName() string { if t.resolvedPointsAtType.InternalName() == "!none" || t.resolvedPointsAtType.InternalName() == "" { return "unsafe.Pointer" - // } else if t.resolvedPointsAtType.Category() == CatUnion { - // // Vulkan unions are just unsafe.Pointers on the internal side, don't need the asterisk - // return t.resolvedPointsAtType.InternalName() } return "*" + t.resolvedPointsAtType.InternalName() } @@ -106,19 +103,7 @@ func (t *pointerType) PrintVulkanizeContent(forMember *structMember, preamble io fmt.Fprint(preamble, pre) structMemberAssignment = "psl_" + forMember.InternalName() } else { - var pre string - // if forMember.resolvedType.Category() == CatPointer && forMember.resolvedType.(*pointerType).resolvedPointsAtType.Category() == CatUnion { - // pre = fmt.Sprintf(sliceTranslationTemplate, - // forMember.InternalName(), "*"+forMember.resolvedType.InternalName(), - // forMember.PublicName(), - // forMember.InternalName(), t.resolvedPointsAtType.InternalName(), forMember.PublicName(), - // forMember.PublicName(), - // forMember.InternalName(), t.resolvedPointsAtType.TranslateToInternal("v"), - // forMember.InternalName(), forMember.InternalName(), - // ) - - // } else { - pre = fmt.Sprintf(sliceTranslationTemplate, + pre := fmt.Sprintf(sliceTranslationTemplate, forMember.InternalName(), forMember.resolvedType.InternalName(), forMember.PublicName(), forMember.InternalName(), t.resolvedPointsAtType.InternalName(), forMember.PublicName(), @@ -127,8 +112,6 @@ func (t *pointerType) PrintVulkanizeContent(forMember *structMember, preamble io forMember.InternalName(), forMember.InternalName(), ) - // } - fmt.Fprint(preamble, pre) structMemberAssignment = "psl_" + forMember.InternalName() } @@ -178,7 +161,7 @@ func (t *pointerType) PrintPublicToInternalTranslation(w io.Writer, publicValueN fmt.Fprintf(w, "%s := &sl_%s[0]\n", internalValueName, internalValueName) if t.lenSpec != "" { - // if lenspec is empty this is one of the few altlen element + // if lenspec is empty this is one of the few altlen elements fmt.Fprintf(w, "%s := uint32(len(sl_%s))\n", t.lenSpec, internalValueName) } @@ -204,18 +187,14 @@ func (t *pointerType) PrintPublicToInternalTranslation(w io.Writer, publicValueN fmt.Fprintf(w, "%s := &sl_%s[0]\n", internalValueName, internalValueName) if t.lenSpec != "" { - // if lenspec is empty this is one of the few altlen element + // if lenspec is empty this is one of the few altlen elements fmt.Fprintf(w, "%s := uint32(len(sl_%s))\n", t.lenSpec, internalValueName) } } else if t.externalSlice { - // if t.resolvedPointsAtType.IsIdenticalPublicAndInternal() { - // fmt.Fprintf(w, "%s = (*%s)(&%s[0])\n", internalValueName, t.resolvedPointsAtType.InternalName(), publicValueName) - // fmt.Fprintf(w, "%s = len(%s)\n", internalLengthName, publicValueName) - // } else { // // TODO: Need to translate each value in the slice... fmt.Fprintf(w, "// marked as external slice TODO Translate each item in the slice\n") - // } + } else if t.resolvedPointsAtType.Category() == CatStruct { fmt.Fprintf(w, "%s := %s.Vulkanize()\n", internalValueName, publicValueName) } @@ -241,8 +220,6 @@ func (t *pointerType) PrintInternalToPublicTranslation(w io.Writer, internalLeng fmt.Fprintf(w, "%s := make([]%s, %d)\n", publicValueName, t.resolvedPointsAtType.InternalName(), internalLength) fmt.Fprintf(w, "TODO: translate/copy values into slice\n") } - // if t.resolvedPointsAtType.IsIdenticalPublicAndInternal() { - // fmt.Fprintf(w, "%s := make([]%s, %d)\n", publicValueName, t.resolvedPointsAtType.InternalName(), internalLength) - // } + } } diff --git a/def/struct_type.go b/def/struct_type.go index 1a6af59..a8549bd 100644 --- a/def/struct_type.go +++ b/def/struct_type.go @@ -90,7 +90,7 @@ func (t *structType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { if m.resolvedType.PublicName() != "unsafe.Pointer" /*&& n.isLenForOtherMember == nil*/ { n.isLenForOtherMember = append(n.isLenForOtherMember, m) - // Edge case for (apparently only) VkWriteDescriptorSet...three arrays types, only one of which + // Edge case for (apparently only) VkWriteDescriptorSet...three array types, only one of which // will be populated. Flagging the len member to use the max length of the three input slices. // In practice, only one of the three should be populated. // if m.noAutoValidityFlag && len(n.isLenForOtherMember) > 1 { @@ -179,7 +179,6 @@ func (t *structType) PrintInternalDeclaration(w io.Writer) { fmt.Fprintf(w, "}\n") } - // if t.isReturnedOnly { // Goify declaration fmt.Fprintf(&preamble, "func (s *%s) Goify() *%s {\n", t.InternalName(), t.PublicName()) @@ -200,7 +199,6 @@ func (t *structType) PrintInternalDeclaration(w io.Writer) { fmt.Fprint(w, preamble.String(), structDecl.String(), epilogue.String()) preamble, structDecl, epilogue = strings.Builder{}, strings.Builder{}, strings.Builder{} - // } else { // Vulkanize declaration // Set required values, like the stype @@ -224,14 +222,14 @@ func (t *structType) PrintInternalDeclaration(w io.Writer) { fmt.Fprintf(&epilogue, "}\n") fmt.Fprint(w, preamble.String(), structDecl.String(), epilogue.String()) - // } + } func (m *structMember) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { m.publicName = strings.Title(RenameIdentifier(m.registryName)) m.internalName = RenameIdentifier(m.registryName) - // This automatically handles non-pointer types + // This automatically handles non-pointer types, i.e. pointerDepth == 0 previousTarget := tr[m.typeRegistryName] for i := m.pointerDepth; i > 0; i-- { pt := pointerType{} @@ -373,7 +371,6 @@ func (m *structMember) PrintVulanizeContent(preamble, structDecl, epilogue io.Wr default: fmt.Fprintf(structDecl, " %s : %s,/*default*/\n", m.InternalName(), m.resolvedType.TranslateToInternal("s."+m.PublicName())) - // fmt.Fprintf(structDecl, "%s: 0, // FELL THROUGH PRINT VULKANIZE CONTENT\n", m.InternalName()) } } @@ -410,6 +407,7 @@ func (m *structMember) PrintGoifyContent(preamble, structDecl, epilogue io.Write // pt := m.resolvedType.(*pointerType) // toBeAssigned := pt.PrintGoifyContent(m, preamble) // fmt.Fprintf(structDecl, " %s : %s,/*c rem*/\n", m.InternalName(), toBeAssigned) + fmt.Fprintf(structDecl, " // Unexpected pointer member %s in returned struct\n", m.InternalName()) case m.resolvedType.Category() == CatArray: at := m.resolvedType.(*arrayType) @@ -480,10 +478,8 @@ func newStructMemberFromXML(node *xmlquery.Node) *structMember { // Go, and struct members have a related length member. But in certain // cases, we will need handle it differently. For example, char* // is transformed to a string using a null byte termination. - // (Of course this is not strictly correct, because char* implies ASCII - // encoding, but a Go string is UTF-8.) - rval.typeRegistryName = xmlquery.FindOne(node, "type").InnerText() // + strings.Repeat("*", rval.pointerDepth) + rval.typeRegistryName = xmlquery.FindOne(node, "type").InnerText() if rval.typeRegistryName == "void" && rval.pointerDepth == 1 { // special case for void* struct members...exceptions.json maps the member to unsafe.Pointer instead of byte* rval.typeRegistryName = "void*" diff --git a/def/union_type.go b/def/union_type.go index 68c4d5e..9e281b8 100644 --- a/def/union_type.go +++ b/def/union_type.go @@ -25,9 +25,6 @@ func (t *unionType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { } is := t.structType.Resolve(tr, vr) - // for _, m := range t.members { - // m.publicName = strcase.ToLowerCamel(m.publicName) - // } is.ResolvedTypes[t.registryName] = t t.isResolved = true @@ -102,25 +99,25 @@ func (t *unionType) PrintInternalDeclaration(w io.Writer) { fmt.Fprintf(w, "func (u *%s) Vulkanize() *%s {\n", t.PublicName(), t.InternalName()) fmt.Fprintf(w, " switch true {\n") - // return (*_vkClearDepthStencilValue)(unsafe.Pointer(s)) + for _, m := range t.members { fmt.Fprintf(w, " case u.as%s:\n", m.PublicName()) fmt.Fprintf(w, " return (*%s)(unsafe.Pointer(&u.%s))\n", t.InternalName(), m.PublicName()) // TODO should be tested but I think there is a bug here. If I have a union with mixed 32 and 64 bit types, and I cast a // 32 bit field as 64 bits (as an 8 byte array), will the field be in the most significant bits of the array? + // Where does Vulkan/C expect them to be? } fmt.Fprintf(w, " default:\nreturn &%s{}\n", t.InternalName()) fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") + // Don't attempt to Goify for now. There may be a command that returns a union, how to handle that TBD // fmt.Fprintf(w, "func (u *%s) Goify() %s {\n", t.InternalName(), t.PublicName()) // fmt.Fprintf(w, " panic(\"Cannot Goify to a Vulkan union type!\")\n") // fmt.Fprintf(w, "}\n") fmt.Fprint(w, preamble.String(), structDecl.String(), epilogue.String()) - - // Goify declaration (if applicable?) } func (t *unionType) TranslateToInternal(inputVar string) string { diff --git a/feat/feature.go b/feat/feature.go index fdd9807..501c68e 100644 --- a/feat/feature.go +++ b/feat/feature.go @@ -63,7 +63,6 @@ func (f *Feature) Resolve(tr def.TypeRegistry, vr def.ValueRegistry) { for k := range f.requireValueNames { val := vr[k] - // later merge valset into the TD? f.MergeIncludeSet(val.Resolve(tr, vr)) resVals, found := f.ResolvedValues[val.UnderlyingTypeName()] @@ -91,7 +90,7 @@ func (f *Feature) FilterByCategory() map[def.TypeCategory]*Feature { // Stuff all the values, segmented first by category then by type, into the new Feature // Lots of maps to make... for _, vr := range f.ResolvedValues { - // Default category to None + // Default category reset before starting the inner loop cat := def.CatExten for valName, valDef := range vr { @@ -123,7 +122,7 @@ func ReadFeatureFromXML(featureNode *xmlquery.Node, tr def.TypeRegistry, vr def. rval.version = featureNode.SelectAttr("number") for _, reqNode := range xmlquery.Find(featureNode, "/require") { - for _, typeNode := range xmlquery.Find(reqNode, "/type") { //} or /command") { + for _, typeNode := range xmlquery.Find(reqNode, "/type") { rval.requireTypeNames[typeNode.SelectAttr("name")] = true } diff --git a/main.go b/main.go index e1612ce..eba3314 100644 --- a/main.go +++ b/main.go @@ -74,11 +74,6 @@ func main() { Fatal("Could not parse XML from the provided file") } - // feats := def.BuildVulkanFeatureSetFromXML(doc, "vulkan", "1.0") - - // tcs := make(def.TypeContainerSet) - // tcs[def.Include] = def.AllIncludeTypesFromXML(doc) - exceptionsBytes, err := os.ReadFile("exceptions.json") if err != nil { logrus.WithField("error", err). @@ -148,7 +143,7 @@ func main() { commandCount := 0 - for tc, reg := range vk1_0.FilterByCategory() { //ResolvedTypes().FilterByCategory() { + for tc, reg := range vk1_0.FilterByCategory() { if tc == def.CatHandle { // Special case...VK_NULL_HANDLE is included by vk.xml as a type, not an enum. vk-gen treats it as a // ValueDefiner, so it must be manually added to the feature registry. @@ -168,14 +163,10 @@ func main() { continue } - // for _, ext := range plat.Extensions() { - // ext.Resolve(globalTypes, globalValues) - // } - pf := plat.GeneratePlatformFeatures() pf.Resolve(globalTypes, globalValues) - for tc, reg := range pf.FilterByCategory() { //ResolvedTypes().FilterByCategory() { + for tc, reg := range pf.FilterByCategory() { printCategory(tc, reg, plat, commandCount) if tc == def.CatCommand { commandCount += len(reg.ResolvedTypes) @@ -183,89 +174,27 @@ func main() { } } - // set.MergeWith(def.ReadFeatureFromXML(xmlquery.FindOne(xmlDoc, "//feature[@name='VK_VERSION_1_1']"), globalTypes, globalValues)) - // ext := def.ReadAllExtensionsFromXML(xmlDoc, globalTypes, globalValues) - // extMap := def.SegmentExtensionsByPlatform(ext) - - // for k, v := range extMap { - // if feat, found := pm[k]; found { - // for _, ext := range v { - // feat.MergeWith(ext) - // } - // } else { - // logrus.Infof("No platform entry for %s", k) - // for _, ext := range v { - // set.MergeWith(ext) - // } - // } - // } - - // set.MergeWith(externalTypes) - - // resolve against a feature set - // set := def.TestingIncludes(globalTypes) - - // set.Resolve(globalTypes, globalValues) - - // for tc, reg := range set.FilterTypesByCategory() { //ResolvedTypes().FilterByCategory() { - // fname := reg.FilenameFragment() - // plat := reg.Platform() - - // _, _ = fname, plat - // printCategory(tc, reg, "") - // } - - // for platformKey, platformFeats := range pm { - // platformFeats.Resolve(globalTypes, globalValues) - // logrus.Infof("Writing platform %s...", platformKey) - - // for tc, reg := range platformFeats.FilterTypesByCategory() { - // printCategory(tc, reg, platformKey) - // } - - // } - copyStaticFiles() - // logrus.Info("Running go generate on output") - // cmd := exec.Command("go", "generate") - // e := &strings.Builder{} - // cmd.Stderr = e - // cmd.Dir = outDirName - - // gogenErr := cmd.Run() - // if gogenErr != nil { - // logrus. - // WithField("error", gogenErr.Error()). - // WithField("stderr output", e.String()). - // Error("go generate failed") - // } } const fileHeader string = "// Code generated by go-vk from %s at %s. DO NOT EDIT.\n\npackage vk\n\n" // fix doc/issue-1 -func printCategory(tc def.TypeCategory, fc *feat.Feature, platform *feat.Platform, startingCount int) { //} pt *def.PlatformType, cat def.TypeCategory, tr def.TypeRegistry) { +func printCategory(tc def.TypeCategory, fc *feat.Feature, platform *feat.Platform, startingCount int) { if tc == def.CatInclude { return } reg := fc.ResolvedTypes - // vals := reg.Val if len(reg) == 0 && len(fc.ResolvedValues) == 0 { return } - // filename := fc.FilenameFragment() - // if platform != "" { - // filename = filename + "_" + platform - // } - filename := strings.ToLower(strings.TrimPrefix(tc.String(), "Cat")) if platform != nil { filename = filename + "_" + platform.Name() } - // filename = filename + ".go" outpath := fmt.Sprintf("%s/%s", outDirName, filename+".go") @@ -295,9 +224,7 @@ func printCategory(tc def.TypeCategory, fc *feat.Feature, platform *feat.Platfor } sort.Sort(def.ByName(types)) - // if cat == def.Enum { def.WriteStringerCommands(f, types, tc, filename) - // } importMap := make(def.ImportMap) for _, t := range types { @@ -350,8 +277,6 @@ func printTypes(w io.Writer, types []def.TypeDefiner, vals map[string]def.ValueR v.PrintPublicDeclaration(contentBuf) v.PrintInternalDeclaration(contentBuf) - // TODO PRINT VALUES vals[v.RegistryName] - v.PrintFileInitContent(initBuf) // Intentionally called after public declaration, which may do some processing needed for file init() } diff --git a/static_include/static_basetype.go b/static_include/static_basetype.go index 2693dc0..fcd6626 100644 --- a/static_include/static_basetype.go +++ b/static_include/static_basetype.go @@ -1,8 +1,11 @@ package vk +// translatePublic_Bool32 is a type conversion function for special handling of Bool32 to bool. It is associated with the Bool32 type through exceptions.json func translatePublic_Bool32(val Bool32) bool { return val != Bool32(FALSE) } + +// translateInternal_Bool32 is a type conversion function for special handling of bool to Bool32. It is associated with the Bool32 type through exceptions.json func translateInternal_Bool32(val bool) Bool32 { if val { return Bool32(TRUE) diff --git a/static_include/static_common.go b/static_include/static_common.go index f082102..e272acb 100644 --- a/static_include/static_common.go +++ b/static_include/static_common.go @@ -33,7 +33,6 @@ func max(nums ...int) int { } // Error implements the error interface -// TODO: Enhance this method to provide error messages from the OS (?) // TODO: A way for commands to indicate if the Result code is an error for that command, or an unexpected return value? func (r Result) Error() string { return r.String() @@ -98,7 +97,6 @@ func execTrampoline(commandKey vkCommandKey, args ...uintptr) uintptr { } var result C.uintptr_t - // var err error switch cmd.argCount { case 1: @@ -143,24 +141,3 @@ func nullTermBytesToString(b []byte) string { n := bytes.IndexByte(b, 0) return string(b[:n]) } - -// func getStringFromPtr(ptr uintptr, len int) string { -// var sl = struct { -// addr uintptr -// len int -// cap int -// }{ptr, len, len} -// return string(*(*[]byte)(unsafe.Pointer(&sl))) -// } -// func nullTermBytesToString(b *byte) string { -// rawPtr := uintptr(unsafe.Pointer(b)) -// strLen := uintptr(0) - -// var nextB byte -// nextB = *(*byte)(unsafe.Pointer(rawPtr + strLen)) - -// for nextB = *(*byte)(unsafe.Pointer(rawPtr)); nextB != 0; strLen++ { -// } - -// return getStringFromPtr(rawPtr, int(strLen)) -// } From 03b096d181de30b6b495b4d8d0dacaaff64e9322 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Thu, 9 Mar 2023 09:57:35 -0600 Subject: [PATCH 2/2] Update docs/comments --- DesignNotes.md | 4 ++++ README.md | 3 --- static_include/README.md | 13 ++----------- static_include/static_defines.go | 3 +++ static_include/static_mem.go | 4 ++-- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/DesignNotes.md b/DesignNotes.md index 14e84d1..c0d2de8 100644 --- a/DesignNotes.md +++ b/DesignNotes.md @@ -2,6 +2,10 @@ vk.xml schema documentation: [https://registry.khronos.org/vulkan/specs/1.3/registry.html] +This file documents some of the thought process and tasks during development of vk-gen. This file remains for historical +reference, but the codebase has grown beyond what is detailed here and you should not assume that this file describes +precisely how the tool works. + ## vk.xml and exceptions.json There are several significant barriers to generating the Go-binding for Vulkan: diff --git a/README.md b/README.md index e965000..9c4269c 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,3 @@ issue/PR will clean this up, but they don't hurt anything at the moment. anything that resolves to a constant in Go, though most typically it will be an integer value (represented as a string). The value should be the aligned (?) data size in bytes of the largest member of the union. -## TODO - -* VkDescriptorDataEXT - Pointer members are being recognized as slices, compile error on slice copy. diff --git a/static_include/README.md b/static_include/README.md index 11483dc..783ee45 100644 --- a/static_include/README.md +++ b/static_include/README.md @@ -229,7 +229,7 @@ than 1.18 (and hence do not have access to generics). In that case you could ven delete the two generic functions. **There are no guardrails on any of these functions! You, the developer, are repsonbile for allocating enough memory -from Vulkan at the destination before calling them.** +at the destination before calling them.** They do not (and cannot) check how much space is available behind the pointer you give them. Under the hood, they create "fake" byte slices at the destination pointer and the source pointer or at the head of the input slice. It then uses Go's copy macro @@ -269,9 +269,6 @@ ccv.AsTypeFloat32(float32[4]{0.0, 0.0, 0.0, 1.0}) See the [go-vk-samples](https://github.com/bbredesen/go-vk-samples) repo for a number of working Vulkan samples using this library. The samples currently only run on Windows. -Minimal testing of `go-vk` has been done against Mac/MoltenVK. Mac versions of the samples will be coming in -the future. No testing has been done (yet) on Linux or other platforms. - ## Known Issues * VkAccelerationStructureMatrixMotionInstanceNV - embedded bit fields in uint32_t are not handled at all...this @@ -279,10 +276,4 @@ the future. No testing has been done (yet) on Linux or other platforms. * H.264 and H.265 commands and types are almost certainly broken. There is no structured specification file similar to vk.xml (that I've found) for the video functions and required types. Instead, the types are directly included through vk.xml as C headers. As a placeholder, all of these types are defined as int32 through exceptions.json. These types - may end up hard-coded. -* vkGetPipelinePropertiesEXT - as of 1.3.240, this is the single command that uses VkBaseOutStructure as a parameter type. - BaseOutStructure (and BaseInStrucutre) are set to be ignored in the binding because they are self-referential and - cause infinite recursion in Resolve(). For the moment, I'm manually updating that parameter to struct{}. -* in/out structures (e.g., VkPhysicalDeviceFeatures2) need to be Vulkanized before passing in, not just allocated on the - Vulkan side. Vulkan is silently failing (i.e. no validation layers report, no error code) when structure type is not - set. Manual update to call Vulkanize on the named return parameter, and then Goify before return. \ No newline at end of file + may end up hard-coded. \ No newline at end of file diff --git a/static_include/static_defines.go b/static_include/static_defines.go index bca6243..87af381 100644 --- a/static_include/static_defines.go +++ b/static_include/static_defines.go @@ -1,5 +1,8 @@ package vk +// The functions in this file are Go versions of C preprocessor macros from vk.xml. Each function here is associated with its +// Vulkan name through exceptions.json + func deprecatedMakeVersion(major, minor, patch uint32) uint32 { return major<<22 | minor<<12 | patch } diff --git a/static_include/static_mem.go b/static_include/static_mem.go index 4c5e6f9..4925b63 100644 --- a/static_include/static_mem.go +++ b/static_include/static_mem.go @@ -32,7 +32,7 @@ intended for use with mapped memory ranges. Note that the destination is passed cannot determine if you have allocated enough memory at that location. You are responsible for requesting enough memory from Vulkan! Unexpected behavior or crashes are very possible if this function is misused or abused. -If you pass a slice to this function, the slice header will be copied, not the contents! See also MemCopySlice. +NOTE: If you pass a slice to this function, the slice header will be copied, not the contents! Use [MemCopySlice] instead. */ func MemCopyObj[T any](dest unsafe.Pointer, src *T) { bytes := int(unsafe.Sizeof(*src)) @@ -44,7 +44,7 @@ func MemCopyObj[T any](dest unsafe.Pointer, src *T) { } /* MemCopy is the closest to C's memcpy...you provide two pointers and a number of bytes to copy, and it will move the -data around. Using MemCopySlice or MemCopyObj instead is highly recommended. There are no guardrails on this function! +data around. Using [MemCopySlice] or [MemCopyObj] instead is highly recommended. There are no guardrails on this function! */ func MemCopy(dest, src unsafe.Pointer, len int) { sl_src := *(*[]byte)(unsafe.Pointer(&sl{uintptr(src), len, len}))