vkg

package module
v0.0.0-...-428aa4c Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 12 Imported by: 0

README

Intro

This repo is very much a work in progress of utilizing Vulkan with go. I've wrapped the vulkan-go/vulkan APIs to make them a little more idiomatic, and easier to use and also provided a bunch of utility classes.

Here is where I'm at:

  • Provides an easier to use API than the native Vulkan APIs
  • Provides for access to all underlying vulkan data structures, so it makes things easy without hiding the necessary bits to utilize the full vulkan API
  • Works with ImGUI
  • Custom memory allocator see allocator.go
  • Utility class called GraphicsApp which does most of the bootstrapping required to get a vulkan app up and going
  • Can display meshes and textures

If you want to get a good idea of where I'm going checkout examples/imgui

Here is where I expect to go;

  • More documentation
  • More examples
  • Unit tests

I'm hoping to continue pushing on this repo more in the next few weeks.

Screenshots

Here is a picture of the examples/imgui program:

Example program

Here is a picture of the examples/texture program:

Example program

Quick example code

Here is the example this code comes from

How to initialize a new graphics app:

// we initialize glfw, so we can create a window
glfw.Init()

// setup vulkan
vk.SetGetInstanceProcAddr(glfw.GetVulkanGetInstanceProcAddress())
vk.Init()

// create our window
glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI)
c.window, _ = glfw.CreateWindow(Width, Height, "VulkanCube", nil, nil)

// create a new graphics app
c.app, _ = vkg.NewGraphicsApp("VulkanCube", vkg.Version{1, 0, 0})

// we need to do some configuration before we can
// can initalize our application
c.app.SetWindow(c.window)
c.app.EnableDebugging()

// initialize our graphics app
c.app.Init()

How to create memory resources from allocated pools

// we allocate a new memory pool, with the size we calculated above, and we tell vulkan where we'd like to store the data
// in this case we're gonna store all our data in the host's memory and use a memory map to sync the data to the GPU
// so we specify HostVisible|HostCoherent to make sure we can memory map the data, and specify that we want to use this buffer
// for vertex, index and uniform buffer storage
cubePool, _ := c.app.ResourceManager.AllocateBufferPoolWithOptions("cube", uint64(bytesNeeded),
	vk.MemoryPropertyHostCoherentBit|vk.MemoryPropertyHostVisibleBit,
	vk.BufferUsageVertexBufferBit|vk.BufferUsageIndexBufferBit|vk.BufferUsageUniformBufferBit,
	vk.SharingModeExclusive)

m.VertexResource, _ = cubePool.AllocateBuffer(uint64(len(m.VertexData.Bytes())), vk.BufferUsageVertexBufferBit)

m.IndexResource, _ = cubePool.AllocateBuffer(uint64(len(m.IndexData.Bytes())), vk.BufferUsageIndexBufferBit)

m.UBOResource, _ = cubePool.AllocateBuffer(uint64(len(m.UBO.Bytes())), vk.BufferUsageUniformBufferBit)

How to map memory:

// Map the data so we can simply write to it
cubePool.Memory.Map()

copy(m.VertexResource.Bytes(), m.VertexData.Bytes())
copy(m.IndexResource.Bytes(), m.IndexData.Bytes())

How to configure a custom graphics pipeline

// create a graphics pipeline
gc := c.app.CreateGraphicsPipelineConfig()

// our mesh implements in interface which allows it
// to describe how it's vertex data is layed out, so we provide
// that interface to our graphics pipeline
gc.AddVertexDescriptor(c.mesh.VertexData)

// load some shaders
gc.AddShaderStageFromFile("shaders/vert.spv", "main", vk.ShaderStageVertexBit)
gc.AddShaderStageFromFile("shaders/frag.spv", "main", vk.ShaderStageFragmentBit)

// set our pipeline layout which describes how we wish to layout our data in our descriptors
gc.SetPipelineLayout(c.pipelineLayout)

// lastly we tell our graphics app about this pipeline config
// we use named pipeline configs because at it's descretion the graphics app
// must be able to recreate the actual pipelines from it's configs
c.app.AddGraphicsPipelineConfig("cube", gc)

How to send commands to the graphics queue

// because command buffers are allocated from a pool
// and reused we must reset it
buffer.Reset()

// clear values are used to clear the screen and depth buffer
clearValues := make([]vk.ClearValue, 2)
clearValues[0].SetColor([]float32{0.2, 0.2, 0.2, 1})
clearValues[1].SetDepthStencil(1, 0)

// begin recording commands
buffer.Begin()

// create a render pass struct
renderPassBeginInfo := vk.RenderPassBeginInfo{
	SType:       vk.StructureTypeRenderPassBeginInfo,
	RenderPass:  c.app.VKRenderPass,
	Framebuffer: c.app.Framebuffers[frame],
	RenderArea: vk.Rect2D{
		Offset: vk.Offset2D{
			X: 0, Y: 0,
		},
		Extent: c.app.GetScreenExtent(),
	},
	ClearValueCount: 2,
	PClearValues:    clearValues,
}

vk.CmdBeginRenderPass(buffer.VK(), &renderPassBeginInfo, vk.SubpassContentsInline)

// we tell vulkan which graphics pipeline we want to use - the one we defined above
vk.CmdBindPipeline(buffer.VK(), vk.PipelineBindPointGraphics, c.app.GraphicsPipelines["cube"])

// tell it which buffer our vertex data comes from
vk.CmdBindVertexBuffers(buffer.VK(), 0, 1, []vk.Buffer{c.mesh.VertexResource.VKBuffer}, []vk.DeviceSize{0})

// tell it which buffer our index data comes from
vk.CmdBindIndexBuffer(buffer.VK(), c.mesh.IndexResource.VKBuffer, vk.DeviceSize(0), vk.IndexTypeUint16)

// tell vulkan about our descriptor sets which feed data to our shaders
vk.CmdBindDescriptorSets(buffer.VK(), vk.PipelineBindPointGraphics,
	c.pipelineLayout.VKPipelineLayout, 0, 1,
	[]vk.DescriptorSet{c.mesh.descriptorSet.VKDescriptorSet}, 0, nil)

// lastly tell vulkan which indexes to draw
vk.CmdDrawIndexed(buffer.VK(), uint32(len(c.mesh.IndexData)), 1, 0, 0, 0)

vk.CmdEndRenderPass(buffer.VK())

buffer.End()

Documentation

Overview

Package vkg implements an abstraction atop the Vulkan graphics framework for go. Vulkan is a very powerful graphics and compute framework, which expands upon what is possible with OpenGL and OpenCL, but at a cost - it is very difficult and complex to use, yet very powerful.

This package provides utility functions and objects which make Vulkan a little more paltable to gophers, with the drawback that it cannot possibly expose all the power inherent in Vulkan, so it strives to avoid limiting users when they desire to utilize the full power of Vulkan.

Overview of Vulkan

Vulkan overcomes many of the drawbacks of OpenGL by providing a much less abstracted interface to GPUs at a pretty hefty cost, all the things OpenGL managed previously are now up to the implementing application to manage. This documentation is woefully inadequate at fully descrbing how Vulkan works, and is meant to provide a refersher and perhaps some bread crumbs which will aid in undersatnding the system.

