Skip to content

feat(ShaderView): warn once on a software (CPU) WebGPU adapter - #26

Closed
blazejkustra wants to merge 1 commit into
mainfrom
feat/warn-software-adapter
Closed

feat(ShaderView): warn once on a software (CPU) WebGPU adapter#26
blazejkustra wants to merge 1 commit into
mainfrom
feat/warn-software-adapter

Conversation

@blazejkustra

Copy link
Copy Markdown
Owner

What

Adds warnIfNotHardwareAccelerated(adapter), called once from useWGPUSetup during development. When WebGPU resolves to a software adapter (most notably SwiftShader on Android emulators), shaders run dramatically slower — the classic "why is my effect at 5fps?" footgun. This surfaces it instead of leaving it silent.

Detection

Matches known software-renderer fingerprints (swiftshader, llvmpipe, lavapipe, microsoft basic render, ...) against adapter.info, plus isFallbackAdapter when a backend reports it (react-native-webgpu currently doesn't — it's undefined at runtime, so we read it defensively).

It deliberately does not flag the iOS simulator, which reports device: "Apple iOS simulator GPU" / description: "Metal driver…" and renders on the host's real GPU. No-op in production (__DEV__).

Verification

  • Unit tests (7) — cover the real SwiftShader and iOS-simulator info strings captured on-device, llvmpipe, fallback-adapter, warn-once, and the __DEV__ guard. All pass.
  • iOS (iPhone 17, argent) — the new code is present in the running bundle, effects render, and the Metal adapter correctly produces no warning.
  • Why the live software path isn't device-tested: the Android emulator available here exposes no WebGPU at all (navigator.gpu is undefined on its JS runtime), and the iOS simulator uses the host GPU (hardware). Neither can present a software WebGPU adapter, so that path is covered by unit tests against the real fingerprint strings.

Files

  • src/utils/warnIfNotHardwareAccelerated.ts (new)
  • src/utils/__tests__/warnIfNotHardwareAccelerated.test.ts (new — first unit test in the repo)
  • src/hooks/useWGPUSetup.tsx — call site
  • tsconfig.json — add "jest" to types so the test typechecks

Adds warnIfNotHardwareAccelerated(adapter), called once from useWGPUSetup
during development. When WebGPU resolves to a software adapter (most
notably SwiftShader on Android emulators) shaders run dramatically
slower — a common "why is my effect at 5fps" footgun. The warning makes
it visible instead of silent.

Detection matches known software-renderer fingerprints (SwiftShader,
llvmpipe, lavapipe, Microsoft Basic Render, ...) against adapter.info,
plus isFallbackAdapter when reported. It deliberately does NOT flag the
iOS simulator, which reports "Apple iOS simulator GPU" / "Metal driver"
and renders on the host's real GPU. No-op in production.

Verified:
- Unit tests (7) cover the real SwiftShader and iOS-simulator info
  strings captured on-device, fallback-adapter, warn-once, and the
  __DEV__ guard.
- On iOS (iPhone 17) the new code is in the running bundle, effects
  render, and the Metal adapter correctly produces no warning. The
  Android emulator here exposes no WebGPU (navigator.gpu undefined), so a
  live software-adapter warning can't be exercised on the available
  devices — hence the unit coverage of that path.

tsconfig: add "jest" to types so the first unit test typechecks.
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