14 Commits

Author SHA1 Message Date
Niklas Haas
1764683668 swscale/ops_backend: disable FP contraction where possible
In particular, Clang defaults to FP contraction enabled. GCC defaults to
off in standard C mode (-std=c11), but the C standard does not actually
require any particular default.

The #pragma STDC pragma, despite its name, warns on anything except Clang.

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/22796
See-also: https://discourse.llvm.org/t/fp-contraction-fma-on-by-default/64975
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-16 17:19:51 +00:00
Niklas Haas
3f39783337 swscale/ops_chain: simplify ff_sws_compile_op_tables() with int index
Instead of this needlessly complicated dance of allocating on-stack copies
of SwsOpList only to iterate with AVERROR(EAGAIN).

This was originally thought to be useful for compiling multiple ops at once,
but even that can be solved in easier ways.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-29 12:13:40 +02:00
Niklas Haas
8e3eacd7ad swscale/ops_chain: allow implementations to expose over_read/write
And plumb it all the way through to the SwsCompiledOp. This is cleaner than
setting up this metadata up-front in x86/ops.c; and more importantly, it
allows us to determine the amount of over-read programmatically during ops
setup.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Niklas Haas
3aef0213e7 swscale/ops_chain: add SwsContext to SwsImplParams
Mainly so that implementations can consult sws->flags, to e.g. decide
whether the kernel needs to be bit-exact.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-18 09:09:44 +00:00
Niklas Haas
4b5122bfb2 swscale/ops_dispatch: move on-stack mutation to ops backends
And move the remainder printing there as well.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Niklas Haas
cc334a223e swscale/ops_backend: move static table out of function body
Ditto for x86.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-05 23:34:56 +00:00
Ramiro Polla
23bb7c3907 swscale/ops_backend: mark unreachable branch
The pixel format for the process loops have already been checked at
this point to be valid.

The switch added in e4abfb8e51 returns AVERROR(EINVAL) in the default
case without calling ff_sws_op_chain_free(chain), but there's no need
to free it since we mark this branch as unreachable.
2026-02-27 16:44:19 +00:00
Lynne
ad452205b6 swscale/ops: add SwsOpBackend.hw_format
Allows to filter hardware formats.

Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:22 +01:00
Lynne
00907e1244 swscale/ops: realign after adding slice_align
This is a separate commit since it makes it easier to see the changes.

Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:21 +01:00
Lynne
9c51aa1824 swscale: add SwsCompiledOp.slice_align
Certain backends may not support (or need) slices, since they
would handle slicing themselves.

Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:21 +01:00
Niklas Haas
e4abfb8e51 swscale/ops_backend: avoid UB from incorrect function signature
Annoying C-ism; we can't overload the function type even though they will
always be pointers. We can't even get away with using (void *) in the
function signature, despite casts to void * being technically valid.

Avoid the issue altogether by just moving the process loop into the
type-specific template altogether, and just referring to the correct
compiled process function at runtime. Hopefully, the compiler should be
able to optimize these into a single implementation. GCC, at least, compiles
these down into a single implementation plus three stubs that just jmp
to the correct one.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-26 10:15:52 +00:00
Niklas Haas
e729f49645 swscale/ops_backend: allocate block storage up-front
Instead of in each read() function. Not only is this slightly faster, due
to promoting more tail calls, but it also allows us to have operation chains
that don't start with a read.

Also simplifies the implementations.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-02-19 19:44:46 +00:00
Kacper Michajłow
66faef3dbe swscale/ops_chain: add type removed ff_sws_op_chain_free_cb
to avoid pointer casting and UB of calling function with different
pointer type.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-09-13 18:14:02 +02:00
Niklas Haas
5aef513fb4 swscale/ops_backend: add reference backend basend on C templates
This will serve as a reference for the SIMD backends to come. That said,
with auto-vectorization enabled, the performance of this is not atrocious.
It easily beats the old C code and sometimes even the old SIMD.

In theory, we can dramatically speed it up by using GCC vectors instead of
arrays, but the performance gains from this are too dependent on exact GCC
versions and flags, so it practice it's not a substitute for a SIMD
implementation.
2025-09-01 19:28:36 +02:00