Sculpt dyntopo: Temp fix for nasty GCC compiler bug on linux.

I'll file a bug report with GCC tomorrow.
This commit is contained in:
Joseph Eagar 2021-08-22 12:51:53 -07:00
parent 36785c83f0
commit 9a197a1185
3 changed files with 77 additions and 16 deletions

View File

@ -3700,7 +3700,7 @@ static void free_meshtest(MeshTest *m)
#define SMOOTH_TEST_STEPS 20
void pbvh_bmesh_smooth_test(BMesh *bm, PBVH *pbvh)
double pbvh_bmesh_smooth_test(BMesh *bm, PBVH *pbvh)
{
double average = 0.0f;
double average_tot = 0.0f;
@ -3762,9 +3762,10 @@ void pbvh_bmesh_smooth_test(BMesh *bm, PBVH *pbvh)
}
printf("time: %.5f\n", average / average_tot);
return average / average_tot;
}
void pbvh_meshtest2_smooth_test(MeshTest2 *m2, PBVH *pbvh)
double pbvh_meshtest2_smooth_test(MeshTest2 *m2, PBVH *pbvh)
{
double average = 0.0f;
double average_tot = 0.0f;
@ -3829,9 +3830,10 @@ void pbvh_meshtest2_smooth_test(MeshTest2 *m2, PBVH *pbvh)
}
printf("time: %.5f\n", average / average_tot);
return average / average_tot;
}
void pbvh_meshtest_smooth_test(MeshTest *m, PBVH *pbvh)
double pbvh_meshtest_smooth_test(MeshTest *m, PBVH *pbvh)
{
double average = 0.0f;
double average_tot = 0.0f;
@ -3902,6 +3904,7 @@ void pbvh_meshtest_smooth_test(MeshTest *m, PBVH *pbvh)
}
printf("time: %.5f\n", average / average_tot);
return average / average_tot;
}
void pbvh_bmesh_cache_test(CacheParams *params, BMesh **r_bm, PBVH **r_pbvh_out)
@ -3909,6 +3912,10 @@ void pbvh_bmesh_cache_test(CacheParams *params, BMesh **r_bm, PBVH **r_pbvh_out)
// build mesh
const int steps = 325;
printf("== Starting Test ==\n");
printf("building test mesh. . .");
BMAllocTemplate templ = {0, 0, 0, 0};
BMesh *bm = BM_mesh_create(&templ,
@ -4052,8 +4059,38 @@ void pbvh_bmesh_cache_test(CacheParams *params, BMesh **r_bm, PBVH **r_pbvh_out)
BM_mesh_elem_table_ensure(bm, BM_VERT | BM_FACE);
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE | BM_FACE);
int loop_size = sizeof(BMLoop) - sizeof(void *) * 4;
size_t s1 = 0, s2 = 0, s3 = 0;
s1 = sizeof(BMVert) * (size_t)bm->totvert + sizeof(BMEdge) * (size_t)bm->totedge +
sizeof(BMLoop) * (size_t)bm->totloop + sizeof(BMFace) * (size_t)bm->totface;
s2 = sizeof(MeshVert2) * (size_t)bm->totvert + sizeof(MeshEdge2) * (size_t)bm->totedge +
sizeof(MeshLoop2) * (size_t)bm->totloop + sizeof(MeshFace2) * (size_t)bm->totface;
s3 = (size_t)loop_size * (size_t)bm->totvert + sizeof(BMEdge) * (size_t)bm->totedge +
sizeof(BMLoop) * (size_t)bm->totloop + sizeof(BMFace) * (size_t)bm->totface;
double times[4];
char *names[4];
int cd_overhead = 0;
CustomData *cdatas[4] = {&bm->vdata, &bm->edata, &bm->ldata, &bm->pdata};
int ctots[4] = {bm->totvert, bm->totedge, bm->totloop, bm->totface};
for (int i = 0; i < 4; i++) {
cd_overhead += cdatas[i]->totsize * ctots[i];
}
s1 += cd_overhead;
s2 += cd_overhead;
printf(" bmesh mem size: %.2fmb %.2mb\n",
(float)s1 / 1024.0f / 1024.0f,
(float)s3 / 1024.0f / 1024.0f);
printf("meshtest2 mem size: %.2fmb\n", (float)s2 / 1024.0f / 1024.0f);
printf("= BMesh random order\n");
pbvh_bmesh_smooth_test(bm, pbvh);
times[0] = pbvh_bmesh_smooth_test(bm, pbvh);
names[0] = "random order";
BMesh *bm2 = BKE_pbvh_reorder_bmesh(pbvh);
printf("= BMesh vertex cluster order\n");
@ -4063,19 +4100,22 @@ void pbvh_bmesh_cache_test(CacheParams *params, BMesh **r_bm, PBVH **r_pbvh_out)
BM_mesh_elem_table_ensure(bm2, BM_VERT | BM_FACE);
BM_mesh_elem_index_ensure(bm2, BM_VERT | BM_EDGE | BM_FACE);
pbvh_bmesh_smooth_test(bm2, pbvh);
times[1] = pbvh_bmesh_smooth_test(bm2, pbvh);
names[1] = "vertex cluser";
printf("= Pure data-oriented (struct of arrays)\n");
MeshTest *m = meshtest_from_bm(bm2);
pbvh_meshtest_smooth_test(m, pbvh);
times[2] = pbvh_meshtest_smooth_test(m, pbvh);
names[2] = "data-oriented";
free_meshtest(m);
printf("= Object-oriented but with integer indices instead of pointers\n");
MeshTest2 *m2 = meshtest2_from_bm(bm2);
pbvh_meshtest2_smooth_test(m2, pbvh);
times[3] = pbvh_meshtest2_smooth_test(m2, pbvh);
names[3] = "integer indices";
free_meshtest2(m2);
@ -4096,6 +4136,14 @@ void pbvh_bmesh_cache_test(CacheParams *params, BMesh **r_bm, PBVH **r_pbvh_out)
else {
BKE_pbvh_free(pbvh);
}
printf("\n== Times ==\n");
for (int i = 0; i < ARRAY_SIZE(times); i++) {
printf(" %s : %.2f\n", names[i], times[i]);
}
printf("== Test Finished ==\n");
}
void pbvh_bmesh_do_cache_test()

