fix(browser): nil descriptor guards for all Device.Create* methods - #316
Merged
Conversation
) 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 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #315 — browser WASM shim panics on nil
TextureViewDescriptor(and other descriptors).device_browser.godereferences descriptor fields unconditionally, while native and Rust backends handle nil gracefullyDevice.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)CreateTextureViewonly, but full audit found 7 additional methods with the same vulnerabilityUnblocks ironwail-go walkthrough HUD (color/char texture uploads) in Chrome/Edge.
Audit
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 cleango build ./...— Windows, Linux, macOSgo test ./...— all passgolangci-lint run --timeout=5m— 0 issues