From daddae08a37a2635d9709948e8bef88d0e29f780 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 13 Apr 2026 02:57:07 -0600 Subject: [PATCH] [gpu] Rename fragment-shader entry points with "draw_" prefix Rename the public fragment-shader entry points provided by the hb_gpu_draw_t renderer: hb_gpu_render(...) -> hb_gpu_draw(...) hb_gpu_darken(...) -> hb_gpu_draw_darken(...) Also rename the internal helper: _hb_gpu_render_single(...) -> _hb_gpu_draw_single(...) A COLRv1 paint renderer is planned and will provide its own fragment entry point (likely hb_gpu_paint returning a vec4); the existing draw/coverage entry point gets a subsystem-qualified name now so draw and paint can coexist. Updates the .glsl/.msl/.wgsl/.hlsl sources, regenerated .hh artifacts, the documentation block in hb-gpu.cc, and the util/gpu demo shaders. No behavior change. Assisted-by: Claude Opus 4.6 (1M context) --- src/hb-gpu-draw-fragment-glsl.hh | 18 +++++++++--------- src/hb-gpu-draw-fragment-hlsl.hh | 18 +++++++++--------- src/hb-gpu-draw-fragment-msl.hh | 18 +++++++++--------- src/hb-gpu-draw-fragment-wgsl.hh | 18 +++++++++--------- src/hb-gpu-draw-fragment.glsl | 18 +++++++++--------- src/hb-gpu-draw-fragment.hlsl | 18 +++++++++--------- src/hb-gpu-draw-fragment.msl | 18 +++++++++--------- src/hb-gpu-draw-fragment.wgsl | 18 +++++++++--------- src/hb-gpu.cc | 12 ++++++------ util/gpu/demo-metal.mm | 4 ++-- util/gpu/demo-renderer-d3d11.cc | 2 +- util/gpu/demo-shader.cc | 4 ++-- util/gpu/web/hb-gpu-web-webgpu.cc | 4 ++-- 13 files changed, 85 insertions(+), 85 deletions(-) diff --git a/src/hb-gpu-draw-fragment-glsl.hh b/src/hb-gpu-draw-fragment-glsl.hh index 141b80c5a..79a93926c 100644 --- a/src/hb-gpu-draw-fragment-glsl.hh +++ b/src/hb-gpu-draw-fragment-glsl.hh @@ -173,7 +173,7 @@ static const char *hb_gpu_draw_fragment_glsl = "}\n" "\n" "/* Single-sample coverage in [0, 1]. */\n" -"float _hb_gpu_render_single (vec2 renderCoord, vec2 pixelsPerEm, uint glyphLoc_)\n" +"float _hb_gpu_draw_single (vec2 renderCoord, vec2 pixelsPerEm, uint glyphLoc_)\n" "{\n" "\n" " _hb_gpu_glyph_info gi = _hb_gpu_decode_glyph (renderCoord, glyphLoc_);\n" @@ -293,12 +293,12 @@ static const char *hb_gpu_draw_fragment_glsl = " * renderCoord: em-space sample position\n" " * glyphLoc: texel offset of glyph blob in atlas\n" " */\n" -"float hb_gpu_render (vec2 renderCoord, uint glyphLoc_)\n" +"float hb_gpu_draw (vec2 renderCoord, uint glyphLoc_)\n" "{\n" " vec2 emsPerPixel = fwidth (renderCoord);\n" " vec2 pixelsPerEm = 1.0 / emsPerPixel;\n" "\n" -" float c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_);\n" +" float c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_);\n" "\n" "#ifndef HB_GPU_NO_MSAA\n" " float ppem = hb_gpu_ppem (renderCoord, glyphLoc_);\n" @@ -307,10 +307,10 @@ static const char *hb_gpu_draw_fragment_glsl = " {\n" " vec2 d = emsPerPixel * (1.0 / 3.0);\n" " float msaa = 0.25 *\n" -" (_hb_gpu_render_single (renderCoord + vec2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" -" _hb_gpu_render_single (renderCoord + vec2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" -" _hb_gpu_render_single (renderCoord + vec2 (-d.x, d.y), pixelsPerEm, glyphLoc_) +\n" -" _hb_gpu_render_single (renderCoord + vec2 ( d.x, d.y), pixelsPerEm, glyphLoc_));\n" +" (_hb_gpu_draw_single (renderCoord + vec2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" +" _hb_gpu_draw_single (renderCoord + vec2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" +" _hb_gpu_draw_single (renderCoord + vec2 (-d.x, d.y), pixelsPerEm, glyphLoc_) +\n" +" _hb_gpu_draw_single (renderCoord + vec2 ( d.x, d.y), pixelsPerEm, glyphLoc_));\n" "\n" " c = mix (c, msaa, smoothstep (16.0, 8.0, ppem));\n" " }\n" @@ -321,11 +321,11 @@ static const char *hb_gpu_draw_fragment_glsl = "\n" "/* Stem darkening for small sizes.\n" " *\n" -" * coverage: output of hb_gpu_render\n" +" * coverage: output of hb_gpu_draw\n" " * brightness: foreground brightness in [0, 1]\n" " * ppem: pixels per em at this fragment\n" " */\n" -"float hb_gpu_darken (float coverage, float brightness, float ppem)\n" +"float hb_gpu_draw_darken (float coverage, float brightness, float ppem)\n" "{\n" " return pow (coverage,\n" " mix (pow (2.0, brightness - 0.5), 1.0,\n" diff --git a/src/hb-gpu-draw-fragment-hlsl.hh b/src/hb-gpu-draw-fragment-hlsl.hh index a76b1932b..efb7999aa 100644 --- a/src/hb-gpu-draw-fragment-hlsl.hh +++ b/src/hb-gpu-draw-fragment-hlsl.hh @@ -159,7 +159,7 @@ static const char *hb_gpu_draw_fragment_hlsl = "\n" "\n" "/* Single-sample coverage in [0, 1]. */\n" -"float _hb_gpu_render_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_)\n" +"float _hb_gpu_draw_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_)\n" "{\n" "\n" " _hb_gpu_glyph_info gi = _hb_gpu_decode_glyph (renderCoord, glyphLoc_);\n" @@ -279,12 +279,12 @@ static const char *hb_gpu_draw_fragment_hlsl = " * renderCoord: em-space sample position\n" " * glyphLoc: texel offset of glyph blob in atlas\n" " */\n" -"float hb_gpu_render (float2 renderCoord, uint glyphLoc_)\n" +"float hb_gpu_draw (float2 renderCoord, uint glyphLoc_)\n" "{\n" " float2 emsPerPixel = fwidth (renderCoord);\n" " float2 pixelsPerEm = 1.0 / emsPerPixel;\n" "\n" -" float c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_);\n" +" float c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_);\n" "\n" "#ifndef HB_GPU_NO_MSAA\n" " float ppem = hb_gpu_ppem (renderCoord, glyphLoc_);\n" @@ -293,10 +293,10 @@ static const char *hb_gpu_draw_fragment_hlsl = " {\n" " float2 d = emsPerPixel * (1.0 / 3.0);\n" " float msaa = 0.25 *\n" -" (_hb_gpu_render_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" -" _hb_gpu_render_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" -" _hb_gpu_render_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_) +\n" -" _hb_gpu_render_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_));\n" +" (_hb_gpu_draw_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" +" _hb_gpu_draw_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) +\n" +" _hb_gpu_draw_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_) +\n" +" _hb_gpu_draw_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_));\n" "\n" " c = lerp (c, msaa, smoothstep (16.0, 8.0, ppem));\n" " }\n" @@ -307,11 +307,11 @@ static const char *hb_gpu_draw_fragment_hlsl = "\n" "/* Stem darkening for small sizes.\n" " *\n" -" * coverage: output of hb_gpu_render\n" +" * coverage: output of hb_gpu_draw\n" " * brightness: foreground brightness in [0, 1]\n" " * ppem: pixels per em at this fragment\n" " */\n" -"float hb_gpu_darken (float coverage, float brightness, float ppem)\n" +"float hb_gpu_draw_darken (float coverage, float brightness, float ppem)\n" "{\n" " return pow (coverage,\n" " lerp (pow (2.0, brightness - 0.5), 1.0,\n" diff --git a/src/hb-gpu-draw-fragment-msl.hh b/src/hb-gpu-draw-fragment-msl.hh index 9472aa564..ca12018c1 100644 --- a/src/hb-gpu-draw-fragment-msl.hh +++ b/src/hb-gpu-draw-fragment-msl.hh @@ -158,7 +158,7 @@ static const char *hb_gpu_draw_fragment_msl = "}\n" "\n" "/* Single-sample coverage in [0, 1]. */\n" -"float _hb_gpu_render_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_,\n" +"float _hb_gpu_draw_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_,\n" " device const short4* hb_gpu_atlas)\n" "{\n" "\n" @@ -280,13 +280,13 @@ static const char *hb_gpu_draw_fragment_msl = " * glyphLoc: texel offset of glyph blob in atlas\n" " * hb_gpu_atlas: device pointer to the atlas buffer\n" " */\n" -"float hb_gpu_render (float2 renderCoord, uint glyphLoc_,\n" +"float hb_gpu_draw (float2 renderCoord, uint glyphLoc_,\n" " device const short4* hb_gpu_atlas)\n" "{\n" " float2 emsPerPixel = fwidth (renderCoord);\n" " float2 pixelsPerEm = 1.0 / emsPerPixel;\n" "\n" -" float c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas);\n" +" float c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas);\n" "\n" "#ifndef HB_GPU_NO_MSAA\n" " float ppem = hb_gpu_ppem (renderCoord, glyphLoc_, hb_gpu_atlas);\n" @@ -295,10 +295,10 @@ static const char *hb_gpu_draw_fragment_msl = " {\n" " float2 d = emsPerPixel * (1.0 / 3.0);\n" " float msaa = 0.25 *\n" -" (_hb_gpu_render_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" -" _hb_gpu_render_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" -" _hb_gpu_render_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" -" _hb_gpu_render_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas));\n" +" (_hb_gpu_draw_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" +" _hb_gpu_draw_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" +" _hb_gpu_draw_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" +" _hb_gpu_draw_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas));\n" "\n" " c = mix (c, msaa, smoothstep (16.0, 8.0, ppem));\n" " }\n" @@ -309,11 +309,11 @@ static const char *hb_gpu_draw_fragment_msl = "\n" "/* Stem darkening for small sizes.\n" " *\n" -" * coverage: output of hb_gpu_render\n" +" * coverage: output of hb_gpu_draw\n" " * brightness: foreground brightness in [0, 1]\n" " * ppem: pixels per em at this fragment\n" " */\n" -"float hb_gpu_darken (float coverage, float brightness, float ppem)\n" +"float hb_gpu_draw_darken (float coverage, float brightness, float ppem)\n" "{\n" " return pow (coverage,\n" " mix (pow (2.0, brightness - 0.5), 1.0,\n" diff --git a/src/hb-gpu-draw-fragment-wgsl.hh b/src/hb-gpu-draw-fragment-wgsl.hh index d70a76933..3bc6ea0f9 100644 --- a/src/hb-gpu-draw-fragment-wgsl.hh +++ b/src/hb-gpu-draw-fragment-wgsl.hh @@ -160,7 +160,7 @@ static const char *hb_gpu_draw_fragment_wgsl = "}\n" "\n" "/* Single-sample coverage in [0, 1]. */\n" -"fn _hb_gpu_render_single (renderCoord: vec2f, pixelsPerEm: vec2f, glyphLoc_: u32,\n" +"fn _hb_gpu_draw_single (renderCoord: vec2f, pixelsPerEm: vec2f, glyphLoc_: u32,\n" " hb_gpu_atlas: ptr>, read>) -> f32\n" "{\n" "\n" @@ -288,13 +288,13 @@ static const char *hb_gpu_draw_fragment_wgsl = " * glyphLoc: texel offset of glyph blob in atlas\n" " * hb_gpu_atlas: storage buffer pointer to the atlas\n" " */\n" -"fn hb_gpu_render (renderCoord: vec2f, glyphLoc_: u32,\n" +"fn hb_gpu_draw (renderCoord: vec2f, glyphLoc_: u32,\n" " hb_gpu_atlas: ptr>, read>) -> f32\n" "{\n" " let emsPerPixel = fwidth (renderCoord);\n" " let pixelsPerEm = 1.0 / emsPerPixel;\n" "\n" -" var c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas);\n" +" var c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas);\n" "\n" " let ppem = hb_gpu_ppem (renderCoord, glyphLoc_, hb_gpu_atlas);\n" "\n" @@ -302,10 +302,10 @@ static const char *hb_gpu_draw_fragment_wgsl = " {\n" " let d = emsPerPixel * (1.0 / 3.0);\n" " let msaa = 0.25 *\n" -" (_hb_gpu_render_single (renderCoord + vec2f (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" -" _hb_gpu_render_single (renderCoord + vec2f ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" -" _hb_gpu_render_single (renderCoord + vec2f (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" -" _hb_gpu_render_single (renderCoord + vec2f ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas));\n" +" (_hb_gpu_draw_single (renderCoord + vec2f (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" +" _hb_gpu_draw_single (renderCoord + vec2f ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" +" _hb_gpu_draw_single (renderCoord + vec2f (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) +\n" +" _hb_gpu_draw_single (renderCoord + vec2f ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas));\n" "\n" " c = mix (c, msaa, smoothstep (16.0, 8.0, ppem));\n" " }\n" @@ -315,11 +315,11 @@ static const char *hb_gpu_draw_fragment_wgsl = "\n" "/* Stem darkening for small sizes.\n" " *\n" -" * coverage: output of hb_gpu_render\n" +" * coverage: output of hb_gpu_draw\n" " * brightness: foreground brightness in [0, 1]\n" " * ppem: pixels per em at this fragment\n" " */\n" -"fn hb_gpu_darken (coverage: f32, brightness: f32, ppem: f32) -> f32\n" +"fn hb_gpu_draw_darken (coverage: f32, brightness: f32, ppem: f32) -> f32\n" "{\n" " return pow (coverage,\n" " mix (pow (2.0, brightness - 0.5), 1.0,\n" diff --git a/src/hb-gpu-draw-fragment.glsl b/src/hb-gpu-draw-fragment.glsl index a3872303a..c53f95fce 100644 --- a/src/hb-gpu-draw-fragment.glsl +++ b/src/hb-gpu-draw-fragment.glsl @@ -172,7 +172,7 @@ ivec2 _hb_gpu_curve_counts (vec2 renderCoord, uint glyphLoc_) } /* Single-sample coverage in [0, 1]. */ -float _hb_gpu_render_single (vec2 renderCoord, vec2 pixelsPerEm, uint glyphLoc_) +float _hb_gpu_draw_single (vec2 renderCoord, vec2 pixelsPerEm, uint glyphLoc_) { _hb_gpu_glyph_info gi = _hb_gpu_decode_glyph (renderCoord, glyphLoc_); @@ -292,12 +292,12 @@ float _hb_gpu_render_single (vec2 renderCoord, vec2 pixelsPerEm, uint glyphLoc_) * renderCoord: em-space sample position * glyphLoc: texel offset of glyph blob in atlas */ -float hb_gpu_render (vec2 renderCoord, uint glyphLoc_) +float hb_gpu_draw (vec2 renderCoord, uint glyphLoc_) { vec2 emsPerPixel = fwidth (renderCoord); vec2 pixelsPerEm = 1.0 / emsPerPixel; - float c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_); + float c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_); #ifndef HB_GPU_NO_MSAA float ppem = hb_gpu_ppem (renderCoord, glyphLoc_); @@ -306,10 +306,10 @@ float hb_gpu_render (vec2 renderCoord, uint glyphLoc_) { vec2 d = emsPerPixel * (1.0 / 3.0); float msaa = 0.25 * - (_hb_gpu_render_single (renderCoord + vec2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) + - _hb_gpu_render_single (renderCoord + vec2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) + - _hb_gpu_render_single (renderCoord + vec2 (-d.x, d.y), pixelsPerEm, glyphLoc_) + - _hb_gpu_render_single (renderCoord + vec2 ( d.x, d.y), pixelsPerEm, glyphLoc_)); + (_hb_gpu_draw_single (renderCoord + vec2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) + + _hb_gpu_draw_single (renderCoord + vec2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) + + _hb_gpu_draw_single (renderCoord + vec2 (-d.x, d.y), pixelsPerEm, glyphLoc_) + + _hb_gpu_draw_single (renderCoord + vec2 ( d.x, d.y), pixelsPerEm, glyphLoc_)); c = mix (c, msaa, smoothstep (16.0, 8.0, ppem)); } @@ -320,11 +320,11 @@ float hb_gpu_render (vec2 renderCoord, uint glyphLoc_) /* Stem darkening for small sizes. * - * coverage: output of hb_gpu_render + * coverage: output of hb_gpu_draw * brightness: foreground brightness in [0, 1] * ppem: pixels per em at this fragment */ -float hb_gpu_darken (float coverage, float brightness, float ppem) +float hb_gpu_draw_darken (float coverage, float brightness, float ppem) { return pow (coverage, mix (pow (2.0, brightness - 0.5), 1.0, diff --git a/src/hb-gpu-draw-fragment.hlsl b/src/hb-gpu-draw-fragment.hlsl index c18898e3a..a466b3584 100644 --- a/src/hb-gpu-draw-fragment.hlsl +++ b/src/hb-gpu-draw-fragment.hlsl @@ -158,7 +158,7 @@ int2 _hb_gpu_curve_counts (float2 renderCoord, uint glyphLoc_) /* Single-sample coverage in [0, 1]. */ -float _hb_gpu_render_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_) +float _hb_gpu_draw_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_) { _hb_gpu_glyph_info gi = _hb_gpu_decode_glyph (renderCoord, glyphLoc_); @@ -278,12 +278,12 @@ float _hb_gpu_render_single (float2 renderCoord, float2 pixelsPerEm, uint glyphL * renderCoord: em-space sample position * glyphLoc: texel offset of glyph blob in atlas */ -float hb_gpu_render (float2 renderCoord, uint glyphLoc_) +float hb_gpu_draw (float2 renderCoord, uint glyphLoc_) { float2 emsPerPixel = fwidth (renderCoord); float2 pixelsPerEm = 1.0 / emsPerPixel; - float c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_); + float c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_); #ifndef HB_GPU_NO_MSAA float ppem = hb_gpu_ppem (renderCoord, glyphLoc_); @@ -292,10 +292,10 @@ float hb_gpu_render (float2 renderCoord, uint glyphLoc_) { float2 d = emsPerPixel * (1.0 / 3.0); float msaa = 0.25 * - (_hb_gpu_render_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) + - _hb_gpu_render_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) + - _hb_gpu_render_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_) + - _hb_gpu_render_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_)); + (_hb_gpu_draw_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_) + + _hb_gpu_draw_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_) + + _hb_gpu_draw_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_) + + _hb_gpu_draw_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_)); c = lerp (c, msaa, smoothstep (16.0, 8.0, ppem)); } @@ -306,11 +306,11 @@ float hb_gpu_render (float2 renderCoord, uint glyphLoc_) /* Stem darkening for small sizes. * - * coverage: output of hb_gpu_render + * coverage: output of hb_gpu_draw * brightness: foreground brightness in [0, 1] * ppem: pixels per em at this fragment */ -float hb_gpu_darken (float coverage, float brightness, float ppem) +float hb_gpu_draw_darken (float coverage, float brightness, float ppem) { return pow (coverage, lerp (pow (2.0, brightness - 0.5), 1.0, diff --git a/src/hb-gpu-draw-fragment.msl b/src/hb-gpu-draw-fragment.msl index bd4ba056b..3c3f23d40 100644 --- a/src/hb-gpu-draw-fragment.msl +++ b/src/hb-gpu-draw-fragment.msl @@ -157,7 +157,7 @@ int2 _hb_gpu_curve_counts (float2 renderCoord, uint glyphLoc_, } /* Single-sample coverage in [0, 1]. */ -float _hb_gpu_render_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_, +float _hb_gpu_draw_single (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_, device const short4* hb_gpu_atlas) { @@ -279,13 +279,13 @@ float _hb_gpu_render_single (float2 renderCoord, float2 pixelsPerEm, uint glyphL * glyphLoc: texel offset of glyph blob in atlas * hb_gpu_atlas: device pointer to the atlas buffer */ -float hb_gpu_render (float2 renderCoord, uint glyphLoc_, +float hb_gpu_draw (float2 renderCoord, uint glyphLoc_, device const short4* hb_gpu_atlas) { float2 emsPerPixel = fwidth (renderCoord); float2 pixelsPerEm = 1.0 / emsPerPixel; - float c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas); + float c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas); #ifndef HB_GPU_NO_MSAA float ppem = hb_gpu_ppem (renderCoord, glyphLoc_, hb_gpu_atlas); @@ -294,10 +294,10 @@ float hb_gpu_render (float2 renderCoord, uint glyphLoc_, { float2 d = emsPerPixel * (1.0 / 3.0); float msaa = 0.25 * - (_hb_gpu_render_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + - _hb_gpu_render_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + - _hb_gpu_render_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + - _hb_gpu_render_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas)); + (_hb_gpu_draw_single (renderCoord + float2 (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + + _hb_gpu_draw_single (renderCoord + float2 ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + + _hb_gpu_draw_single (renderCoord + float2 (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + + _hb_gpu_draw_single (renderCoord + float2 ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas)); c = mix (c, msaa, smoothstep (16.0, 8.0, ppem)); } @@ -308,11 +308,11 @@ float hb_gpu_render (float2 renderCoord, uint glyphLoc_, /* Stem darkening for small sizes. * - * coverage: output of hb_gpu_render + * coverage: output of hb_gpu_draw * brightness: foreground brightness in [0, 1] * ppem: pixels per em at this fragment */ -float hb_gpu_darken (float coverage, float brightness, float ppem) +float hb_gpu_draw_darken (float coverage, float brightness, float ppem) { return pow (coverage, mix (pow (2.0, brightness - 0.5), 1.0, diff --git a/src/hb-gpu-draw-fragment.wgsl b/src/hb-gpu-draw-fragment.wgsl index 7691142fd..21e751be2 100644 --- a/src/hb-gpu-draw-fragment.wgsl +++ b/src/hb-gpu-draw-fragment.wgsl @@ -159,7 +159,7 @@ fn _hb_gpu_curve_counts (renderCoord: vec2f, glyphLoc_: u32, } /* Single-sample coverage in [0, 1]. */ -fn _hb_gpu_render_single (renderCoord: vec2f, pixelsPerEm: vec2f, glyphLoc_: u32, +fn _hb_gpu_draw_single (renderCoord: vec2f, pixelsPerEm: vec2f, glyphLoc_: u32, hb_gpu_atlas: ptr>, read>) -> f32 { @@ -287,13 +287,13 @@ fn _hb_gpu_render_single (renderCoord: vec2f, pixelsPerEm: vec2f, glyphLoc_: u32 * glyphLoc: texel offset of glyph blob in atlas * hb_gpu_atlas: storage buffer pointer to the atlas */ -fn hb_gpu_render (renderCoord: vec2f, glyphLoc_: u32, +fn hb_gpu_draw (renderCoord: vec2f, glyphLoc_: u32, hb_gpu_atlas: ptr>, read>) -> f32 { let emsPerPixel = fwidth (renderCoord); let pixelsPerEm = 1.0 / emsPerPixel; - var c = _hb_gpu_render_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas); + var c = _hb_gpu_draw_single (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas); let ppem = hb_gpu_ppem (renderCoord, glyphLoc_, hb_gpu_atlas); @@ -301,10 +301,10 @@ fn hb_gpu_render (renderCoord: vec2f, glyphLoc_: u32, { let d = emsPerPixel * (1.0 / 3.0); let msaa = 0.25 * - (_hb_gpu_render_single (renderCoord + vec2f (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + - _hb_gpu_render_single (renderCoord + vec2f ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + - _hb_gpu_render_single (renderCoord + vec2f (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + - _hb_gpu_render_single (renderCoord + vec2f ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas)); + (_hb_gpu_draw_single (renderCoord + vec2f (-d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + + _hb_gpu_draw_single (renderCoord + vec2f ( d.x, -d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + + _hb_gpu_draw_single (renderCoord + vec2f (-d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas) + + _hb_gpu_draw_single (renderCoord + vec2f ( d.x, d.y), pixelsPerEm, glyphLoc_, hb_gpu_atlas)); c = mix (c, msaa, smoothstep (16.0, 8.0, ppem)); } @@ -314,11 +314,11 @@ fn hb_gpu_render (renderCoord: vec2f, glyphLoc_: u32, /* Stem darkening for small sizes. * - * coverage: output of hb_gpu_render + * coverage: output of hb_gpu_draw * brightness: foreground brightness in [0, 1] * ppem: pixels per em at this fragment */ -fn hb_gpu_darken (coverage: f32, brightness: f32, ppem: f32) -> f32 +fn hb_gpu_draw_darken (coverage: f32, brightness: f32, ppem: f32) -> f32 { return pow (coverage, mix (pow (2.0, brightness - 0.5), 1.0, diff --git a/src/hb-gpu.cc b/src/hb-gpu.cc index 303ee51da..077e1cdf2 100644 --- a/src/hb-gpu.cc +++ b/src/hb-gpu.cc @@ -256,7 +256,7 @@ * The fragment library provides two functions: * * |[ - * float hb_gpu_render (vec2 renderCoord, uint glyphLoc); + * float hb_gpu_draw (vec2 renderCoord, uint glyphLoc); * ]| * * It requires the `hb_gpu_atlas` uniform to be bound to the @@ -288,7 +288,7 @@ * out vec4 fragColor; * * void main () { - * float coverage = hb_gpu_render (v_texcoord, v_glyphLoc); + * float coverage = hb_gpu_draw (v_texcoord, v_glyphLoc); * fragColor = vec4 (0.0, 0.0, 0.0, coverage); * } * ]| @@ -300,7 +300,7 @@ * # Stem darkening * * |[ - * float hb_gpu_darken (float coverage, float brightness, float ppem); + * float hb_gpu_draw_darken (float coverage, float brightness, float ppem); * ]| * * Optional stem darkening adjusts coverage at small sizes so @@ -308,7 +308,7 @@ * * Parameters: * - * - coverage: the output of hb_gpu_render. + * - coverage: the output of hb_gpu_draw. * * - brightness: foreground brightness in [0, 1], computed as * `dot (foreground.rgb, vec3 (1.0 / 3.0))`. @@ -319,10 +319,10 @@ * Example: * * |[ - * float coverage = hb_gpu_render (v_texcoord, v_glyphLoc); + * float coverage = hb_gpu_draw (v_texcoord, v_glyphLoc); * float brightness = dot (u_foreground.rgb, vec3 (1.0 / 3.0)); * float ppem = 1.0 / max (fwidth (v_texcoord).x, * fwidth (v_texcoord).y); - * coverage = hb_gpu_darken (coverage, brightness, ppem); + * coverage = hb_gpu_draw_darken (coverage, brightness, ppem); * ]| **/ diff --git a/util/gpu/demo-metal.mm b/util/gpu/demo-metal.mm index 6e7dfb1d6..873926a35 100644 --- a/util/gpu/demo-metal.mm +++ b/util/gpu/demo-metal.mm @@ -60,11 +60,11 @@ vertex VertexOut vertex_main(VertexIn in [[stage_in]], fragment float4 fragment_main(VertexOut in [[stage_in]], constant Uniforms& uniforms [[buffer(1)]], device const short4* atlas [[buffer(0)]]) { - float coverage = hb_gpu_render(in.texcoord, in.glyphLoc, atlas); + float coverage = hb_gpu_draw(in.texcoord, in.glyphLoc, atlas); /* Stem darkening / thinning at small sizes. */ if (uniforms.stem_darkening > 0.0) - coverage = hb_gpu_darken(coverage, + coverage = hb_gpu_draw_darken(coverage, dot(uniforms.foreground.rgb, float3(1.0 / 3.0)), 1.0 / max(fwidth(in.texcoord).x, fwidth(in.texcoord).y)); diff --git a/util/gpu/demo-renderer-d3d11.cc b/util/gpu/demo-renderer-d3d11.cc index 8e9c3e88c..a53266a3e 100644 --- a/util/gpu/demo-renderer-d3d11.cc +++ b/util/gpu/demo-renderer-d3d11.cc @@ -123,7 +123,7 @@ PSInput vs_main (VSInput input) { } float4 ps_main (PSInput input) : SV_Target { - float coverage = hb_gpu_render (input.texcoord, input.glyphLoc); + float coverage = hb_gpu_draw (input.texcoord, input.glyphLoc); if (stem_darkening > 0.0) { float2 fw = fwidth (input.texcoord); float ppem = 1.0 / max (fw.x, fw.y); diff --git a/util/gpu/demo-shader.cc b/util/gpu/demo-shader.cc index d971fa007..483d4518d 100644 --- a/util/gpu/demo-shader.cc +++ b/util/gpu/demo-shader.cc @@ -46,14 +46,14 @@ out vec4 fragColor; void main () { - float coverage = hb_gpu_render (v_texcoord, v_glyphLoc); + float coverage = hb_gpu_draw (v_texcoord, v_glyphLoc); /* Stem darkening / thinning at small sizes. * Light text on dark: stems get too fat → thin them (exponent > 1). * Dark text on light: stems get too thin → darken them (exponent < 1). * The foreground brightness tells us which mode we're in. */ if (u_stem_darkening > 0.0) - coverage = hb_gpu_darken (coverage, + coverage = hb_gpu_draw_darken (coverage, dot (u_foreground.rgb, vec3 (1.0 / 3.0)), hb_gpu_ppem (v_texcoord, v_glyphLoc)); diff --git a/util/gpu/web/hb-gpu-web-webgpu.cc b/util/gpu/web/hb-gpu-web-webgpu.cc index a12294a24..c491e72e6 100644 --- a/util/gpu/web/hb-gpu-web-webgpu.cc +++ b/util/gpu/web/hb-gpu-web-webgpu.cc @@ -103,10 +103,10 @@ struct VertexOutput { } @fragment fn fs_main (in: VertexOutput) -> @location(0) vec4f { - var coverage = hb_gpu_render (in.texcoord, in.glyphLoc, &hb_gpu_atlas); + var coverage = hb_gpu_draw (in.texcoord, in.glyphLoc, &hb_gpu_atlas); if (u.stem_darkening > 0.0) { - coverage = hb_gpu_darken (coverage, + coverage = hb_gpu_draw_darken (coverage, dot (u.foreground.rgb, vec3f (1.0 / 3.0)), 1.0 / max (fwidth (in.texcoord).x, fwidth (in.texcoord).y)); }