From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/vvc/vvc_ps: Use union for luts to avoid unaligned accesses
Date: Sun, 18 Feb 2024 20:31:04 +0100
Message-ID: <AS8P250MB074422156135108D0B1AE5588F522@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB0744726A9B33410FA1ED1C1F8F522@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
These arrays are currently accessed via uint16_t* pointers
although nothing guarantees their alignment. Furthermore,
this is problematic wrt the effective-type rules.
Fix this by using a union of arrays of uint8_t and uint16_t.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vvc/vvc_filter.c | 2 +-
libavcodec/vvc/vvc_filter_template.c | 4 ++--
libavcodec/vvc/vvc_inter.c | 4 ++--
libavcodec/vvc/vvc_ps.c | 8 ++++----
libavcodec/vvc/vvc_ps.h | 7 ++++---
libavcodec/vvc/vvcdsp.h | 2 +-
6 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index df77e443f6..5fa711c9e0 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -1328,5 +1328,5 @@ void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y)
const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
uint8_t *data = fc->frame->data[LUMA] + y * fc->frame->linesize[LUMA] + (x << fc->ps.sps->pixel_shift);
if (sc->sh.r->sh_lmcs_used_flag)
- fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, fc->ps.lmcs.inv_lut);
+ fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut);
}
diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c
index b7eaef5125..9b3a0e46f7 100644
--- a/libavcodec/vvc/vvc_filter_template.c
+++ b/libavcodec/vvc/vvc_filter_template.c
@@ -22,9 +22,9 @@
#include "libavcodec/h26x/h2656_sao_template.c"
-static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut)
+static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const void *_lut)
{
- const pixel *lut = (const pixel *)_lut;
+ const pixel *lut = _lut;
pixel *dst = (pixel*)_dst;
dst_stride /= sizeof(pixel);
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
index e05f3db93e..6c9c8a7165 100644
--- a/libavcodec/vvc/vvc_inter.c
+++ b/libavcodec/vvc/vvc_inter.c
@@ -571,7 +571,7 @@ static void pred_regular_luma(VVCLocalContext *lc, const int hf_idx, const int v
const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 0);
if (sc->sh.r->sh_lmcs_used_flag)
- fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, fc->ps.lmcs.fwd_lut);
+ fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, &fc->ps.lmcs.fwd_lut);
fc->vvcdsp.inter.put_ciip(dst, dst_stride, sbw, sbh, inter, inter_stride, intra_weight);
}
@@ -887,7 +887,7 @@ static void predict_inter(VVCLocalContext *lc)
if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
uint8_t* dst0 = POS(0, cu->x0, cu->y0);
- fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, fc->ps.lmcs.fwd_lut);
+ fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut);
}
}
diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index 376027ed81..e6e46d2039 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -642,9 +642,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw
const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
input_pivot, scale_coeff, idx_y, max);
if (bit_depth > 8)
- ((uint16_t *)lmcs->fwd_lut)[sample] = fwd_sample;
+ lmcs->fwd_lut.u16[sample] = fwd_sample;
else
- lmcs->fwd_lut[sample] = fwd_sample;
+ lmcs->fwd_lut.u8 [sample] = fwd_sample;
}
@@ -659,9 +659,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw
inv_scale_coeff, i, max);
if (bit_depth > 8)
- ((uint16_t *)lmcs->inv_lut)[sample] = inv_sample;
+ lmcs->inv_lut.u16[sample] = inv_sample;
else
- lmcs->inv_lut[sample] = inv_sample;
+ lmcs->inv_lut.u8 [sample] = inv_sample;
}
return 0;
diff --git a/libavcodec/vvc/vvc_ps.h b/libavcodec/vvc/vvc_ps.h
index 3d3aa061f5..5adf3f3453 100644
--- a/libavcodec/vvc/vvc_ps.h
+++ b/libavcodec/vvc/vvc_ps.h
@@ -191,9 +191,10 @@ typedef struct VVCLMCS {
uint8_t min_bin_idx;
uint8_t max_bin_idx;
- //*2 for high depth
- uint8_t fwd_lut[LMCS_MAX_LUT_SIZE * 2];
- uint8_t inv_lut[LMCS_MAX_LUT_SIZE * 2];
+ union {
+ uint8_t u8[LMCS_MAX_LUT_SIZE];
+ uint16_t u16[LMCS_MAX_LUT_SIZE]; ///< for high bit-depth
+ } fwd_lut, inv_lut;
uint16_t pivot[LMCS_MAX_BIN_SIZE + 1];
uint16_t chroma_scale_coeff[LMCS_MAX_BIN_SIZE];
diff --git a/libavcodec/vvc/vvcdsp.h b/libavcodec/vvc/vvcdsp.h
index 6f59e73654..f4fb3cb7d7 100644
--- a/libavcodec/vvc/vvcdsp.h
+++ b/libavcodec/vvc/vvcdsp.h
@@ -119,7 +119,7 @@ typedef struct VVCItxDSPContext {
} VVCItxDSPContext;
typedef struct VVCLMCSDSPContext {
- void (*filter)(uint8_t *dst, ptrdiff_t dst_stride, int width, int height, const uint8_t *lut);
+ void (*filter)(uint8_t *dst, ptrdiff_t dst_stride, int width, int height, const void *lut);
} VVCLMCSDSPContext;
typedef struct VVCLFDSPContext {
--
2.34.1
_______________________________________________
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".
next prev parent reply other threads:[~2024-02-18 19:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-18 19:29 [FFmpeg-devel] [PATCH 1/4] avcodec/vvc/vvc_ps: Check before access Andreas Rheinhardt
2024-02-18 19:31 ` Andreas Rheinhardt [this message]
2024-02-18 19:31 ` [FFmpeg-devel] [PATCH 3/4] avcodec/vvc/vvcdsp: Remove pointless wrappers Andreas Rheinhardt
2024-02-18 19:31 ` [FFmpeg-devel] [PATCH 4/4] avcodec: Remove superfluous '; ' outside of functions Andreas Rheinhardt
2024-02-19 23:26 ` [FFmpeg-devel] [PATCH 1/4] avcodec/vvc/vvc_ps: Check before access Andreas Rheinhardt
2024-02-20 5:06 ` Nuo Mi
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=AS8P250MB074422156135108D0B1AE5588F522@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/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
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