Skip to content

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Jan 4, 2026

Summary

This PR implements the Core-HAL Bridge - the foundational layer connecting wgpu/core (validation/state tracking) with wgpu/hal (GPU backends).

Features (CORE-001 → CORE-007)

Task Description
CORE-001 Snatchable pattern for safe deferred resource destruction
CORE-002 Resource types with HAL handles
CORE-003 Core Device with HAL integration
CORE-004 Core Buffer with HAL integration
CORE-005 Core CommandEncoder with HAL dispatch
CORE-006 TrackerIndex Allocator for efficient state tracking
CORE-007 Buffer State Tracker

Code Quality

Metrics

  • Test coverage: 89.7%
  • golangci-lint: 0 issues
  • TODO/FIXME: 186 → 128 (remaining are in generated code)

Test Plan

  • Pre-release script passes
  • All tests pass
  • Build successful on all platforms
  • go vet clean

kolkov added 7 commits January 5, 2026 00:12
Implement the foundation for connecting wgpu/core validation layer to wgpu/hal
hardware abstraction layer. This enables core functions to create real GPU
resources instead of placeholders.

CORE-001: Snatchable[T] pattern
- Generic wrapper for safe deferred destruction of HAL resources
- SnatchLock/SnatchGuard for device-global coordination
- Thread-safe with RWMutex semantics

CORE-002: Device wraps HAL
- Device struct embeds Snatchable[hal.Device]
- NewDevice() constructor for HAL-integrated devices
- Destroy() with proper HAL cleanup
- Backward compatibility with ID-based API

CORE-003: Buffer wraps HAL
- Buffer struct embeds Snatchable[hal.Buffer]
- BufferInitTracker for initialization tracking
- BufferMapState for mapping state management
- TrackingData stub for future state tracking

CORE-004: CreateBuffer validation flow
- Device.CreateBuffer() with full WebGPU validation
- Size, usage, and mapping validation
- CreateBufferError with detailed error context
- types.BufferUsage.Contains() and ContainsUnknownBits()

Tests: 50+ new tests with 0 linter issues
Add HAL-integrated command encoder with proper state management:
- CoreCommandEncoder with Recording/Locked/Finished/Error/Consumed states
- CoreRenderPassEncoder and CoreComputePassEncoder for pass recording
- CoreCommandBuffer for finished command buffers
- CommandBufferMutable for resource tracking during encoding
- Device.CreateCommandEncoder() method
- CreateCommandEncoderError and EncoderStateError types

Comprehensive test coverage with 84 tests passing.
Add dense index allocation for efficient resource state tracking:
- TrackerIndex type with IsValid() helper
- TrackerIndexAllocator with LIFO reuse for cache locality
- SharedTrackerIndexAllocator for thread-safe sharing
- TrackerIndexAllocators for all resource types
- TrackingData for embedding in resources
- Comprehensive tests including concurrent access
Add buffer usage tracking for automatic barrier generation:
- BufferUses flags for granular usage states
- BufferTracker for device-level state tracking
- BufferUsageScope for per-command-buffer tracking
- StateTransition and PendingTransition for barrier insertion
- Merge() generates transitions when scopes are combined
- IntoHAL() converts transitions to HAL BufferBarriers
- ResourceMetadata for ownership tracking
- Comprehensive tests with benchmarks
Convert 27 TODO comments in core/ package to proper documentation:
- Mark legacy ID-based API functions as Deprecated
- Add Note: comments explaining HAL integration architecture
- Document that ID-based API is for validation, HAL-based for GPU ops

Files updated: adapter.go, command.go, device.go, instance.go,
pipeline.go, queue.go
HAL backends cleanup (58 TODOs removed):
- Vulkan: Document feature/limits mapping gaps with version targets
- DX12: Document advanced feature requirements
- GLES: Document GL version requirements and limitations

Added Known Limitations section to CHANGELOG.md.
Created GitHub issues #32-#36 for future implementation.

Files: 17 changed across hal/vulkan, hal/dx12, hal/gles
@kolkov kolkov merged commit 454c372 into main Jan 4, 2026
20 checks passed
@kolkov kolkov deleted the feat/TASK-CORE-hal-bridge branch January 4, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants