Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9bef5d3
upipe_blit: merge the background copy and the blit into a single pass
kierank Aug 1, 2026
b959010
tests: add new program to test ubuf_pic_blit
JDarnley Jul 1, 2026
fb8ae03
ubuf_pic_blit_test: add 1920x1080 benchmarks
JDarnley Jul 8, 2026
24c0c21
upipe: move ubuf_pic_blit out of header
JDarnley Aug 5, 2026
5a8b706
ubuf_pic: remove divides from the loops in ubuf_pic_blit_alpha10
JDarnley Aug 5, 2026
e791261
ubuf_pic: prefer size_t array indicies in ubuf_pic_blit_alpha10
JDarnley Aug 5, 2026
4409202
ubuf_pic: add SIMD optimized functions for threshold copy
JDarnley Aug 5, 2026
3a2c128
ubuf_pic_blit_test: check whole planes, in place and against a backgr…
kierank Aug 5, 2026
77001f0
upipe_blit: keep the subpicture across a flow definition change
kierank Aug 12, 2026
61cbd70
ubuf_pic_blit: add 10 bit alpha blend kernels
kierank Aug 12, 2026
b86e369
tests: the saturated threshold has kernels too now
kierank Aug 12, 2026
b757fb3
checkasm: cover the 10 bit alpha blend kernels
kierank Aug 12, 2026
5072c0b
ubuf_pic_blit: drop the SSSE3 kernels
kierank Aug 12, 2026
afb2e71
ubuf_pic_blit: add 8 bit alpha blend functions
JDarnley Aug 17, 2026
5191b91
checkasm: test the 8 bit blit blend kernels
kierank Oct 6, 2026
bac02a8
ubuf_pic_blit: 8 bit blend with pmaddubsw and pmulhuw
kierank Oct 6, 2026
9a2adae
tests: checkasm test for the blit threshold kernels
kierank Sep 28, 2026
78103e8
ubuf_pic_blit: add avx512 threshold kernels
kierank Sep 28, 2026
5edd0cd
ubuf_pic_blit: in place avx512 threshold kernels
kierank Oct 9, 2026
ffdcdc1
ubuf_pic_blit: fused avx512 hsub1 threshold kernels at 256 bits
kierank Oct 9, 2026
eaa4fba
ubuf_pic_blit: in place avx2 threshold and blend kernels that skip, a…
kierank Oct 9, 2026
545e590
ubuf_pic_blit: avx512 blend in place, rows shorter than one vector
kierank Oct 9, 2026
73da751
ubuf_pic_blit: dispatch the in place kernels where they win
kierank Oct 9, 2026
eaaa974
ubuf_pic_blit: kmovw from a 32 bit register
kierank Oct 9, 2026
59c5abf
ubuf_pic_blit: detect avx512 once
kierank Oct 16, 2026
bfd34be
x86inc: add the avx512icl cpuflag
JDarnley Aug 26, 2022
5f3c956
ubuf_pic_blit: blit10_blend hsub1/hsub2 AVX512-VNNI in ymm
kierank Nov 1, 2026
0403cfb
ubuf_pic_blit: blit8_blend_hsub2 in ymm with a vpermt2b alpha gather
kierank Nov 1, 2026
0b84cd1
ubuf_pic_blit: use the asm kernels only when they are built
kierank Nov 5, 2026
7737294
ubuf_pic_blit: add licence headers to the blit files
kierank Nov 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
379 changes: 77 additions & 302 deletions include/upipe/ubuf_pic.h

Large diffs are not rendered by default.

