Hi,
I have been working on adding support for the DRM 10:10:10:2 pixel formats
(`BGRA1010102LE` and `RGBA1010102LE`, which are 10-bit RGB with a 2-bit
alpha
channel in the low bits, matching `DXGI_FORMAT_R10G10B10A2_UNORM` and the
corresponding Vulkan layouts) to the bundled FFmpeg, and wanted to raise
something I found in the new swscale ops framework.
The legacy side is complete and working: the formats are described in
libavutil,
registered in the legacy format tables, and implemented for both the scaled
input/output paths and the unscaled special converters, so conversions to
the
usual RGB and planar targets behave as expected. The problem shows up only
with
the new ops backend.
For same-size conversions from either of these formats to a destination that
carries alpha, for example RGBA64 or GBRAP, the optimizer splits a
non-diagonal
float LINEAR into a float SWIZZLE plus a diagonal scale
(`extract_swizzle()` in
`libswscale/ops_optimizer.c`), because the source has real alpha in the low
bits
rather than padding. The compiler then lowers that SWIZZLE to
`SWS_UOP_PERMUTE`/`COPY` with type `SWS_PIXEL_F32`, but `uops_macros.h`
declares
no `F32` PERMUTE/COPY entries. As a result no backend can compile the chain,
including the C reference, and the conversion silently falls back to the
legacy
path. Without alpha in the destination the same source works fine through
the
ops backend, and `X2RGB10`/`X2BGR10` do not run into this because their two
spare bits are padding, so the optimizer keeps the swizzle in the integer
domain.
I spent some time trying to understand whether this is intended. The design
document says the goal is 100% coverage of all operations, and the commits
that
auto-generate the C reference from `uops_macros.h` and that introduced
PERMUTE/COPY describe them as operations for the C backend, so I would have
expected the entries to exist. The generator does call
`ff_sws_op_list_optimize()` and `translate_op()` translates `SWS_OP_SWIZZLE`
unconditionally, so if the optimized list contained the float swizzle it
should
have been registered. With the format present the generator does register
the
four-component U32 conversions (`u32_to_{u16,f32}_xyzw`), which tells me the
format pair is enumerated and only the float swizzle is missing. I also
tried
expanding the generator's flag and scaler combinations (`SWS_POINT`,
`SWS_BILINEAR`, `SWS_LANCZOS`, `SWS_ACCURATE_RND`, `SWS_BITEXACT`, and
`SWS_SCALE_AUTO`, `POINT`, `BILINEAR`, `LANCZOS`, `BICUBIC`) and none of
them
makes it emit `F32` PERMUTE/COPY. The swizzle only appears once the runtime
graph
composes passes, which the single `ff_sws_op_list_generate()` call used by
the
generator does not reproduce.
So the generated table cannot capture uops that are only introduced by the
graph
composition. I can see two ways to fix this and would like to know which
one you
consider correct: either make the macro generation cover the same op lists
the
graph can produce, so every optimizer/graph-introduced uop is registered, or
make sure the optimizer/graph does not introduce a swizzle in a pixel type
that
has no PERMUTE/COPY implementation. Registering `F32` PERMUTE/COPY
explicitly
does make the conversion work, since the C template is type-agnostic and the
kernels are auto-generated from the table, but I did not want to
special-case it
before asking.
Thanks,
Luan Weslley <[email protected]>
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]