At a high level vulkan provides a method of submiting work to command queues which execute various pipeline (which the application has configured) to either display graphics or peform compute work. An example of a pipeline might be one which displays a set of vertex data in a specific way, or a compute pipeline which pefroms some massively parallel mathmatical operation on a large set of data. The challenge then becomes providing the data in a way which these pipelines can utilize, so the data must be described adqueately enough so that the GPU can work with the data in an optimal way. To allow application developers to better utilize the underlying hardware, many decisions about how this data is managed is now left up to the application developer, rather than manged by a framework like OpenGL.

This means the application developer is now responsible for deciding where the data which is to be processed by the pipeline will reside, what the format of the data is and how to make sure the data arrives at the appopriate time to best utilize the underlying hardware (this is a daunting task and application specific). So a game developed with Vulkan will have different needs and priorites than a scientific computing application developed with Vulkan, or even a 3D editor.

This package can provide some assitance in getting started with vulkan but cannot possibly provide apporpaite abstractions for all possible use cases, or else it would fall into the trap of OpenGL - doing too much in a sub optimal way.

Back to a discussion of Vulkan, we have command queues, which are feeding pipelines, which are using data provided by the application.

Native Vulkan terms

Instance 	the vulkan runtime instance
PhysicalDevice	the physical hardware device
LogicalDevice	a representation of the device which is the target of most of the vulkan apis.
Pipeline	a description of how to process data on the GPU
Queue 		a queue which work (comand buffers) may be submitted to
DeviceMemory	a allocation of memory on the host or device for use by buffers and images
Buffer		a description of some bit of data (vertex, index, or other)
Image		a description of some image
ImageView	a way of descibing how an image is utilized or viewed
DescriptorSet 	a mapping of data for use by shaders
DescriptorSetLayout a description of what data is in the descriptor set
Swapchain	a grouping of images which are used to display graphical data

When thinking about how a graphics application with Vulkan works a very high level sequences of might be:

  1. Intialize the vulkan instance
  2. Setup the swapchain and framebuffers
  3. Allocate buffers and device memory 3a. Allocate a buffer and memory on the host for vertex data 3b. Allocate a staging buffer in host memory to send texture data to the device 3c. Allocate a image in the device memory to recieve the texture data
  4. Load data 4a. Load vertex into the host allocated memory by 'mapping' the memory 4b. Load texture data into a host allocated staging buffer
  5. Query the physical device for queues which work may be submitted to
  6. Submit a command buffer to a device queue to copy the image data loaded in 3b. to the image created in 3c
  7. Create a descriptor set which describes how data is related in the application
  8. Configure and create a graphics pipeline (and provide it the descriptor set)
  9. Start drawing frames:
  10. Fill a command buffer with the pipeline and vertex details to draw
  11. Draw the image and display it.

About this package

This package provides a basic set of APIs which wrap some of the Vulkan APIs to make them a bit less painful to work with, the trade off being that many of the native Vulkan APIs expose options which are not exposed in the APIs provided by the package. To mitigate the drawback of this approach native vulkan structures are exposed in all the objects prefixed with the 'VK' in the name - so applications aren't limited by what this package provides.

This package goes beyond what Vulkan natively provides to make Vulkan a bit easier to work with:

GraphicsApp:

a basic graphics application framework which managed setup and frame drawing

ResourceManager:

a resource manager which manages memory allocation and can assist with staging of resources

Utility interfaces:

for using and describing data

Index

Constants

View Source
const StagingPoolName = "staging"
View Source
const StopCmdBufferConstruction = -1

StopCmdBufferConstruction is used to signal that command buffer construction should stop

Variables

View Source
var FrameLag = 3

Functions

func DefaultDebugCallback

func DefaultDebugCallback(flags vk.DebugReportFlags, objectType vk.DebugReportObjectType,
	object uint64, location uint, messageCode int32, pLayerPrefix string,
	pMessage string, pUserData unsafe.Pointer) vk.Bool32

DefaultDebugCallback - taken from github.com/vulkan-go/asche/

func InitializeForComputeOnly

func InitializeForComputeOnly() error

InitializeCompute initializes Vulkan for a compute based task, it doesn't enable any graphics capabilties.

func SupportedExtensions

func SupportedExtensions() ([]string, error)

SupportedExtensions returns a list of supported extensions for use by Vulkan this may crash if Vulkan has not been initialized previously for use in a compute, or graphics capability of some kind

func SupportedLayers

func SupportedLayers() ([]string, error)

SupportedLayers returns a list of supported layers for use by Vulkan this may crash if Vulkan has not been initialized previously for use in a compute, or graphics capability of some kind

func ToBytes

func ToBytes(ptr unsafe.Pointer, lenInBytes int) []byte

ToBytes will take an unsafe.Pointer and length in bytes and convert it to a byte slice

Types

type Allocation

type Allocation struct {
	// Offset in memory to this object
	Offset uint64
	// Size of the allocated memory
	Size uint64

	// The item that was allocated
	Object IAllocatedItem
}

Allocation is an allocation of some hunk of memory

func (*Allocation) String

func (a *Allocation) String() string

String for stringer interface

type App

type App struct {
	// Name the name of the application
	Name string
	// Engine the name of the engine associated with the application
	EngineName string
	// Version the version of the application
	Version Version
	// APIVersion the expected minimum version of the Vulkan API (i.e. 1.0.0)
	APIVersion Version

	// EnabledLayers the enabled layers
	EnabledLayers []string

	// EnabledExtensions the enabled extensions
	EnabledExtensions []string
}

App is used to provide information about this specific application to Vulkan

func (*App) CreateInstance

func (a *App) CreateInstance() (*Instance, error)

CreateInstance creates an the Vulkan Instance

func (*App) EnableDebugging

func (a *App) EnableDebugging()

func (*App) EnableExtension

func (a *App) EnableExtension(extension string) *App

Enable an extension for use by the application

func (*App) EnableLayer

func (a *App) EnableLayer(layer string) (*App, error)

Enable a specific layer

func (*App) VKApplicationInfo

func (a *App) VKApplicationInfo() vk.ApplicationInfo

VKApplicationInfo creates a structure representing this application in a Vulkan friendly format

type Buffer

type Buffer struct {
	Device   *Device
	VKBuffer vk.Buffer
	Usage    vk.BufferUsageFlagBits
	Size     uint64
}

Buffer in vulkan are essentially a way of identifying and describing resources to the system. So for example you can have a buffer which holds vertex data in a specific format, or index data or a U.B.O (Uniform Buffer Object - which is data which is provided to a shader), or a buffer which is a source or destination for data from other locations. Buffers can reside either in the host memory or in the GPU (device) memory. The buffer itself is not the allocation of memory but simply a description of what the memory is and where it is. Device or host memory must still be allocated using the physical device object to actually hold the data associated with the buffer.

func (*Buffer) Bind

func (b *Buffer) Bind(memory *DeviceMemory, offset uint64) error

Bind associates a specific bit of device memory with this buffer, essentially identifying the memory as being used by this buffer. The offset is provied so that the buffer can be bound to a certain place in memory. There is a requirement that the buffer be bound in accordance with the alignment requirements returned by .VKMemoryRequirements().

func (*Buffer) Destroy

