Documentation
¶
Overview ¶
Package gpu is Hover's own small binding to wgpu-native v29: the calls the office renderer and the notch spike need, and nothing else. go-webgpu was dropped for it (its v0.5.5 structs no longer matched wgpu-native v29, see docs/development/go-port.md).
Every C struct is in wire.go, and wire_test.go checks their sizes, offsets and the enum numbers against what the C compiler gave for wgpu-native's own webgpu.h. The public API takes Go values; each call builds its wire structs, pins them (so the GC can neither move nor free what the C side reads) and unpins them when the call returns.
Windows calls wgpu_native.dll through syscall (no C compiler). Linux and macOS go through purego (no C compiler either; the Linux app has one for Gio, and purego works with it).
ponytail: only what the office and the spike draw with. A new call is one method here and, if it takes a struct, one wire struct and one line in wire_test.go.
Index ¶
- Constants
- func Init() error
- type Adapter
- type AdapterInfo
- type AdapterType
- type AddressMode
- type BackendType
- type BindGroup
- type BindGroupLayout
- type Blend
- type BlendComponent
- type BlendFactor
- type BlendOp
- type Buffer
- type BufferUsage
- type Color
- type ColorAttachment
- type CommandBuffer
- type CommandEncoder
- type Compare
- type CullMode
- type DepthAttachment
- type DepthState
- type Device
- func (d *Device) BindGroup(layout BindGroupLayout, entries ...GroupEntry) BindGroup
- func (d *Device) BindGroupLayout(entries ...LayoutEntry) BindGroupLayout
- func (d *Device) Buffer(usage BufferUsage, size uint64) Buffer
- func (d *Device) BufferWith(usage BufferUsage, data []byte) Buffer
- func (d *Device) CheckShader(inst Instance, label, wgsl string) string
- func (d *Device) Encoder() CommandEncoder
- func (d *Device) Errors() []string
- func (d *Device) PipelineLayout(layouts ...BindGroupLayout) PipelineLayout
- func (d *Device) Poll(wait bool)
- func (d *Device) Release()
- func (d *Device) RenderPipeline(p PipelineDesc) RenderPipeline
- func (d *Device) Sampler(s SamplerDesc) Sampler
- func (d *Device) ShaderModule(label, wgsl string) ShaderModule
- func (d *Device) Texture(t TextureDesc) Texture
- type FilterMode
- type FrontFace
- type GroupEntry
- type IndexFormat
- type Instance
- type LayoutEntry
- type PipelineDesc
- type PipelineLayout
- type Queue
- type RenderPass
- func (p RenderPass) Draw(vertices, instances, firstVertex, firstInstance uint32)
- func (p RenderPass) DrawIndexed(indices, instances, firstIndex uint32, baseVertex int32, firstInstance uint32)
- func (p RenderPass) End()
- func (p RenderPass) SetBindGroup(index uint32, g BindGroup, offsets ...uint32)
- func (p RenderPass) SetIndexBuffer(b Buffer, f IndexFormat)
- func (p RenderPass) SetPipeline(pl RenderPipeline)
- func (p RenderPass) SetVertexBuffer(slot uint32, b Buffer)
- type RenderPipeline
- type SampleType
- type Sampler
- type SamplerDesc
- type ShaderModule
- type ShaderStage
- type Target
- type Texture
- type TextureDesc
- type TextureFormat
- type TextureUsage
- type TextureView
- type Topology
- type VertexAttr
- type VertexFormat
- type VertexLayout
Constants ¶
const ( FormatRGBA8Unorm TextureFormat = 0x16 FormatRGBA8UnormSrgb TextureFormat = 0x17 FormatRGBA16Float TextureFormat = 0x28 FormatDepth32Float TextureFormat = 0x30 TextureCopySrc TextureUsage = 0x1 TextureCopyDst TextureUsage = 0x2 TextureBinding TextureUsage = 0x4 TextureRenderAttachmt TextureUsage = 0x10 BufferMapRead BufferUsage = 0x1 BufferCopySrc BufferUsage = 0x4 BufferCopyDst BufferUsage = 0x8 BufferIndex BufferUsage = 0x10 BufferVertex BufferUsage = 0x20 BufferUniform BufferUsage = 0x40 StageVertex ShaderStage = 0x1 StageFragment ShaderStage = 0x2 SampleFloat SampleType = 2 SampleDepth SampleType = 4 IndexUint32 IndexFormat = 2 VertexFloat32x2 VertexFormat = 0x1d VertexFloat32x3 VertexFormat = 0x1e PointList Topology = 1 TriangleList Topology = 4 FrontCCW FrontFace = 1 CullNone CullMode = 1 CullFront CullMode = 2 CullBack CullMode = 3 CompareLessEqual Compare = 4 BlendAdd BlendOp = 1 FactorOne BlendFactor = 2 FactorSrcAlpha BlendFactor = 5 FactorOneMinusSrcAlpha BlendFactor = 6 FilterNearest FilterMode = 1 FilterLinear FilterMode = 2 ClampToEdge AddressMode = 1 BackendD3D12 BackendType = 4 BackendMetal BackendType = 5 BackendVulkan BackendType = 6 BackendOpenGL BackendType = 7 BackendOpenGLES BackendType = 8 AdapterCPU AdapterType = 3 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
func (Adapter) Info ¶
func (a Adapter) Info() AdapterInfo
ponytail: the info's strings are wgpu-native's and are not freed (a few bytes, once per adapter): wgpuAdapterInfoFreeMembers takes the 96-byte struct by value.
type AdapterInfo ¶
type AdapterInfo struct {
Name string
Backend BackendType
Type AdapterType
}
AdapterInfo is what the office logs and what decides software rendering.
func (AdapterInfo) String ¶
func (i AdapterInfo) String() string
type AdapterType ¶
type AdapterType uint32
type AddressMode ¶
type AddressMode uint32
type BackendType ¶
type BackendType uint32
type BindGroupLayout ¶
type BindGroupLayout struct {
// contains filtered or unexported fields
}
func (BindGroupLayout) Release ¶
func (x BindGroupLayout) Release()
type Blend ¶
type Blend struct{ Color, Alpha BlendComponent }
type BlendComponent ¶
type BlendComponent struct {
Op BlendOp
Src, Dst BlendFactor
}
type BlendFactor ¶
type BlendFactor uint32
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
func (Buffer) MapRead ¶
MapRead maps size bytes of a MAP_READ buffer and waits for it. The bytes are Mapped's until Unmap.
type BufferUsage ¶
type BufferUsage uint64
type ColorAttachment ¶
type ColorAttachment struct {
View TextureView
Clear Color
}
ColorAttachment is cleared to Clear and stored.
type CommandBuffer ¶
type CommandBuffer struct {
// contains filtered or unexported fields
}
func (CommandBuffer) Release ¶
func (x CommandBuffer) Release()
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
func (CommandEncoder) CopyTextureToBuffer ¶
func (e CommandEncoder) CopyTextureToBuffer(t Texture, b Buffer, bytesPerRow, w, h uint32)
CopyTextureToBuffer copies a whole w x h texture into a buffer, rows bytesPerRow apart (a multiple of 256).
func (CommandEncoder) Finish ¶
func (e CommandEncoder) Finish() CommandBuffer
Finish ends the encoder (and releases it) and returns its commands.
func (CommandEncoder) Release ¶
func (x CommandEncoder) Release()
func (CommandEncoder) RenderPass ¶
func (e CommandEncoder) RenderPass(label string, color *ColorAttachment, depth *DepthAttachment) RenderPass
RenderPass begins a pass. Color may be nil: a depth-only pass (the shadow map).
type DepthAttachment ¶
type DepthAttachment struct {
View TextureView
Clear float32
}
DepthAttachment is cleared to Clear and stored.
type DepthState ¶
type DepthState struct {
Format TextureFormat
Write bool
Compare Compare
}
type Device ¶
type Device struct {
Queue Queue
// contains filtered or unexported fields
}
Device is a device, its queue and the id its error callbacks report under.
func (*Device) BindGroup ¶
func (d *Device) BindGroup(layout BindGroupLayout, entries ...GroupEntry) BindGroup
func (*Device) BindGroupLayout ¶
func (d *Device) BindGroupLayout(entries ...LayoutEntry) BindGroupLayout
func (*Device) BufferWith ¶
func (d *Device) BufferWith(usage BufferUsage, data []byte) Buffer
BufferWith makes a buffer holding data (COPY_DST is added to its usage). Its size is rounded up to 4 bytes, as a buffer write needs.
func (*Device) CheckShader ¶
CheckShader compiles WGSL inside a validation error scope and returns wgpu's message, or "" when it compiled.
func (*Device) Encoder ¶
func (d *Device) Encoder() CommandEncoder
func (*Device) Errors ¶
Errors returns and forgets the errors the device reported outside an error scope (a validation error, a lost device), oldest first.
func (*Device) PipelineLayout ¶
func (d *Device) PipelineLayout(layouts ...BindGroupLayout) PipelineLayout
func (*Device) Poll ¶
Poll waits for the queue's work (wait) or only collects what has finished; map callbacks fire in it.
func (*Device) RenderPipeline ¶
func (d *Device) RenderPipeline(p PipelineDesc) RenderPipeline
func (*Device) Sampler ¶
func (d *Device) Sampler(s SamplerDesc) Sampler
func (*Device) ShaderModule ¶
func (d *Device) ShaderModule(label, wgsl string) ShaderModule
func (*Device) Texture ¶
func (d *Device) Texture(t TextureDesc) Texture
type FilterMode ¶
type FilterMode uint32
type GroupEntry ¶
type GroupEntry struct {
Binding uint32
Buffer Buffer
Offset uint64
// Size 0 is the whole buffer.
Size uint64
Sampler Sampler
View TextureView
}
GroupEntry is one resource of a bind group: a buffer range, a sampler or a view.
type IndexFormat ¶
type IndexFormat uint32
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func CreateInstance ¶
CreateInstance makes an instance. On Windows it asks for DX12 only: a device on its own also woke Vulkan and OpenGL on every graphics card (the Rust office's note), and DX12 is what WARP, the runner's CPU adapter, speaks.
func (Instance) RequestAdapter ¶
RequestAdapter asks for a low-power adapter; fallback asks for the CPU one (WARP on Windows, llvmpipe on Linux).
type LayoutEntry ¶
type LayoutEntry struct {
Binding uint32
Visibility ShaderStage
// Uniform: a uniform buffer; Dynamic: it takes a dynamic offset; MinSize: 0 for any.
Uniform bool
Dynamic bool
MinSize uint64
Sampler bool
// Texture: its sample type (SampleFloat, SampleDepth), 0 for none.
Texture SampleType
}
LayoutEntry is one binding of a bind group layout: a uniform buffer, a filtering sampler or a 2D texture.
type PipelineDesc ¶
type PipelineDesc struct {
Label string
Layout PipelineLayout
Module ShaderModule
VS, FS string
Buffers []VertexLayout
Targets []Target
Topology Topology
Front FrontFace
Cull CullMode
Depth *DepthState
}
PipelineDesc describes a render pipeline. A zero Layout is the automatic one; an empty FS is no fragment stage (a depth-only pass).
type PipelineLayout ¶
type PipelineLayout struct {
// contains filtered or unexported fields
}
func (PipelineLayout) Release ¶
func (x PipelineLayout) Release()
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
func (Queue) Submit ¶
func (q Queue) Submit(cmds ...CommandBuffer)
Submit sends the commands and releases them: a submitted command buffer can't be used again, and one never released keeps its device alive (wgpu-core holds the device in it), so a dropped office kept its whole device, about 350 MB a time on an NVIDIA card.
type RenderPass ¶
type RenderPass struct {
// contains filtered or unexported fields
}
func (RenderPass) Draw ¶
func (p RenderPass) Draw(vertices, instances, firstVertex, firstInstance uint32)
func (RenderPass) DrawIndexed ¶
func (p RenderPass) DrawIndexed(indices, instances, firstIndex uint32, baseVertex int32, firstInstance uint32)
func (RenderPass) SetBindGroup ¶
func (p RenderPass) SetBindGroup(index uint32, g BindGroup, offsets ...uint32)
func (RenderPass) SetIndexBuffer ¶
func (p RenderPass) SetIndexBuffer(b Buffer, f IndexFormat)
func (RenderPass) SetPipeline ¶
func (p RenderPass) SetPipeline(pl RenderPipeline)
func (RenderPass) SetVertexBuffer ¶
func (p RenderPass) SetVertexBuffer(slot uint32, b Buffer)
type RenderPipeline ¶
type RenderPipeline struct {
// contains filtered or unexported fields
}
func (RenderPipeline) Release ¶
func (x RenderPipeline) Release()
type SampleType ¶
type SampleType uint32
type SamplerDesc ¶
type SamplerDesc struct {
Mag, Min FilterMode
AddressU AddressMode
AddressV AddressMode
}
type ShaderModule ¶
type ShaderModule struct {
// contains filtered or unexported fields
}
func (ShaderModule) Release ¶
func (x ShaderModule) Release()
type ShaderStage ¶
type ShaderStage uint64
type Target ¶
type Target struct {
Format TextureFormat
// Blend nil writes the colour as it is.
Blend *Blend
}
type TextureDesc ¶
type TextureDesc struct {
Label string
W, H uint32
Format TextureFormat
Usage TextureUsage
}
type TextureFormat ¶
type TextureFormat uint32
type TextureUsage ¶
type TextureUsage uint64
type TextureView ¶
type TextureView struct {
// contains filtered or unexported fields
}
func (TextureView) Release ¶
func (x TextureView) Release()
type VertexAttr ¶
type VertexAttr struct {
Format VertexFormat
Offset uint64
Location uint32
}
type VertexFormat ¶
type VertexFormat uint32
type VertexLayout ¶
type VertexLayout struct {
Stride uint64
Attrs []VertexAttr
}