Comments (11)
Multithreaded rendering context will use multiple worker threads to process render commands within the same context. It will work like the following:
- Each render command will be enqueued instead of rendered synchronously
- When the command queue reaches certain limit the engine would signal worker threads
- Each thread will render the whole queue in bands, when done it will move to the next available band
This means that the rendering will be asynchronous.
There are few challenges here, but the idea is solid and I have already started working on it. The idea of bands makes rendering very cache friendly as each worker pass (rendering the whole queue of single band) will be limited to only a certain part of the destination image. In addition, if there are bands where nothing happens these could be skipped quickly so the work should be evenly distributed across workers.
So yeah, I plan to have something ready for experimenting very soon.
from blend2d.
great. I'm a bit skeptical as to whether worker threads will improve over what a single processor pinned thread can do. Are you concerned with context switch time being a waste vs the benefits of multiple threads? Are you going to pin threads on different cores? What about memory bus conflicts? I've never really tried having multiple threads write into same memory, so I'm not too familiar with how performant it's going to be, or how contentious.
from blend2d.
The idea is that threads will not write into the same memory. The reason I use bands is that workers will only access bands, and each worker will only access specific bands, so it should theoretically not happen that two threads would write into the same memory.
The reason of command queue is to minimize synchronization. If one worker processes for example 256 batched commands at once and then synchronize it's much better than synchronizing after each command.
from blend2d.
by 'same memory' I really mean at a systems level. There's only one RAM, and one bus (or maybe two) to get from the CPU to it. Having multiple threads trying to write to RAM at the 'same' time might cause some contention? Maybe that kind of contention is so much less these days as you state, you intend to be cache friendly, so most likely no real contention that any human will notice.
I get the apparent speedup of the queue of commands. This is essentially parallel vs serial. The only caveat is i'll have to rely on flush, or sync if I care to ensure my buffer is actually complete, or at least that all the outstanding commands have been written.
I'm thinking you might need a barrier of some sort that I can grab so that I can sync to that barrier. Otherwise, new commands might come in while I'm waiting? And I'll never sync? Or do you just check lengths of queues at time of sync call, and process that many commands?
from blend2d.
oh, and I love command queues. Very multi-task friendly, scalable, and remotable.
from blend2d.
A main memory read is about 10 times faster than a context switch which requires to store the whole register set. Nowadays done by a shadowing unit to speed things up.
from blend2d.
Are you suggesting single thread will outperform? Im guessing with threads pinned to cores, this is essentially true parallelism, with minimal context switch? T least if that's what's sought, i can believe it will outperform single thread. Otherwise, context switching on single core doesnt sound particularly speedy, dependwing on mix of compute vs pure memory manipulation.
But, im no asmjit expert, im curious to see how it works out.
from blend2d.
I don't plan pinning threads to particular cores btw, here I think that OS should distribute the work better, imagine 5 apps pinning a particular thread to the first core, they would fight for it. The idea of MT in Blend2D is to distribute the work evenly across N threads with minimized synchronization (ideally the sync would only happen after X commands like 128, 256, etc).
It will work out, I have done it once, now I'm gonna do it even better, just need a bit of time to finish :)
from blend2d.
Yah, I'm definitely not the expert on multi-threaded drawing, so I'll trust your experience. My line of questioning here shows my naivete, and I'm happy to be schooled in the finer arts of modern day multi-core programming. I am so looking forward to this working as it will be a great learning moment.
from blend2d.
Are you suggesting single thread will outperform?
No, my answer relates to your fear about multiple threads accessing RAM. Since there is a hierarchical memory architecture anyway, context switches are much worse than trying to access the RAM. Which means: I don't share your fear ;-)
from blend2d.
Ill close this as it was just a discussion
from blend2d.
Related Issues (20)
- img.getData 0.9.0 to 0.10.5 version HOT 4
- Wish: implement an API to rendering text along/by a path HOT 1
- composition operator not work on macOS MPB with Apple m1 HOT 2
- [Portable Pipeline] Composition operators not working (only SrcCopy and SrcOver) HOT 11
- Rendering bug with BLContext for certain image sizes HOT 2
- Wish: Android support HOT 2
- Raspberry Pi 2B rev1.1 compilation failed HOT 3
- about BLFont question HOT 12
- strokedPath error HOT 1
- Can bled2d be easily ported to rtos? HOT 3
- Rendering of fonts in various national languages HOT 2
- Build failure simdx86_test_avx512.cpp, MingGW-w64, static, cmake/ninja, no tests HOT 4
- clipToRect not correctly applied to fillGlyphRun within rotated context HOT 4
- crash with gcc (Debian 12.2.0-14) 12.2.0 HOT 4
- build errors on Fedora s390x HOT 1
- Crash on blitImage with different image format HOT 3
- ctest of bl_test_unit failed on fedora s390x HOT 5
- Support 8-bit (s)RGBA BLImages? HOT 5
- Unexpected results with BLPattern HOT 2
- close() on path doesn't interact with stroking as expected. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blend2d.