mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 23:11:04 +01:00
[gpu] Unify shader source getters; rename for draw/paint split
Replace the two separate getters hb_gpu_shader_fragment_source (lang) hb_gpu_shader_vertex_source (lang) with a single hb_gpu_draw_shader_source (stage, lang) where stage is the new hb_gpu_shader_stage_t enum (VERTEX or FRAGMENT). Parameter order is stage-first because "the vertex shader in GLSL" reads more naturally than the reverse, and stage is the primary axis (it determines which shader object the source is compiled into). The `_draw_` in the new name makes room for the incoming hb_gpu_paint_shader_source() once the COLRv1 encoder lands — that family will have its own (likely different) shader sources per stage and language. Updated the four in-tree callers: test/api/test-gpu.cc, and the GPU demos under util/gpu/. ABI break on a 14.0-only API; the gpu library is still young enough that this is acceptable. Marked new API with XSince: REPLACEME. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
891cb21c7b
commit
eeec9bd9fa
9 files changed
+58
-68
No files matched your search
@@ -1119,8 +1119,8 @@ hb_vector_paint_recycle_blob
|
||||
<SECTION>
|
||||
<FILE>hb-gpu</FILE>
|
||||
hb_gpu_shader_lang_t
|
||||
hb_gpu_shader_fragment_source
|
||||
hb_gpu_shader_vertex_source
|
||||
hb_gpu_shader_stage_t
|
||||
hb_gpu_draw_shader_source
|
||||
hb_gpu_draw_t
|
||||
hb_gpu_draw_create_or_fail
|
||||
hb_gpu_draw_reference
|
||||
|
||||
+29
-46
@@ -39,62 +39,45 @@
|
||||
|
||||
|
||||
/**
|
||||
* hb_gpu_shader_fragment_source:
|
||||
* hb_gpu_draw_shader_source:
|
||||
* @stage: pipeline stage (vertex or fragment)
|
||||
* @lang: shader language variant
|
||||
*
|
||||
* Returns the fragment shader source for the specified shader
|
||||
* language. The returned string is static and must not be freed.
|
||||
* Returns the shader source for the hb_gpu_draw_t renderer for the
|
||||
* specified stage and language. The returned string is static and
|
||||
* must not be freed.
|
||||
*
|
||||
* The caller should prepend a `#version` directive and append
|
||||
* their own `main()` function, then pass the combined sources
|
||||
* For GLSL, the caller should prepend a `#version` directive and
|
||||
* append their own `main()` function, then pass the combined sources
|
||||
* to `glShaderSource()`.
|
||||
*
|
||||
* Return value: (transfer none):
|
||||
* A shader source string, or `NULL` if @lang is unsupported.
|
||||
* A shader source string, or `NULL` if @stage or @lang is
|
||||
* unsupported.
|
||||
*
|
||||
* Since: 14.0.0
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
const char *
|
||||
hb_gpu_shader_fragment_source (hb_gpu_shader_lang_t lang)
|
||||
hb_gpu_draw_shader_source (hb_gpu_shader_stage_t stage,
|
||||
hb_gpu_shader_lang_t lang)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_gpu_shader_vertex_source:
|
||||
* @lang: shader language variant
|
||||
*
|
||||
* Returns the vertex shader source for the specified shader
|
||||
* language. The returned string is static and must not be freed.
|
||||
*
|
||||
* Return value: (transfer none):
|
||||
* A shader source string, or `NULL` if @lang is unsupported.
|
||||
*
|
||||
* Since: 14.0.0
|
||||
**/
|
||||
const char *
|
||||
hb_gpu_shader_vertex_source (hb_gpu_shader_lang_t lang)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
+2
-7
@@ -100,15 +100,10 @@
|
||||
* directive and append your own main():
|
||||
*
|
||||
* |[<!-- language="plain" -->
|
||||
* unsigned vert_count, frag_count;
|
||||
* const char * const *vert_lib = hb_gpu_shader_vertex_sources (
|
||||
* HB_GPU_SHADER_LANG_GLSL, &vert_count);
|
||||
* const char * const *frag_lib = hb_gpu_shader_fragment_sources (
|
||||
* HB_GPU_SHADER_LANG_GLSL, &frag_count);
|
||||
*
|
||||
* const char *vert_sources[] = {
|
||||
* "#version 330\n",
|
||||
* hb_gpu_shader_vertex_source (HB_GPU_SHADER_LANG_GLSL),
|
||||
* hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_VERTEX,
|
||||
* HB_GPU_SHADER_LANG_GLSL),
|
||||
* your_vertex_main
|
||||
* };
|
||||
* glShaderSource (vert_shader, 3, vert_sources, NULL);
|
||||
|
||||
+15
-3
@@ -50,11 +50,23 @@ typedef enum {
|
||||
HB_GPU_SHADER_LANG_HLSL,
|
||||
} hb_gpu_shader_lang_t;
|
||||
|
||||
HB_EXTERN const char *
|
||||
hb_gpu_shader_fragment_source (hb_gpu_shader_lang_t lang);
|
||||
/**
|
||||
* hb_gpu_shader_stage_t:
|
||||
* @HB_GPU_SHADER_STAGE_VERTEX: Vertex shader stage.
|
||||
* @HB_GPU_SHADER_STAGE_FRAGMENT: Fragment shader stage.
|
||||
*
|
||||
* Shader pipeline stage.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
*/
|
||||
typedef enum {
|
||||
HB_GPU_SHADER_STAGE_VERTEX,
|
||||
HB_GPU_SHADER_STAGE_FRAGMENT,
|
||||
} hb_gpu_shader_stage_t;
|
||||
|
||||
HB_EXTERN const char *
|
||||
hb_gpu_shader_vertex_source (hb_gpu_shader_lang_t lang);
|
||||
hb_gpu_draw_shader_source (hb_gpu_shader_stage_t stage,
|
||||
hb_gpu_shader_lang_t lang);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,8 +182,8 @@ test_draw_funcs (void)
|
||||
static void
|
||||
test_shader_sources (void)
|
||||
{
|
||||
g_assert_nonnull (hb_gpu_shader_fragment_source (HB_GPU_SHADER_LANG_GLSL));
|
||||
g_assert_nonnull (hb_gpu_shader_vertex_source (HB_GPU_SHADER_LANG_GLSL));
|
||||
g_assert_nonnull (hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_FRAGMENT, HB_GPU_SHADER_LANG_GLSL));
|
||||
g_assert_nonnull (hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_VERTEX, HB_GPU_SHADER_LANG_GLSL));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -405,8 +405,8 @@ demo_renderer_create_metal (GLFWwindow *window)
|
||||
nswindow.contentView.wantsLayer = YES;
|
||||
|
||||
/* Compile shaders */
|
||||
const char *vert_src = hb_gpu_shader_vertex_source (HB_GPU_SHADER_LANG_MSL);
|
||||
const char *frag_src = hb_gpu_shader_fragment_source (HB_GPU_SHADER_LANG_MSL);
|
||||
const char *vert_src = hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_VERTEX, HB_GPU_SHADER_LANG_MSL);
|
||||
const char *frag_src = hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_FRAGMENT, HB_GPU_SHADER_LANG_MSL);
|
||||
|
||||
NSString *preamble = @"#include <metal_stdlib>\nusing namespace metal;\n";
|
||||
NSString *source = [NSString stringWithFormat:@"%@%s%s%s",
|
||||
|
||||
@@ -140,9 +140,9 @@ float4 ps_main (PSInput input) : SV_Target {
|
||||
|
||||
std::string full;
|
||||
full += "StructuredBuffer<int4> hb_gpu_atlas : register(t0);\n";
|
||||
full += hb_gpu_shader_vertex_source (HB_GPU_SHADER_LANG_HLSL);
|
||||
full += hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_VERTEX, HB_GPU_SHADER_LANG_HLSL);
|
||||
full += "\n";
|
||||
full += hb_gpu_shader_fragment_source (HB_GPU_SHADER_LANG_HLSL);
|
||||
full += hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_FRAGMENT, HB_GPU_SHADER_LANG_HLSL);
|
||||
full += "\n";
|
||||
full += hlsl_demo;
|
||||
|
||||
|
||||
@@ -156,14 +156,14 @@ demo_shader_create_program (void)
|
||||
#endif
|
||||
|
||||
const GLchar *vert_sources[] = {preamble,
|
||||
hb_gpu_shader_vertex_source (HB_GPU_SHADER_LANG_GLSL),
|
||||
hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_VERTEX, HB_GPU_SHADER_LANG_GLSL),
|
||||
demo_vertex_glsl};
|
||||
vertex_shader = compile_shader (GL_VERTEX_SHADER,
|
||||
ARRAY_LEN (vert_sources),
|
||||
vert_sources);
|
||||
|
||||
const GLchar *frag_sources[] = {preamble,
|
||||
hb_gpu_shader_fragment_source (HB_GPU_SHADER_LANG_GLSL),
|
||||
hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_FRAGMENT, HB_GPU_SHADER_LANG_GLSL),
|
||||
demo_fragment_glsl};
|
||||
fragment_shader = compile_shader (GL_FRAGMENT_SHADER,
|
||||
ARRAY_LEN (frag_sources),
|
||||
|
||||
@@ -831,9 +831,9 @@ static void
|
||||
create_pipeline ()
|
||||
{
|
||||
std::string wgsl;
|
||||
wgsl += hb_gpu_shader_vertex_source (HB_GPU_SHADER_LANG_WGSL);
|
||||
wgsl += hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_VERTEX, HB_GPU_SHADER_LANG_WGSL);
|
||||
wgsl += "\n";
|
||||
wgsl += hb_gpu_shader_fragment_source (HB_GPU_SHADER_LANG_WGSL);
|
||||
wgsl += hb_gpu_draw_shader_source (HB_GPU_SHADER_STAGE_FRAGMENT, HB_GPU_SHADER_LANG_WGSL);
|
||||
wgsl += "\n";
|
||||
wgsl += wgsl_demo_shader;
|
||||
|
||||
|
||||
Reference in new issue
Block a user