vkdevice

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

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

View Source
const (
	XRGB8888 uint32 = 0x34325258
	ARGB8888 uint32 = 0x34325241
)
View Source
const AtlasPages = 4
View Source
const AtlasSize = 1024

AtlasSize and AtlasPages are shared with the CPU preparer at the session boundary.

Variables

View Source
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 Matches

func Matches(main Identity, primary, render Identity, hasPrimary, hasRender bool) bool

func SwizzleBGRA

func SwizzleBGRA(img *image.NRGBA)

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 Open

func Open(main Identity) (_ *Device, err error)

func (*Device) AllocateImage

func (d *Device) AllocateImage(width, height int32, selected Modifier) (img *Image, err error)

func (*Device) Close

func (d *Device) Close()

func (*Device) ExportableModifiers

func (d *Device) ExportableModifiers() (map[uint64]bool, error)

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) NewFrame

func (d *Device) NewFrame(img *Image) (f *Frame, err error)

func (*Device) NewListPipeline

func (d *Device) NewListPipeline(width, height int32) (p *Pipeline, err error)

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 (d *Device) NewReadback(width, height int32) (r *Readback, err error)

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 Format added in v0.5.0

type Format struct {
	FourCC   uint32
	Modifier uint64
}

Format is one DRM format and modifier pair the compositor accepts.

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) Close

func (f *Frame) Close()

func (*Frame) ExportSignal added in v0.5.1

func (f *Frame) ExportSignal() (int, error)

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) Ready

func (f *Frame) Ready() (bool, error)

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.

func (*Frame) Wait

func (f *Frame) Wait() error

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 DecodeDevice(device []byte) (Identity, error)

func DeviceIdentity

func DeviceIdentity(device uint64) Identity

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.

func (*Image) Close

func (img *Image) Close()

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

type Modifier struct {
	DRMFormat uint32
	Value     uint64
}

Modifier is the one-plane GPU/compositor common image layout chosen in compositor tranche order. XRGB and ARGB both use B8G8R8A8_UNORM on Vulkan.

func ChooseModifier

func ChooseModifier(formats []Format, transparent bool, supported map[uint64]bool) (Modifier, error)

ChooseModifier picks the first format in the compositor's preference order whose modifier the GPU can also export.

type Pipeline

type Pipeline struct {
	Handle vulkan.Pipeline
	Layout vulkan.PipelineLayout
	// contains filtered or unexported fields
}

func (*Pipeline) Close

func (p *Pipeline) Close()

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.

func (*Readback) Close

func (r *Readback) Close()

func (*Readback) Copy

func (r *Readback) Copy() (*image.NRGBA, error)

Copy returns the completed readback as an owned image whose pixels are still in B8G8R8A8 order. It performs one bulk copy; call SwizzleBGRA off the state owner before encoding.

type Validation

type Validation struct {
	// contains filtered or unexported fields
}

func (*Validation) Messages

func (v *Validation) Messages() []string

Jump to

Keyboard shortcuts

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