gleval

package
v0.0.0-...-bed2388 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init1x1GLFW

func Init1x1GLFW() (terminate func(), err error)

Init1x1GLFW starts a 1x1 sized GLFW so that user can start working with GPU. It returns a termination function that should be called when user is done running loads on GPU.

func NormalsCentralDiff

func NormalsCentralDiff(s SDF3, pos []ms3.Vec, normals []ms3.Vec, step float32, userData any) error

NormalsCentralDiff uses central differences algorithm for normal calculation, which are stored in normals for each position. The returned normals are not normalized (converted to unit length).

Types

type BlockCachedSDF3

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

func (*BlockCachedSDF3) Bounds

func (c3 *BlockCachedSDF3) Bounds() ms3.Box

Bounds returns the SDF's bounding box such that all of the shape is contained within.

func (*BlockCachedSDF3) CacheHits

func (c3 *BlockCachedSDF3) CacheHits() uint64

CacheHits returns total amount of cached evalutions done throughout the SDF's lifetime.

func (*BlockCachedSDF3) Evaluate

func (c3 *BlockCachedSDF3) Evaluate(pos []ms3.Vec, dist []float32, userData any) error

Evaluate implements the SDF3 interface with cached evaluation.

func (*BlockCachedSDF3) Evaluations

func (c3 *BlockCachedSDF3) Evaluations() uint64

Evaluations returns total evaluations performed succesfully during sdf's lifetime, including cached.

func (*BlockCachedSDF3) Reset

func (c3 *BlockCachedSDF3) Reset(sdf SDF3, resX, resY, resZ float32) error

Reset resets the SDF3 and reuses the underlying buffers for future SDF evaluations. It also resets statistics such as evaluations and cache hits.

func (*BlockCachedSDF3) VecPool

func (c3 *BlockCachedSDF3) VecPool() *VecPool

type ComputeConfig

type ComputeConfig struct {
	// InvocX represents the size of the worker group in warps/invocations as configured in the shader.
	// This is configured in a declaration of the following style in the shader:
	//  layout(local_size_x = <InvocX>, local_size_y = 1, local_size_z = 1) in;
	InvocX int
	// ShaderObjects contains buffer data and definitions required by shader for correct evaluation.
	ShaderObjects []glbuild.ShaderObject
}

type DisplaceMulti2D

type DisplaceMulti2D struct {
	Displacements []ms2.Vec
	// contains filtered or unexported fields
}

PolygonGPU implements a direct polygon evaluation via GPU.

func (*DisplaceMulti2D) Bounds

func (disp *DisplaceMulti2D) Bounds() ms2.Box

func (*DisplaceMulti2D) Configure

func (disp *DisplaceMulti2D) Configure(programmer *glbuild.Programmer, element glbuild.Shader2D, cfg ComputeConfig) error

func (*DisplaceMulti2D) Evaluate

