Blender V5.3
lattice_deform_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#include "testing/testing.h"
5
6#include "BKE_gtest_base.hh"
7
8#define DO_PERF_TESTS 0
9
10#if DO_PERF_TESTS
11
12# include "BKE_idtype.hh"
13# include "BKE_lattice.hh"
14
15# include "MEM_guardedalloc.h"
16
17# include "DNA_lattice_types.h"
18# include "DNA_mesh_types.h"
19# include "DNA_object_types.h"
20
21# include "BLI_rand.hh"
22
23namespace blender::bke::tests {
24
25struct LatticeDeformTestContext {
26 Lattice lattice;
27 Object ob_lattice;
28 Mesh mesh;
29 Object ob_mesh;
30 float (*coords)[3];
31 LatticeDeformData *ldd;
32};
33
34static void test_lattice_deform_init(LatticeDeformTestContext *ctx,
35 RandomNumberGenerator *rng,
36 int32_t num_items)
37{
38 /* Generate random input data between -5 and 5. */
39 ctx->coords = MEM_new_array_uninitialized<float[3]>(size_t(num_items), __func__);
40 for (uint32_t index = 0; index < num_items; index++) {
41 ctx->coords[index][0] = (rng->get_float() - 0.5f) * 10;
42 ctx->coords[index][1] = (rng->get_float() - 0.5f) * 10;
43 ctx->coords[index][2] = (rng->get_float() - 0.5f) * 10;
44 }
45 IDType_ID_LT.init_data(&ctx->lattice.id);
46 STRNCPY(ctx->lattice.id.name, "LTLattice");
47 IDType_ID_OB.init_data(&ctx->ob_lattice.id);
48 ctx->ob_lattice.type = OB_LATTICE;
49 ctx->ob_lattice.data = &ctx->lattice;
50 IDType_ID_OB.init_data(&ctx->ob_mesh.id);
51 IDType_ID_ME.init_data(&ctx->mesh.id);
52 ctx->ob_mesh.type = OB_MESH;
53 ctx->ob_mesh.data = &ctx->mesh;
54
55 ctx->ldd = BKE_lattice_deform_data_create(&ctx->ob_lattice, &ctx->ob_mesh);
56}
57
58static void test_lattice_deform(LatticeDeformTestContext *ctx, int32_t num_items)
59{
60 for (int i = 0; i < num_items; i++) {
61 float *co = &ctx->coords[i][0];
62 BKE_lattice_deform_data_eval_co(ctx->ldd, co, 1.0f);
63 }
64}
65
66static void test_lattice_deform_free(LatticeDeformTestContext *ctx)
67{
69 MEM_delete(ctx->coords);
70 IDType_ID_LT.free_data(&ctx->lattice.id);
71 IDType_ID_OB.free_data(&ctx->ob_lattice.id);
72 IDType_ID_OB.free_data(&ctx->ob_mesh.id);
73 IDType_ID_ME.free_data(&ctx->mesh.id);
74}
75
76class LatticeDeformPerformanceTest : public BlenderGTestBase {};
77
78TEST_F(LatticeDeformPerformanceTest, performance_no_dvert_1)
79{
80 const int32_t num_items = 1;
81 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
82 RandomNumberGenerator rng;
83 test_lattice_deform_init(&ctx, &rng, num_items);
84 test_lattice_deform(&ctx, num_items);
85 test_lattice_deform_free(&ctx);
86}
87TEST_F(LatticeDeformPerformanceTest, performance_no_dvert_1000)
88{
89 const int32_t num_items = 1000;
90 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
91 RandomNumberGenerator rng;
92 test_lattice_deform_init(&ctx, &rng, num_items);
93 test_lattice_deform(&ctx, num_items);
94 test_lattice_deform_free(&ctx);
95}
96TEST_F(LatticeDeformPerformanceTest, performance_no_dvert_10000)
97{
98 const int32_t num_items = 10000;
99 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
100 RandomNumberGenerator rng;
101 test_lattice_deform_init(&ctx, &rng, num_items);
102 test_lattice_deform(&ctx, num_items);
103 test_lattice_deform_free(&ctx);
104}
105TEST_F(LatticeDeformPerformanceTest, performance_no_dvert_100000)
106{
107 const int32_t num_items = 100000;
108 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
109 RandomNumberGenerator rng;
110 test_lattice_deform_init(&ctx, &rng, num_items);
111 test_lattice_deform(&ctx, num_items);
112 test_lattice_deform_free(&ctx);
113}
114TEST_F(LatticeDeformPerformanceTest, performance_no_dvert_1000000)
115{
116 const int32_t num_items = 1000000;
117 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
118 RandomNumberGenerator rng;
119 test_lattice_deform_init(&ctx, &rng, num_items);
120 test_lattice_deform(&ctx, num_items);
121 test_lattice_deform_free(&ctx);
122}
123TEST_F(LatticeDeformPerformanceTest, performance_no_dvert_10000000)
124{
125 const int32_t num_items = 10000000;
126 LatticeDeformTestContext ctx = {dna::shallow_zero_initialize()};
127 RandomNumberGenerator rng;
128 test_lattice_deform_init(&ctx, &rng, num_items);
129 test_lattice_deform(&ctx, num_items);
130 test_lattice_deform_free(&ctx);
131}
132
133} // namespace blender::bke::tests
134#endif
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
TEST_F(FFmpegTest, libaom_av1_AV_PIX_FMT_YUV420P)
#define index(i)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str)
Definition mallocn.cc:129
internal::ShallowZeroInitializeTag shallow_zero_initialize()
Definition DNA_defs.h:159
IDTypeInfo IDType_ID_ME
char * STRNCPY(char(&dst)[N], const char *src)
IDTypeInfo IDType_ID_LT
Definition lattice.cc:167
void BKE_lattice_deform_data_eval_co(LatticeDeformData *lattice_deform_data, float co[3], float weight)
IDTypeInfo IDType_ID_OB
Definition object.cc:1269
unsigned int uint32_t
Definition BKE_text.h:81
void BKE_lattice_deform_data_destroy(LatticeDeformData *lattice_deform_data)
LatticeDeformData * BKE_lattice_deform_data_create(const Object *oblatt, const Object *ob) ATTR_WARN_UNUSED_RESULT
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
IDTypeInitDataFunction init_data
IDTypeFreeDataFunction free_data