npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@forgeax/engine-rhi-wgpu

v0.2.2

Published

TS-only thin shell implementation of @forgeax/engine-rhi — depends on @forgeax/engine-wgpu-wasm for the merged wgpu 29 + naga 29 wasm bindings; spec-aligned wasm-bindgen surface, math-free.

Readme

@forgeax/engine-rhi-wgpu

import { rhi, ensureReady, acquireCanvasContext } from '@forgeax/engine-rhi-wgpu' + await ensureReady() + const ctx = (await rhi.acquireCanvasContext(canvas)).unwrap() -- non-browser rendering path via wgpu-wasm.

Overview

This package is the dual-impl partner of @forgeax/engine-rhi-webgpu. Both export the same @forgeax/engine-rhi surface; the runtime createRenderer auto-select facade picks one at runtime based on navigator.gpu availability.

AI engine users do NOT import this package directly -- Engine.create({ canvas }) / createRenderer(canvas) auto-selects Channel 2 (rhi-webgpu, navigator.gpu) or Channel 3 (rhi-wgpu, this package) transparently.

Channel architecture

createRenderer uses a three-channel selection (plan-strategy section 7):

| Channel | Trigger | Backend | Context acquisition | |:--|:--|:--|:--| | 1 | options.rhi explicit escape hatch | caller-supplied | caller-supplied | | 2 | navigator.gpu present | rhi-webgpu (static import) | canvas.getContext('webgpu') | | 3 | navigator.gpu absent, or Channel 2 fails | rhi-wgpu (dynamic import) | wasm createSurface(canvas) |

Channel 3 loads the engine-wgpu-wasm bundle lazily (via ensureReady()). The wasm bundle (~0.53 MB gzip) is only downloaded when neither Channel 1 nor 2 succeeds, keeping browser-only bundles lean.

acquireCanvasContext(canvas)

Single-entry surface for context acquisition. Replaces the deleted createCanvasContext.

function acquireCanvasContext(
  canvas: HTMLCanvasElement
): Result<RhiCanvasContext, RhiError>

The wasm surface path internally:

  1. Gets the RhiWgpuInstance from the wasm module
  2. Calls instance.createSurface(canvas) to create a wgpu Surface handle
  3. Returns a branded RhiCanvasContext wrapping the Surface

On failure returns RhiError({ code: 'rhi-not-available' }) with .hint describing the cause.

AI users call this through pack.rhi.acquireCanvasContext(canvas) inside the runtime -- the runtime auto-selects between rhi-webgpu (which uses canvas.getContext('webgpu')) and rhi-wgpu (this path).

The command encoder forwards real render and compute passes into wgpu-wasm. Compute passes support pipeline/bind-group binding plus direct and indirect workgroup dispatch; they are not structural no-ops.

requestAdapter and compatibleSurface

function requestAdapter(
  opts?: { compatibleSurface?: HTMLCanvasElement }
): Promise<Result<RhiAdapter, RhiError>>

When compatibleSurface is provided:

  • The wasm path calls RhiWgpuInstance.requestAdapterWithCanvas(canvas) instead of requestAdapter()
  • The rhi-webgpu fast path ignores this parameter (not needed for navigator.gpu)

This is needed by the wgpu GL backend, which requires a compatible_surface to enumerate adapters (plan-strategy D-9, requirements AC-11).

Relationship with @forgeax/engine-wgpu-wasm

This package is a TS-only thin shell. It:

  • Imports @forgeax/engine-wgpu-wasm for wasm-bindgen types + ensureReady
  • Wraps raw wasm exports into the @forgeax/engine-rhi interface shape
  • Does NOT contain its own wasm bundle or Rust source

See packages/wgpu-wasm/README.md for the full wasm-bindgen method table.

Exports

| Export | Kind | Description | |:--|:--|:--| | rhi | RhiInstance singleton | requestAdapter, acquireCanvasContext (the rhi-wgpu backend pack) | | ensureReady() | async function | Lazy-loads the wasm bundle; must be awaited before using rhi | | requestAdapter(opts?) | async function | Adapter request with optional compatibleSurface | | acquireCanvasContext(canvas) | function | Canvas context acquisition via wasm Surface path | | createShaderModule(device, desc) | async function | Async shader module factory | | err, ok, RhiErrorClass | re-export | From @forgeax/engine-rhi |

Constraints

  • acquireCanvasContext must be called BEFORE requestAdapter when using Channel 3 (the wasm Surface is created first; the adapter is requested with compatibleSurface to ensure GL context compatibility)
  • The wasm bundle is lazily loaded and only downloaded when needed
  • device.caps reports false for features unsupported by the wgpu GL backend

destroyBuffer / destroyTexture (feat-20260612)

Per-handle destroyed-state bookkeeping in the TS shim layer mirrors rhi-webgpu behavior. Wgpu's Rust Buffer::destroy() / Texture::destroy() are idempotent void (not drop-trait panic, confirmed by research F-1 correction). The shim adds fail-fast on second destroy with 'destroy-after-destroy' error code via a per-handle destroyed: boolean field -- never crossing the wasm boundary for state checking (plan-strategy D-6).

Implementation locations:

  • packages/rhi-wgpu/src/device.ts -- destroyBuffer / destroyTexture methods
  • packages/rhi-wgpu/src/buffer.ts -- per-handle destroyed flag in the buffer wrapper