A few of you might remember my DMX ambilight project from some years back, where I was capturing the screen in real-time on Windows using DXGI, averaging the edges, and sending the data out to a DMX transmitter that could then ambilight a whole stage using RGB PAR cans.
-
Prikaži ovu nit
-
The major challenge was averaging the data fast enough. The data is given as a flat array of 32-bit RGBA8 values, and at 3840x2160 it can be quite computationally intensive to average all the edge blocks at 60fps. I mostly cheated by sampling every nth pixel in a block.
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđaPrikaži ovu nit -
The problem is trivially parallelisable, of course, but since you can't guarantee that threads will be scheduled when you want them to be, it's often *slower* to do it this way because for short operations it's slower to context switch than do it all on one thread.
0 proslijeđenih tweetova 1 korisnik označava da mu se sviđaPrikaži ovu nit -
It also didn't help that I was doing this in C#, which is fast enough for most cases but isn't necessarily ideal for performance-sensitive applications like this. I did try some tricks to improve performance, though.
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđaPrikaži ovu nit -
My first attempt was to rewrite a bunch of the code in .NET Core and make use of the System.Runtime.Intrinsics namespace to explicitly vectorise the operations. Unfortunately this was really slow because (at the time) I couldn't easily use the intrinsics against array elements.
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđaPrikaži ovu nit -
I then had a bit of a go at doing the averaging with a compute shader, which was fun but turned out to be absurdly slow because the pixel data was being pulled off the GPU during DXGI, then pushed back to the GPU when invoking the compute shader. Soooo sloooooow.
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđaPrikaži ovu nit -
I mostly decided that the cheating nth-pixel approach was good enough. I used prime values of n to try to avoid just sampling fixed columns in a block and it worked quite nicely. I ran it at NOVA demoparty one year and it looked great. I left the code alone until today.
1 reply 0 proslijeđenih tweetova 0 korisnika označava da im se sviđaPrikaži ovu nit -
While looking into something completely different I happened to stumble upon this project on GitHub. It's a C++ function that performs ultra-fast colour averaging over an image using SIMD. Benchmarks show a full 3840x2160 image can be averaged in <2ms.https://github.com/Wunkolo/qAverageColor …
1 reply 1 proslijeđeni tweet 5 korisnika označava da im se sviđaPrikaži ovu nit -
Even using it in the most naive way I could think of (one call per row in every block) it only takes ~3ms, which is about as fast as my implementation that cheats and only samples a small subset of pixels.
1 reply 0 proslijeđenih tweetova 1 korisnik označava da mu se sviđaPrikaži ovu nit
Hacking this implementation to process a rectangle of pixels within an image should be significantly faster. Likely sub-millisecond processing times on a single core. At 60fps that's under 6% of my CPU time budget!
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.