Skip to content

feat: enterprise-grade validation layer (VAL-001..004, COV-001)#100

Merged
kolkov merged 8 commits intomainfrom
feat/validation-layer
Mar 10, 2026
Merged

feat: enterprise-grade validation layer (VAL-001..004, COV-001)#100
kolkov merged 8 commits intomainfrom
feat/validation-layer

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Mar 10, 2026

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)

  • 7 validation functions in core/validate.go covering textures, samplers, shaders, pipelines, bind groups, and bind group layouts
  • 7 typed error types with specific error kinds and context fields (e.g., CreateTextureError with 13 kinds)
  • All support errors.As() for programmatic error handling

VAL-003: WebGPU deferred error pattern for nil inputs

  • 10 pass encoder methods that silently ignored nil now record deferred errors
  • Errors surface at End() / Finish() per WebGPU spec pattern
  • Covers RenderPass.SetPipeline, SetBindGroup, SetVertexBuffer, SetIndexBuffer, DrawIndirect, DrawIndexedIndirect, ComputePass.SetPipeline, SetBindGroup, DispatchIndirect, CommandEncoder.CopyBufferToBuffer

VAL-004: HAL defense-in-depth

  • HAL nil checks now use "BUG: ..." prefix to signal core validation gaps
  • Removed 6 redundant spec checks from Vulkan, Metal, DX12 (core validates these)
  • Added 9 missing nil checks to GLES, Software, Noop backends

COV-001: Backend format conversion tests

  • 26 new test functions across Metal (20), Vulkan (4), DX12 (2), GLES (5 cases)

Dependency update

  • gputypes v0.2.0 → v0.3.0 (TextureUsage.ContainsUnknownBits())

Architecture

User Code → wgpu/ (public API, nil checks)
         → core/ (exhaustive spec validation, typed errors)
         → hal/  (defense-in-depth BUG: nil guards only)

Test plan

  • go build ./... passes
  • go test ./... — all tests pass (including ~85 new tests)
  • GOWORK=off go build ./... passes
  • GOWORK=off golangci-lint run --timeout=5m — 0 issues
  • go fmt ./... clean

kolkov added 8 commits March 10, 2026 21:10
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)
@kolkov kolkov merged commit 1070724 into main Mar 10, 2026
10 checks passed
@codecov
Copy link

codecov bot commented Mar 10, 2026

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.

1 participant