blob: 3aa07cc80d3ba835612299818f0d17e49d85409f [file] [log] [blame]
// Copyright (C) 2016 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.
package vulkan
import (
"fmt"
"reflect"
"android.googlesource.com/platform/tools/gpu/framework/binary"
"android.googlesource.com/platform/tools/gpu/framework/binary/registry"
"android.googlesource.com/platform/tools/gpu/gapid/atom"
"android.googlesource.com/platform/tools/gpu/gapid/gfxapi"
)
// AddMetadata annotates all atoms in the namespace
func AddMetadata(n *registry.Namespace) {
n.Visit(func(c binary.Class) {
ent := c.Schema()
if ent == nil {
return
}
if atom.FindMetadata(ent) != nil {
// Don't add metadata, if there is already metadata. Duplicates
// can happen because it is not easy to distinguish Frozen from
// Generated.
return
}
u := n.LookupUpgrader(ent.Signature())
if u == nil {
return
}
obj := u.New()
if a, ok := obj.(atom.Atom); ok {
atom.AddMetadata(a, ent)
}
})
}
// Note vulkan_binary.go must initialize first. We really on the Go's
// lexigraphical provision; that is "metadata.go" > "vulkan_binary.go"
// for correct order of initialization.
func init() {
AddMetadata(Namespace)
if err := atom.AddSnippetsFromBase64String(
Namespace, embedded[snippets_base64_file]); err != nil {
panic(fmt.Errorf("Error decoding atom snippets: %v", err))
}
var state *State
entity := state.Class().Schema()
if err := gfxapi.AddStateSnippetsFromBase64String(
entity,
embedded[globals_snippets_base64_file]); err != nil {
panic(fmt.Errorf("Error decoding global state snippets: %v", err))
}
gfxapi.AddCanFollowState(reflect.TypeOf(state).Elem(), &entity.Metadata)
}