feat(ShaderView): warn once on a software (CPU) WebGPU adapter - #26
Closed
blazejkustra wants to merge 1 commit into
Closed
feat(ShaderView): warn once on a software (CPU) WebGPU adapter#26blazejkustra wants to merge 1 commit into
blazejkustra wants to merge 1 commit into
Conversation
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.
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.
What
Adds
warnIfNotHardwareAccelerated(adapter), called once fromuseWGPUSetupduring 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, ...) againstadapter.info, plusisFallbackAdapterwhen a backend reports it (react-native-webgpu currently doesn't — it'sundefinedat 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
SwiftShaderand iOS-simulatorinfostrings captured on-device,llvmpipe, fallback-adapter, warn-once, and the__DEV__guard. All pass.navigator.gpuisundefinedon 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 sitetsconfig.json— add"jest"totypesso the test typechecks