Commit Graph
70 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 07598f4bb2 [gpu] Support middle-click in WebGPU demo
Map DOM button 1 (middle) to GLFW middle button so middle-click
reset and middle-drag zoom work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:42:05 -06:00
Behdad EsfahbodandClaude Opus 4.6 c8e0670f7c [gpu] Document middle-click reset in help text
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:38:07 -06:00
Behdad EsfahbodandClaude Opus 4.6 fd465792c9 [gpu] Middle-click to reset view
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:33:00 -06:00
Behdad EsfahbodandClaude Opus 4.6 b68fc1de22 [gpu] Fix WebGPU scroll zoom sensitivity
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:05:29 -06:00
Behdad EsfahbodandClaude Opus 4.6 5a08291dde [gpu] Use raw string literal for WGSL demo shader
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:03:41 -06:00
Behdad EsfahbodandClaude Opus 4.6 f3be5f329b [gpu] Inline demo shaders as raw string literals
Replace separate .glsl files and generated .hh headers with C++11
raw string literals (R"glsl(...)glsl") directly in demo-shader.cc.
Matches the pattern already used by demo-metal.mm and the WebGPU
demo. Removes demo shader generation from meson and the generator
script.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:02:00 -06:00
Behdad EsfahbodandClaude Opus 4.6 09e85623bc [gpu] Fix Metal build; silence float-to-double warning
Add missing set_debug() to Metal renderer.
Cast float to double in demo-shader.h vertex extents.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:56:48 -06:00
Behdad EsfahbodandClaude Opus 4.6 b42cd76d05 [gpu] Remove debug heatmap from WebGPU demo
The WGSL shader compilation fails with _hb_gpu_curve_counts.
Debug mode is available in desktop and WebGL demos.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:44:30 -06:00
Behdad EsfahbodandClaude Opus 4.6 c2618a00c4 [gpu] Use alpha blending for debug heatmap
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:42:21 -06:00
Behdad EsfahbodandClaude Opus 4.6 ddd6a86470 [gpu] Add debug heatmap mode (d key)
Refactor library fragment shaders (GLSL, MSL, WGSL) to extract
_hb_gpu_decode_glyph and _hb_gpu_curve_counts helpers, used by
both hb_gpu_render and the debug visualization.

Debug mode (d key) shows per-pixel curve counts as a heatmap:
R = horizontal band curves, G = vertical band curves, B = text
coverage. Scale 0-8 curves maps to 0-1 intensity.

Also auto-generates demo shader headers via meson, and adds
set_debug to the renderer interface.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:40:38 -06:00
Behdad EsfahbodandClaude Opus 4.6 47512ddcb4 [gpu] Add Backspace as alternative reset key
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 16:48:32 -06:00
Behdad EsfahbodandClaude Opus 4.6 98f7d746f3 [gpu] Add 3-finger touch gesture for 3D rotation
Three-finger drag on mobile now does trackball rotation, matching
right-drag on desktop. Uses centroid of three touch points.
Release with momentum triggers spin animation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 16:18:44 -06:00
Behdad EsfahbodandClaude Opus 4.6 33de483673 [gpu] Fix NaN in trackball rotation speed
Clamp dquat[3] to [-1, 1] before acos() to prevent NaN from
float imprecision. Without the clamp, slightly-out-of-range
quaternion w values make rot_speed NaN, poisoning the quaternion
and causing text to disappear until reset.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 16:03:38 -06:00
Behdad EsfahbodandClaude Opus 4.6 30ff2b7d9d [gpu] Fix drag-release animation in WebGPU demo
Don't call demo_view_motion_func in on_mouseup — it zeros dx/dy
(same position as last mousemove), killing the velocity needed
for drag-release spin detection. Also remove debug printfs.

Track active_buttons to filter spurious document-level mouseup
events from UI controls while still catching drag releases
outside the canvas.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:51:57 -06:00
Behdad EsfahbodandClaude Opus 4.6 ca2fb1eb68 [gpu] Share demo_view between WebGL and WebGPU web demos
Refactor demo_view to work without GLFW (guarded by HB_GPU_NO_GLFW):
- Add demo_view_create_headless() for non-GLFW use
- Store fb/window dimensions in the view struct
- Use emscripten_get_now() for timing when on Emscripten
- Guard GLFW-specific calls (fullscreen, window close, cursor query)

Rewrite WebGPU entry point to use demo_view and demo_renderer_t
interface instead of duplicated view/input code. This gives the
WebGPU demo identical trackball rotation, drag-release animation,
keyboard shortcuts, and gamma cycling as the GL demos.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:36:19 -06:00
Behdad EsfahbodandClaude Opus 4.6 41973ac2c4 [gpu] Polish WebGPU error message layout
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:26:40 -06:00
Behdad EsfahbodandClaude Opus 4.6 c43e4cc8d0 [gpu] Sync C++ WebGPU error message with JS one
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:24:44 -06:00
Behdad EsfahbodandClaude Opus 4.6 3a7d9d8679 [gpu] Clean up web demo error message and titles
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:23:36 -06:00
Behdad EsfahbodandClaude Opus 4.6 d35076bb28 [gpu] Fix line break in WebGPU error message
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:18:18 -06:00
Behdad EsfahbodandClaude Opus 4.6 10f18a652f [gpu] WebGPU error handling and UI polish
- Show helpful error with browser support link when WebGPU is
  unavailable (JS-level check before WASM loads)
- Suggest Linux Chrome flags for Vulkan/WebGPU
- Prevent onRuntimeInitialized from hiding the error message
- Set page title to WebGL/WebGPU variant
- Make adapter failure in C++ also show HTML error

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:16:41 -06:00
Behdad EsfahbodandClaude Opus 4.6 9507f513c3 [gpu] Show helpful error when WebGPU is not available
Display browser support link and Linux Chrome flags when
adapter or device creation fails.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:05:08 -06:00
Behdad EsfahbodandClaude Opus 4.6 a3dedf59b9 [gpu] Fix WebGPU demo gamma, colors, and UI
- Default to light mode matching GL demo
- Gamma cycles between 2.2 and none (no sRGB framebuffer)
- Gamma depends on dark_mode (1/2.2 for dark, 2.2 for light)
- Add console logging for key presses
- Blur backend dropdown after selection to prevent space capture

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 15:03:33 -06:00
Behdad EsfahbodandClaude Opus 4.6 dbbcca47b0 [gpu] WebGPU web demo working
Fix WebGPU rendering: remove wgpuSurfacePresent (browser auto-presents),
query preferred surface format, set depthSlice undefined for 2D targets.
Match GL demo behavior: light mode default, proper trackball rotation,
CSS-pixel coordinate mapping, perspective frustum projection.

Add backend dropdown (WebGL/WebGPU) to shell.html that navigates
between index.html and webgpu.html.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 14:56:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 e51d769ce3 [gpu] Add WebGPU web demo
Add a WebGPU variant of the web demo using Emscripten's
emdawnwebgpu port. Uses the WGSL shaders from the library API,
a storage buffer for the atlas (i16→i32 expansion on upload),
and Emscripten HTML5 APIs for input (no GLFW).

Also moves demo_shader_add_glyph_vertices to demo-shader.h as
static inline so demo-buffer.cc can be compiled without GL.

