Commit Graph

2772 Commits

Author SHA1 Message Date
Henrik Gramner c720f4d355 cli: Fix input_open() memory leak on fopen() failure 1.5.2 2025-10-27 20:44:47 +01:00
Niklas Haas fcbc3d1b93 loopfilter: align Av1FilterLUT struct members
Fixes a bug where the Av1FilterLUT instance used in checkasm was not
aligned properly.

In theory, the first ALIGN macro should imply the latter alignments as well,
but I decided to mark all fields as explicitly aligned for clarity; and
because that's the precedent set in other headers.

Allows us to drop the ALIGN macro on the other usage of this struct.
2025-10-20 13:50:43 +00:00
Jean-Baptiste Kempf f6965b7f12 Update NEWS for nasm 3.00 2025-10-20 11:20:53 +02:00
Adam Sampson 0bc6bd9341 x86: put the memory operand first for test
Older versions of nasm allowed the operands in either order, but nasm
3.00 requires the memory operand to be first as per the spec.
2025-10-05 14:03:24 +01:00
Khalid Masum af5cf2b1e7 Readme: improve consitency of compilation steps
Currently compilation steps use two different types of methods, manual
build directory creation and using meson setup build to directly create
the build directory. This potential makes the new user who wants to
build docs or cross compile confused about which step of compilation the
user is in. This patch aims to make these steps clear.
2025-08-24 17:26:19 +00:00
Jean-Baptiste Kempf 0558c332ca On the road to 1.5.2
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
2025-08-12 01:23:20 +02:00
Jean-Baptiste Kempf 04faac6900 Update COPYING years 2025-08-12 01:23:14 +02:00
Henrik Gramner 716164239a obu: Improve short-signaling reference frame index calculation
Reduces code size a fair amount, and with some loop unrolling
by the compiler the code becomes nearly branchless.
2025-07-09 14:24:07 +02:00
Henrik Gramner fa30043ba0 obu: Remove redundant zeroing in frame header parsing
The Dav1dFrameHeader struct is already zero-initialized,
so zeroing individual values a second time is redundant.
2025-07-07 16:00:30 +02:00
Matthias Dressel c3f3a7e567 CI: Check --frametimes with msan
This would have caught 583e8e02eb.
2025-07-01 18:35:31 +02:00
Ronald S. Bultje 583e8e02eb tools/dav1d: initialize elapsed
Based on the following comment on IRC:
"<aconz2> the `elapsed` variable in main() is read uninitialized in
 synchronize and makes the first frametime with --frametime incorrect
 I think. Should be initialized to 0"

