gtk-rs-core icon indicating copy to clipboard operation
gtk-rs-core copied to clipboard

[FEATURE REQUEST] mutable graphene operations

Open ranfdev opened this issue 2 years ago • 3 comments

Let's take Vec2 as an example: most operations are similar to fn op(&self, &Vec2) -> Vec2. But If I have an array of vectors (which is mostly always what I need to squeeze maximum performance), I can't apply any of those operations on my vector inside the array, because the operation doesn't mutate in place.

If I have an array of 1000 Vec2, creating a copy at each frame is going to destroy the performance of my app.

The graphene C API can work in place (or at least it can put the result to a user specified pointer).

ranfdev avatar May 03 '22 14:05 ranfdev

We have normally manual implementations for the setters. I have probably missed some, feel free to send a patch

bilelmoussaoui avatar May 03 '22 14:05 bilelmoussaoui

If I have an array of 1000 Vec2, creating a copy at each frame is going to destroy the performance of my app.

I don't think so. Updating a Vec2 should be quite optimizable for the compiler and effectively do the same as if you had setters.

But for nicer usage having setters would be nice.

sdroege avatar May 03 '22 18:05 sdroege

I'd like to point out that SIMD types are not mutable by design: accessing single lanes to change stuff destroys any performance advantage those types provide.

Every SIMD operation, down to the assembly level, returns a new value; you can pass the address of the original variable to replace its contents wholesale, but that requires passing around stack allocated values, and never heap allocated ones. In any case, you still get a whole new vector.

ebassi avatar Sep 07 '22 12:09 ebassi

I can't apply any of those operations on my vector inside the array, because the operation doesn't mutate in place.

You can mutate the array by doing array[i] = array[i].add(x).

Can we close this issue and move it to upstream graphene?

jf2048 avatar Oct 09 '22 06:10 jf2048