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
This commit is contained in:
parent
6265fe8605
commit
cde858ae98
Notes:
blender-bot
2023-02-14 09:48:25 +01:00
Referenced by issue #77348, Blender LTS: Maintenance Task 2.83
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue