Commit Graph
16016 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 14effc302a [gpu] Add hb_gpu_darken() to all shader languages
Library function for stem darkening: pow(2, brightness-0.5)
scaled by ppem. Added to GLSL, MSL, WGSL, HLSL with consistent
brief docs. Demo shaders now call the library function.
Section docs in hb-gpu.cc updated with usage example.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 19:49:42 -06:00
Behdad EsfahbodandClaude Opus 4.6 b9e864e9e7 [gpu] Link to live web demo from API docs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 19:04:07 -06:00
Behdad EsfahbodandClaude Opus 4.6 d55db833fd [gpu] Fix WGSL: use gi.bandIndex.y for hband fetch
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 22:03:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 cb9ab32b8b [gpu] Add _hb_gpu_decode_glyph and _hb_gpu_curve_counts to WGSL
Bring WGSL shader in line with GLSL/MSL/HLSL by extracting the
header decode + band index computation into a shared helper.
Enables future debug heatmap support in the WebGPU demo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 22:01:44 -06:00
Behdad EsfahbodandClaude Opus 4.6 f215e90916 [gpu] Consistent shader function naming across all languages
Make hb_gpu_fetch public (no underscore prefix) in all shaders.
Internal functions use _hb_gpu_* consistently, including WGSL
(single leading underscore is legal per gpuweb/gpuweb#2298).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 21:53:02 -06:00
Behdad EsfahbodandClaude Opus 4.6 22c16a95c6 [gpu] Document font scale, dilation, and static dilation alternative
Explain why font scale should be left at default, how dilation
works and what jac means, and provide a simpler static dilation
alternative for 2D rendering at known sizes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 21:43:45 -06:00
Behdad EsfahbodandClaude Opus 4.6 7990799ac9 [gpu] Simplify meson shader generation into one loop
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:16:21 -06:00
Behdad EsfahbodandClaude Opus 4.6 9ad26d9823 [gpu] Add HLSL shader sources for Direct3D
Port fragment and vertex shaders to HLSL (Shader Model 5.0+).
Uses asuint for bit reinterpretation, StructuredBuffer<int4> for
atlas, and mul() for matrix multiply. Verified with DXC on Linux.

Adds HB_GPU_SHADER_LANG_HLSL to the enum. Reorders enum to:
GLSL, WGSL, MSL, HLSL. Updates doc strings for consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:15:33 -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 709b1d8f32 [gpu] Add WGSL shader generation to meson
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:51:39 -06:00
Behdad EsfahbodandClaude Opus 4.6 f35ff87a1a [gpu] Fix WGSL naming: avoid reserved underscore prefix
WGSL reserves identifiers starting with underscore. Use hb_gpu_fetch
(no prefix) for the atlas fetch helper, and hb_gpu__* (double
underscore mid-identifier) for truly internal functions. Reverts the
decode_glyph/curve_counts refactor from the WGSL shader since it
was causing compilation failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:50:28 -06:00
Behdad EsfahbodandClaude Opus 4.6 b884ee12bf [gpu] Fix WGSL shader: rename underscore-prefixed identifiers
WGSL reserves identifiers starting with underscore. Rename all
_hb_gpu_* functions and _hb_gpu_glyph_info struct to use hbgpu_*
and HbGpuGlyphInfo prefixes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:46: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 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 09f6ef66e8 [gpu] Add WGSL shader sources for WebGPU
Port fragment and vertex shaders to WGSL. Key differences from
GLSL/MSL: no preprocessor (constants instead of #define), bitcast
instead of floatBitsToUint, storage buffer pointer parameter for
atlas, and emsPerPixel passed explicitly since fwidth() is only
available in the caller's fragment entry point.

Adds HB_GPU_SHADER_LANG_WGSL to the shader language enum.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 14:22:41 -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 29996d32a0 [gpu] Compute quadratic coefficients from raw coordinates
Compute a and b from unshifted (raw int16 × power-of-2) coordinates
so they are exact, then pass renderCoord-shifted p1 separately as
the constant term.  This eliminates float rounding residuals that
made a non-zero for true lines, removing the need for an epsilon
threshold in the linear fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 00:12:11 -06:00
Behdad EsfahbodandClaude Opus 4.6 4682e7b125 [gpu] Widen linear-fallback threshold in quadratic solver
Use 1.0/16384.0 instead of 1.0/65536.0 for detecting
near-degenerate quadratics in both horizontal and vertical
poly solvers, fixing rendering artifacts (thin white gaps)
at curve junctions caused by float rounding residuals in
the second-order coefficient.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 00:02:57 -06:00
Behdad EsfahbodandClaude Opus 4.6 e8b793af6f [gpu] Add harfbuzz-gpu to CMake build
Add HB_BUILD_GPU option (default ON), gpu source/header lists,
library target, linker language, macOS framework support,
pkg-config template, header and library install targets.

Follows the same pattern as harfbuzz-raster and harfbuzz-vector.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 16:08:37 -06:00
Behdad EsfahbodandClaude Opus 4.6 88a25addf9 [gpu] Sort HB_HAS_GPU alphabetically in hb-features.h.in
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 03:02:07 -06:00
Behdad EsfahbodandClaude Opus 4.6 a002a14b2e [amalgamation] Add harfbuzz-world.cc single-compilation-unit build
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 02:57:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 f7ce7665e6 [amalgamation] Add harfbuzz-world.cc single-compilation-unit build
A template-based amalgamation that includes all harfbuzz components
behind HB_HAS_* guards:

  #define HB_HAS_SUBSET
  #define HB_HAS_GPU
  #include "harfbuzz-world.cc"

If HB_FEATURES_H is defined, includes that header for the defines.
HB_HAS_SUBSET selects harfbuzz-subset sources, otherwise core only.
Optional modules: HB_HAS_ICU, HB_HAS_CAIRO, HB_HAS_RASTER,
HB_HAS_VECTOR, HB_HAS_GPU.

Generated from meson source lists via gen-harfbuzz-world.py and
a .cc.in template. Committed artifact auto-regenerates like
harfbuzz.cc.

Also: add include guard to hb-zlib.cc (shared between raster
and vector, would cause duplicate symbols without it), and
remove .hh files from hb_gpu_sources list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 02:13:18 -06:00
Behdad Esfahbod 9f18532510 Merge pull request #5878 from harfbuzz/hb-gpu
[gpu] Add hb-gpu library ported from GLyphy
2026-03-28 01:47:39 -06:00
Behdad EsfahbodandClaude Opus 4.6 2dbb476313 [gpu] Fix GTK-Doc formatting in shader documentation
Replace **bold** markdown with plain text (unsupported by
GTK-Doc).  Wrap multi-line code snippets in |[ ]| blocks
instead of backticks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 01:35:27 -06:00
Behdad EsfahbodandClaude Opus 4.6 90e8b99cd5 [gpu] Add Emscripten web demo; mobile touch support
Web build using Emscripten + WebGL2 with HB_GPU_ATLAS_2D mode.
Touch support: drag to pan, tap to toggle animation.
FPS counter overlay. Viewport meta for mobile.

Fix cursor position on first touch by querying glfwGetCursorPos
in mouse_func. Left click/tap also toggles animation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 01:31:28 -06:00
Behdad EsfahbodandClaude Opus 4.6 d46f8e3444 [gpu] Rename HB_GPU_SHADER_GLSL_330 to HB_GPU_SHADER_LANG_GLSL
The shader source is compatible with both GLSL 3.30 and
GLSL ES 3.00.  Rename the enum value to reflect this and
match the type name convention.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:40:11 -06:00
Behdad EsfahbodandClaude Opus 4.6 35aee6047f [gpu] Add HB_GPU_ATLAS_2D mode for WebGL2 / GLSL ES 3.00
When HB_GPU_ATLAS_2D is defined before including the fragment
shader source, the atlas switches from isamplerBuffer to
isampler2D with a width uniform.  All texelFetch calls go
through _hb_gpu_fetch() which handles the 1D-to-2D coordinate
conversion.

The vertex shader works in both GLSL 330 and ES 300 as-is.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:35:05 -06:00
Behdad EsfahbodandClaude Opus 4.6 b1ad797e50 [gpu] Commit stringized shader headers; auto-regenerate like ragel
Pre-generate hb-gpu-{fragment,vertex}-glsl.hh from the .glsl
sources so the library builds without Python/stringize at
compile time.

When stringize is found, a build rule regenerates them from
the .glsl sources and copies back to the source tree, matching
the ragel artifact pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 23:37:52 -06:00
Behdad Esfahbod 2af0d9787f Update ragel-generated files 2026-03-27 19:59:03 -06:00
Behdad EsfahbodandClaude Opus 4.6 e4c174015f [gpu] Rename u_atlas uniform to hb_gpu_atlas
Namespace the GLSL uniform to avoid conflicts with user code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:21:27 -06:00
Behdad EsfahbodandClaude Opus 4.6 0582846c08 [gpu] Simplify shader API: return single string per language
Change hb_gpu_shader_{fragment,vertex}_sources() (array + count)
to hb_gpu_shader_{fragment,vertex}_source() returning a single
const char *.  Each language variant is one complete string.

Simplifies the demo shader compilation and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:10:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 77f7bde2a6 [gpu] Add comprehensive shader and rendering documentation
Document the full GPU rendering pipeline in the SECTION doc:
atlas setup, shader compilation, vertex attributes (position,
texcoord, normal, jac), hb_gpu_dilate usage, hb_gpu_render
usage, and typical vertex/fragment shader mains.

Note that this implements the Slug algorithm by Eric Lengyel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:06:15 -06:00
Behdad EsfahbodandClaude Opus 4.6 3ab11b19b6 [gpu] Clean up doc prose; add sample code to section doc
Remove stray "glyph" from doc comments where it referred to
the encoder rather than an actual glyph.  Add typical usage
example to the SECTION doc block.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:45:52 -06:00
Behdad EsfahbodandClaude Opus 4.6 686f3caa86 [gpu] Implement blob recycling in encode
recycle_blob stores the blob; encode reuses both the blob object
and its data buffer when the buffer is >= needed and < 2x needed.
Otherwise malloc fresh and replace_buffer on the recycled blob.

hb_blob_t::replace_buffer now skips destroy_user_data when the
new data pointer is the same as the old one (same-buffer reuse).

Add explicit destructor to hb_gpu_draw_t for recycled_blob cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:13:44 -06:00
Behdad EsfahbodandClaude Opus 4.6 9b918c5f77 [gpu] Use clear() instead of shrink(0) for curves on reset
shrink(0) frees the allocation; clear() keeps it.  Avoids
re-allocation on every encode cycle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:38:54 -06:00
Behdad EsfahbodandClaude Opus 4.6 023380343d [gpu] Use uint16 offset range via int16 bias trick
Store blob offsets as value-32768 in the signed int16 texel
fields; the shader recovers with +32768.  This doubles the
maximum blob size from 32767 to 65535 texels.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:36:58 -06:00
Behdad EsfahbodandClaude Opus 4.6 76eb0ae60f [gpu] Detect degenerate cubics in cu2qu and emit lines
Cubics with collinear control points (common in CJK fonts)
caused cu2qu to subdivide to max depth, generating up to 1024
line segments per cubic.  Detect the collinear case early
using cross-product distance and emit a single line instead.

Fixes encode failure for NotoSerifCJK gid 897 (48 cubics
were producing 24672 quadratics; now produces 48 lines).
Reduces total encode size for the font by ~34%.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:29:19 -06:00
Behdad EsfahbodandClaude Opus 4.6 4b9ef70d85 [post] Fix glyph name sort direction for std::sort
The old cmp_gids comparator produced descending order due to
hb_array_t::cmp's reversed memcmp argument order.  This
happened to work with hb_qsort on Linux but broke with
std::sort on other platforms since bsearch expects ascending.

Switch to find_glyph_name(a).cmp(find_glyph_name(b)) > 0
which sorts ascending, matching what cmp_key expects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:13:53 -06:00
Behdad EsfahbodandClaude Opus 4.6 f82046bb01 [gpu] Use arrayZ[] for unchecked scratch vector access in encode
All indices are guaranteed in-range by construction.  Bypass
operator[] bounds checking for the hot encode loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:02:35 -06:00
Khaled Hosny 44b44a6230 [message] Improve recursing message
Currently if recursed to lookup does nothing, no message is shown:

    start lookup 56 feature 'rlig'
    recursing to lookup 43 at 8
    replacing glyph at 8 (single substitution)
    replaced glyph at 8 (single substitution)
    recursed to lookup 43
    recursing to lookup 51 at 10
    end lookup 56 feature 'rlig'

With this change we always show paired “start recursing to lookup” /
“end recursing to lookup” messages:

    start lookup 56 feature 'rlig'
    start recursing to lookup 43 at 8
    replacing glyph at 8 (single substitution)
    replaced glyph at 8 (single substitution)
    end recursing to lookup 43
    start recursing to lookup 51 at 10
    end recursing to lookup 51
    end lookup 56 feature 'rlig'
2026-03-27 22:01:48 +02:00
Behdad EsfahbodandClaude Opus 4.6 52bb8a8304 [post] Break ties by gid in glyph name sort
std::sort is not stable — when two gids have the same name,
their relative order was undefined, causing the wrong gid to
be found by binary search on some platforms.

Break ties with the gid value itself to make the order
deterministic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 13:46:50 -06:00
Behdad EsfahbodandClaude Opus 4.6 a32cd49bc4 [gpu] Add encode scratch buffers to avoid per-call allocation
Embed hb_gpu_encode_scratch_t in hb_gpu_draw_t with all the
temporary vectors the encoder needs.  They persist across
encode calls and only grow, never shrink — eliminating
malloc/free overhead after the first glyph.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 13:46:29 -06:00
Behdad EsfahbodandClaude Opus 4.6 52f0115c0f [algs] Use std::sort in hb_array_t::qsort; simplify hb_qsort
hb_array_t::qsort(Compar) now uses std::sort for typed, inlineable
sorting.  The no-arg qsort() uses priority dispatch: std::sort for
move-assignable types, hb_qsort fallback for packed OT structs
with deleted move ops.

hb_qsort itself is simplified to just forward to system qsort().
sort_r_simple is retained as fallback when qsort is unavailable.

Convert all direct hb_qsort callers to use typed array qsort with
lambdas.  Remove dead comparator functions.

225 tests pass, 0 failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 13:14:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 df433afe6c [algs] Simplify hb_qsort: single template, inline all callers
Reduce to one templated hb_qsort, one templated qsort() on
hb_array_t/hb_vector_t, plus the no-arg qsort() that casts
Type::cmp to resolve ambiguity.

Convert all external call sites to lambdas so comparators
inline everywhere.  Remove the void*-arg overload and the
plain function-pointer overload.

225 tests pass, 0 failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 12:50:30 -06:00
Behdad EsfahbodandClaude Opus 4.6 05762b2fac [algs] Template hb_qsort comparator for inlining
Make sort_r_simple and sort_r_cmpswap take the comparator as a
template parameter instead of a function pointer.  This allows
lambdas and functors to inline into the sort, avoiding the
indirect-call overhead.

The function-pointer overloads remain for backward compatibility
and for the __OPTIMIZE_SIZE__ / qsort_r paths.

17% speedup on GPU encode benchmark (NotoSansCJK).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 12:36:59 -06:00
Behdad EsfahbodandClaude Opus 4.6 583b13d95c [gpu] Fix stale parameter names in header; add section doc
Three declarations in hb-gpu.h still had *glyph instead of *draw.
Add SECTION doc block in new hb-gpu.cc for gtk-doc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:33:29 -06:00
Behdad EsfahbodandClaude Opus 4.6 33ad6419e3 [gpu] Remove std::sort; add qsort with context to hb_array_t
Add an hb_array_t::qsort overload that takes a comparator with a
void* context argument, forwarding to hb_qsort's existing qsort_r
support.  Use it in the GPU encoder to eliminate the last std::
usage from library code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:48:10 -06:00
Behdad EsfahbodandClaude Opus 4.6 f5f6e90703 [gpu] Replace std:: with hb equivalents in encode
Use hb_min/hb_max instead of std::min/std::max, and
INT16_MIN/INT16_MAX instead of std::numeric_limits.
Only std::sort remains (needs lambda captures).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:43:45 -06:00
Behdad EsfahbodandClaude Opus 4.6 83fe2fa4fa [gpu] Fix doc comments: "GPU shape encoder", "GPU rasterization library"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:37:52 -06:00
Behdad EsfahbodandClaude Opus 4.6 2e24eccfd3 [gpu] Use XSince: REPLACEME in doc comments
Per AGENTS.md, new API uses XSince not Since.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:34:51 -06:00