api

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2017 License: Apache-2.0 Imports: 38 Imported by: 158

Documentation

Overview

Package api exposes the shared behavior of all graphics api's.

Index

Constants

View Source
const (
	// ErrParameterNotFound is the error returned by GetParameter() and
	// SetParameter() when the command does not have the named parameter.
	ErrParameterNotFound = fault.Const("Parameter not found")
	// ErrResultNotFound is the error returned by GetResult() and SetResult()
	// when the command does not have a result value.
	ErrResultNotFound = fault.Const("Result not found")
)
View Source
const CmdNoID = CmdID(1<<63 - 1) // use max int64 for the benefit of java

CmdNoID is used when you have to pass an ID, but don't have one to use.

Variables

This section is empty.

Functions

func CmdToProto

func CmdToProto(handler func(a atom_pb.Atom)) func(context.Context, Cmd) error

CmdToProto returns a function that converts all the commands it is handed, passing the generated protos to the handler.

func GetParameter

func GetParameter(ctx context.Context, c Cmd, name string) (interface{}, error)

GetParameter returns the parameter value with the specified name.

func GetResult

func GetResult(ctx context.Context, c Cmd) (interface{}, error)

GetResult returns the command's result value.

func IsErrCmdAborted

func IsErrCmdAborted(err error) bool

IsErrCmdAborted returns true if the cause of the error err was due to an abort() in the command.

func ProtoToCmd

func ProtoToCmd(handler func(Cmd)) func(context.Context, atom_pb.Atom) error

ProtoToCmd returns a function that converts all the storage commands it is handed, passing the generated live atoms to the handler. You must call this with a nil to flush the final atom.

func Register

func Register(api API)

Register adds an api to the understood set. It is illegal to register the same name twice.

func SetParameter

func SetParameter(ctx context.Context, c Cmd, name string, val interface{}) error

SetParameter sets the parameter with the specified name with val.

func SetResult

func SetResult(ctx context.Context, c Cmd, val interface{}) error

SetResult sets the commands result value to val.

Types

type API

type API interface {
	// Name returns the official name of the api.
	Name() string

	// Index returns the API index.
	Index() uint8

	// ID returns the unique API identifier.
	ID() ID

	// ConstantSets returns the constant set pack for the API.
	ConstantSets() *constset.Pack

	// GetFramebufferAttachmentInfo returns the width, height, and format of the
	// specified framebuffer attachment.
	// It also returns an API specific index that maps the given attachment into
	// an API specific representation.
	GetFramebufferAttachmentInfo(state *State, thread uint64, attachment FramebufferAttachment) (width, height uint32, index uint32, format *image.Format, err error)

	// Context returns the active context for the given state.
	Context(state *State, thread uint64) Context

	// CreateCmd constructs and returns a new command with the specified name.
	CreateCmd(name string) Cmd
}

API is the common interface to a graphics programming api.

func Find

func Find(id ID) API

Find looks up a graphics API by identifier. If the id has not been registered, it returns nil.

type APIObject

type APIObject interface {
	// API returns the API identifier that this type belongs to.
	API() API
}

APIObject is the interface implemented by types that belong to an API.

type Aborted

type Aborted struct {
	IsAssert bool
	Reason   string
}

Aborted is an CmdExtra used to mark atoms which did not finish execution. This can be expected (e.g. GL error), or unexpected (failed assertion).

type AllocResult

type AllocResult struct {
	// contains filtered or unexported fields
}

AllocResult represents the result of allocating a range using a memory.Allocator, and potentially the database ID for data that's meant to be stored in the range.

func (AllocResult) Address

func (r AllocResult) Address() uint64

Address returns the beginning of the range.

func (AllocResult) Data

func (r AllocResult) Data() (memory.Range, id.ID)

Data can be used as a helper to Add(Read|Write) methods on commands.

func (AllocResult) Free

func (r AllocResult) Free()

Free frees the memory range through the originating allocator. This is not currently used.

func (AllocResult) Offset

func (r AllocResult) Offset(n uint64) memory.Pointer

Offset returns a pointer n bytes to the right of the associated range.

func (AllocResult) Ptr

func (r AllocResult) Ptr() memory.Pointer

