public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: Hans Verkuil <hverkuil+cisco@kernel.org>,
	nicolas.dufresne@collabora.com, p.zabel@pengutronix.de,
	mchehab@kernel.org, heiko@sntech.de
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, kernel@collabora.com
Subject: Re: [PATCH v3] media: verisilicon: Create AV1 helper library
Date: Mon, 4 May 2026 12:25:54 +0200	[thread overview]
Message-ID: <da591ba8-9563-4e89-88c2-bf18d41d1bee@collabora.com> (raw)
In-Reply-To: <8f29d271-da7d-4456-9427-2fb66136747a@kernel.org>


Le 04/05/2026 à 09:20, Hans Verkuil a écrit :
> Hi Benjamin,
>
> I have a few comments about this:
>
> On 15/04/2026 09:38, Benjamin Gaignard wrote:
>> Regroup all none hardware related AV1 functions into a helper library.
>> The goal is to avoid code duplication for futur AV1 codecs.
> futur -> future
>
>> Tested on rock 5b board Fluster score remains the same 204/241.
>>
>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
>> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
>> ---
>> changes in version 3:
>>   - Remove useless wrapper functions.
>>
>>   drivers/media/platform/verisilicon/Makefile   |   7 +-
>>   .../media/platform/verisilicon/hantro_av1.c   | 780 +++++++++++++++
>>   .../media/platform/verisilicon/hantro_av1.h   |  62 ++
>>   ...entropymode.c => hantro_av1_entropymode.c} |  18 +-
>>   ...entropymode.h => hantro_av1_entropymode.h} |  18 +-
>>   ...av1_filmgrain.c => hantro_av1_filmgrain.c} |  82 +-
>>   .../verisilicon/hantro_av1_filmgrain.h        |  44 +
>>   .../media/platform/verisilicon/hantro_hw.h    |   7 +-
>>   .../verisilicon/rockchip_av1_filmgrain.h      |  36 -
>>   .../verisilicon/rockchip_vpu981_hw_av1_dec.c  | 935 ++----------------
>>   .../platform/verisilicon/rockchip_vpu_hw.c    |   7 +-
>>   11 files changed, 1041 insertions(+), 955 deletions(-)
>>   create mode 100644 drivers/media/platform/verisilicon/hantro_av1.c
>>   create mode 100644 drivers/media/platform/verisilicon/hantro_av1.h
>>   rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.c => hantro_av1_entropymode.c} (99%)
>>   rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.h => hantro_av1_entropymode.h} (95%)
>>   rename drivers/media/platform/verisilicon/{rockchip_av1_filmgrain.c => hantro_av1_filmgrain.c} (92%)
>>   create mode 100644 drivers/media/platform/verisilicon/hantro_av1_filmgrain.h
>>   delete mode 100644 drivers/media/platform/verisilicon/rockchip_av1_filmgrain.h
>>
> <snip>
>
>> diff --git a/drivers/media/platform/verisilicon/hantro_av1.c b/drivers/media/platform/verisilicon/hantro_av1.c
>> new file mode 100644
>> index 000000000000..5a51ac877c9c
>> --- /dev/null
>> +++ b/drivers/media/platform/verisilicon/hantro_av1.c
>> @@ -0,0 +1,780 @@
> <snip>
>
>> +
>> +int hantro_av1_tile_log2(int target)
>> +{
>> +	int k;
>> +
>> +	/*
>> +	 * returns the smallest value for k such that 1 << k is greater
>> +	 * than or equal to target
>> +	 */
>> +	for (k = 0; (1 << k) < target; k++);
> Checkpatch gives:
>
> ERROR: trailing statements should be on next line
> #637: FILE: drivers/media/platform/verisilicon/hantro_av1.c:568:
> +       for (k = 0; (1 << k) < target; k++);
>
> Just move the ';' to the next line.

OK I will do that.

>
>> +
>> +	return k;
>> +}
>> +
> <snip>
>
>> diff --git a/drivers/media/platform/verisilicon/hantro_av1_filmgrain.h b/drivers/media/platform/verisilicon/hantro_av1_filmgrain.h
>> new file mode 100644
>> index 000000000000..5593e84114d0
>> --- /dev/null
>> +++ b/drivers/media/platform/verisilicon/hantro_av1_filmgrain.h
>> @@ -0,0 +1,44 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +
>> +#ifndef _HANTRO_AV1_FILMGRAIN_H_
>> +#define _HANTRO_AV1_FILMGRAIN_H_
>> +
>> +#include <linux/types.h>
>> +
>> +struct hantro_av1_film_grain {
>> +	u8 scaling_lut_y[256];
>> +	u8 scaling_lut_cb[256];
>> +	u8 scaling_lut_cr[256];
>> +	s16 cropped_luma_grain_block[4096];
>> +	s16 cropped_chroma_grain_block[1024 * 2];
>> +};
> This struct is not used in hantro_av1_filmgrain.c/h.
>
> Does this belong here?

The same structure can used for future Verisilicon hardware block so I would prefer to
keep it here.

>
>> +
>> +void hantro_av1_generate_luma_grain_block(s32 (*luma_grain_block)[73][82],
>> +					  s32 bitdepth,
>> +					  u8 num_y_points,
>> +					  s32 grain_scale_shift,
>> +					  s32 ar_coeff_lag,
>> +					  s32 (*ar_coeffs_y)[24],
>> +					  s32 ar_coeff_shift,
>> +					  s32 grain_min,
>> +					  s32 grain_max,
>> +					  u16 random_seed);
>> +
>> +void hantro_av1_generate_chroma_grain_block(s32 (*luma_grain_block)[73][82],
>> +					    s32 (*cb_grain_block)[38][44],
>> +					    s32 (*cr_grain_block)[38][44],
>> +					    s32 bitdepth,
>> +					    u8 num_y_points,
>> +					    u8 num_cb_points,
>> +					    u8 num_cr_points,
>> +					    s32 grain_scale_shift,
>> +					    s32 ar_coeff_lag,
>> +					    s32 (*ar_coeffs_cb)[25],
>> +					    s32 (*ar_coeffs_cr)[25],
>> +					    s32 ar_coeff_shift,
>> +					    s32 grain_min,
>> +					    s32 grain_max,
>> +					    u8 chroma_scaling_from_luma,
>> +					    u16 random_seed);
>> +
> I get a lot of checkpatch warnings of this type:
>
> WARNING: function definition argument 's32' should also have an identifier name
> #1205: FILE: drivers/media/platform/verisilicon/hantro_av1_filmgrain.h:16:
> +void hantro_av1_generate_luma_grain_block(s32 (*luma_grain_block)[73][82],
> Looking at how it is used in rockchip_vpu981_av1_dec_set_fgs() I think this
> can be done a lot easier if you add a new struct here containing those
> arrays. E.g.:
>
> struct hantro_av1_coeffs_grain_block {
>          s32 ar_coeffs_y[24];
>          s32 ar_coeffs_cb[25];
>          s32 ar_coeffs_cr[25];
>          s32 luma_grain_block[73][82];
>          s32 cb_grain_block[38][44];
>          s32 cr_grain_block[38][44];
> };
>
> Then in rockchip_vpu981_av1_dec_set_fgs you can just kzalloc that struct
> and pass it to these filmgrain functions.

I will do that.

>
> Also consider using #defines for the array sizes.

Chapter "7.18.3.3. Generate grain process" of AV1 spec doesn't define/name
these values so keep them like this make the code more easy to review with
the spec.

https://aomediacodec.github.io/av1-spec/#generate-grain-process

That said I'm always for naming values so good suggestion are welcome.

Thanks,
Benjamin

>
> If you decide not to use a struct, then you can at least change simply use
> 's32 luma_grain_block[73][82]' as arguments to these helper functions. There
> is no need to complicate the function prototypes.
>
> But I think creating a struct is a cleaner approach.
>
> Regards,
>
> 	Hans
>


      reply	other threads:[~2026-05-04 10:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  7:38 [PATCH v3] media: verisilicon: Create AV1 helper library Benjamin Gaignard
2026-05-04  7:20 ` Hans Verkuil
2026-05-04 10:25   ` Benjamin Gaignard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da591ba8-9563-4e89-88c2-bf18d41d1bee@collabora.com \
    --to=benjamin.gaignard@collabora.com \
    --cc=heiko@sntech.de \
    --cc=hverkuil+cisco@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=p.zabel@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox