Skip to content

Commit fcc049c

Browse files
committed
Bug 1700434 - Add SWGL fast-path for ps_text_run. r=jrmuizel
This adds some swgl_commitTextureLinearR8ToRGBA8 variations so that we can deal with alpha glyph formats. Following that, a simple span shader is added that dispatches to this as appropriate. Differential Revision: https://phabricator.services.mozilla.com/D115551 [ghsync] From https://hg.mozilla.org/mozilla-central/rev/e53af9e245db6f90ebf083c66456a12ee99832cb
1 parent 4cdc61c commit fcc049c

File tree

6 files changed

+92
-22
lines changed

6 files changed

+92
-22
lines changed

glsl-to-cxx/src/hir.rs

+14
Original file line numberDiff line numberDiff line change
@@ -3976,6 +3976,13 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
39763976
Type::new(Void),
39773977
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4)],
39783978
);
3979+
declare_function(
3980+
state,
3981+
"swgl_commitTextureLinearR8ToRGBA8",
3982+
None,
3983+
Type::new(Void),
3984+
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4)],
3985+
);
39793986
declare_function(
39803987
state,
39813988
"swgl_commitPartialTextureLinearR8",
@@ -4011,6 +4018,13 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
40114018
Type::new(Void),
40124019
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4), Type::new(Float)],
40134020
);
4021+
declare_function(
4022+
state,
4023+
"swgl_commitTextureLinearColorR8ToRGBA8",
4024+
None,
4025+
Type::new(Void),
4026+
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4), Type::new(Vec4)],
4027+
);
40144028