Ptr returns the beginning of the range as an application pool pointer.

func (AllocResult) Range

func (r AllocResult) Range() memory.Range

Range returns the associated memory.Range.

type Cmd

type Cmd interface {
	// All commands belong to an API
	APIObject

	// Thread returns the thread index this command was executed on.
	Thread() uint64

	// SetThread changes the thread index.
	SetThread(uint64)

	// CmdName returns the name of the command.
	CmdName() string

	// CmdFlags returns the flags of the command.
	CmdFlags() CmdFlags

	// Extras returns all the Extras associated with the dynamic command.
	Extras() *CmdExtras

	// Mutate mutates the State using the command. If the builder argument is
	// not nil then it will call the replay function on the builder.
	Mutate(context.Context, *State, *builder.Builder) error
}

Cmd is the interface implemented by all graphics API commands.

func ServiceToCmd

func ServiceToCmd(c *Command) (Cmd, error)

ServiceToCmd returns the command built from c.

func WithExtras

func WithExtras(a Cmd, extras ...CmdExtra) Cmd

WithExtras adds the given extras to a command and returns it.

type CmdExtra

type CmdExtra interface{}

CmdExtra is the interface implemented by command 'extras' - additional information that can be placed inside a command.

type CmdExtras

type CmdExtras []CmdExtra

CmdExtras is a list of CmdExtra objects.

func (*CmdExtras) Aborted

func (e *CmdExtras) Aborted() *Aborted

Aborted returns a pointer to the Aborted structure in the CmdExtras, or nil if not found.

func (*CmdExtras) Add

func (e *CmdExtras) Add(es ...CmdExtra)

Add appends one or more CmdExtras to the list of CmdExtras.

func (*CmdExtras) All

func (e *CmdExtras) All() CmdExtras

func (*CmdExtras) Convert

func (e *CmdExtras) Convert(ctx context.Context, out atom_pb.Handler) error

Convert calls the Convert method on all the extras in the list.

func (*CmdExtras) GetOrAppendObservations

func (e *CmdExtras) GetOrAppendObservations() *CmdObservations

GetOrAppendObservations returns a pointer to the existing Observations structure in the CmdExtras, or appends and returns a pointer to a new observations structure if the CmdExtras does not already contain one.

func (*CmdExtras) Observations

func (e *CmdExtras) Observations() *CmdObservations

Observations returns a pointer to the CmdObservations structure in the CmdExtras, or nil if there are no observations in the CmdExtras.

type CmdFlags

type CmdFlags uint32

CmdFlags is a bitfield describing characteristics of a command.

const (
	DrawCall CmdFlags = 1 << iota
	Clear
	StartOfFrame
	EndOfFrame
	PushUserMarker
	PopUserMarker
	UserMarker
)

func (CmdFlags) IsClear

func (f CmdFlags) IsClear() bool

IsClear returns true if the atom is a clear call.

func (CmdFlags) IsDrawCall

func (f CmdFlags) IsDrawCall() bool

IsDrawCall returns true if the atom is a draw call.

func (CmdFlags) IsEndOfFrame

func (f CmdFlags) IsEndOfFrame() bool

IsEndOfFrame returns true if the atom represents the end of a frame.

func (CmdFlags) IsPopUserMarker

func (f CmdFlags) IsPopUserMarker() bool

IsPopUserMarker returns true if the atom represents the end of the last pushed user marker.

func (CmdFlags) IsPushUserMarker

func (f CmdFlags) IsPushUserMarker() bool

IsPushUserMarker returns true if the atom represents the start of a user marker group. The atom may implement the Labeled interface to expose the marker name.

func (CmdFlags) IsStartOfFrame

func (f CmdFlags) IsStartOfFrame() bool

IsStartOfFrame returns true if the atom represents the begin of a frame.

func (CmdFlags) IsUserMarker

func (f CmdFlags) IsUserMarker() bool

IsUserMarker returns true if the atom represents a non-grouping user marker. The atom may implement the Labeled interface to expose the marker name.

type CmdID

type CmdID uint64

CmdID is the index of an atom in an atom stream.

func (CmdID) Derived

func (id CmdID) Derived() CmdID

