[gpu] Merge *-shaders.cc dispatchers into the subsystem .cc files

Each subsystem already had a dedicated source file for its C API;
having the shader-source getter live in a separate `*-shaders.cc`
was unnecessary.  Merge:

  hb-gpu-shaders.cc       -> hb-gpu.cc
  hb-gpu-draw-shaders.cc  -> hb-gpu-draw.cc
  hb-gpu-paint-shaders.cc -> hb-gpu-paint.cc

Each subsystem's .cc is now self-contained: the lifecycle, glyph
accumulation, and shader-source getter all live together.

The large stringized-shader .hh artifacts are included locally at
the bottom of each file, right above the function that uses them,
rather than with the primary includes at the top -- they are only
used by one function.

Updates meson.build, CMakeLists.txt, and harfbuzz-world.cc to
drop the removed files.  All 241 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-13 12:10:35 -06:00
1 parent 70310b9e65
commit c643c5245c
9 files changed
+163 -259

No files matched your search

-3
View File
@@ -271,11 +271,8 @@ set (vector_project_headers
)
set (gpu_project_sources
${PROJECT_SOURCE_DIR}/src/hb-gpu.cc
${PROJECT_SOURCE_DIR}/src/hb-gpu-shaders.cc
${PROJECT_SOURCE_DIR}/src/hb-gpu-draw.cc
${PROJECT_SOURCE_DIR}/src/hb-gpu-draw-shaders.cc
${PROJECT_SOURCE_DIR}/src/hb-gpu-paint.cc
${PROJECT_SOURCE_DIR}/src/hb-gpu-paint-shaders.cc
)
set (gpu_project_headers
${PROJECT_SOURCE_DIR}/src/hb-gpu.h
-3
View File
@@ -102,11 +102,8 @@
#endif
#ifdef HB_HAS_GPU
#include "hb-gpu-draw-shaders.cc"
#include "hb-gpu-draw.cc"
#include "hb-gpu-paint-shaders.cc"
#include "hb-gpu-paint.cc"
#include "hb-gpu-shaders.cc"
#include "hb-gpu.cc"
#include "hb-static.cc"
#endif
-86
View File
@@ -1,86 +0,0 @@
/*
* Copyright (C) 2026 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author(s): Behdad Esfahbod
*/
#include "hb.hh"
#include "hb-gpu.h"
#include "hb-gpu-draw-fragment-glsl.hh"
#include "hb-gpu-draw-fragment-msl.hh"
#include "hb-gpu-draw-fragment-wgsl.hh"
#include "hb-gpu-draw-fragment-hlsl.hh"
/**
* hb_gpu_draw_shader_source:
* @stage: pipeline stage (vertex or fragment)
* @lang: shader language variant
*
* Returns the draw-renderer-specific shader source for the
* specified stage and language. The returned string is static
* and must not be freed.
*
* This source assumes the shared helpers returned by
* hb_gpu_shader_source() are concatenated ahead of it. The
* caller should assemble the full shader as
* `#version`-directive + hb_gpu_shader_source() +
* hb_gpu_draw_shader_source() + caller's `main()`.
*
* The vertex stage currently has no draw-specific helpers; this
* function returns an empty string for that stage so the caller
* can concatenate unconditionally.
*
* Return value: (transfer none):
* A shader source string, or `NULL` if @stage or @lang is
* unsupported.
*
* XSince: REPLACEME
**/
const char *
hb_gpu_draw_shader_source (hb_gpu_shader_stage_t stage,
hb_gpu_shader_lang_t lang)
{
switch (stage) {
case HB_GPU_SHADER_STAGE_FRAGMENT:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_draw_fragment_glsl;
case HB_GPU_SHADER_LANG_MSL: return hb_gpu_draw_fragment_msl;
case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_draw_fragment_wgsl;
case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_draw_fragment_hlsl;
default: return nullptr;
}
case HB_GPU_SHADER_STAGE_VERTEX:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL:
case HB_GPU_SHADER_LANG_MSL:
case HB_GPU_SHADER_LANG_WGSL:
case HB_GPU_SHADER_LANG_HLSL: return "";
default: return nullptr;
}
default:
return nullptr;
}
}
+57
View File
@@ -1168,3 +1168,60 @@ hb_gpu_draw_recycle_blob (hb_gpu_draw_t *draw,
return;
draw->recycled_blob = blob;
}
#include "hb-gpu-draw-fragment-glsl.hh"
#include "hb-gpu-draw-fragment-msl.hh"
#include "hb-gpu-draw-fragment-wgsl.hh"
#include "hb-gpu-draw-fragment-hlsl.hh"
/**
* hb_gpu_draw_shader_source:
* @stage: pipeline stage (vertex or fragment)
* @lang: shader language variant
*
* Returns the draw-renderer-specific shader source for the
* specified stage and language. The returned string is static
* and must not be freed.
*
* This source assumes the shared helpers returned by
* hb_gpu_shader_source() are concatenated ahead of it. The
* caller should assemble the full shader as
* `#version`-directive + hb_gpu_shader_source() +
* hb_gpu_draw_shader_source() + caller's `main()`.
*
* The vertex stage currently has no draw-specific helpers; this
* function returns an empty string for that stage so the caller
* can concatenate unconditionally.
*
* Return value: (transfer none):
* A shader source string, or `NULL` if @stage or @lang is
* unsupported.
*
* XSince: REPLACEME
**/
const char *
hb_gpu_draw_shader_source (hb_gpu_shader_stage_t stage,
hb_gpu_shader_lang_t lang)
{
switch (stage) {
case HB_GPU_SHADER_STAGE_FRAGMENT:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_draw_fragment_glsl;
case HB_GPU_SHADER_LANG_MSL: return hb_gpu_draw_fragment_msl;
case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_draw_fragment_wgsl;
case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_draw_fragment_hlsl;
default: return nullptr;
}
case HB_GPU_SHADER_STAGE_VERTEX:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL:
case HB_GPU_SHADER_LANG_MSL:
case HB_GPU_SHADER_LANG_WGSL:
case HB_GPU_SHADER_LANG_HLSL: return "";
default: return nullptr;
}
default:
return nullptr;
}
}
-75
View File
@@ -1,75 +0,0 @@
/*
* Copyright (C) 2026 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author(s): Behdad Esfahbod
*/
#include "hb.hh"
#include "hb-gpu.h"
/**
* hb_gpu_paint_shader_source:
* @stage: pipeline stage (vertex or fragment)
* @lang: shader language variant
*
* Returns the paint-renderer-specific shader source for the
* specified stage and language. The returned string is static
* and must not be freed.
*
* This source assumes the shared helpers returned by
* hb_gpu_shader_source() are concatenated ahead of it. The
* caller should assemble the full shader as
* `#version`-directive + hb_gpu_shader_source() +
* hb_gpu_paint_shader_source() + caller's `main()`.
*
* The paint-renderer shaders have not yet been implemented; this
* function currently returns an empty string for supported
* @stage / @lang combinations so callers can concatenate
* unconditionally.
*
* Return value: (transfer none):
* A shader source string, or `NULL` if @stage or @lang is
* unsupported.
*
* XSince: REPLACEME
**/
const char *
hb_gpu_paint_shader_source (hb_gpu_shader_stage_t stage,
hb_gpu_shader_lang_t lang)
{
switch (stage) {
case HB_GPU_SHADER_STAGE_FRAGMENT:
case HB_GPU_SHADER_STAGE_VERTEX:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL:
case HB_GPU_SHADER_LANG_MSL:
case HB_GPU_SHADER_LANG_WGSL:
case HB_GPU_SHADER_LANG_HLSL: return "";
default: return nullptr;
}
default:
return nullptr;
}
}
+46
View File
@@ -122,3 +122,49 @@ hb_gpu_paint_get_user_data (const hb_gpu_paint_t *paint,
{
return hb_object_get_user_data (paint, key);
}
/**
* hb_gpu_paint_shader_source:
* @stage: pipeline stage (vertex or fragment)
* @lang: shader language variant
*
* Returns the paint-renderer-specific shader source for the
* specified stage and language. The returned string is static
* and must not be freed.
*
* This source assumes the shared helpers returned by
* hb_gpu_shader_source() are concatenated ahead of it. The
* caller should assemble the full shader as
* `#version`-directive + hb_gpu_shader_source() +
* hb_gpu_paint_shader_source() + caller's `main()`.
*
* The paint-renderer shaders have not yet been implemented; this
* function currently returns an empty string for supported
* @stage / @lang combinations so callers can concatenate
* unconditionally.
*
* Return value: (transfer none):
* A shader source string, or `NULL` if @stage or @lang is
* unsupported.
*
* XSince: REPLACEME
**/
const char *
hb_gpu_paint_shader_source (hb_gpu_shader_stage_t stage,
hb_gpu_shader_lang_t lang)
{
switch (stage) {
case HB_GPU_SHADER_STAGE_FRAGMENT:
case HB_GPU_SHADER_STAGE_VERTEX:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL:
case HB_GPU_SHADER_LANG_MSL:
case HB_GPU_SHADER_LANG_WGSL:
case HB_GPU_SHADER_LANG_HLSL: return "";
default: return nullptr;
}
default:
return nullptr;
}
}
-89
View File
@@ -1,89 +0,0 @@
/*
* Copyright (C) 2026 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author(s): Behdad Esfahbod
*/
#include "hb.hh"
#include "hb-gpu.h"
#include "hb-gpu-fragment-glsl.hh"
#include "hb-gpu-fragment-msl.hh"
#include "hb-gpu-fragment-wgsl.hh"
#include "hb-gpu-fragment-hlsl.hh"
#include "hb-gpu-vertex-glsl.hh"
#include "hb-gpu-vertex-msl.hh"
#include "hb-gpu-vertex-wgsl.hh"
#include "hb-gpu-vertex-hlsl.hh"
/**
* hb_gpu_shader_source:
* @stage: pipeline stage (vertex or fragment)
* @lang: shader language variant
*
* Returns the shared helper shader source used by the hb-gpu
* renderers for the specified stage and language. The returned
* string is static and must not be freed.
*
* The shared source defines utilities such as the atlas sampler
* and the `hb_gpu_fetch()` accessor for the fragment stage, and
* the `hb_gpu_dilate()` helper for the vertex stage. Each
* renderer-specific source (for example,
* hb_gpu_draw_shader_source()) assumes these helpers are already
* in scope — callers should concatenate a `#version` directive,
* then this shared source, then the renderer-specific source,
* then their own `main()`.
*
* Return value: (transfer none):
* A shader source string, or `NULL` if @stage or @lang is
* unsupported.
*
* XSince: REPLACEME
**/
const char *
hb_gpu_shader_source (hb_gpu_shader_stage_t stage,
hb_gpu_shader_lang_t lang)
{
switch (stage) {
case HB_GPU_SHADER_STAGE_FRAGMENT:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_fragment_glsl;
case HB_GPU_SHADER_LANG_MSL: return hb_gpu_fragment_msl;
case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_fragment_wgsl;
case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_fragment_hlsl;
default: return nullptr;
}
case HB_GPU_SHADER_STAGE_VERTEX:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_vertex_glsl;
case HB_GPU_SHADER_LANG_MSL: return hb_gpu_vertex_msl;
case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_vertex_wgsl;
case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_vertex_hlsl;
default: return nullptr;
}
default:
return nullptr;
}
}
+60
View File
@@ -338,3 +338,63 @@
* coverage = hb_gpu_stem_darken (coverage, brightness, ppem);
* ]|
**/
#include "hb-gpu-fragment-glsl.hh"
#include "hb-gpu-fragment-msl.hh"
#include "hb-gpu-fragment-wgsl.hh"
#include "hb-gpu-fragment-hlsl.hh"
#include "hb-gpu-vertex-glsl.hh"
#include "hb-gpu-vertex-msl.hh"
#include "hb-gpu-vertex-wgsl.hh"
#include "hb-gpu-vertex-hlsl.hh"
/**
* hb_gpu_shader_source:
* @stage: pipeline stage (vertex or fragment)
* @lang: shader language variant
*
* Returns the shared helper shader source used by the hb-gpu
* renderers for the specified stage and language. The returned
* string is static and must not be freed.
*
* The shared source defines utilities such as the atlas sampler
* and the `hb_gpu_fetch()` accessor for the fragment stage, and
* the `hb_gpu_dilate()` helper for the vertex stage. Each
* renderer-specific source (for example,
* hb_gpu_draw_shader_source()) assumes these helpers are already
* in scope — callers should concatenate a `#version` directive,
* then this shared source, then the renderer-specific source,
* then their own `main()`.
*
* Return value: (transfer none):
* A shader source string, or `NULL` if @stage or @lang is
* unsupported.
*
* XSince: REPLACEME
**/
const char *
hb_gpu_shader_source (hb_gpu_shader_stage_t stage,
hb_gpu_shader_lang_t lang)
{
switch (stage) {
case HB_GPU_SHADER_STAGE_FRAGMENT:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_fragment_glsl;
case HB_GPU_SHADER_LANG_MSL: return hb_gpu_fragment_msl;
case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_fragment_wgsl;
case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_fragment_hlsl;
default: return nullptr;
}
case HB_GPU_SHADER_STAGE_VERTEX:
switch (lang) {
case HB_GPU_SHADER_LANG_GLSL: return hb_gpu_vertex_glsl;
case HB_GPU_SHADER_LANG_MSL: return hb_gpu_vertex_msl;
case HB_GPU_SHADER_LANG_WGSL: return hb_gpu_vertex_wgsl;
case HB_GPU_SHADER_LANG_HLSL: return hb_gpu_vertex_hlsl;
default: return nullptr;
}
default:
return nullptr;
}
}
-3
View File
@@ -851,11 +851,8 @@ endforeach
hb_gpu_sources = files(
'hb-gpu.cc',
'hb-gpu-shaders.cc',
'hb-gpu-draw.cc',
'hb-gpu-draw-shaders.cc',
'hb-gpu-paint.cc',
'hb-gpu-paint-shaders.cc',
'hb-static.cc',
)