func (b *Buffer) Destroy()

Destroy the buffer

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) VKMemoryRequirements

func (b *Buffer) VKMemoryRequirements() vk.MemoryRequirements

VKMemoryRequirements returns the vulkan native vk.MemoryRequirements objects which can be inspected to learn more about the memory requirements assocaited with this buffer. (You must call .Deref() on this object to populate it).

type BufferResource

type BufferResource struct {
	Buffer
	ResourcePool    *BufferResourcePool
	Allocation      *Allocation
	StagingResource *BufferResource
}

BufferResource is a buffer based resource, for example vertex buffer, index buffer, UBO, which have been allocated from a larger pool of device memory. Vulkan limits the number of memory allocations that can be done by an application, so applications should manage their own pools of memory. A BufferResource is a buffer which has been managed by the ResourceManager.

func (*BufferResource) AllocateStagingResource

func (r *BufferResource) AllocateStagingResource() error

AllocateStagingResource will allocate an apporpriate resource which can be used for staging this resource. Once allocated it must be explicitly free'd. The staging resource is allocated from a resource pool called 'staging', which the program must create

func (*BufferResource) Bytes

func (r *BufferResource) Bytes() []byte

Bytes returns a byte slice representing the mapped memory, which can be read from or copied to

func (*BufferResource) Destroy

func (r *BufferResource) Destroy()

func (*BufferResource) Free

func (r *BufferResource) Free()

Free this resource and it's associated resources

func (*BufferResource) FreeStagingResource

func (r *BufferResource) FreeStagingResource()

FreeStagingResource will free the staged resource associated with this resource

func (*BufferResource) RequiresStaging

func (r *BufferResource) RequiresStaging() bool

RequiresStaging indicates that this particular buffer resource must be staged before it can be used. This is primarly indicative that the BufferResource is stored in device memory.

func (*BufferResource) String

func (r *BufferResource) String() string

func (*BufferResource) VKMappedMemoryRange

func (r *BufferResource) VKMappedMemoryRange() vk.MappedMemoryRange

VKMappedMemoryRange is provided so that the buffer implements MappedMemoryRange interface which can be used by device.FlushMappedRanges(...)

type BufferResourcePool

type BufferResourcePool struct {
	Device           *Device
	Name             string
	Usage            vk.BufferUsageFlagBits
	Sharing          vk.SharingMode
	MemoryProperties vk.MemoryPropertyFlagBits
	Size             uint64
	Allocator        IAllocator
	Memory           *DeviceMemory
	NeedsStaging     bool
	ResourceManager  *ResourceManager
}

func (*BufferResourcePool) AllocateBuffer

func (p *BufferResourcePool) AllocateBuffer(size uint64, usage vk.BufferUsageFlagBits) (*BufferResource, error)

func (*BufferResourcePool) AllocateFor

func (p *BufferResourcePool) AllocateFor(src ByteSourcer) (*BufferResource, error)

func (*BufferResourcePool) Destroy

func (p *BufferResourcePool) Destroy()

func (*BufferResourcePool) LogDetails

func (p *BufferResourcePool) LogDetails()

type ByteSourcer

type ByteSourcer interface {
	Bytes() []byte
}

You try to make a idiomatic go interface name out of an object that can represent stuff as bytes - byteabler?

type CommandBuffer

type CommandBuffer struct {
	VKCommandBuffer vk.CommandBuffer
}

CommandBuffers describe a sequence of commands that will be executed upon being sent to a device queue. Not all available vulkan commands are wrapped by this package. It is expected that the calling application must call the native vulkan command APIs.

func (*CommandBuffer) Begin

func (c *CommandBuffer) Begin() error

Begin capturing work for this command buffer

func (*CommandBuffer) BeginContinueRenderPass

func (c *CommandBuffer) BeginContinueRenderPass(renderpass vk.RenderPass, framebuffer vk.Framebuffer) error

Begin capturing work for this command buffer

func (*CommandBuffer) BeginOneTime

func (c *CommandBuffer) BeginOneTime() error

BeginOneTime begins capturing work for this command buffer, with the stipulation that it will only be used once (instead of put back in the pool of command buffers)

func (*CommandBuffer) CmdBindComputePipeline

func (c *CommandBuffer) CmdBindComputePipeline(p *ComputePipeline)

func (*CommandBuffer) CmdBindDescriptorSets

func (c *CommandBuffer) CmdBindDescriptorSets(bindPoint vk.PipelineBindPoint, layout *PipelineLayout, firstSet int, descriptorSets ...*DescriptorSet)

func (*CommandBuffer) CmdCopyBufferFromStagedResource

func (c *CommandBuffer) CmdCopyBufferFromStagedResource(resource *BufferResource)

CmdCopyBufferFromStagedResource will populate this buffer from the previously allocated staged resource

func (*CommandBuffer) CmdDispatch

func (c *CommandBuffer) CmdDispatch(x, y, z int)

func (*CommandBuffer) End

func (c *CommandBuffer) End() error

End describing work for this command buffer

func (*CommandBuffer) Reset

func (c *CommandBuffer) Reset() error

Reset this command buffer

func (*CommandBuffer) ResetAndRelease

func (c *CommandBuffer) ResetAndRelease() error

ResetAndRelease will reset this commandbuffer and release the associated resources

func (*CommandBuffer) StageImageResource

func (cb *CommandBuffer) StageImageResource(img *ImageResource) error

func (*CommandBuffer) TransitionImageLayout

func (cb *CommandBuffer) TransitionImageLayout(img *ImageResource, format vk.Format, oldLayout, newLayout vk.ImageLayout)

func (*CommandBuffer) VK

func (c *CommandBuffer) VK() vk.CommandBuffer

VK is a utility function for accessing the native vulkan command buffer

type CommandPool

type CommandPool struct {
	Device        *Device
	QueueFamily   *QueueFamily
	VKCommandPool vk.CommandPool
}

CommandPool for managing a pool of command buffers

func (*CommandPool) AllocateBuffer

func (c *CommandPool) AllocateBuffer(level vk.CommandBufferLevel) (*CommandBuffer, error)

AllocateBuffer allocates a single command buffer

func (*CommandPool) AllocateBuffers

func (c *CommandPool) AllocateBuffers(count int, level vk.CommandBufferLevel) ([]*CommandBuffer, error)

AllocateBuffers allocates some number of command buffers

func (*CommandPool) Destroy

func (c *CommandPool) Destroy()

Destroy this command pool

func (*CommandPool) FreeBuffer

func (c *CommandPool) FreeBuffer(b *CommandBuffer)

FreeBuffer frees a single buffer

func (*CommandPool) FreeBuffers

func (c *CommandPool) FreeBuffers(bs []*CommandBuffer)

FreeBuffers frees a set of command buffers

type ComputePipeline

type ComputePipeline struct {
	Device                          *Device
	VKPipeline                      vk.Pipeline
	VKPipelineShaderStageCreateInfo vk.PipelineShaderStageCreateInfo
	VKPipelineLayout                vk.PipelineLayout
}

func (*ComputePipeline) Destroy

func (c *ComputePipeline) Destroy()

func (*ComputePipeline) SetPipelineLayout

func (c *ComputePipeline) SetPipelineLayout(layout *PipelineLayout)