Derived is used to create an ID which is used for generated extra atoms. It is used purely for debugging (to print the related original atom ID).

func (CmdID) String

func (id CmdID) String() string

type CmdIDGroup

type CmdIDGroup struct {
	Name  string     // Name of this group.
	Range CmdIDRange // The range of commands this group (and items) represents.
	Spans Spans      // All sub-groups and sub-ranges of this group.
}

CmdIDGroup represents a named group of commands with support for sparse sub-groups and sub-command-ranges. Groups are ideal for expressing nested hierarchies of commands.

Groups have the concept of items. An item is either an immediate sub-group, or an command range that is within this group's span but outside of any sub-group.

func (*CmdIDGroup) AddAtoms

func (g *CmdIDGroup) AddAtoms(pred func(id CmdID) bool, maxChildren uint64) error

AddAtoms fills the group and sub-groups with commands based on the predicate pred. If maxChildren is positive, the group, and any of it's decendent groups, which have more than maxChildren child elements, will have their children grouped into new synthetic groups of at most maxChildren children.

func (*CmdIDGroup) AddGroup

func (g *CmdIDGroup) AddGroup(start, end CmdID, name string) error

AddGroup inserts a new sub-group with the specified range and name.

If the new group does not overlap any existing groups in the list then it is inserted into the list, keeping ascending command-identifier order. If the new group sits completely within an existing group then this new group will be added to the existing group's sub-groups. If the new group completely wraps one or more existing groups in the list then these existing groups are added as sub-groups to the new group and then the new group is added to the list, keeping ascending command-identifier order. If the new group partially overlaps any existing group then the function will return an error.

*** Warning *** All groups must be added before commands. Attemping to call this function after commands have been added may result in panics!

func (CmdIDGroup) Bounds

func (g CmdIDGroup) Bounds() CmdIDRange

func (CmdIDGroup) Count

func (g CmdIDGroup) Count() uint64

Count returns the number of immediate items this group contains.

func (CmdIDGroup) DeepCount

func (g CmdIDGroup) DeepCount(pred func(g CmdIDGroup) bool) uint64

DeepCount returns the total (recursive) number of items this group contains. The given predicate determines wheter the tested group is counted as 1 or is recursed into.

func (CmdIDGroup) Format

func (g CmdIDGroup) Format(f fmt.State, r rune)

Format writes a string representing the group's name, range and sub-groups.

func (CmdIDGroup) Index

func (g CmdIDGroup) Index(index uint64) CmdIDGroupOrID

Index returns the item at the specified index.

func (CmdIDGroup) IndexOf

func (g CmdIDGroup) IndexOf(id CmdID) uint64

IndexOf returns the item index that id refers directly to, or contains id.

func (CmdIDGroup) IterateBackwards

func (g CmdIDGroup) IterateBackwards(index uint64, cb func(childIdx uint64, item CmdIDGroupOrID) error) error

IterateBackwards calls cb with each contained command index or group starting with the item at index. If cb returns an error then traversal is stopped and the error is returned.

func (CmdIDGroup) IterateForwards

func (g CmdIDGroup) IterateForwards(index uint64, cb func(childIdx uint64, item CmdIDGroupOrID) error) error

IterateForwards calls cb with each contained command index or group starting with the item at index. If cb returns an error then traversal is stopped and the error is returned.

func (CmdIDGroup) Traverse

func (g CmdIDGroup) Traverse(backwards bool, start []uint64, cb TraverseCallback) error

Traverse traverses the command group starting with the specified index, calling cb for each encountered node.

type CmdIDGroupOrID

type CmdIDGroupOrID interface {
	// contains filtered or unexported methods
}

CmdIDGroupOrID is a dummy interface exclusively implemented by CmdIDGroup and CmdID.

type CmdIDRange

type CmdIDRange struct {
	Start CmdID // The first atom within the range.
	End   CmdID // One past the last atom within the range.
}

CmdIDRange describes an interval of commands.

func (CmdIDRange) Bounds

func (r CmdIDRange) Bounds() CmdIDRange

func (CmdIDRange) Clamp

func (i CmdIDRange) Clamp(id CmdID) CmdID

Clamp returns the nearest index in the range to id.

