31 Commits

Author SHA1 Message Date
Niklas Haas
0e983a0604 swscale: align allocated frame buffers to SwsPass hints
This avoids hitting the slow memcpy fallback paths altogether, whenever
swscale.c is handling plane allocation.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
5441395a48 swscale/graph: add optimal alignment/padding hints
Allows the pass buffer allocator to make smarter decisions based on the actual
alignment requirements of the specific pass.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-10 15:12:18 +02:00
Niklas Haas
53ee892035 swscale/graph: add way to roll back passes
When an op list needs to be decomposed into a more complicated sequence
of passes, the compile() code may need to roll back passes that have already
been partially compiled, if a later pass fails to compile.

This matters for subpass splitting (e.g. for filtering), as well as for
plane splitting.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-28 18:50:13 +01:00
Niklas Haas
5230624619 swscale/graph: allocate output buffers after adding all passes
There's no reason to immediately allocate all of these; we can do it at the
end when we know for sure which passes we have.

This will matter especially if we ever add a way to remove passes again after
adding them (spoiler: we will).

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Niklas Haas
563cc8216b swscale/graph: allow setup() to return an error code
Useful for a handful of reasons, including Vulkan (which depends on external
device resources), but also a change I want to make to the tail handling.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-12 21:02:48 +00:00
Niklas Haas
2e29833832 swscale/graph: have ff_sws_graph_add_pass() free priv on failure
This is arguably more convenient for most downstream users, as will be
more prominently seen in the next commit.

Also allows this code to re-use a pass_free() helper with the graph uninit.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:01:51 +01:00
Niklas Haas
42a47838ea swscale/graph: add setup()/free() to ff_sws_graph_add_pass() signature
This is just slightly common enough a pattern that it IMO makes sense to do
so. This will also make more sense after the following commits.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:01:51 +01:00
Niklas Haas
5b8889f4e8 swscale/graph: add typedef for SwsPassSetup
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:01:51 +01:00
Niklas Haas
254c07bf60 swscale/graph: rename sws_filter_run_t to SwsPassFunc
This name is weirdly out-of-place in the libswscale naming convention.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:01:51 +01:00
Niklas Haas
d9e594ca96 swscale/graph: have ff_sws_graph_add_pass() return an error code
This allows distinguishing between different types of failure, e.g.
AVERROR(EINVAL) on invalid pass dimensions.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
02e4b45f7f swscale/graph: reintroduce SwsFrame
AVFrame just really doesn't have the semantics we want. However, there a
tangible benefit to having SwsFrame act as a carbon copy of a (subset of)
AVFrame.

This partially reverts commit 67f3627267.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-01 21:57:53 +00:00
Niklas Haas
67f3627267 swscale/graph: nuke SwsImg
This has now become fully redundant with AVFrame, especially since the
existence of SwsPassBuffer. Delete it, simplifying a lot of things and
avoiding reinventing the wheel everywhere.

Also generally reduces overhead, since there is less redundant copying
going on.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
4d7b1c3685 swscale/graph: move frame->field init logic to SwsGraph
And have ff_sws_graph_run() just take a bare AVFrame. This will help with
an upcoming change, aside from being a bit friendlier towards API users
in general.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
5121665463 swscale/graph: use AVFrame to track internal allocation
This commit replaces the AVBufferRef inside SwsPassBuffer by an AVFrame, in
anticipation of the SwsImg removal.

Incidentally, we could also now just use av_frame_get_buffer() here, but
at the cost of breaking the 1:1 relationship between planes and buffers,
which is required for per-plane refcopies.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Niklas Haas
e9d1ed3fdc swscale/graph: avoid stack copies of SwsImg
In the process of nuking this abstraction in favor of AVFrame.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-27 16:18:34 +00:00
Lynne
1d2e616d5f swscale: add a Vulkan backend for ops.c
Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:22 +01:00
Lynne
c911295f09 swscale: forward original frame pointers to ops.c backend
Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:21 +01:00
Niklas Haas
d918551650 swscale/graph: switch SwsPass.output to refstruct
Allows multiple passes to share a single output buffer reference. We always
allocate an output buffer so that subpasses can share the same output buffer
reference while still allowing that reference to implicitly point to the
final output image.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-23 19:39:17 +00:00
Niklas Haas
cc346b232d swscale/graph: store current pass input instead of global args
The global args to ff_sws_graph_run() really shouldn't matter inside thread
workers. If they ever do, it indicates a leaky abstraction. The only reason
it was needed in the first place was because of the way the input/output
buffers implicitly defaulted to the global args.

However, we can solve this much more elegantly by just calculating it in
ff_sws_graph_run() directly and storing the computed SwsImg inside the
execution state.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-23 19:39:17 +00:00
Niklas Haas
0b446cdccd swscale/graph: switch to an AVBufferRef per plane
This annoyingly requires recreating some of the logic inside av_img_alloc(),
because there's no good existing current helper accessible from libswscale
that gives per-plane allocations like this.

The new code is based off the calculations inside libavframe/bufferpool.c.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-23 19:39:17 +00:00
Niklas Haas
afa08f4971 swscale/graph: duplicate buffer dimensions in SwsPassBuffer
When multiple passes share a buffer reference, the true buffer dimensions
may be different for each pass, depending on slice alignment. So we can't
rely on the pass dimensions being representative.

Instead, store this information in the SwsPassBuffer itself.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-23 19:39:17 +00:00
Niklas Haas
fe25e54d0f swscale/graph: move output image into separate struct
I want to add more metadata to this and also turn it into a refstruct,
but get the cosmetic diff out of the way first.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-23 19:39:17 +00:00
Niklas Haas
18060a8820 swscale/graph: simplify ff_sws_graph_run() API
There's little reason not to directly take an SwsImg here; it's already an
internally visible struct.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-23 19:39:17 +00:00
Niklas Haas
c18676aae4 swscale/graph: pass per-pass image pointers to setup()
This behavior had no real justification and was just incredibly confusing,
since the in/out pointers passet to setup() did not match those passed to
run(), all for what is arguably an exception anyways (the palette setup).
2025-09-01 19:27:53 +02:00
Niklas Haas
6072e27e9a swscale/graph: prefer bools to ints
This is more consistent with the rest of the newly added code, which
universally switched to using bools for boolean values.
2025-05-18 15:00:45 +02:00
Niklas Haas
d95944786e swscale/graph: move vshift() and shift_img() to shared header
I need to reuse these inside `ops.c`.
2025-05-18 14:39:57 +02:00
Niklas Haas
51e912466f swscale/graph: expose ff_sws_graph_add_pass
So we can move pass-adding business logic outside of graph.c.
2025-05-18 14:37:33 +02:00
Niklas Haas
ae84aa775f swscale/utils: split off format code into new file
utils.c is getting quite crowded, and I need a new place to dump a lot of
format handling code for the ongoing rewrite. Rather than bloating this file
even more, start splitting format handling helpers off into a new file.

This also renames the existing utils.h header, which didn't really contain
anything except the SwsFormat definition anyway (the prototypes for what should
have been in utils.h are all still in the legacy swscale_internal.h).
2025-03-14 19:50:44 +01:00
Andreas Rheinhardt
4973bb661e swscale/cms,graph,lut3d: Use ff_-prefix, don't export internal functions
Symbols with the sws_* prefix are exported.

Reviewed-by: Alexander Strasser <eclipse7@gmx.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-01-12 15:41:39 +01:00
Niklas Haas
6da940e118 swscale/graph: allow dynamically updating HDR metadata
Without triggering a full graph reinit.
2024-12-23 12:33:43 +01:00
Niklas Haas
bf738412e8 swscale/graph: add new high-level scaler dispatch mechanism
This interface has been designed from the ground up to serve as a new
framework for dispatching various scaling operations at a high level. This
will eventually replace the old ad-hoc system of using cascaded contexts,
as well as allowing us to plug in more dynamic scaling passes requiring
intermediate steps, such as colorspace conversions, etc.

The starter implementation merely piggybacks off the existing sws_init() and
sws_scale(), functions, though it does bring the immediate improvement of
splitting up cascaded functions and pre/post conversion functions into
separate filter passes, which allows them to e.g. be executed in parallel
even when the main scaler is required to be single threaded. Additionally,
a dedicated (multi-threaded) noop memcpy pass substantially improves
throughput of that fast path.

Follow-up commits will eventually expand this to move all of the scaling
decision logic into the graph init function, and also eliminate some of the
current special cases.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-11-25 11:02:16 +01:00