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

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
1328 const int height = FFMIN(fc->ps.pps->height - y, ctb_size);1328 const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
1329 uint8_t *data = fc->frame->data[LUMA] + y * fc->frame->linesize[LUMA] + (x << fc->ps.sps->pixel_shift);1329 uint8_t *data = fc->frame->data[LUMA] + y * fc->frame->linesize[LUMA] + (x << fc->ps.sps->pixel_shift);
1330 if (sc->sh.r->sh_lmcs_used_flag)1330 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);
1332}1332}
libavcodec/vvc/vvc_filter_template.c+2−2
@@ -22,9 +22,9 @@ · 21 unmodified lines
22 22
23#include "libavcodec/h26x/h2656_sao_template.c"23#include "libavcodec/h26x/h2656_sao_template.c"
24 24
25static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut)25static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const void *_lut)
26{26{
27 const pixel *lut = (const pixel *)_lut;27 const pixel *lut = _lut;
28 pixel *dst = (pixel*)_dst;28 pixel *dst = (pixel*)_dst;
29 dst_stride /= sizeof(pixel);29 dst_stride /= sizeof(pixel);
30 30
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
571 const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);571 const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
572 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 0);572 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 0);
573 if (sc->sh.r->sh_lmcs_used_flag)573 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);
575 fc->vvcdsp.inter.put_ciip(dst, dst_stride, sbw, sbh, inter, inter_stride, intra_weight);575 fc->vvcdsp.inter.put_ciip(dst, dst_stride, sbw, sbh, inter, inter_stride, intra_weight);
576 576
577 }577 }
@@ -887,7 +887,7 @@ static void predict_inter(VVCLocalContext *lc) · 309 unmodified lines
887 887
888 if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {888 if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
889 uint8_t* dst0 = POS(0, cu->x0, cu->y0);889 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);
891 }891 }
892}892}
893 893
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
642 const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,642 const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
643 input_pivot, scale_coeff, idx_y, max);643 input_pivot, scale_coeff, idx_y, max);
644 if (bit_depth > 8)644 if (bit_depth > 8)
645 ((uint16_t *)lmcs->fwd_lut)[sample] = fwd_sample;645 lmcs->fwd_lut.u16[sample] = fwd_sample;
646 else646 else
647 lmcs->fwd_lut[sample] = fwd_sample;647 lmcs->fwd_lut.u8 [sample] = fwd_sample;
648 648
649 }649 }
650 650
@@ -659,9 +659,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw · 8 unmodified lines
659 inv_scale_coeff, i, max);659 inv_scale_coeff, i, max);
660 660
661 if (bit_depth > 8)661 if (bit_depth > 8)
662 ((uint16_t *)lmcs->inv_lut)[sample] = inv_sample;662 lmcs->inv_lut.u16[sample] = inv_sample;
663 else663 else
664 lmcs->inv_lut[sample] = inv_sample;664 lmcs->inv_lut.u8 [sample] = inv_sample;
665 }665 }
666 666
667 return 0;667 return 0;
libavcodec/vvc/vvc_ps.h+4−3
@@ -191,9 +191,10 @@ typedef struct VVCLMCS { · 190 unmodified lines
191 uint8_t min_bin_idx;191 uint8_t min_bin_idx;
192 uint8_t max_bin_idx;192 uint8_t max_bin_idx;
193 193
194 //*2 for high depth194 union {
195 uint8_t fwd_lut[LMCS_MAX_LUT_SIZE * 2];195 uint8_t u8[LMCS_MAX_LUT_SIZE];
196 uint8_t inv_lut[LMCS_MAX_LUT_SIZE * 2];196 uint16_t u16[LMCS_MAX_LUT_SIZE]; ///< for high bit-depth
197 } fwd_lut, inv_lut;
197 198
198 uint16_t pivot[LMCS_MAX_BIN_SIZE + 1];199 uint16_t pivot[LMCS_MAX_BIN_SIZE + 1];
199 uint16_t chroma_scale_coeff[LMCS_MAX_BIN_SIZE];200 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
119} VVCItxDSPContext;119} VVCItxDSPContext;
120 120
121typedef struct VVCLMCSDSPContext {121typedef 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);
123} VVCLMCSDSPContext;123} VVCLMCSDSPContext;
124 124
125typedef struct VVCLFDSPContext {125typedef 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