40154029
declare_function(
40164030
state,

swgl/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ those span boundary pixels to estimate the coverage based on edge slope.
153153
```
154154
void swgl_commitTextureLinearRGBA8(sampler, vec2 uv, vec4 uv_bounds);
155155
void swgl_commitTextureLinearR8(sampler, vec2 uv, vec4 uv_bounds);
156+
void swgl_commitTextureLinearR8ToRGBA8(sampler, vec2 uv, vec4 uv_bounds);
156157
157158
void swgl_commitTextureLinearColorRGBA8(sampler, vec2 uv, vec4 uv_bounds, vec4|float color);
158159
void swgl_commitTextureLinearColorR8(sampler, vec2 uv, vec4 uv_bounds, vec4|float color);
160+
void swgl_commitTextureLinearColorR8ToRGBA8(sampler, vec2 uv, vec4 uv_bounds, vec4|float color);
159161
160162
void swgl_commitTextureLinearRepeatRGBA8(sampler, vec2 uv, vec2 tile_repeat, vec4 uv_repeat, vec4 uv_bounds);
161163
void swgl_commitTextureLinearRepeatColorRGBA8(sampler, vec2 uv, vec2 tile_repeat, vec4 uv_repeat, vec4 uv_bounds, vec4|float color);
@@ -181,7 +183,9 @@ within the supplied uv bounds. The color variations also accept a supplied color
181183
that modulates the result.
182184

183185
The RGBA8 versions may only be used to commit within `swgl_drawSpanRGBA8`, and
184-
the R8 versions may only be used to commit within `swgl_drawSpanR8`.
186+
the R8 versions may only be used to commit within `swgl_drawSpanR8`. The R8ToRGBA8
187+
versions may be used to sample from an R8 source while committing to an RGBA8
188+
framebuffer.
185189

186190
The Linear variations use a linear filter that bilinearly interpolates between
187191
the four samples near the pixel. The Nearest variations use a nearest filter

swgl/src/blend.h

+8-14
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,16 @@ static ALWAYS_INLINE P applyColor(P src, InvertColor) {
155155

156156
template <typename P>
157157
static ALWAYS_INLINE P applyColor(P src, P color) {
158-
return muldiv256(src, color);
158+
return muldiv255(color, src);
159159
}
160160

161161
static ALWAYS_INLINE WideRGBA8 applyColor(PackedRGBA8 src, WideRGBA8 color) {
162-
return muldiv256(unpack(src), color);
162+
return applyColor(unpack(src), color);
163163
}
164164

165-
// Packs a color on a scale of 0..256 rather than 0..255 to allow faster scale
166-
// math with muldiv256. Note that this can cause a slight rounding difference in
167-
// the result versus the 255 scale. To alleviate this we scale by 256.49, so
168-
// that the color rounds slightly up and in turn causes the the value it scales
169-
// to round slightly up as well.
170165
template <typename P, typename C>
171166
static ALWAYS_INLINE auto packColor(P* buf, C color) {
172-
return pack_span(buf, color, 256.49f);
167+
return pack_span(buf, color, 255.0f);
173168
}
174169

175170
template <typename P>
@@ -347,11 +342,10 @@ static void* swgl_SpanBuf = nullptr;
347342
// A pointer into the clip mask for the start of the span.
348343
static uint8_t* swgl_ClipMaskBuf = nullptr;
349344

350-
static ALWAYS_INLINE WideR8 expand_clip_mask(UNUSED uint8_t* buf, WideR8 mask) {
345+
static ALWAYS_INLINE WideR8 expand_mask(UNUSED uint8_t* buf, WideR8 mask) {
351346
return mask;
352347
}
353-
static ALWAYS_INLINE WideRGBA8 expand_clip_mask(UNUSED uint32_t* buf,
354-
WideR8 mask) {
348+
static ALWAYS_INLINE WideRGBA8 expand_mask(UNUSED uint32_t* buf, WideR8 mask) {
355349
WideRG8 maskRG = zip(mask, mask);
356350
return zip(maskRG, maskRG);
357351
}
@@ -367,9 +361,9 @@ static ALWAYS_INLINE uint8_t* get_clip_mask(P* buf) {
367361

368362
template <typename P>
369363
static ALWAYS_INLINE auto load_clip_mask(P* buf, int span)
370-
-> decltype(expand_clip_mask(buf, 0)) {
371-
return expand_clip_mask(
372-
buf, unpack(load_span<PackedR8>(get_clip_mask(buf), span)));
364+
-> decltype(expand_mask(buf, 0)) {
365+
return expand_mask(buf,
366+
unpack(load_span<PackedR8>(get_clip_mask(buf), span)));
373367
}
374368

375369
// Temporarily removes masking from the blend stage, assuming the caller will

swgl/src/swgl_ext.h

+42-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ static void commit_masked_solid_span(P* buf, C color, int len) {
1414
for (P* end = &buf[len]; buf < end; buf += 4, mask += 4) {
1515
commit_span(
1616
buf,
17-
blend_span(buf,
18-
applyColor(expand_clip_mask(
19-
buf, unpack(unaligned_load<PackedR8>(mask))),
20-
color)));
17+
blend_span(
18+
buf,
19+
applyColor(expand_mask(buf, unpack(unaligned_load<PackedR8>(mask))),
20+
color)));
2121
}
2222
restore_clip_mask();
2323
}
@@ -614,6 +614,44 @@ static inline LinearFilter needsTextureLinear(S sampler, T P, int span) {
614614
#define swgl_commitTextureLinearColorR8(s, p, uv_rect, color) \
615615
swgl_commitTextureLinear(R8, s, p, uv_rect, color, swgl_SpanLength)
616616

617+
// Helper function that samples from an R8 texture while expanding it to support
618+
// a differing framebuffer format.
619+
template <bool BLEND, typename S, typename C, typename P>
620+
static inline int blendTextureLinearR8(S sampler, vec2 uv, int span,
621+
const vec4_scalar& uv_rect, C color,
622+
P* buf) {
623+
if (!swgl_isTextureR8(sampler)) {
624+
return 0;
625+
}
626+
LINEAR_QUANTIZE_UV(sampler, uv, uv_step, uv_rect, min_uv, max_uv);
627+
for (P* end = buf + span; buf < end; buf += swgl_StepSize, uv += uv_step) {
628+
commit_blend_span<BLEND>(
629+
buf, applyColor(expand_mask(buf, textureLinearUnpackedR8(
630+
sampler,
631+
ivec2(clamp(uv, min_uv, max_uv)))),
632+
color));
633+
}
634+
return span;
635+
}
636+
637+
// Commit an entire span with linear filtering while expanding from R8 to RGBA8
638+
#define swgl_commitTextureLinearColorR8ToRGBA8(s, p, uv_rect, color) \
639+
do { \
640+
auto packed_color = packColor(swgl_OutRGBA8, color); \
641+
int drawn = 0; \
642+
if (blend_key) { \
643+
drawn = blendTextureLinearR8<true>(s, p, swgl_SpanLength, uv_rect, \
644+
packed_color, swgl_OutRGBA8); \
645+
} else { \
646+
drawn = blendTextureLinearR8<false>(s, p, swgl_SpanLength, uv_rect, \
647+
packed_color, swgl_OutRGBA8); \
648+
} \
649+
swgl_OutRGBA8 += drawn; \
650+
swgl_SpanLength -= drawn; \
651+
} while (0)
652+
#define swgl_commitTextureLinearR8ToRGBA8(s, p, uv_rect) \
653+
swgl_commitTextureLinearColorR8ToRGBA8(s, p, uv_rect, NoColor())
654+
617655
// Compute repeating UVs, possibly constrained by tile repeat limits
618656
static inline vec2 tileRepeatUV(vec2 uv, const vec2_scalar& tile_repeat) {
619657
if (tile_repeat.x > 0.0f) {

webrender/res/ps_text_run.glsl

+20
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,24 @@ void main() {
326326
#endif
327327
}
328328

329+
#if defined(SWGL_DRAW_SPAN) && defined(SWGL_BLEND) && defined(SWGL_CLIP_DIST)
330+
void swgl_drawSpanRGBA8() {
331+
// Only support simple swizzles for now. More complex swizzles must either
332+
// be handled by blend overrides or the slow path.
333+
if (v_mask_swizzle.x != 0.0 && v_mask_swizzle.x != 1.0) {
334+
return;
335+
}
336+
337+
#ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
338+
swgl_commitTextureLinearRGBA8(sColor0, v_uv, v_uv_bounds);
339+
#else
340+
if (swgl_isTextureR8(sColor0)) {
341+
swgl_commitTextureLinearColorR8ToRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
342+
} else {
343+
swgl_commitTextureLinearColorRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
344+
}
345+
#endif
346+
}
347+
#endif
348+
329349
#endif // WR_FRAGMENT_SHADER

wrench/reftests/text/reftest.list

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ fuzzy(1,1) == shadow-huge.yaml shadow-huge-ref.yaml
1616
== decorations.yaml decorations-ref.yaml
1717
skip_on(android,device) fuzzy(1,3635) fuzzy-if(platform(swgl),3,13395) == decorations-suite.yaml decorations-suite.png # Fails on Pixel2
1818
== 1658.yaml 1658-ref.yaml
19-
fuzzy(2,405) == split-batch.yaml split-batch-ref.yaml
19+
fuzzy(2,405) fuzzy-if(platform(swgl),2,1508) == split-batch.yaml split-batch-ref.yaml
2020
# Next 3 tests affected by bug 1548099 on Android
2121
skip_on(android) == shadow-red.yaml shadow-red-ref.yaml
22-
skip_on(android) fuzzy(1,999) fuzzy-if(platform(swgl),2,1081) == shadow-grey.yaml shadow-grey-ref.yaml
23-
skip_on(android) fuzzy(1,828) fuzzy-if(platform(swgl),1,1249) == shadow-grey-transparent.yaml shadow-grey-ref.yaml
22+
skip_on(android) fuzzy(1,999) fuzzy-if(platform(swgl),2,1324) == shadow-grey.yaml shadow-grey-ref.yaml
23+
skip_on(android) fuzzy(1,828) fuzzy-if(platform(swgl),2,1538) == shadow-grey-transparent.yaml shadow-grey-ref.yaml
2424
== subtle-shadow.yaml subtle-shadow-ref.yaml
2525
fuzzy(1,64) == shadow-atomic.yaml shadow-atomic-ref.yaml
2626
fuzzy(1,64) == shadow-clip-rect.yaml shadow-atomic-ref.yaml

0 commit comments

Comments
 (0)