-
Notifications
You must be signed in to change notification settings - Fork 22
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
struct Rav1dFrameContext_lf::cdef_line
: Convert pointers to offsets
#777
Conversation
1c915d7
to
b152d3c
Compare
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.
I had some comments about the pixel casting checks, but the rest of the offset stuff all looks good.
include/common/bitdepth.rs
Outdated
assert!(bytes.len() % len == 0); | ||
assert!(bytes.as_ptr() as usize % mem::align_of::<Self::Pixel>() == 0); |
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.
We don't want to have to check this everytime we access the pixels, so it'd be better to check it once during creation. I'd been planning to create a type for this. This is probably fine in the meantime, though, just worst perf.
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.
What were you thinking wrt making a custom type to handle it? Something like a PixelBuf
type that wraps a Vec<u8>
and has helpers for accessing the buffer as either a &[u8]
or a &[Pixel]
?
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.
What were you thinking wrt making a custom type to handle it? Something like a
PixelBuf
type that wraps aVec<u8>
and has helpers for accessing the buffer as either a&[u8]
or a&[Pixel]
?
Yeah, basically. It's a bit trickier for Rav1dPicture::data
specifically since it supports custom allocators, but that'd be the gist. The alignment/length stuff would all be checked during construction, and so these safe transmute casts would be no-ops other than dividing the length.
Rav1dFrameContext_lf::cdef_line
: Convert pointers to offsetsstruct Rav1dFrameContext_lf::cdef_line
: Convert pointers to offsets
dae2cc1
to
3fba038
Compare
8a433b4
to
73689be
Compare
ca91098
to
b344fd2
Compare
73689be
to
1d83d68
Compare
…be used non-generically (#780) @randomPoison, follow-up to #777 (comment). I wanted to share the implementation between `BPC::pxstride` and `BitDepth::pxstride`.
1d83d68
to
89acd73
Compare
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.
I think you merged the changes from #780 wrong; they're all overwritten here with the old versions.
89acd73
to
285a342
Compare
Oh weird, idk how I did that. Should be fixed now. |
The pointers in
cdef_line
were pointing into the buffer owned bycdef_line_buf
. In converting them to offsets, I had to make sure that that offsets were consistently in terms of pixels (rather than bytes). The original code was inconsistent here, with the logic working withu8
pointers (and so was using byte offsets), but the code that usescdef_line
treats the pointers asBD::Pixel
pointers, so the offset logic is calculated in terms of pixels. In converting to offsets I normalized on pixel offsets. To do so I had to add a couple of helpers:BPC::pxstride
- Does the same thing asBitDepth::pxstride
, but works in non generic code. This was needed to calculate pixel offsets during the initialization logic.BitDepth::cast_pixel_slice{_mut}
- Converts a&[u8]
to a&[Pixel]
. This was needed so that we could index into the buffer using pixel indices within our bidepth-dependent code.In practice most of the usages of
cdef_line
is to calculate pointers to be passed into asm functions, so the cleaned up code is still doing some pointer arithmetic, though we never dereference those pointers from Rust code.