Skip to content

research: audit public API layer — logging, validation, error handling #97

@kolkov

Description

@kolkov

The public wgpu API layer was the last thing we built, and it shows. The HAL backends have mature logging (73 structured slog calls across Vulkan, Metal, DX12, GLES) and consistent validation — but the public layer that users actually interact with has none of that discipline.

This came up during PR #95 review — a contributor asked about validation style and we realized there isn't one. There are at least 4 different patterns in the same package.

What needs investigation

Logging:

  • Public API layer has zero slog calls — no diagnostics at all
  • HAL backends log everything (resource creation, errors, debug messages)
  • Users debugging issues get nothing from the layer they interact with

Validation:

  • WriteBuffer: compact combined nil check
  • ReadBuffer: separate checks, different error format
  • device.go: sentinel errors + fmt.Errorf mix
  • encoder.go: no validation at all, straight passthrough to HAL
  • No clear rule on what should be checked where

Error handling:

  • Mixed formats: "wgpu: queue not available" vs "wgpu: WriteBuffer: queue or buffer is nil" vs "wgpu: buffer descriptor is nil"
  • Some HAL errors wrapped with context, some passed through raw
  • Sentinel errors (ErrReleased) used inconsistently

What we need to figure out

  1. What should the public API layer actually validate vs delegate to HAL?
  2. Should we log at the public layer, and if so — what and at what level?
  3. One consistent error message format across all public methods
  4. How does Rust wgpu handle this? (spoiler: zero validation in public layer, everything in wgpu-core)
  5. Is our current split (public API → HAL) the right architecture, or do we need a core validation layer in between?

Deliverable

Research document + style guide before any code changes. We want to get this right, not just patch it.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: highImportant for next releasetype: refactorCode cleanup, no behavior change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions