spanification: spanify Vp9Parser. [chromium/src : main]

0 views
Skip to first unread message

Weidong Liu (Gerrit)

unread,
Dec 21, 2025, 9:53:13 PM (6 days ago) Dec 21
to Thomas Guilbert, Chromium LUCI CQ, chromium...@chromium.org, AyeAye, vaapi-...@chromium.org, mac-r...@chromium.org, media-cro...@chromium.org, feature-me...@chromium.org, chromeos-gfx-...@google.com, oshima...@chromium.org
Attention needed from Thomas Guilbert

Weidong Liu added 1 comment

Patchset-level comments
File-level comment, Patchset 3 (Latest):
Weidong Liu . resolved

Hi, Thomas. PTAL.

Open in Gerrit

Related details

Attention is currently required from:
  • Thomas Guilbert
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I62c8367093d928f3a999543aabf9af4a72d8efa7
Gerrit-Change-Number: 7281025
Gerrit-PatchSet: 3
Gerrit-Owner: Weidong Liu <weido...@chromium.org>
Gerrit-Reviewer: Thomas Guilbert <tgui...@chromium.org>
Gerrit-Reviewer: Weidong Liu <weido...@chromium.org>
Gerrit-Attention: Thomas Guilbert <tgui...@chromium.org>
Gerrit-Comment-Date: Mon, 22 Dec 2025 02:52:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Thomas Guilbert (Gerrit)

unread,
Dec 23, 2025, 4:25:37 PM (4 days ago) Dec 23
to Weidong Liu, Thomas Guilbert, Chromium LUCI CQ, chromium...@chromium.org, AyeAye, vaapi-...@chromium.org, mac-r...@chromium.org, media-cro...@chromium.org, feature-me...@chromium.org, chromeos-gfx-...@google.com, oshima...@chromium.org
Attention needed from Weidong Liu

Thomas Guilbert added 7 comments

Patchset-level comments
Thomas Guilbert . resolved

Thanks for the cleanup! FYI, I will have very limited code review bandwidth until January, due to the holidays.

Thanks

File media/parsers/vp9_parser.h
Line 89, Patchset 3 (Latest): Vp9SegmentationParams();
Vp9SegmentationParams(const Vp9SegmentationParams&);
Vp9SegmentationParams(Vp9SegmentationParams&&);
Vp9SegmentationParams& operator=(const Vp9SegmentationParams&);
Vp9SegmentationParams& operator=(Vp9SegmentationParams&&);
~Vp9SegmentationParams();
Thomas Guilbert . unresolved

Since these are all default, are these needed? It's ok if this is just to silence a compiler error.

Line 34, Patchset 3 (Latest):const int kVp9MaxProfile = 4;
const int kVp9NumRefFramesLog2 = 3;
const size_t kVp9NumRefFrames = 1 << kVp9NumRefFramesLog2;
const uint8_t kVp9MaxProb = 255;
const size_t kVp9NumRefsPerFrame = 3;
const size_t kVp9NumFrameContextsLog2 = 2;
const size_t kVp9NumFrameContexts = 1 << kVp9NumFrameContextsLog2;
Thomas Guilbert . unresolved

While you're here, could you make all of these constants `constexpr`? TY!

File media/parsers/vp9_parser.cc
Line 285, Patchset 3 (Latest):bool ContainsZero(const void* __s, size_t __n) {
return UNSAFE_TODO(memchr(__s, 0, __n)) != nullptr;
}
Thomas Guilbert . unresolved

From intuition and then confirming the syntax with Gemini, this could work:

```
#include "base/containers/contains.h"
#include "base/containers/span.h"

// Generic helper that works for 1D, 2D, ... 6D arrays
template <typename T>
bool ContainsZero(const T& data) {
return base::Contains(base::as_byte_span(data), 0);
}
```
Line 383, Patchset 3 (Latest): for (auto& a : coef_probs) {
for (auto& ai : a) {
for (auto& aj : ai) {
for (auto& ak : aj) {
size_t max_l = (+ak == +aj[0]) ? 3 : 6;
const bool has_zero = std::ranges::any_of(
base::span(ak).first(max_l),
[](const auto& v) { return ContainsZero(v, sizeof(v)); });
if (has_zero) {
return false;
}
}
}
}
}
Thomas Guilbert . unresolved

