I’m writing a toy renderer to learn a bit about Rust. So far, I’m generating my image in a Vec, where Color is a simple RGB triplet of f64.
I’m trying to parallelize the rendering by splitting it into tiles of 32x32 pixels. The worker threads simply pick up an unrendered tile when they’re finished with the previous one.
I’m having trouble writing the results from the threads. Each threads needs to write parts of the result [1024 pixels for each tile], but the Vec cannot be shared mutably across threads.
In theory, it is largely fine - each thread ends up being responsible for different parts of the generated image. However, I don’t know how to represent that properly in Rust.
Any idea which kind of structure or construct can I use to represent the image in memory, while still allowing multiple threads to write to it?
[In general I want to reduce moving data around uselessly, so copying the tiles is not really a good option - I would prefer to write them in place directly.].