blob: dac12cc03de1df898fd5d60c8a9a809fd803d9ae [file] [log] [blame]
{{/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/}}
{{Global "module" ""}}
{{Include "go_common.tmpl"}}
{{$ | Macro "api.go" | GoFmt | Write "api.go"}}
{{define "api.go"}}
{{template "Go.GeneratedHeader" (Global "OutputDir")}}
import (
"fmt"
"android.googlesource.com/platform/tools/gpu/atom"
"android.googlesource.com/platform/tools/gpu/binary"
"android.googlesource.com/platform/tools/gpu/gfxapi"
"android.googlesource.com/platform/tools/gpu/log"
"android.googlesource.com/platform/tools/gpu/memory"
"android.googlesource.com/platform/tools/gpu/replay/builder"
"android.googlesource.com/platform/tools/gpu/service"
)
{{range $p := $.Pseudonyms}}
{{template "Pseudonym" $p}}
{{end}}
{{range $p := $.Pointers}}
{{template "Pointer" $p}}
{{end}}
{{range $s := $.Slices}}
{{template "Slice" $s}}
{{end}}
{{range $m := $.Maps}}
{{template "Map" $m}}
{{end}}
{{range $i, $c := AllCommands $}}
{{Macro "CommandEntry" "Command" $c "Index" $i}}
{{end}}
{{range $c := $.Classes}}
{{template "Class" $c}}
{{end}}
{{range $e := $.Enums}}
{{template "Enum" $e}}
{{end}}
{{template "Globals" $}}
{{template "NewAtoms" $}}
{{template "API" $}}
func init() {
gfxapi.Register(API())
{{range $i, $c := AllCommands $}}
atom.Register(atom.TypeInfo{
Name: "{{Macro "CmdName" $c}}",
Docs: "{{$c.Docs}}",
ID: {{$i}},
New: func() atom.Atom { return &{{Macro "Go.CmdName" $c}}{} },
})
{{end}}
}
func min(a, b uint64) uint64 {
if a < b {
return a
} else {
return b
}
}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration for the specified pseudonym.
-------------------------------------------------------------------------------
*/}}
{{define "Pseudonym"}}
{{AssertType $ "Pseudonym"}}
{{$u := $ | Underlying}}
{{ if IsPointer $u}}{{Macro "Pointer" $}}
{{else if IsSlice $u}}{{Macro "Slice" $}}
{{else }}type {{$.Name}} {{Macro "Go.Type" $.To}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the Pointer type or indirect
type (Pseudonym) to Pointer.
-------------------------------------------------------------------------------
*/}}
{{define "Pointer"}}
{{AssertType $ "Pointer" "Pseudonym"}}
{{$p := $ | Underlying | Unpack }}
{{$slice_ty := Macro "Go.Type" $p.Slice }}
{{$ptr_ty := Macro "Go.Type" $ }}
{{$el_ty := Macro "Go.Type" $p.To }}
{{$el_is_void := IsVoid ($p.To | Underlying | Unpack) }}
{{$el_is_ptr := IsPointer ($p.To | Underlying | Unpack) }}
// {{$ptr_ty}} is a pointer to a {{$el_ty}} element.
{{if $el_is_ptr}}
// Note: Pointers are stored differently between the application pool and internal pools.
// * The application pool stores pointers as an address an architecture-dependant size.
// * Internal pools store pointers as an 64-bit unsigned address and a 32-bit unsigned
// pool identifier.
{{end}}
type {{$ptr_ty}} struct {
binary.Generate
Address memory.Pointer
Pool memory.PoolID
}
// New{{$ptr_ty}} returns a {{$ptr_ty}} that points to addr in the application pool.
func New{{$ptr_ty}}(addr memory.Pointer) {{$ptr_ty}} {
return {{$ptr_ty}}{Address: addr, Pool: memory.ApplicationPool}
}
// Unbounded returns a new unbounded memory.Slice based at p.
func (p {{$ptr_ty}}) Unboundeds *gfxapi.State) memory.Slice {
return ϟs.Memory[p.Pool].At(p.Address)
}
// ElementSize returns the size in bytes of an element that {{$ptr_ty}} points to.
func (p {{$ptr_ty}}) ElementSizes *gfxapi.State) uint64 {
{{if $el_is_ptr}}
if p.Pool == memory.ApplicationPool {
return uint64s.Architecture.PointerSize)
} else {
return 12
}
{{else}}
return {{Macro "Go.SizeOf" $p.To}}
{{end}}
}
{{if not $el_is_void}}
// Read reads and returns the {{$el_ty}} element at the pointer.
func (p {{$ptr_ty}}) Reads *gfxapi.State, ϟd database.Database, ϟl log.Logger) {{$el_ty}} {
return p.Slice(0, 1, ϟs).Reads, ϟd, ϟl)[0]
}
// Write writes value to the {{$el_ty}} element at the pointer.
func (p {{$ptr_ty}}) Write(value {{$el_ty}}, ϟs *gfxapi.State) {
p.Slice(0, 1, ϟs).Write([]{{$el_ty}}{value}, ϟs)
}
{{end}}
// Slice returns a new {{$slice_ty}} from the pointer using start and end indices.
func (p {{$ptr_ty}}) Slice(start, end uint64, ϟs *gfxapi.State) {{$slice_ty}} {
if start > end {
panic(fmt.Errorf("Slice start (%d) is greater than the end (%d)", start, end))
}
return {{$slice_ty}}{Root: p.Address, Base: p.Address.Offset(start * p.ElementSizes)), Count: end-start, Pool: p.Pool}
}
// String returns a string description of the {{$ptr_ty}} pointer.
func (p {{$ptr_ty}}) String() string {
return fmt.Sprintf("%v@%v", p.Address, p.Pool)
}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the Slice type or indirect
type (Pseudonym) to Slice.
-------------------------------------------------------------------------------
*/}}
{{define "Slice"}}
{{AssertType $ "Slice" "Pseudonym"}}
{{$s := $ | Underlying | Unpack }}
{{$slice_ty := Macro "Go.Type" $ }}
{{$ptr_ty := Macro "Go.Type" $s.Pointer }}
{{$el_ty := Macro "Go.Type" $s.To }}
{{$el_size := Macro "Go.SizeOf" $s.To }}
{{$el_is_char := IsChar ($s.To | Underlying | Unpack) }}
{{$el_is_void := IsVoid ($s.To | Underlying | Unpack) }}
{{$el_is_ptr := IsPointer ($s.To | Underlying | Unpack) }}
type {{$slice_ty}} struct {
binary.Generate
Root memory.Pointer // Original pointer this slice derives from.
Base memory.Pointer // Address of first element.
Count uint64 // Number of elements in the slice.
Pool memory.PoolID // Pool that holds the element data.
}
{{if $el_is_char}}
// Make{{$slice_ty}}FromString returns a {{$slice_ty}} backed by a new
// memory pool containing a copy of str.
func Make{{$slice_ty}}FromString(str string, ϟs *gfxapi.State) {{$slice_ty}} {
pool := &memory.Pool{}
pool.Write(0, memory.Blob([]byte(str)))
id := ϟs.NextPoolID
ϟs.Memory[id] = pool
ϟs.NextPoolID++
return {{$slice_ty}}{Count: uint64(len(str)), Pool: id}
}
{{end}}
// Make{{$slice_ty}} returns a {{$slice_ty}} backed by a new memory pool.
func Make{{$slice_ty}}(count uint64, ϟs *gfxapi.State) {{$slice_ty}} {
id := ϟs.NextPoolID
ϟs.Memory[id] = &memory.Pool{}
ϟs.NextPoolID++
return {{$slice_ty}}{Count: count, Pool: id}
}
// Clone returns a copy of the {{$slice_ty}} in a new memory pool.
func (s {{$slice_ty}}) Clones *gfxapi.State) {{$slice_ty}} {
pool := &memory.Pool{}
pool.Write(0, ϟs.Memory[s.Pool].Slice(s.Ranges)))
id := ϟs.NextPoolID
ϟs.Memory[id] = pool
ϟs.NextPoolID++
dst := {{$slice_ty}}{Count: s.Count, Pool: id}
return dst
}
// ElementSize returns the size in bytes of an element that {{$slice_ty}} points to.
func (s {{$slice_ty}}) ElementSizes *gfxapi.State) uint64 {
{{if $el_is_ptr}}
if s.Pool == memory.ApplicationPool {
return uint64s.Architecture.PointerSize)
} else {
return 12
}
{{else}}
return {{Macro "Go.SizeOf" $s.To}}
{{end}}
}
// Range returns the memory range this slice represents in the underlying pool.
func (s {{$slice_ty}}) Ranges *gfxapi.State) memory.Range {
return s.Base.Range(s.Count * s.ElementSizes))
}
// ResourceID returns an identifier to a resource representing the data of
// this slice.
func (s {{$slice_ty}}) ResourceIDs *gfxapi.State, ϟd database.Database, ϟl log.Logger) binary.ID {
id, err := ϟs.Memory[s.Pool].Slice(s.Ranges)).ResourceIDd, ϟl)
if err != nil {
panic(err)
}
return id
}
// Decoder returns a memory decoder for the slice.
func (s {{$slice_ty}}) Decoders *gfxapi.State, ϟd database.Database, ϟl log.Logger) binary.Decoder {
return ϟs.MemoryDecoders.Memory[s.Pool].Slice(s.Ranges)), ϟd, ϟl)
}
// Encoder returns a memory encoder for the slice.
func (s {{$slice_ty}}) Encoders *gfxapi.State) binary.Encoder {
return ϟs.MemoryEncoders.Memory[s.Pool], s.Ranges))
}
{{if not $el_is_void}}
// Read reads and returns all the {{$el_ty}} elements in this {{$slice_ty}}.
func (s {{$slice_ty}}) Reads *gfxapi.State, ϟd database.Database, ϟl log.Logger) []{{$el_ty}} {
d, res := s.Decoders, ϟd, ϟl), make([]{{$el_ty}}, s.Count)
for i := range res {
{{if $el_is_ptr}}
if s.Pool == memory.ApplicationPool {
ptr, err := binary.ReadUint(d, ϟs.Architecture.PointerSize*8)
if err != nil {
panic(err)
}
res[i] = New{{$el_ty}}(memory.Pointer(ptr))
} else {
{{end}}
{{Macro "Go.Decode" "Name" "res[i]" "Type" $s.To "ErrHandler" "panic(err)"}}
{{if $el_is_ptr}} } {{end}}
}
return res
}
// Write copies elements from src to this slice. The number of elements copied is returned
// which is the minimum of dst.Count and src.Count.
func (dst {{$slice_ty}}) Write(src []{{$el_ty}}, ϟs *gfxapi.State) uint64 {
count := min(dst.Count, uint64(len(src)))
dst = dst.Slice(0, count, ϟs)
e := dst.Encoders)
for i := uint64(0); i < count; i++ {
{{if $el_is_ptr}}
if dst.Pool == memory.ApplicationPool {
if err := binary.WriteUint(e, ϟs.Architecture.PointerSize*8, uint64(src[i].Address)); err != nil {
panic(err)
}
} else {
{{end}}
{{Macro "Go.Encode" "Name" "src[i]" "Type" $s.To "ErrHandler" "panic(err)"}}
{{if $el_is_ptr}} } {{end}}
}
return count
}
// Copy copies elements from src to this slice.
// The number of elements copied is the minimum of dst.Count and src.Count.
// The slices of this and dst to the copied elements is returned.
func (dst {{$slice_ty}}) Copy(src {{$slice_ty}}, ϟs *gfxapi.State, ϟd database.Database, ϟl log.Logger) (d, s {{$slice_ty}}) {
count := min(dst.Count, src.Count)
dst, src = dst.Slice(0, count, ϟs), src.Slice(0, count, ϟs)
{{if $el_is_ptr}}
if (dst.Pool == memory.ApplicationPool) != (src.Pool == memory.ApplicationPool) {
dst.Write(src.Reads, ϟd, ϟl), ϟs)
} else {
{{end}}
ϟs.Memory[dst.Pool].Write(dst.Base, ϟs.Memory[src.Pool].Slice(src.Ranges)))
{{if $el_is_ptr}} } {{end}}
return dst, src
}
{{end}}
// Index returns a {{$ptr_ty}} to the i'th element in this {{$slice_ty}}.
func (s {{$slice_ty}}) Index(i uint64, ϟs *gfxapi.State) {{$ptr_ty}} {
return {{$ptr_ty}}{Address: s.Base.Offset(i * s.ElementSizes)), Pool: s.Pool}
}
// Slice returns a sub-slice from the {{$slice_ty}} using start and end indices.
func (s {{$slice_ty}}) Slice(start, end uint64, ϟs *gfxapi.State) {{$slice_ty}} {
if start >= end {
panic(fmt.Errorf("%v.Slice(%d, %d) - start must be less than end", s, start, end))
}
if end > s.Count {
panic(fmt.Errorf("%v.Slice(%d, %d) - out of bounds", s, start, end))
}
return {{$slice_ty}}{Root: s.Root, Base: s.Base.Offset(start * s.ElementSizes)), Count: end-start, Pool: s.Pool}
}
// String returns a string description of the {{$slice_ty}} slice.
func (s {{$slice_ty}}) String() string {
return fmt.Sprintf("{{$el_ty}}(%v@%v)[%d]", s.Base, s.Pool, s.Count)
}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the specified static array.
-------------------------------------------------------------------------------
*/}}
{{define "StaticArray"}}
{{AssertType $ "StaticArray"}}
type {{$.Name}} [{{$.Size}}]{{Macro "Go.Type" $.ValueType}}
func (s {{$.Name}}) Len() int { return {{$.Size}} }
func (s {{$.Name}}) Range() [{{$.Size}}]{{Macro "Go.Type" $.ValueType}} { return s}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the specified map.
-------------------------------------------------------------------------------
*/}}
{{define "Map"}}
{{AssertType $ "Map"}}
{{$name := $.Name}}
{{$key := Macro "Go.Type" $.KeyType}}
{{$value := Macro "Go.Type" $.ValueType}}
type {{$name}} map[{{$key}}]{{$value}}
func (m {{$name}}) Get(key {{$key}}) {{$value}} {
{{$init := Macro "Init" "Name" "v" "Type" $.ValueType}}
{{if $init}}
v, ok := m[key]
if !ok {
{{$init}}
}
return v
{{else}}
return m[key]
{{end}}
}
func (m {{$name}}) Contains(key {{$key}}) bool {
_, ok := m[key]
return ok
}
func (m {{$name}}) Delete(key {{$key}}) {
delete(m, key)
}
func (m {{$name}}) Range() []{{$value}} {
values := make([]{{$value}}, 0, len(m))
for _, value := range m {
values = append(values, value)
}
return values
}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits initialization code for the specified type.
-------------------------------------------------------------------------------
*/}}
{{define "Init"}}
{{AssertType $.Type "Type"}}
{{AssertType $.Name "string"}}
{{ if IsMap $.Type}}{{$.Name}} = make({{Macro "Go.Type" $.Type}})
{{else if IsClass $.Type}}{{$.Name}}.Init()
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the specified command.
-------------------------------------------------------------------------------
*/}}
{{define "CommandEntry"}}
{{AssertType $.Command "Function"}}
{{$name := Macro "Go.CmdName" $.Command}}
{{$ret := not (IsVoid $.Command.Return.Type)}}
{{template "Go.CommentHeader" $name}}
type {{$name}} struct {
binary.Generate
observations atom.Observations
{{range $p := $.Command.FullParameters}}
{{Macro "Go.Public" $p.Name}} {{Macro "Go.Type" $p}}
{{end}}
}
func (a *{{$name}}) String() string {
return fmt.Sprintf("{{Macro "CmdName" $.Command}}(§
{{range $i, $p := $.Command.CallParameters}}
{{if $i}}, §{{end}}
{{$p.Name}}: %v§
{{end}}
){{if $ret}} → %v{{end}}"
{{range $i, $p := $.Command.CallParameters}}
a.{{Macro "Go.Parameter" $p}}, §
{{end}}
{{if $ret}}a.Result§{{end}}
)
}
// AddRead appends a new read observation to the atom of the range rng with
// the data id.
// The {{$name}} pointer is returned so that calls can be chained.
func (a *{{$name}}) AddRead(rng memory.Range, id binary.ID) *{{$name}} {
a.observations.Reads = append(a.observations.Reads, atom.Observation{Range: rng, ID: id})
return a
}
// AddWrite appends a new write observation to the atom of the range rng with
// the data id.
// The {{$name}} pointer is returned so that calls can be chained.
func (a *{{$name}}) AddWrite(rng memory.Range, id binary.ID) *{{$name}} {
a.observations.Writes = append(a.observations.Writes, atom.Observation{Range: rng, ID: id})
return a
}
func (c *{{$name}}) API() gfxapi.API { return api{} }
func (c *{{$name}}) TypeID() atom.TypeID { return {{$.Index}} }
func (c *{{$name}}) Flags() atom.Flags { return 0 §
{{if GetAnnotation $.Command "DrawCall"}} | atom.DrawCall §{{end}}
{{if GetAnnotation $.Command "EndOfFrame"}} | atom.EndOfFrame §{{end}}
}
func (a *{{$name}}) Observations() *atom.Observations { return &a.observations }
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the specified class.
-------------------------------------------------------------------------------
*/}}
{{define "Class"}}
{{AssertType $ "Class"}}
{{template "Go.CommentHeader" print "class " $.Name }}
{{if GetAnnotation $ "Interface"}}
type {{$.Name}} interface {
{{Macro "ClassInterface" $}}
}
{{else}}
type {{$.Name}} struct {
binary.Generate
CreatedAt atom.ID
{{Macro "ClassFields" $}}
}
func (c *{{$.Name}}) Init() {
{{Macro "FieldsInit" "Type" $ "Name" "c"}}
}
func (c *{{$.Name}}) GetCreatedAt() atom.ID {return c.CreatedAt}
{{range $c := $.Extends}}
{{Macro "ClassImpl" "Class" $c "Impl" $.Name}}
{{end}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits an interface declaration for the specified @interface class.
-------------------------------------------------------------------------------
*/}}
{{define "ClassInterface"}}
{{AssertType $ "Class"}}
{{range $v := $.Fields}}
{{$type := TypeOf $v}}
Get{{Title $v.Name}}() {{Macro "Go.Type" $type}}
Set{{Title $v.Name}}({{Macro "Go.Type" $type}})
{{end}}
{{range $c := $.Extends}}
{{Macro "ClassInterface" $c}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a list of fields of the specified class.
-------------------------------------------------------------------------------
*/}}
{{define "ClassFields"}}
{{AssertType $ "Class"}}
{{range $v := $.Fields}}
{{Title $v.Name}} {{Macro "Go.Type" $v}}
{{end}}
{{range $c := $.Extends}}
// {{$c.Name}}
{{Macro "ClassFields" $c}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits initialization code for all fields of the specified class.
-------------------------------------------------------------------------------
*/}}
{{define "FieldsInit"}}
{{AssertType $.Type "Class" "API"}}
{{AssertType $.Name "string"}}
{{range $v := $.Type.Fields}}
{{Macro "FieldInit" "Field" $v "Name" (print $.Name "." $v.Name)}}
{{end}}
{{range $c := $.Extends}}
// {{$c.Name}}
{{Macro "FieldsInit" "Type" $c "Name" $.Name}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits initialization code for the specified class field.
-------------------------------------------------------------------------------
*/}}
{{define "FieldInit"}}
{{AssertType $.Field "Field" "Global"}}
{{AssertType $.Name "string"}}
{{if $.Field.Default}}{{$.Name}} = {{Macro "Default" $.Field.Default}}
{{else }}{{Macro "Init" "Type" (TypeOf $.Field) "Name" $.Name}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the default value for the specified type.
-------------------------------------------------------------------------------
*/}}
{{define "Default"}}
{{ if IsBoolValue $}}{{$}}
{{else if IsNumericValue $}}{{$}}
{{else if IsStringValue $}}{{$}}
{{else if IsEnumEntry $}}{{$.Enum.Name}}_{{$.Name}}
{{else if IsCast $}}{{Macro "Default" $.Object}}
{{else}}{{Error "macro Default called with unsupported type: %T" $}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the implementation code for the specified class.
-------------------------------------------------------------------------------
*/}}
{{define "ClassImpl"}}
{{AssertType $.Class "Class"}}
{{AssertType $.Impl "string"}}
{{range $v := $.Class.Fields}}
{{$type := TypeOf $v}}
{{$FType := Macro "Go.Type" $type}}
func (i *{{$.Impl}}) Get{{$v.Name}}() {{$FType}} { return i.{{$v.Name}} }
func (i *{{$.Impl}}) Set{{$v.Name}}(v {{$FType}}) { i.{{$v.Name}} = v }
{{end}}
{{range $c := $.Class.Extends}}
{{Macro "ClassImpl" "Class" $c "Impl" $.Impl}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration and implementation for the specified enum.
-------------------------------------------------------------------------------
*/}}
{{define "Enum"}}
{{AssertType $ "Enum"}}
{{template "Go.CommentHeader" print "enum " $.Name }}
type {{$.Name}} uint32
{{Macro "EnumConstants" "Enum" $ "Name" $.Name}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a list of entries for the specified enum.
-------------------------------------------------------------------------------
*/}}
{{define "EnumConstants"}}
{{AssertType $.Enum "Enum"}}
{{AssertType $.Name "string"}}
const (
{{range $e := $.Enum.Entries}}
{{$.Name}}_{{$e.Name}} = {{$.Name}}({{$e.Value}})
{{end}}
)
{{range $e := $.Enum.Extends}}
// {{$e.Name}}
{{Macro "EnumConstants" "Enum" $e "Name" $.Name}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits cases matching a string representation for each entry of the specified enum.
-------------------------------------------------------------------------------
*/}}
{{define "EnumStringCases"}}
{{AssertType $ "Enum"}}
{{range $e := $.Entries}}
case {{$e.Value}}: return "{{$e.Name}}"
{{end}}
{{range $e := $.Extends}}
// {{$e.Name}}
{{Macro "EnumStringCases" $e}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a type declaration for holding global variables.
-------------------------------------------------------------------------------
*/}}
{{define "Globals"}}
{{template "Go.CommentHeader" "Globals"}}
type Globals struct {
binary.Generate
{{range $g := $.Globals}}
{{Title $g.Name}} {{Macro "Go.Type" $g}}
{{end}}
}
func (g *Globals) Init() {
{{range $g := $.Globals}}
{{Macro "FieldInit" "Field" $g "Name" (print "g." $g.Name)}}
{{end}}
}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits a top-level type declaration for the specified API.
-------------------------------------------------------------------------------
*/}}
{{define "API"}}
{{template "Go.CommentHeader" "API"}}
var apiID = gfxapi.ID(binary.NewID([]byte("{{Global "API"}}")))
type api struct {}
func (api) Name() string {
return "{{Global "API"}}"
}
func (api) ID() gfxapi.ID {
return apiID
}
func (api) GetFramebufferAttachmentSize(state *gfxapi.State, attachment gfxapi.FramebufferAttachment) (width uint32, height uint32, err error) {
return getState(state).getFramebufferAttachmentSize(attachment)
}
func API() gfxapi.API {
return api{}
}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the logic to retrieve the specified value.
-------------------------------------------------------------------------------
*/}}
{{define "Value"}}
c.Get{{(TypeOf $).Name}}()
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the boolean expression testing for equality between LHS and RHS.
-------------------------------------------------------------------------------
*/}}
{{define "Equal"}}
{{AssertType $.Type "Type"}}
{{Macro "BinaryOp" "Type" $.Type "LHS" $.LHS "RHS" $.RHS "Operator" "==" "Name" "Equal"}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the boolean expression that is true if LHS < RHS, otherwise false.
-------------------------------------------------------------------------------
*/}}
{{define "Less"}}
{{AssertType $.Type "Type"}}
{{if IsBool $.Type}}false
{{else }}{{Macro "BinaryOp" "Type" $.Type "LHS" $.LHS "RHS" $.RHS "Operator" "<" "Name" "Less"}}
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits the binary expression for the given LHS and RHS types.
-------------------------------------------------------------------------------
*/}}
{{define "BinaryOp"}}
{{AssertType $.Name "string"}}
{{AssertType $.Operator "string"}}
{{AssertType $.Type "Type"}}
{{ if IsS8 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsU8 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsU16 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsS16 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsF32 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsU32 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsS32 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsF64 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsU64 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsS64 $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsInt $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsUint $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsString $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsEnum $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else if IsPointer $.Type}}{{$.LHS}} {{$.Operator}} {{$.RHS}}
{{else }}{{$.LHS}}.{{$.Name}}({{$.RHS}})
{{end}}
{{end}}
{{/*
-------------------------------------------------------------------------------
Emits an Atom constructor for each command.
-------------------------------------------------------------------------------
*/}}
{{define "NewAtoms"}}
{{AssertType $ "API"}}
{{range $c := AllCommands $}}
{{$name := Macro "Go.CmdName" $c}}
func New{{$name}}(§
{{range $p := $c.FullParameters}}
{{if $p | TypeOf | Underlying | IsPointer}}
{{Title $p.Name}} memory.Pointer
{{else}}
{{Title $p.Name}} {{Macro "Go.Type" $p}},§
{{end}}
{{end}}
) *{{$name}} {
return &{{$name}}
{{range $p := $c.FullParameters}}
{{if $p | TypeOf | Underlying | IsPointer}}
{{Macro "Go.Public" $p.Name}}: New{{Macro "Go.Type" $p}}({{Title $p.Name}}),§
{{else}}
{{Macro "Go.Public" $p.Name}}: {{Title $p.Name}},§
{{end}}
{{end}}
}
}
{{end}}
{{end}}