112 changes: 102 additions & 10 deletions lib/upipe-modules/upipe_blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ struct upipe_blit_sub {
/** computed vertical position */
uint64_t vposition;

/* The geometry above is what the next input is validated against, and a
* new flow definition replaces it. The ubuf keeps the geometry it was
* accepted under, so it stays blittable while the flow definition of the
* subpicture that follows it is being negotiated. */

/** horizontal size of ubuf */
uint64_t ubuf_hsize;
/** vertical size of ubuf */
uint64_t ubuf_vsize;
/** horizontal position of ubuf */
uint64_t ubuf_hposition;
/** vertical position of ubuf */
uint64_t ubuf_vposition;

/** flow format urequests */
struct uchain flow_format_requests;

Expand Down Expand Up @@ -217,6 +231,8 @@ static struct upipe *upipe_blit_sub_alloc(struct upipe_mgr *mgr,
sub->loffset_r = sub->roffset_r = sub->toffset_r = sub->boffset_r = 0;
sub->ubuf = NULL;
sub->hsize = sub->vsize = sub->hposition = sub->vposition = UINT64_MAX;
sub->ubuf_hsize = sub->ubuf_vsize =
sub->ubuf_hposition = sub->ubuf_vposition = UINT64_MAX;
ulist_init(&sub->flow_format_requests);

upipe_throw_ready(upipe);
Expand All @@ -237,8 +253,9 @@ static void upipe_blit_sub_work(struct upipe *upipe, struct uref *uref)
if (unlikely(sub->ubuf == NULL))
return;

int err = uref_pic_blit(uref, sub->ubuf, sub->hposition, sub->vposition,
0, 0, sub->hsize, sub->vsize, sub->alpha,
int err = uref_pic_blit(uref, sub->ubuf,
sub->ubuf_hposition, sub->ubuf_vposition,
0, 0, sub->ubuf_hsize, sub->ubuf_vsize, sub->alpha,
sub->alpha_threshold);
if (unlikely(!ubase_check(err))) {
upipe_warn(upipe, "unable to blit picture");
Expand Down Expand Up @@ -281,6 +298,13 @@ static void upipe_blit_sub_input(struct upipe *upipe, struct uref *uref,

ubuf_free(sub->ubuf);
sub->ubuf = uref_detach_ubuf(uref);
/* Keep the geometry it was accepted under: the one above is replaced as
* soon as the next subpicture's flow definition is negotiated, which
* happens while this one is still being blitted. */
sub->ubuf_hsize = sub->hsize;
sub->ubuf_vsize = sub->vsize;
sub->ubuf_hposition = sub->hposition;
sub->ubuf_vposition = sub->vposition;
uref_free(uref);
}

Expand Down Expand Up @@ -571,8 +595,9 @@ static int upipe_blit_sub_set_flow_def(struct upipe *upipe,
uref_pic_get_hposition(flow_def, &sub->hposition);
uref_pic_get_vposition(flow_def, &sub->vposition);

ubuf_free(sub->ubuf);
sub->ubuf = NULL;
/* The subpicture keeps being blitted until the next one arrives, and with
* a geometry per subpicture a flow definition arrives with every one of
* them, so dropping it here would leave nothing to blit. */

return UBASE_ERR_NONE;
}
Expand Down Expand Up @@ -749,6 +774,8 @@ static int _upipe_blit_sub_flush(struct upipe *upipe)
struct upipe_blit_sub *sub = upipe_blit_sub_from_upipe(upipe);
ubuf_free(sub->ubuf);
sub->ubuf = NULL;
sub->ubuf_hsize = sub->ubuf_vsize =
sub->ubuf_hposition = sub->ubuf_vposition = UINT64_MAX;
return UBASE_ERR_NONE;
}

Expand Down Expand Up @@ -1040,6 +1067,13 @@ static int upipe_blit_set_flow_def(struct upipe *upipe, struct uref *flow_def)
struct uchain *uchain;
ulist_foreach (&upipe_blit->subs, uchain) {
struct upipe_blit_sub *sub = upipe_blit_sub_from_uchain(uchain);
/* The subpictures were scaled and placed for the previous format, so
* unlike a change of their own flow definition this does invalidate
* them. */
ubuf_free(sub->ubuf);
sub->ubuf = NULL;
sub->ubuf_hsize = sub->ubuf_vsize =
sub->ubuf_hposition = sub->ubuf_vposition = UINT64_MAX;
upipe_blit_sub_provide_flow_format(upipe_blit_sub_to_upipe(sub));
}
return UBASE_ERR_NONE;
Expand Down Expand Up @@ -1086,24 +1120,82 @@ static int _upipe_blit_prepare(struct upipe *upipe, struct upump **upump_p)
}
}

/* Subpipe whose blit was merged with the copy, or NULL */
struct upipe_blit_sub *fused = NULL;

if (!writable) {
if (unlikely(!upipe_blit->ubuf_mgr)) {
upipe_warn(upipe, "no ubuf manager set, dropping...");
uref_free(uref);
return UBASE_ERR_BUSY;
}
struct ubuf *ubuf = ubuf_pic_copy(upipe_blit->ubuf_mgr,
uref->ubuf, 0, 0, -1, -1);
if (unlikely(ubuf == NULL)) {
uref_free(uref);
return UBASE_ERR_ALLOC;;
struct ubuf *old = uref->ubuf;
struct ubuf *ubuf = NULL;
size_t hsize, vsize;

/* Merge the copy and the blit of the bottom-most subpicture in a
* single pass: copy the four bands around the subpicture rectangle
* and compose the rectangle directly from the background and the
* subpicture, so that each pixel is written only once. */
if (ubase_check(ubuf_pic_size(old, &hsize, &vsize, NULL))) {
ulist_foreach (&upipe_blit->subs, uchain) {
struct upipe_blit_sub *sub = upipe_blit_sub_from_uchain(uchain);
if (sub->ubuf != NULL &&
sub->ubuf_hposition + sub->ubuf_hsize <= hsize &&
sub->ubuf_vposition + sub->ubuf_vsize <= vsize) {
fused = sub;
break;
}
}
}

if (fused != NULL) {
int w = hsize, h = vsize;
int hp = fused->ubuf_hposition, vp = fused->ubuf_vposition;
int hs = fused->ubuf_hsize, vs = fused->ubuf_vsize;
ubuf = ubuf_pic_alloc(upipe_blit->ubuf_mgr, w, h);
if (ubuf != NULL) {
int err = UBASE_ERR_NONE;
if (vp > 0)
err = ubuf_pic_blit(ubuf, old, 0, 0, 0, 0,
w, vp, 0xff, 0);
if (ubase_check(err) && vp + vs < h)
err = ubuf_pic_blit(ubuf, old, 0, vp + vs, 0, vp + vs,
w, h - vp - vs, 0xff, 0);
if (ubase_check(err) && hp > 0)
err = ubuf_pic_blit(ubuf, old, 0, vp, 0, vp,
hp, vs, 0xff, 0);
if (ubase_check(err) && hp + hs < w)
err = ubuf_pic_blit(ubuf, old, hp + hs, vp, hp + hs, vp,
w - hp - hs, vs, 0xff, 0);
if (ubase_check(err))
err = ubuf_pic_blit_bg(ubuf, old, fused->ubuf,
hp, vp, hp, vp, 0, 0, hs, vs,
fused->alpha,
fused->alpha_threshold);
if (unlikely(!ubase_check(err))) {
/* Fall back to a full copy followed by a blit */
ubuf_free(ubuf);
ubuf = NULL;
}
}
}

if (ubuf == NULL) {
fused = NULL;
ubuf = ubuf_pic_copy(upipe_blit->ubuf_mgr, old, 0, 0, -1, -1);
if (unlikely(ubuf == NULL)) {
uref_free(uref);
return UBASE_ERR_ALLOC;
}
}
uref_attach_ubuf(uref, ubuf);
}

ulist_foreach (&upipe_blit->subs, uchain) {
struct upipe_blit_sub *sub = upipe_blit_sub_from_uchain(uchain);
upipe_blit_sub_work(upipe_blit_sub_to_upipe(sub), uref);
if (sub != fused)
upipe_blit_sub_work(upipe_blit_sub_to_upipe(sub), uref);
}

upipe_blit_output(upipe, uref, upump_p);
Expand Down
5 changes: 5 additions & 0 deletions lib/upipe/Build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ libupipe-src = \
ubuf_mem.c \
ubuf_mem_common.c \
ubuf_pic.c \
ubuf_pic_blit_x86.h \
ubuf_pic_common.c \
ubuf_pic_mem.c \
ubuf_sound_common.c \
Expand Down Expand Up @@ -163,6 +164,10 @@ libupipe-src = \
utrace.c \
uuri.c

libupipe-src += \
$(if $(and $(have_x86asm),$(have_x86_64)),x86/ubuf_pic_blit.asm) \
$(if $(and $(have_x86asm),$(have_x86_64)),x86/ubuf_pic_blit.h)

libupipe-ldlibs = -lm

include/upipe/config.h: config.h
Expand Down
Loading
Loading