func (*ComputePipeline) SetShaderStage

func (c *ComputePipeline) SetShaderStage(entryPoint string, shaderModule *ShaderModule)

type CreateDeviceOptions

type CreateDeviceOptions struct {
	EnabledExtensions []string
	EnabledLayers     []string
}

type CreateSwapchainOptions

type CreateSwapchainOptions struct {
	OldSwapchain              *Swapchain
	ActualSize                vk.Extent2D
	DesiredNumSwapchainImages int
}

type DebugCallback

type DebugCallback func(flags vk.DebugReportFlags, objectType vk.DebugReportObjectType,
	object uint64, location uint, messageCode int32, pLayerPrefix string,
	pMessage string, pUserData unsafe.Pointer) vk.Bool32

type Descriptor

type Descriptor struct {
	Type        vk.DescriptorType
	ShaderStage vk.ShaderStageFlags
	Set         int
	Binding     int
}

type DescriptorBinder

type DescriptorBinder interface {
	Descriptor() *Descriptor
}

type DescriptorPool

type DescriptorPool struct {
	Device               *Device
	VKDescriptorPool     vk.DescriptorPool
	VKDescriptorPoolSize []vk.DescriptorPoolSize
}

DescriptorPool is essentially a resource manager for descriptor pools provided by Vulkan.

func (*DescriptorPool) AddPoolSize

func (d *DescriptorPool) AddPoolSize(dtype vk.DescriptorType, count int)

AddPoolSize informs the descriptor pool how many of a certain descriptortype it will contain

func (*DescriptorPool) Allocate

func (d *DescriptorPool) Allocate(layouts ...*DescriptorSetLayout) (*DescriptorSet, error)

Allocate allocates a descriptor set from the pool given the descriptor set layout

func (*DescriptorPool) Destroy

func (d *DescriptorPool) Destroy()

func (*DescriptorPool) Free

func (d *DescriptorPool) Free(ds *DescriptorSet) error

func (*DescriptorPool) Reset

func (d *DescriptorPool) Reset() error

type DescriptorSet

type DescriptorSet struct {
	Device               *Device
	DescriptorPool       *DescriptorPool
	VKDescriptorSet      vk.DescriptorSet
	VKWriteDiscriptorSet []vk.WriteDescriptorSet
}

DescriptorSet is a binding of resources to a descriptor, per a specific DescriptorSetLayout

func (*DescriptorSet) AddBuffer

func (du *DescriptorSet) AddBuffer(dstBinding int, dtype vk.DescriptorType, b *Buffer, offset int)

AddBuffer adds a specific buffer to this descirptor set

func (*DescriptorSet) AddCombinedImageSampler

func (du *DescriptorSet) AddCombinedImageSampler(dstBinding int, layout vk.ImageLayout, imageView vk.ImageView, sampler vk.Sampler)

AddCombinedImageSampler adds an image layout, image view and sampler to support displaying a texture

func (*DescriptorSet) Write

func (du *DescriptorSet) Write()

Write modifies the descriptor set

type DescriptorSetLayout

type DescriptorSetLayout struct {
	Device                        *Device
	VKDescriptorSetLayout         vk.DescriptorSetLayout
	VKDescriptorSetLayoutBindings []vk.DescriptorSetLayoutBinding
}

DescriptorSetLayout describes the layout of a descriptorset

func (*DescriptorSetLayout) AddBinding

func (d *DescriptorSetLayout) AddBinding(binding vk.DescriptorSetLayoutBinding)

AddBinding adds a binding to the descriptor set

func (*DescriptorSetLayout) Destroy

func (d *DescriptorSetLayout) Destroy()

Destroy destroys this descriptor set layout

type Device

type Device struct {
	PhysicalDevice *PhysicalDevice
	VKDevice       vk.Device
}

Device is a logical device per Vulkan terminology

func (*Device) Allocate

func (d *Device) Allocate(sizeInBytes int, memoryTypeBits uint32, memoryProperties vk.MemoryPropertyFlagBits) (*DeviceMemory, error)

Allocate allocates a certain amount and type of memory

func (*Device) CreateBufferWithOptions

func (d *Device) CreateBufferWithOptions(sizeInBytes uint64, usage vk.BufferUsageFlagBits, sharing vk.SharingMode) (*Buffer, error)

CreateBufferWithOptions creates a buffer object of a certain size, for a certain usage, with certain sharing options. This buffer can be used to describe memory which is allocated on either the host or device.

func (*Device) CreateCommandPool

func (d *Device) CreateCommandPool(q *QueueFamily) (*CommandPool, error)

CreateCommandPool given a specific queue family

func (*Device) CreateComputePipelines

func (d *Device) CreateComputePipelines(pc *PipelineCache, cp ...*ComputePipeline) error

func (*Device) CreateDescriptorPool

func (d *Device) CreateDescriptorPool(pool *DescriptorPool, maxSets int) (*DescriptorPool, error)

CreateDescriptorPool creates the descriptor pool

func (*Device) CreateDescriptorSetLayout

func (d *Device) CreateDescriptorSetLayout(layout *DescriptorSetLayout) (*DescriptorSetLayout, error)

CreateDescriptorSetLayout creates this descriptor set layout

func (*Device) CreateFence

func (d *Device) CreateFence() (*Fence, error)

func (*Device) CreateGraphicsPipelineConfig

func (d *Device) CreateGraphicsPipelineConfig() *GraphicsPipelineConfig

CreateGraphicsPipelineConfig creates a new config object

func (*Device) CreateImageWithOptions

func (d *Device) CreateImageWithOptions(extent vk.Extent2D, format vk.Format, tiling vk.ImageTiling, usage vk.ImageUsageFlagBits) (*Image, error)

CreateImageWithOptions creates an image with some commonly used options

func (*Device) CreatePipelineCache

func (d *Device) CreatePipelineCache() (*PipelineCache, error)

func (*Device) CreatePipelineLayout

func (d *Device) CreatePipelineLayout(descriptorSetLayouts ...*DescriptorSetLayout) (*PipelineLayout, error)

func (*Device) CreatePipelineLayoutWithPushConstants

func (d *Device) CreatePipelineLayoutWithPushConstants(descriptorSetLayouts []*DescriptorSetLayout, pushConstants []vk.PushConstantRange) (*PipelineLayout, error)

func (*Device) CreateResourceManager

func (d *Device) CreateResourceManager() *ResourceManager

func (*Device) CreateSwapchain

func (p *Device) CreateSwapchain(surface vk.Surface, graphicsQueue, presentQueue *Queue, options *CreateSwapchainOptions) (*Swapchain, error)

func (*Device) DefaultNumSwapchainImages

func (p *Device) DefaultNumSwapchainImages(surface vk.Surface) (int, error)

func (*Device) Destroy

func (d *Device) Destroy()

Destroy destroys the device

func (*Device) DestroyAny

func (d *Device) DestroyAny(i interface{})

DestroyAny is a utility function which given an item will try to figure out how to destroy it

func (*Device) FlushMappedRanges

func (d *Device) FlushMappedRanges(r ...MappedMemoryRange) error

FlushMappedRanges will flush mapped memory ranges, it can take a BufferResource directly, as it implements the required interface

