thread

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package thread provides thread abstraction for GPU operations. Based on Ebiten's thread architecture for professional responsiveness.

Architecture:

  • Main thread: Window events, user input (must be OS main thread on Windows)
  • Render thread: All GPU operations (device, swapchain, commands)

This separation ensures window responsiveness during heavy GPU operations like swapchain recreation, which requires vkDeviceWaitIdle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RenderLoop

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

RenderLoop manages the separation between UI and render threads. Based on Ebiten's architecture for professional responsiveness.

Key pattern: All GPU operations (including vkDeviceWaitIdle) happen on the render thread, never blocking the UI thread.

func NewRenderLoop

func NewRenderLoop() *RenderLoop

NewRenderLoop creates a new render loop with a dedicated render thread.

func (*RenderLoop) ConsumePendingResize

func (rl *RenderLoop) ConsumePendingResize() (width, height uint32, ok bool)

ConsumePendingResize returns the pending resize dimensions and clears the flag. Returns (0, 0, false) if no resize is pending.

func (*RenderLoop) HasPendingResize

func (rl *RenderLoop) HasPendingResize() bool

HasPendingResize returns true if a resize is pending.

func (*RenderLoop) IsRenderingPaused

func (rl *RenderLoop) IsRenderingPaused() bool

IsRenderingPaused returns true if rendering is paused.

func (*RenderLoop) PauseRendering

func (rl *RenderLoop) PauseRendering()

PauseRendering pauses render operations (during modal resize).

func (*RenderLoop) RequestResize

func (rl *RenderLoop) RequestResize(width, height uint32)

RequestResize queues a resize to be applied on the render thread. This is called from the UI thread (WM_SIZE handler). The actual swapchain recreation happens in ApplyPendingResize.

func (*RenderLoop) ResumeRendering

func (rl *RenderLoop) ResumeRendering()

ResumeRendering resumes render operations.

func (*RenderLoop) RunOnRenderThread

func (rl *RenderLoop) RunOnRenderThread(f func() any) any

RunOnRenderThread executes f on the render thread and waits for completion. Use for GPU operations that need synchronous results.

func (*RenderLoop) RunOnRenderThreadAsync

func (rl *RenderLoop) RunOnRenderThreadAsync(f func())

RunOnRenderThreadAsync executes f on the render thread without waiting. Use for fire-and-forget GPU operations.

func (*RenderLoop) RunOnRenderThreadVoid

func (rl *RenderLoop) RunOnRenderThreadVoid(f func())

RunOnRenderThreadVoid executes f on the render thread and waits for completion. Use for GPU operations without return values.

func (*RenderLoop) Stop

func (rl *RenderLoop) Stop()

Stop stops the render loop and its thread.

type Thread

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

Thread represents a dedicated OS thread for specific operations. All function calls are serialized and executed on the same thread.

func New

func New() *Thread

New creates a new thread and starts it. The thread is locked to an OS thread (runtime.LockOSThread).

func (*Thread) Call

func (t *Thread) Call(f func() any) any

Call executes f on the thread and waits for completion. Returns the result from f.

func (*Thread) CallAsync

func (t *Thread) CallAsync(f func())

CallAsync executes f on the thread without waiting. Use for fire-and-forget operations.

func (*Thread) CallVoid

func (t *Thread) CallVoid(f func())

CallVoid executes f on the thread and waits for completion. Use when no return value is needed.

func (*Thread) IsRunning

func (t *Thread) IsRunning() bool

IsRunning returns true if the thread is running.

func (*Thread) Stop

func (t *Thread) Stop()

Stop stops the thread.

Jump to

Keyboard shortcuts

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