Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Werner <stefan.werner@tangent-animation.com>2021-01-20 13:17:32 +0300
committerJeroen Bakker <jeroen@blender.org>2021-01-25 12:10:40 +0300
commitcde858ae98a5bcc214cabae0890a09b5b41e9909 (patch)
treef870dbf9068bf8bf81597de483fe40b9fdc8fc9b
parent6265fe860588e9e20e0f3baf8f42ef6247b36ff8 (diff)
Particles: Fixed thread work size calculation.
Dividing the workload by number of tasks in float is imprecise and lead in some cases to particles not being calculated at all (example: 20000 particles, 144 tasks). Switching this calculation to integer makes sure we don't lose count. Differential Revision: https://developer.blender.org/D10157
-rw-r--r--source/blender/blenkernel/intern/particle_system.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index b3472bfe716..615c4350fe4 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -476,20 +476,24 @@ void psys_tasks_create(ParticleThreadContext *ctx,
{
ParticleTask *tasks;
int numtasks = min_ii(BLI_system_thread_count() * 4, endpart - startpart);
- float particles_per_task = (float)(endpart - startpart) / (float)numtasks, p, pnext;
- int i;
+ int particles_per_task = numtasks > 0 ? (endpart - startpart) / numtasks : 0;
+ int remainder = numtasks > 0 ? (endpart - startpart) - particles_per_task * numtasks : 0;
tasks = MEM_callocN(sizeof(ParticleTask) * numtasks, "ParticleThread");
*r_numtasks = numtasks;
*r_tasks = tasks;
- p = (float)startpart;
- for (i = 0; i < numtasks; i++, p = pnext) {
- pnext = p + particles_per_task;
-
+ int p = startpart;
+ for (int i = 0; i < numtasks; i++) {
tasks[i].ctx = ctx;
- tasks[i].begin = (int)p;
- tasks[i].end = min_ii((int)pnext, endpart);
+ tasks[i].begin = p;
+ p = p + particles_per_task + (i < remainder ? 1 : 0);
+ tasks[i].end = p;
+ }
+
+ /* Verify that all particles are accounted for. */
+ if (numtasks > 0) {
+ BLI_assert(tasks[numtasks - 1].end == endpart);
}
}