Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] libswscale.c : ff_xyz12Torgb48 expensive unaligned 16 byte accesses
       [not found] <DM4PR21MB46198B14FF74B677790A8459929AA@DM4PR21MB4619.namprd21.prod.outlook.com>
@ 2025-05-26  0:44 ` Chitra Dey Sarkar via ffmpeg-devel
  2025-05-26  0:58   ` James Almer
  0 siblings, 1 reply; 2+ messages in thread
From: Chitra Dey Sarkar via ffmpeg-devel @ 2025-05-26  0:44 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Chitra Dey Sarkar

H
We have been profiling FFmpeg at Microsoft and have identified that ff_xyz12ToRgb48 has a high sample count ( profiled every 1ms )

It seems like ff_xyz12ToRgb48 has performance penalty for

  1.  Unaligned read and write access
  2.  Access to xyz2rgb_matrix
  3.  Multiplication

I would be interested in optimizing this code , wanted to check if there is an existing optimized version of this function, or any recommended approach to improve it(?
I can move the repeated access to xyz2rgb_matrix outside the inner loop and load a full cache line at once to extract the X, Y, and Z values more efficiently-but I wanted to start by getting some initial feedback or thoughts before proceeding further


File : FFmpeg/libswscale/swscale.c at a79720e10f30e9fd18bd78242ce96dde06461343 * FFmpeg/FFmpeg<https://github.com/FFmpeg/FFmpeg/blob/a79720e10f30e9fd18bd78242ce96dde06461343/libswscale/swscale.c#L739>

void ff_xyz12Torgb48(const SwsInternal *c, uint8_t *dst, int dst_stride,
                     const uint8_t *src, int src_stride, int w, int h)
{
.......... Unaligned read .......................
               x = AV_RL16(src16 + xp + 0);
                y = AV_RL16(src16 + xp + 1);
                z = AV_RL16(src16 + xp + 2);


.......... DRAM Access and multiply  .......................

            // convert from XYZlinear to sRGBlinear
            r = c->xyz2rgb_matrix[0][0] * x +
                c->xyz2rgb_matrix[0][1] * y +
                c->xyz2rgb_matrix[0][2] * z >> 12;
            g = c->xyz2rgb_matrix[1][0] * x +
                c->xyz2rgb_matrix[1][1] * y +
                c->xyz2rgb_matrix[1][2] * z >> 12;
            b = c->xyz2rgb_matrix[2][0] * x +
                c->xyz2rgb_matrix[2][1] * y +
                c->xyz2rgb_matrix[2][2] * z >> 12;

.......... RMW Access .......................
                AV_WL16(dst16 + xp + 0, c->rgbgamma[r] << 4);
                AV_WL16(dst16 + xp + 1, c->rgbgamma[g] << 4);
                AV_WL16(dst16 + xp + 2, c->rgbgamma[b] << 4);


Regards
Chitra
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] libswscale.c : ff_xyz12Torgb48 expensive unaligned 16 byte accesses
  2025-05-26  0:44 ` [FFmpeg-devel] libswscale.c : ff_xyz12Torgb48 expensive unaligned 16 byte accesses Chitra Dey Sarkar via ffmpeg-devel
@ 2025-05-26  0:58   ` James Almer
  0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2025-05-26  0:58 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1002 bytes --]

On 5/25/2025 9:44 PM, Chitra Dey Sarkar via ffmpeg-devel wrote:
> H
> We have been profiling FFmpeg at Microsoft and have identified that ff_xyz12ToRgb48 has a high sample count ( profiled every 1ms )
> 
> It seems like ff_xyz12ToRgb48 has performance penalty for
> 
>    1.  Unaligned read and write access
>    2.  Access to xyz2rgb_matrix
>    3.  Multiplication
> 
> I would be interested in optimizing this code , wanted to check if there is an existing optimized version of this function, or any recommended approach to improve it(?
> I can move the repeated access to xyz2rgb_matrix outside the inner loop and load a full cache line at once to extract the X, Y, and Z values more efficiently-but I wanted to start by getting some initial feedback or thoughts before proceeding further

Niklas is currently working in a library rewrite, which may affect xyz 
scaling. But in any case, the obvious approach is a SIMD optimized 
implementation (SSE2, AVX2, etc) of this function.


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-26  0:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <DM4PR21MB46198B14FF74B677790A8459929AA@DM4PR21MB4619.namprd21.prod.outlook.com>
2025-05-26  0:44 ` [FFmpeg-devel] libswscale.c : ff_xyz12Torgb48 expensive unaligned 16 byte accesses Chitra Dey Sarkar via ffmpeg-devel
2025-05-26  0:58   ` James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git