[Bf-blender-cvs] [927d099ec09] master: Particles: Fixed thread work size calculation.
Stefan Werner
noreply at git.blender.org
Fri Jan 22 09:30:38 CET 2021
Commit: 927d099ec099e176b6e1f65555cbd4e70f681301
Author: Stefan Werner
Date: Wed Jan 20 11:17:32 2021 +0100
Branches: master
https://developer.blender.org/rB927d099ec099e176b6e1f65555cbd4e70f681301
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
===================================================================
M source/blender/blenkernel/intern/particle_system.c
===================================================================
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index ad98079bc27..55d4043f96c 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -475,20 +475,24 @@ void psys_tasks_create(ParticleThreadContext *ctx,
{
ParticleTask *tasks;
int numtasks = min_ii(BLI_system_thread_count() * 4, endpart - startpart);
- float particles_per_task = numtasks > 0 ? (float)(endpart - startpart) / (float)numtasks : 0;
+ 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;
- float pnext;
- float p = (float)startpart;
- for (int 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);
}
}
More information about the Bf-blender-cvs
mailing list