Commit graph

38 commits

Author SHA1 Message Date
Niklas Haas
cf2d40f65d swscale/ops: add explicit clear mask to SwsClearOp
Instead of implicitly testing for NaN values. This is mostly a straightforward
translation, but we need some slight extra boilerplate to ensure the mask
is correctly updated when e.g. commuting past a swizzle.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-16 23:23:36 +02:00
Zhao Zhili
9917308cc2 swscale/vulkan: fix dither buffer leak on mapping failure
A failure while preparing a dither buffer leaves the newly allocated
buffer outside the cleanup range, leaking Vulkan resources. Make the
failure path cover the current buffer as well.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-04-07 17:53:14 +00:00
Lynne
2b6fbcad6d swscale/vulkan: compile SPIR-V backed only if SPIR-V headers are found
Instead of making Vulkan depend on the headers, make the compilation of
the SPIR-V backend depend on the headers.

Sponsored-by: Sovereign Tech Fund
2026-04-04 19:02:27 +00:00
Lynne
47e4e95173
swscale/vulkan: add a native SPIR-V assembler backend
swscale gets runtime-defined assembly once again!

This commit splits the Vulkan backend into two, SPIR-V and GLSL,
enabling falling back onto the GLSL implementation if an instruction
is unavailable, or simply for testing.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:06 +02:00
Lynne
6a723420dc
swscale/vulkan: add a SPIR-V assembler header file
This commit adds a SPIR-V assembler header file. It was partially generated
from the SPIR-V header file JSON definition, then edited by hand to template
and reduce its size as much as possible.
It only implements the essentials required for SPIR-V assembly that swscale
requires.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:06 +02:00
Lynne
5fa4085774
swscale/vulkan: use uniform buffers for dither matrix
Uniform buffers are much simpler to index, and require no work from
the driver compiler to optimize.
In SPIR-V, large 2D shader constants can be spilled into scratch memory,
since you need to create a function variable to index them during runtime.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:06 +02:00
Lynne
d4bcd3340e
swscale/vulkan: add a check for BGRA features
The issue is that very often, hardware has limited support for BGRA
formats.

As this is a limitation of Vulkan itself, we cannot work around this
in a compatible way.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:06 +02:00
Lynne
0a543441be
swscale/vulkan: always reserve 4 image descriptors
The issue is that with multiplane images, or packed images,
there may be some mismatching between what .elems has, and what
we need.
Descriptors are cheap, so just always reserve 4.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:05 +02:00
Lynne
eb71c6c9a4
swscale/vulkan: move execution context to be a part of a shader
The issue is that the main Vulkan context is shared between possibly
multiple shaders, and registering a new shader requires allocating
descriptors.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:05 +02:00
Lynne
7c33948b29
swscale/vulkan: fix potential memory issues
The issue is that updating descriptors relies on the pointers of
the structures remaining the same since creation.

Sponsored-by: Sovereign Tech Fund
2026-04-02 21:15:01 +02:00
Niklas Haas
85bef2c2bc swscale/ops: split SwsConst up into op-specific structs
It was a bit clunky, lacked semantic contextual information, and made it
harder to reason about the effects of extending this struct. There should be
zero runtime overhead as a result of the fact that this is already a big
union.

I made the changes in this commit by hand, but due to the length and noise
level of the commit, I used Opus 4.6 to verify that I did not accidentally
introduce any bugs or typos.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-02 11:48:15 +00:00
Niklas Haas
c24d67a0ff swscale/vulkan/ops: use QSTR/QTYPE to print all rationals
Now this helper is a bit more useful.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-02 11:48:15 +00:00
Niklas Haas
7a4cffa25d swscale/vulkan/ops: simplify QTYPE macro
There's no reason for this macro to hard-code op->c.q4[i].

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-02 11:48:15 +00:00
Niklas Haas
c0cc7f341a swscale/ops: simplify SwsOpList.order_src/dst
Just define these directly as integer arrays; there's really no point in
having them re-use SwsSwizzleOp; the only place this was ever even remotely
relevant was in the no-op check, which any decent compiler should already
be capable of optimizing into a single 32-bit comparison.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-29 09:39:09 +00:00
Lynne
0e077f2dc1
swscale/vulkan: do not apply order_src/dst for packed r/w
> packed = load all components from a single plane (the index given by order_src[0])
> planar = load one component each from separate planes (the index given by order_src[i])

Sponsored-by: Sovereign Tech Fund
2026-03-28 19:36:04 +01:00
Lynne
69c9cfbddf
swscale/vulkan: fix redundant check for packed data
This is always in the branch where packed == false.

Sponsored-by: Sovereign Tech Fund
2026-03-28 19:36:04 +01:00
Niklas Haas
bf09910292 swscale/ops: add filter kernel to SwsReadWriteOp
This allows reads to directly embed filter kernels. This is because, in
practice, a filter needs to be combined with a read anyways. To accomplish
this, we define filter ops as their semantic high-level operation types, and
then have the optimizer fuse them with the corresponding read/write ops
(where possible).

Ultimately, something like this will be needed anyways for subsampled formats,
and doing it here is just incredibly clean and beneficial compared to each
of the several alternative designs I explored.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-28 18:50:13 +01:00
Lynne
e88d4ef718
swscale/vulkan: take order_src/order_dst into account
This fixes rgba/gbrap/bgra conversions.

Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:17 +01:00
Lynne
e01d19aad6
swscale/vulkan: implement SWS_OP_LINEAR
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:17 +01:00
Lynne
4805f317a6
swscale/vulkan: implement SWS_OP_DITHER
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:17 +01:00
Lynne
d212ff08e0
swscale/vulkan: implement SWS_OP_CONVERT
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:17 +01:00
Lynne
bea41f1f90
swscale/vulkan: implement SWS_OP_LSHIFT/SWS_OP_RSHIFT
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:17 +01:00
Lynne
d35a77879c
swscale/vulkan: implement SWS_OP_MIN/SWS_OP_MAX
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:16 +01:00
Lynne
bf93a67733
swscale/vulkan: implement SW_OP_SCALE
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:16 +01:00
Lynne
41f748d2ee
swscale/vulkan: add precise qualifier to f32
Sponsored-by: Sovereign Tech Fund
2026-03-24 15:21:09 +01:00
Niklas Haas
68046d0b33 Revert "swscale/vulkan/ops: move buffer desc setting to helper function"
This reverts commit 32554fc107.

Accidentally pushed this commit twice, with the wrong location.
Correct version is 97682155e6.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:16:42 +01:00
Niklas Haas
143cb56501 swscale/vulkan/ops: use opaque run function
Avoids some unnecessary round-trips through the execution harness, as well
as removing one unnecessary layer of abstraction (SwsOpExec).

It's a bit unfortunate that we have to cast away the const on the AVFrame,
since the Vulkan functions take non-const everywhere, even though all they're
doing is modifying frame internal metadata, but alas.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:01:51 +01:00
Niklas Haas
97682155e6 swscale/vulkan/ops: move buffer desc setting to helper function
And call it on the read/write ops directly, rather than this awkward loop.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 12:01:51 +01:00
Niklas Haas
32554fc107 swscale/vulkan/ops: move buffer desc setting to helper function
And call it on the read/write ops directly, rather than this awkward loop.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 11:25:58 +01:00
Niklas Haas
b6ebee038f swscale/vulkan/ops: move fractional read/write rejection to implementation
Rather than testing for it separately for some reason.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 11:25:57 +01:00
Niklas Haas
104475ecb9 swscale/vulkan/ops: fix undefined behavior on SWS_OP_CLEAR
op->rw.frac dereferences nonsense on clear ops.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 11:25:57 +01:00
Niklas Haas
b8cd331305 swscale/vulkan/ops: log op name in generated shader
I think this just makes for a marginally nicer debugging experience.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-09 11:25:57 +01:00
Niklas Haas
cef2fbfd4b swscale/vulkan: fix include order (cosmetic)
Non-local includes before local includes.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-04 12:04:12 +01:00
Niklas Haas
1512e52cb4 swscale: switch to refstruct for hw_priv
This is a bit more forward-facing than a bare allocation, and importantly,
allows the `swscale/utils.c` code to remain agnostic about how to correctly
uninit this struct.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-04 12:04:09 +01:00
Niklas Haas
5375cfd9c7 swscale/vulkan/ops: fix typo
Checks src.interlaced twice.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-03-01 21:57:53 +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
Lynne
bd24abfb6c
swscale/vulkan: initialize GLSL compilation and shader execution
Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:22 +01:00
Lynne
1d2e616d5f
swscale: add a Vulkan backend for ops.c
Sponsored-by: Sovereign Tech Fund
2026-02-26 14:10:22 +01:00