Commit 12e58bd
authored
feat: complete three-layer WebGPU public API (v0.21.0)
* feat(core): complete all 12 stub resource types (CORE-001)
Replace empty struct{} stubs in core/resource.go with full implementations
following the existing Buffer pattern:
- Texture: format, dimension, usage, size, mip levels, sample count
- Sampler, ShaderModule, QuerySet: HAL handle + properties
- BindGroupLayout, PipelineLayout, BindGroup: binding infrastructure
- RenderPipeline, ComputePipeline: pipeline types
- CommandEncoder, CommandBuffer: command recording types
- Surface: HAL surface (not Snatchable, owned by Instance)
Each type has: Snatchable HAL handle (where applicable), device reference,
WebGPU properties, constructor function, and Raw() accessor.
Foundation for CORE-002 (Surface lifecycle), CORE-003 (CommandEncoder
state machine), and CORE-004 (pipeline validation).
* feat(core): Surface lifecycle state machine with PrepareFrame hook (CORE-002)
Implement full surface lifecycle management in core.Surface:
- State machine: Unconfigured → Configured → Acquired → Configured
- Mutex-protected thread-safe transitions
- Configure/Unconfigure with device validation
- AcquireTexture with state check + PrepareFrame hook
- Present with acquired texture validation
- DiscardTexture for error recovery
- PrepareFrameFunc callback for platform DPI/scale integration
(Metal contentsScale, Windows WM_DPICHANGED, Wayland wl_output.scale)
- Auto-reconfigure on dimension change from PrepareFrame
Global registry changed from Registry[Surface] to Registry[*Surface]
to support sync.Mutex (non-copyable).
16 new tests covering all state transitions and error conditions.
* feat: migrate public API Surface to core.Surface delegation (CORE-005)
wgpu.Surface now delegates to core.Surface instead of using hal.Surface
directly. All lifecycle methods go through core validation and state
tracking:
- Configure/Unconfigure → core state machine validation
- GetCurrentTexture → PrepareFrame hook + state check + HAL acquire
- Present → acquired texture validation + HAL present
New public methods:
- SetPrepareFrame(fn) — platform hook for HiDPI/DPI changes
(Metal contentsScale, Windows WM_DPICHANGED, Wayland wl_output.scale)
- HAL() — escape hatch for backward-compatible direct HAL access
This enables gogpu PLAT-001 (PrepareFrame architecture) to register
platform callbacks on the wgpu Surface.
* feat(core): CommandEncoder/CommandBuffer state machine (CORE-003)
CommandEncoder tracks pass state with validated transitions:
- Recording → BeginRenderPass → InRenderPass → EndRenderPass → Recording
- Recording → BeginComputePass → InComputePass → EndComputePass → Recording
- Recording → Finish → Finished (validates no open passes)
- Any state → RecordError → Error (captures first error message)
CommandBuffer tracks submission state:
- Available → MarkSubmitted → Submitted (prevents double-submit)
13 new tests covering all state transitions and error conditions.
* feat(core): resource accessor methods and Destroy for all types (CORE-004)
Add read-only accessors and idempotent Destroy for 9 resource types:
- Texture: Format, Dimension, Usage, Size, MipLevelCount, SampleCount
- BindGroupLayout: Entries, EntryCount
- QuerySet: QueryType, Count
- All types: Label, Destroy, IsDestroyed
Destroy follows Buffer snatch-and-release pattern: read-lock device,
release lock, write-lock to snatch HAL handle, destroy via device.
Safe to call multiple times (idempotent).
Methods in separate resource_accessors.go with full test coverage.
* feat: complete public API for gogpu renderer migration
Add missing public API methods needed for full gogpu migration from
HAL direct to wgpu public API:
- Fence type wrapper with Release() (fence.go)
- Device: CreateFence, ResetFence, GetFenceStatus, WaitForFence,
FreeCommandBuffer (for FencePool pattern)
- Queue: SubmitWithFence for non-blocking async submission
- Surface: DiscardTexture for error recovery
All existing resource types already had Release() methods.
CommandEncoder/RenderPassEncoder/CommandBuffer wrappers already existed.
This completes the wgpu public API surface needed for gogpu to stop
using HAL directly and go through the proper wgpu → core → HAL chain.
* feat: HAL accessor methods + wgpu API triangle examples
- texture.go: HalTextureView() on *TextureView for gg integration
- wrap.go: HalDevice(), HalQueue() on *Device for legacy HAL access
- surface.go: fix nil TextureViewDescriptor (pass nil to HAL, not empty),
remove unnecessary fence in GetCurrentTexture, remove debug logging
- cmd/wgpu-triangle/: single-threaded wgpu public API triangle example
- cmd/wgpu-triangle-mt/: multi-threaded wgpu public API triangle example
(same architecture as gogpu renderer — validates wgpu API thread safety)
* feat: add CopyTextureToBuffer, TransitionTextures, HalTexture for gg migration
CommandEncoder: CopyTextureToBuffer, TransitionTextures, DiscardEncoding.
Texture: HalTexture() accessor for texture barrier interop.
Required by gg GPU-API-001 migration (readback + Vulkan layout transitions).
* feat: promote HAL types to wgpu public API (WGPU-API-002)
Replace type aliases to hal with proper struct definitions + toHAL() converters:
- Extent3D, Origin3D, ImageDataLayout, DepthStencilState, StencilFaceState
- New: TextureBarrier, TextureRange, TextureUsageTransition, BufferTextureCopy
- StencilOperation kept as alias (uint8 enum, same as CompareFunction)
- CommandEncoder signatures use wgpu types (no hal in public API)
- New wgpu.SetLogger()/Logger() for stack-wide logging propagation
- Device.CreateTexture uses desc.toHAL() (removed duplication)
* docs: add HAL escape hatch note to timestamp queries guide
* chore: update naga v0.14.6 → v0.14.7
Fixes MSL sequential per-type binding indices across bind groups.
* docs: update CHANGELOG and ROADMAP for v0.21.0 release
* fix: lint issues in triangle examples1 parent c80d13c commit 12e58bd
29 files changed
Lines changed: 4496 additions & 107 deletions
File tree
- cmd
- wgpu-triangle-mt
- wgpu-triangle
- core
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
10 | 64 | | |
11 | 65 | | |
12 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
32 | 45 | | |
33 | 46 | | |
34 | | - | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
0 commit comments