func (CmdIDRange) CmdIDRange

func (i CmdIDRange) CmdIDRange() (start, end CmdID)

CmdIDRange returns the start and end of the range.

func (CmdIDRange) Contains

func (i CmdIDRange) Contains(id CmdID) bool

Contains returns true if atomIndex is within the range, otherwise false.

func (CmdIDRange) First

func (i CmdIDRange) First() CmdID

First returns the first atom index within the range.

func (CmdIDRange) Last

func (i CmdIDRange) Last() CmdID

Last returns the last atom index within the range.

func (CmdIDRange) Length

func (i CmdIDRange) Length() uint64

Length returns the number of atoms in the range.

func (*CmdIDRange) SetSpan

func (i *CmdIDRange) SetSpan(span interval.U64Span)

SetSpan sets the start and end range using a U64Span.

func (CmdIDRange) Span

func (i CmdIDRange) Span() interval.U64Span

Span returns the start and end of the range as a U64Span.

func (CmdIDRange) Split

func (r CmdIDRange) Split(i uint64) (CmdIDRange, CmdIDRange)

Split splits this range into two subranges where the first range will have a length no larger than the given value.

func (CmdIDRange) String

func (i CmdIDRange) String() string

String returns a string representing the range.

type CmdIDSet

type CmdIDSet map[CmdID]struct{}

CmdIDSet is a set of CmdIDs.

func (*CmdIDSet) Add

func (s *CmdIDSet) Add(id CmdID)

Add adds id to the set. If the id was already in the set then the call does nothing.

func (CmdIDSet) Contains

func (s CmdIDSet) Contains(id CmdID) bool

Contains returns true if id is in the set, otherwise false.

func (*CmdIDSet) Remove

func (s *CmdIDSet) Remove(id CmdID)

Remove removes id from the set. If the id was not in the set then the call does nothing.

type CmdObservation

type CmdObservation struct {
	Range memory.Range // Memory range that was observed.
	ID    id.ID        // The resource identifier of the observed data.
}

CmdObservation represents a single read or write observation made by an atom.

func (CmdObservation) String

func (o CmdObservation) String() string

type CmdObservations

type CmdObservations struct {
	Reads  []CmdObservation
	Writes []CmdObservation
}

CmdObservations is a collection of reads and write observations performed by an atom.

func (*CmdObservations) AddRead

func (o *CmdObservations) AddRead(rng memory.Range, id id.ID)

AddRead appends the read to the list of observations.

func (*CmdObservations) AddWrite

func (o *CmdObservations) AddWrite(rng memory.Range, id id.ID)

AddWrite appends the write to the list of observations.

func (*CmdObservations) ApplyReads

func (o *CmdObservations) ApplyReads(p *memory.Pool)

ApplyReads applies all the observed reads to memory pool p. This is a no-op when called when o is nil.

func (*CmdObservations) ApplyWrites

func (o *CmdObservations) ApplyWrites(p *memory.Pool)

ApplyReads applies all the observed writes to the memory pool p. This is a no-op when called when o is nil.

func (*CmdObservations) DataString

func (o *CmdObservations) DataString(ctx context.Context) string

DataString returns a string describing all reads/writes and their raw data.

func (*CmdObservations) String

func (o *CmdObservations) String() string

type Context

type Context interface {
	// Name returns the display-name of the context.
	Name() string

	// ID returns the context's unique identifier
	ID() ContextID
}

Context represents a graphics API's unique context of execution.

type ContextID

type ContextID id.ID

ContextID is the unique identifier for a context.

type ErrCmdAborted

type ErrCmdAborted string

ErrCmdAborted is the error returned by Cmd.Mutate() when the execution was terminated by the abort() intrinsic.

func (ErrCmdAborted) Error

func (e ErrCmdAborted) Error() string

type ID

type ID id.ID

ID is an API identifier

func (ID) IsValid

func (i ID) IsValid() bool

IsValid returns true if the id is not the default zero value.

type Labeled

type Labeled interface {
	// Label returns the commands's label.
	Label(ctx context.Context, s *State) string
}

Labeled is the interface implemented commands that have a label.

type MeshProvider

