History

avcodec/vvc/vvc_ps: Use union for luts to avoid unaligned accesses

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.

Andreas Rheinhardt committed 2 years ago

Commit ef047371 parent 1eafbc26 files · +14 −13Browse files

Showing the changes to libavcodec (6 of 6 files). Show all

Unified · Split

6 files
  1. libavcodec/vvc/vvc_filter.c +1 −1
  2. libavcodec/vvc/vvc_filter_template.c +2 −2
  3. libavcodec/vvc/vvc_inter.c +2 −2
  4. libavcodec/vvc/vvc_ps.c +4 −4
  5. libavcodec/vvc/vvc_ps.h +4 −3
  6. libavcodec/vvc/vvcdsp.h +1 −1
libavcodec/vvc/vvc_filter.c+1−1
@@ -1328,5 +1328,5 @@ void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y) · 1327 unmodified lines
13281328 const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
13291329 uint8_t *data = fc->frame->data[LUMA] + y * fc->frame->linesize[LUMA] + (x << fc->ps.sps->pixel_shift);
13301330 if (sc->sh.r->sh_lmcs_used_flag)
1331− fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, fc->ps.lmcs.inv_lut);
1331+ fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut);
13321332 }
libavcodec/vvc/vvc_filter_template.c+2−2
@@ -22,9 +22,9 @@ · 21 unmodified lines
2222
2323 #include "libavcodec/h26x/h2656_sao_template.c"
2424
25−static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut)
25+static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const void *_lut)
2626 {
27− const pixel *lut = (const pixel *)_lut;
27+ const pixel *lut = _lut;
2828 pixel *dst = (pixel*)_dst;
2929 dst_stride /= sizeof(pixel);
3030
libavcodec/vvc/vvc_inter.c+2−2
@@ -571,7 +571,7 @@ static void pred_regular_luma(VVCLocalContext *lc, const int hf_idx, const int v · 570 unmodified lines
571571 const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
572572 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 0);
573573 if (sc->sh.r->sh_lmcs_used_flag)
574− fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, fc->ps.lmcs.fwd_lut);
574+ fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, &fc->ps.lmcs.fwd_lut);
575575 fc->vvcdsp.inter.put_ciip(dst, dst_stride, sbw, sbh, inter, inter_stride, intra_weight);
576576
577577 }
@@ -887,7 +887,7 @@ static void predict_inter(VVCLocalContext *lc) · 309 unmodified lines
887887
888888 if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
889889 uint8_t* dst0 = POS(0, cu->x0, cu->y0);
890− fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, fc->ps.lmcs.fwd_lut);
890+ fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut);
891891 }
892892 }
893893
libavcodec/vvc/vvc_ps.c+4−4
@@ -642,9 +642,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw · 641 unmodified lines
642642 const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
643643 input_pivot, scale_coeff, idx_y, max);
644644 if (bit_depth > 8)
645− ((uint16_t *)lmcs->fwd_lut)[sample] = fwd_sample;
645+ lmcs->fwd_lut.u16[sample] = fwd_sample;
646646 else
647− lmcs->fwd_lut[sample] = fwd_sample;
647+ lmcs->fwd_lut.u8 [sample] = fwd_sample;
648648
649649 }
650650
@@ -659,9 +659,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw · 8 unmodified lines
659659 inv_scale_coeff, i, max);
660660
661661 if (bit_depth > 8)
662− ((uint16_t *)lmcs->inv_lut)[sample] = inv_sample;
662+ lmcs->inv_lut.u16[sample] = inv_sample;
663663 else
664− lmcs->inv_lut[sample] = inv_sample;
664+ lmcs->inv_lut.u8 [sample] = inv_sample;
665665 }
666666
667667 return 0;
libavcodec/vvc/vvc_ps.h+4−3
@@ -191,9 +191,10 @@ typedef struct VVCLMCS { · 190 unmodified lines
191191 uint8_t min_bin_idx;
192192 uint8_t max_bin_idx;
193193
194− //*2 for high depth
195− uint8_t fwd_lut[LMCS_MAX_LUT_SIZE * 2];
196− uint8_t inv_lut[LMCS_MAX_LUT_SIZE * 2];
194+ union {
195+ uint8_t u8[LMCS_MAX_LUT_SIZE];
196+ uint16_t u16[LMCS_MAX_LUT_SIZE]; ///< for high bit-depth
197+ } fwd_lut, inv_lut;
197198
198199 uint16_t pivot[LMCS_MAX_BIN_SIZE + 1];
199200 uint16_t chroma_scale_coeff[LMCS_MAX_BIN_SIZE];
libavcodec/vvc/vvcdsp.h+1−1
@@ -119,7 +119,7 @@ typedef struct VVCItxDSPContext { · 118 unmodified lines
119119 } VVCItxDSPContext;
120120
121121 typedef struct VVCLMCSDSPContext {
122− void (*filter)(uint8_t *dst, ptrdiff_t dst_stride, int width, int height, const uint8_t *lut);
122+ void (*filter)(uint8_t *dst, ptrdiff_t dst_stride, int width, int height, const void *lut);
123123 } VVCLMCSDSPContext;
124124
125125 typedef struct VVCLFDSPContext {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t