Build: bash util/gpu/web/build-webgpu.sh → out/webgpu.html
The existing WebGL build continues to work unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 14:39:50 -06:00
Behdad EsfahbodandClaude Opus 4.6 0c150b97b4 [gpu] Update web demo for demo_renderer_t refactor
Replace demo_glstate_t with demo_renderer_t interface, use
demo_renderer_create_gl(), and add demo-renderer-gl.cc to
the web build.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 14:02:30 -06:00
Behdad EsfahbodandClaude Opus 4.6 67528cdab3 [gpu] Remove dead GL code from demo_buffer_t
Drawing is now handled by the renderer, so demo_buffer_t no longer
needs its own VAO/VBO or demo_buffer_draw(). The buffer is now a
pure vertex data container.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 14:01:27 -06:00
Behdad EsfahbodandClaude Opus 4.6 892f9ebffc [gpu] Add loading screen to web demo
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:59:02 -06:00
Behdad EsfahbodandClaude Opus 4.6 27265bcd08 [gpu] Revert GL FBO experiment; keep Metal offscreen optimization
GL doesn't benefit from FBO indirection — glfwSwapBuffers with
vsync off is already non-blocking on macOS. Reverted to direct
rendering.

Metal keeps the offscreen texture approach (4000fps vs 280fps).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:55:40 -06:00
Behdad EsfahbodandClaude Opus 4.6 a20f09edea [gpu] Optimize rendering performance
GL renderer:
- Set up VAO once (deferred to first draw after shader ready)
- Cache vertex data; only re-upload when pointer changes
- Query attribute locations once and store in VAO state

Metal renderer:
- Cache vertex buffer across frames
- When vsync off, render to offscreen texture at full GPU speed
  and present to display at ~120Hz to stay responsive
- Fix vsync toggle (CAMetalLayer.displaySyncEnabled)

Also: FPS reporting interval 5s -> 2s.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:52:31 -06:00
Behdad EsfahbodandClaude Opus 4.6 216fb4fb43 [gpu] Refactor demo to virtual renderer interface
Replace backend-specific branches with a demo_renderer_t base class
that both GL and Metal implement. This eliminates all if(metal) checks
in the view code and makes adding future backends (WebGPU) clean.

- Add demo-renderer.h with virtual interface
- Add demo-renderer-gl.cc wrapping existing GL code
- Rewrite demo-metal.mm to implement renderer interface
- Move VBO/VAO management from demo_buffer into GL renderer
- Fix Metal vsync (CAMetalLayer.displaySyncEnabled)
- Fix dark mode crash on Metal (was calling GL directly)
- Add set_background to renderer for clear color control

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:42:57 -06:00
Behdad EsfahbodandClaude Opus 4.6 6910b9a3ed [gpu] Add Metal backend for macOS demo
Add MSL shader translations of the Slug GPU text rasterizer, and a
Metal rendering backend for hb-gpu-demo selectable via --metal flag.

Library changes:
- Add HB_GPU_SHADER_LANG_MSL enum value
- Add hb-gpu-vertex.msl and hb-gpu-fragment.msl
- Extend gen-gpu-shader-artifacts.py for MSL

Demo changes:
- Add demo-metal.h/mm with CAMetalLayer rendering
- Add external atlas backend for non-GL paths
- Add demo_buffer_get_vertices for Metal draw path
- Skip GL init when using Metal (GLFW_NO_API)
- Add --metal command-line flag

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:36:28 -06:00
Behdad EsfahbodandClaude Opus 4.6 58f84001c3 [gpu] Show simplified help text on mobile, clean up desktop help
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 12:57:49 -06:00
Behdad EsfahbodandClaude Opus 4.6 1a8621c557 [gpu] Show simplified help text on mobile
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 12:54:02 -06:00
Behdad EsfahbodandClaude Opus 4.6 ccc532d999 [gpu] Hide font/text buttons on mobile
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 12:51:52 -06:00
Behdad EsfahbodandClaude Opus 4.6 67ecdf8da7 [gpu] Add text editing modal to web demo
Add a "text" button that opens a modal textarea with the current
text.  Apply sends new text to WASM, flushing the glyph cache and
atlas.  Custom text is preserved across font changes.

Also adds demo_font_clear_cache() and demo_atlas_clear() for
flushing state without full destroy/recreate.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 12:48:44 -06:00
Behdad EsfahbodandClaude Opus 4.6 6ea5c5682b [gpu] Fix black screen on web demo initial load
Don't call demo_view_display from main() — let the main loop
handle the first frame.  The premature call could render before
the browser's canvas was ready, and since it cleared needs_redraw,
no subsequent frame was drawn until user interaction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 11:41:35 -06:00
Behdad EsfahbodandClaude Opus 4.6 ce3b2df037 [gpu] Add font file loading to web demo
Add a font button and drag-and-drop support to the web demo.
When a user provides their own .ttf/.otf font, the glyph cache
and atlas are flushed and the display is rebuilt with English-only
text (since the font may not support Persian).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 11:41:22 -06:00
Behdad EsfahbodandClaude Opus 4.6 1ffb1faf82 [gpu] Add controls overlay to web demo
Show mouse and keyboard shortcuts in the bottom-left corner.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 17:30:11 -06:00
Behdad EsfahbodandClaude Opus 4.6 ddd158101c [gpu] Add dark mode toggle (b key)
White-on-black with inverted gamma correction.  Foreground
color passed as u_foreground uniform; background via
glClearColor.  GL alpha blending preserved for glyph overlap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 17:21:00 -06:00
Behdad EsfahbodandClaude Opus 4.6 d4b7b1f060 [gpu] Reduce demo text to 30 lines per script
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 16:47:31 -06:00
Behdad EsfahbodandClaude Opus 4.6 457de66b8e [gpu] Use Apple OpenGL framework on macOS
dependency('gl') resolves to Mesa's libGL via Homebrew, which
can't render to native macOS windows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 13:50:36 -06:00
Behdad Esfahbod f7d154bc97 Revert "[gpu] Right-align RTL lines to average width"
This reverts commit d87651e02fe44afcb57974b8f807d26462c7469c.
2026-03-28 12:56:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 a41f194bef [gpu] Right-align RTL lines to average width
Detect RTL direction from shaped buffers and right-align those
lines in the demo.  Uses the average width of RTL lines as the
alignment target for a balanced look.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 12:54:26 -06:00
Behdad EsfahbodandClaude Opus 4.6 793c6b7b78 [gpu] Add combined cropped text for web demo
Generate default-text-combined.hh with 35 lines of English +
35 lines of Persian for the web demo, matching the desktop
demo's adaptive line count.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 12:35:19 -06:00
Behdad EsfahbodandClaude Opus 4.6 62166176c3 [gpu] Subset default font to demo texts; adaptive line count
Replace the embedded default font with Parastoo-Regular subsetted
to just the characters in the English and Persian demo texts (28K).

Adaptive line count: 70 total lines divided equally among
supported scripts.  A Latin-only font gets 70 lines of English;
a Latin+Arabic font gets 35 of each.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 12:29:49 -06:00
Behdad EsfahbodandClaude Opus 4.6 066da3ed3d [gpu] Multi-script default text based on font GSUB
Check the font's GSUB table for Latin and Arabic script support.
Build default demo text from English (Lorem Ipsum) and Persian
paragraphs for supported scripts, cropped to 35 lines each.

Source paragraphs live in perf/texts/{en,fa}-paragraph.txt.
gen-default-texts.py wraps them at fixed width and generates
the .hh headers.

Web demo hardcodes both texts since the embedded font supports
both scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 12:23:43 -06:00
Behdad EsfahbodandClaude Opus 4.6 468bbb1b5d [gpu] Use -Oz for web demo build
Reduces wasm size from 687K to 593K.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 11:14:51 -06:00
Behdad EsfahbodandClaude Opus 4.6 833e90f904 [gpu] Use -Os -flto for web demo build
Reduces wasm size from 933K to 687K via size optimization
and link-time dead code elimination.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 03:56:14 -06:00
Behdad EsfahbodandClaude Opus 4.6 30e1a703f0 [gpu] Convert matrix4x4 and trackball to C++ headers
Merge the .c and .h files into single .hh headers with
static inline functions.  Eliminates the C/C++ linkage issue
and simplifies the web demo build to a single em++ call.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 03:53:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 2f486f7447 [gpu] Fix help text: align columns, s→g for gamma
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 03:30:49 -06:00