func (*Device) GetQueue

func (d *Device) GetQueue(qf *QueueFamily) *Queue

GetQueue gets a queue matching a specific queue family

func (*Device) LoadShaderModuleFromFile

func (d *Device) LoadShaderModuleFromFile(file string) (*ShaderModule, error)

func (*Device) NewDescriptorPool

func (d *Device) NewDescriptorPool() *DescriptorPool

func (*Device) NewDescriptorSet

func (d *Device) NewDescriptorSet() *DescriptorSet

func (*Device) NewDescriptorSetLayout

func (d *Device) NewDescriptorSetLayout() *DescriptorSetLayout

func (*Device) String

func (d *Device) String() string

String is a stringer interface for the device

func (*Device) VKCreateFence

func (d *Device) VKCreateFence(signaled bool) (vk.Fence, error)

func (*Device) VKCreateSemaphore

func (d *Device) VKCreateSemaphore() (vk.Semaphore, error)

VKCreateSemaphore creates a native vulkan semaphore object

func (*Device) VKDestroyFence

func (d *Device) VKDestroyFence(f vk.Fence)

func (*Device) VKDestroySemaphore

func (d *Device) VKDestroySemaphore(s vk.Semaphore)

func (*Device) VKGetFenceStatus

func (d *Device) VKGetFenceStatus(f vk.Fence) vk.Result

func (*Device) WaitForFences

func (d *Device) WaitForFences(waitForAll bool, ts time.Duration, fences ...*Fence) error

func (*Device) WaitIdle

func (d *Device) WaitIdle() error

WaitIdle waits until the device is idle

type DeviceMemory

type DeviceMemory struct {
	Device         *Device
	VKDeviceMemory vk.DeviceMemory
	Size           uint64
	MapCount       int32
	Ptr            unsafe.Pointer
}

DeviceMemory maps to Vulkan DeviceMemory and can either be memory on the host or on the device

func (*DeviceMemory) Destroy

func (d *DeviceMemory) Destroy()

Destroy destorys this memory

func (*DeviceMemory) IsMapped

func (d *DeviceMemory) IsMapped() bool

IsMapped returns true if the device memory is currently mapped

func (*DeviceMemory) Map

func (d *DeviceMemory) Map() (unsafe.Pointer, error)

Map will map the entirety of this memory

func (*DeviceMemory) MapCopyUnmap

func (d *DeviceMemory) MapCopyUnmap(data []byte) error

MapCopyUnmap will map this memory, copy the specified data to it and unmap

func (*DeviceMemory) MapWithOffset

func (d *DeviceMemory) MapWithOffset(size uint64, offset uint64) (unsafe.Pointer, error)

MapWithOffset will map the memory with a certain size and offset

func (*DeviceMemory) MapWithSize

func (d *DeviceMemory) MapWithSize(size int) (unsafe.Pointer, error)

MapWithSize will map this memory starting at offset 0 with a particular size

func (*DeviceMemory) Unmap

func (d *DeviceMemory) Unmap()

Unmap this memory

type Fence

type Fence struct {
	Device  *Device
	VKFence vk.Fence
}

func (*Fence) Destroy

func (f *Fence) Destroy()

type GraphicsApp

type GraphicsApp struct {
	Instance *Instance
	App      *App

	Window    *glfw.Window
	VKSurface vk.Surface

	Device         *Device
	PhysicalDevice *PhysicalDevice

	CommandBuffers          []*CommandBuffer
	GraphicsPipelineConfigs map[string]IGraphicsPipelineConfig

	// Generated from GraphicsPipelineConfigs
	GraphicsPipelines map[string]vk.Pipeline

	ResourceManager *ResourceManager

	GraphicsQueue *Queue
	PresentQueue  *Queue
	PipelineCache *PipelineCache

	GraphicsCommandPool    *CommandPool
	GraphicsCommandBuffers []*CommandBuffer

	DefaultNumSwapchainImages int

	Swapchain           *Swapchain
	SwapchainImages     []*Image
	SwapchainImageViews []*ImageView
	DepthImage          *ImageResource
	DepthImageView      *ImageView
	Framebuffers        []vk.Framebuffer

	VKRenderPass vk.RenderPass

	// ConfigureRenderPass is a call back which can be supplied to
	// allow for custimization of the render pass
	ConfigureRenderPass func(renderPass vk.RenderPassCreateInfo)
	MakeCommandBuffer   func(command *CommandBuffer, frame int)
	// contains filtered or unexported fields
}

GraphicsApp is a utility object which implements many of the core requirements to get to a functioning Vulkan app. It will setup the appropriate devices and do many of the necissary preprations to begin drawing.

See https://vulkan-tutorial.com/ for a good walkthrough of what this code does.

func NewGraphicsApp

func NewGraphicsApp(name string, version Version) (*GraphicsApp, error)

NewGraphicsApp creates a new graphics app with the given name and version

func (*GraphicsApp) AddGraphicsPipelineConfig

func (p *GraphicsApp) AddGraphicsPipelineConfig(name string, config IGraphicsPipelineConfig)

AddGraphicsPipelineConfig adds this graphic pipeline config back into the app

func (*GraphicsApp) CreateGraphicsPipelineConfig

func (p *GraphicsApp) CreateGraphicsPipelineConfig() *GraphicsPipelineConfig

CreateGraphicsPipelineConfig creates a graphic pipeline configuration for customization

func (*GraphicsApp) Destroy

func (p *GraphicsApp) Destroy()

Destroy tears down the graphics application

func (*GraphicsApp) DrawFrameSync

func (p *GraphicsApp) DrawFrameSync() error

DrawFrameSync draws one frame at a time to the GPU it does not utilize the GPU particularly well but simplifies application development because it insures that resources utilized by the created command buffers are not also utilized currently by the GPU. The specified call back is utilized to populate the command buffer.

The 'frame' parameter is provided so that the application may utilize multiple buffers if desired, although it should not be needed with this frame drawing method

See https://vulkan-tutorial.com/Uniform_buffers/Descriptor_layout_and_buffer for a discussion of how memory usage and frame drawing might require a more complex resource allocation approach

func (*GraphicsApp) EnableDebugging

func (p *GraphicsApp) EnableDebugging() bool

EnableDebugging enables a list of commonly used debugging layers

func (*GraphicsApp) EnableExtension

func (p *GraphicsApp) EnableExtension(extension string) bool

EnableExtension enables a specific extension

func (*GraphicsApp) EnableLayer

func (p *GraphicsApp) EnableLayer(layer string) bool

EnableLayer enables a specific layer of the code

func (*GraphicsApp) GetScreenExtent

func (p *GraphicsApp) GetScreenExtent() vk.Extent2D

GetScreenExtent gets the current screen extents

func (*GraphicsApp) Init

func (p *GraphicsApp) Init() error

Init initializes the graphics app

func (*GraphicsApp) NumFramebuffers

func (p *GraphicsApp) NumFramebuffers() int

NumFramebuffers returns the number of framebuffers that have been created

func (*GraphicsApp) PhysicalDevices

func (p *GraphicsApp) PhysicalDevices() ([]*PhysicalDevice, error)

PhysicalDevices returns a list of physical devices

func (*GraphicsApp) PrepareToDraw

