Skip to content

fix(browser): nil descriptor guards for all Device.Create* methods - #316

Merged
kolkov merged 3 commits into
mainfrom
fix/browser-nil-descriptor-315
Aug 13, 2026
Merged

fix(browser): nil descriptor guards for all Device.Create* methods#316
kolkov merged 3 commits into
mainfrom
fix/browser-nil-descriptor-315

Conversation

@kolkov

@kolkov kolkov commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #315 — browser WASM shim panics on nil TextureViewDescriptor (and other descriptors).

  • Root cause: device_browser.go dereferences descriptor fields unconditionally, while native and Rust backends handle nil gracefully
  • Fix: Add nil descriptor guards to all 10 Device.Create* methods, matching native/Rust behavior:
    • CreateTextureView / CreateSampler: nil → default descriptor (WebGPU spec: "default view" / "default sampler")
    • CreateBuffer / CreateTexture / CreateShaderModule / CreateBindGroupLayout / CreatePipelineLayout / CreateBindGroup / CreateRenderPipeline / CreateComputePipeline: nil → return error (matches native/Rust)
  • Scope: Issue reported for CreateTextureView only, but full audit found 7 additional methods with the same vulnerability

Unblocks ironwail-go walkthrough HUD (color/char texture uploads) in Chrome/Edge.

Audit

Method nil behavior Consistent across native/rust/browser?
CreateBuffer error
CreateTexture error
CreateTextureView default view
CreateSampler default sampler
CreateShaderModule error
CreateBindGroupLayout error
CreatePipelineLayout error
CreateBindGroup error
CreateRenderPipeline error
CreateComputePipeline error
CreateCommandEncoder default label="" ✅ (already correct)

Non-creator browser methods (queue, encoder, render/compute pass) were also audited — all already have proper nil guards.

Test plan

  • GOOS=js GOARCH=wasm go build github.com/gogpu/wgpu — builds clean
  • go build ./... — Windows, Linux, macOS
  • go test ./... — all pass
  • golangci-lint run --timeout=5m — 0 issues

kolkov added 2 commits August 13, 2026 08:08
)

Browser WASM shim panicked on nil descriptors in CreateTextureView and
other Create* methods. Native and Rust backends already handle nil
correctly. This aligns browser behavior:

- CreateTextureView/CreateSampler: nil desc → default (WebGPU spec)
- CreateBuffer/Texture/ShaderModule/BindGroupLayout/PipelineLayout/
  BindGroup/RenderPipeline/ComputePipeline: nil desc → error

Reported by @darkliquid — blocks ironwail-go WASM HUD rendering.
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

CI lint runs on ubuntu-latest only — darwin build-tagged files were
never checked. Fixed all 10 issues found by macOS cross-platform lint:

- misspell: honour → honor (US locale per .golangci.yml)
- nolintlint: remove 3 stale //nolint:nestif (nestif excluded for hal/ in config)
- revive: rename max → maxCount (shadows Go 1.21 builtin)
- unconvert: remove unnecessary uintptr(unsafe.Sizeof()) conversion
- unparam: add //nolint:unparam for writeTextureShared (error return for API parity)
- unused: remove dead test helper createMetalTextureCopyTestArray
- whitespace: remove leading newline in applyBindGroup
@kolkov
kolkov merged commit ea7a3cb into main Aug 13, 2026
15 checks passed
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.

bug(js/wasm): CreateTextureView panics on nil descriptor (browser shim diverges from native)

1 participant