Confirmed that after initializing to zero, the first line in the file
generated by --frametime is reasonable.
2025-07-01 08:26:31 -04:00
yuanhecai a86d561b79 loongarch: rename looprestoration_tmpl.c
Rename loongarch/looprestoration_tmpl.c to loongarch/looprestoration_inner.c.
Compiling both src/looprestoration_tmpl.c and loongarch/looprestoration_tmpl.c
produces looprestoration_tmpl.c.o, causing a conflict during linking.
2025-06-25 17:25:27 +08:00
yuanhecai 9eea4fe842 loongarch: Fix Clang compilation errors 2025-06-25 17:25:21 +08:00
Henrik Gramner b3c5848f7f loongarch: Use hidden visibility for asm functions 2025-06-07 22:36:38 +02:00
Henrik Gramner 63bf075aad recon: Fix level index calculation optimization for 2D transforms
Due to a typo this was never actually enabled since being added in
5ef6b24. As a result the slow path was always being used.
2025-06-02 15:54:28 +02:00
Henrik Gramner fe0ab51460 Use exact-width integer min/max defines where appropriate
Improves support for niche systems with uncommon integer sizes.
2025-05-29 19:38:49 +02:00
Henrik Gramner 29efbb9496 refmvs: Shrink mfmv_ref arrays
Includes updates to load_tmvs() asm implementations.
2025-05-28 19:01:45 +02:00
Henrik Gramner 68dc20035b refmvs: Shrink refpoc arrays 2025-05-28 19:01:45 +02:00
Henrik Gramner 7889ac7603 cdf: Remove unused eob_hi_bit entries 2025-05-28 02:06:08 +02:00
Matthias Dressel 8d95618093 CI: Build '-mavx' code as debugoptimized
Workaround a GCC 14 bug where it does not insert `vzeroupper` in C code
built without at least '-O2'.
2025-03-10 16:40:35 +01:00
Matthias Dressel edeac873c4 CI: Update images 2025-03-10 16:40:35 +01:00
Matthias Dressel 1d0cda02a6 CI: Update ppc64le image
Since there seems to be a problem with gcc-14 stay on gcc-13 for now.
2025-03-05 21:58:24 +01:00
Gianni Rosato caef968117 refactor: simplify deltaq bitstream parsing logic 2025-02-28 09:28:46 -05:00
Pranav Kant 7d4b789f55 Mark C globals with small code model
We have new option in clang (https://github.com/llvm/llvm-project/pull/124834)
to mark globals to be allocated in non-large sections. We can mark all globals
that are referenced from hardcoded assembly (which implicitly references globals
assuming they are in non-large sections) with this attribute to avoid running
into problems when dav1d is built with -mcmodel=medium with clang.
2025-02-21 15:55:00 +00:00
Jean-Baptiste Kempf 42b2b24fb8 Update NEWS for 1.5.1 1.5.1 2025-01-19 22:33:54 +01:00
Wan-Teh Chang 40ff2a1251 Include <string.h> for memcpy() 2025-01-10 01:54:41 +00:00
Arpad Panyik edb16889d1 AArch64: Add Neon implementation of load_tmvs
This patch adds a vectorised variant of the mv_projection calculation
and a faster initialisation of motion vectors for load_tmvs_neon.

Checkasm uplifts after this patch on some Neoverse and Cortex CPU cores
compared to the C reference compiled with GCC-13 and Clang-19:

                     GCC    Clang
 AWS Graviton 4:   1.62x    1.59x
 Cortex-X4:        1.45x    1.46x
 Cortex-X3:        1.68x    1.69x
 Cortex-X1:        1.55x    1.52x
 Cortex-A720:      1.54x    1.57x
 Cortex-A715:      1.47x    1.55x
 Cortex-A78:       1.21x    1.18x
 Cortex-A76:       1.38x    1.37x
 Cortex-A72:       1.08x    1.11x
 Cortex-A520:      0.97x    1.18x
 Cortex-A510:      0.99x    1.14x
 Cortex-A55:       1.16x    1.23x

This patch increases the .text by ~660 bytes, but smaller than the
reference implementation by about 0.5 KiB.
2025-01-09 14:59:31 +01:00
Martin Storsjö b129d9f2cb mc: Reduce stack use in {put,prep}_scaled_{bilin,8tap}
For the bilin cases, this seems to make things marginally faster
(measured on x86_64; 7-25% faster with compiler autovectorization).
For 8tap, it doesn't make much of a difference at all.

Before:                                      GCC   Clang
mc_scaled_8tap_regular_w128_8bpc_c:     115155.5   98549.3
mc_scaled_8tap_regular_w128_8bpc_ssse3:  17936.0   18411.1
mc_scaled_bilinear_w128_8bpc_c:          40290.0   51812.9
mc_scaled_bilinear_w128_8bpc_ssse3:      18243.9   18177.0
After:
mc_scaled_8tap_regular_w128_8bpc_c:     116304.3   99453.2
mc_scaled_8tap_regular_w128_8bpc_ssse3:  18387.0   18077.3
mc_scaled_bilinear_w128_8bpc_c:          37381.4   41145.0
mc_scaled_bilinear_w128_8bpc_ssse3:      18423.8   18031.6

(Benchmarked with the seed 0; the total runtime for the scaled
benchmarks are significantly affected by the random seed.)

This reduces the stack usage of these functions from around 65 KB
each, to less than 1 KB for bilin, and around 2 KB for 8tap.

With this in place, the required stack space for dav1d should
be mostly identical across configurations; on x86_64 (both with
and without assembly), it can run with 62 KB of stack, and
on arm and aarch64, it can run with 58 KB of stack.
2025-01-02 15:30:21 +00:00
Brad Smith cd5bfa124a riscv: Fix building on non-Linux OS's
CLOCK_MONOTONIC_RAW is not POSIX/portable.
2024-12-29 18:32:23 +00:00
James Almer 5ea4939a1d obu: don't print warnings for Metadata OBUs of types "Unregistered user private" 2024-12-27 13:48:54 -03:00
Martin Storsjö 2ba57aa535 arm32: looprestoration: Rewrite the wiener functions
Switch to the same cache-friendly algorithm as was done for arm64
in 2e73051c57 and for the reference
C code in 8291a66e50.

Contrary to the arm64 implementation, this uses a main loop in C
(very similar to the one in the main C implementation in
8291a66e50) rather than assembly;
this gives a bit more overhead on the call to each function, but
it shouldn't affect the big picture much.

Performane wise, this doesn't make much of a difference - it makes
things a little bit faster on some cores, and a little bit slower
on others:

Before:                 Cortex A7        A8       A53       A72       A73
wiener_7tap_8bpc_neon:   269384.4  147730.7  140028.5   92662.5   92929.0
wiener_7tap_10bpc_neon:  352690.2  159970.2  169427.8  116614.9  119371.1
After:
wiener_7tap_8bpc_neon:   238328.0  157274.1  134588.6   92200.3   97619.6
wiener_7tap_10bpc_neon:  336369.3  162182.0  161954.4  125521.2  130634.0

This is mostly in line with the results on arm64 in
2e73051c57. On arm64, there was a
bit larger speedup for the 7tap case, mostly attributed to
unrolling the vertical filter (and the new filter_hv function) to
operate on 16 pixels at a time. On arm32, there's not enough
registers to do that, so we can't get such gains from unrolling.
(Reducing the unrolling on the arm64 version to match the case
on arm32 also shows similar performance numbers as on arm32 here.)

In the arm64 version, we also added separate 5tap versions of all
functions; not doing that for arm32 at this point.

This increases the binary size by 2 KB.

This doesn't have any immediate effect on how much stack space
dav1d requires in total, since the largest stack users on arm
currently are the 8tap_scaled functions.
2024-12-20 14:32:32 +02:00
Martin Storsjö 8291a66e50 looprestoration: Use only 6 row buffer for wiener, like NEON/x86
This uses a separate function for combined horizontal and vertical
filtering, without needing to write the intermediate results
back to memory inbetween.

This mostly serves as an example for how to adjust the logic for
that case; unless we actually merge the horizontal and vertical
filtering within the _hv function, we still need space for a
7th row on the stack within that function (which means we use just
as much stack as before), but we also need one extra memcpy to
write it into the right destination.

In a build where the compiler is allowed to vectorize and inline
the wiener functions into each other, this change actually reduces
the final binary size by 4 KB, if the C version of the wiener filter
is retained.

This change makes the vectorized C code as fast as it was before
with Clang 18; on Xcode Clang 16, it's 2x slower than it was before.

Unfortunately, with GCC, this change makes the code a bit slower
again.
2024-12-19 14:19:19 +02:00
Martin Storsjö a149f5c3c0 looprestoration: Make the C wiener h filter more optimizable for the compiler
This increases the binary size by 9 KB, on aarch64 with Xcode Clang 16,
if the C version of the filter is retained (which it isn't
by default).

This makes the vectorized C code roughly as fast as it was before
the rewrite on GCC; on Clang it also becomes 1.3x-2.0x faster,
while still being slower than it was initially.
2024-12-19 14:19:19 +02:00
Martin Storsjö 9da303e989 looprestoration: Rewrite the C version of the wiener filter
This reduces the stack usage of these functions (the C version)
significantly.

These C versions aren't used on architectures that already have
wiener filters implemented in assembly, but they matter both if
running e.g. with assembly disabled (e.g. for sanitizer builds),
and matter as example for how to do a cache efficient SIMD
implementation.

This roughly matches how these functions are implemented in the
aarch64 assembly (although that assembly function uses a mainloop
function written in assembly, and custom calling conventions
between the functions).

With this in place, dav1d can run with around 76 KB of stack
with assembly disabled.

This increases the binary size by around 14 KB (in the case of
aarch64 with Xcode Clang 16), unless built with (the default)
-Dtrim_dsp=true. (By default, the C version of the wiener filter
gets skipped entirely.)

On 32 bit arm, the assembly wiener function implementation still
uses large buffers on the stack though, but due to other functions
using less stack there, dav1d can still run with 72 KB of stack
there.

Unfortunately, this change also makes the functions slower, depending
on how well the compiler was able to optimize the previous version.
On GCC (which didn't manage to vectorize the functions so well before),
it becomes 1.6x-2.0x slower, while it gets 2.5x-5x slower on Clang
(where it was very well vectorized before).

Most of this performance can be gained back with later changes on
top, though.
2024-12-19 14:19:13 +02:00
Luc Trudeau d242c47b43 Replace Av1Block with pal_sz in read_pal_indices 2024-12-02 09:32:33 -05:00
Henrik Gramner 9a75cebc36 Explicitly use uint8_t for the order_palette() scratch buffer
It previously used 'pixel' which is typedefed to uint8_t in files
that aren't bitdepth-templated, but those are indices and not
pixels so that was just confusing and misleading.
2024-12-02 13:47:04 +01:00
victorien 575af25859 flush: Reset f->task_thread.error
f->task_thread.error can be set during flushing, not resetting this can
lead to c->task_thread.first being increased after having already submitted
a frame post flushing. That's fine if it happens on the very first frame,
but if that's the case on any subsequent frame it will incur a wrong frame
ordering.
Now that a non-first frame will be considered as such, its tasks won't be
able to execute (since they depend on a truly previous frame considered as
being after) and c->task_thread.cur will be increased past that frame, with
no way of it being reset, eventually leading to a hang.
2024-11-28 17:56:13 +01:00
Wan-Teh Chang 767efeca06 Fix ClangTidy misc-include-cleaner warnings 2024-11-26 14:26:25 +00:00
Martin Storsjö f8d2620d82 checkasm: looprestoration: Do strict bounds checking of the output
This would allow to immediately detect unintended writes out of
bounds like the ones fixed in
72b5380757 and
1c7433a5eb.

Extend the PIXEL_RECT macro to provide a variable containing the
full, padded height of the buffer, for uses that operate on the
full buffer.

Allow overwriting past the right edge of the target output rectangle,
up to an alignment of 64 pixels, but allow no overwrite past the
bottom.
2024-11-21 09:05:33 +00:00
Brad Smith f15666b703 riscv: Enable FreeBSD / OpenBSD elf_aux_info() support 2024-11-21 08:41:38 +00:00
Martin Storsjö 30c3dd8edd arm32: looprestoration: Rewrite the SGR functions
Switch to the same cache-friendly algorithm as was done for arm64
in c121b831e2.

This uses much less stack memory, and is much more cache friendly.
In this form, most of the individual asm functions only operate on
one single row of data at a time.

Some of the functions used to be unrolled to operate on two rows
at a time, while they now only operate on one at a time. In practice,
this is still a large performance win, as data is accessed in a
much more cache friendly manner.

This gives a 2-37% speedup, and reduces the peak amount of stack
used for these functions from 255 KB to 33 KB.

Before:              Cortex A7         A8        A53        A72        A73
sgr_3x3_8bpc_neon:    873990.7   748341.9   543410.2   383200.4   357502.9
sgr_3x3_10bpc_neon:   909728.0   732594.5   560123.6   392765.5   359377.7
sgr_5x5_8bpc_neon:    591597.9   527353.1   350347.4   263464.9   243098.8
sgr_5x5_10bpc_neon:   637958.2   529462.8   364613.3   280664.6   255164.6
sgr_mix_8bpc_neon:   1458977.4  1185423.2   884017.7   632922.5   587395.2
sgr_mix_10bpc_neon:  1532376.5  1259111.4   918729.3   658787.6   600317.0
After:
sgr_3x3_8bpc_neon:    836138.7   635556.5   530596.1   335794.6   348209.9
sgr_3x3_10bpc_neon:   850835.4   596445.0   534583.2   342713.4   349713.5
sgr_5x5_8bpc_neon:    577039.7   443916.5   341684.8   223374.0   232841.3
sgr_5x5_10bpc_neon:   600975.7   400041.3   347529.8   234759.9   239351.7
sgr_mix_8bpc_neon:   1297988.7   925739.1   830360.7   545476.1   548706.6
sgr_mix_10bpc_neon:  1340112.6   914395.7   873342.4   574815.7   554681.6

With this change in place, dav1d can run with around 72 KB of stack
on arm targets.

Not all functions have been merged in the same way as they were
for arm64 in c121b831e2, so some
minor differences remain; it's possible to incrementally optimize
this, e.g. to fuse box3/5_row_v with calc_row_ab1/2, fuse
finish_filter_row1/2 with sgr_weighted_row1, and make a version of
finish_filter_row1 that produces 2 rows, like is done for arm64.

It's also possible to rewrite the logic for calculating sgr_x_by_x
in the same way as was done for arm64 in
79db162487.
2024-11-19 11:58:25 +02:00
Martin Storsjö 1b7f126361 arm32: looprestoration: Apply simplifications to align with C code
This applies the same simplifications that were done for the C
code and the x86 assembly in 4613d3a530,
and the arm64 assembly in ce80e6daf6,
to the arm32 implementation.

This gives a minor speedup of around a couple percent.

Before:             Cortex A7         A8        A53        A72        A73
sgr_3x3_8bpc_neon:   926600.0   753468.3   553704.1   399379.1   369674.4
sgr_5x5_8bpc_neon:   621722.9   540412.7   357275.9   274474.3   254996.0
sgr_mix_8bpc_neon:  1529715.1  1171282.5   894982.9   659996.6   610407.2
After:
sgr_3x3_8bpc_neon:   899020.3   697278.6   541569.9   382824.3   353891.8
sgr_5x5_8bpc_neon:   602183.2   498322.9   348974.5   264833.9   243837.7
sgr_mix_8bpc_neon:  1497870.8  1182121.3   880470.9   635939.3   590909.3
2024-11-18 16:08:00 +02:00
Martin Storsjö c43debf1b1 arm64: looprestoration: Fix a comment typo 2024-11-18 16:07:40 +02:00
Martin Storsjö 1c7433a5eb arm: looprestoration: Fix the single line loop in sgr_weighted2
After processing one block, this accidentally jumped to the loop
for processing two lines at once.

The same bug was replicated in both 32 and 64 bit versions.
2024-11-18 16:07:40 +02:00
Martin Storsjö f32b314616 looprestoration: Rewrite the C version of the SGR filter
This reduces the stack usage of these functions (the C version)
significantly, and gives them a 15-40% speedup (on an Apple M3,
with Xcode Clang 16).

The C versions of this function does matter; even though we have
assembly implementations of it on x86 and aarch64, those only
covert the 8 and 10 bpc cases, while the C version is used as
fallback for 12 bpc.

This matches how these functions are implemented in the aarch64
assembly; operate over a window of 3 or 5 lines (of 384 pixels
each), instead of doing a full 384 x 64 block.

The individual functions for filtering a line each end up
much simpler, and closer to how this can be implemented in
assembly - but the overall business logic ends up much much
more complex.

The main difference to the aarch64 assembly implementation,
is that any buffer which is of int16_t size in the aarch64
assembly implementation, uses the type "coef" here, which
is 32 bit in the 10/12 bpc cases. (This is required for handling
the 12 bpc cases.)

With this in place, dav1d can run with around 66 KB of stack
on x86_64 with assembly enabled, with around 74 KB of stack on
aarch64 with assembly enabled, and with 118 KB of stack with
assembly disabled.

This increases the binary size by around 14 KB (in the case of
aarch64 with Xcode Clang 16).

On 32 bit arm, dav1d still requires around 270 KB of stack, as
that assembly implementation of the SGR filter uses a different
algorithm.
2024-11-18 15:57:19 +02:00
Martin Storsjö 01d417c2fa arm: looprestoration: Give symbols and defines unique names
As the machine specific init file is included in the common
template, give symbols and defines unique names that won't
clash with similar ones in the main template.
2024-11-18 15:39:28 +02:00
Martin Storsjö 847eece170 arm: looprestoration: Add spacing around operators 2024-11-18 15:39:28 +02:00
Martin Storsjö 56a55933b3 arm: looprestoration: Get rid of unnecessary rotate_ab_N intermediate functions 2024-11-18 15:39:28 +02:00
Martin Storsjö 9db59d8904 arm: looprestoration: Apply 'const' more consistently on parameters 2024-11-18 15:39:28 +02:00
Marvin Scholz c8fdaa8611 checkasm: add loongarch GAS file to checkasm_asm_sources
This is not an object so putting it in the objects variable seems wrong
and would also break using gaspp for that file.
2024-11-16 14:51:35 +01:00