Open mabruzzo opened 1 month ago
My thoughts:
I like idea number one. Although it might get complicated to keep particles of different types in the same data structure. If someone needs particles of different types in the same run it probably would be better to have multiple particle data structures, each for each type.
I don't see the benefit of the second idea. You mention that the benefit would be to loop over the batch when removing particles, instead of looping over the entire particle array. But you would have to do that for all batches, so I don't see what's the advantage. Regardless of how you do it, you still have to check all particles to see which ones need to be moved to another GPU. Also, dividing the particles into small groups like that would require a bunch of house keeping that would complicate stuff. Just to start, you would need to track how many particles are in each batch, as particles move to other GPUs and as a GPU receives particles, you would have to accommodate them into the empty spaces of different batches otherwise you would be wasting memory with all the empty spaces and you would have to track which spaces are empty. Also you don't want to launch many tiny kernels (one for each batch), this would introduce a lot of overhead from the launch latency and the GPU will be very underutilized. So, this really would complicate stuff a lot and would probably make things slower.
That's my opinion, I'm happy to discuss further if you want.
While thinking about how to modify the particle system to better support star-particle creation, I had some thoughts on how we could potentially improve the particle system in general.
These are mostly thoughts for an "ideal world." I'm not really suggesting that anybody should spend time doing this.
support different particle "types": so that we could support star particles and sink particles. (Ideally with the option for them to have different particle attributes -- but that's obviously far less important)
rather than organizing particles in a giant array, it would be worth reorganizing them into "batches" (or "chunks")
T
, rather than storing the values in 1 giant array, we would instead store the values in a series of chunks.For the sake of concreteness, a naive implementation of this might look like:
In the above snippet,
CHUNK_CAPACITY
is some compile-time constant (e.g. 8, 16, 32, etc.).The control-flow would change from
to
[^1]: For example, it may be better to store batch size separately from the data in a given batch (you could do away with the
Batch<T>
Class template and store the values directly within Batches). If we also pre-allocate the memory for the maximum allowed number of particles (which would probably be beneficial), you could allocate all of the memory for all batches in a single array (rather than storing pointers to each batch, you could then store the index of each batch).