Skip to content

Commit

Permalink
Merge pull request #38 from bbredesen/enhancement/8
Browse files Browse the repository at this point in the history
Enhancement/8
  • Loading branch information
bbredesen committed Mar 28, 2023
2 parents 64da48b + 533cf1a commit 9040c56
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Install: `go install github.com/bbredesen/vk-gen@latest`

Download the latest registry file: `curl https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/registry/vk.xml > vk.xml`

(Or, replace "main" in the URL above with the tagged version you want to generate against: e.g.,
`https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/v1.2.203/registry/vk.xml` for the last version 1.2 specification.)

Run the tool: `vk-gen`

Use `-inFile` to specify a registry filename or path (defaults to `./vk.xml`)
Expand Down
37 changes: 6 additions & 31 deletions def/command_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,6 @@ func (t *commandType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet {
return iset
}

func (t *commandType) PrintGlobalDeclarations(w io.Writer, idx int, isStart bool) {
if t.staticCodeRef != "" || t.IsAlias() {
// Ignored, static refs from exceptions.json aren't processed through
// Cgo/lazyCommands and no need to write key entries for alias commands
return
}

if isStart {
if idx == 0 {
fmt.Fprintf(w, "%s vkCommandKey = iota\n", t.keyName())
} else {
fmt.Fprintf(w, "%s vkCommandKey = iota + %d\n", t.keyName(), idx)
}
} else {
fmt.Fprintln(w, t.keyName())
}
}

func (t *commandType) PrintFileInitContent(w io.Writer) {
if t.IsAlias() {
// No need to write key entries for alias commands
return
}
fmt.Fprintf(w, "lazyCommands[%s] = vkCommand{\"%s\", %d, %v, nil}\n",
t.keyName(), t.RegistryName(), t.bindingParamCount, t.resolvedReturnType != nil)

}

func (t *commandType) PrintPublicDeclaration(w io.Writer) {
if t.staticCodeRef != "" {
fmt.Fprintf(w, "// %s is static code, not generated from vk.xml; aliased to %s\n", t.PublicName(), t.staticCodeRef)
Expand Down Expand Up @@ -489,6 +461,9 @@ func (t *commandType) PrintPublicDeclaration(w io.Writer) {
}

fmt.Fprintf(w, "}\n\n")

fmt.Fprintf(w, "var %s = &vkCommand{\"%s\", %d, %v, nil}\n",
t.RegistryName(), t.RegistryName(), t.bindingParamCount, t.resolvedReturnType != nil)
}

func trampStringFromParams(sl []*commandParam) string {
Expand All @@ -509,13 +484,13 @@ func (t *commandType) printTrampolineCall(w io.Writer, trampParams []*commandPar

if returnParam != nil {
if returnParam.resolvedType.IsIdenticalPublicAndInternal() {
fmt.Fprintf(w, " %s = %s(execTrampoline(%s%s))\n", returnParam.publicName, returnParam.resolvedType.PublicName(), t.keyName(), trampParamsString)
fmt.Fprintf(w, " %s = %s(execTrampoline(%s%s))\n", returnParam.publicName, returnParam.resolvedType.PublicName(), t.RegistryName(), trampParamsString)
} else {
fmt.Fprintf(w, " rval := %s(execTrampoline(%s%s))\n", returnParam.resolvedType.InternalName(), t.keyName(), trampParamsString)
fmt.Fprintf(w, " rval := %s(execTrampoline(%s%s))\n", returnParam.resolvedType.InternalName(), t.RegistryName(), trampParamsString)
fmt.Fprintf(w, " %s = %s\n", returnParam.publicName, returnParam.resolvedType.TranslateToPublic("rval"))
}
} else {
fmt.Fprintf(w, " execTrampoline(%s%s)\n", t.keyName(), trampParamsString)
fmt.Fprintf(w, " execTrampoline(%s%s)\n", t.RegistryName(), trampParamsString)
}
}

Expand Down
13 changes: 4 additions & 9 deletions static_include/static_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ func (r Result) Error() string {
return r.String()
}

type vkCommandKey int
type vkCommand struct {
protoName string
argCount int
hasReturn bool
fnHandle unsafe.Pointer
}

var lazyCommands map[vkCommandKey]vkCommand = make(map[vkCommandKey]vkCommand)

var dlHandle unsafe.Pointer

var overrideLibName string
Expand All @@ -60,7 +57,7 @@ func OverrideDefaultVulkanLibrary(nameOrPath string) {
overrideLibName = nameOrPath
}

func execTrampoline(commandKey vkCommandKey, args ...uintptr) uintptr {
func execTrampoline(cmd *vkCommand, args ...uintptr) uintptr {
if dlHandle == nil {
var libName string
switch runtime.GOOS {
Expand All @@ -86,10 +83,10 @@ func execTrampoline(commandKey vkCommandKey, args ...uintptr) uintptr {
C.free(unsafe.Pointer(cstr))
}

cmd := lazyCommands[commandKey]
// cmd := lazyCommands[commandKey]
if cmd.fnHandle == nil {
cmd.fnHandle = C.SymbolFromName(dlHandle, unsafe.Pointer(sys_stringToBytePointer(cmd.protoName)))
lazyCommands[commandKey] = cmd
// lazyCommands[commandKey] = cmd
}

if len(args) != cmd.argCount {
Expand Down Expand Up @@ -126,9 +123,7 @@ func execTrampoline(commandKey vkCommandKey, args ...uintptr) uintptr {
panic("Unhandled number of arguments passed for cmd " + cmd.protoName)
}

// Trampoline is always returning a file does not exist error in the second return value, so that error reporting is disabled

return uintptr(result) //, err
return uintptr(result)
}

func stringToNullTermBytes(s string) *byte {
Expand Down

0 comments on commit 9040c56

Please sign in to comment.