Skip to content

Fix add WebGPU renderer support in PerfHeadless#71

Open
YusefNsar wants to merge 1 commit intoutsuboco:mainfrom
YusefNsar:main
Open

Fix add WebGPU renderer support in PerfHeadless#71
YusefNsar wants to merge 1 commit intoutsuboco:mainfrom
YusefNsar:main

Conversation

@YusefNsar
Copy link
Copy Markdown

Summary

Adds compatibility with Three.js WebGPURenderer in PerfHeadless, while keeping full backward compatibility with WebGLRenderer.

Detection

WebGPURenderer.getContext() exists but returns null (unlike WebGLRenderer which returns a WebGL2RenderingContext). Detection is done by checking the return value and the presence of getExtension/getParameter on it:

const glContext = gl.getContext?.() as WebGL2RenderingContext | null
const isWebGPU = !glContext || typeof glContext.getExtension !== 'function' || typeof glContext.getParameter !== 'function'

Changes

  • GPU timing: EXT_disjoint_timer_query_webgl2 is WebGL-only. When WebGPU is detected, gl is not passed to GLPerf (skipping the WebGL timer query path). Instead, info.render.timestamp (written by WebGPU's built-in timestamp queries) is used as the GPU time value via logger.gpu || glRender.timestamp.

  • Timestamp resolution: After each frame on WebGPU, resolveTimestampsAsync('render') is called so that info.render.timestamp is populated before the next paramLogger invocation.

  • Renderer info: WEBGL_debug_renderer_info and ctx.getParameter are WebGL-only. On WebGPU, the infos block falls back to static 'WebGPU' strings. GPUAdapter.requestAdapterInfo() would provide real values but is async — left as a TODO.

  • Draw call stats (calls, triangles, points, lines): gl.info.render is available on both renderers with the same field names, so these work unchanged.

What still doesn't work on WebGPU

  • deepAnalyze / program list panel: relies on gl.info.programs which is WebGL-only and not present on WebGPURenderer.
  • GPU vendor/renderer strings: requires the async GPUAdapter.requestAdapterInfo() API.

Test plan

  • Verified FPS, CPU, GPU metrics display correctly with WebGPURenderer + enableTimestamps: true
  • Verified no regressions on WebGLRenderer
  • deepAnalyze gracefully shows nothing (empty program list) on WebGPU without throwing

@YusefNsar YusefNsar changed the title Fix performance issues with WebGPURenderer in r3f Fix add WebGPU renderer support in PerfHeadless Mar 15, 2026
@YusefNsar
Copy link
Copy Markdown
Author

This is a fix for issue #63

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