func (disp *DisplaceMulti2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error

type Lines2DGPU

type Lines2DGPU struct {
	Lines [][2]ms2.Vec
	Width float32
	// contains filtered or unexported fields
}

PolygonGPU implements a direct polygon evaluation via GPU.

func (*Lines2DGPU) Bounds

func (lines *Lines2DGPU) Bounds() ms2.Box

func (*Lines2DGPU) Configure

func (lines *Lines2DGPU) Configure(cfg ComputeConfig) error

func (*Lines2DGPU) Evaluate

func (lines *Lines2DGPU) Evaluate(pos []ms2.Vec, dist []float32, userData any) error

type PolygonGPU

type PolygonGPU struct {
	Vertices []ms2.Vec
	// contains filtered or unexported fields
}

PolygonGPU implements a direct polygon evaluation via GPU.

func (*PolygonGPU) Bounds

func (poly *PolygonGPU) Bounds() ms2.Box

func (*PolygonGPU) Configure

func (poly *PolygonGPU) Configure(cfg ComputeConfig) error

func (*PolygonGPU) Evaluate

func (poly *PolygonGPU) Evaluate(pos []ms2.Vec, dist []float32, userData any) error

type SDF2

type SDF2 interface {
	// Evaluate evaluates the signed distance field over pos positions.
	// dist and pos must be of same length.  Resulting distances are stored
	// in dist.
	//
	// userData facilitates getting data to the evaluators for use in processing, such as [VecPool].
	Evaluate(pos []ms2.Vec, dist []float32, userData any) error
	// Bounds returns the SDF's bounding box such that all of the shape is contained within.
	Bounds() ms2.Box
}

SDF2 implements a 2D signed distance field in vectorized form suitable for running on GPU.

func AssertSDF2

func AssertSDF2(s bounder2) (SDF2, error)

AssertSDF2 asserts the argument as a SDF2 implementation and returns the raw result. It provides readable errors beyond simply converting the interface.

type SDF2CPU

type SDF2CPU struct {
	SDF SDF2
	// contains filtered or unexported fields
}

func NewCPUSDF2

func NewCPUSDF2(root bounder2) (*SDF2CPU, error)

NewCPUSDF2 checks if the shader implements CPU evaluation and returns a SDF2CPU ready for evaluation, taking care of the buffers for evaluating the SDF correctly.

The returned SDF2 should only require a gleval.VecPool as a userData argument, this is automatically taken care of if a nil userData is passed in.

func (*SDF2CPU) Bounds

func (sdf *SDF2CPU) Bounds() ms2.Box

Bounds returns the bounds of the underlying SDF.

func (*SDF2CPU) Evaluate

func (sdf *SDF2CPU) Evaluate(pos []ms2.Vec, dist []float32, userData any) error

Evaluate performs CPU evaluation of the underlying SDF2.

func (*SDF2CPU) Evaluations

func (sdf *SDF2CPU) Evaluations() uint64

Evaluations returns total evaluations performed succesfully during sdf's lifetime.

func (*SDF2CPU) VecPool

func (sdf *SDF2CPU) VecPool() *VecPool

VecPool method exposes the SDF2CPU's VecPool in case user wishes to use their own userData in evaluations.

type SDF2Compute

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

func NewComputeGPUSDF2

func NewComputeGPUSDF2(glglSourceCode io.Reader, bb ms2.Box, cfg ComputeConfig) (*SDF2Compute, error)

NewComputeGPUSDF2 instantiates a SDF2 that runs on the GPU.

func (*SDF2Compute) Bounds

func (sdf *SDF2Compute) Bounds() ms2.Box

func (*SDF2Compute) Evaluate

func (sdf *SDF2Compute) Evaluate(pos []ms2.Vec, dist []float32, userData any) error

func (*SDF2Compute) Evaluations

func (sdf *SDF2Compute) Evaluations() uint64

Evaluations returns total evaluations performed succesfully during sdf's lifetime.

type SDF3

type SDF3 interface {
	// Evaluate evaluates the signed distance field over pos positions.
	// dist and pos must be of same length.  Resulting distances are stored
	// in dist.
	//
	// userData facilitates getting data to the evaluators for use in processing, such as [VecPool].
	Evaluate(pos []ms3.Vec, dist []float32, userData any) error
	// Bounds returns the SDF's bounding box such that all of the shape is contained within.
	Bounds() ms3.Box
}

SDF3 implements a 3D signed distance field in vectorized form suitable for running on GPU.

func AssertSDF3

func AssertSDF3(s bounder3) (SDF3, error)

AssertSDF3 asserts the Shader3D as a SDF3 implementation and returns the raw result. It provides readable errors beyond simply converting the interface.

type SDF3CPU

type SDF3CPU struct {
	SDF SDF3
	// contains filtered or unexported fields
}

func NewCPUSDF3

func NewCPUSDF3(root bounder3) (*SDF3CPU, error)

NewCPUSDF2 checks if the shader implements CPU evaluation and returns a *SDF3CPU ready for evaluation, taking care of the buffers for evaluating the SDF correctly.

The returned SDF3 should only require a VecPool as a userData argument, this is automatically taken care of if a nil userData is passed in.

func (*SDF3CPU) Bounds

func (sdf *SDF3CPU) Bounds() ms3.Box

func (*SDF3CPU) Evaluate

func (sdf *SDF3CPU) Evaluate(pos []ms3.Vec, dist []float32, userData any) error

func (*SDF3CPU) Evaluations

func (sdf *SDF3CPU) Evaluations() uint64

Evaluations returns total evaluations performed succesfully during sdf's lifetime.

func (*SDF3CPU) VecPool

func (sdf *SDF3CPU) VecPool() *VecPool

VecPool method exposes the SDF3CPU's VecPool in case user wishes to use their own userData in evaluations.

type SDF3Compute

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

func NewComputeGPUSDF3

func NewComputeGPUSDF3(glglSourceCode io.Reader, bb ms3.Box, cfg ComputeConfig) (*SDF3Compute, error)

NewComputeGPUSDF3 instantiates a SDF3 that runs on the GPU.

func (*SDF3Compute) Bounds

func (sdf *SDF3Compute) Bounds() ms3.Box

func (*SDF3Compute) Evaluate

func (sdf *SDF3Compute) Evaluate(pos []ms3.Vec, dist []float32, userData any) error

func (*SDF3Compute) Evaluations

func (sdf *SDF3Compute) Evaluations() uint64

Evaluations returns total evaluations performed succesfully during sdf's lifetime.

type VecPool

type VecPool struct {
	V3    bufPool[ms3.Vec]
	V2    bufPool[ms2.Vec]
	Float bufPool[float32]
}

VecPool serves as a pool of Vec3 and float32 slices for evaluating SDFs on the CPU while reducing garbage generation. It also aids in calculation of memory usage.

func GetVecPool

func GetVecPool(userData any) (*VecPool, error)

GetVecPool asserts the userData as a VecPool. If assert fails then an error is returned with information on what went wrong.

func (*VecPool) AssertAllReleased

func (vp *VecPool) AssertAllReleased() error

AssertAllReleased checks all buffers are not in use. Should be called after ending a run to find memory leaks.

func (*VecPool) SetMinAllocationLen

func (vp *VecPool) SetMinAllocationLen(minumumAlloca int)

SetMinAllocationLen sets the minimum length allocated when creating a new buffer for all buffer pools.

func (*VecPool) TotalSize

func (vp *VecPool) TotalSize() uint64

TotalSize returns the number of bytes allocated by all underlying buffers.

Jump to

Keyboard shortcuts

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