(Suggested by Gemini) Assuming the `ContainsZero` helper is updated above, this could be replaced with

```
// Iterate down to the [6][6][3] array
for (const auto& a : coef_probs) {
for (const auto& ai : a) {
for (const auto& aj : ai) {
// 1. Check first 3 rows of the first block (aj[0])
if (ContainsZero(base::span(aj[0]).first(3))) {
return false;
}
      // 2. Check the remaining 5 blocks (aj[1]..aj[5]) completely
if (ContainsZero(base::span(aj).subspan<1u>())) {
return false;
}
}
}
}
```
Line 898, Patchset 3 (Latest): if (!loop_filter.delta_enabled) {
Thomas Guilbert . unresolved

NIT: Flip the conditional and if/else blocks.

Line 900, Patchset 3 (Latest): for (size_t j = 0; j < VP9_FRAME_MAX; ++j) {
std::ranges::fill(loop_filter.lvl[i][j], levels[i]);
}
Thomas Guilbert . unresolved

You might be able to use `std::ranges::fill(base::as_writable_byte_span(loop_filter.lvl[i]), levels[i]);` and avoid the for loop.

Open in Gerrit

Related details

Attention is currently required from:
  • Weidong Liu
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I62c8367093d928f3a999543aabf9af4a72d8efa7
    Gerrit-Change-Number: 7281025
    Gerrit-PatchSet: 3
    Gerrit-Owner: Weidong Liu <weido...@chromium.org>
    Gerrit-Reviewer: Thomas Guilbert <tgui...@chromium.org>
    Gerrit-Reviewer: Weidong Liu <weido...@chromium.org>
    Gerrit-Attention: Weidong Liu <weido...@chromium.org>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 21:25:27 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Weidong Liu (Gerrit)

    unread,
    Dec 23, 2025, 10:56:27 PM (4 days ago) Dec 23
    to Thomas Guilbert, Chromium LUCI CQ, chromium...@chromium.org, AyeAye, vaapi-...@chromium.org, mac-r...@chromium.org, media-cro...@chromium.org, feature-me...@chromium.org, chromeos-gfx-...@google.com, oshima...@chromium.org
    Attention needed from Thomas Guilbert

    Weidong Liu added 6 comments

    File media/parsers/vp9_parser.h
    Line 89, Patchset 3: Vp9SegmentationParams();

    Vp9SegmentationParams(const Vp9SegmentationParams&);
    Vp9SegmentationParams(Vp9SegmentationParams&&);
    Vp9SegmentationParams& operator=(const Vp9SegmentationParams&);
    Vp9SegmentationParams& operator=(Vp9SegmentationParams&&);
    ~Vp9SegmentationParams();
    Thomas Guilbert . resolved

    Since these are all default, are these needed? It's ok if this is just to silence a compiler error.

    Weidong Liu

    Yes. Because the modified version does not meet the Chromium-style check.

    Line 34, Patchset 3:const int kVp9MaxProfile = 4;

    const int kVp9NumRefFramesLog2 = 3;
    const size_t kVp9NumRefFrames = 1 << kVp9NumRefFramesLog2;
    const uint8_t kVp9MaxProb = 255;
    const size_t kVp9NumRefsPerFrame = 3;
    const size_t kVp9NumFrameContextsLog2 = 2;
    const size_t kVp9NumFrameContexts = 1 << kVp9NumFrameContextsLog2;
    Thomas Guilbert . resolved

    While you're here, could you make all of these constants `constexpr`? TY!

    Weidong Liu

    Done

    File media/parsers/vp9_parser.cc
    Line 285, Patchset 3:bool ContainsZero(const void* __s, size_t __n) {

    return UNSAFE_TODO(memchr(__s, 0, __n)) != nullptr;
    }
    Thomas Guilbert . unresolved

    From intuition and then confirming the syntax with Gemini, this could work:

    ```
    #include "base/containers/contains.h"
    #include "base/containers/span.h"

    // Generic helper that works for 1D, 2D, ... 6D arrays
    template <typename T>
    bool ContainsZero(const T& data) {
    return base::Contains(base::as_byte_span(data), 0);
    }
    ```
    Weidong Liu

    In [another CL](https://chromium-review.googlesource.com/c/chromium/src/+/6779046/comment/ce42a213_4abf12cf) last time, dalecurtis@ mentioned that `memchr` performs better than `std::rangee::find`. Therefore, I didn't modify this.

    Do you think performance is a concern here?

    Line 383, Patchset 3: for (auto& a : coef_probs) {

    for (auto& ai : a) {
    for (auto& aj : ai) {
    for (auto& ak : aj) {
    size_t max_l = (+ak == +aj[0]) ? 3 : 6;
    const bool has_zero = std::ranges::any_of(
    base::span(ak).first(max_l),
    [](const auto& v) { return ContainsZero(v, sizeof(v)); });
    if (has_zero) {
    return false;
    }
    }
    }
    }
    }
    Thomas Guilbert . resolved

    (Suggested by Gemini) Assuming the `ContainsZero` helper is updated above, this could be replaced with

    ```
    // Iterate down to the [6][6][3] array
    for (const auto& a : coef_probs) {
    for (const auto& ai : a) {
    for (const auto& aj : ai) {
    // 1. Check first 3 rows of the first block (aj[0])
    if (ContainsZero(base::span(aj[0]).first(3))) {
    return false;
    }
          // 2. Check the remaining 5 blocks (aj[1]..aj[5]) completely
    if (ContainsZero(base::span(aj).subspan<1u>())) {
    return false;
    }
    }
    }
    }
    ```
    Weidong Liu

    Thanks, this has been very enlightening. It turns out that APIs like `base::as_byte_span` can be used to compress the dimensions of `uint8_t` arrays.

    Line 898, Patchset 3: if (!loop_filter.delta_enabled) {
    Thomas Guilbert . resolved

    NIT: Flip the conditional and if/else blocks.

    Weidong Liu

    Done

    Line 900, Patchset 3: for (size_t j = 0; j < VP9_FRAME_MAX; ++j) {

    std::ranges::fill(loop_filter.lvl[i][j], levels[i]);
    }
    Thomas Guilbert . resolved

    You might be able to use `std::ranges::fill(base::as_writable_byte_span(loop_filter.lvl[i]), levels[i]);` and avoid the for loop.

    Weidong Liu

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Thomas Guilbert
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I62c8367093d928f3a999543aabf9af4a72d8efa7
    Gerrit-Change-Number: 7281025
    Gerrit-PatchSet: 4
    Gerrit-Owner: Weidong Liu <weido...@chromium.org>
    Gerrit-Reviewer: Thomas Guilbert <tgui...@chromium.org>
    Gerrit-Reviewer: Weidong Liu <weido...@chromium.org>
    Gerrit-Attention: Thomas Guilbert <tgui...@chromium.org>
    Gerrit-Comment-Date: Wed, 24 Dec 2025 03:55:53 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Thomas Guilbert <tgui...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Weidong Liu (Gerrit)

    unread,
    Dec 23, 2025, 11:00:35 PM (4 days ago) Dec 23
    to Thomas Guilbert, Chromium LUCI CQ, chromium...@chromium.org, AyeAye, vaapi-...@chromium.org, mac-r...@chromium.org, media-cro...@chromium.org, feature-me...@chromium.org, chromeos-gfx-...@google.com, oshima...@chromium.org
    Attention needed from Thomas Guilbert

    Weidong Liu added 1 comment

    Patchset-level comments
    Thomas Guilbert . resolved

    Thanks for the cleanup! FYI, I will have very limited code review bandwidth until January, due to the holidays.

    Thanks

    Weidong Liu

    Please enjoy your holiday. You may review the application whenever you wish.

    Gerrit-Comment-Date: Wed, 24 Dec 2025 04:00:03 +0000
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages