mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 22:41:10 +01:00
[gpu] Compute quadratic coefficients from raw coordinates
Compute a and b from unshifted (raw int16 × power-of-2) coordinates so they are exact, then pass renderCoord-shifted p1 separately as the constant term. This eliminates float rounding residuals that made a non-zero for true lines, removing the need for an epsilon threshold in the linear fallback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4682e7b125
commit
29996d32a0
2 files changed
+56
-44
No files matched your search
+28
-22
@@ -74,40 +74,36 @@ static const char *hb_gpu_fragment_glsl =
|
||||
" return (0x2E74U >> shift) & 0x0101U;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"vec2 _hb_gpu_solve_horiz_poly (vec4 p12, vec2 p3)\n"
|
||||
"vec2 _hb_gpu_solve_horiz_poly (vec2 a, vec2 b, vec2 p1)\n"
|
||||
"{\n"
|
||||
" vec2 a = p12.xy - p12.zw * 2.0 + p3;\n"
|
||||
" vec2 b = p12.xy - p12.zw;\n"
|
||||
" float ra = 1.0 / a.y;\n"
|
||||
" float rb = 0.5 / b.y;\n"
|
||||
"\n"
|
||||
" float d = sqrt (max (b.y * b.y - a.y * p12.y, 0.0));\n"
|
||||
" float d = sqrt (max (b.y * b.y - a.y * p1.y, 0.0));\n"
|
||||
" float t1 = (b.y - d) * ra;\n"
|
||||
" float t2 = (b.y + d) * ra;\n"
|
||||
"\n"
|
||||
" if (abs (a.y) < 1.0 / 16384.0)\n"
|
||||
" t1 = t2 = p12.y * rb;\n"
|
||||
" if (a.y == 0.0)\n"
|
||||
" t1 = t2 = p1.y * rb;\n"
|
||||
"\n"
|
||||
" return vec2 ((a.x * t1 - b.x * 2.0) * t1 + p12.x,\n"
|
||||
" (a.x * t2 - b.x * 2.0) * t2 + p12.x);\n"
|
||||
" return vec2 ((a.x * t1 - b.x * 2.0) * t1 + p1.x,\n"
|
||||
" (a.x * t2 - b.x * 2.0) * t2 + p1.x);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"vec2 _hb_gpu_solve_vert_poly (vec4 p12, vec2 p3)\n"
|
||||
"vec2 _hb_gpu_solve_vert_poly (vec2 a, vec2 b, vec2 p1)\n"
|
||||
"{\n"
|
||||
" vec2 a = p12.xy - p12.zw * 2.0 + p3;\n"
|
||||
" vec2 b = p12.xy - p12.zw;\n"
|
||||
" float ra = 1.0 / a.x;\n"
|
||||
" float rb = 0.5 / b.x;\n"
|
||||
"\n"
|
||||
" float d = sqrt (max (b.x * b.x - a.x * p12.x, 0.0));\n"
|
||||
" float d = sqrt (max (b.x * b.x - a.x * p1.x, 0.0));\n"
|
||||
" float t1 = (b.x - d) * ra;\n"
|
||||
" float t2 = (b.x + d) * ra;\n"
|
||||
"\n"
|
||||
" if (abs (a.x) < 1.0 / 16384.0)\n"
|
||||
" t1 = t2 = p12.x * rb;\n"
|
||||
" if (a.x == 0.0)\n"
|
||||
" t1 = t2 = p1.x * rb;\n"
|
||||
"\n"
|
||||
" return vec2 ((a.y * t1 - b.y * 2.0) * t1 + p12.y,\n"
|
||||
" (a.y * t2 - b.y * 2.0) * t2 + p12.y);\n"
|
||||
" return vec2 ((a.y * t1 - b.y * 2.0) * t1 + p1.y,\n"
|
||||
" (a.y * t2 - b.y * 2.0) * t2 + p1.y);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float _hb_gpu_calc_coverage (float xcov, float ycov, float xwgt, float ywgt)\n"
|
||||
@@ -169,8 +165,11 @@ static const char *hb_gpu_fragment_glsl =
|
||||
" ivec4 raw12 = _hb_gpu_fetch (glyphLoc + curveOffset);\n"
|
||||
" ivec4 raw3 = _hb_gpu_fetch (glyphLoc + curveOffset + 1);\n"
|
||||
"\n"
|
||||
" vec4 p12 = vec4 (raw12) * HB_GPU_INV_UNITS - vec4 (renderCoord, renderCoord);\n"
|
||||
" vec2 p3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS - renderCoord;\n"
|
||||
" vec4 q12 = vec4 (raw12) * HB_GPU_INV_UNITS;\n"
|
||||
" vec2 q3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS;\n"
|
||||
"\n"
|
||||
" vec4 p12 = q12 - vec4 (renderCoord, renderCoord);\n"
|
||||
" vec2 p3 = q3 - renderCoord;\n"
|
||||
"\n"
|
||||
" if (hLeftRay) {\n"
|
||||
" if (min (min (p12.x, p12.z), p3.x) * pixelsPerEm.x > 0.5) break;\n"
|
||||
@@ -181,7 +180,9 @@ static const char *hb_gpu_fragment_glsl =
|
||||
" uint code = _hb_gpu_calc_root_code (p12.y, p12.w, p3.y);\n"
|
||||
" if (code != 0U)\n"
|
||||
" {\n"
|
||||
" vec2 r = _hb_gpu_solve_horiz_poly (p12, p3) * pixelsPerEm.x;\n"
|
||||
" vec2 a = q12.xy - q12.zw * 2.0 + q3;\n"
|
||||
" vec2 b = q12.xy - q12.zw;\n"
|
||||
" vec2 r = _hb_gpu_solve_horiz_poly (a, b, p12.xy) * pixelsPerEm.x;\n"
|
||||
" /* For leftward ray: saturate(0.5 - r) counts coverage from the left */\n"
|
||||
" vec2 cov = hLeftRay ? clamp (vec2 (0.5) - r, 0.0, 1.0)\n"
|
||||
" : clamp (r + vec2 (0.5), 0.0, 1.0);\n"
|
||||
@@ -216,8 +217,11 @@ static const char *hb_gpu_fragment_glsl =
|
||||
" ivec4 raw12 = _hb_gpu_fetch (glyphLoc + curveOffset);\n"
|
||||
" ivec4 raw3 = _hb_gpu_fetch (glyphLoc + curveOffset + 1);\n"
|
||||
"\n"
|
||||
" vec4 p12 = vec4 (raw12) * HB_GPU_INV_UNITS - vec4 (renderCoord, renderCoord);\n"
|
||||
" vec2 p3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS - renderCoord;\n"
|
||||
" vec4 q12 = vec4 (raw12) * HB_GPU_INV_UNITS;\n"
|
||||
" vec2 q3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS;\n"
|
||||
"\n"
|
||||
" vec4 p12 = q12 - vec4 (renderCoord, renderCoord);\n"
|
||||
" vec2 p3 = q3 - renderCoord;\n"
|
||||
"\n"
|
||||
" if (vLeftRay) {\n"
|
||||
" if (min (min (p12.y, p12.w), p3.y) * pixelsPerEm.y > 0.5) break;\n"
|
||||
@@ -228,7 +232,9 @@ static const char *hb_gpu_fragment_glsl =
|
||||
" uint code = _hb_gpu_calc_root_code (p12.x, p12.z, p3.x);\n"
|
||||
" if (code != 0U)\n"
|
||||
" {\n"
|
||||
" vec2 r = _hb_gpu_solve_vert_poly (p12, p3) * pixelsPerEm.y;\n"
|
||||
" vec2 a = q12.xy - q12.zw * 2.0 + q3;\n"
|
||||
" vec2 b = q12.xy - q12.zw;\n"
|
||||
" vec2 r = _hb_gpu_solve_vert_poly (a, b, p12.xy) * pixelsPerEm.y;\n"
|
||||
" vec2 cov = vLeftRay ? clamp (vec2 (0.5) - r, 0.0, 1.0)\n"
|
||||
" : clamp (r + vec2 (0.5), 0.0, 1.0);\n"
|
||||
"\n"
|
||||
|
||||
+28
-22
@@ -73,40 +73,36 @@ uint _hb_gpu_calc_root_code (float y1, float y2, float y3)
|
||||
return (0x2E74U >> shift) & 0x0101U;
|
||||
}
|
||||
|
||||
vec2 _hb_gpu_solve_horiz_poly (vec4 p12, vec2 p3)
|
||||
vec2 _hb_gpu_solve_horiz_poly (vec2 a, vec2 b, vec2 p1)
|
||||
{
|
||||
vec2 a = p12.xy - p12.zw * 2.0 + p3;
|
||||
vec2 b = p12.xy - p12.zw;
|
||||
float ra = 1.0 / a.y;
|
||||
float rb = 0.5 / b.y;
|
||||
|
||||
float d = sqrt (max (b.y * b.y - a.y * p12.y, 0.0));
|
||||
float d = sqrt (max (b.y * b.y - a.y * p1.y, 0.0));
|
||||
float t1 = (b.y - d) * ra;
|
||||
float t2 = (b.y + d) * ra;
|
||||
|
||||
if (abs (a.y) < 1.0 / 16384.0)
|
||||
t1 = t2 = p12.y * rb;
|
||||
if (a.y == 0.0)
|
||||
t1 = t2 = p1.y * rb;
|
||||
|
||||
return vec2 ((a.x * t1 - b.x * 2.0) * t1 + p12.x,
|
||||
(a.x * t2 - b.x * 2.0) * t2 + p12.x);
|
||||
return vec2 ((a.x * t1 - b.x * 2.0) * t1 + p1.x,
|
||||
(a.x * t2 - b.x * 2.0) * t2 + p1.x);
|
||||
}
|
||||
|
||||
vec2 _hb_gpu_solve_vert_poly (vec4 p12, vec2 p3)
|
||||
vec2 _hb_gpu_solve_vert_poly (vec2 a, vec2 b, vec2 p1)
|
||||
{
|
||||
vec2 a = p12.xy - p12.zw * 2.0 + p3;
|
||||
vec2 b = p12.xy - p12.zw;
|
||||
float ra = 1.0 / a.x;
|
||||
float rb = 0.5 / b.x;
|
||||
|
||||
float d = sqrt (max (b.x * b.x - a.x * p12.x, 0.0));
|
||||
float d = sqrt (max (b.x * b.x - a.x * p1.x, 0.0));
|
||||
float t1 = (b.x - d) * ra;
|
||||
float t2 = (b.x + d) * ra;
|
||||
|
||||
if (abs (a.x) < 1.0 / 16384.0)
|
||||
t1 = t2 = p12.x * rb;
|
||||
if (a.x == 0.0)
|
||||
t1 = t2 = p1.x * rb;
|
||||
|
||||
return vec2 ((a.y * t1 - b.y * 2.0) * t1 + p12.y,
|
||||
(a.y * t2 - b.y * 2.0) * t2 + p12.y);
|
||||
return vec2 ((a.y * t1 - b.y * 2.0) * t1 + p1.y,
|
||||
(a.y * t2 - b.y * 2.0) * t2 + p1.y);
|
||||
}
|
||||
|
||||
float _hb_gpu_calc_coverage (float xcov, float ycov, float xwgt, float ywgt)
|
||||
@@ -168,8 +164,11 @@ float hb_gpu_render (vec2 renderCoord, uint glyphLoc_)
|
||||
ivec4 raw12 = _hb_gpu_fetch (glyphLoc + curveOffset);
|
||||
ivec4 raw3 = _hb_gpu_fetch (glyphLoc + curveOffset + 1);
|
||||
|
||||
vec4 p12 = vec4 (raw12) * HB_GPU_INV_UNITS - vec4 (renderCoord, renderCoord);
|
||||
vec2 p3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS - renderCoord;
|
||||
vec4 q12 = vec4 (raw12) * HB_GPU_INV_UNITS;
|
||||
vec2 q3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS;
|
||||
|
||||
vec4 p12 = q12 - vec4 (renderCoord, renderCoord);
|
||||
vec2 p3 = q3 - renderCoord;
|
||||
|
||||
if (hLeftRay) {
|
||||
if (min (min (p12.x, p12.z), p3.x) * pixelsPerEm.x > 0.5) break;
|
||||
@@ -180,7 +179,9 @@ float hb_gpu_render (vec2 renderCoord, uint glyphLoc_)
|
||||
uint code = _hb_gpu_calc_root_code (p12.y, p12.w, p3.y);
|
||||
if (code != 0U)
|
||||
{
|
||||
vec2 r = _hb_gpu_solve_horiz_poly (p12, p3) * pixelsPerEm.x;
|
||||
vec2 a = q12.xy - q12.zw * 2.0 + q3;
|
||||
vec2 b = q12.xy - q12.zw;
|
||||
vec2 r = _hb_gpu_solve_horiz_poly (a, b, p12.xy) * pixelsPerEm.x;
|
||||
/* For leftward ray: saturate(0.5 - r) counts coverage from the left */
|
||||
vec2 cov = hLeftRay ? clamp (vec2 (0.5) - r, 0.0, 1.0)
|
||||
: clamp (r + vec2 (0.5), 0.0, 1.0);
|
||||
@@ -215,8 +216,11 @@ float hb_gpu_render (vec2 renderCoord, uint glyphLoc_)
|
||||
ivec4 raw12 = _hb_gpu_fetch (glyphLoc + curveOffset);
|
||||
ivec4 raw3 = _hb_gpu_fetch (glyphLoc + curveOffset + 1);
|
||||
|
||||
vec4 p12 = vec4 (raw12) * HB_GPU_INV_UNITS - vec4 (renderCoord, renderCoord);
|
||||
vec2 p3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS - renderCoord;
|
||||
vec4 q12 = vec4 (raw12) * HB_GPU_INV_UNITS;
|
||||
vec2 q3 = vec2 (raw3.rg) * HB_GPU_INV_UNITS;
|
||||
|
||||
vec4 p12 = q12 - vec4 (renderCoord, renderCoord);
|
||||
vec2 p3 = q3 - renderCoord;
|
||||
|
||||
if (vLeftRay) {
|
||||
if (min (min (p12.y, p12.w), p3.y) * pixelsPerEm.y > 0.5) break;
|
||||
@@ -227,7 +231,9 @@ float hb_gpu_render (vec2 renderCoord, uint glyphLoc_)
|
||||
uint code = _hb_gpu_calc_root_code (p12.x, p12.z, p3.x);
|
||||
if (code != 0U)
|
||||
{
|
||||
vec2 r = _hb_gpu_solve_vert_poly (p12, p3) * pixelsPerEm.y;
|
||||
vec2 a = q12.xy - q12.zw * 2.0 + q3;
|
||||
vec2 b = q12.xy - q12.zw;
|
||||
vec2 r = _hb_gpu_solve_vert_poly (a, b, p12.xy) * pixelsPerEm.y;
|
||||
vec2 cov = vLeftRay ? clamp (vec2 (0.5) - r, 0.0, 1.0)
|
||||
: clamp (r + vec2 (0.5), 0.0, 1.0);
|
||||
|
||||
|
||||
Reference in new issue
Block a user