type MeshProvider interface {
	// Mesh returns the mesh representation of the object o.
	// If nil, nil then the object cannot be represented as a mesh.
	Mesh(ctx context.Context, o interface{}, p *path.Mesh) (*Mesh, error)
}

MeshProvider is the interface implemented by types that provide meshes.

type ReplaceCallback

type ReplaceCallback func(where uint64, with interface{})

ReplaceCallback is called from SetResourceData to propagate changes to current atom stream.

type Resource

type Resource interface {
	// ResourceHandle returns the UI identity for the resource.
	// For GL this is the GLuint object name, for Vulkan the pointer.
	ResourceHandle() string

	// ResourceLabel returns the UI name for the resource.
	ResourceLabel() string

	// Order returns an integer used to sort the resources for presentation.
	Order() uint64

	// ResourceType returns the type of this resource.
	ResourceType(ctx context.Context) ResourceType

	// ResourceData returns the resource data given the current state.
	ResourceData(ctx context.Context, s *State) (*ResourceData, error)

	// SetResourceData sets resource data in a new capture.
	SetResourceData(ctx context.Context, at *path.Command, data *ResourceData, resources ResourceMap, edits ReplaceCallback) error
}

Resource represents an asset in a capture.

type ResourceMap

type ResourceMap map[Resource]id.ID

ResourceMap is a map from Resource to its id in a database.

type ResourceMeta

type ResourceMeta struct {
	Resource Resource    // Resolved resource.
	IDMap    ResourceMap // Map for resolved resources to ids.
}

ResourceMeta represents resource with a state information obtained during building.

type Span

type Span interface {
	// Bounds returns the absolute range of command indices for the span.
	Bounds() CmdIDRange
	// contains filtered or unexported methods
}

Span is a child of a CmdIDGroup. It is implemented by CmdIDGroup and Range.

type Spans

type Spans []Span

Spans is a list of Span elements. Functions in this package expect the list to be in ascending command index order, and maintain that order on mutation.

func (Spans) GetSpan

func (l Spans) GetSpan(index int) interval.U64Span

GetSpan returns the command index span for the group at index in the list.

func (*Spans) IndexOf

func (l *Spans) IndexOf(atomIndex uint64) int

IndexOf returns the index of the group that contains the command index or -1 if not found.

func (Spans) Length

func (l Spans) Length() int

Length returns the number of groups in the list.

type State

type State struct {
	// MemoryLayout holds information about the device memory layout that was
	// used to create the capture.
	MemoryLayout *device.MemoryLayout

	// Memory holds the memory state of the application.
	Memory memory.Pools

	// NextPoolID hold the identifier of the next Pool to be created.
	NextPoolID memory.PoolID

	// APIs holds the per-API context states.
	APIs map[API]interface{}

	// Allocator keeps track of and reserves memory areas not used in the trace.
	Allocator memory.Allocator

	// OnResourceCreated is called when a new resource is created.
	OnResourceCreated func(Resource)

	// OnResourceAccessed is called when a resource is used.
	OnResourceAccessed func(Resource)

	// OnError is called when the command does not conform to the API.
	OnError func(err interface{})

	// NewMessage is called when there is a message to be passed to a report.
	NewMessage func(level log.Severity, msg *stringtable.Msg) uint32

	// AddTag is called when we want to tag report item.
	AddTag func(msgID uint32, msg *stringtable.Msg)
}

State represents the graphics state across all contexts.

func NewStateWithAllocator

func NewStateWithAllocator(allocator memory.Allocator, memoryLayout *device.MemoryLayout) *State

NewStateWithAllocator returns a new, default-initialized State object, that uses the given memory.Allocator instance.

func NewStateWithEmptyAllocator

func NewStateWithEmptyAllocator(memoryLayout *device.MemoryLayout) *State

NewStateWithEmptyAllocator returns a new, default-initialized State object, that uses an allocator with no allocations.

func (*State) Alloc

func (s *State) Alloc(ctx context.Context, size uint64) (AllocResult, error)

Alloc allocates a memory range using the Allocator associated with the given State, and returns a AllocResult that can be used to access the pointer, and range.

func (*State) AllocData

func (s *State) AllocData(ctx context.Context, v ...interface{}) (AllocResult, error)