View File

@ -228,10 +228,26 @@ void BM_enter_multires_space(Object *ob, BMesh *bm, int space)
*
* \warning This function doesn't calculate face normals.
*/
/* joeedh:
GCC under linux is doing something very weird. In the line below:
MultiresModifierData *mmd = ob ? get_multires_modifier(NULL, ob, true) : NULL;
ob is evaulating to true when optimizations are on. The following code:
printf("ob: %p, %s\n", ob, ob ? "true" : "false");
will print (nil), true. Very strange!
*/
#ifdef __GNUC__
__attribute__((optimize("O0")))
#endif
void BM_mesh_bm_from_me(Object *ob,
BMesh *bm,
const Mesh *me,
const struct BMeshFromMeshParams *params)
BMesh *bm,
const Mesh *me,
const struct BMeshFromMeshParams *params)
{
const bool is_new = !(bm->totvert || (bm->vdata.totlayer || bm->edata.totlayer ||
bm->pdata.totlayer || bm->ldata.totlayer));

View File

@ -731,7 +731,6 @@ void SCULPT_dynamic_topology_enable_ex(Main *bmain, Depsgraph *depsgraph, Scene
/* Dynamic topology doesn't ensure selection state is valid, so remove T36280. */
BKE_mesh_mselect_clear(me);
/* Create triangles-only BMesh. */
#if 1
ss->bm = BM_mesh_create(&allocsize,
&((struct BMeshCreateParams){.use_toolflags = false,
@ -1009,17 +1008,14 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(o
return OPERATOR_FINISHED;
}
static int dyntopo_error_popup(bContext *C, wmOperatorType *ot, enum eDynTopoWarnFlag flag)
{
uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Error!"), ICON_ERROR);
uiLayout *layout = UI_popup_menu_layout(pup);
if (flag & DYNTOPO_ERROR_MULTIRES) {
const char *msg_error = TIP_("Multires modifier detected; cannot enable dyntopo.");
const char *msg = TIP_(
"Dyntopo and multires cannot be mixed.");
const char *msg = TIP_("Dyntopo and multires cannot be mixed.");
uiItemL(layout, msg_error, ICON_INFO);
uiItemL(layout, msg, ICON_NONE);
@ -1125,7 +1121,8 @@ static int sculpt_dynamic_topology_toggle_invoke(bContext *C,
if (flag & DYNTOPO_ERROR_MULTIRES) {
return dyntopo_error_popup(C, op->type, flag);
} else if (flag) {
}
else if (flag) {
/* The mesh has customdata that will be lost, let the user confirm this is OK. */
return dyntopo_warning_popup(C, op->type, flag);
}