feat: enterprise-grade validation layer (VAL-001..004, COV-001)#100
Merged
feat: enterprise-grade validation layer (VAL-001..004, COV-001)#100
Conversation
Prevent panics on nil user input in public API methods: - Device.CreateBindGroup: nil Layout check - Device.CreatePipelineLayout: nil element in BindGroupLayouts - Queue.Submit: nil element in commandBuffers - Surface.Configure: nil device parameter - Surface.Present: nil texture parameter Each check returns a descriptive error instead of panicking. Added unit tests for all 5 nil input cases.
…-001) Metal: 20 new test functions (textureFormat, blendFactor, topology, etc.) Vulkan: +4 tests (loadOp, storeOp, presentMode, boolToVk) DX12: +2 tests (textureFormatToDXGI, compositeAlphaMode) GLES: +5 format cases (Depth32FloatStencil8, BGRA8UnormSrgb, etc.)
Implement exhaustive validation in core/ layer before HAL calls: - 7 typed error types (CreateTextureError, CreateSamplerError, CreateShaderModuleError, CreateRenderPipelineError, CreateComputePipelineError, CreateBindGroupLayoutError, CreateBindGroupError) with specific error kinds and context fields - 7 validation functions in core/validate.go covering 30+ rules (texture dimensions/limits/multisampling, sampler LOD/anisotropy, shader source, pipeline stages, bind group layout) - ~63 table-driven tests in core/validate_test.go - Wired validation into device.go Create* methods - Extracted unnamedLabel constant for goconst compliance - Extracted helpers for gocognit/nestif compliance
Implement WebGPU deferred error pattern for nil input detection: - RenderPass: SetPipeline, SetBindGroup, SetVertexBuffer, SetIndexBuffer, DrawIndirect, DrawIndexedIndirect now record errors via encoder.setError() - ComputePass: SetPipeline, SetBindGroup, DispatchIndirect — same - CommandEncoder: CopyBufferToBuffer nil src/dst — same - Add public SetError() on CoreCommandEncoder (thread-safe wrapper) - Add setError() helper on CommandEncoder for pass encoder use - 11 new tests verify nil → Finish() returns error Previously nil inputs were silently ignored — user got no feedback when passing nil pipeline/buffer/bind group. Now errors surface at Finish() following the WebGPU spec deferred error pattern.
Refine HAL validation after core now validates exhaustively (VAL-002): - Change 21 nil checks to BUG: prefix across 6 backends — these should never fire; if they do, it signals a core validation gap - Remove 6 redundant spec checks (buffer size>0, texture dims>0) from Vulkan, Metal, DX12 — core/validate.go handles these - Add 9 missing nil checks to GLES (5), Software (2), Noop (2) - Update hal/doc.go with HAL validation contract documentation HAL contract: core validates spec rules, HAL retains only nil guards as defense-in-depth with diagnostic BUG: error messages.
Add entries for VAL-001 (5 nil panic fixes), COV-001 (26 backend tests), VAL-002 (core validation + typed errors), VAL-003 (deferred nil errors), VAL-004 (HAL defense-in-depth). Bump version from 0.19.8 to 0.20.0 since VAL-002 adds new public API (typed errors, validation functions).
Required for TextureUsage.ContainsUnknownBits() used in core validation.
… layer - Rename architecture.md → ARCHITECTURE.md - Rename compute-backends.md → COMPUTE-BACKENDS.md - Rename compute-shaders.md → COMPUTE-SHADERS.md - Update ARCHITECTURE.md with core validation and HAL contract details - Fix internal links in COMPUTE-SHADERS.md (lowercase → UPPERCASE)
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Enterprise-grade validation layer for wgpu, implementing exhaustive WebGPU spec validation before HAL calls. This is a major quality milestone — the first comprehensive validation infrastructure in the project.
What's included
VAL-001: Fix 5 critical nil panic paths
CreateBindGroup(nil layout),CreatePipelineLayout(nil bind group layout element),Queue.Submit(nil command buffer),Surface.Configure(nil device),Surface.Present(nil texture)VAL-002: Core validation + typed errors (30+ rules)
core/validate.gocovering textures, samplers, shaders, pipelines, bind groups, and bind group layoutsCreateTextureErrorwith 13 kinds)errors.As()for programmatic error handlingVAL-003: WebGPU deferred error pattern for nil inputs
End()/Finish()per WebGPU spec patternRenderPass.SetPipeline,SetBindGroup,SetVertexBuffer,SetIndexBuffer,DrawIndirect,DrawIndexedIndirect,ComputePass.SetPipeline,SetBindGroup,DispatchIndirect,CommandEncoder.CopyBufferToBufferVAL-004: HAL defense-in-depth
"BUG: ..."prefix to signal core validation gapsCOV-001: Backend format conversion tests
Dependency update
TextureUsage.ContainsUnknownBits())Architecture
Test plan
go build ./...passesgo test ./...— all tests pass (including ~85 new tests)GOWORK=off go build ./...passesGOWORK=off golangci-lint run --timeout=5m— 0 issuesgo fmt ./...clean