diff --git a/src/hb-gpu-paint-fragment-glsl.hh b/src/hb-gpu-paint-fragment-glsl.hh index a8b95e5bd..d9dd00cb1 100644 --- a/src/hb-gpu-paint-fragment-glsl.hh +++ b/src/hb-gpu-paint-fragment-glsl.hh @@ -216,6 +216,22 @@ static const char *hb_gpu_paint_fragment_glsl = " return r;\n" "}\n" "\n" +"/* Wrap _hb_gpu_slug with a sub-glyph extents bail-out. Many\n" +" * paint layers cover a small region of the outer glyph quad; for\n" +" * fragments outside the layer's bbox (with an AA + MSAA-spread\n" +" * margin) the slug coverage is exactly 0, so we can skip the\n" +" * band/curve walk entirely. */\n" +"float _hb_gpu_slug_clipped (vec2 renderCoord, vec2 pixelsPerEm, uint glyphLoc_)\n" +"{\n" +" ivec4 header0 = hb_gpu_fetch (int (glyphLoc_));\n" +" vec4 ext = vec4 (header0) * HB_GPU_INV_UNITS;\n" +" vec2 margin = 2.0 / pixelsPerEm;\n" +" if (any (lessThan (renderCoord, ext.xy - margin)) ||\n" +" any (greaterThan (renderCoord, ext.zw + margin)))\n" +" return 0.0;\n" +" return _hb_gpu_slug (renderCoord, pixelsPerEm, glyphLoc_);\n" +"}\n" +"\n" "/* Walks the paint blob's flat op stream and returns a\n" " * premultiplied RGBA coverage value for the current fragment.\n" " *\n" @@ -257,8 +273,8 @@ static const char *hb_gpu_paint_fragment_glsl = " ? foreground\n" " : vec4 (ct) / 32767.0;\n" "\n" -" float cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" uint (base + payload));\n" +" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" uint (base + payload));\n" " vec4 src = vec4 (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" @@ -286,8 +302,8 @@ static const char *hb_gpu_paint_fragment_glsl = " base + grad_payload,\n" " stop_count, extend, foreground);\n" "\n" -" float cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" uint (base + payload));\n" +" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" uint (base + payload));\n" " vec4 src = vec4 (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" diff --git a/src/hb-gpu-paint-fragment-hlsl.hh b/src/hb-gpu-paint-fragment-hlsl.hh index 07218c3e3..9b90537b4 100644 --- a/src/hb-gpu-paint-fragment-hlsl.hh +++ b/src/hb-gpu-paint-fragment-hlsl.hh @@ -181,6 +181,22 @@ static const char *hb_gpu_paint_fragment_hlsl = " return r;\n" "}\n" "\n" +"/* Wrap _hb_gpu_slug with a sub-glyph extents bail-out. Many\n" +" * paint layers cover a small region of the outer glyph quad; for\n" +" * fragments outside the layer's bbox (with an AA + MSAA-spread\n" +" * margin) the slug coverage is exactly 0, so we can skip the\n" +" * band/curve walk entirely. */\n" +"float _hb_gpu_slug_clipped (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_)\n" +"{\n" +" int4 header0 = hb_gpu_fetch ((int) glyphLoc_);\n" +" float4 ext = (float4) header0 * HB_GPU_INV_UNITS;\n" +" float2 margin = 2.0 / pixelsPerEm;\n" +" if (any (renderCoord < ext.xy - margin) ||\n" +" any (renderCoord > ext.zw + margin))\n" +" return 0.0;\n" +" return _hb_gpu_slug (renderCoord, pixelsPerEm, glyphLoc_);\n" +"}\n" +"\n" "#define HB_GPU_PAINT_GROUP_DEPTH 4\n" "\n" "float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground)\n" @@ -212,8 +228,8 @@ static const char *hb_gpu_paint_fragment_hlsl = " ? foreground\n" " : (float4) ct / 32767.0;\n" "\n" -" float cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" (uint) (base + payload));\n" +" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" (uint) (base + payload));\n" " float4 src = float4 (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" @@ -240,8 +256,8 @@ static const char *hb_gpu_paint_fragment_hlsl = " base + grad_payload,\n" " stop_count, extend, foreground);\n" "\n" -" float cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" (uint) (base + payload));\n" +" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" (uint) (base + payload));\n" " float4 src = float4 (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" diff --git a/src/hb-gpu-paint-fragment-msl.hh b/src/hb-gpu-paint-fragment-msl.hh index 3e3841d70..47ff83dcf 100644 --- a/src/hb-gpu-paint-fragment-msl.hh +++ b/src/hb-gpu-paint-fragment-msl.hh @@ -191,6 +191,23 @@ static const char *hb_gpu_paint_fragment_msl = " return r;\n" "}\n" "\n" +"/* Wrap _hb_gpu_slug with a sub-glyph extents bail-out. Many\n" +" * paint layers cover a small region of the outer glyph quad; for\n" +" * fragments outside the layer's bbox (with an AA + MSAA-spread\n" +" * margin) the slug coverage is exactly 0, so we can skip the\n" +" * band/curve walk entirely. */\n" +"float _hb_gpu_slug_clipped (float2 renderCoord, float2 pixelsPerEm, uint glyphLoc_,\n" +" device const short4* hb_gpu_atlas)\n" +"{\n" +" int4 header0 = hb_gpu_fetch (hb_gpu_atlas, int (glyphLoc_));\n" +" float4 ext = float4 (header0) * HB_GPU_INV_UNITS;\n" +" float2 margin = 2.0 / pixelsPerEm;\n" +" if (any (renderCoord < ext.xy - margin) ||\n" +" any (renderCoord > ext.zw + margin))\n" +" return 0.0;\n" +" return _hb_gpu_slug (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas);\n" +"}\n" +"\n" "#define HB_GPU_PAINT_GROUP_DEPTH 4\n" "\n" "float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,\n" @@ -223,8 +240,8 @@ static const char *hb_gpu_paint_fragment_msl = " ? foreground\n" " : float4 (ct) / 32767.0;\n" "\n" -" float cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" uint (base + payload), hb_gpu_atlas);\n" +" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" uint (base + payload), hb_gpu_atlas);\n" " float4 src = float4 (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" @@ -254,8 +271,8 @@ static const char *hb_gpu_paint_fragment_msl = " stop_count, extend, foreground,\n" " hb_gpu_atlas);\n" "\n" -" float cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" uint (base + payload), hb_gpu_atlas);\n" +" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" uint (base + payload), hb_gpu_atlas);\n" " float4 src = float4 (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" diff --git a/src/hb-gpu-paint-fragment-wgsl.hh b/src/hb-gpu-paint-fragment-wgsl.hh index e4217b4a0..9d63b2d79 100644 --- a/src/hb-gpu-paint-fragment-wgsl.hh +++ b/src/hb-gpu-paint-fragment-wgsl.hh @@ -193,6 +193,24 @@ static const char *hb_gpu_paint_fragment_wgsl = " return r;\n" "}\n" "\n" +"/* Wrap _hb_gpu_slug with a sub-glyph extents bail-out. Many\n" +" * paint layers cover a small region of the outer glyph quad; for\n" +" * fragments outside the layer's bbox (with an AA + MSAA-spread\n" +" * margin) the slug coverage is exactly 0, so we can skip the\n" +" * band/curve walk entirely. */\n" +"fn _hb_gpu_slug_clipped (renderCoord: vec2f, pixelsPerEm: vec2f, glyphLoc_: u32,\n" +" hb_gpu_atlas: ptr>, read>) -> f32\n" +"{\n" +" let header0 = hb_gpu_fetch (hb_gpu_atlas, i32 (glyphLoc_));\n" +" let ext = vec4f (header0) * HB_GPU_INV_UNITS;\n" +" let margin = 2.0 / pixelsPerEm;\n" +" if (any (renderCoord < ext.xy - margin) ||\n" +" any (renderCoord > ext.zw + margin)) {\n" +" return 0.0;\n" +" }\n" +" return _hb_gpu_slug (renderCoord, pixelsPerEm, glyphLoc_, hb_gpu_atlas);\n" +"}\n" +"\n" "const HB_GPU_PAINT_GROUP_DEPTH: i32 = 4;\n" "\n" "fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,\n" @@ -233,8 +251,8 @@ static const char *hb_gpu_paint_fragment_wgsl = " col = vec4f (ct) / 32767.0;\n" " }\n" "\n" -" let cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" u32 (base + payload), hb_gpu_atlas);\n" +" let cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" u32 (base + payload), hb_gpu_atlas);\n" " let src = vec4f (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n" @@ -263,8 +281,8 @@ static const char *hb_gpu_paint_fragment_wgsl = " hb_gpu_atlas);\n" " }\n" "\n" -" let cov = _hb_gpu_slug (renderCoord, pixelsPerEm,\n" -" u32 (base + payload), hb_gpu_atlas);\n" +" let cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n" +" u32 (base + payload), hb_gpu_atlas);\n" " let src = vec4f (col.rgb * col.a, col.a) * cov;\n" " acc = src + acc * (1.0 - src.a);\n" "\n"