AllocData encodes and stores the value v to the database d, allocates a memory range big enough to store it using the Allocator associated with the given State, and returns a AllocResult that can be used to access the database ID, pointer, and range.

func (*State) AllocDataOrPanic

func (s *State) AllocDataOrPanic(ctx context.Context, v ...interface{}) AllocResult

AllocDataOrPanic is like AllocData, but panics if there's an error.

func (*State) AllocOrPanic

func (s *State) AllocOrPanic(ctx context.Context, size uint64) AllocResult

AllocOrPanic is like Alloc, but panics if there's an error.

func (State) MemoryDecoder

func (s State) MemoryDecoder(ctx context.Context, d memory.Data) *memory.Decoder

MemoryDecoder returns a memory decoder using the state's memory layout to decode data from d.

func (State) MemoryEncoder

func (s State) MemoryEncoder(p memory.PoolID, rng memory.Range) *memory.Encoder

MemoryEncoder returns a memory encoder using the state's memory layout to encode to the pool p, for the range rng.

func (State) MemoryReader

func (s State) MemoryReader(ctx context.Context, d memory.Data) binary.Reader

MemoryReader returns a binary reader using the state's memory endianness to read data from d.

func (State) MemoryWriter

func (s State) MemoryWriter(p memory.PoolID, rng memory.Range) binary.Writer

MemoryWriter returns a binary writer using the state's memory endianness to write data to the pool p, for the range rng.

func (State) String

func (s State) String() string

type TraverseCallback

type TraverseCallback func(indices []uint64, item CmdIDGroupOrID) error

TraverseCallback is the function that's called for each traversed item in a group.

Directories

Path Synopsis
Package all is used to import all known api APIs for their side effects.
Package all is used to import all known api APIs for their side effects.
core
core_pb
Package core_pb contains legacy protos which will be removed soon.
Package core_pb contains legacy protos which will be removed soon.
Package gles implementes the API interface for the OpenGL ES graphics library.
Package gles implementes the API interface for the OpenGL ES graphics library.
gles_pb
Package gles_pb describes the serialization format for the gles api.
Package gles_pb describes the serialization format for the gles api.
glsl
Package glsl contains routines for manipulation of OpenGL ES Shading Language programs.
Package glsl contains routines for manipulation of OpenGL ES Shading Language programs.
glsl/ast
Package ast defines the abstract syntax tree of OpenGL ES Shading Language programs.
Package ast defines the abstract syntax tree of OpenGL ES Shading Language programs.
glsl/builtins
Package builtins contains the definitions of all OpenGL ES Shading Language builtin functions.
Package builtins contains the definitions of all OpenGL ES Shading Language builtin functions.
glsl/evaluator
Package evaluator is responsible for evaluating expressions in OpenGL ES Shading Language programs.
Package evaluator is responsible for evaluating expressions in OpenGL ES Shading Language programs.
glsl/parser
Package parser implements parsing and serializing an OpenGL ES Shading Language programs.
Package parser implements parsing and serializing an OpenGL ES Shading Language programs.
glsl/preprocessor
Package preprocessor defines the preprocessor for the OpenGL ES Shading Language.
Package preprocessor defines the preprocessor for the OpenGL ES Shading Language.
glsl/sema
Package sema performs semantic checking of OpenGL ES Shading Language programs.
Package sema performs semantic checking of OpenGL ES Shading Language programs.
Package sync provides interfaces for managing externally synchronized APIs.
Package sync provides interfaces for managing externally synchronized APIs.
Package test is the integration test suite for the api compiler and templates.
Package test is the integration test suite for the api compiler and templates.
test_pb
Package test_pb describes the serialization format for the test api.
Package test_pb describes the serialization format for the test api.
Package testcmd provides fake commands used for testing.
Package testcmd provides fake commands used for testing.
Package transform provides transforms on commands.
Package transform provides transforms on commands.
Package vulkan implementes the API interface for the Vulkan graphics library.
Package vulkan implementes the API interface for the Vulkan graphics library.
vulkan_pb
Package vulkan_pb describes the serialization format for the vulkan api.
Package vulkan_pb describes the serialization format for the vulkan api.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL