vgpu

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: BSD-3-Clause Imports: 22 Imported by: 10

README

vGPU: emergent GPU hardware support

GoDocs for vGPU

Note: this is the sub-readme docs for the vgpu library itself, whereas overall repo project README can provide higher-level intro -- this is more for the "tech nitty-gritty".

This is a work in progress exploring using Vulkan to access the GPU. Ultimately, it should replace the opengl implementation of the oswin/gpu interfaces in GoGi, to provide a more future-proof graphics backend. As such, the code is being organized around that structure.

The Go vulkan bindings are from here: https://github.com/goki/vulkan, and the initial boilerplate code for various things is from https://github.com/vulkan-go/asche and https://github.com/vulkan-go/demos

Key docs for all major Vulkan types: https://gpuopen.com/learn/understanding-vulkan-objects/

For compute engine use, we are following this tutorial and associated linked ones: https://bakedbits.dev/posts/vulkan-compute-example/

TODO

  • verify that Mem.Config works when called repeatedly.

  • multisampling

  • Full Phong package -- shouldn't have to write that separately.

Documentation

Index

Constants

View Source
const (
	// FlipY used as named arg for flipping the Y axis of images, etc
	FlipY = true

	// NoFlipY uased as named arg for not flipping the Y axis of images
	NoFlipY = false
)
View Source
const (
	// CullBack is for SetCullFace function
	CullBack = true

	// CullFront is for SetCullFace function
	CullFront = false

	// CCW is for SetFrontFace function
	CCW = true

	// CW is for SetFrontFace function
	CW = false
)
View Source
const (
	// MaxTexturesPerSet is the maximum number of image variables that can be used
	// in one descriptor set.  This value is a lowest common denominator across
	// platforms.  To overcome this limitation, when more Texture vals are allocated,
	// multiple NDescs are used, setting the and switch
	// across those -- each such Desc set can hold this many textures.
	// NValsPer on a Texture var can be set higher and only this many will be
	// allocated in the descriptor set, with bindings of values wrapping
	// around across as many such sets as are vals, with a warning if insufficient
	// numbers are present.
	MaxTexturesPerSet = 16

	// MaxImageLayers is the maximum number of layers per image
	MaxImageLayers = 128
)
View Source
const (
	VertexSet = -2
	PushSet   = -1
)
View Source
const (
	Version     = "v1.0.0"
	GitCommit   = "5c94a0e"          // the commit JUST BEFORE the release
	VersionDate = "2022-06-01 09:38" // UTC
)

Variables

BuffUsages maps BuffTypes into buffer usage flags

FormatSizes gives size of known vulkan formats in bytes

View Source
var ImageFormatNames = map[vk.Format]string{
	vk.FormatR8g8b8a8Srgb:           "RGBA 8bit sRGB colorspace",
	vk.FormatR8g8b8a8Unorm:          "RGBA 8bit unsigned linear colorspace",
	vk.FormatR5g6b5UnormPack16:      "RGB 5bit (pack 16bit total) unsigned linear colorspace",
	vk.FormatA2b10g10r10UnormPack32: "ABGR 10bit, 2bit alpha (pack 32bit total), unsigned linear colorspace",
	vk.FormatB8g8r8a8Srgb:           "BGRA 8bit sRGB colorspace",
	vk.FormatB8g8r8a8Unorm:          "BGRA 8bit unsigned linear colorspace",
	vk.FormatR16g16b16a16Sfloat:     "RGBA 16bit signed floating point linear colorspace",
	vk.FormatA2r10g10b10UnormPack32: "ARGB 10bit, 2bit alpha (pack 32bit total), unsigned linear colorspace",
}

ImageFormatNames translates image format into human-readable string for most commonly-available formats

View Source
var KiT_BorderColors = kit.Enums.AddEnum(BorderColorsN, kit.NotBitFlag, nil)
View Source
var KiT_BuffTypes = kit.Enums.AddEnum(BuffTypesN, kit.NotBitFlag, nil)
View Source
var KiT_ImageFlags = kit.Enums.AddEnum(ImageFlagsN, kit.BitFlag, nil)
View Source
var KiT_SamplerModes = kit.Enums.AddEnum(SamplerModesN, kit.NotBitFlag, nil)
View Source
var KiT_Topologies = kit.Enums.AddEnum(TopologiesN, kit.NotBitFlag, nil)
View Source
var KiT_Types = kit.Enums.AddEnum(TypesN, kit.NotBitFlag, nil)
View Source
var KiT_ValFlags = kit.Enums.AddEnum(ValFlagsN, kit.BitFlag, nil)
View Source
var KiT_VarRoles = kit.Enums.AddEnum(VarRolesN, kit.NotBitFlag, nil)

RoleBuffers maps VarRoles onto type of memory buffer

VulkanTypes maps vgpu.Types to vulkan types

Functions

func AllocBuffMem

func AllocBuffMem(dev vk.Device, buffer vk.Buffer, props vk.MemoryPropertyFlagBits) vk.DeviceMemory

AllocBuffMem allocates memory for given buffer, with given properties

func CheckErr

func CheckErr(err *error)

func CheckExisting

func CheckExisting(actual, required []string) (existing []string, missing int)

func CmdBegin

func CmdBegin(cmd vk.CommandBuffer)

CmdBegin does BeginCommandBuffer on buffer

func CmdBeginOneTime

func CmdBeginOneTime(cmd vk.CommandBuffer)

CmdBeginOneTime does BeginCommandBuffer with OneTimeSubmit set on buffer

func CmdEnd

func CmdEnd(cmd vk.CommandBuffer)

CmdEnd does EndCommandBuffer on buffer

func CmdReset

func CmdReset(cmd vk.CommandBuffer)

CmdReset resets the command buffer so it is ready for recording new commands.

func CmdResetBegin

func CmdResetBegin(cmd vk.CommandBuffer)

CmdResetBegin resets the command buffer so it is ready for recording new commands. and then calls CmdBegin to begin recording

func CmdSubmit

func CmdSubmit(cmd vk.CommandBuffer, dev *Device)

CmdSubmit submits commands in buffer to given device queue, without any semaphore logic -- suitable for a WaitIdle logic.

func CmdSubmitWait

func CmdSubmitWait(cmd vk.CommandBuffer, dev *Device)

CmdSubmitWait does End, Submit, WaitIdle on command Buffer

func DestroyBuffer

func DestroyBuffer(dev vk.Device, buff *vk.Buffer)

DestroyBuffer destroys given buffer and nils the pointer

func DeviceExts

func DeviceExts(gpu vk.PhysicalDevice) (names []string, err error)

DeviceExts gets a list of instance extensions available on the provided physical device.

func FindRequiredMemoryType

func FindRequiredMemoryType(props vk.PhysicalDeviceMemoryProperties,
	deviceRequirements, hostRequirements vk.MemoryPropertyFlagBits) (uint32, bool)

func FindRequiredMemoryTypeFallback

func FindRequiredMemoryTypeFallback(props vk.PhysicalDeviceMemoryProperties,
	deviceRequirements, hostRequirements vk.MemoryPropertyFlagBits) (uint32, bool)

func FindString

func FindString(str string, strs []string) int

FindString returns index of string if in list, else -1

func FreeBuffMem

func FreeBuffMem(dev vk.Device, memory *vk.DeviceMemory)

FreeBuffMem frees given device memory to nil

func IfPanic

func IfPanic(err error, finalizers ...func())

func InstanceExts

func InstanceExts() (names []string, err error)

InstanceExts gets a list of instance extensions available on the platform.

func IsError

func IsError(ret vk.Result) bool

func MapMemory

func MapMemory(dev vk.Device, mem vk.DeviceMemory, size int) unsafe.Pointer

MapMemory maps the buffer memory, returning a pointer into start of buffer memory

func MapMemoryAll

func MapMemoryAll(dev vk.Device, mem vk.DeviceMemory) unsafe.Pointer

MapMemoryAll maps the WholeSize of buffer memory, returning a pointer into start of buffer memory

func MemSizeAlign

func MemSizeAlign(size, align int) int

MemSizeAlign returns the size aligned according to align byte increments e.g., if align = 16 and size = 12, it returns 16

func NDescForTextures

func NDescForTextures(nvals int) int

NDescForTextures returns number of descriptors (NDesc) required for given number of texture values.

func NewBuffer

func NewBuffer(dev vk.Device, size int, usage vk.BufferUsageFlagBits) vk.Buffer

NewBuffer makes a buffer of given size, usage

func NewError

func NewError(ret vk.Result) error

func NewFence

func NewFence(dev vk.Device) vk.Fence

func NewSemaphore

func NewSemaphore(dev vk.Device) vk.Semaphore

func PlatformDefaults added in v1.0.0

func PlatformDefaults(gp *GPU)

func SafeString

func SafeString(s string) string

func SafeStrings

func SafeStrings(list []string) []string

func SaveImage

func SaveImage(path string, im image.Image) error

SaveImage saves image to file, with format inferred from filename -- JPEG and PNG supported by default.

func SliceUint32

func SliceUint32(data []byte) []uint32

func ValidationLayers

func ValidationLayers() (names []string, err error)

ValidationLayers gets a list of validation layers available on the platform.

Types

type BorderColors

type BorderColors int32

Texture image sampler modes

const (
	// Repeat the texture when going beyond the image dimensions.
	BorderTrans BorderColors = iota
	BorderBlack
	BorderWhite

	BorderColorsN
)

func (*BorderColors) FromString

func (i *BorderColors) FromString(s string) error

func (BorderColors) String

func (i BorderColors) String() string

func (BorderColors) VkColor

func (bc BorderColors) VkColor() vk.BorderColor

type BuffTypes

type BuffTypes int32

BuffTypes are memory buffer types managed by the Memory object

const (
	// VtxIdxBuff is a buffer holding Vertex and Index values
	VtxIdxBuff BuffTypes = iota

	// UniformBuff holds Uniform and UniformTexel objects: read-only, small footprint
	UniformBuff

	// StorageBuff holds Storage and StorageTexel: read-write, larger
	// mostly for compute shaders
	StorageBuff

	// TextureBuff holds Images / Textures -- hardware optimizes allocation
	// on device side, and staging-side is general
	TextureBuff

	BuffTypesN
)

func (BuffTypes) AlignBytes

func (bt BuffTypes) AlignBytes(gp *GPU) int

AlignBytes returns alignment bytes for offsets into given buffer

func (*BuffTypes) FromString

func (i *BuffTypes) FromString(s string) error

func (BuffTypes) IsReadOnly

func (bt BuffTypes) IsReadOnly() bool

IsReadOnly returns true if buffer is read-only (most), else read-write (Storage)

func (BuffTypes) String

func (i BuffTypes) String() string

type CmdPool

type CmdPool struct {
	Pool vk.CommandPool
	Buff vk.CommandBuffer
}

CmdPool is a command pool and buffer

func (*CmdPool) BeginCmd

func (cp *CmdPool) BeginCmd() vk.CommandBuffer

BeginCmd does BeginCommandBuffer on buffer

func (*CmdPool) BeginCmdOneTime

func (cp *CmdPool) BeginCmdOneTime() vk.CommandBuffer

BeginCmdOneTime does BeginCommandBuffer with OneTimeSubmit set on buffer

func (*CmdPool) ConfigResettable

func (cp *CmdPool) ConfigResettable(dv *Device)

ConfigResettable configures the pool for persistent, resettable command buffers, used for rendering commands.

func (*CmdPool) ConfigTransient

func (cp *CmdPool) ConfigTransient(dv *Device)

ConfigTransient configures the pool for transient command buffers, which are best used for random functions, such as memory copying. Use SubmitWaitFree logic.

func (*CmdPool) Destroy

func (cp *CmdPool) Destroy(dev vk.Device)

Destroy

func (*CmdPool) EndCmd

func (cp *CmdPool) EndCmd()

EndCmd does EndCommandBuffer on buffer

func (*CmdPool) FreeBuffer

func (cp *CmdPool) FreeBuffer(dev *Device)

FreeBuffer frees the current Buff buffer

func (*CmdPool) NewBuffer

func (cp *CmdPool) NewBuffer(dv *Device) vk.CommandBuffer

NewBuffer makes a buffer in pool, setting Buff to point to it and also returning the buffer.

func (*CmdPool) Reset

func (cp *CmdPool) Reset()

Reset resets the command buffer so it is ready for recording new commands.

func (*CmdPool) Submit

func (cp *CmdPool) Submit(dev *Device)

Submit submits commands in buffer to given device queue, without any semaphore logic -- suitable for a WaitIdle logic.

func (*CmdPool) SubmitWait

func (cp *CmdPool) SubmitWait(dev *Device)

SubmitWait does End, Submit, WaitIdle on Buffer

func (*CmdPool) SubmitWaitFree

func (cp *CmdPool) SubmitWaitFree(dev *Device)

SubmitWaitFree does End, Submit, WaitIdle, Free on Buffer

type Device

type Device struct {
	Device     vk.Device `desc:"logical device"`
	QueueIndex uint32    `desc:"queue index for device"`
	Queue      vk.Queue  `desc:"queue for device"`
}

Device holds Device and associated Queue info

func (*Device) Destroy

func (dv *Device) Destroy()

func (*Device) FindQueue

func (dv *Device) FindQueue(gp *GPU, flags vk.QueueFlagBits) error

FindQueue finds queue for given flag bits, sets in QueueIndex returns error if not found.

func (*Device) Init

func (dv *Device) Init(gp *GPU, flags vk.QueueFlagBits) error

Init initializes a device based on QueueFlagBits

func (*Device) MakeDevice

func (dv *Device) MakeDevice(gp *GPU)

MakeDevice and Queue based on QueueIndex

type Framebuffer

type Framebuffer struct {
	Format      ImageFormat    `desc:"target framebuffer format -- if multisampling is active then Image has samples = 1, Render.Multi has full samples"`
	Image       Image          `desc:"the image behind the framebuffer, includes the format -- this "`
	Render      *Render        `desc:"pointer to the associated renderpass and depth buffer"`
	Framebuffer vk.Framebuffer `desc:"vulkan framebuffer"`
	HasCleared  bool           `desc:"has this framebuffer been cleared yet?  if not, must be prior to use as a non-clearing Load case"`
}

Framebuffer combines an Image and Render info (which has a depth buffer)

func (*Framebuffer) Config

func (fb *Framebuffer) Config()

Config configures a new vulkan framebuffer object with current settings, destroying any existing

func (*Framebuffer) ConfigRender

func (fb *Framebuffer) ConfigRender(rp *Render)

ConfigRender configures for Render, assuming image is already set and Configs the Framebuffer based on that.

func (*Framebuffer) ConfigRenderImage

func (fb *Framebuffer) ConfigRenderImage(dev vk.Device, fmt ImageFormat)

ConfigRenderImage configures a new image for a standalone framebuffer not associated with an existing surface, for RenderFrame target. In general it is recommended to use vk.SampleCount4Bit to avoid aliasing. Does not yet make the Framebuffer because it still needs the Render (see ConfigRender)

func (*Framebuffer) ConfigSurfaceImage

func (fb *Framebuffer) ConfigSurfaceImage(dev vk.Device, fmt ImageFormat, img vk.Image)

ConfigSurfaceImage configures settings for given existing surface image and format. Does not yet make the Framebuffer because it still needs the Render (see ConfigAll for all)

func (*Framebuffer) CopyToImage

func (fb *Framebuffer) CopyToImage(toImg *Image, dev vk.Device, cmd vk.CommandBuffer)

CopyToImage copies the current framebuffer image to given image dest using given command buffer which must have the cmdBegin called already.

func (*Framebuffer) Destroy

func (fb *Framebuffer) Destroy()

Destroy destroys everything

func (*Framebuffer) DestroyFrame

func (fb *Framebuffer) DestroyFrame()

DestroyFrame destroys the framebuffer if non-nil

func (*Framebuffer) GrabImage

func (fb *Framebuffer) GrabImage(dev vk.Device, cmd vk.CommandBuffer)

GrabImage grabs the current framebuffer image, using given command buffer which must have the cmdBegin called already.

type GPU

type GPU struct {
	Instance         vk.Instance            `desc:"handle for the vulkan driver instance"`
	GPU              vk.PhysicalDevice      `desc:"handle for the vulkan physical GPU hardware"`
	AppName          string                 `desc:"name of application -- set during Config and used in init of GPU"`
	APIVersion       vk.Version             `desc:"version of vulkan API to target"`
	AppVersion       vk.Version             `desc:"version of application -- optional"`
	InstanceExts     []string               `desc:"use Add method to add required instance extentions prior to calling Config"`
	DeviceExts       []string               `desc:"use Add method to add required device extentions prior to calling Config"`
	ValidationLayers []string               `desc:"set Add method to add required validation layers prior to calling Config"`
	Debug            bool                   `desc:"set to true prior to calling Config to enable debug mode"`
	DebugCallback    vk.DebugReportCallback `desc:"our custom debug callback"`

	GPUProps    vk.PhysicalDeviceProperties       `desc:"properties of physical hardware -- populated after Config"`
	MemoryProps vk.PhysicalDeviceMemoryProperties `desc:"properties of device memory -- populated after Config"`
}

GPU represents the GPU hardware

var TheGPU *GPU

TheGPU is a global for the GPU

func NewComputeGPU

func NewComputeGPU() *GPU

NewComputeGPU returns a new GPU struct with Compute Defaults set configure any additional defaults before calling Config. Use NewGPU for a graphics enabled GPU.

func NewGPU

func NewGPU() *GPU

NewGPU returns a new GPU struct with Graphics Defaults set configure any additional defaults before calling Config. Use NewComputeGPU for a compute-only GPU that doesn't load graphics extensions.

func (*GPU) AddDeviceExt

func (gp *GPU) AddDeviceExt(ext ...string) bool

AddDeviceExt adds given extension(s), only if not already set returns true if added.

func (*GPU) AddInstanceExt

func (gp *GPU) AddInstanceExt(ext ...string) bool

AddInstanceExt adds given extension(s), only if not already set returns true if added.

func (*GPU) AddValidationLayer

func (gp *GPU) AddValidationLayer(ext string) bool

AddValidationLayer adds given validation layer, only if not already set returns true if added.

func (*GPU) Config

func (gp *GPU) Config(name string) error

Config

func (*GPU) Defaults

func (gp *GPU) Defaults(graphics bool)

Defaults sets up default parameters, with the graphics flag determining whether graphics-relevant items are added.

func (*GPU) Destroy

func (gp *GPU) Destroy()

Destroy destroys GPU resources -- call after everything else has been destroyed

func (*GPU) NewComputeSystem

func (gp *GPU) NewComputeSystem(name string) *System

NewComputeSystem returns a new system initialized for this GPU, for Compute, not graphics functionality.

func (*GPU) NewGraphicsSystem

func (gp *GPU) NewGraphicsSystem(name string, dev *Device) *System

NewGraphicsSystem returns a new system initialized for this GPU, for graphics functionality, using Device from the Surface or RenderFrame depending on the target of rendering.

func (*GPU) PropsString

func (gp *GPU) PropsString(print bool) string

PropsString returns a human-readable summary of the GPU properties.

type HostImage

type HostImage struct {
	Size   int             `desc:"size in bytes allocated for host representation of image"`
	Buff   vk.Buffer       `view:"-" desc:"buffer for host CPU-visible memory, for staging -- can be owned by us or managed by Memory (for Val)"`
	Offset int             `desc:"offset into host buffer, when Buff is Memory managed"`
	Mem    vk.DeviceMemory `view:"-" desc:"host CPU-visible memory, for staging, when we manage our own memory"`
	Ptr    unsafe.Pointer  `view:"-" desc:"memory mapped pointer into host memory -- remains mapped"`
}

HostImage is the host representation of an Image

func (*HostImage) Pixels

func (hi *HostImage) Pixels() []byte

Pixels returns the byte slice of the pixels for host image Only valid if host is active! No error checking is performed here.

func (*HostImage) SetNil

func (hi *HostImage) SetNil()

type Image

type Image struct {
	Name   string          `` /* 153-byte string literal not displayed */
	Flags  int32           `desc:"bit flags for image state, for indicating nature of ownership and state"`
	Format ImageFormat     `desc:"format & size of image"`
	Image  vk.Image        `view:"-" desc:"vulkan image handle, in device memory"`
	View   vk.ImageView    `view:"-" desc:"vulkan image view"`
	Mem    vk.DeviceMemory `view:"-" desc:"memory for image when we allocate it"`
	Dev    vk.Device       `view:"-" desc:"keep track of device for destroying view"`
	Host   HostImage       `desc:"host memory buffer representation of the image"`
}

Image represents a vulkan image with an associated ImageView. The vulkan Image is in device memory, in an optimized format. There can also be an optional host-visible, plain pixel buffer which can be a pointer into a larger buffer or owned by the Image.

func (*Image) AllocHost

func (im *Image) AllocHost()

AllocHost allocates a staging buffer on the host for the image on the device (must set first), based on the current Format info, and other flags. If the existing host buffer is sufficient to hold the image, then nothing happens.

func (*Image) AllocImage

func (im *Image) AllocImage()

AllocImage allocates the VkImage on the device (must set first), based on the current Format info, and other flags.

func (*Image) ClearFlag

func (im *Image) ClearFlag(flag ...int)

ClearFlag clears flag(s) using atomic, safe for concurrent access

func (*Image) ConfigDepth

func (im *Image) ConfigDepth(dev vk.Device, depthType Types, imgFmt *ImageFormat)

ConfigDepth configures this image as a depth image using given depth image format, and other on format information from the render image format.

func (*Image) ConfigDepthView

func (im *Image) ConfigDepthView()

ConfigDepthView configures a depth view image

func (*Image) ConfigFramebuffer

func (im *Image) ConfigFramebuffer(dev vk.Device, imgFmt *ImageFormat)

ConfigFramebuffer configures this image as a framebuffer image using format. Sets multisampling to 1, layers to 1. Only makes a device image -- no host rep.

func (*Image) ConfigGoImage

func (im *Image) ConfigGoImage(sz image.Point, layers int)

ConfigGoImage configures the image for storing an image of the given size, for images allocated in a shared host buffer. (i.e., not Var.TextureOwns). Image format will be set to default unless format is already set. Layers is number of separate images of given size allocated in a texture array. Once memory is allocated then SetGoImage can be called in a second pass.

func (*Image) ConfigMulti

func (im *Image) ConfigMulti(dev vk.Device, imgFmt *ImageFormat)

ConfigMulti configures this image as a mutisampling image using format. Only makes a device image -- no host rep.

func (*Image) ConfigStdView

func (im *Image) ConfigStdView()

ConfigStdView configures a standard 2D image view, for current image, format, and device.

func (*Image) ConfigValHost

func (im *Image) ConfigValHost(buff *MemBuff, buffPtr unsafe.Pointer, offset int)

ConfigValHost configures host staging buffer from memory buffer for val-owned image

func (*Image) CopyImageRec

func (im *Image) CopyImageRec() vk.ImageCopy

CopyImageRec returns info for this Image for the ImageCopy operations

func (*Image) CopyRec

func (im *Image) CopyRec() vk.BufferImageCopy

CopyRec returns info for this Image for the BufferImageCopy operations

func (*Image) Destroy

func (im *Image) Destroy()

Destroy destroys any existing view, nils fields

func (*Image) DestroyView

func (im *Image) DestroyView()

DestroyView destroys any existing view

func (*Image) DevGoImage

func (im *Image) DevGoImage() (*image.RGBA, error)

DevGoImage returns an *image.RGBA standard Go image, of the Device memory representation. Only works if ImageOnHostOnly and Format is default vk.FormatR8g8b8a8Srgb (strongly recommended in any case)

func (*Image) FreeHost

func (im *Image) FreeHost()

FreeHost frees memory in host buffer representation of image Only if we own the host buffer.

func (*Image) FreeImage

func (im *Image) FreeImage()

FreeImage frees device memory version of image that we own

func (*Image) GoImage

func (im *Image) GoImage(layer int) (*image.RGBA, error)

GoImage returns an *image.RGBA standard Go image, of the Host memory representation at given layer. Only works if IsHostActive and Format is default vk.FormatR8g8b8a8Srgb (strongly recommended in any case)

func (*Image) HasFlag

func (im *Image) HasFlag(flag ImageFlags) bool

HasFlag checks if flag is set using atomic, safe for concurrent access

func (*Image) HostPixels

func (im *Image) HostPixels(layer int) []byte

HostPixels returns host staging pixels at given layer

func (*Image) IsActive

func (im *Image) IsActive() bool

IsActive returns true if the image is set and has a view

func (*Image) IsHostActive

func (im *Image) IsHostActive() bool

IsHostActive returns true if the Host accessible version of image is active and ready to use

func (*Image) IsHostOwner

func (im *Image) IsHostOwner() bool

IsHostOwner returns true if the host buffer is owned by us

func (*Image) IsImageOwner

func (im *Image) IsImageOwner() bool

IsImageOwner returns true if the vk.Image is owned by us

func (*Image) IsVal

func (im *Image) IsVal() bool

IsVal returns true if the image belongs to a Val

func (*Image) SetFlag

func (im *Image) SetFlag(flag ...int)

SetFlag sets flag(s) using atomic, safe for concurrent access

func (*Image) SetGoImage

func (im *Image) SetGoImage(img image.Image, layer int, flipY bool) error

SetGoImage sets staging image data from a standard Go image at given layer. This is most efficiently done using an image.RGBA, but other formats will be converted as necessary. If flipY is true then the Image Y axis is flipped when copying into the image data, so that images will appear upright in the standard OpenGL Y-is-up coordinate system. If using the Y-is-down Vulkan coordinate system, don't flip. Only works if IsHostActive and Image Format is default vk.FormatR8g8b8a8Srgb, Must still call AllocImage to have image allocated on the device, and copy from this host staging data to the device.

func (*Image) SetNil

func (im *Image) SetNil()

SetNil sets everything to nil, for shared image

func (*Image) SetSize

func (im *Image) SetSize(size image.Point) bool

SetSize sets the size. If the size is not the same as current, and Image owns the Host and / or Image, then those are resized. returns true if resized.

func (*Image) SetVkImage

func (im *Image) SetVkImage(dev vk.Device, img vk.Image)

SetVkImage sets a Vk Image and configures a default 2D view based on existing format information (which must be set properly). Any exiting view is destroyed first. Must pass the relevant device.

func (*Image) Transition

func (im *Image) Transition(cmd vk.CommandBuffer, format vk.Format, oldLayout, newLayout vk.ImageLayout, srcStage, dstStage vk.PipelineStageFlagBits)

Transition transitions image to new layout

func (*Image) TransitionDstToGeneral

func (im *Image) TransitionDstToGeneral(cmd vk.CommandBuffer)

TransitionDstToGeneral transitions from Dst to General, in prep for copy from dev to host

func (*Image) TransitionDstToShader

func (im *Image) TransitionDstToShader(cmd vk.CommandBuffer)

TransitionDstToShader transitions from TransferDstOptimal to TransferShaderReadOnly

func (*Image) TransitionForDst

func (im *Image) TransitionForDst(cmd vk.CommandBuffer, srcStage vk.PipelineStageFlagBits)

TransitionForDst transitions to TransferDstOptimal to prepare device image to be copied to. source stage is as specified.

type ImageFlags

type ImageFlags int32

ImageFlags are bitflags for Image state

const (
	// ImageActive: the Image and ImageView are configured and ready to use
	ImageActive ImageFlags = iota

	// ImageHostActive: the Host representation of the image is present and
	// ready to be accessed
	ImageHostActive

	// ImageOwnsImage: we own the Vk.Image
	ImageOwnsImage

	// ImageOwnsHost: we own the Host buffer (and it is initialized)
	ImageOwnsHost

	// ImageIsVal: we are a Val image and our Host buffer is shared, with offset.
	// this is incompatible with ImageOwnsHost
	ImageIsVal

	// DepthImage indicates that this is a Depth buffer image
	DepthImage

	// FramebufferImage indicates that this is a Framebuffer image
	FramebufferImage

	// ImageOnHostOnly causes the image to be created only on host visible
	// memory, not on device memory -- no additional host buffer should be created.
	// this is for an ImageGrab image.  layout is LINEAR
	ImageOnHostOnly

	ImageFlagsN
)

func (*ImageFlags) FromString

func (i *ImageFlags) FromString(s string) error

func (ImageFlags) String

func (i ImageFlags) String() string

type ImageFormat

type ImageFormat struct {
	Size    image.Point            `desc:"Size of image"`
	Format  vk.Format              `desc:"Image format -- FormatR8g8b8a8Srgb is a standard default"`
	Samples vk.SampleCountFlagBits `desc:"number of samples -- set higher for Framebuffer rendering but otherwise default of SampleCount1Bit"`
	Layers  int                    `desc:"number of layers for texture arrays"`
}

ImageFormat describes the size and vulkan format of an Image If Layers > 1, all must be the same size.

func NewImageFormat

func NewImageFormat(width, height, layers int) *ImageFormat

NewImageFormat returns a new ImageFormat with default format and given size and number of layers

func (*ImageFormat) Aspect

func (im *ImageFormat) Aspect() float32

Aspect returns the aspect ratio X / Y

func (*ImageFormat) Bounds

func (im *ImageFormat) Bounds() image.Rectangle

Bounds returns the rectangle defining this image: 0,0,w,h

func (*ImageFormat) BytesPerPixel

func (im *ImageFormat) BytesPerPixel() int

BytesPerPixel returns number of bytes required to represent one Pixel (in Host memory at least). TODO only works for known formats -- need to add more as needed.

func (*ImageFormat) Defaults

func (im *ImageFormat) Defaults()

func (*ImageFormat) IsStdRGBA

func (im *ImageFormat) IsStdRGBA() bool

IsStdRGBA returns true if image format is the standard vk.FormatR8g8b8a8Srgb format which is compatible with go image.RGBA format.

func (*ImageFormat) LayerByteSize

func (im *ImageFormat) LayerByteSize() int

LayerByteSize returns number of bytes required to represent one layer of image in Host memory. TODO only works for known formats -- need to add more as needed.

func (*ImageFormat) Set

func (im *ImageFormat) Set(w, h int, ft vk.Format)

Set sets width, height and format

func (*ImageFormat) SetFormat

func (im *ImageFormat) SetFormat(ft Types)

SetFormat sets the format using vgpu standard Types

func (*ImageFormat) SetMultisample

func (im *ImageFormat) SetMultisample(nsamp int)

SetMultisample sets the number of multisampling to decrease aliasing 4 is typically sufficient. Values must be power of 2.

func (*ImageFormat) SetSize

func (im *ImageFormat) SetSize(w, h int)

SetSize sets the width, height

func (*ImageFormat) Size32

func (im *ImageFormat) Size32() (width, height uint32)

Size32 returns size as uint32 values

func (*ImageFormat) Stride

func (im *ImageFormat) Stride() int

Stride returns number of bytes per image row. TODO only works for known formats -- need to add more as needed.

func (*ImageFormat) String

func (im *ImageFormat) String() string

String returns human-readable version of format

func (*ImageFormat) TotalByteSize

func (im *ImageFormat) TotalByteSize() int

TotalByteSize returns total number of bytes required to represent all layers of images in Host memory. TODO only works for known formats -- need to add more as needed.

type MemBuff

type MemBuff struct {
	Type       BuffTypes       `desc:"type of memory in this buffer"`
	Size       int             `desc:"allocated buffer size"`
	Host       vk.Buffer       `view:"-" desc:"logical descriptor for host CPU-visible memory, for staging"`
	HostMem    vk.DeviceMemory `view:"-" desc:"host CPU-visible memory, for staging"`
	Dev        vk.Buffer       `view:"-" desc:"logical descriptor for device GPU-local memory, for computation"`
	DevMem     vk.DeviceMemory `view:"-" desc:"device GPU-local memory, for computation"`
	HostPtr    unsafe.Pointer  `view:"-" desc:"memory mapped pointer into host memory -- remains mapped"`
	AlignBytes int             `desc:"alignment of offsets into this buffer"`
	Active     bool            `inactive:"+" desc:"true if memory has been allocated, copied, transfered"`
}

MemBuff is a memory buffer holding a particular type of memory with staging Host-based memory and Device memory

func (*MemBuff) AllocDev

func (mb *MemBuff) AllocDev(dev vk.Device)

AllocDev allocates device local memory for this buffer.

func (*MemBuff) AllocHost

func (mb *MemBuff) AllocHost(dev vk.Device, bsz int) bool

AllocHost allocates memory for this buffer of given size in bytes, freeing any existing memory allocated first. Host and Dev buffers are made, and host memory is allocated and mapped for staging purposes. Call AllocDev to allocate device memory. Returns true if new memory was allocated.

func (*MemBuff) Free

func (mb *MemBuff) Free(dev vk.Device)

Free frees all memory for this buffer, including destroying buffers which have size associated with them.

type MemReg

type MemReg struct {
	Offset int
	Size   int
}

MemReg is a region of memory

type Memory

type Memory struct {
	GPU     *GPU
	Device  Device               `desc:"logical device that this memory is managed for -- set from System"`
	CmdPool CmdPool              `desc:"command pool for memory transfers"`
	Vars    Vars                 `desc:"Vars variables used in shaders, which manage associated Vals containing specific value instances of each var"`
	Buffs   [BuffTypesN]*MemBuff `desc:"memory buffers, organized by different Roles of vars"`
}

Memory manages memory for the GPU, using separate buffers for different roles, defined in the BuffTypes and managed by a MemBuff. Memory is organized by Vars with associated Vals.

func (*Memory) AllocBuffMem

func (mm *Memory) AllocBuffMem(buffer vk.Buffer, props vk.MemoryPropertyFlagBits) vk.DeviceMemory

AllocBuffMem allocates memory for given buffer, with given properties

func (*Memory) AllocDev

func (mm *Memory) AllocDev()

AllocDev allocates device memory for all bufers

func (*Memory) AllocDevBuff

func (mm *Memory) AllocDevBuff(bt BuffTypes)

AllocDevBuff allocates memory on the device for given buffer

func (*Memory) AllocHost

func (mm *Memory) AllocHost()

AllocHost allocates memory for all buffers

func (*Memory) AllocHostBuff

func (mm *Memory) AllocHostBuff(bt BuffTypes)

AllocHostBuff allocates host memory for given buffer

func (*Memory) Config

func (mm *Memory) Config(dev vk.Device)

Config should be called after all Vals have been configured and are ready to go with their initial data. Does: AllocHost(), AllocDev()

func (*Memory) Deactivate

func (mm *Memory) Deactivate()

Deactivate deactivates device memory for all buffs

func (*Memory) DeactivateBuff

func (mm *Memory) DeactivateBuff(bt BuffTypes)

DeactivateBuff deactivates device memory in given buffer

func (*Memory) Destroy

func (mm *Memory) Destroy(dev vk.Device)

Destroy destroys all vulkan allocations, using given dev

func (*Memory) Free

func (mm *Memory) Free() bool

Free frees memory for all buffers -- returns true if any freed

func (*Memory) FreeBuff

func (mm *Memory) FreeBuff(bt BuffTypes) bool

FreeBuff frees any allocated memory in buffer -- returns true if freed

func (*Memory) FreeBuffMem

func (mm *Memory) FreeBuffMem(memory *vk.DeviceMemory)

FreeBuffMem frees given device memory to nil

func (*Memory) Init

func (mm *Memory) Init(gp *GPU, device *Device)

Init configures the Memory for use with given gpu, device, and associated queueindex

func (*Memory) NewBuffer

func (mm *Memory) NewBuffer(size int, usage vk.BufferUsageFlagBits) vk.Buffer

NewBuffer makes a buffer of given size, usage

func (*Memory) SyncToGPU

func (mm *Memory) SyncToGPU()

SyncToGPU syncs all modified Val regions from CPU to GPU device memory, for all buffs

func (*Memory) SyncToGPUBuff

func (mm *Memory) SyncToGPUBuff(bt BuffTypes)

SyncToGPUBuff syncs all modified Val regions from CPU to GPU device memory, for given buff

func (*Memory) SyncValFmGPU

func (mm *Memory) SyncValFmGPU(vl *Val)

SyncValFmGPU syncs given value from GPU device memory to CPU host memory. Must be in Storage memory -- otherwise an error will be printed and returned.

func (*Memory) SyncValIdxFmGPU

func (mm *Memory) SyncValIdxFmGPU(set int, varNm string, valIdx int) error

SyncValIdxFmGPU syncs given value from GPU device memory to CPU host memory, specifying value by index for given named variable, in given set. Variable can only only be Storage memory -- otherwise an error is returned.

func (*Memory) SyncValNameFmGPU

func (mm *Memory) SyncValNameFmGPU(set int, varNm, valNm string) error

SyncValNameFmGPU syncs given value from GPU device memory to CPU host memory, specifying value by name for given named variable in given set. Variable can only only be Storage memory -- otherwise an error is returned.

func (*Memory) SyncValsTextures

func (mm *Memory) SyncValsTextures(buff *MemBuff)

SyncValsTextures syncs all changed vals images from host buffer to device memory

func (*Memory) TransferAllValsTextures

func (mm *Memory) TransferAllValsTextures(buff *MemBuff)

TransferAllValsTextures copies all vals images from host buffer to device memory

func (*Memory) TransferImagesFmGPU

func (mm *Memory) TransferImagesFmGPU(buff vk.Buffer, imgs ...*Image)

TransferImagesFmGPU transfers image memory from GPU to CPU for given images. the image Host.Offset *must* be accurate for the given buffer, whether its own individual buffer or the shared memory-managed buffer.

func (*Memory) TransferRegsFmGPU

func (mm *Memory) TransferRegsFmGPU(buff *MemBuff, regs []MemReg)

TransferRegsFmGPU transfers memory from GPU to CPU for given regions

func (*Memory) TransferRegsToGPU

func (mm *Memory) TransferRegsToGPU(buff *MemBuff, regs []MemReg)

TransferRegsToGPU transfers memory from CPU to GPU for given regions

func (*Memory) TransferTexturesToGPU

func (mm *Memory) TransferTexturesToGPU(buff vk.Buffer, imgs ...*Image)

TransferTexturesToGPU transfers texture image memory from CPU to GPU for given images. Transitions device image as destination, then to Shader read only source, for use in fragment shader texture sampling. The image Host.Offset *must* be accurate for the given buffer, whether its own individual buffer or the shared memory-managed buffer.

func (*Memory) TransferToGPU

func (mm *Memory) TransferToGPU()

TransferToGPU transfers entire staging to GPU for all buffs

func (*Memory) TransferToGPUBuff

func (mm *Memory) TransferToGPUBuff(bt BuffTypes)

TransferToGPUBuff transfers entire staging to GPU for given buffer

type Pipeline

type Pipeline struct {
	Name      string             `desc:"unique name of this pipeline"`
	Sys       *System            `desc:"system that we belong to and manages all shared resources (Memory, Vars, Vals, etc), etc"`
	Shaders   []*Shader          `desc:"shaders in order added -- should be execution order"`
	ShaderMap map[string]*Shader `desc:"shaders loaded for this pipeline"`

	VkConfig   vk.GraphicsPipelineCreateInfo `desc:"vulkan pipeline configuration options"`
	VkPipeline vk.Pipeline                   `desc:"the created vulkan pipeline"`
	VkCache    vk.PipelineCache              `desc:"cache"`
}

Pipeline manages Shader program(s) that accomplish a specific type of rendering or compute function, using Vars / Vals defined by the overall System. In the graphics context, each pipeline could handle a different class of materials (textures, Phong lighting, etc).

func (*Pipeline) AddShader

func (pl *Pipeline) AddShader(name string, typ ShaderTypes) *Shader

AddShader adds Shader with given name and type to the pipeline

func (*Pipeline) AddShaderCode

func (pl *Pipeline) AddShaderCode(name string, typ ShaderTypes, code []byte) *Shader

AddShaderCode adds Shader with given name and type to the pipeline, Loading SPV code from given bytes

func (*Pipeline) AddShaderFile

func (pl *Pipeline) AddShaderFile(name string, typ ShaderTypes, fname string) *Shader

AddShaderFile adds Shader with given name and type to the pipeline, Opening SPV code from given filename

func (*Pipeline) BindDrawVertex

func (pl *Pipeline) BindDrawVertex(cmd vk.CommandBuffer, descIdx int)

BindDrawVertex adds commands to the given command buffer to bind this pipeline, and then bind vertex / index values and Draw based on current vals for any Vertex (and associated Index) Vars. for given descIdx set of descriptors (see Vars NDescs for info). This is the standard unit of drawing between Begin and End.

func (*Pipeline) BindPipeline

func (pl *Pipeline) BindPipeline(cmd vk.CommandBuffer)

BindPipeline adds commands to the given command buffer to bind this pipeline to command buffer. System BeginRenderPass must have been called at some point before this.

func (*Pipeline) ComputeCommand

func (pl *Pipeline) ComputeCommand(cmd vk.CommandBuffer, nx, ny, nz int)

ComputeCommand adds commands to run the compute shader for given number of computational elements along 3 dimensions, which are passed as indexes into the shader.

func (*Pipeline) Config

func (pl *Pipeline) Config()

Config is called once all the VkConfig options have been set using Set* methods, and the shaders have been loaded. The parent System has already done what it can for its config

func (*Pipeline) ConfigCompute

func (pl *Pipeline) ConfigCompute()

ConfigCompute does the configuration for a Compute pipeline

func (*Pipeline) ConfigStages

func (pl *Pipeline) ConfigStages()

ConfigStages configures the shader stages

func (*Pipeline) Destroy

func (pl *Pipeline) Destroy()

func (*Pipeline) DestroyPipeline added in v1.0.0

func (pl *Pipeline) DestroyPipeline()

func (*Pipeline) Draw

func (pl *Pipeline) Draw(cmd vk.CommandBuffer, vtxCount, instanceCount, firstVtx, firstInstance int)

Draw adds CmdDraw command to the given command buffer BindPipeline must have been called before this. SeeDrawVertex for more typical case using Vertex (and Index) variables.

func (*Pipeline) DrawVertex

func (pl *Pipeline) DrawVertex(cmd vk.CommandBuffer, descIdx int)

DrawVertex adds commands to the given command buffer to bind vertex / index values and Draw based on current BindVertexVal setting for any Vertex (and associated Index) Vars, for given descIdx set of descriptors (see Vars NDescs for info).

func (*Pipeline) FreeShaders

func (pl *Pipeline) FreeShaders()

FreeShaders is called after successful pipeline creation, to unload shader modules as they are no longer needed

func (*Pipeline) Init

func (pl *Pipeline) Init(sy *System)

Init initializes pipeline as part of given System

func (*Pipeline) InitPipeline

func (pl *Pipeline) InitPipeline()

func (*Pipeline) Push

func (pl *Pipeline) Push(cmd vk.CommandBuffer, vr *Var, val unsafe.Pointer)

Push pushes given value as a push constant for given registered push constant variable. Note: it is *essential* to use a local, stack variable for the push value as cgo will likely complain if it is inside some other structure. BindPipeline must have been called before this.

func (*Pipeline) RunComputeWait

func (pl *Pipeline) RunComputeWait(cmd vk.CommandBuffer, nx, ny, nz int)

RunComputeWait runs the compute shader for given number of computational elements along 3 dimensions, which are passed as indexes into the shader. Submits the run command and waits for the queue to finish so the results will be available immediately after this.

func (*Pipeline) SetColorBlend

func (pl *Pipeline) SetColorBlend(alphaBlend bool)

SetColorBlend determines the color blending function: either 1-source alpha (alphaBlend) or no blending: new color overwrites old. Default is alphaBlend = true

func (*Pipeline) SetCullFace

func (pl *Pipeline) SetCullFace(back bool)

SetCullFace sets the face culling mode: true = back, false = front use CullBack, CullFront constants

func (*Pipeline) SetDynamicState

func (pl *Pipeline) SetDynamicState()

SetDynamicState sets dynamic state (Scissor, Viewport, what else?)

func (*Pipeline) SetFrontFace

func (pl *Pipeline) SetFrontFace(ccw bool)

SetFrontFace sets the winding order for what counts as a front face true = CCW, false = CW

func (*Pipeline) SetGraphicsDefaults

func (pl *Pipeline) SetGraphicsDefaults()

SetGraphicsDefaults configures all the default settings for a graphics rendering pipeline (not for a compute pipeline)

func (*Pipeline) SetLineWidth

func (pl *Pipeline) SetLineWidth(lineWidth float32)

SetLineWidth sets the rendering line width -- 1 is default.

func (*Pipeline) SetRasterization

func (pl *Pipeline) SetRasterization(polygonMode vk.PolygonMode, cullMode vk.CullModeFlagBits, frontFace vk.FrontFace, lineWidth float32)

SetRasterization sets various options for how to rasterize shapes: Defaults are: vk.PolygonModeFill, vk.CullModeBackBit, vk.FrontFaceCounterClockwise, 1.0 There are also separate methods for CullFace, FrontFace, and LineWidth

func (*Pipeline) SetTopology

func (pl *Pipeline) SetTopology(topo Topologies, restartEnable bool)

SetTopology sets the topology of vertex position data. TriangleList is the default. Also for Strip modes, restartEnable allows restarting a new strip by inserting a ??

func (*Pipeline) ShaderByName

func (pl *Pipeline) ShaderByName(name string) *Shader

ShaderByName returns Shader by name. Returns nil if not found (error auto logged).

func (*Pipeline) Vars

func (pl *Pipeline) Vars() *Vars

Vars returns a pointer to the vars for this pipeline, which has vals within it

type Render

type Render struct {
	Dev        vk.Device       `desc:"the device we're associated with -- this must be the same device that owns the Framebuffer -- e.g., the Surface"`
	Format     ImageFormat     `desc:"image format information for the framebuffer we render to"`
	Depth      Image           `desc:"the associated depth buffer, if set"`
	HasDepth   bool            `desc:"is true if configured with depth buffer"`
	Multi      Image           `desc:"for multisampling, this is the multisampled image that is the actual render target"`
	HasMulti   bool            `desc:"is true if multsampled image configured"`
	Grab       Image           `` /* 202-byte string literal not displayed */
	NotSurface bool            `desc:"set this to true if it is not using a Surface render target (i.e., it is a RenderFrame)"`
	ClearVals  []vk.ClearValue `desc:"values for clearing image when starting render pass"`

	VkClearPass vk.RenderPass `desc:"the vulkan renderpass config that clears target first"`
	VkLoadPass  vk.RenderPass `desc:"the vulkan renderpass config that does not clear target first (loads previous)"`
}

Render manages various elements needed for rendering, including a vulkan RenderPass object, which specifies parameters for rendering to a Framebuffer. It holds the Depth buffer if one is used, and a multisampling image too. The Render object lives on the System, and any associated Surface, RenderFrame, and Framebuffers point to it.

func (*Render) BeginRenderPass

func (rp *Render) BeginRenderPass(cmd vk.CommandBuffer, fr *Framebuffer)

BeginRenderPass adds commands to the given command buffer to start the render pass on given framebuffer. Clears the frame first, according to the ClearVals See BeginRenderPassNoClear for non-clearing version.

func (*Render) BeginRenderPassImpl

func (rp *Render) BeginRenderPassImpl(cmd vk.CommandBuffer, fr *Framebuffer, clear bool)

BeginRenderPassImpl adds commands to the given command buffer to start the render pass on given framebuffer. If clear = true, clears the frame according to the ClearVals.

func (*Render) BeginRenderPassNoClear

func (rp *Render) BeginRenderPassNoClear(cmd vk.CommandBuffer, fr *Framebuffer)

BeginRenderPassNoClear adds commands to the given command buffer to start the render pass on given framebuffer. does NOT clear the frame first -- loads prior state.

func (*Render) Config

func (rp *Render) Config(dev vk.Device, imgFmt *ImageFormat, depthFmt Types, notSurface bool)

Config configures the render pass for given device, Using standard parameters for graphics rendering, based on the given image format and depth image format (pass UndefType for no depth buffer).

func (*Render) ConfigGrab

func (rp *Render) ConfigGrab(dev vk.Device)

ConfigGrab configures the Grab for copying rendered image back to host memory. Uses format of current Image.

func (*Render) ConfigImpl

func (rp *Render) ConfigImpl(dev vk.Device, imgFmt *ImageFormat, depthFmt Types, clear bool) vk.RenderPass

func (*Render) Destroy

func (rp *Render) Destroy()

func (*Render) SetClearColor

func (rp *Render) SetClearColor(r, g, b, a float32)

SetClearColor sets the RGBA colors to set when starting new render

func (*Render) SetClearDepthStencil

func (rp *Render) SetClearDepthStencil(depth float32, stencil uint32)

SetClearDepthStencil sets the depth and stencil values when starting new render

func (*Render) SetSize

func (rp *Render) SetSize(size image.Point)

SetSize sets updated size of the render target -- resizes depth and multi buffers as needed

type RenderFrame

type RenderFrame struct {
	GPU           *GPU           `desc:"pointer to gpu device, for convenience"`
	Device        Device         `desc:"device for this surface -- each window surface has its own device, configured for that surface"`
	Render        *Render        `desc:"the Render for this RenderFrame, typically from a System"`
	Format        ImageFormat    `desc:"has the current image format and dimensions"`
	NFrames       int            `` /* 182-byte string literal not displayed */
	Frames        []*Framebuffer `` /* 126-byte string literal not displayed */
	ImageAcquired vk.Semaphore   `view:"-" desc:"semaphore used internally for waiting on acquisition of next frame"`
	RenderDone    vk.Semaphore   `` /* 130-byte string literal not displayed */
	RenderFence   vk.Fence       `view:"-" desc:"fence for rendering command running"`
	OwnDevice     bool           `desc:"do we own the device?"`
}

RenderFrame is an offscreen, non-window-backed rendering target, functioning like a Surface

func NewRenderFrame

func NewRenderFrame(gp *GPU, dev *Device, size image.Point) *RenderFrame

NewRenderFrame returns a new renderframe initialized for given GPU, of given size. using given device, e.g., from a Surface -- to transition images from renderframe to surface, they must use the same device. if device is nil, own device is created.

func NewRenderFrameOwnDevice

func NewRenderFrameOwnDevice(gp *GPU, size image.Point) *RenderFrame

NewRenderFrameOwnDevice returns a new renderframe initialized for given GPU, of given size. This version creates a new Graphics device -- for purely offscreen usage.

func (*RenderFrame) Config

func (rf *RenderFrame) Config()

Config configures the framebuffers etc

func (*RenderFrame) Defaults

func (rf *RenderFrame) Defaults()

func (*RenderFrame) Destroy

func (rf *RenderFrame) Destroy()

func (*RenderFrame) Free

func (rf *RenderFrame) Free()

Free frees any existing (for ReInit or Destroy)

func (*RenderFrame) GrabImage

func (rf *RenderFrame) GrabImage(cmd vk.CommandBuffer, idx int)

GrabImage grabs rendered image of given index to Framebuffer.ImageGrab. must have waited for render already.

func (*RenderFrame) Init

func (rf *RenderFrame) Init(gp *GPU, makeDevice bool) error

Init initializes the device and all other resources for the renderframe.

func (*RenderFrame) ReConfig

func (rf *RenderFrame) ReConfig()

ReConfig reconfigures rendering

func (*RenderFrame) ReConfigFrames

func (rf *RenderFrame) ReConfigFrames()

ReConfigFrames re-configures the Famebuffers using exiting settings. Assumes Config has been called.

func (*RenderFrame) SetRender

func (rf *RenderFrame) SetRender(rp *Render)

SetRender sets the Render and updates frames accordingly

func (*RenderFrame) SetSize

func (rf *RenderFrame) SetSize(size image.Point) bool

SetSize sets the size for the render frame, doesn't do anything if already that size (returns fale)

func (*RenderFrame) SubmitRender

func (rf *RenderFrame) SubmitRender(cmd vk.CommandBuffer)

SubmitRender submits a rendering command that must have been added to the given command buffer, calling CmdEnd on the buffer first. This buffer triggers the associated Fence logic to control the sequencing of render commands over time. The ImageAcquired semaphore before the command is run.

func (*RenderFrame) WaitForRender

func (rf *RenderFrame) WaitForRender()

WaitForRender waits until the last submitted render completes

type Sampler

type Sampler struct {
	Name      string
	UMode     SamplerModes `desc:"for U (horizontal) axis -- what to do when going off the edge"`
	VMode     SamplerModes `desc:"for V (vertical) axis -- what to do when going off the edge"`
	WMode     SamplerModes `desc:"for W (horizontal) axis -- what to do when going off the edge"`
	Border    BorderColors `desc:"border color for Clamp modes"`
	VkSampler vk.Sampler   `desc:"the vulkan sampler"`
}

Sampler represents a vulkan image sampler

func (*Sampler) Config

func (sm *Sampler) Config(dev vk.Device)

Config configures sampler on device

func (*Sampler) Defaults

func (sm *Sampler) Defaults()

func (*Sampler) Destroy

func (sm *Sampler) Destroy(dev vk.Device)

type SamplerModes

type SamplerModes int32

Texture image sampler modes

const (
	// Repeat the texture when going beyond the image dimensions.
	Repeat SamplerModes = iota

	// Like repeat, but inverts the coordinates to mirror the image when going beyond the dimensions.
	MirroredRepeat

	// Take the color of the edge closest to the coordinate beyond the image dimensions.
	ClampToEdge

	// Return a solid color when sampling beyond the dimensions of the image.
	ClampToBorder

	// Like clamp to edge, but instead uses the edge opposite to the closest edge.
	MirrorClampToEdge

	SamplerModesN
)

func (*SamplerModes) FromString

func (i *SamplerModes) FromString(s string) error

func (SamplerModes) String

func (i SamplerModes) String() string

func (SamplerModes) VkMode

func (sm SamplerModes) VkMode() vk.SamplerAddressMode

type Shader

type Shader struct {
	Name     string
	Type     ShaderTypes
	VkModule vk.ShaderModule
}

Shader manages a single Shader program

func (*Shader) Free

func (sh *Shader) Free(dev vk.Device)

Free deletes the shader module, which can be done after the pipeline is created.

func (*Shader) Init

func (sh *Shader) Init(name string, typ ShaderTypes)

Init initializes the shader

func (*Shader) OpenCode

func (sh *Shader) OpenCode(dev vk.Device, code []byte) error

OpenCode loads given SPIR-V ".spv" code for the Shader.

func (*Shader) OpenFile

func (sh *Shader) OpenFile(dev vk.Device, fname string) error

OpenFile loads given SPIR-V ".spv" code from file for the Shader.

type ShaderTypes

type ShaderTypes int32

ShaderTypes is a list of GPU shader types

const (
	VertexShader ShaderTypes = iota
	TessCtrlShader
	TessEvalShader
	GeometryShader
	FragmentShader
	ComputeShader
	AllShaders
)

type StackFrame

type StackFrame struct {
	File           string
	LineNumber     int
	Name           string
	Package        string
	ProgramCounter uintptr
}

A StackFrame contains all necessary information about to generate a line in a callstack.

func (*StackFrame) Func

func (frame *StackFrame) Func() *runtime.Func

Func returns the function that this stackframe corresponds to

func (*StackFrame) SourceLine

func (frame *StackFrame) SourceLine() (string, error)

SourceLine gets the line of code (from File and Line) of the original source if possible

func (*StackFrame) String

func (frame *StackFrame) String() string

String returns the stackframe formatted in the same way as go does in runtime/debug.Stack()

type Surface

type Surface struct {
	GPU            *GPU           `desc:"pointer to gpu device, for convenience"`
	Device         Device         `desc:"device for this surface -- each window surface has its own device, configured for that surface"`
	Render         *Render        `desc:"the Render for this Surface, typically from a System"`
	Format         ImageFormat    `desc:"has the current swapchain image format and dimensions"`
	DesiredFormats []vk.Format    `desc:"ordered list of surface formats to select"`
	NFrames        int            `` /* 182-byte string literal not displayed */
	Frames         []*Framebuffer `` /* 130-byte string literal not displayed */
	Surface        vk.Surface     `view:"-" desc:"vulkan handle for surface"`
	Swapchain      vk.Swapchain   `view:"-" desc:"vulkan handle for swapchain"`
	ImageAcquired  vk.Semaphore   `view:"-" desc:"semaphore used internally for waiting on acquisition of next frame"`
	RenderDone     vk.Semaphore   `` /* 130-byte string literal not displayed */
	RenderFence    vk.Fence       `view:"-" desc:"fence for rendering command running"`
}

Surface manages the physical device for the visible image of a window surface, and the swapchain for presenting images.

func NewSurface

func NewSurface(gp *GPU, vsurf vk.Surface) *Surface

NewSurface returns a new surface initialized for given GPU and vulkan Surface handle, obtained from a valid window.

func (*Surface) AcquireNextImage

func (sf *Surface) AcquireNextImage() uint32

AcquireNextImage gets the next frame index to render to. It automatically handles any issues with out-of-date swapchain. It triggers the ImageAcquired semaphore when image actually acquired. Must call SubmitRender with command to launch command contingent on that semaphore.

func (*Surface) ConfigSwapchain

func (sf *Surface) ConfigSwapchain()

ConfigSwapchain configures the swapchain for surface. This assumes that all existing items have been destroyed.

func (*Surface) Defaults

func (sf *Surface) Defaults()

func (*Surface) Destroy

func (sf *Surface) Destroy()

func (*Surface) FreeSwapchain

func (sf *Surface) FreeSwapchain()

FreeSwapchain frees any existing swawpchain (for ReInit or Destroy)

func (*Surface) Init

func (sf *Surface) Init(gp *GPU, vs vk.Surface) error

Init initializes the device and all other resources for the surface based on the vulkan surface handle which must be obtained from the OS-specific window, created first (e.g., via glfw)

func (*Surface) PresentImage

func (sf *Surface) PresentImage(frameIdx uint32) error

PresentImage waits on the RenderDone semaphore to present the rendered image to the surface, for the given frame index, as returned by AcquireNextImage.

func (*Surface) ReConfigFrames

func (sf *Surface) ReConfigFrames()

ReConfigFrames re-configures the Famebuffers using exiting settings. Assumes ConfigSwapchain has been called.

func (*Surface) ReConfigSwapchain

func (sf *Surface) ReConfigSwapchain()

ReConfigSwapchain does a re-initialize of swapchain, freeing existing. This must be called when the window is resized.

func (*Surface) SetRender

func (sf *Surface) SetRender(rp *Render)

SetRender sets the Render and updates frames accordingly

func (*Surface) SubmitRender

func (sf *Surface) SubmitRender(cmd vk.CommandBuffer)

SubmitRender submits a rendering command that must have been added to the given command buffer, calling CmdEnd on the buffer first. This buffer triggers the associated Fence logic to control the sequencing of render commands over time. The ImageAcquired semaphore efore the command is run.

type System

type System struct {
	Name        string               `desc:"optional name of this System"`
	GPU         *GPU                 `desc:"gpu device"`
	Device      Device               `desc:"logical device for this System, which is a non-owned copy of either Surface or RenderFrame device"`
	CmdPool     CmdPool              `desc:"cmd pool specific to this system"`
	Compute     bool                 `desc:"if true, this is a compute system -- otherwise is graphics"`
	Pipelines   []*Pipeline          `desc:"all pipelines"`
	PipelineMap map[string]*Pipeline `desc:"map of all pipelines -- names must be unique"`
	Mem         Memory               `desc:"manages all the memory for all the Vals"`
	Render      Render               `desc:"renderpass with depth buffer for this system"`
}

System manages a system of Pipelines that all share a common collection of Vars, Vals, and a Memory manager. For example, this could be a collection of different pipelines for different material types, or different compute operations performed on a common set of data. It maintains its own logical device and associated queue.

func (*System) AddPipeline

func (sy *System) AddPipeline(pl *Pipeline)

AddPipeline adds given pipeline

func (*System) BeginRenderPass

func (sy *System) BeginRenderPass(cmd vk.CommandBuffer, fr *Framebuffer, descIdx int)

BeginRenderPass adds commands to the given command buffer to start the render pass on given framebuffer. Clears the frame first, according to the ClearVals. Also Binds descriptor sets to command buffer for given collection of descriptors descIdx (see Vars NDescs for info).

func (*System) BeginRenderPassNoClear

func (sy *System) BeginRenderPassNoClear(cmd vk.CommandBuffer, fr *Framebuffer, descIdx int)

BeginRenderPassNoClear adds commands to the given command buffer to start the render pass on given framebuffer. does NOT clear the frame first -- loads prior state. Also Binds descriptor sets to command buffer for given collection of descriptors descIdx (see Vars NDescs for info).

func (*System) CmdBindTextureVarIdx

func (sy *System) CmdBindTextureVarIdx(cmd vk.CommandBuffer, setIdx int, varNm string, valIdx int) (txIdx, descIdx int, switched bool, err error)

CmdBindTextureVarIdx returns the txIdx needed to select the given Texture value at valIdx in given variable in given set index, for use in a shader (i.e., pass txIdx as a push constant to the shader to select this texture). If there are more than MaxTexturesPerSet textures, then it may need to select a different descIdx where that val has been allocated -- the descIdx is returned, and switched is true if it had to issue a CmdBindVars to given command buffer to bind to that desc set, updating BindDescIdx. Typically other vars are bound to the same vals across sets, so this should not affect them, but that is not necessarily the case, so other steps might need to be taken. If the texture is not valid, a -1 is returned for txIdx, and an error is logged.

func (*System) CmdBindVars

func (sy *System) CmdBindVars(cmd vk.CommandBuffer, descIdx int)

CmdBindVars adds command to the given command buffer to bind the Vars descriptors, for given collection of descriptors descIdx (see Vars NDescs for info).

func (*System) CmdResetBindVars

func (sy *System) CmdResetBindVars(cmd vk.CommandBuffer, descIdx int)

CmdResetBindVars adds command to the given command buffer to bind the Vars descriptors, for given collection of descriptors descIdx (see Vars NDescs for info).

func (*System) Config

func (sy *System) Config()

Config configures the entire system, after everything has been setup (Pipelines, Vars, etc). Memory / Vals do not yet need to be configured and are not Config'd by this call.

func (*System) ConfigRender

func (sy *System) ConfigRender(imgFmt *ImageFormat, depthFmt Types)

ConfigRender configures the renderpass, including the image format that we're rendering to, for a surface render target, and the depth buffer format (pass UndefType for no depth buffer).

func (*System) ConfigRenderNonSurface

func (sy *System) ConfigRenderNonSurface(imgFmt *ImageFormat, depthFmt Types)

ConfigRenderNonSurface configures the renderpass, including the image format that we're rendering to, for a RenderFrame non-surface target, and the depth buffer format (pass UndefType for no depth buffer).

func (*System) Destroy

func (sy *System) Destroy()

func (*System) EndRenderPass

func (sy *System) EndRenderPass(cmd vk.CommandBuffer)

EndRenderPass adds commands to the given command buffer to end the render pass. It does not call EndCommandBuffer, in case any further commands are to be added.

func (*System) InitCmd

func (sy *System) InitCmd()

InitCmd initializes the command pool and buffer

func (*System) InitCompute

func (sy *System) InitCompute(gp *GPU, name string) error

InitCompute initializes the System for compute functionality, which creates its own Compute device.

func (*System) InitGraphics

func (sy *System) InitGraphics(gp *GPU, name string, dev *Device) error

InitGraphics initializes the System for graphics use, using the graphics device from the Surface associated with this system or another device can be initialized by calling sy.Device.Init(gp, vk.QueueGraphicsBit)

func (*System) MemCmdStart

func (sy *System) MemCmdStart() vk.CommandBuffer

MemCmdStart starts a one-time memory command using the Memory CmdPool and Device associated with this System Use this for other random memory transfer commands.

func (*System) MemCmdSubmitWaitFree

func (sy *System) MemCmdSubmitWaitFree()

MemCmdSubmitWaitFree submits current one-time memory command using the Memory CmdPool and Device associated with this System Use this for other random memory transfer commands.

func (*System) NewPipeline

func (sy *System) NewPipeline(name string) *Pipeline

NewPipeline returns a new pipeline added to this System, initialized for use in this system.

func (*System) ResetBeginRenderPass

func (sy *System) ResetBeginRenderPass(cmd vk.CommandBuffer, fr *Framebuffer, descIdx int)

ResetBeginRenderPass adds commands to the given command buffer to reset command buffer and call begin on it, then starts the render pass on given framebuffer (BeginRenderPass) Clears the frame first, according to the ClearVals. Also Binds descriptor sets to command buffer for given collection of descriptors descIdx (see Vars NDescs for info).

func (*System) ResetBeginRenderPassNoClear

func (sy *System) ResetBeginRenderPassNoClear(cmd vk.CommandBuffer, fr *Framebuffer, descIdx int)

ResetBeginRenderPassNoClear adds commands to the given command buffer to reset command buffer and call begin on it, then starts the render pass on given framebuffer (BeginRenderPass) does NOT clear the frame first -- loads prior state. Also Binds descriptor sets to command buffer for given collection of descriptors descIdx (see Vars NDescs for info).

func (*System) SetClearColor

func (sy *System) SetClearColor(r, g, b, a float32)

SetClearColor sets the RGBA colors to set when starting new render For all pipelines, to keep graphics settings consistent.

func (*System) SetClearDepthStencil

func (sy *System) SetClearDepthStencil(depth float32, stencil uint32)

SetClearDepthStencil sets the depth and stencil values when starting new render For all pipelines, to keep graphics settings consistent.

func (*System) SetColorBlend

func (sy *System) SetColorBlend(alphaBlend bool)

SetColorBlend determines the color blending function: either 1-source alpha (alphaBlend) or no blending: new color overwrites old. Default is alphaBlend = true For all pipelines, to keep graphics settings consistent.

func (*System) SetCullFace

func (sy *System) SetCullFace(back bool)

SetCullFace sets the face culling mode: true = back, false = front use CullBack, CullFront constants

func (*System) SetFrontFace

func (sy *System) SetFrontFace(ccw bool)

SetFrontFace sets the winding order for what counts as a front face true = CCW, false = CW

func (*System) SetGraphicsDefaults

func (sy *System) SetGraphicsDefaults()

SetGraphicsDefaults configures all the default settings for all graphics rendering pipelines (not for a compute pipeline)

func (*System) SetLineWidth

func (sy *System) SetLineWidth(lineWidth float32)

SetLineWidth sets the rendering line width -- 1 is default.

func (*System) SetRasterization

func (sy *System) SetRasterization(polygonMode vk.PolygonMode, cullMode vk.CullModeFlagBits, frontFace vk.FrontFace, lineWidth float32)

SetRasterization sets various options for how to rasterize shapes: Defaults are: vk.PolygonModeFill, vk.CullModeBackBit, vk.FrontFaceCounterClockwise, 1.0 For all pipelines, to keep graphics settings consistent.

func (*System) SetTopology

func (sy *System) SetTopology(topo Topologies, restartEnable bool)

SetTopology sets the topology of vertex position data. TriangleList is the default. Also for Strip modes, restartEnable allows restarting a new strip by inserting a ?? For all pipelines, to keep graphics settings consistent.

func (*System) Vars

func (sy *System) Vars() *Vars

Vars returns a pointer to the vars for this pipeline, which has vals within it

type Texture

type Texture struct {
	Image
	Sampler `desc:"sampler for image"`
}

Texture supplies an Image and a Sampler

func (*Texture) AllocTexture

func (tx *Texture) AllocTexture()

AllocTexture allocates texture device image, stdview, and sampler

func (*Texture) Defaults

func (tx *Texture) Defaults()

func (*Texture) Destroy

func (tx *Texture) Destroy()

type Topologies

type Topologies int32

Topologies are the different vertex topology

func (*Topologies) FromString

func (i *Topologies) FromString(s string) error

func (Topologies) String

func (i Topologies) String() string

type Types

type Types int32

Types is a list of supported GPU data types, which can be stored properly aligned in device memory, and used by the shader code. Note that a Vec3 or arrays of single scalar values such as Float32 are not well supported outside of Vertex due to the std410 convention: http://www.opengl.org/registry/doc/glspec45.core.pdf#page=159 The Struct type is particularly challenging as each member must be aligned in general on a 16 byte boundary (i.e., vec4) (unless all elements are exactly 4 bytes, which might work?). Go automatically aligns members to 8 bytes on 64 bit machines, but that doesn't quite cut it.

const (
	UndefType Types = iota
	Bool32

	Int16
	Uint16

	Int32
	Int32Vec2
	Int32Vec4

	Uint32
	Uint32Vec2
	Uint32Vec4

	Float32
	Float32Vec2
	Float32Vec3 // note: only use for vertex data -- not properly aligned for uniforms
	Float32Vec4

	Float64
	Float64Vec2
	Float64Vec3
	Float64Vec4

	Float32Mat4 // std xform matrix: mat32.Mat4 works directly
	Float32Mat3 // std xform matrix: mat32.Mat3 works directly

	ImageRGBA32 // 32 bits with 8 bits per component of R,G,B,A -- std image format

	Depth32      // standard float32 depth buffer
	Depth24Sten8 // standard 24 bit float with 8 bit stencil

	Struct
	TypesN
)

func (Types) Bytes

func (tp Types) Bytes() int

Bytes returns number of bytes for this type

func (*Types) FromString

func (i *Types) FromString(s string) error

func (Types) String

func (i Types) String() string

func (Types) VkFormat

func (tp Types) VkFormat() vk.Format

VkFormat returns the Vulkan VkFormat for given type

func (Types) VkIndexType

func (tp Types) VkIndexType() vk.IndexType

VkIndexType returns the Vulkan vk.IndexType for var must be either Uint16 or Uint32

type Val

type Val struct {
	Name      string         `desc:"name of this value, named by default as the variable name_idx"`
	Idx       int            `desc:"index of this value within the Var list of values"`
	N         int            `` /* 146-byte string literal not displayed */
	Offset    int            `desc:"offset in bytes from start of memory buffer"`
	Flags     int32          `desc:"val state flags"`
	ElSize    int            `` /* 234-byte string literal not displayed */
	AllocSize int            `` /* 145-byte string literal not displayed */
	Texture   *Texture       `desc:"for Texture Var roles, this is the Texture"`
	MemPtr    unsafe.Pointer `view:"-" desc:"pointer to the start of the staging memory for this value"`
}

Val represents a specific value of a Var variable.

func (*Val) AllocHost

func (vl *Val) AllocHost(vr *Var, buff *MemBuff, buffPtr unsafe.Pointer, offset int) int

AllocHost allocates this value at given offset in owning Memory buffer. Computes the MemPtr for this item, and returns AllocSize() of this value, so memory can increment to next item. offsets are guaranteed to be properly aligned per minUniformBufferOffsetAlignment.

func (*Val) Bytes

func (vl *Val) Bytes() []byte

Bytes returns byte array of the Val data, including any additional alignment -- can be written to directly. Be mindful of potential padding and alignment issues relative to go-based storage. Set Mod flag when changes have been made.

func (*Val) ClearFlag

func (vl *Val) ClearFlag(flag ...int)

ClearFlag clears flag(s) using atomic, safe for concurrent access

func (*Val) ClearMod

func (vl *Val) ClearMod()

ClearMod clears modified flag

func (*Val) CopyBytes

func (vl *Val) CopyBytes(srcPtr unsafe.Pointer)

CopyBytes copies bytes from given source pointer into memory, and sets Mod flag.

func (*Val) Floats32

func (vl *Val) Floats32() mat32.ArrayF32

Floats32 returns mat32.ArrayF32 of the Val data -- can be written to directly. Only recommended for Vertex data. Otherwise, be mindful of potential padding and alignment issues relative to go-based storage. Set Mod flag when changes have been made.

func (*Val) Free

func (vl *Val) Free()

Free resets the MemPtr for this value

func (*Val) HasFlag

func (vl *Val) HasFlag(flag ValFlags) bool

HasFlag checks if flag is set using atomic, safe for concurrent access

func (*Val) Init

func (vl *Val) Init(vr *Var, idx int)

Init initializes value based on variable and index within list of vals for this var

func (*Val) IsMod

func (vl *Val) IsMod() bool

IsMod returns true if the value has been modified since last memory sync

func (*Val) MemReg

func (vl *Val) MemReg() MemReg

MemReg returns the memory region for this value

func (*Val) MemSize

func (vl *Val) MemSize(vr *Var) int

MemSize returns the memory allocation size for this value, in bytes

func (*Val) PaddedArrayCheck

func (vl *Val) PaddedArrayCheck() error

PaddedArrayCheck checks if this is an array with padding on the elements due to alignment issues. If this is the case, then direct copying is not possible.

func (*Val) SetFlag

func (vl *Val) SetFlag(flag ...int)

SetFlag sets flag(s) using atomic, safe for concurrent access

func (*Val) SetGoImage

func (vl *Val) SetGoImage(img image.Image, layer int, flipY bool) error

SetGoImage sets Texture image data from an *image.RGBA standard Go image, at given layer, and sets the Mod flag, so it will be sync'd by Memory or if TextureOwns is set for the var, it allocates Host memory. This is most efficiently done using an image.RGBA, but other formats will be converted as necessary. If flipY is true then the Image Y axis is flipped when copying into the image data (requires row-by-row copy) -- can avoid this by configuring texture coordinates to compensate.

func (*Val) SetMod

func (vl *Val) SetMod()

SetMod sets modified flag

func (*Val) UInts32

func (vl *Val) UInts32() mat32.ArrayU32

UInts32 returns mat32.ArrayU32 of the Val data -- can be written to directly. Only recommended for Vertex data. Otherwise, be mindful of potential padding and alignment issues relative to go-based storage. Set Mod flag when changes have been made.

type ValFlags

type ValFlags int32

ValFlags are bitflags for Val state

const (
	// ValMod the value has been modified
	ValMod ValFlags = iota

	// ValPaddedArray array had to be padded -- cannot access elements continuously
	ValPaddedArray

	// ValTextureOwns val owns and manages the host staging memory for texture.
	// based on Var TextureOwns -- for dynamically changings images.
	ValTextureOwns

	ValFlagsN
)

func (*ValFlags) FromString

func (i *ValFlags) FromString(s string) error

func (ValFlags) String

func (i ValFlags) String() string

type Vals

type Vals struct {
	Vals       []*Val          `desc:"values in indexed order"`
	NameMap    map[string]*Val `desc:"map of vals by name -- only for specifically named vals vs. generically allocated ones -- names must be unique"`
	TexSzAlloc szalloc.SzAlloc `` /* 318-byte string literal not displayed */
	GpTexVals  []*Val          `` /* 157-byte string literal not displayed */
}

Vals is a list container of Val values, accessed by index or name

func (*Vals) ActiveVals added in v1.0.0

func (vs *Vals) ActiveVals() []*Val

ActiveVals returns the Vals to actually use for memory allocation etc this is Vals list except for textures with TexSzAlloc.On active

func (*Vals) AllocHost

func (vs *Vals) AllocHost(vr *Var, buff *MemBuff, offset int) int

AllocHost allocates values at given offset in given Memory buffer. Computes the MemPtr for each item, and returns TotSize across all vals. The effective offset increment (based on size) is aligned at the given align byte level, which should be MinUniformBufferOffsetAlignment from gpu.

func (*Vals) AllocTexBySize added in v1.0.0

func (vs *Vals) AllocTexBySize(vr *Var)

AllocTexBySize allocates textures by size so they fit within the MaxTexturesPerGroup. Must call ConfigGoImage on the original values to set the sizes prior to calling this, and cannot have the TextureOwns flag set. Also does not support arrays in source vals. Apps can always use szalloc.SzAlloc upstream of this to allocate. This method creates actual image vals in GpTexVals, which are allocated. Must call SetGoImage on Vals here, which redirects to the proper allocated GpTexVals image and layer.

func (*Vals) AllocTextures

func (vs *Vals) AllocTextures(mm *Memory)

AllocTextures allocates images on device memory only called on Role = TextureRole

func (*Vals) ConfigVals

func (vs *Vals) ConfigVals(dev vk.Device, vr *Var, nvals int) bool

ConfigVals configures given number of values in the list for given variable. If the same number of vals is given, nothing is done, so it is safe to call repeatedly. Otherwise, any existing vals will be deleted -- the Memory system must free all associated memory prior! Returns true if new config made, else false if same size.

func (*Vals) Destroy

func (vs *Vals) Destroy()

Destroy frees all existing values and resets the list of Vals so subsequent Config will start fresh (e.g., if Var type changes).

func (*Vals) Free

func (vs *Vals) Free()

Free resets the MemPtr for values, resets any self-owned resources (Textures)

func (*Vals) MemSize

func (vs *Vals) MemSize(vr *Var, alignBytes int) int

MemSize returns size across all Vals in list

func (*Vals) ModRegs

func (vs *Vals) ModRegs() []MemReg

ModRegs returns the regions of Vals that have been modified

func (*Vals) SetGoImage added in v1.0.0

func (vs *Vals) SetGoImage(idx int, img image.Image, flipy bool)

SetGoImage calls SetGoImage on the proper Texture value for given index. if TexSzAlloc.On via AllocTexBySize then this is routed to the actual allocated image array, otherwise it goes directly to the standard Val.

SetGoImage sets staging image data from a standard Go image at given layer. This is most efficiently done using an image.RGBA, but other formats will be converted as necessary. If flipY is true then the Image Y axis is flipped when copying into the image data, so that images will appear upright in the standard OpenGL Y-is-up coordinate system. If using the Y-is-down Vulkan coordinate system, don't flip. Only works if IsHostActive and Image Format is default vk.FormatR8g8b8a8Srgb, Must still call AllocImage to have image allocated on the device, and copy from this host staging data to the device.

func (*Vals) SetName

func (vs *Vals) SetName(idx int, name string) (*Val, error)

SetName sets name of given Val, by index, adds name to map, checking that it is not already there yet. Returns val.

func (*Vals) ValByIdxTry

func (vs *Vals) ValByIdxTry(idx int) (*Val, error)

ValByIdxTry returns Val at given index with range checking error message.

func (*Vals) ValByNameTry

func (vs *Vals) ValByNameTry(name string) (*Val, error)

ValByNameTry returns value by name, returning error if not found

type Var

type Var struct {
	Name        string                 `desc:"variable name"`
	Type        Types                  `` /* 433-byte string literal not displayed */
	ArrayN      int                    `` /* 217-byte string literal not displayed */
	Role        VarRoles               `` /* 368-byte string literal not displayed */
	Shaders     vk.ShaderStageFlagBits `desc:"bit flags for set of shaders that this variable is used in"`
	Set         int                    `` /* 139-byte string literal not displayed */
	BindLoc     int                    `` /* 188-byte string literal not displayed */
	SizeOf      int                    `` /* 245-byte string literal not displayed */
	TextureOwns bool                   `` /* 180-byte string literal not displayed */
	DynOffIdx   int                    `` /* 149-byte string literal not displayed */
	Vals        Vals                   `` /* 298-byte string literal not displayed */
	BindValIdx  []int                  `` /* 354-byte string literal not displayed */
	Offset      int                    `desc:"offset -- only for push constants"`
}

Var specifies a variable used in a pipeline, accessed in shader programs. A Var represents a type of input or output into the GPU program, including things like Vertex arrays, transformation matricies (Uniforms), Images (Textures), and arbitrary Structs for Compute shaders. Each Var belongs to a Set, and its binding location is allocated within that. Each set is updated at the same time scale, and all vars in the set have the same number of allocated Val instances representing a specific value of the variable. There must be a unique Val instance for each value of the variable used in a single render -- a previously-used Val's contents cannot be updated within the render pass, but new information can be written to an as-yet unused Val prior to using in a render (although this comes at a performance cost).

func (*Var) AllocHost

func (vr *Var) AllocHost(buff *MemBuff, offset int) int

AllocHost allocates values at given offset in given Memory buffer. Computes the MemPtr for each item, and returns TotSize across all vals. The effective offset increment (based on size) is aligned at the given align byte level, which should be MinUniformBufferOffsetAlignment from gpu.

func (*Var) AllocTextures

func (vr *Var) AllocTextures(mm *Memory)

AllocTextures allocates images on device memory only called on Role = TextureRole

func (*Var) BindVal

func (vr *Var) BindVal(descIdx int) (*Val, error)

BindVal returns the currently bound value at given descriptor collection index as set by BindDyn* methods. Returns nil, error if not valid.

func (*Var) BuffType

func (vr *Var) BuffType() BuffTypes

BuffType returns the memory buffer type for this variable, based on Var.Role

func (*Var) Free

func (vr *Var) Free()

Free resets the MemPtr for values, resets any self-owned resources (Textures)

func (*Var) Init

func (vr *Var) Init(name string, typ Types, arrayN int, role VarRoles, set int, shaders ...ShaderTypes)

Init initializes the main values

func (*Var) MemSize

func (vr *Var) MemSize() int

MemSize returns the memory allocation size for this value, in bytes

func (*Var) ModRegs

func (vr *Var) ModRegs() []MemReg

ModRegs returns the regions of Vals that have been modified

func (*Var) SetTextureDev

func (vr *Var) SetTextureDev(dev vk.Device)

SetTextureDev sets Device for textures only called on Role = TextureRole

func (*Var) String

func (vr *Var) String() string

func (*Var) TextureValidIdx

func (vr *Var) TextureValidIdx(stIdx, idx int) int

TextureValidIdx returns the index of the given texture value at our index in list of vals, starting at given index, skipping over any inactive textures which do not show up when accessed in the shader. You must use this value when passing a texture index to the shader! returns -1 if idx is not valid

func (*Var) ValsMemSize

func (vr *Var) ValsMemSize(alignBytes int) int

ValsMemSize returns the memory allocation size for all values for this Var, in bytes

type VarList

type VarList struct {
	Vars   []*Var          `desc:"variables in order"`
	VarMap map[string]*Var `desc:"map of vars by name -- names must be unique"`
}

VarList is a list of variables

func (*VarList) ValByIdxTry

func (vs *VarList) ValByIdxTry(varName string, valIdx int) (*Var, *Val, error)

ValByIdxTry returns value by first looking up variable name, then value index, returning error if not found

func (*VarList) ValByNameTry

func (vs *VarList) ValByNameTry(varName, valName string) (*Var, *Val, error)

ValByNameTry returns value by first looking up variable name, then value name, returning error if not found

func (*VarList) VarByNameTry

func (vs *VarList) VarByNameTry(name string) (*Var, error)

VarByNameTry returns Var by name, returning error if not found

type VarRoles

type VarRoles int32

VarRoles are the functional roles of variables, corresponding to Vertex input vectors and all the different "uniform" types as enumerated in vk.DescriptorType. This does NOT map directly to DescriptorType because we combine vertex and uniform data and require a different ordering.

const (
	UndefVarRole VarRoles = iota
	Vertex                // vertex shader input data: mesh geometry points, normals, etc.  These are automatically located in a separate Set, VertexSet (-2), and managed separately.
	Index                 // for indexed access to Vertex data, also located in VertexSet (-2) -- only one such Var per VarSet should be present -- will automatically be used if a dynamically bound val is set
	Push                  // for push constants, which have a minimum of 128 bytes and are stored directly in the command buffer -- they do not require any host-device synchronization or buffering, and are fully dynamic.  They are ideal for transformation matricies or indexes for accessing data.  They are stored in a special PushSet (-1) and managed separately.
	Uniform               // read-only general purpose data, uses UniformBufferDynamic with offset specified at binding time, not during initial configuration -- compared to Storage, Uniform items can be put in local cache for each shader and thus can be much faster to access -- use for a smaller number of parameters such as transformation matricies
	Storage               // read-write general purpose data, in StorageBufferDynamic (offset set at binding) -- this is a larger but slower pool of memory, with more flexible alignment constraints, used primarily for compute data
	UniformTexel          // read-only image-formatted data, which cannot be accessed via ImageView or Sampler -- only for rare cases where optimized image format (e.g., rgb values of specific bit count) is useful.  No Dynamic mode is available, so this can only be used for a fixed Val.
	StorageTexel          // read-write image-formatted data, which cannot be accessed via ImageView or Sampler -- only for rare cases where optimized image format (e.g., rgb values of specific bit count) is useful. No Dynamic mode is available, so this can only be used for a fixed Val.
	StorageImage          // read-write access through an ImageView (but not a Sampler) of an Image
	TextureRole           // a Texture is a CombinedImageSampler in Vulkan terminology -- a combination of a Sampler and a specific Image, which appears as a single entity in the shader.
	VarRolesN
)

func (VarRoles) BuffType

func (vr VarRoles) BuffType() BuffTypes

BuffType returns type of memory buffer for this role

func (*VarRoles) FromString

func (i *VarRoles) FromString(s string) error

func (VarRoles) IsDynamic

func (vr VarRoles) IsDynamic() bool

IsDynamic returns true if role has dynamic offset binding

func (VarRoles) String

func (i VarRoles) String() string

func (VarRoles) VkDescriptor

func (vr VarRoles) VkDescriptor() vk.DescriptorType

VkDescriptor returns the vk.DescriptorType

type VarSet

type VarSet struct {
	VarList
	Set           int                 `desc:"set number"`
	NValsPer      int                 `` /* 586-byte string literal not displayed */
	NTextureDescs int                 `` /* 273-byte string literal not displayed */
	RoleMap       map[VarRoles][]*Var `desc:"map of vars by different roles, within this set -- updated in Config(), after all vars added"`
	ParentVars    *Vars               `desc:"the parent vars we belong to"`

	VkLayout   vk.DescriptorSetLayout `desc:"set layout info -- static description of each var type, role, binding, stages"`
	VkDescSets []vk.DescriptorSet     `` /* 210-byte string literal not displayed */
}

VarSet contains a set of Var variables that are all updated at the same time and have the same number of distinct Vals values per Var per render pass. The first set at index -1 contains Vertex and Index data, handed separately.

func (*VarSet) Add

func (st *VarSet) Add(name string, typ Types, arrayN int, role VarRoles, shaders ...ShaderTypes) *Var

Add adds a new variable of given type, role, arrayN, and shaders where used

func (*VarSet) AddStruct

func (st *VarSet) AddStruct(name string, size int, arrayN int, role VarRoles, shaders ...ShaderTypes) *Var

AddStruct adds a new struct variable of given total number of bytes in size, type, role, set, and shaders where used

func (*VarSet) AddVar

func (st *VarSet) AddVar(vr *Var)

AddVar adds given variable

func (*VarSet) BindDynVal

func (st *VarSet) BindDynVal(vs *Vars, vr *Var, vl *Val) error

BindDynVal dynamically binds given uniform or storage value for given variable in given set.

This only dynamically updates the offset to point to the specified val. MUST call System.BindVars prior to any subsequent draw calls for this new offset to be bound at the proper point in the command buffer prior (call after all such dynamic bindings are updated.)

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*VarSet) BindDynValIdx

func (st *VarSet) BindDynValIdx(vs *Vars, varNm string, valIdx int) error

BindDynValIdx dynamically binds given uniform or storage value by index for given variable name, in given set.

This only dynamically updates the offset to point to the specified val. MUST call System.BindVars prior to any subsequent draw calls for this new offset to be bound at the proper point in the command buffer prior (call after all such dynamic bindings are updated.)

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*VarSet) BindDynValName

func (st *VarSet) BindDynValName(vs *Vars, varNm, valNm string) error

BindDynValName dynamically binds given uniform or storage value by name for given variable name, in given set.

This only dynamically updates the offset to point to the specified val. MUST call System.BindVars prior to any subsequent draw calls for this new offset to be bound at the proper point in the command buffer prior (call after all such dynamic bindings are updated.)

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*VarSet) BindDynVar

func (st *VarSet) BindDynVar(vs *Vars, vr *Var) error

BindDynVar binds dynamic variable for given var for Uniform, Storage variables.

All vals must be uploaded to Device memory prior to this, and it is not possible to update actual values during a render pass. The memory buffer is essentially what is bound here.

Must have called BindVarsStart prior to this.

func (*VarSet) BindDynVarName

func (st *VarSet) BindDynVarName(vs *Vars, varNm string) error

BindDynVarName binds dynamic variable for given var looked up by name, for Uniform, Storage variables.

All vals must be uploaded to Device memory prior to this, and it is not possible to update actual values during a render pass. The memory buffer is essentially what is bound here.

Must have called BindVarsStart prior to this.

func (*VarSet) BindDynVars

func (st *VarSet) BindDynVars(vs *Vars)

BindDynVars binds all dynamic vars in set, to be able to use dynamic vars, in subsequent BindDynVal* calls during the render pass, which update the offsets. For Uniform & Storage variables, which use dynamic binding.

All vals must be uploaded to Device memory prior to this, and it is not possible to update actual values during a render pass. The memory buffer is essentially what is bound here.

Must have called BindVarsStart prior to this.

func (*VarSet) BindStatVar

func (st *VarSet) BindStatVar(vs *Vars, vr *Var)

BindStatVar does static variable binding for given var, For non-Uniform, Storage, variables (e.g., Textures). Each Val for a given Var is given a descriptor binding and the shader sees an array of values of corresponding length. All vals must be uploaded to Device memory prior to this, and it is not possible to update anything during a render pass.

func (*VarSet) BindStatVarName

func (st *VarSet) BindStatVarName(vs *Vars, varNm string) error

BindStatVarName does static variable binding for given var looked up by name, For non-Uniform, Storage, variables (e.g., Textures). Each Val for a given Var is given a descriptor binding and the shader sees an array of values of corresponding length. All vals must be uploaded to Device memory prior to this, and it is not possible to update anything during a render pass.

func (*VarSet) BindStatVars

func (st *VarSet) BindStatVars(vs *Vars)