func (p *GraphicsApp) PrepareToDraw() error

PrepareToDraw creates the nescissary objects required to start drawing, it must be called after Init is called and after MakeCommandBuffers is set

func (*GraphicsApp) Resize

func (p *GraphicsApp) Resize()

Resize is used to signal that we need to resize

func (*GraphicsApp) SetWindow

func (p *GraphicsApp) SetWindow(window *glfw.Window) error

SetWindow sets the GLFW window for the graphics app

func (*GraphicsApp) SupportedExtensions

func (p *GraphicsApp) SupportedExtensions() ([]string, error)

SupportedExtensions returns alist of supported extensions

func (*GraphicsApp) SupportedLayers

func (p *GraphicsApp) SupportedLayers() ([]string, error)

SupportedLayers returns a list of supported layers

func (*GraphicsApp) VKRenderPassCreateInfo

func (p *GraphicsApp) VKRenderPassCreateInfo() vk.RenderPassCreateInfo

VKRenderPassCreateInfo is a utility function which creates the render pass info, the implementing application can implement the ConfigureRenderPass function to customize the render pass

type GraphicsPipelineConfig

type GraphicsPipelineConfig struct {
	Device               *Device
	ShaderStages         []vk.PipelineShaderStageCreateInfo
	VertexSource         VertexSourcer
	DescriptorSetLayouts []*DescriptorSetLayout

	PipelineLayout *PipelineLayout

	// Called as the last step in config generation to allow for
	// additional configuration
	Configure func(config vk.GraphicsPipelineCreateInfo)

	// PrimativeTopology see https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkPrimitiveTopology.html
	// defaults to VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
	PrimitiveTopology vk.PrimitiveTopology

	// PrimativeRestartEnable see https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkPipelineInputAssemblyStateCreateInfo.html
	// defaults to False
	PrimitiveRestartEnable vk.Bool32

	// PolygonMode see https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkPolygonMode.html
	// defaults to VK_POLYGON_MODE_FILL
	PolygonMode vk.PolygonMode

	// LineWidth of rasterized lines see https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkPipelineRasterizationStateCreateInfo.html
	// defaults to 1.0
	LineWidth float32

	// CullModes specifies which triangles will be culled. See https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkCullModeFlagBits
	// Defaults to vk.CullModeBackBit
	CullMode vk.CullModeFlagBits

	// DynamicState specifies which part of the pipeline might be modified by the command buffer see
	// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkDynamicState
	// defaults to none
	DynamicState []vk.DynamicState

	// FrontFace specifies how the front face of a triangle is determined, see https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFrontFace
	// defaults to vk.FrontFaceCounterClockwise
	FrontFace vk.FrontFace

	// Add a pipeline color blend attachment state, by default it's assumed that all colors are set to no blending
	// see https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkPipelineColorBlendAttachmentState.html
	BlendAttachments []vk.PipelineColorBlendAttachmentState

	// DepthTestEnable defaults to true
	DepthTestEnable bool

	// DepthWriteEnable defaults to true
	DepthWriteEnable bool

	VertexInputBindingDescriptions   []vk.VertexInputBindingDescription
	VertexInputAttributeDescriptions []vk.VertexInputAttributeDescription

	Viewport *vk.Viewport
	// contains filtered or unexported fields
}

GraphicsPipelineConfig is a utility object to ease construction of graphics pipelines

func (*GraphicsPipelineConfig) AddBlendAttachment

AddBlendAttachment adds a new blend attachment

func (*GraphicsPipelineConfig) AddDescriptorSetLayout

func (g *GraphicsPipelineConfig) AddDescriptorSetLayout(d *DescriptorSetLayout) *GraphicsPipelineConfig

AddDescriptorSetLayout adds a specific DescriptorSetLayout

func (*GraphicsPipelineConfig) AddShaderStageFromFile

func (g *GraphicsPipelineConfig) AddShaderStageFromFile(file, entryPoint string, stageType vk.ShaderStageFlagBits) error

AddShaderStageFromFile adds a shader from a specified file

func (*GraphicsPipelineConfig) AddVertexDescriptor

AddVertexDescriptor adds vertex descriptors based off the specified interface

func (*GraphicsPipelineConfig) Destroy

func (g *GraphicsPipelineConfig) Destroy()

func (*GraphicsPipelineConfig) SetCullMode

SetCullMode sets the cull mode

func (*GraphicsPipelineConfig) SetDynamicState

func (g *GraphicsPipelineConfig) SetDynamicState(states ...vk.DynamicState) *GraphicsPipelineConfig

SetDynamicState specifies which part of the pipeline may be changed with command buffer commands

func (*GraphicsPipelineConfig) SetPipelineLayout

func (g *GraphicsPipelineConfig) SetPipelineLayout(layout *PipelineLayout) *GraphicsPipelineConfig

SetPipelineLayout sets the pipeline layout

func (*GraphicsPipelineConfig) SetShaderStages

SetShaderStages sets the shader stages directly

func (*GraphicsPipelineConfig) VKGraphicsPipelineCreateInfo

func (g *GraphicsPipelineConfig) VKGraphicsPipelineCreateInfo(extent vk.Extent2D) (vk.GraphicsPipelineCreateInfo, error)

VKGraphicsPipelineCreateInfo uses the provided config information to create a vulkank vk.GraphicsPipelineCreateInfo structure

type IAllocatedItem

type IAllocatedItem interface {
	Destroy()
	String() string
}

type IAllocator

type IAllocator interface {
	Free(a *Allocation)
	Allocate(size uint64, align uint64) *Allocation
	Allocations() []*Allocation
	DestroyContents()
	LogDetails()
}

IAllocator is an interface for generic memroy allocation, it can be utilized to provide a more powerful allocation capability than the currently implemented linear allocator Allocater

type IDestructable

type IDestructable interface {
	Destroy()
}

Destroyer

type IGraphicsPipelineConfig

type IGraphicsPipelineConfig interface {
	VKGraphicsPipelineCreateInfo(screenExtents vk.Extent2D) (vk.GraphicsPipelineCreateInfo, error)
	Destroy()
}

GraphicsPipelineConfigurer

type Image

type Image struct {
	Device   *Device
	VKImage  vk.Image
	VKFormat vk.Format
	Size     uint64
	Extent   vk.Extent2D
}

Image is analogous to a buffer, it is essentially a designation that a resource is an image.

func (*Image) CreateImageView

func (i *Image) CreateImageView() (*ImageView, error)

func (*Image) CreateImageViewWithAspectMask

func (i *Image) CreateImageViewWithAspectMask(mask vk.ImageAspectFlags) (*ImageView, error)

func (*Image) Destroy

func (d *Image) Destroy()

Destroy destroys the image

func (*Image) VKMemoryRequirements

func (d *Image) VKMemoryRequirements() vk.MemoryRequirements

VKMemoryRequirements return the memory requirements for the images

type ImageResource

type ImageResource struct {
	Image
	ResourcePool    *ImageResourcePool
	Allocation      *Allocation
	StagingResource *BufferResource
	// Does this resource have it's own pool it is responsible for?
	IndividualPool bool
}

func (*ImageResource) AllocateStagingResource

func (r *ImageResource) AllocateStagingResource() error

AllocateStagingResource will allocate an apporpriate resource which can be used for staging this resource. Once allocated it must be explicitly free'd. The staging resource is allocated from a resource pool called 'staging', which the program must create

func (*ImageResource) Bytes

func (r *ImageResource) Bytes() ([]byte, error)

Bytes returns a byte slice representing the mapped memory, which can be read from or copied to

func (*ImageResource) Destroy

func (r *ImageResource) Destroy()

func (*ImageResource) Free

func (r *ImageResource) Free()

Free this resource and it's associated resources

func (*ImageResource) FreeStagingResource

func (r *ImageResource) FreeStagingResource()

FreeStagingResource will free the staged resource associated with this resource

func (*ImageResource) RequiresStaging

func (r *ImageResource) RequiresStaging() bool

RequiresStaging indicates that this particular buffer resource must be staged before it can be used

func (*ImageResource) String

func (r *ImageResource) String() string

type ImageResourcePool

type ImageResourcePool struct {
	Device           *Device
	Name             string
	Usage            vk.ImageUsageFlagBits
	Sharing          vk.SharingMode
	MemoryProperties vk.MemoryPropertyFlagBits
	Size             uint64
	Allocator        IAllocator
	Memory           *DeviceMemory
	NeedsStaging     bool
	ResourceManager  *ResourceManager
}

func (*ImageResourcePool) AllocateImage

func (p *ImageResourcePool) AllocateImage(extent vk.Extent2D, format vk.Format, tiling vk.ImageTiling, usage vk.ImageUsageFlagBits) (*ImageResource, error)

func (*ImageResourcePool) Destroy

func (p *ImageResourcePool) Destroy()

func (*ImageResourcePool) LogDetails

func (p *ImageResourcePool) LogDetails()

func (*ImageResourcePool) StageTextureFromDisk

func (p *ImageResourcePool) StageTextureFromDisk(filename string, cmd *CommandBuffer, queue *Queue) (*ImageResource, error)

func (*ImageResourcePool) StageTextureFromImage

func (p *ImageResourcePool) StageTextureFromImage(srcImg *image.RGBA, cmd *CommandBuffer, queue *Queue) (*ImageResource, error)

type ImageView

type ImageView struct {
	Device      *Device
	VKImageView vk.ImageView
}

func (*ImageView) Destroy

func (i *ImageView) Destroy()

type IndexSliceUint16

type IndexSliceUint16 []uint16

func (IndexSliceUint16) Bytes

func (i IndexSliceUint16) Bytes() []byte

func (IndexSliceUint16) IndexType

func (i IndexSliceUint16) IndexType() vk.IndexType

type IndexSliceUint32

type IndexSliceUint32 []uint16

func (IndexSliceUint32) Bytes

func (i IndexSliceUint32) Bytes() []byte

func (IndexSliceUint32) IndexType

func (i IndexSliceUint32) IndexType() vk.IndexType

type IndexSourcer

type IndexSourcer interface {
	ByteSourcer
	IndexType() vk.IndexType
}

type Instance

type Instance struct {
	//VKInstance is the native Vulkan instance object
	VKInstance vk.Instance
}

Instance is an instance of the Vulkan subsystem

func (*Instance) Destroy

func (i *Instance) Destroy() error

func (*Instance) PhysicalDevices

func (i *Instance) PhysicalDevices() ([]*PhysicalDevice, error)

PhysicalDevices returns a list of physical devices known to Vulkan

func (*Instance) SetDebugCallback

func (i *Instance) SetDebugCallback(callback vk.DebugReportCallbackFunc) error

func (*Instance) UseDefaultDebugCallback

func (i *Instance) UseDefaultDebugCallback()

type LinearAllocator

type LinearAllocator struct {
	Size uint64
	// contains filtered or unexported fields
}

LinearAllocator is a basic linear allocator for memory, it simply allocates blocks of memory and will return the first allocation that that fits the request, it's not ideal, but works.

func (*LinearAllocator) Allocate

func (p *LinearAllocator) Allocate(size uint64, align uint64) *Allocation

Allocate a new hunk of memory

func (*LinearAllocator) Allocations

func (p *LinearAllocator) Allocations() []*Allocation

func (*LinearAllocator) DestroyContents

func (p *LinearAllocator) DestroyContents()

func (*LinearAllocator) Free

func (p *LinearAllocator) Free(fa *Allocation)

Free the specified allocation

func (*LinearAllocator) LogDetails

func (p *LinearAllocator) LogDetails()

func (*LinearAllocator) String

func (p *LinearAllocator) String() string

String for stringer interface

type MappedMemoryRange

type MappedMemoryRange interface {
	VKMappedMemoryRange() vk.MappedMemoryRange
}

type MemoryTypeSlice

type MemoryTypeSlice []vk.MemoryType

func (MemoryTypeSlice) Filter

func (m MemoryTypeSlice) Filter(f func(properties vk.MemoryPropertyFlagBits) bool) MemoryTypeSlice

func (MemoryTypeSlice) NumHostCoherent

func (m MemoryTypeSlice) NumHostCoherent() int

func (MemoryTypeSlice) NumHostVisible

func (m MemoryTypeSlice) NumHostVisible() int

func (MemoryTypeSlice) NumHostVisibleAndCoherent

func (m MemoryTypeSlice) NumHostVisibleAndCoherent() int

type PhysicalDevice

type PhysicalDevice struct {
	DeviceName                 string
	VKPhysicalDevice           vk.PhysicalDevice
	VKPhysicalDeviceProperties vk.PhysicalDeviceProperties
}

func (*PhysicalDevice) CreateLogicalDevice

func (p *PhysicalDevice) CreateLogicalDevice(qfs QueueFamilySlice) (*Device, error)

func (*PhysicalDevice) CreateLogicalDeviceWithOptions

func (p *PhysicalDevice) CreateLogicalDeviceWithOptions(qfs QueueFamilySlice, options *CreateDeviceOptions) (*Device, error)

func (*PhysicalDevice) FindMemoryType

func (p *PhysicalDevice) FindMemoryType(memoryTypeBits uint32, properties vk.MemoryPropertyFlagBits) (uint32, error)

func (*PhysicalDevice) GetSurfaceCapabilities

func (p *PhysicalDevice) GetSurfaceCapabilities(surface vk.Surface) (*vk.SurfaceCapabilities, error)

func (*PhysicalDevice) GetSurfaceFormats

func (p *PhysicalDevice) GetSurfaceFormats(surface vk.Surface) (VKSurfaceFormats, error)

func (*PhysicalDevice) GetSurfacePresentModes

func (p *PhysicalDevice) GetSurfacePresentModes(surface vk.Surface) (VKPresentModes, error)

func (*PhysicalDevice) MemoryTypes

func (p *PhysicalDevice) MemoryTypes() []vk.MemoryType

func (*PhysicalDevice) QueueFamilies

func (p *PhysicalDevice) QueueFamilies() (QueueFamilySlice, error)

func (*PhysicalDevice) String

func (p *PhysicalDevice) String() string

func (*PhysicalDevice) SupportedExtensions

func (p *PhysicalDevice) SupportedExtensions() ([]vk.ExtensionProperties, error)

func (*PhysicalDevice) VKPhysicalDeviceFeatures

func (p *PhysicalDevice) VKPhysicalDeviceFeatures() vk.PhysicalDeviceFeatures

func (*PhysicalDevice) VKPhysicalDeviceMemoryProperties

func (p *PhysicalDevice) VKPhysicalDeviceMemoryProperties() vk.PhysicalDeviceMemoryProperties

type PipelineCache

type PipelineCache struct {
	Device          *Device
	VKPipelineCache vk.PipelineCache
}

func (*PipelineCache) Destroy

func (c *PipelineCache) Destroy()

type PipelineLayout

type PipelineLayout struct {
	Device           *Device
	VKPipelineLayout vk.PipelineLayout
}

func (*PipelineLayout) Destroy

func (p *PipelineLayout) Destroy()

type Queue

type Queue struct {
	Device      *Device
	QueueFamily *QueueFamily
	VKQueue     vk.Queue
}

func (*Queue) String

func (q *Queue) String() string

func (*Queue) SubmitWaitIdle

func (q *Queue) SubmitWaitIdle(buffers ...*CommandBuffer) error

func (*Queue) SubmitWithFence

func (q *Queue) SubmitWithFence(fence *Fence, buffers ...*CommandBuffer) error

func (*Queue) WaitIdle

func (q *Queue) WaitIdle() error

type QueueFamily

type QueueFamily struct {
	Index                   int
	PhysicalDevice          *PhysicalDevice
	VKQueueFamilyProperties vk.QueueFamilyProperties
}

func (*QueueFamily) IsCompute

func (q *QueueFamily) IsCompute() bool

func (*QueueFamily) IsGraphics

func (q *QueueFamily) IsGraphics() bool

func (*QueueFamily) IsTransfer

func (q *QueueFamily) IsTransfer() bool

func (*QueueFamily) String

func (q *QueueFamily) String() string

func (*QueueFamily) SupportsPresent

func (q *QueueFamily) SupportsPresent(surface vk.Surface) bool

type QueueFamilySlice

type QueueFamilySlice []*QueueFamily

func (QueueFamilySlice) Filter

func (ql QueueFamilySlice) Filter(f func(q *QueueFamily) bool) QueueFamilySlice

func (QueueFamilySlice) FilterCompute

func (ql QueueFamilySlice) FilterCompute() QueueFamilySlice

func (QueueFamilySlice) FilterGraphics

func (ql QueueFamilySlice) FilterGraphics() QueueFamilySlice

func (QueueFamilySlice) FilterGraphicsAndPresent

func (ql QueueFamilySlice) FilterGraphicsAndPresent(surface vk.Surface) QueueFamilySlice

func (QueueFamilySlice) FilterPresent

func (ql QueueFamilySlice) FilterPresent(surface vk.Surface) QueueFamilySlice

func (QueueFamilySlice) FilterTransfer

func (ql QueueFamilySlice) FilterTransfer() QueueFamilySlice

type ResourceManager

type ResourceManager struct {
	Device *Device
	// contains filtered or unexported fields
}

func (*ResourceManager) AllocateBufferPoolWithOptions

func (r *ResourceManager) AllocateBufferPoolWithOptions(name string, size uint64, mprops vk.MemoryPropertyFlagBits, usage vk.BufferUsageFlagBits, sharing vk.SharingMode) (*BufferResourcePool, error)

func (*ResourceManager) AllocateDeviceTexturePool

func (r *ResourceManager) AllocateDeviceTexturePool(name string, size uint64) (*ImageResourcePool, error)

func (*ResourceManager) AllocateHostVertexAndIndexBufferPool

func (r *ResourceManager) AllocateHostVertexAndIndexBufferPool(name string, size uint64) (*BufferResourcePool, error)

func (*ResourceManager) AllocateImagePoolWithOptions

func (r *ResourceManager) AllocateImagePoolWithOptions(name string, size uint64, mprops vk.MemoryPropertyFlagBits, usage vk.ImageUsageFlagBits, sharing vk.SharingMode) (*ImageResourcePool, error)

func (*ResourceManager) AllocateStagingPool

func (r *ResourceManager) AllocateStagingPool(size uint64) (*BufferResourcePool, error)

func (*ResourceManager) BufferPool

func (r *ResourceManager) BufferPool(name string) *BufferResourcePool

func (*ResourceManager) Destroy

func (r *ResourceManager) Destroy()

func (*ResourceManager) GetStagingPool

func (r *ResourceManager) GetStagingPool() *BufferResourcePool

func (*ResourceManager) HasStagingPool

func (r *ResourceManager) HasStagingPool() bool

func (*ResourceManager) ImagePool

func (r *ResourceManager) ImagePool(name string) *ImageResourcePool

func (*ResourceManager) LogDetails

func (r *ResourceManager) LogDetails()

func (*ResourceManager) NewImageResourceWithOptions

func (r *ResourceManager) NewImageResourceWithOptions(extent vk.Extent2D, format vk.Format, tiling vk.ImageTiling, usage vk.ImageUsageFlagBits, sharing vk.SharingMode, mprops vk.MemoryPropertyFlagBits) (*ImageResource, error)

NewImageResourceWithOptions will create a image resource which has it's own exclusive pool

type ShaderModule

type ShaderModule struct {
	Device         *Device
	Description    string
	VKShaderModule vk.ShaderModule
}

func (*ShaderModule) Destroy

func (s *ShaderModule) Destroy()

func (*ShaderModule) VKPipelineShaderStageCreateInfo

func (s *ShaderModule) VKPipelineShaderStageCreateInfo(stage vk.ShaderStageFlagBits, entryPoint string) vk.PipelineShaderStageCreateInfo

type Swapchain

type Swapchain struct {
	Extent      vk.Extent2D
	Format      vk.Format
	Device      *Device
	VKSwapchain vk.Swapchain
}

func (*Swapchain) Destroy

func (s *Swapchain) Destroy()

func (*Swapchain) GetImages

func (s *Swapchain) GetImages() ([]*Image, error)

type UpdateFrequencyType

type UpdateFrequencyType int
const (
	// If this object is put into device memory it will be tossed from host memory?
	Once UpdateFrequencyType = iota
	// We will potentialy pause the draw frame to update this
	Occasionally
	// We will assume this item needs to be updated almost every frame
	Frequently
)

type VKBufferProvider

type VKBufferProvider interface {
	GetVKBufer() vk.Buffer
}

type VKImageProvider

type VKImageProvider interface {
	GetVKImage() vk.Image
}

type VKPresentModes

type VKPresentModes []vk.PresentMode

func (VKPresentModes) Filter

type VKSurfaceFormats

type VKSurfaceFormats []vk.SurfaceFormat

func (VKSurfaceFormats) Filter

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version is used to specify versions of components

func (*Version) VKVersion

func (v *Version) VKVersion() uint32

VKVersion returns a Vulkan compatible version representation

type VertexDescriptor

type VertexDescriptor interface {
	GetBindingDescription() vk.VertexInputBindingDescription
	GetAttributeDescriptions() []vk.VertexInputAttributeDescription
}

type VertexSourcer

type VertexSourcer interface {
	ByteSourcer
	VertexDescriptor
}

Directories

Path Synopsis
examples
sdf

Jump to

Keyboard shortcuts

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