Documentation
¶
Overview ¶
Package vkdevice selects a Vulkan graphics device by compositor-advertised DRM dev_t. It rejects cross-GPU fallback rather than silently copying images.
Index ¶
- Constants
- Variables
- func Matches(main Identity, primary, render Identity, hasPrimary, hasRender bool) bool
- func SwizzleBGRA(img *image.NRGBA)
- type Batch
- type BinaryFence
- type Device
- func (d *Device) AllocateImage(width, height int32, selected Modifier) (img *Image, err error)
- func (d *Device) Close()
- func (d *Device) ExportableModifiers() (map[uint64]bool, error)
- func (d *Device) NewBinaryFence(export bool) (*BinaryFence, error)
- func (d *Device) NewFrame(img *Image) (f *Frame, err error)
- func (d *Device) NewListPipeline(width, height int32) (p *Pipeline, err error)
- func (d *Device) NewReadback(width, height int32) (r *Readback, err error)
- func (d *Device) SubmitEmpty(signal *BinaryFence, wait *BinaryFence) error
- type Format
- type Frame
- type Identity
- type Image
- type ImageTexture
- type Instance
- type Modifier
- type Pipeline
- type Readback
- type Validation
Constants ¶
const ( XRGB8888 uint32 = 0x34325258 ARGB8888 uint32 = 0x34325241 )
const AtlasPages = 4
const AtlasSize = 1024
AtlasSize and AtlasPages are shared with the CPU preparer at the session boundary.
Variables ¶
var RequiredExtensions = []string{
"VK_EXT_physical_device_drm",
"VK_KHR_external_memory_fd",
"VK_EXT_external_memory_dma_buf",
"VK_EXT_image_drm_format_modifier",
"VK_KHR_external_semaphore_fd",
}
RequiredExtensions are mandatory on the matched device. Vulkan 1.3 supplies dynamic rendering and synchronization2 as core features.
Functions ¶
func SwizzleBGRA ¶
SwizzleBGRA converts B8G8R8A8 pixels to RGBA in place.
Types ¶
type Batch ¶
type Batch struct {
First, Count uint32
Source image.Image
Texture *ImageTexture
}
Batch preserves the painter's order. Non-image runs use set 0 (atlas); image draws bind Texture at set 1. Source is borrowed until cache resolution. The image's interface value must be comparable and its pixels immutable. First indexes the shared instance buffer; Count is the instance count.
type BinaryFence ¶
type BinaryFence struct {
Device *Device
Semaphore vulkan.Semaphore
// contains filtered or unexported fields
}
BinaryFence exports a SYNC_FD after its queue submit, never an OPAQUE_FD. Vulkan consumes a successfully imported SYNC_FD; a failed import leaves it with the caller. Exported SYNC_FDs belong to the caller until DRM accepts.
func (*BinaryFence) Close ¶
func (s *BinaryFence) Close()
func (*BinaryFence) Export ¶
func (s *BinaryFence) Export() (int, error)
func (*BinaryFence) ImportTemporary ¶
func (s *BinaryFence) ImportTemporary(fd int) error
type Device ¶
type Device struct {
Instance vulkan.Instance
InstanceDispatch *vulkan.InstanceDispatch
Physical vulkan.PhysicalDevice
Logical vulkan.Device
Dispatch *vulkan.DeviceDispatch
Queue vulkan.Queue
QueueFamily uint32
Render Identity
Validation *Validation
// contains filtered or unexported fields
}
func (*Device) AllocateImage ¶
func (*Device) ExportableModifiers ¶
ExportableModifiers checks the exact usage required by drawing and readback; the presence of a modifier alone is not sufficient to allocate a DMA-BUF.
func (*Device) NewBinaryFence ¶
func (d *Device) NewBinaryFence(export bool) (*BinaryFence, error)
func (*Device) NewListPipeline ¶
NewListPipeline creates an instanced, premultiplied-alpha quad pipeline. It fixes the Vulkan viewport and scissor to the image size: the pinned Vulkan binding does not expose vkCmdSetViewport/Scissor, so resize builds a new pipeline rather than recording unsupported dynamic-state calls.
func (*Device) NewReadback ¶
func (*Device) SubmitEmpty ¶
func (d *Device) SubmitEmpty(signal *BinaryFence, wait *BinaryFence) error
SubmitEmpty is a hardware probe for the fence bridge. The production renderer must submit its draw command buffer instead of an empty submit. The queue is idle before exporting so this test isolates FD interop from in-flight rendering; it does not authorize a CPU-wait presentation fallback.
type Frame ¶
type Frame struct {
Pool vulkan.CommandPool
Commands vulkan.CommandBuffer
Done vulkan.Fence
Signal *BinaryFence
View vulkan.ImageView
Readback *Readback
// contains filtered or unexported fields
}
Frame records into its own command buffer and signals a binary semaphore. Do not reset the command buffer or destroy the semaphore until its GPU fence completes. The compositor's release point is an independent ownership gate.
func (*Frame) ExportSignal ¶ added in v0.5.1
ExportSignal exports the submitted frame's acquire SYNC_FD. The export resets the semaphore, which lets the next recording of this frame reuse it.
func (*Frame) RecordList ¶
func (f *Frame) RecordList(img *Image, pipe *Pipeline, width, height int32, instances []Instance, uploads []text.Upload, batches []Batch, initial, capture bool) error
RecordList records an ordered list of physical-pixel quads. Reuse is gated by Ready, including any instance-buffer growth.
func (*Frame) Submit ¶
func (f *Frame) Submit(wait *BinaryFence) error
Submit has no CPU wait: the next render waits on a temporarily imported release SYNC_FD, and the compositor waits on the exported acquire SYNC_FD.
type Identity ¶
type Identity struct{ Major, Minor uint32 }
Identity uses the Linux gnu_dev_major/minor dev_t encoding. A Wayland main_device is an 8-byte native-endian dev_t, not a Vulkan device index.
func DecodeDevice ¶
func DeviceIdentity ¶
type Image ¶
type Image struct {
Image vulkan.Image
Memory vulkan.DeviceMemory
FD int // exported DMA-BUF, -1 when none
Modifier uint64
Offset, Stride uint32
// contains filtered or unexported fields
}
Image owns a Vulkan image, dedicated exportable memory and the exported DMA-BUF file descriptor. FD stays owned by the Image and is closed by Close; a transport that consumes descriptors must be handed a dup. The compositor's import keeps its own kernel reference, so Close may run while the compositor still holds the buffer, but the GPU must be done with the image first.
type ImageTexture ¶
type ImageTexture struct {
Set vulkan.DescriptorSet
}
ImageTexture owns a GPU image and the descriptor slot assigned by the cache. Its lifetime is gated by the last frame fence that sampled it.
type Instance ¶
type Instance struct {
Bounds [4]float32
Color [4]float32
Clip [4]float32
Radii [4]float32
// UV stores normalized atlas min/max. KindLayer.x is 1 for glyphs;
// KindLayer.y selects the array layer. Rectangles keep both zero.
UV [4]float32
KindLayer [4]float32
Widths [4]float32 // top, right, bottom, left
Sides [4][4]float32 // top, right, bottom, left straight RGBA
Shape [4]float32 // original box for outline/shadow
Shadow [4]float32 // offset x/y, blur, spread
}
Instance is a physical-pixel list quad. Color is straight sRGB; the shader premultiplies it. Clip uses x/y/width/height, radii are TL/TR/BR/BL. KindLayer.x = 6 samples set 1 binding 0 as a 2D image texture.
type Modifier ¶
Modifier is the one-plane GPU/compositor common image layout chosen in compositor tranche order. XRGB and ARGB both use B8G8R8A8_UNORM on Vulkan.
type Pipeline ¶
type Pipeline struct {
Handle vulkan.Pipeline
Layout vulkan.PipelineLayout
// contains filtered or unexported fields
}
type Readback ¶
type Readback struct {
Buffer vulkan.Buffer
Memory vulkan.DeviceMemory
// contains filtered or unexported fields
}
Readback is only allocated for tests. Its transfer copy is recorded after drawing and before the acquire semaphore signals; mapping waits for the submission fence, never for compositor release.
type Validation ¶
type Validation struct {
// contains filtered or unexported fields
}
func (*Validation) Messages ¶
func (v *Validation) Messages() []string