BindStatVars binds all static vars to their current values, for non-Uniform, Storage, variables (e.g., Textures). Each Val for a given Var is given a descriptor binding and the shader sees an array of values of corresponding length. All vals must be uploaded to Device memory prior to this, and it is not possible to update anything during a render pass.

func (*VarSet) Config

func (st *VarSet) Config(dev vk.Device) error

Config must be called after all variables have been added. configures binding / location for all vars based on sequential order. also does validation and returns error message.

func (*VarSet) ConfigVals

func (st *VarSet) ConfigVals(nvals int)

ConfigVals configures the Vals for the vars in this set, allocating nvals per variable. There must be a unique value available for each distinct value to be rendered within a single pass. All Vars in the same set have the same number of vals. Any existing vals will be deleted -- must free all associated memory prior!

func (*VarSet) DescLayout

func (st *VarSet) DescLayout(dev vk.Device, vs *Vars)

DescLayout creates the DescriptorSetLayout in DescLayout for given set. Only for non-VertexSet sets. Must have set NValsPer for any TextureRole vars, which require separate descriptors per.

func (*VarSet) Destroy

func (st *VarSet) Destroy(dev vk.Device)

Destroy destroys infrastructure for Set, Vars and Vals -- assumes Free has already been called to free host and device memory.

func (*VarSet) DestroyLayout

func (st *VarSet) DestroyLayout(dev vk.Device)

DestroyLayout destroys layout

func (*VarSet) TexGpSzIdxs added in v1.0.0

func (st *VarSet) TexGpSzIdxs(vs *Vars, varNm string, valIdx int) *szalloc.Idxs

TexGpSzIdxs for texture at given index, allocated in groups by size using Vals.AllocTexBySize, returns the indexes for the texture and layer to actually select the texture in the shader, and proportion of the Gp allocated texture size occupied by the texture.

func (*VarSet) VkPushConfig

func (vs *VarSet) VkPushConfig() []vk.PushConstantRange

VkPushConfig returns vulkan push constant ranges

func (*VarSet) VkVertexConfig

func (st *VarSet) VkVertexConfig() *vk.PipelineVertexInputStateCreateInfo

VkVertexConfig fills in the relevant info into given vulkan config struct. for VertexSet only! Note: there is no support for interleaved arrays so each binding and location is assigned the same sequential number, recorded in var BindLoc

type Vars

type Vars struct {
	SetMap    map[int]*VarSet     `desc:"map of sets, by set number -- VertexSet is -2, PushSet is -1, rest are added incrementally"`
	RoleMap   map[VarRoles][]*Var `` /* 142-byte string literal not displayed */
	HasVertex bool                `inactive:"+" desc:"true if a VertexSet has been added"`
	HasPush   bool                `inactive:"+" desc:"true if PushSet has been added"`
	NDescs    int                 `` /* 442-byte string literal not displayed */
	Mem       *Memory             `view:"-" desc:"our parent memory manager"`

	VkDescLayout vk.PipelineLayout       `view:"-" desc:"vulkan descriptor layout based on vars"`
	VkDescPool   vk.DescriptorPool       `view:"-" desc:"vulkan descriptor pool, allocated for NDescs and the different descriptor pools"`
	VkDescSets   [][]vk.DescriptorSet    `` /* 372-byte string literal not displayed */
	VkWriteVals  []vk.WriteDescriptorSet `` /* 133-byte string literal not displayed */
	BindDescIdx  int                     `inactive:"-" desc:"current descriptor collection index, set in BindValsStart"`
	DynOffs      [][]uint32              `` /* 273-byte string literal not displayed */
}

Vars are all the variables that are used by a pipeline, organized into Sets (optionally including the special VertexSet or PushSet). Vars are allocated to bindings / locations sequentially in the order added!

func (*Vars) AddDynOff

func (vs *Vars) AddDynOff()

AddDynOff adds one more dynamic offset across all NDescs

func (*Vars) AddPushSet

func (vs *Vars) AddPushSet() *VarSet

AddPushSet adds a new push constant Set -- this is a special Set holding values sent directly in the command buffer.

func (*Vars) AddSet

func (vs *Vars) AddSet() *VarSet

AddSet adds a new non-Vertex Set for holding Uniforms, Storage, etc Sets are automatically numbered sequentially

func (*Vars) AddVertexSet

func (vs *Vars) AddVertexSet() *VarSet

AddVertexSet adds a new Vertex Set -- this is a special Set holding Vertex, Index vars

func (*Vars) AllocHost

func (vs *Vars) AllocHost(buff *MemBuff, offset int) int

func (*Vars) AllocTextures

func (vs *Vars) AllocTextures(mm *Memory)

AllocTextures allocates images on device memory

func (*Vars) BindAllTextureVars

func (vs *Vars) BindAllTextureVars(set int) error

BindAllTextureVars binds all Texture vars in given set to their current values, iterating over NTextureDescs in case there are multiple Desc sets required to represent more than MaxTexturesPerSet. Each Val for a given Var is given a descriptor binding and the shader sees an array of values of corresponding length. All vals must be uploaded to Device memory prior to this, and it is not possible to update anything during a render pass. This calls BindStart / Bind

func (*Vars) BindDynVal

func (vs *Vars) BindDynVal(set int, vr *Var, vl *Val) error

BindDynVal dynamically binds given uniform or storage value for given variable in given set.

This only dynamically updates the offset to point to the specified val. MUST call System.BindVars prior to any subsequent draw calls for this new offset to be bound at the proper point in the command buffer prior (call after all such dynamic bindings are updated.)

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*Vars) BindDynValIdx

func (vs *Vars) BindDynValIdx(set int, varNm string, valIdx int) error

BindDynValIdx dynamically binds given uniform or storage value by index for given variable name, in given set.

This only dynamically updates the offset to point to the specified val. MUST call System.BindVars prior to any subsequent draw calls for this new offset to be bound at the proper point in the command buffer prior (call after all such dynamic bindings are updated.)

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*Vars) BindDynValName

func (vs *Vars) BindDynValName(set int, varNm, valNm string) error

BindDynValName dynamically binds given uniform or storage value by name for given variable name, in given set.

This only dynamically updates the offset to point to the specified val. MUST call System.BindVars prior to any subsequent draw calls for this new offset to be bound at the proper point in the command buffer prior (call after all such dynamic bindings are updated.)

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*Vars) BindDynVarName

func (vs *Vars) BindDynVarName(set int, varNm string) error

BindDynVarName binds dynamic variable for given var looked up by name, for Uniform, Storage variables.

All vals must be uploaded to Device memory prior to this, and it is not possible to update actual values during a render pass. The memory buffer is essentially what is bound here.

Must have called BindVarsStart prior to this.

func (*Vars) BindDynVars

func (vs *Vars) BindDynVars(set int) error

BindDynVars binds all dynamic vars in given set, to be able to use dynamic vars, in subsequent BindDynVal* calls during the render pass, which update the offsets. For Uniform & Storage variables, which use dynamic binding.

This is automatically called during Config on the System, and usually does not need to be called again.

All vals must be uploaded to Device memory prior to this, and it is not possible to update actual values during a render pass. The memory buffer is essentially what is bound here.

Must have called BindVarsStart prior to this.

func (*Vars) BindDynVarsAll

func (vs *Vars) BindDynVarsAll()

BindDynVarsAll binds all dynamic vars across all sets. Called during system config.

func (*Vars) BindStatVarName

func (vs *Vars) BindStatVarName(set int, varNm string) error

BindStatVarName does static variable binding for given var looked up by name, for non-Uniform, Storage, variables (e.g., Textures). Each Val for a given Var is given a descriptor binding and the shader sees an array of values of corresponding length.

All vals must be uploaded to Device memory prior to this, and it is not possible to update anything during a render pass.

Must have called BindVarsStart prior to this.

func (*Vars) BindStatVars

func (vs *Vars) BindStatVars(set int) error

BindStatVars binds all static vars to their current values, for given set, for non-Uniform, Storage, variables (e.g., Textures). Each Val for a given Var is given a descriptor binding and the shader sees an array of values of corresponding length.

All vals must be uploaded to Device memory prior to this, and it is not possible to update anything during a render pass.

Must have called BindVarsStart prior to this.

func (*Vars) BindVarsEnd

func (vs *Vars) BindVarsEnd()

BindVarsEnd finishes a new step of binding started by BindVarsStart. Actually executes the binding updates, based on prior BindVar* calls.

func (*Vars) BindVarsStart

func (vs *Vars) BindVarsStart(descIdx int)

BindVarsStart starts a new step of binding vars to descriptor sets, using given descIdx description set index (among the NDescs allocated). Bound vars determine what the shader programs see, in subsequent calls to Pipeline commands.

This must be called *prior* to a render pass, never within it. Only BindDyn* and BindVertex* calls can be called within render.

Do NOT use this around BindDynVal or BindVertexVal calls only for BindVar* methods.

Subsequent calls of BindVar* methods will add to a list, which will be executed when BindValsEnd is called.

This creates a set of entries in a list of WriteDescriptorSet's

func (*Vars) BindVertexValIdx

func (vs *Vars) BindVertexValIdx(varNm string, valIdx int) error

BindVertexValIdx dynamically binds given VertexSet value by index for given variable name. using given descIdx description set index (among the NDescs allocated).

Value must have already been updated into device memory prior to this, ideally through a batch update prior to starting rendering, so that all the values are ready to be used during the render pass. This only dynamically updates the offset to point to the specified val.

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*Vars) BindVertexValName

func (vs *Vars) BindVertexValName(varNm, valNm string) error

BindVertexValName dynamically binds given VertexSet value by name for given variable name. using given descIdx description set index (among the NDescs allocated).

Value must have already been updated into device memory prior to this, ideally through a batch update prior to starting rendering, so that all the values are ready to be used during the render pass. This dynamically updates the offset to point to the specified val.

Do NOT call BindValsStart / End around this.

returns error if not found.

func (*Vars) Config

func (vs *Vars) Config() error

Config must be called after all variables have been added. Configures all Sets and also does validation, returning error does DescLayout too, so all ready for Pipeline config.

func (*Vars) DescLayout

func (vs *Vars) DescLayout(dev vk.Device)

DescLayout configures the PipelineLayout of DescriptorSetLayout info for all of the non-Vertex vars

func (*Vars) Destroy

func (vs *Vars) Destroy(dev vk.Device)

func (*Vars) Free

func (vs *Vars) Free(buff *MemBuff)

Free resets the MemPtr for values, resets any self-owned resources (Textures)

func (*Vars) MemSize

func (vs *Vars) MemSize(buff *MemBuff) int

func (*Vars) ModRegs

func (vs *Vars) ModRegs(bt BuffTypes) []MemReg

ModRegs returns the regions of Vals that have been modified

func (*Vars) NSets

func (vs *Vars) NSets() int

NSets returns the number of regular non-VertexSet sets

func (*Vars) PushSet

func (vs *Vars) PushSet() *VarSet

PushSet returns the Push Set -- a special Set holding push constants

func (*Vars) SetTry

func (vs *Vars) SetTry(set int) (*VarSet, error)

SetTry returns set by index, returning nil and error if not found

func (*Vars) StartSet

func (vs *Vars) StartSet() int

StartSet returns the starting set to use for iterating sets

func (*Vars) StringDoc

func (vs *Vars) StringDoc() string

StringDoc returns info on variables

func (*Vars) TexGpSzIdxs added in v1.0.0

func (vs *Vars) TexGpSzIdxs(set int, varNm string, valIdx int) *szalloc.Idxs

TexGpSzIdxs for texture at given index, allocated in groups by size using Vals.AllocTexBySize, returns the indexes for the texture and layer to actually select the texture in the shader, and proportion of the Gp allocated texture size occupied by the texture.

func (*Vars) ValByIdxTry

func (vs *Vars) ValByIdxTry(set int, varName string, valIdx int) (*Var, *Val, error)

ValByIdxTry returns value by first looking up variable name, then value index, returning error if not found

func (*Vars) ValByNameTry

func (vs *Vars) ValByNameTry(set int, varName, valName string) (*Var, *Val, error)

ValByNameTry returns value by first looking up variable name, then value name, within given set number, returning error if not found

func (*Vars) VarByNameTry

func (vs *Vars) VarByNameTry(set int, name string) (*Var, error)

VarByNameTry returns Var by name in given set number, returning error if not found

func (*Vars) VertexSet

func (vs *Vars) VertexSet() *VarSet

VertexSet returns the Vertex Set -- a special Set holding Vertex, Index vars

func (*Vars) VkPushConfig

func (vs *Vars) VkPushConfig() []vk.PushConstantRange

VkPushConfig returns vulkan push constant ranges, only if PushSet used.

func (*Vars) VkVertexConfig

func (vs *Vars) VkVertexConfig() *vk.PipelineVertexInputStateCreateInfo

VkVertexConfig returns vulkan vertex config struct, for VertexSet only! Note: there is no support for interleaved arrays so each binding and location is assigned the same sequential number, recorded in var BindLoc

Jump to

Keyboard shortcuts

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