sarah-quinones / aligned-vec

MIT License
21 stars 7 forks source link

Expose alignment to `avec![]` / deduce it automatically #2

Closed SK83RJOSH closed 7 months ago

SK83RJOSH commented 1 year ago

I really love this crate, but one of the more cumbersome aspects of it is the inability to create non-runtime aligned vectors conveniently. It would be really handy to be able to either deduce the alignment automatically, or specify it explicitly like so:

let vec: AVec<u8, ConstAlign<16>> = avec![0; 128];
let vec: AVec<u8> = avec![[16]| 0; 128];
sarah-quinones commented 1 year ago

i haven't used anything other than the default const alignment (cacheline size) in practice :sweat_smile: is it something you use often?

SK83RJOSH commented 1 year ago

Indeed, I'm doing some homebrew at the moment and different types of graphics buffers need different alignment. For example, texture data needs to be 128-byte aligned for fast path rendering on the psp, and vertex data must be 16-byte aligned for the SoC to do interpolation of vertex attributes. :)

I'm of course not sure how frequently this comes up in practice, since I suppose cache line size covers everything adequately well; my current approach is to be explicit since I don't know a lot about the allocation scheme under the hood, and have concerns about memory fragmentation.

sarah-quinones commented 1 year ago

automatic deduction is gonna be a bit tricky, but i can do the second option i think

sarah-quinones commented 7 months ago

added the second macro variant in 0.6.0