From 5aebca65ed0de60899e6ea6db8d0e18abdd6b4c1 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 7 Mar 2023 10:13:49 -0500 Subject: [PATCH 01/15] Generics require go 1.18 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6de80d8..0ed2709 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bbredesen/vk-gen -go 1.17 +go 1.18 require ( github.com/antchfx/xmlquery v1.3.13 From a2d7a24357b4dabbf106349ff37dddaf747772df Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 7 Mar 2023 10:23:39 -0500 Subject: [PATCH 02/15] Spelling fixes --- README.md | 4 ++-- def/command_type.go | 4 ++-- def/define_type.go | 2 +- def/enum_value.go | 2 +- def/registry_extensions.go | 2 +- def/struct_type.go | 4 ++-- main.go | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 418a0be..e965000 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ vk-gen is a tool used to create Go bindings for the Vulkan graphics API. It uses the Vulkan XML specification to generate all type definitions and native function calls for the API. It generates the code for [go-vk](https://github.com/bbredesen/go-vk), but it can just as well be used to create a modified binding set in your -own projects (for example, excluding certain vendor extensions, incluidng beta extensions, or to generate code from a +own projects (for example, excluding certain vendor extensions, including beta extensions, or to generate code from a specific version of the Vulkan headers). ## Basic Usage @@ -40,7 +40,7 @@ issue/PR will clean this up, but they don't hurt anything at the moment. * `go:internalSize` - Go has no notion of union types. This field allows you to specify a size for the public to internal translation result. By default, vk-gen will use the size of the first member in the union, but that is - not neccesarily the largest member. This value must be a string and is copied to an array declaration. It can be + not necessarily the largest member. This value must be a string and is copied to an array declaration. It can be 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. diff --git a/def/command_type.go b/def/command_type.go index 0b8fb6a..8a0b106 100644 --- a/def/command_type.go +++ b/def/command_type.go @@ -309,7 +309,7 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { t.printTrampolineCall(epilogue, funcTrampolineParams, trampolineReturns) fmt.Fprintln(epilogue) - // If the output requires tranlation, iterate the slice and translate here + // If the output requires translation, iterate the slice and translate here fmt.Fprintf(epilogue, outputTranslation.String()) } @@ -371,7 +371,7 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { 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) - // At a practical level, this is only used to return an array of handles, we can avoid tranlation altogether; see + // At a practical level, this is only used to return an array of handles, we can avoid translation altogether; see // AllocateCommandBuffers for an example. It is possible that a future API release will need // updates here. diff --git a/def/define_type.go b/def/define_type.go index 1a7d6d2..5fe984c 100644 --- a/def/define_type.go +++ b/def/define_type.go @@ -70,7 +70,7 @@ func ReadDefineTypesFromXML(doc *xmlquery.Node, tr TypeRegistry, _ ValueRegistry var s = unsafe.Sizeof(uintptr(0)) -// NewDefineTypeFromXML has a few procesing paths. First, the name is typically +// NewDefineTypeFromXML has a few processing paths. First, the name is typically // a child node, but is an XML attribute for a few entries. Next, some defines // such as VK_API_VERSION_1_0 are actually macro calls, which is named in a // child node for type. Defines may also have a requires attr, which also diff --git a/def/enum_value.go b/def/enum_value.go index 936199d..a6a6a3b 100644 --- a/def/enum_value.go +++ b/def/enum_value.go @@ -166,7 +166,7 @@ func NewEnumValueFromXML(td TypeDefiner, elt *xmlquery.Node) *enumValue { rval.direction = 1 } - // Only applies when an extension is promoted to core, otherwise the Extensioner needs to add the extention number to the value + // Only applies when an extension is promoted to core, otherwise the Extensioner needs to add the extension number to the value extNumStr := elt.SelectAttr("extnumber") if extNumStr != "" { if rval.extNumber, err = strconv.Atoi(extNumStr); err != nil { diff --git a/def/registry_extensions.go b/def/registry_extensions.go index bd0797d..62ced47 100644 --- a/def/registry_extensions.go +++ b/def/registry_extensions.go @@ -58,7 +58,7 @@ func ReadAllExtensionsFromXML(doc *xmlquery.Node, tr TypeRegistry, vr ValueRegis } // Enum values are actually defined in the extension, though they may be re-defined or partially defined - // elsehwere if the extension was promoted to core. Add the value name, plus create the ValueDefiner and put + // elsewhere if the extension was promoted to core. Add the value name, plus create the ValueDefiner and put // it in the registry. for _, enumNode := range xmlquery.Find(reqNode, "/enum") { // Also, bitmasks and values with offsets are defined in the same place, so first figure out which type diff --git a/def/struct_type.go b/def/struct_type.go index 4cd57c0..5e496a4 100644 --- a/def/struct_type.go +++ b/def/struct_type.go @@ -315,7 +315,7 @@ func (m *structMember) PrintInternalDeclaration(w io.Writer) { // struct and directly assign it to the output struct // 3) Embedded structs - we can Vulkanize and dereference the embedded struct in // the output struct declaration. -// 4) Slices of "IsIdential..." types - assign the address of the 0 element. +// 4) Slices of "IsIdentical..." types - assign the address of the 0 element. // 5) Slices of non-"IsIdentical..." types - build a temporary slice of the // translated values, and then assign the 0-address as above. // 6) Length fields - Array pointers have an associated length member in the @@ -379,7 +379,7 @@ func (m *structMember) PrintGoifyContent(preamble, structDecl, epilogue io.Write case m.isLenForOtherMember != nil: // Edge case 6 happens, but is not identified in vk.xml. // Example: VkPhysicalDeviceMemoryProperties has two fixed length - // arrays, each of which has an associated lenght member to indicate how + // arrays, each of which has an associated length member to indicate how // many values were returned. The XML file does not link those fields // via "len" on the arrays. You could probably infer the information // because the member names are (e.g.) memoryTypeCount and memoryTypes. diff --git a/main.go b/main.go index 41a63d9..70f5e3a 100644 --- a/main.go +++ b/main.go @@ -267,7 +267,7 @@ func printCategory(tc def.TypeCategory, fc *feat.Feature, platform *feat.Platfor outpath := fmt.Sprintf("%s/%s", outDirName, filename+".go") f, _ := os.Create(outpath) - // explict f.Close() below; not defered because the file must be written to disk before goimports is run + // explicit f.Close() below; not deferred because the file must be written to disk before goimports is run if platform != nil && platform.GoBuildTag != "" { fmt.Fprintf(f, "//go:build %s\n", platform.GoBuildTag) @@ -400,7 +400,7 @@ func copyStaticFiles() { logrus.Info("Copying static files") source := "static_include" - // Naieve solution from https://stackoverflow.com/questions/51779243/copy-a-folder-in-go + // Naive solution from https://stackoverflow.com/questions/51779243/copy-a-folder-in-go var err error = filepath.Walk(source, func(path string, info os.FileInfo, err error) error { var relPath string = strings.Replace(path, source, "", 1) if relPath == "" { From cd54fe0a4e5bbfafc60487edef19b6d96865aeca Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 7 Mar 2023 13:16:46 -0500 Subject: [PATCH 03/15] Fix spelling in exceptions.json --- exceptions.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exceptions.json b/exceptions.json index 990e55b..e0148b0 100644 --- a/exceptions.json +++ b/exceptions.json @@ -128,7 +128,7 @@ "external" : { "int8_t": { "go:type": "int8", "primitive": true, - "comment": "Primitive indicates a direct replacement? Neccessary or not?" }, + "comment": "Primitive indicates a direct replacement? Necessary or not?" }, "uint8_t": { "go:type": "uint8", "primitive": true }, "int16_t": { "go:type": "int16", "primitive": true }, "uint16_t": { "go:type": "uint16", "primitive": true }, @@ -274,7 +274,7 @@ "basetype": { "VkBool32": { - "!comment": "must be re-defined as an exception, becuase vk.xml specifies the type of VK_TRUE/FALSE as uint32_t, not VkBool32, and because the translation is non-trivial", + "!comment": "must be re-defined as an exception, because vk.xml specifies the type of VK_TRUE/FALSE as uint32_t, not VkBool32, and because the translation is non-trivial", "comment": "Note that go-vk uses standard Go bools throughout the public API. Bool32 is only used internally and is automatically translated for you.", "go:type": "bool", "go:translatePublic": "translatePublic_Bool32", From 57d17e9112603f338c046a48590176f8cfbd5e96 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Tue, 7 Mar 2023 15:14:12 -0600 Subject: [PATCH 04/15] Solved basein/baseout recursion issue, issue #4 --- def/struct_type.go | 9 ++++++++- exceptions.json | 8 -------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/def/struct_type.go b/def/struct_type.go index 5e496a4..1b75bfd 100644 --- a/def/struct_type.go +++ b/def/struct_type.go @@ -50,6 +50,8 @@ func (t *structType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { return NewIncludeSet() } + t.isResolved = true // Moved here from end of function as part of issue #4 fix + if t.publicName == "!ignore" { t.isResolved = true return NewIncludeSet() @@ -108,15 +110,20 @@ func (t *structType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { rb.ResolvedTypes[t.registryName] = t - t.isResolved = true return rb } func (t *structType) IsIdenticalPublicAndInternal() bool { for _, m := range t.members { + // part of fix for issue #4 + if asPointerType, isPointer := m.resolvedType.(*pointerType); isPointer && asPointerType.resolvedPointsAtType == t { + continue + } + if !m.IsIdenticalPublicAndInternal() { return false } + } return true } diff --git a/exceptions.json b/exceptions.json index 990e55b..a28fcc4 100644 --- a/exceptions.json +++ b/exceptions.json @@ -315,14 +315,6 @@ }, "struct": { - "VkBaseInStructure": { - "publicName": "!ignore", - "!comment": "Causes a stack overflow in resolution by recursive self-referencing. Declares pNext, formally part of the API, but never actually used anywhere else." - }, - "VkBaseOutStructure": { - "publicName": "!ignore", - "!comment": "See VkBaseInStructure" - }, "VkDescriptorSetLayoutBinding": { "forceIncludeMember": "descriptorCount", "forceIncludeComment": "descriptorCount references an array field in the XML, but that field might be null and then descriptor count has a different meaning. See the man pages/spec." From 466c0a4eb7c05e2ea83fe03e2590f6c7bbc4e71d Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Tue, 7 Mar 2023 15:49:31 -0600 Subject: [PATCH 05/15] add VK_REMAINING_3D_SLICES_EXT for 1.3.242 --- exceptions.json | 1 + 1 file changed, 1 insertion(+) diff --git a/exceptions.json b/exceptions.json index 990e55b..12c9f86 100644 --- a/exceptions.json +++ b/exceptions.json @@ -138,6 +138,7 @@ "enums": { "VK_REMAINING_MIP_LEVELS": "^uint32(0)", "VK_REMAINING_ARRAY_LAYERS": "^uint32(0)", + "VK_REMAINING_3D_SLICES_EXT": "^uint32(0)", "VK_ATTACHMENT_UNUSED": "^uint32(0)", "VK_QUEUE_FAMILY_IGNORED": "^uint32(0)", "VK_QUEUE_FAMILY_EXTERNAL": "^uint32(1)", From ca41a0de7de0dc09d85436a8b1b01f41b8bc333e Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Wed, 8 Mar 2023 12:10:05 -0600 Subject: [PATCH 06/15] Handle pointer members in unions, bugfix/issue-16 --- def/union_type.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/def/union_type.go b/def/union_type.go index 35b8010..6e67a9c 100644 --- a/def/union_type.go +++ b/def/union_type.go @@ -49,7 +49,7 @@ func (t *unionType) PrintPublicDeclaration(w io.Writer) { for i, m := range t.members { if m.pointerDepth > 0 && m.resolvedType.PublicName() != "string" { - if m.resolvedType.PublicName() == "unsafe.Pointer" { + if m.resolvedType.PublicName() == "unsafe.Pointer" || m.resolvedType.Category() == CatPointer { // bugfix/issue-16 fmt.Fprintf(w, "func (u *%s) As%s(ptr %s) {\n", t.PublicName(), m.PublicName(), m.resolvedType.PublicName(), ) @@ -85,7 +85,17 @@ func (t *unionType) PrintInternalDeclaration(w io.Writer) { // _vk type declaration var sizeString = t.internalByteSize if t.internalByteSize == "" { - sizeString = fmt.Sprintf("unsafe.Sizeof(%s{})", t.members[0].resolvedType.InternalName()) + switch t.members[0].resolvedType.Category() { // updated with bugfix/issue-16 + case CatPointer: + sizeString = fmt.Sprintf("unsafe.Sizeof((%s)(nil))", t.members[0].resolvedType.InternalName()) // Internal name will include the pointer and the underlying type + case CatArray: + fallthrough // Array will use the same syntax as structs + case CatStruct: + sizeString = fmt.Sprintf("unsafe.Sizeof(%s{})", t.members[0].resolvedType.InternalName()) + default: + sizeString = fmt.Sprintf("unsafe.Sizeof(%s(0))", t.members[0].resolvedType.InternalName()) // fallthrough to assmption that this is a primitve type + + } } fmt.Fprintf(w, "type %s [%s]byte\n", t.InternalName(), sizeString) From 484405524e44d5aef9e0b52b2c76e209fd4daedc Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Wed, 8 Mar 2023 13:26:22 -0600 Subject: [PATCH 07/15] Handle altlen on params. Fixes #17 --- def/command_type.go | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/def/command_type.go b/def/command_type.go index 8a0b106..2412720 100644 --- a/def/command_type.go +++ b/def/command_type.go @@ -230,6 +230,20 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { funcTrampolineParams = append(funcTrampolineParams, p) + } else if p.altLenSpec != "" { + // This is another edge case where the length of the array is embedded in a bitfield. For now, the + // user must provide the bitfield and must ensure that their slice is the appropriate length. + // See vkCmdSetSampleMaskEXT for an example. Addressed as "no action" relative to other slices in + // Resolve(). Fix for issue #17 + fmt.Fprintf(preamble, " // %s is an edge case input slice, with an alternative length encoding. Developer must provide the length themselves.\n", p.publicName) + fmt.Fprintf(preamble, " // No handling for internal vs. external types at this time, the only case this appears as of 1.3.240 is a handle type with a bitfield length encoding\n") + fmt.Fprintf(preamble, " var %s *%s\n", p.internalName, p.resolvedType.(*pointerType).resolvedPointsAtType.PublicName()) + fmt.Fprintf(preamble, " if %s != nil {\n", p.publicName) + fmt.Fprintf(preamble, " %s = &%s[0]\n", p.internalName, p.publicName) + fmt.Fprintf(preamble, " }\n") + + funcTrampolineParams = append(funcTrampolineParams, p) + } else { // Parameter is a singular input if p.resolvedType.IsIdenticalPublicAndInternal() { @@ -573,8 +587,8 @@ type commandParam struct { optionalParamString string isAlwaysOptional bool - pointerLevel int - lenSpec string + pointerLevel int + lenSpec, altLenSpec string parentCommand *commandType isResolved bool @@ -607,7 +621,17 @@ func (p *commandParam) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { } // check for length specification - if p.lenSpec != "" { + if p.altLenSpec != "" { + // If altlen is present, then the array is a fixed length per the spec. + // as of 1.3.240, only vkCmdSetSampleMaskEXT has an altlen parameter, where the expected array length is + // embedded in a sample mask bitfield. + // + // Fix for issue #17 is to recognize this parameter as a slice, but we won't try to calculate the bitfield. + // (i.e., the developer needs to just pass a SampleMaskBits value that matches the slice) + // + // Net effect is to do noting here in Resolve. + + } else if p.lenSpec != "" { for _, otherP := range p.parentCommand.parameters { if otherP.registryName == p.lenSpec { otherP.isLenMemberFor = append(otherP.isLenMemberFor, p) @@ -728,6 +752,7 @@ func NewCommandParamFromXML(elt *xmlquery.Node, forCommand *commandType) *comman rval.isConstParam = strings.HasPrefix(elt.InnerText(), "const") rval.pointerLevel = strings.Count(elt.InnerText(), "*") rval.lenSpec = elt.SelectAttr("len") + rval.altLenSpec = elt.SelectAttr("altlen") rval.parentCommand = forCommand From 21b18e338d6b9996a62a31b4c743f7a6f03e8f7a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Mar 2023 19:49:32 +0000 Subject: [PATCH 08/15] Bump golang.org/x/text from 0.3.7 to 0.3.8 Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.7 to 0.3.8. - [Release notes](https://github.com/golang/text/releases) - [Commits](https://github.com/golang/text/compare/v0.3.7...v0.3.8) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 0ed2709..5aaeb56 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/iancoleman/strcase v0.2.0 github.com/sirupsen/logrus v1.9.0 github.com/tidwall/gjson v1.14.4 - golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f ) require ( @@ -16,5 +16,5 @@ require ( github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect - golang.org/x/text v0.3.7 // indirect + golang.org/x/text v0.3.8 // indirect ) diff --git a/go.sum b/go.sum index ed69c44..e8a2e89 100644 --- a/go.sum +++ b/go.sum @@ -26,11 +26,13 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacp golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= From 6e455b1fb81c677b940ce4b8a3bd89008b97cd86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Mar 2023 19:51:28 +0000 Subject: [PATCH 09/15] Bump golang.org/x/net from 0.0.0-20220127200216-cd36cc0744dd to 0.7.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20220127200216-cd36cc0744dd to 0.7.0. - [Release notes](https://github.com/golang/net/releases) - [Commits](https://github.com/golang/net/commits/v0.7.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 5aaeb56..6563dce 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/iancoleman/strcase v0.2.0 github.com/sirupsen/logrus v1.9.0 github.com/tidwall/gjson v1.14.4 - golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f + golang.org/x/sys v0.5.0 ) require ( @@ -15,6 +15,6 @@ require ( github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect - golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect - golang.org/x/text v0.3.8 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/text v0.7.0 // indirect ) diff --git a/go.sum b/go.sum index e8a2e89..2b1111c 100644 --- a/go.sum +++ b/go.sum @@ -22,17 +22,18 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= From cb6a4f96c64694a8dfac1e11569df1f3171f4165 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Wed, 8 Mar 2023 19:26:27 -0600 Subject: [PATCH 10/15] Internal conv. of vk-populated vals. Fixes #23 --- def/command_type.go | 23 +++++++++++++---------- def/pointer_type.go | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/def/command_type.go b/def/command_type.go index 2412720..04ca7d1 100644 --- a/def/command_type.go +++ b/def/command_type.go @@ -411,19 +411,22 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) { } else { fmt.Fprintf(preamble, "// %s is a binding-allocated single return value and will be populated by Vulkan, but requiring translation\n", p.publicName) if p.resolvedType.Category() == CatPointer { - fmt.Fprintf(preamble, "var %s %s\n", p.internalName, p.resolvedType.(*pointerType).resolvedPointsAtType.InternalName()) - fmt.Fprintf(preamble, "ptr_%s := &%s\n", p.internalName, p.internalName) - - fmt.Fprintf(epilogue, " %s = %s\n", p.publicName, p.resolvedType.(*pointerType).resolvedPointsAtType.TranslateToPublic(p.internalName)) + underlyingType := p.resolvedType.(*pointerType).resolvedPointsAtType + if underlyingType.Category() == CatStruct || underlyingType.Category() == CatUnion { + // Pointer type will end up calling Vulkanize() + fmt.Fprintf(preamble, "var %s %s = %s\n", p.internalName, p.resolvedType.InternalName(), p.resolvedType.TranslateToInternal(p.publicName)) + + fmt.Fprintf(epilogue, " %s = %s\n", p.publicName, p.resolvedType.(*pointerType).resolvedPointsAtType.TranslateToPublic(p.internalName)) + } else { + fmt.Fprintf(preamble, "var internal_%s %s = %s\n", p.publicName, underlyingType.InternalName(), underlyingType.TranslateToInternal(p.publicName)) + fmt.Fprintf(preamble, "var %s = &internal_%s\n", p.internalName, p.publicName) + fmt.Fprintf(epilogue, " %s = %s\n", p.publicName, underlyingType.TranslateToPublic("internal_"+p.publicName)) + } } else { - fmt.Fprintf(preamble, "var %s %s\n", p.internalName, p.resolvedType.InternalName()) - fmt.Fprintf(preamble, "ptr_%s := &%s\n", p.internalName, p.internalName) - - fmt.Fprintf(epilogue, " %s = *%s\n", p.publicName, p.resolvedType.TranslateToPublic(p.internalName)) + // Vulkan *must* be accepting a pointer, if it is planning to fill in any kind of data + panic("found non-pointer return value from vulkan!") } - p.internalName = "ptr_" + p.internalName // Done after the fact so the internal pointer will be used in the tramp params - fmt.Fprintln(preamble) } diff --git a/def/pointer_type.go b/def/pointer_type.go index ceef82e..f366504 100644 --- a/def/pointer_type.go +++ b/def/pointer_type.go @@ -81,6 +81,7 @@ func (t *pointerType) TranslateToInternal(inputVar string) string { } else if t.resolvedPointsAtType.IsIdenticalPublicAndInternal() { return inputVar } else if t.resolvedPointsAtType.Category() == CatStruct || t.resolvedPointsAtType.Category() == CatUnion { + // This overrides the normal struct TranslateToInternal, to avoid uneccssary dereferencing and addressing a new pointer return fmt.Sprintf("%s.Vulkanize()", inputVar) } else { return fmt.Sprintf("(%s)(%s)", t.InternalName(), t.resolvedPointsAtType.TranslateToInternal(inputVar)) From a2ae1822c4d05c1f596eb0f60285d65ed7a8bef6 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Wed, 8 Mar 2023 20:24:41 -0600 Subject: [PATCH 11/15] Fix duplicated code comments --- def/internal_type.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/def/internal_type.go b/def/internal_type.go index 0eff72f..5b3cee5 100644 --- a/def/internal_type.go +++ b/def/internal_type.go @@ -39,10 +39,6 @@ func (t *internalType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet { func (t *internalType) PrintPublicDeclaration(w io.Writer) { t.PrintDocLink(w) - if t.comment != "" { - fmt.Fprintln(w, "// ", t.comment) - } - if t.IsAlias() { fmt.Fprintf(w, "type %s = %s\n", t.PublicName(), t.resolvedAliasType.PublicName()) } else { From 0ff7bb7e5e04747ce852da2fc7f1b5853a168f67 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Wed, 8 Mar 2023 20:25:35 -0600 Subject: [PATCH 12/15] Fixes for #26, ignore !comment, minor cleanup --- def/base_type.go | 7 ------- def/command_type.go | 2 +- def/external_type.go | 4 ---- def/handle_type.go | 4 +++- def/struct_type.go | 4 ---- def/union_type.go | 1 - main.go | 3 +++ 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/def/base_type.go b/def/base_type.go index 9f10bc8..23ab0c2 100644 --- a/def/base_type.go +++ b/def/base_type.go @@ -129,13 +129,6 @@ func ReadBaseTypeExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr entry := NewOrUpdateBaseTypeFromJSON(key.String(), exVal, tr, vr) tr[key.String()] = 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/command_type.go b/def/command_type.go index 04ca7d1..cbe1208 100644 --- a/def/command_type.go +++ b/def/command_type.go @@ -764,7 +764,7 @@ func NewCommandParamFromXML(elt *xmlquery.Node, forCommand *commandType) *comman func ReadCommandExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr ValueRegistry) { exceptions.Get("command").ForEach(func(key, exVal gjson.Result) bool { - if key.String() == "comment" { + if key.String() == "!comment" { return true } // Ignore comments diff --git a/def/external_type.go b/def/external_type.go index a34b1fe..d156a0d 100644 --- a/def/external_type.go +++ b/def/external_type.go @@ -78,10 +78,6 @@ func NewOrUpdateExternalTypeFromJSON(key string, exception gjson.Result, tr Type existing := tr[key] var updatedEntry *externalType - if key == "!comment" { - return nil - } - if existing == nil { logrus.WithField("registry type", key).Info("no existing registry entry for external type") updatedEntry = &externalType{} diff --git a/def/handle_type.go b/def/handle_type.go index ac47aab..44fb709 100644 --- a/def/handle_type.go +++ b/def/handle_type.go @@ -71,7 +71,7 @@ func NewHandleTypeFromXML(node *xmlquery.Node) TypeDefiner { func ReadHandleExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr ValueRegistry) { exceptions.Get("handle").ForEach(func(key, exVal gjson.Result) bool { - if key.String() == "comment" { + if key.String() == "!comment" { return true } // Ignore comments @@ -101,5 +101,7 @@ func NewHandleTypeFromJSON(key, json gjson.Result) TypeDefiner { rval.publicName = json.Get("publicName").String() rval.underlyingTypeName = json.Get("underlyingType").String() + rval.comment = json.Get("comment").String() + return &rval } diff --git a/def/struct_type.go b/def/struct_type.go index 1b75bfd..1a6af59 100644 --- a/def/struct_type.go +++ b/def/struct_type.go @@ -510,11 +510,7 @@ func ReadStructExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr V } entry := NewOrUpdateStructTypeFromJSON(key, exVal, existing) - // if entry == nil { - // delete(tr, key.String()) - // } else { tr[key.String()] = entry - // } return true }) diff --git a/def/union_type.go b/def/union_type.go index 6e67a9c..68c4d5e 100644 --- a/def/union_type.go +++ b/def/union_type.go @@ -158,7 +158,6 @@ func ReadUnionExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr Va } // Ignore comments UpdateUnionTypeFromJSON(key, exVal, tr[key.String()].(*unionType)) - // tr[key.String()] = entry return true }) diff --git a/main.go b/main.go index 70f5e3a..e1612ce 100644 --- a/main.go +++ b/main.go @@ -111,6 +111,9 @@ func main() { platforms[plat.Name()] = plat } jsonDoc.Get("platform").ForEach(func(key, value gjson.Result) bool { + if key.String() == "!comment" { + return true + } r := feat.NewOrUpdatePlatformFromJSON(key.String(), value, platforms[key.String()]) platforms[r.Name()] = r return true From dd5d182f3ca693dec83784abb8be684e0cbb0f41 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Wed, 8 Mar 2023 20:26:10 -0600 Subject: [PATCH 13/15] Cleanup "comment" to "!comment", part of #26 --- exceptions.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exceptions.json b/exceptions.json index 64076d6..65a7edd 100644 --- a/exceptions.json +++ b/exceptions.json @@ -32,13 +32,15 @@ "VK_USE_64_BIT_PTR_DEFINES": { "constantValue": "unsafe.Sizeof(uintptr(0))", - "comment": "Included for completeness, but this value is only used in a macro to determine how VK_NULL_HANDLE should be defined in C, based on architecture and compiler." + "!comment": "Included for completeness, but this value is only used in a macro to determine how VK_NULL_HANDLE should be defined in C, based on architecture and compiler." } }, "handle": { - "VK_DEFINE_HANDLE": { "publicName": "handle", "underlyingType": "uintptr_t", + "VK_DEFINE_HANDLE": { + "publicName": "handle", + "underlyingType": "uintptr_t", "constants": { "VK_NULL_HANDLE" : "0" } @@ -50,7 +52,7 @@ }, "VK_USE_64_BIT_PTR_DEFINES": { "publicName": "!ignore", - "comment": "This and several following entries are defined as types in the spec, though they're really values. !ignore allows this type to be created for resolving the feature set, but it will not be output to the generated code." + "!comment": "This and several following entries are defined as types in the spec, though they're really values. !ignore allows this type to be created for resolving the feature set, but it will not be output to the generated code." }, "VK_NULL_HANDLE": { "publicName": "!ignore" @@ -128,7 +130,7 @@ "external" : { "int8_t": { "go:type": "int8", "primitive": true, - "comment": "Primitive indicates a direct replacement? Necessary or not?" }, + "!comment": "Primitive indicates a direct replacement? Necessary or not?" }, "uint8_t": { "go:type": "uint8", "primitive": true }, "int16_t": { "go:type": "int16", "primitive": true }, "uint16_t": { "go:type": "uint16", "primitive": true }, From f81dbe0e9da3efb43ec6a2b0318404fc6c9bf52e Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Thu, 9 Mar 2023 09:57:12 -0600 Subject: [PATCH 14/15] 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 15/15] 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}))