Skip to content

Move lossless DPCM check inside prune_intra_y_mode - #5177

Open
mudassir-sg wants to merge 1 commit into
AOMediaCodec:av2-encfrom
mudassir-sg:av2-refactor
Open

Move lossless DPCM check inside prune_intra_y_mode#5177
mudassir-sg wants to merge 1 commit into
AOMediaCodec:av2-encfrom
mudassir-sg:av2-refactor

Conversation

@mudassir-sg

Copy link
Copy Markdown
Contributor

This change moves condition checks related to lossless DPCM modes inside prune_intra_y_mode() and updates its return type from int to bool.

No stats changed.

@mudassir-sg

Copy link
Copy Markdown
Contributor Author

Comment thread av2/encoder/intra_mode_search.c Outdated
int64_t *best_model_rd, int64_t top_intra_model_rd[],
int k) {
const MB_MODE_INFO *const mbmi = xd->mi[0];
if (xd->lossless[mbmi->segment_id] && mbmi->use_dpcm_y != 0) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we only pass in (xd->lossless[mbmi->segment_id] && mbmi->use_dpcm_y != 0) to this function instead of xd?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since mbmi->use_dpcm_y=1 is applicable for lossless mode, checking xd->lossless is redundant. We have updated the function to take mbmi->use_dpcm_y directly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"mbmi->use_dpcm_y=1 is applicable for lossless mode". Is there any code to guarantee this? Otherwise, could we at least add an assertion before calling prune_intra_y_mode()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mbmi->use_dpcm_y = 1 is applicable only for lossless mode.

For example, in the Decoder (decodemv.c, line 1654), mbmi->use_dpcm_y is read from the bitstream only when xd->lossless[mbmi->segment_id] is set:

if (xd->lossless[mbmi->segment_id]) {
  mbmi->use_dpcm_y = read_dpcm_mode(ec_ctx, r);

Similar handling is present on the encoder side as well (in bitstream writing and intra mode search).

To make this invariant explicit, we have two options to add an assertion:

Option 1: Add assert(IMPLIES(mbmi->use_dpcm_y, lossless)) outside prune_intra_y_mode() at all 4 call sites.
Option 2: Pass lossless (or xd->lossless[mbmi->segment_id]) to prune_intra_y_mode() and add the assertion inside prune_intra_y_mode().
Please let us know which option would be preferred.

@yunqingwang1 yunqingwang1 Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine. Since one condition is being removed, let's add a check to ensure this logic isn't mistakenly broken in the future. Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the assertion inside prune_intra_y_mode() to guarantee that use_dpcm_y is set only for the lossless case.

During further testing, we noticed a bit-mismatch on the Vertical_Bayshore_270x480_2997 sequence in the speed=0 Low-Delay (LD) configuration.
Root Cause: When evaluating lossless DPCM mode (use_dpcm_y != 0), the function returned early before updating best_model_rd and top_intra_model_rd[] . However, best_model_rd is later being used in:

  • model_intra_yrd_and_prune() (for palette mode search)
  • rd_pick_intra_dip_sby() (as an input feature to the ML model that prunes DIP modes)

(Note: While top_intra_model_rd[] is also bypassed during the early return for lossless DPCM, this is not an issue since top_intra_model_rd[] is reset prior to its usage).
Fix: Moved the best_model_rd update before the early exit check for use_dpcm_y.

This change moves condition checks related to lossless DPCM modes
inside prune_intra_y_mode() and updates its return type from int to
bool.

No stats changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants