Behdad Esfahbod
dfd5d5b3cb
[gpu] Paint: port to HLSL/WGSL; add _hb_gpu_draw_impl; fix WGSL
...
This commit unblocks end-to-end paint rendering on the WebGPU
demo, adds the HLSL port, and avoids losing MSAA or stem
darkening along the way.
### Shared: _hb_gpu_draw_impl
hb_gpu_draw internally did fwidth(renderCoord) + MSAA. That works
fine in the single-call-per-fragment case but not when called from
inside a non-uniform branch (e.g. an op-stream LAYER_SOLID
conditional in the paint fragment shader) -- WGSL rejects fwidth
from non-uniform control flow.
Factor the MSAA-aware body into _hb_gpu_draw_impl, which takes a
caller-supplied pixelsPerEm. hb_gpu_draw is now a thin wrapper
that computes pixelsPerEm via fwidth and delegates. The paint
fragment shader in every language now computes pixelsPerEm once
at the top of hb_gpu_paint and calls _hb_gpu_draw_impl per layer
-- MSAA preserved, no redundant fwidth calls per layer.
In WGSL, _hb_gpu_draw_impl also inlines the ppem computation from
pixelsPerEm rather than recurring into hb_gpu_ppem (which itself
calls fwidth).
### Paint shaders
- hb-gpu-paint-fragment.hlsl (new): HLSL transcription. Assumes
a caller-declared StructuredBuffer<float4> hb_gpu_palette at
register(t1).
- hb-gpu-paint-fragment.wgsl: switched from hb_gpu_draw to
_hb_gpu_draw_impl; comment updated.
- hb-gpu-paint-fragment.msl, .glsl: same switch, cached
pixelsPerEm at entry.
hb_gpu_paint_shader_source() now returns content for all four
languages.
### Demos
- util/gpu/demo-fragment.glsl: restores stem darkening (dropped in
the first paint wiring commit); applies to the premultiplied
RGBA by scaling both colour and alpha. The desktop GL demo
regenerates demo-fragment-glsl.hh from this source.
- util/gpu/web/hb-gpu-web-webgpu.cc: WGSL fs_main concatenates the
paint source, binds a zero-filled palette storage buffer at
@group(0) @binding(2), and restores stem darkening. fwidth
hoisted outside the stem-darkening conditional so WGSL's
derivative-uniformity rule is happy.
- util/gpu/demo-renderer-d3d11.cc: HLSL ps_main switches to
hb_gpu_paint. Adds a second StructuredBuffer<float4>
hb_gpu_palette at t1, zero-filled for now, bound alongside the
atlas SRV.
### Misc
- perf/benchmark-gpu.cc: fix stale reset/encode(draw) calls.
Measured build (local Emscripten):
WebGL index.wasm : 443638 181640 gz
WebGPU webgpu.wasm : 461626 188400 gz
COLRv0 rendering (BungeeTint, Noto Color Emoji, etc.) now works
end-to-end on WebGL and WebGPU with the correct palette. Metal
and D3D11 demos should likewise compile against the new shader
flow; real palette upload cross-backend remains a TODO.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com >
2026-04-13 15:52:21 -06:00
..
2026-04-13 11:01:19 -06:00
2025-05-08 16:03:02 +03:00
2026-04-13 11:01:19 -06:00
2026-04-11 22:20:01 -06:00
2023-07-08 13:51:07 -04:00
2025-03-07 18:19:29 -07:00
2026-03-10 09:56:47 -03:00
2025-05-06 13:17:13 +03:00
2025-05-06 13:17:13 +03:00
2025-05-06 13:17:13 +03:00
2025-05-06 13:17:13 +03:00
2026-03-09 22:37:07 -06:00
2025-07-30 01:19:29 +03:00
2025-05-06 13:17:13 +03:00
2026-03-09 22:37:07 -06:00
2024-03-30 02:20:21 +02:00
2026-03-02 13:49:56 -03:00
2026-03-03 05:28:38 -03:00
2025-03-31 16:28:28 -06:00
2026-03-03 05:38:25 -03:00
2026-04-13 15:10:09 -06:00
2026-03-28 02:57:56 -06:00
2025-11-14 14:39:52 +02:00
2026-03-03 05:28:38 -03:00
2026-03-27 23:37:52 -06:00
2026-03-03 06:12:35 -03:00
2025-08-15 00:54:52 -06:00
2026-03-03 06:27:43 -03:00
2026-03-03 06:18:08 -03:00
2023-11-30 16:31:44 +08:00
2024-11-28 02:31:46 +02:00
2026-03-28 16:08:37 -06:00
2026-03-13 01:21:13 +02:00
2026-02-17 13:42:08 -07:00
2026-03-13 01:21:13 +02:00
2026-04-13 12:10:35 -06:00
2026-03-28 02:57:56 -06:00
2025-07-28 10:24:45 -06:00
2023-11-04 15:21:47 -06:00
2023-11-04 15:21:47 -06:00
2026-03-25 11:59:58 -06:00
2023-11-04 15:21:47 -06:00
2024-09-23 08:02:25 -06:00
2026-04-13 11:01:19 -06:00
2026-04-13 11:01:19 -06:00
2024-09-23 08:02:25 -06:00
2025-03-27 15:10:52 -06:00
2025-03-27 15:37:01 -06:00
2025-03-27 15:37:01 -06:00
2025-03-27 14:44:52 -06:00
2023-11-04 15:21:47 -06:00
2025-03-13 01:07:35 -06:00
2023-01-12 10:44:08 -07:00
2026-04-12 20:22:00 -06:00
2025-10-17 15:23:05 -06:00
2026-04-13 11:01:19 -06:00
2026-02-24 16:57:44 -03:00
2026-03-26 15:15:56 -06:00
2025-09-23 19:09:46 -06:00
2026-02-13 15:06:01 -07:00
2026-02-13 15:06:01 -07:00
2025-03-12 23:56:52 -06:00
2026-04-13 01:16:42 -06:00
2023-02-21 18:07:53 +02:00
2026-03-27 15:13:44 -06:00
2026-03-27 19:59:03 -06:00
2025-04-04 16:17:32 -06:00
2026-03-27 19:59:03 -06:00
2025-04-04 16:17:32 -06:00
2026-03-27 19:59:03 -06:00
2025-03-10 16:20:16 -06:00
2026-03-08 00:03:57 +02:00
2026-04-13 00:43:06 -06:00
2026-03-22 22:49:14 -06:00
2026-03-04 09:16:54 -07:00
2026-03-04 09:16:54 -07:00
2025-12-20 17:08:48 -07:00
2026-04-13 01:32:55 -06:00
2023-08-15 10:30:38 -06:00
2026-02-22 00:20:31 -03:00
2026-02-22 00:20:31 -03:00
2023-01-06 11:01:25 -07:00
2026-04-07 15:36:21 -06:00
2026-02-24 02:25:55 -03:00
2023-05-23 11:57:53 -06:00
2024-08-14 10:19:40 -07:00
2026-03-26 15:15:56 -06:00
2026-02-17 13:42:08 -07:00
2025-11-12 14:04:34 -05:00
2025-04-09 10:43:02 -06:00
2026-04-01 15:03:53 -06:00
2025-08-25 09:50:54 -06:00
2026-02-20 11:25:24 -07:00
2026-04-12 20:09:44 -06:00
2025-03-11 11:56:00 -06:00
2025-03-15 13:59:16 -06:00
2026-04-13 00:38:40 -06:00
2025-11-12 14:04:34 -05:00
2025-02-28 01:13:25 -07:00
2025-07-20 21:08:56 +03:00
2025-05-08 14:30:07 -06:00
2025-03-24 02:08:04 -06:00
2026-02-16 02:28:45 +01:00
2025-03-22 16:02:39 -06:00
2025-04-08 02:13:39 -06:00
2026-04-12 20:09:44 -06:00
2025-04-22 19:52:21 -06:00
2025-04-22 19:52:21 -06:00
2026-03-27 13:14:56 -06:00
2025-07-28 03:19:17 -06:00
2025-04-06 19:16:43 -06:00
2025-03-12 18:27:27 -06:00
2026-03-28 03:02:07 -06:00
2026-04-12 20:09:44 -06:00
2025-07-20 21:40:37 +03:00
2026-03-24 11:29:02 -06:00
2025-03-24 00:33:53 +02:00
2025-09-15 23:56:25 -06:00
2025-07-20 07:19:23 -06:00
2026-04-12 20:09:44 -06:00
2025-03-11 11:56:00 -06:00
2026-04-12 20:09:44 -06:00
2026-04-09 23:21:05 -06:00
2025-07-02 20:14:51 +03:00
2025-07-02 20:14:51 +03:00
2025-07-02 20:14:51 +03:00
2023-01-11 13:41:44 -07:00
2026-03-26 19:09:40 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 12:10:35 -06:00
2026-04-03 12:09:02 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 15:52:21 -06:00
2026-04-13 14:26:08 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:23 -06:00
2026-04-13 12:10:35 -06:00
2026-04-13 14:26:08 -06:00
2026-04-13 00:43:06 -06:00
2025-08-23 18:43:50 -06:00
2024-10-27 16:14:53 -07:00
2025-10-13 13:11:15 -06:00
2026-01-01 21:01:30 -07:00
2025-08-29 00:08:28 -06:00
2026-04-10 18:06:24 -06:00
2026-04-13 11:01:19 -06:00
2023-08-25 07:51:05 -06:00
2023-06-03 14:56:47 -06:00
2026-01-09 04:54:49 -07:00
2023-06-03 15:48:54 -06:00
2026-03-26 15:15:56 -06:00
2023-06-25 18:14:56 -06:00
2025-04-08 01:58:10 -06:00
2024-12-02 14:55:50 -07:00
2026-03-27 19:59:03 -06:00
2023-01-20 15:52:09 -07:00
2026-03-10 01:04:11 -03:00
2025-11-11 13:58:58 -07:00
2026-04-13 11:01:19 -06:00
2025-08-07 22:38:58 -06:00
2025-02-18 20:54:56 -07:00
2026-04-13 11:01:19 -06:00
2025-06-08 13:43:27 +03:00
2026-04-13 11:01:19 -06:00
2026-04-13 11:01:19 -06:00
2026-03-02 13:49:56 -03:00
2026-03-10 00:19:39 -06:00
2026-02-24 16:39:39 -03:00
2026-03-10 00:19:39 -06:00
2025-03-03 02:17:13 -07:00
2026-04-12 20:09:44 -06:00
2026-04-13 11:01:19 -06:00
2023-11-04 15:21:47 -06:00
2023-11-04 15:21:47 -06:00
2025-07-29 14:31:53 -06:00
2026-04-13 11:01:19 -06:00
2025-11-11 12:29:06 -07:00
2026-04-13 11:01:19 -06:00
2023-01-28 12:09:45 -07:00
2025-08-20 00:06:00 -06:00
2025-08-20 00:06:00 -06:00
2026-04-13 11:01:19 -06:00
2023-11-04 15:21:47 -06:00
2026-03-19 16:07:30 +02:00
2025-09-30 13:31:04 -06:00
2025-09-30 13:31:04 -06:00
2025-02-14 21:54:30 +02:00
2025-02-14 21:54:30 +02:00
2025-08-21 11:24:35 -06:00
2025-04-06 02:48:49 +02:00
2023-11-04 15:21:47 -06:00
2023-11-04 15:21:47 -06:00
2023-04-30 11:11:19 -06:00
2023-01-28 12:09:45 -07:00
2023-04-24 13:04:05 -06:00
2023-02-11 23:52:58 +02:00
2026-04-13 11:01:19 -06:00
2023-01-12 18:37:07 -07:00
2025-08-07 22:38:58 -06:00
2024-08-21 12:06:02 -06:00
2026-03-27 14:13:53 -06:00
2025-08-27 15:36:48 -06:00
2026-03-18 23:36:54 +02:00
2025-08-07 22:04:20 -06:00
2026-03-19 00:45:24 +02:00
2026-03-19 00:45:24 +02:00
2025-10-13 13:26:23 -06:00
2025-02-06 14:26:37 +00:00
2025-09-10 11:18:07 -04:00
2026-03-02 15:57:03 -03:00
2026-03-02 15:57:03 -03:00
2026-03-11 10:53:09 -06:00
2026-02-20 11:25:24 -07:00
2024-06-06 13:52:44 -06:00
2026-03-27 19:59:03 -06:00
2025-01-03 05:19:13 -07:00
2026-03-02 15:57:03 -03:00
2025-11-12 14:04:34 -05:00
2026-03-27 19:59:03 -06:00
2023-01-12 17:04:24 -07:00
2025-11-12 14:04:34 -05:00
2026-03-27 19:59:03 -06:00
2025-01-03 05:19:13 -07:00
2023-06-22 11:02:22 -06:00
2026-02-20 11:25:24 -07:00
2026-03-27 19:59:03 -06:00
2025-01-03 05:19:13 -07:00
2026-03-03 06:27:43 -03:00
2023-06-22 20:56:08 -04:00
2026-03-03 06:18:08 -03:00
2025-09-10 11:35:54 -04:00
2025-11-11 12:29:06 -07:00
2026-03-03 05:57:33 -03:00
2026-03-03 05:57:33 -03:00
2026-01-07 12:49:37 -07:00
2026-04-13 11:01:19 -06:00
2025-11-22 18:08:27 -07:00
2025-06-08 13:43:27 +03:00
2026-04-13 11:01:19 -06:00
2026-04-13 11:01:19 -06:00
2024-02-06 14:52:03 -07:00
2024-04-16 17:10:09 -06:00
2025-06-08 13:43:27 +03:00
2025-07-20 07:19:23 -06:00
2025-11-05 15:47:01 -07:00
2026-03-26 15:15:56 -06:00
2025-04-20 04:02:05 -06:00
2025-04-20 04:53:33 -06:00
2025-06-08 13:43:27 +03:00
2025-06-08 13:43:27 +03:00
2026-04-12 20:09:44 -06:00
2026-04-07 20:12:59 -06:00
2026-04-13 01:32:55 -06:00
2026-03-26 15:15:56 -06:00
2026-04-13 01:59:18 -06:00
2026-04-13 03:39:36 -06:00
2026-03-09 22:37:07 -06:00
2026-04-13 03:37:06 -06:00
2026-04-13 03:35:47 -06:00
2026-02-24 04:29:07 -03:00
2026-04-13 03:35:47 -06:00
2026-04-13 03:39:36 -06:00
2026-04-10 18:06:24 -06:00
2025-11-10 02:55:44 -07:00
2025-10-01 08:24:34 +03:00
2025-09-15 23:56:25 -06:00
2025-09-23 11:23:03 -04:00
2023-08-25 07:51:05 -06:00
2023-06-03 14:56:47 -06:00
2025-03-12 23:05:04 -06:00
2025-02-12 11:23:28 +00:00
2025-08-20 23:15:46 -06:00
2025-01-07 11:29:35 -07:00
2025-07-23 21:39:23 +03:00
2026-03-28 02:57:56 -06:00
2025-08-07 22:38:58 -06:00
2024-08-23 08:58:50 -06:00
2023-06-25 18:14:56 -06:00
2026-03-26 15:15:56 -06:00
2026-02-17 13:42:08 -07:00
2026-02-17 13:42:08 -07:00
2026-03-09 23:08:02 -03:00
2026-03-10 19:47:03 +02:00
2026-03-04 12:55:54 -07:00
2025-04-05 23:27:15 -06:00
2023-05-12 11:09:04 -06:00
2025-09-22 14:48:42 -04:00
2025-09-16 23:51:19 -04:00
2026-03-17 09:12:35 -06:00
2025-09-11 16:44:24 -06:00
2025-09-26 12:10:28 -04:00
2025-09-26 12:10:28 -04:00
2026-03-10 11:58:52 -06:00
2025-12-11 10:54:49 -07:00
2025-12-11 10:54:49 -07:00
2025-01-11 18:13:18 +02:00
2025-01-11 18:13:18 +02:00
2026-04-13 03:13:37 -06:00
2025-07-25 00:05:46 -06:00
2025-07-25 00:05:46 -06:00
2025-07-25 00:05:46 -06:00
2025-07-25 00:05:46 -06:00
2025-07-25 02:18:15 -06:00
2025-07-25 00:05:46 -06:00
2026-04-13 03:13:37 -06:00
2025-07-24 22:47:08 -06:00
2026-03-02 15:57:03 -03:00
2026-03-02 15:57:03 -03:00
2026-04-12 20:09:44 -06:00
2023-04-27 00:48:00 +02:00
2025-05-12 14:05:39 -06:00
2026-04-13 00:40:07 -06:00
2025-08-28 15:58:39 -06:00
2026-04-13 03:38:34 -06:00
2026-04-11 23:15:40 -06:00
2026-04-13 02:47:18 -06:00
2026-04-13 03:38:34 -06:00
2026-04-12 21:27:00 -06:00
2026-04-11 23:16:47 -06:00
2026-04-11 23:16:47 -06:00
2026-04-11 23:15:40 -06:00
2026-04-13 01:32:55 -06:00
2026-04-13 02:01:22 -06:00
2026-02-24 08:52:34 -03:00
2026-04-13 03:38:34 -06:00
2026-04-13 11:01:19 -06:00
2026-04-04 20:31:18 +02:00
2023-03-31 17:38:23 -06:00
2023-06-26 18:36:23 -06:00
2023-03-31 17:33:44 -06:00
2023-06-26 18:36:23 -06:00
2023-06-26 18:36:23 -06:00
2023-03-31 17:38:23 -06:00
2023-03-31 17:33:45 -06:00
2023-03-31 17:33:44 -06:00
2024-04-01 01:55:38 -06:00
2023-03-31 17:33:45 -06:00
2026-04-13 00:40:07 -06:00
2026-04-12 19:59:19 -06:00
2026-03-12 02:41:44 -03:00
2022-12-23 13:37:59 -07:00
2026-04-12 19:51:38 -06:00
2025-03-07 18:19:29 -07:00
2026-03-10 00:19:39 -06:00
2026-04-13 15:52:21 -06:00
2023-10-18 07:40:40 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2026-04-09 23:21:05 -06:00
2025-07-25 03:00:38 -06:00
2023-06-07 16:25:11 -06:00
2025-07-25 03:00:38 -06:00
2026-03-12 10:29:21 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2025-12-19 21:42:20 -07:00
2025-07-25 03:00:38 -06:00
2025-07-25 03:00:38 -06:00
2026-03-17 09:12:35 -06:00
2025-09-15 19:50:04 -06:00
2023-01-12 17:04:24 -07:00
2025-07-25 03:00:38 -06:00
2023-01-12 17:04:24 -07:00
2026-03-02 15:39:57 -03:00