Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.0] - 2026-02-10

### Added

- **HalProvider interface** for direct HAL device/queue access ([gg#95](https://github.com/gogpu/gg/issues/95))
- `HalDevice() any` — returns underlying HAL device for direct GPU access
- `HalQueue() any` — returns underlying HAL queue for direct GPU access
- Optional interface — use type assertion on DeviceProvider:
`if hp, ok := provider.(gpucontext.HalProvider); ok { ... }`
- Enables GPU accelerators (e.g., gg SDF pipeline) to share devices with host applications
without creating their own wgpu instance

## [0.8.0] - 2026-02-06

### Added
Expand Down Expand Up @@ -93,6 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **TouchCancelled → TouchCanceled** — US English spelling (misspell linter)
- Removed unused `DeviceHandle` alias

[0.9.0]: https://github.com/gogpu/gpucontext/releases/tag/v0.9.0
[0.8.0]: https://github.com/gogpu/gpucontext/releases/tag/v0.8.0
[0.7.0]: https://github.com/gogpu/gpucontext/releases/tag/v0.7.0
[0.6.0]: https://github.com/gogpu/gpucontext/releases/tag/v0.6.0
Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go get github.com/gogpu/gpucontext
## Features

- **DeviceProvider** — Interface for injecting GPU device and queue
- **HalProvider** — Optional direct access to HAL device/queue for GPU accelerators
- **WindowProvider** — Window geometry, DPI scale factor, and redraw requests
- **PlatformProvider** — Clipboard, cursor, dark mode, and accessibility preferences
- **CursorShape** — 12 standard cursor shapes (arrow, pointer, text, resize, etc.)
Expand Down Expand Up @@ -65,6 +66,26 @@ func NewGPUCanvas(provider gpucontext.DeviceProvider) *Canvas {
}
```

### HalProvider (for GPU accelerators)

`HalProvider` is an optional interface on `DeviceProvider` that exposes low-level HAL types.
This enables GPU accelerators (like gg's SDF pipeline) to share the host device without creating their own:

```go
// In gogpu/gg - GPU accelerator checks for HAL access
func (a *SDFAccelerator) SetDeviceProvider(dp gpucontext.DeviceProvider) {
if hp, ok := dp.(gpucontext.HalProvider); ok {
device := hp.HalDevice().(hal.Device)
queue := hp.HalQueue().(hal.Queue)
a.initWithSharedDevice(device, queue)
}
}

// In gogpu/gogpu - implements HalProvider
func (app *App) HalDevice() any { return app.halDevice }
func (app *App) HalQueue() any { return app.halQueue }
```

### WindowProvider (for UI frameworks)

The `WindowProvider` interface enables UI frameworks to query window dimensions and DPI:
Expand Down Expand Up @@ -261,9 +282,9 @@ names := backends.Available() // ["vulkan", "software"]
gpucontext
(imports gputypes)
DeviceProvider, WindowProvider,
PlatformProvider, EventSource,
Texture, PointerEventSource, Registry
DeviceProvider, HalProvider,
WindowProvider, PlatformProvider,
EventSource, Texture, Registry
┌───────────────┼───────────────┐
│ │ │
Expand Down
27 changes: 27 additions & 0 deletions hal_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2026 The gogpu Authors
// SPDX-License-Identifier: MIT

package gpucontext

// HalProvider is an optional interface for DeviceProviders that can expose
// low-level HAL types directly. This enables GPU accelerators to share
// devices without creating their own.
//
// The returned any values are hal.Device and hal.Queue from wgpu/hal.
// Consumers type-assert to the concrete hal types they need.
//
// Example usage:
//
// if hp, ok := provider.(gpucontext.HalProvider); ok {
// device := hp.HalDevice().(hal.Device)
// queue := hp.HalQueue().(hal.Queue)
// }
type HalProvider interface {
// HalDevice returns the underlying HAL device for direct GPU access.
// Returns nil if HAL access is not available.
HalDevice() any

// HalQueue returns the underlying HAL queue for direct GPU access.
// Returns nil if HAL access is not available.
HalQueue() any
}
Loading