Documentation
¶
Overview ¶
Package render is the Vulkan backend: instance, device, swapchain, frame pacing, resource uploads and readback. It knows nothing about windows beyond a VkSurfaceKHR handed to it, and nothing about what is drawn.
Index ¶
- Constants
- Variables
- func BeginTargetPass(cb vk.VkCommandBuffer, p PassDesc)
- func ClearColorForSampling(cb vk.VkCommandBuffer, img *Image)
- func ClearDepthForSampling(cb vk.VkCommandBuffer, depth *Image)
- func ClearRect(cb vk.VkCommandBuffer, r vk.VkRect2D, color [4]float32)
- func CopyColorForSampling(cb vk.VkCommandBuffer, src, dst *Image)
- func CubemapData(size uint32, texelBytes int, faces [][6][]byte) ([]byte, error)
- func EndTargetPass(cb vk.VkCommandBuffer, t *Target)
- func EndTargetPassDesc(cb vk.VkCommandBuffer, p PassDesc)
- func HasStencil(f vk.VkFormat) bool
- func HeadlessSurfaceExtensions() []string
- func MipLevels(extent vk.VkExtent2D) uint32
- func NewHeadlessSurface(instance vk.VkInstance) (vk.VkSurfaceKHR, error)
- func RecordBufferUpload(cb vk.VkCommandBuffer, dst, staging *Buffer, offset, size vk.VkDeviceSize)
- func RecordCubemapUpload(cb vk.VkCommandBuffer, img *Image, texelBytes int, staging *Buffer, ...)
- func RecordImageCopy(cb vk.VkCommandBuffer, src, dst *Image, rect image.Rectangle, ...)
- func RecordImageReadback(cb vk.VkCommandBuffer, img *Image, buf *Buffer, offset vk.VkDeviceSize)
- func RecordImageUpload(cb vk.VkCommandBuffer, img *Image, staging *Buffer, offset vk.VkDeviceSize)
- func RecordImageWrite(cb vk.VkCommandBuffer, img *Image, x, y, w, h int, staging *Buffer, ...)
- func RecordLevelsUpload(cb vk.VkCommandBuffer, img *Image, staging *Buffer, levels []LevelCopy)
- func SetScissor(cb vk.VkCommandBuffer, extent vk.VkExtent2D, x, y int32, w, h uint32, ...)
- func SetScissorRect(cb vk.VkCommandBuffer, r vk.VkRect2D)
- func SetViewport(cb vk.VkCommandBuffer, extent vk.VkExtent2D)
- func SetViewportRect(cb vk.VkCommandBuffer, r vk.VkRect2D)
- type AllocStats
- type Arena
- type BlendFactors
- type Buffer
- type ColorAttachment
- type Config
- type DescriptorBinding
- type DescriptorSets
- func (ds *DescriptorSets) Allocate(view vk.VkImageView, sampler vk.VkSampler) (vk.VkDescriptorSet, error)
- func (ds *DescriptorSets) AllocateBuffer(buf *Buffer, size vk.VkDeviceSize) (vk.VkDescriptorSet, error)
- func (ds *DescriptorSets) AllocateMany(bindings []SamplerBinding) (vk.VkDescriptorSet, error)
- func (ds *DescriptorSets) Destroy()
- func (ds *DescriptorSets) Free(set vk.VkDescriptorSet)
- func (ds *DescriptorSets) Update(set vk.VkDescriptorSet, bindings []SamplerBinding)
- type Device
- func (d *Device) DepthClamp() bool
- func (d *Device) Destroy()
- func (d *Device) FlushUploads() error
- func (d *Device) IndependentBlend() bool
- func (d *Device) Limits() *vk.VkPhysicalDeviceLimits
- func (d *Device) MaxSamples() int
- func (d *Device) NewBuffer(size vk.VkDeviceSize, usage vk.VkBufferUsageFlags, ...) (*Buffer, error)
- func (d *Device) NewCubemapImage(size uint32, format vk.VkFormat, texelBytes int, faces [][6][]byte) (*Image, error)
- func (d *Device) NewCubemapImageEmpty(size uint32, format vk.VkFormat, mips uint32) (*Image, error)
- func (d *Device) NewDescriptors(bindings []DescriptorBinding, capacity uint32) (*DescriptorSets, error)
- func (d *Device) NewDeviceBuffer(size vk.VkDeviceSize, usage vk.VkBufferUsageFlags) (*Buffer, error)
- func (d *Device) NewDeviceLocalBuffer(data []byte, usage vk.VkBufferUsageFlags) (*Buffer, error)
- func (d *Device) NewDynamicUniforms(blockRange vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*DynamicUniforms, error)
- func (d *Device) NewFrameSets(size, storageSize vk.VkDeviceSize, fixed []vk.VkDeviceSize, ...) (*UniformSets, error)
- func (d *Device) NewImage(extent vk.VkExtent2D, format vk.VkFormat, usage vk.VkImageUsageFlags, ...) (*Image, error)
- func (d *Device) NewImageMips(extent vk.VkExtent2D, format vk.VkFormat, usage vk.VkImageUsageFlags, ...) (*Image, error)
- func (d *Device) NewImageSamples(extent vk.VkExtent2D, format vk.VkFormat, usage vk.VkImageUsageFlags, ...) (*Image, error)
- func (d *Device) NewImmutableSamplerDescriptors(bindings int, capacity uint32, sampler vk.VkSampler) (*DescriptorSets, error)
- func (d *Device) NewLevelledImage(extent vk.VkExtent2D, format vk.VkFormat, mips uint32) (*Image, error)
- func (d *Device) NewLevelledTextureImage(extent vk.VkExtent2D, format vk.VkFormat, data []byte, levels []LevelCopy) (*Image, error)
- func (d *Device) NewPipeline(desc PipelineDesc) (*Pipeline, error)
- func (d *Device) NewSampledImage(extent vk.VkExtent2D, format vk.VkFormat, mipmaps bool) (*Image, error)
- func (d *Device) NewSampler(linear bool) (vk.VkSampler, error)
- func (d *Device) NewSamplerDescriptors(bindings int, capacity uint32) (*DescriptorSets, error)
- func (d *Device) NewSamplerRepeat(linear, repeat bool) (vk.VkSampler, error)
- func (d *Device) NewShadowSampler() (vk.VkSampler, error)
- func (d *Device) NewStaging() *Staging
- func (d *Device) NewStorageSets(size vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*StorageSets, error)
- func (d *Device) NewSwapchain(surface vk.VkSurfaceKHR, fallback vk.VkExtent2D, vsync bool) (*Swapchain, error)
- func (d *Device) NewTarget(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
- func (d *Device) NewTargetCopyable(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
- func (d *Device) NewTargetDesc(desc TargetDesc) (*Target, error)
- func (d *Device) NewTargetReadable(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
- func (d *Device) NewTargetSampled(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
- func (d *Device) NewTextureDescriptors(capacity uint32) (*DescriptorSets, error)
- func (d *Device) NewTextureImage(extent vk.VkExtent2D, format vk.VkFormat, pixels []byte, mipmaps bool) (*Image, error)
- func (d *Device) NewTimestamps() *Timestamps
- func (d *Device) NewUniformSets(size vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*UniformSets, error)
- func (d *Device) NewUniformStorageSets(size, storageSize vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*UniformSets, error)
- func (d *Device) OneShot(record func(cb vk.VkCommandBuffer)) error
- func (d *Device) Physical() vk.VkPhysicalDevice
- func (d *Device) ReadDepth(img *Image) ([]float32, error)
- func (d *Device) ReadImage(img *Image) (*image.RGBA, error)
- func (d *Device) ReadImageRaw(img *Image, texelBytes int) ([]byte, error)
- func (d *Device) Retire(fn func())
- func (d *Device) RetireBuffers(bufs [FramesInFlight]*Buffer)
- func (d *Device) SampleCount(n int) vk.VkSampleCountFlagBits
- func (d *Device) ShadowFormat(fallback vk.VkFormat) vk.VkFormat
- func (d *Device) StageUpload(size vk.VkDeviceSize) (*Buffer, vk.VkDeviceSize, []byte, error)
- func (d *Device) Stats() AllocStats
- func (d *Device) SupportsFormat(f vk.VkFormat) bool
- func (d *Device) UploadCommands() (vk.VkCommandBuffer, error)
- func (d *Device) WaitIdle() error
- func (d *Device) Waits() uint64
- func (d *Device) WriteImage(img *Image, x, y, w, h int, pixels []byte) error
- type DynamicUniforms
- type Frame
- type Image
- type Instance
- type LevelCopy
- type PassDesc
- type Pipeline
- type PipelineDesc
- type Renderer
- func (r *Renderer) BeginFrame() (*Frame, bool, error)
- func (r *Renderer) BeginSwapchainPass(fr *Frame, clear [4]float32)
- func (r *Renderer) Destroy()
- func (r *Renderer) EndFrame(fr *Frame, capture bool) (*image.RGBA, error)
- func (r *Renderer) NewOutput(surfaceExts []string, makeSurface SurfaceFunc, extent vk.VkExtent2D, ...) (*Renderer, error)
- func (r *Renderer) OnResize(fn func(extent vk.VkExtent2D) error)
- func (r *Renderer) Resize(width, height int)
- type SamplerBinding
- type Span
- type Staging
- type StencilState
- type StorageSets
- type SurfaceFunc
- type Swapchain
- type Target
- type TargetDesc
- type Timestamps
- type UniformSets
Constants ¶
const FramesInFlight = 2
FramesInFlight is how many frames the CPU may record ahead of the GPU. Per-frame resources such as instance buffers need one copy each.
Variables ¶
var ErrDeviceLost = errors.New("render: device lost")
ErrDeviceLost reports that the GPU was reset; the renderer and every resource created from it must be rebuilt.
var PremultipliedOver = BlendFactors{ SrcColor: vk.VK_BLEND_FACTOR_ONE, DstColor: vk.VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, ColorOp: vk.VK_BLEND_OP_ADD, SrcAlpha: vk.VK_BLEND_FACTOR_ONE, DstAlpha: vk.VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, AlphaOp: vk.VK_BLEND_OP_ADD, }
PremultipliedOver is source-over blending for premultiplied colour.
Functions ¶
func BeginTargetPass ¶
func BeginTargetPass(cb vk.VkCommandBuffer, p PassDesc)
BeginTargetPass transitions the target's images for rendering and opens a dynamic-rendering pass. The colour image ends in colour-attachment layout and the depth image in depth-attachment layout; EndTargetPass moves both to shader-read-only so the next pass can sample them.
A multisampled target renders into MSColor and MSDepth and resolves into Color and Depth as the pass ends: colour by averaging the samples, depth by taking sample zero, which every device supports and which costs nothing beyond the resolve the colour attachment already needs. The passes that read the scene depth afterwards (ambient occlusion, decals, the transmission snapshot) therefore see one exact sample per pixel rather than a blend of unrelated depths.
func ClearColorForSampling ¶
func ClearColorForSampling(cb vk.VkCommandBuffer, img *Image)
ClearColorForSampling clears a colour image (every mip level) to black and leaves it in shader-read-only layout, so it can be sampled before its first pass.
func ClearDepthForSampling ¶
func ClearDepthForSampling(cb vk.VkCommandBuffer, depth *Image)
ClearDepthForSampling clears a depth image to 1 (nothing occluded) and leaves it in shader-read-only layout, for shadow maps that are bound before any shadow pass has run.
func ClearRect ¶
func ClearRect(cb vk.VkCommandBuffer, r vk.VkRect2D, color [4]float32)
ClearRect fills a rectangle of the pass's colour attachment with a colour, inside the pass.
func CopyColorForSampling ¶
func CopyColorForSampling(cb vk.VkCommandBuffer, src, dst *Image)
CopyColorForSampling copies a colour image that a finished pass left in shader-read-only layout into dst, fills dst's mip chain with blurred copies, and leaves both readable by shaders. dst may be a different size; the copy is a linear blit.
func CubemapData ¶
CubemapData flattens faces[level][face] into the one blob a staging buffer holds, level by level and face by face, checking each square is size>>level texels of texelBytes each.
func EndTargetPass ¶
func EndTargetPass(cb vk.VkCommandBuffer, t *Target)
EndTargetPass closes the pass and makes the images readable by shaders.
func EndTargetPassDesc ¶
func EndTargetPassDesc(cb vk.VkCommandBuffer, p PassDesc)
EndTargetPassDesc is EndTargetPass for a pass begun with the same description, so a pass without a depth attachment leaves the depth image as it was.
func HasStencil ¶
HasStencil reports whether a depth format carries a stencil aspect.
func HeadlessSurfaceExtensions ¶
func HeadlessSurfaceExtensions() []string
HeadlessSurfaceExtensions lists what a headless renderer needs on the instance: nothing. Headless rendering draws into ordinary images and never creates a surface, so no window system and no surface extension is involved.
func MipLevels ¶
func MipLevels(extent vk.VkExtent2D) uint32
MipLevels is the full mip chain length for an extent.
func NewHeadlessSurface ¶
func NewHeadlessSurface(instance vk.VkInstance) (vk.VkSurfaceKHR, error)
NewHeadlessSurface is the SurfaceFunc for a headless renderer. It returns a zero surface; the renderer then picks any graphics-capable device and builds a headless swapchain of plain images, for tests and offscreen rendering on machines whose driver has no windowed path.
func RecordBufferUpload ¶
func RecordBufferUpload(cb vk.VkCommandBuffer, dst, staging *Buffer, offset, size vk.VkDeviceSize)
RecordBufferUpload records a copy of size bytes from a staging buffer, at offset, into the whole of a device-local buffer, with the barrier that lets a draw recorded later in the same command buffer read it as vertex and index data.
func RecordCubemapUpload ¶
func RecordCubemapUpload(cb vk.VkCommandBuffer, img *Image, texelBytes int, staging *Buffer, offset vk.VkDeviceSize)
RecordCubemapUpload records the fill of a cube map from a staging buffer holding CubemapData at offset, leaving every level and face in shader-read-only layout. texelBytes says how the levels are spaced. The image must still be in undefined layout.
func RecordImageCopy ¶
func RecordImageCopy(cb vk.VkCommandBuffer, src, dst *Image, rect image.Rectangle, point image.Point)
RecordImageCopy copies a validated level-zero region between identical-format single-sample images in shader-read-only layout. It rebuilds destination mips and restores that layout. Same-image regions must not overlap.
func RecordImageReadback ¶
func RecordImageReadback(cb vk.VkCommandBuffer, img *Image, buf *Buffer, offset vk.VkDeviceSize)
RecordImageReadback records a copy of level 0 of a colour image that is in shader-read-only layout into buf at offset, texels packed row after row with no padding, and leaves the image in shader-read-only layout. The barriers order the copy after the passes and reads recorded before it and before any later read of the image, so one command buffer can render an image, copy it out, and render into it again. The bytes are in buf once the command buffer has finished.
func RecordImageUpload ¶
func RecordImageUpload(cb vk.VkCommandBuffer, img *Image, staging *Buffer, offset vk.VkDeviceSize)
RecordImageUpload records the first fill of a sampled image from a staging buffer at offset: the whole of level 0, then the mip chain, leaving every level in shader-read-only layout. The image must still be in undefined layout, which is how NewSampledImage leaves it.
func RecordImageWrite ¶
func RecordImageWrite(cb vk.VkCommandBuffer, img *Image, x, y, w, h int, staging *Buffer, offset vk.VkDeviceSize)
RecordImageWrite records a copy of a staging buffer, from offset, into a rectangle of a sampled image, with the barriers that order it after earlier reads on the queue and before later ones, and rebuilds the mip chain. The image must be in shader-read-only layout, which is where RecordImageUpload leaves it.
func RecordLevelsUpload ¶
func RecordLevelsUpload(cb vk.VkCommandBuffer, img *Image, staging *Buffer, levels []LevelCopy)
RecordLevelsUpload records the fill of every mip level of an image from one staging buffer, leaving the whole chain in shader-read-only layout. The image must still be in undefined layout, which is how NewLevelledImage leaves it, and each level's offset must suit the format's block size, which the caller arranges when it packs them.
func SetScissor ¶
func SetScissor(cb vk.VkCommandBuffer, extent vk.VkExtent2D, x, y int32, w, h uint32, full bool)
SetScissor limits rasterisation to a pixel rectangle clamped to the extent; full resets to the whole extent.
func SetScissorRect ¶
func SetScissorRect(cb vk.VkCommandBuffer, r vk.VkRect2D)
SetScissorRect limits rasterisation to a pixel rectangle.
func SetViewport ¶
func SetViewport(cb vk.VkCommandBuffer, extent vk.VkExtent2D)
SetViewport records a full-extent viewport and scissor. Vulkan's viewport is flipped here so that +Y is down, matching 2D screen conventions.
func SetViewportRect ¶
func SetViewportRect(cb vk.VkCommandBuffer, r vk.VkRect2D)
SetViewportRect sets the viewport to a pixel rectangle.
Types ¶
type AllocStats ¶
type AllocStats struct {
Blocks, Dedicated, Live int
Reserved, Used vk.VkDeviceSize
}
AllocStats reports allocator activity for diagnostics.
type Arena ¶
type Arena struct {
// contains filtered or unexported fields
}
Arena collects uniform blocks on the CPU for one frame, aligned for dynamic offsets.
func (*Arena) Add ¶
Add copies a block in and returns its offset. The padding before the block is zeroed. The storage grows by doubling and is kept across Reset, so a frame of n blocks costs time linear in its size.
type BlendFactors ¶
type BlendFactors struct {
SrcColor, DstColor vk.VkBlendFactor
ColorOp vk.VkBlendOp
SrcAlpha, DstAlpha vk.VkBlendFactor
AlphaOp vk.VkBlendOp
}
BlendFactors is a fixed-function blend equation: colour and alpha are each src·SrcFactor op dst·DstFactor.
type Buffer ¶
type Buffer struct {
Handle vk.VkBuffer
Size vk.VkDeviceSize
Mapped unsafe.Pointer // nil unless host-visible
// contains filtered or unexported fields
}
Buffer is a VkBuffer bound to allocator memory. Most buffers share memory blocks; MoltenVK index buffers use separate allocations at offset zero. Host-visible buffers are mapped for their whole life.
func (*Buffer) Destroy ¶
func (b *Buffer) Destroy()
Destroy frees the buffer. An upload batch still writing it is submitted or finished first.
func (*Buffer) NoteUpload ¶
func (b *Buffer) NoteUpload()
NoteUpload is Image.NoteUpload for a buffer an upload batch writes.
type ColorAttachment ¶
type ColorAttachment struct {
Format vk.VkFormat
Blend bool // blending on; premultiplied source-over unless Factors is set
Factors *BlendFactors // blend equation when Blend is set
}
ColorAttachment is one of a pipeline's colour attachments past the first: the format it writes and how it blends. The fragment shader writes it from the output at the matching location.
type Config ¶
type Config struct {
AppName string
Validation bool // enable VK_LAYER_KHRONOS_validation and debug messages when available
Log *slog.Logger
}
Config selects instance-level behaviour.
type DescriptorBinding ¶
type DescriptorBinding struct {
Type vk.VkDescriptorType
// Count is how many descriptors the binding holds; zero means one.
Count uint32
// Stages is which shader stages see it; zero means the fragment
// stage alone.
Stages vk.VkShaderStageFlags
// Immutable bakes samplers into the layout, so no set ever writes
// them. MoltenVK requires it for comparison samplers, and the mesh
// material set uses it for its shared samplers.
Immutable []vk.VkSampler
}
DescriptorBinding declares one binding of a set layout.
type DescriptorSets ¶
type DescriptorSets struct {
Layout vk.VkDescriptorSetLayout
// contains filtered or unexported fields
}
DescriptorSets hands out sets of a fixed layout of image and sampler bindings. Sets come from a chain of pools: when the current pool is full another of the same capacity is added, so the number of live textures, materials and render textures is bounded by memory rather than by a starting guess.
func (*DescriptorSets) Allocate ¶
func (ds *DescriptorSets) Allocate(view vk.VkImageView, sampler vk.VkSampler) (vk.VkDescriptorSet, error)
Allocate makes a set pointing at view through sampler (one logical texture).
func (*DescriptorSets) AllocateBuffer ¶
func (ds *DescriptorSets) AllocateBuffer(buf *Buffer, size vk.VkDeviceSize) (vk.VkDescriptorSet, error)
AllocateBuffer makes a set whose one binding is the whole of a buffer, for a layout of a single storage buffer made with NewDescriptors. It is what data that never changes after it is uploaded is bound through: one set per buffer, freed with the buffer, rather than one per frame in flight.
func (*DescriptorSets) AllocateMany ¶
func (ds *DescriptorSets) AllocateMany(bindings []SamplerBinding) (vk.VkDescriptorSet, error)
AllocateMany makes a set, adding a pool when the current one is full. Entries name logical texture pairs for NewSamplerDescriptors layouts, or actual bindings for NewDescriptors layouts.
func (*DescriptorSets) Destroy ¶
func (ds *DescriptorSets) Destroy()
func (*DescriptorSets) Free ¶
func (ds *DescriptorSets) Free(set vk.VkDescriptorSet)
Free returns a set to the pool it came from.
func (*DescriptorSets) Update ¶
func (ds *DescriptorSets) Update(set vk.VkDescriptorSet, bindings []SamplerBinding)
Update rewrites a set's bindings, starting at zero. Entries name logical texture pairs for NewSamplerDescriptors layouts, or actual bindings for NewDescriptors layouts. Bindings past the entries given, and bindings of immutable samplers, are left alone. A sampled-image binding takes the entry's view and ignores its sampler.
type Device ¶
type Device struct {
Handle vk.VkDevice
Queue vk.VkQueue
QueueFamily uint32
Name string
// contains filtered or unexported fields
}
Device is a logical device with one graphics+present queue and a command pool for the frame ring. Everything drawn goes through it.
func NewDevice ¶
func NewDevice(inst *Instance, surface vk.VkSurfaceKHR) (*Device, error)
NewDevice picks a GPU able to present to surface and creates the logical device with dynamic rendering and synchronization2 enabled.
func (*Device) DepthClamp ¶
DepthClamp reports whether the device clamps depth for pipelines that ask for it. Without it a pipeline clips at its near and far planes, and the caller compensates.
func (*Device) Destroy ¶
func (d *Device) Destroy()
Destroy releases the device after waiting for it to go idle.
func (*Device) FlushUploads ¶
FlushUploads submits the open upload batch, if there is one, without waiting for it. Work submitted to the queue afterwards sees what the batch wrote. The renderer calls it before submitting a frame, and WaitIdle and OneShot call it before they wait, so a caller only needs it to start the transfers early. It also frees the staging of batches that have finished.
func (*Device) IndependentBlend ¶
IndependentBlend reports whether a pipeline may give each colour attachment its own blend equation. A pipeline whose ExtraColor differs from its first attachment needs it, and the caller falls back to something else where it is missing.
func (*Device) Limits ¶
func (d *Device) Limits() *vk.VkPhysicalDeviceLimits
Limits exposes the physical device limits.
func (*Device) MaxSamples ¶
MaxSamples is the highest sample count the device supports for colour and depth attachments together, one of 1, 2, 4, 8, 16, 32 or 64. It is never below 1: every device supports single-sample rendering.
func (*Device) NewBuffer ¶
func (d *Device) NewBuffer(size vk.VkDeviceSize, usage vk.VkBufferUsageFlags, props vk.VkMemoryPropertyFlags) (*Buffer, error)
NewBuffer creates and binds a buffer. Host-visible buffers are mapped.
func (*Device) NewCubemapImage ¶
func (d *Device) NewCubemapImage(size uint32, format vk.VkFormat, texelBytes int, faces [][6][]byte) (*Image, error)
NewCubemapImage uploads a cube map with mip levels: faces[level][face] holds a square of side size>>level texels in format's layout, faces in Vulkan order (+X, -X, +Y, -Y, +Z, -Z). The image ends in shader-read-only layout with a cube view over every level. It is for uploads outside a frame: the copy goes into the device's upload batch and costs no wait. Inside a frame use NewCubemapImageEmpty, CubemapData and RecordCubemapUpload.
func (*Device) NewCubemapImageEmpty ¶
NewCubemapImageEmpty creates a cube map of mips levels with a cube view over all of them. Its contents are undefined until RecordCubemapUpload fills them.
func (*Device) NewDescriptors ¶
func (d *Device) NewDescriptors(bindings []DescriptorBinding, capacity uint32) (*DescriptorSets, error)
NewDescriptors creates a layout from explicit bindings, numbered from zero in order, and a first pool for capacity sets; more pools follow as needed. Update writes the bindings that are not immutable samplers.
func (*Device) NewDeviceBuffer ¶
func (d *Device) NewDeviceBuffer(size vk.VkDeviceSize, usage vk.VkBufferUsageFlags) (*Buffer, error)
NewDeviceBuffer creates an empty device-local buffer that a transfer can fill, for vertex and index data. Its contents are undefined until RecordBufferUpload copies into it.
func (*Device) NewDeviceLocalBuffer ¶
NewDeviceLocalBuffer uploads data into device-local memory through a staging buffer, for vertex, index and storage data that never changes. It is for uploads outside a frame: the copy goes into the device's upload batch and costs no wait, and the batch is submitted before the next frame or wait. Inside a frame use NewDeviceBuffer and RecordBufferUpload.
func (*Device) NewDynamicUniforms ¶
func (d *Device) NewDynamicUniforms(blockRange vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*DynamicUniforms, error)
NewDynamicUniforms creates the layout (binding 0, visible to stages), one set per frame in flight, and buffers of an initial size.
func (*Device) NewFrameSets ¶
func (d *Device) NewFrameSets(size, storageSize vk.VkDeviceSize, fixed []vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*UniformSets, error)
NewFrameSets is NewUniformStorageSets with a storage buffer at each of bindings 2 and up, one for every size in fixed. Those buffers keep the size they are made with, so WriteFixed never grows one and a frame writes them without waiting for the device. Use them for a per-frame array whose size is a constant, such as a cluster grid's tables.
func (*Device) NewImage ¶
func (d *Device) NewImage(extent vk.VkExtent2D, format vk.VkFormat, usage vk.VkImageUsageFlags, aspect vk.VkImageAspectFlags) (*Image, error)
NewImage creates a 2D image with one mip level, binds memory and makes a view.
func (*Device) NewImageMips ¶
func (d *Device) NewImageMips(extent vk.VkExtent2D, format vk.VkFormat, usage vk.VkImageUsageFlags, aspect vk.VkImageAspectFlags, mips uint32) (*Image, error)
NewImageMips creates a 2D image with mips levels.
func (*Device) NewImageSamples ¶
func (d *Device) NewImageSamples(extent vk.VkExtent2D, format vk.VkFormat, usage vk.VkImageUsageFlags, aspect vk.VkImageAspectFlags, mips uint32, samples vk.VkSampleCountFlagBits) (*Image, error)
NewImageSamples creates a 2D image with mips levels and a sample count. A multisampled image is an attachment only: it has one level, nothing samples it, and a resolve writes its result into a single-sample image.
func (*Device) NewImmutableSamplerDescriptors ¶
func (d *Device) NewImmutableSamplerDescriptors(bindings int, capacity uint32, sampler vk.VkSampler) (*DescriptorSets, error)
NewImmutableSamplerDescriptors is NewSamplerDescriptors with the sampler baked into the layout, which MoltenVK requires for comparison samplers.
func (*Device) NewLevelledImage ¶
func (d *Device) NewLevelledImage(extent vk.VkExtent2D, format vk.VkFormat, mips uint32) (*Image, error)
NewLevelledImage creates a sampled image with the mip levels given, for a texture whose levels come ready made rather than being blitted from level zero. A compressed format cannot be blitted, so this is the only way to fill one.
func (*Device) NewLevelledTextureImage ¶
func (d *Device) NewLevelledTextureImage(extent vk.VkExtent2D, format vk.VkFormat, data []byte, levels []LevelCopy) (*Image, error)
NewLevelledTextureImage uploads a whole mip chain outside a frame. The copy goes into the device's upload batch and costs no wait. Inside a frame use NewLevelledImage with RecordLevelsUpload instead. To fill the staging in place rather than from a packed slice, use NewLevelledImage, StageUpload and UploadCommands.
func (*Device) NewPipeline ¶
func (d *Device) NewPipeline(desc PipelineDesc) (*Pipeline, error)
NewPipeline builds a graphics pipeline from desc.
func (*Device) NewSampledImage ¶
func (d *Device) NewSampledImage(extent vk.VkExtent2D, format vk.VkFormat, mipmaps bool) (*Image, error)
NewSampledImage creates an empty image for a texture, with a full mip chain when mipmaps is set. Its contents are undefined until RecordImageUpload fills them.
func (*Device) NewSampler ¶
NewSampler makes a clamp-to-edge sampler, nearest or linear. Linear samplers filter across the mip chain with anisotropy when the GPU has it.
func (*Device) NewSamplerDescriptors ¶
func (d *Device) NewSamplerDescriptors(bindings int, capacity uint32) (*DescriptorSets, error)
NewSamplerDescriptors creates a layout with bindings image/sampler pairs and a first pool for capacity sets; more pools follow as needed. Logical texture N occupies sampled-image binding 2N and sampler binding 2N+1.
func (*Device) NewSamplerRepeat ¶
NewSamplerRepeat is NewSampler with a choice of edge behaviour.
func (*Device) NewShadowSampler ¶
NewShadowSampler makes a comparison sampler for shadow maps: linear filtering of the comparison result gives free 2x2 percentage-closer filtering, and clamp-to-border white keeps everything outside the map lit.
func (*Device) NewStaging ¶
NewStaging makes the upload arena for a device's frame ring.
func (*Device) NewStorageSets ¶
func (d *Device) NewStorageSets(size vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*StorageSets, error)
NewStorageSets creates the layout, pool, buffers and sets for size bytes.
func (*Device) NewSwapchain ¶
func (d *Device) NewSwapchain(surface vk.VkSurfaceKHR, fallback vk.VkExtent2D, vsync bool) (*Swapchain, error)
NewSwapchain creates a swapchain sized to the surface's current extent, or to fallback when the surface leaves the size to the application. A zero surface creates a headless swapchain of the fallback extent.
func (*Device) NewTarget ¶
func (d *Device) NewTarget(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
NewTarget creates a colour (and depth) target of the given formats; pass VK_FORMAT_UNDEFINED to omit either image.
func (*Device) NewTargetCopyable ¶
func (d *Device) NewTargetCopyable(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
NewTargetCopyable is NewTarget with a colour image that transfers can read, for snapshots taken with CopyColorForSampling.
func (*Device) NewTargetDesc ¶
func (d *Device) NewTargetDesc(desc TargetDesc) (*Target, error)
NewTargetDesc creates a target from a full description.
func (*Device) NewTargetReadable ¶
func (d *Device) NewTargetReadable(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
NewTargetReadable is NewTargetSampled with a colour image that can also be read back to the host with ReadImage.
func (*Device) NewTargetSampled ¶
func (d *Device) NewTargetSampled(extent vk.VkExtent2D, colorFormat, depthFormat vk.VkFormat) (*Target, error)
NewTargetSampled is NewTarget with a colour image that can also be cleared by transfer, for render textures that may be sampled before their first pass.
func (*Device) NewTextureDescriptors ¶
func (d *Device) NewTextureDescriptors(capacity uint32) (*DescriptorSets, error)
NewTextureDescriptors creates one image/sampler pair for the 2D path.
func (*Device) NewTextureImage ¶
func (d *Device) NewTextureImage(extent vk.VkExtent2D, format vk.VkFormat, pixels []byte, mipmaps bool) (*Image, error)
NewTextureImage uploads RGBA pixels (row-major, 4 bytes per pixel) into a sampled image, generates a full mip chain when mipmaps is set, and leaves it in shader-read-only layout. It is for uploads outside a frame: the copy goes into the device's upload batch and costs no wait, and the batch is submitted before the next frame or wait. Inside a frame use NewSampledImage and RecordImageUpload.
func (*Device) NewTimestamps ¶
func (d *Device) NewTimestamps() *Timestamps
NewTimestamps makes a query pool for timing the frame's passes, or returns nil when the device cannot time them: a zero timestamp period, or a queue family with no valid timestamp bits. Query pool creation failure also returns nil. The caller keeps a nil value and every method does nothing. Available queries may still report equal counters and zero durations, including on MoltenVK without Metal counter sampling.
func (*Device) NewUniformSets ¶
func (d *Device) NewUniformSets(size vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*UniformSets, error)
NewUniformSets creates the layout, pool, buffers and sets for size bytes of uniform data visible to stages.
func (*Device) NewUniformStorageSets ¶
func (d *Device) NewUniformStorageSets(size, storageSize vk.VkDeviceSize, stages vk.VkShaderStageFlags) (*UniformSets, error)
NewUniformStorageSets is NewUniformSets with a storage buffer at binding 1 of the same set, holding storageSize bytes to start with and grown by WriteStorage. Use it for a per-frame array a uniform block cannot hold, such as an irradiance grid.
func (*Device) OneShot ¶
func (d *Device) OneShot(record func(cb vk.VkCommandBuffer)) error
OneShot records commands into a fresh buffer, submits them and waits. It is for readbacks and other setup work whose result the caller needs at once, not per-frame work; an upload that only has to be on the GPU before the next frame goes through StageUpload and UploadCommands and costs no wait. The open upload batch is submitted just ahead of the commands, so they see everything uploaded before them or while they were being recorded.
func (*Device) Physical ¶
func (d *Device) Physical() vk.VkPhysicalDevice
Physical exposes the physical device handle for surface queries.
func (*Device) ReadDepth ¶
ReadDepth copies the depth aspect of an image that a finished pass left in shader-read-only layout back to the host, one float per pixel in row-major order, 0 at the near plane and 1 at the far plane. It waits for the device, so it belongs in tools and tests rather than in a frame. The image must not be in use by a frame in flight, and a multisampled image is read through the one it resolves into.
func (*Device) ReadImage ¶
ReadImage copies level 0 of an image that is in shader-read-only layout back to the host as RGBA, swizzling BGRA formats. The image must not be in use by a frame in flight.
func (*Device) ReadImageRaw ¶
ReadImageRaw copies level 0 of a colour image that is in shader-read-only layout back to the host as its own texels, texelBytes per texel, rows packed with no padding. Use it for a format ReadImage cannot express as an RGBA image, such as the half-float scene image a probe bake captures. The image must not be in use by a frame in flight.
func (*Device) Retire ¶
func (d *Device) Retire(fn func())
Retire schedules fn to free a GPU object once every frame that may still reference it has finished. Use it instead of WaitIdle for anything a recorded frame has already bound: a replaced buffer, a descriptor pool whose sets a submitted frame holds. The frame ring runs fn from a later BeginFrame, after that frame's fence has been waited on, so retiring costs no stall. A device with no frames running frees everything retired when it is destroyed.
func (*Device) RetireBuffers ¶
func (d *Device) RetireBuffers(bufs [FramesInFlight]*Buffer)
RetireBuffers schedules a ring of per-frame buffers for destruction once no frame in flight can still reference them. A stream that outgrew its buffers allocates a new ring and retires the old one, so growing costs no wait. Nil entries are ignored.
func (*Device) SampleCount ¶
func (d *Device) SampleCount(n int) vk.VkSampleCountFlagBits
SampleCount turns a requested sample count into the flag bit for it, rounded down to a power of two the device supports. Zero and one both mean no multisampling.
func (*Device) ShadowFormat ¶
ShadowFormat picks the format for a depth image that is only ever rendered to and sampled, never stencilled: a shadow atlas. It prefers a format without a stencil aspect, which costs half the memory of D32_SFLOAT_S8 on the desktop GPUs that pad that format to eight bytes a texel, and falls back to the renderer's own depth format. Both candidates must also filter, since the shadow sampler compares with linear filtering.
func (*Device) StageUpload ¶
func (d *Device) StageUpload(size vk.VkDeviceSize) (*Buffer, vk.VkDeviceSize, []byte, error)
StageUpload reserves size bytes of host-visible staging in the open upload batch and returns the buffer, the offset within it and the mapped bytes to fill. Record the copy from that buffer and offset into the command buffer UploadCommands returns, before the next call that can flush: another StageUpload, FlushUploads, WaitIdle or OneShot. The offset is a multiple of 16 and of the device's preferred copy alignment.
func (*Device) Stats ¶
func (d *Device) Stats() AllocStats
Stats returns the current allocator statistics. Pending uploads are finished first, so the staging they hold for a moment is not counted; that can wait for the GPU when an upload batch is still running.
func (*Device) SupportsFormat ¶
SupportsFormat reports whether the device can sample an image in the format with optimal tiling. A block-compressed format is optional in Vulkan, so the caller checks before uploading one and decodes on the processor when the answer is no.
func (*Device) UploadCommands ¶
func (d *Device) UploadCommands() (vk.VkCommandBuffer, error)
UploadCommands returns the open upload batch's command buffer, opening a batch if there is none, and counts one upload against the batch's limit. Record into it at once: the next StageUpload, FlushUploads, WaitIdle or OneShot may submit it.
func (*Device) WaitIdle ¶
WaitIdle submits the open upload batch and blocks until the device has finished all submitted work. It stalls the GPU, so it belongs in setup and teardown rather than in a frame; Waits counts every such stall. When nothing has been submitted since the device was last waited idle it returns at once and counts nothing. Prefer Retire for an object a recorded frame may still reference.
func (*Device) Waits ¶
Waits is how many times the device or its queue has been waited on since it was created. A frame that uploads and destroys through the staging arena and the retire ring adds nothing to it, so the count stands still once a game is running.
func (*Device) WriteImage ¶
WriteImage replaces a rectangle of a sampled image's level 0 with RGBA pixels (row-major, 4 bytes per pixel, w*h*4 bytes) and rebuilds any mip chain. It is for writes outside a frame: the copy goes into the device's upload batch and costs no wait. Its barriers order it after every earlier read of the image on the queue.
type DynamicUniforms ¶
type DynamicUniforms struct {
Layout vk.VkDescriptorSetLayout
Sets [FramesInFlight]vk.VkDescriptorSet
Range vk.VkDeviceSize // largest block a shader may declare
Align vk.VkDeviceSize
// contains filtered or unexported fields
}
DynamicUniforms is a growable per-frame arena of uniform data bound through one dynamic uniform buffer descriptor: many draws share the set and select their block with an offset. Blocks are at most Range bytes and start on the device's offset alignment.
func (*DynamicUniforms) Destroy ¶
func (u *DynamicUniforms) Destroy()
func (*DynamicUniforms) NewArena ¶
func (u *DynamicUniforms) NewArena() *Arena
NewArena makes an arena for a DynamicUniforms' alignment.
type Frame ¶
type Frame struct {
CB vk.VkCommandBuffer
ImageIndex uint32
Slot int // which of the FramesInFlight per-frame resources to use
Extent vk.VkExtent2D
}
Frame is what a caller records into between BeginFrame and EndFrame.
type Image ¶
type Image struct {
Handle vk.VkImage
View vk.VkImageView
AttachView vk.VkImageView
Format vk.VkFormat
Extent vk.VkExtent2D
Mips uint32
Samples vk.VkSampleCountFlagBits // one unless the image is a multisampled attachment
// contains filtered or unexported fields
}
Image is a VkImage with allocator memory and a view over every level. A depth image with a stencil aspect has two views: View covers depth alone, for sampling, and AttachView covers both aspects, for rendering.
func (*Image) Destroy ¶
func (i *Image) Destroy()
Destroy frees the image. An upload batch still writing it is submitted or finished first, so an image destroyed straight after an upload outside a frame is safe to free.
func (*Image) NoteUpload ¶
func (i *Image) NoteUpload()
NoteUpload records that the open upload batch writes the image, so that Destroy first makes sure the batch has run rather than freeing an image a pending copy still targets. The upload helpers in this package call it; a caller recording into UploadCommands itself calls it too.
type Instance ¶
type Instance struct {
Handle vk.VkInstance
// contains filtered or unexported fields
}
Instance owns the VkInstance and, when validation is on, the debug messenger.
func NewInstance ¶
NewInstance creates an instance or retains the compatible active instance. Validation and logger must match an existing family; requested surface extensions must already be enabled. The initial application name is kept. Each returned reference must be destroyed once; repeated Destroy is safe.
type LevelCopy ¶
type LevelCopy struct {
Offset vk.VkDeviceSize
Width, Height uint32
}
LevelCopy is where one mip level's bytes sit in a staging buffer and what size that level is in texels.
type PassDesc ¶
type PassDesc struct {
Target *Target
ClearColor [4]float32
ClearDepth float32 // 1 for a normal depth pass
LoadColor bool // keep existing colour instead of clearing
LoadDepth bool // keep existing depth (and stencil) instead of clearing
NoDepth bool // render without the depth attachment, leaving the depth image readable
// Extra are colour attachments after the target's own, in the order
// a pipeline's ExtraColor lists them, and at most three. Each is the
// target's extent, is cleared to the colour at the same index in
// ExtraClear, and ends readable by shaders like the target's own.
// They are single-sample and carry no resolve, so a target with them
// must be single-sample too: every attachment of a pass shares one
// sample count.
Extra []*Image
ExtraClear [][4]float32
// Depth is a depth image to render into instead of the target's own,
// for a pass that shares another target's depth. Nil uses the
// target's, and LoadDepth applies to whichever is used.
Depth *Image
// DiscardMS marks the last pass that renders into a multisampled
// target's MSColor and MSDepth. They still resolve into Color and
// Depth as the pass ends, but their samples are not written back to
// memory, which is most of what multisampling costs in bandwidth. A
// later pass that loads them finds undefined contents. It has no
// effect on a single-sample target.
DiscardMS bool
// ReadOnlyDepth is for a pass that loads a depth attachment to test
// against and writes neither its depth nor its stencil. The
// attachment is not stored back (STORE_OP_NONE), so the image keeps
// what it held before the pass. A pass that does write depth or
// stencil with it set leaves the attachment undefined.
ReadOnlyDepth bool
}
PassDesc describes one dynamic-rendering pass into a target.
type Pipeline ¶
type Pipeline struct {
Handle vk.VkPipeline
Layout vk.VkPipelineLayout
// contains filtered or unexported fields
}
Pipeline is a graphics pipeline and its layout.
type PipelineDesc ¶
type PipelineDesc struct {
Vert, Frag []byte // SPIR-V
ColorFormat vk.VkFormat
DepthFormat vk.VkFormat // VK_FORMAT_UNDEFINED for no depth attachment
Bindings []vk.VkVertexInputBindingDescription
Attributes []vk.VkVertexInputAttributeDescription
Topology vk.VkPrimitiveTopology
CullMode vk.VkCullModeFlags
Blend bool // blending on; premultiplied source-over unless Factors is set
Factors *BlendFactors // blend equation when Blend is set
DepthTest bool
DepthWrite bool
DepthCompare vk.VkCompareOp // zero means less-or-equal
Stencil *StencilState // stencil test and write, when the depth format has stencil
PushConstantSize uint32 // bytes visible to all stages, 0 for none
SetLayouts []vk.VkDescriptorSetLayout
// Samples is the sample count of the attachments the pipeline renders
// into; zero or one is no multisampling. It must match the target's,
// so a pass that changes sample count needs its own pipelines.
Samples vk.VkSampleCountFlagBits
NoColor bool // depth-only pass (shadow maps)
NoColorWrite bool // keep the colour attachment but disable its writes
DepthBias float32 // constant depth bias, for shadow passes
DepthSlopeBias float32
// DepthClamp clamps a fragment's depth to the viewport's range instead
// of clipping the primitive at the near and far planes, so a shadow
// caster in front of the near plane still writes depth. It needs the
// device's depthClamp feature and is dropped where that is missing;
// Device.DepthClamp says whether it took effect.
DepthClamp bool
FrontFace vk.VkFrontFace // zero means counter-clockwise
// ExtraColor describes the colour attachments after the first: their
// formats and how each blends. The first attachment stays
// ColorFormat with Blend and Factors. A pass drawing with the
// pipeline binds the same attachments in the same order, through
// PassDesc.Extra.
ExtraColor []ColorAttachment
}
PipelineDesc describes a graphics pipeline for dynamic rendering. Viewport and scissor are always dynamic so a resize never rebuilds pipelines.
type Renderer ¶
type Renderer struct {
Instance *Instance
Device *Device
Swapchain *Swapchain
// DepthFormat is the format of the depth attachment every frame carries;
// pipelines must declare it.
DepthFormat vk.VkFormat
// contains filtered or unexported fields
}
Renderer ties an instance, device and swapchain together with a ring of in-flight frames. A frame is BeginFrame, record, EndFrame.
func NewRenderer ¶
func NewRenderer(cfg Config, surfaceExts []string, makeSurface SurfaceFunc, extent vk.VkExtent2D, vsync bool) (*Renderer, error)
NewRenderer brings the whole stack up: instance, surface, device, swapchain and frame ring. extent is used only when the surface has no fixed size.
func (*Renderer) BeginFrame ¶
BeginFrame waits for the frame slot, acquires a swapchain image and starts the command buffer. It returns ok=false, with no error, when the swapchain had to be rebuilt and the caller should try again next loop. The caller then records any offscreen passes and calls BeginSwapchainPass.
func (*Renderer) BeginSwapchainPass ¶
BeginSwapchainPass opens the final pass into the acquired swapchain image, with the frame's depth attachment, cleared to clear.
func (*Renderer) Destroy ¶
func (r *Renderer) Destroy()
Destroy tears everything down in reverse order.
func (*Renderer) EndFrame ¶
EndFrame closes the render pass, submits and presents. With capture set it also copies the finished image to host memory and returns it, which costs a full GPU sync and is meant for screenshots and tests.
func (*Renderer) NewOutput ¶
func (r *Renderer) NewOutput(surfaceExts []string, makeSurface SurfaceFunc, extent vk.VkExtent2D, vsync bool) (*Renderer, error)
NewOutput creates an independent device, swapchain and frame ring under this renderer's retained instance. Graphics resources belong to their output and cannot be passed between outputs. Destroying either output leaves the other alive. Required surface extensions are checked before makeSurface is called.
type SamplerBinding ¶
type SamplerBinding struct {
View vk.VkImageView
Sampler vk.VkSampler
Layout vk.VkImageLayout // zero means shader-read-only
}
SamplerBinding supplies an image and sampler for one logical texture in a NewSamplerDescriptors layout. In an explicit NewDescriptors layout it supplies one actual binding: sampled images use View, samplers use Sampler, and combined image samplers use both. Layout applies only to the image.
type Staging ¶
type Staging struct {
// contains filtered or unexported fields
}
Staging is the upload arena of the frame ring: one host-visible bump allocator per frame slot, for copies recorded into that frame's command buffer. Take space with Alloc, record a copy from the buffer and offset it returns, and call Begin(slot) once the slot's fence has been waited on, which frees what the last pass through the ring used.
func (*Staging) Alloc ¶
Alloc copies data into the slot's arena and returns the buffer and the offset within it to copy from. The space is valid until the next Begin of that slot, which is why the copy must be recorded into that slot's frame.
func (*Staging) Begin ¶
Begin frees what the slot's last frame staged and starts it empty. The caller must have waited on that slot's fence first.
func (*Staging) Destroy ¶
func (s *Staging) Destroy()
Destroy frees every arena. The device must be idle.
func (*Staging) Reserve ¶
func (s *Staging) Reserve(slot int, size vk.VkDeviceSize) (*Buffer, vk.VkDeviceSize, []byte, error)
Reserve is Alloc without the copy: it takes size bytes of the slot's arena and returns the buffer, the offset and the mapped bytes, for a caller that writes its data in place rather than building a slice to copy from. The same lifetime applies.
type StencilState ¶
type StencilState struct {
Compare vk.VkCompareOp
Ref uint32
Write bool
Pass vk.VkStencilOp
Fail, DepthFail vk.VkStencilOp
ReadMask, WriteMask uint32 // zero means all eight bits; Write controls updates
}
StencilState is a stencil test applied to both faces: fragments pass using Vulkan's comparison of masked Ref against masked stored value. Pass, Fail and DepthFail update the stored value when Write is set. Zero masks mean all eight bits, preserving the ordinary full-mask case.
func StencilNotEqual ¶
func StencilNotEqual(ref uint32) *StencilState
StencilNotEqual passes only where the stored value differs from ref.
func StencilWrite ¶
func StencilWrite(ref uint32) *StencilState
StencilWrite marks every fragment drawn with ref.
type StorageSets ¶
type StorageSets struct {
Layout vk.VkDescriptorSetLayout
Sets [FramesInFlight]vk.VkDescriptorSet
Buffers [FramesInFlight]*Buffer
// contains filtered or unexported fields
}
StorageSets is a descriptor set layout with one storage buffer at binding 0, with one host-visible buffer and set per frame in flight that grow on demand: joint matrices and other per-frame arrays live here.
func (*StorageSets) Destroy ¶
func (s *StorageSets) Destroy()
type SurfaceFunc ¶
type SurfaceFunc func(instance vk.VkInstance) (vk.VkSurfaceKHR, error)
SurfaceFunc creates the presentation surface once the instance exists.
type Swapchain ¶
type Swapchain struct {
Handle vk.VkSwapchainKHR
Format vk.VkFormat
Extent vk.VkExtent2D
Images []vk.VkImage
Views []vk.VkImageView
// contains filtered or unexported fields
}
Swapchain owns the presentable images for one surface. Recreate handles resizes; the caller decides when by watching the platform's resize events and the results of Acquire and Present. A zero surface makes a headless swapchain: ordinary images of the fallback extent, one per frame in flight, with a zero Handle and nothing to acquire or present.
type Target ¶
type Target struct {
Color *Image // nil for depth-only targets; the resolve destination when multisampled
Depth *Image
MSColor *Image // the multisampled colour attachment, nil at one sample
MSDepth *Image // the multisampled depth attachment, nil at one sample
Samples vk.VkSampleCountFlagBits // one unless the target is multisampled
Extent vk.VkExtent2D
// contains filtered or unexported fields
}
Target is an offscreen render target: a colour image and optionally a depth image, both sampleable afterwards. Scene rendering goes to an HDR target before post-processing; shadow maps are depth-only targets.
A multisampled target keeps the attachments a pass renders into in MSColor and MSDepth and resolves them into Color and Depth when the pass ends, so everything downstream reads the same single-sample images whatever the sample count.
type TargetDesc ¶
type TargetDesc struct {
Extent vk.VkExtent2D
ColorFormat vk.VkFormat // VK_FORMAT_UNDEFINED for a depth-only target
DepthFormat vk.VkFormat // VK_FORMAT_UNDEFINED for no depth attachment
Samples vk.VkSampleCountFlagBits // zero or one renders without multisampling
ColorUsage vk.VkImageUsageFlags // added to the single-sample colour image
DepthUsage vk.VkImageUsageFlags // added to the depth image
}
TargetDesc describes an offscreen target. The zero value of every field is the plain case: a single-sample target with no extra usage.
type Timestamps ¶
type Timestamps struct {
// contains filtered or unexported fields
}
Timestamps times a frame's passes on the GPU with timestamp queries. To use one, call Reset at the start of each frame slot's command buffer and wrap each pass in Begin and End; Spans reports the newest frame whose results have arrived. Results are read back at the slot's next Reset, by which point the slot's fence has been waited on, so a frame never stalls for them and the figures lag the frame on screen by FramesInFlight. Sections with the same name are summed, so a pass that runs once per render texture reads as one entry.
NewTimestamps returns nil on a device without timestamp queries, and every method here is safe on a nil receiver, so a caller keeps the value and gets empty results.
func (*Timestamps) Begin ¶
func (t *Timestamps) Begin(cb vk.VkCommandBuffer, name string)
Begin starts timing a section named name. Pairs nest, so a pass may time the parts inside it. A frame that has used all its queries records nothing and the matching End does nothing.
A command buffer that has not called Reset records nothing either, so work recorded outside the frame ring, such as a probe bake on a one-shot buffer, neither writes into queries it never reset nor consumes the open frame's. A one-shot buffer's handle cannot equal a frame's, because a frame's is allocated for the life of the device.
func (*Timestamps) End ¶
func (t *Timestamps) End(cb vk.VkCommandBuffer)
End closes the innermost open section. Calling it without a matching Begin, or on a buffer that has not called Reset, does nothing.
func (*Timestamps) FrameMS ¶
func (t *Timestamps) FrameMS() float64
FrameMS is the GPU time from the first timed section's start to the last one's end, which is the whole frame when the outermost sections cover it. It is zero until results arrive, and also when all available counters are equal because of the device's timestamp resolution.
func (*Timestamps) Reset ¶
func (t *Timestamps) Reset(cb vk.VkCommandBuffer, slot int)
Reset publishes the results the slot's last frame left, then records the reset of that slot's queries into cb. Every frame must call it before the first Begin, at the top of the frame's command buffer.
func (*Timestamps) Spans ¶
func (t *Timestamps) Spans() []Span
Spans is the newest frame's sections, in the order they were opened, summed by name. The slice is reused every time results arrive, so copy it to keep it. A span with equal available counters is retained with zero duration; it is distinct from an unavailable query, which is omitted.
type UniformSets ¶
type UniformSets struct {
Layout vk.VkDescriptorSetLayout
Sets [FramesInFlight]vk.VkDescriptorSet
Buffers [FramesInFlight]*Buffer
// contains filtered or unexported fields
}
UniformSets is a descriptor set layout with one uniform buffer at binding 0, plus one buffer and set per frame in flight so that a frame's data can be written while the previous frame still reads its own. With NewUniformStorageSets the same set carries a storage buffer at binding 1, for a per-frame array too large for a uniform block, and with NewFrameSets more of them at bindings 2 and up, each fixed at its size.
func (*UniformSets) Destroy ¶
func (u *UniformSets) Destroy()
func (*UniformSets) Write ¶
func (u *UniformSets) Write(slot int, data []byte) error
Write stores this frame's uniform data into the slot's buffer.
func (*UniformSets) WriteFixed ¶
func (u *UniformSets) WriteFixed(slot, binding int, data []byte) error
WriteFixed stores data at the start of the slot's buffer for one of the fixed storage bindings, counting from zero at binding 2. Data longer than the buffer is an error, since those buffers never grow.
func (*UniformSets) WriteStorage ¶
func (u *UniformSets) WriteStorage(slot int, data []byte) error
WriteStorage stores data into the slot's storage buffer at binding 1, growing every slot's buffer when it no longer fits. Growing waits for the device, so it happens when a grid changes size and not per frame.