-
Notifications
You must be signed in to change notification settings - Fork 63
mod lf_apply: clean up code and use slices instead of raw pointers
#728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
kkysen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, feel free to split this PR up more if it's taking a while, and it's easier to review it in smaller chunks as well.
kkysen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly looks good. I had some small comments, as well as a bigger one concerning the "unaligned" reads of lvl, which is UB the way we're currently doing it.
…vl: &[[u8; 4]]`, as previous accesses were UB (#731) See: * #728 (comment) * #728 (comment) The current "unaligned" access of `lvl`, added in #726, and a proposed change in #728, [are UB according to `miri`](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=80849f822a890cabd324b3b898b291b8), as they cast `&[u8; 3]` and `&u8` to `&[u8; 4]`, which is an out of bounds read of a borrow. This `fn unaligned_lvl_slice` helper `fn` fixes it and passes `miri` by transmuting (through `.align_to`) to a `&[u8]`, doing the slice, and then doing a checked cast back to `[u8; 4]`. It also does correct bounds checking, as the previous ways were off by one in their bounds checking, as they didn't consider the read of the unaligned part into the next `[u8; 4]`. Doing it this way also optimizes just as well as the previous methods. We could also use a dependency like `zerocopy` to encapsulate the `unsafe` `.align_to`, but as long as these kinds of "unaligned" array reads are a one-off, doing it inline here seems better. Update: Switched to using unstable `fn`s from `std` that make things fully safe and correct, copied into our codebase for stability. I already figured out how to fix the UB in reviewing #728, so I just went ahead and made the fix independently.
The first few commits are now in #739 |
10d7d46 to
2f784f5
Compare
lf_apply.rs: clean up code and use slices instead of raw pointerslf_apply.rs: clean up code and use slices instead of raw pointers
|
Is this good to go in now? Seems it needs a rebase but anything else beyond that? |
I need to re-review it. |
2f784f5 to
ba4f768
Compare
Does this fix and close #702, or just address part of it? If it does, can you use one of the special linking keywords like "fix", "close", or "resolve"? |
kkysen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few little things left. Also, for the previous unresolved comments, if those were .add()s where the resulting pointer is negatively offset later, you can dismiss my comments. I wasn't sure if that was the case for all of them, though it may.
lf_apply.rs: clean up code and use slices instead of raw pointersmod lf_apply: clean up code and use slices instead of raw pointers
f5c44bb to
864fb5a
Compare
|
I ran into some issues with borrowing |
That looks right. That said, we could put that |
864fb5a to
5eccc3a
Compare
Use `for` instead of `while`
Define masks as `u16` and simplify code to look more like original C code.
Parameter `p` is changed to be an array of slices. A parameter `p_offset` is added to indicate the location of the "origin" sample within the slice. Note that the offset is the same for both chroma components. Hence `p_offset` has one fewer entries than `p`.
Offsets `dst_offset` and `uv_offset` are added to point to "origin" position within slice
Use slices for parameter of `rav1d_loopfilter_sbrow_rows` and `rav1d_copy_lpf`
Dimensions of slice initially created had to be adjusted to account for memory allocation constraints (e.g., sizes of multiples of 128). Not doing so leeds to invalid access when picture dimensiosn are odd numbers.
Also rename variables, dropping `data` prefix.
`dst_offset` is also added to enable accessing elements in the slice that precede the reference position that was pointed to by `dst`
Use slice for pixel data. Add an offset parameter to indicate reference index within slice.
68b9f35 to
5a24dbd
Compare
Had to resolve some conflicts but nothing tedious |
Uh oh!
There was an error while loading. Please reload this page.