From cdf564277c4d31d98dad78c0d7ad03603896cf4b Mon Sep 17 00:00:00 2001 From: Stefan Werner Date: Wed, 20 Jan 2021 11:17:32 +0100 Subject: [PATCH 1/2] 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 --- .../blenkernel/intern/particle_system.c | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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); } } From 0373d1b09fc9db2c237a507dc6ef649c5d2b8703 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 22 Jan 2021 11:25:32 +0100 Subject: [PATCH 2/2] GPencil: Fix unreported Vertex Paint masking error The masking was not working as expected and allowed to paint non selected strokes. --- source/blender/editors/gpencil/gpencil_vertex_paint.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c index 62ddfaab012..e2c81d53fba 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_paint.c +++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c @@ -845,6 +845,13 @@ static bool gpencil_vertexpaint_select_stroke(tGP_BrushVertexpaintData *gso, bool saved = false; + /* Check stroke masking. */ + if (GPENCIL_ANY_VERTEX_MASK(gso->mask)) { + if ((gps->flag & GP_STROKE_SELECT) == 0) { + return false; + } + } + /* Check if the stroke collide with brush. */ if (!ED_gpencil_stroke_check_collision(gsc, gps, gso->mval, radius, diff_mat)) { return false;