67 .pixels = calloc((
size_t)
W *
H * 4,
sizeof(
float)),
68 .external_alloc =
TRUE };
70 .pixels = calloc((
size_t)
W *
H,
sizeof(
float)),
71 .external_alloc =
TRUE };
72 assert_non_null(
p->patch.pixels);
73 assert_non_null(
p->mask.pixels);
78 free(
p->patch.pixels);
84 const float opacity,
const float radius,
const float step,
85 const float sprinkles)
87 for(
int i = 0;
i < count;
i++)
90 .x = 24.0f + step * (float)
i,
95 .sample_spacing = step,
96 .sample_opacity_scale = 1.0f,
99 .sprinkles = sprinkles,
100 .sprinkle_size = 3.0f,
101 .sprinkle_coarseness = 0.5f,
103 .
color = { 0.8f, 0.4f, 0.2f, 1.0f },
114 const float opacity,
const float radius,
const float step)
123 assert_non_null(runtime);
124 for(
int i = 0;
i < count;
i++)
134 float *transmittance = calloc((
size_t)
W *
H,
sizeof(
float));
135 float *
noise = calloc((
size_t)
W *
H,
sizeof(
float));
136 assert_non_null(transmittance);
137 assert_non_null(
noise);
146 for(
size_t i = 0;
i <
n;
i++)
148 const double d = fabs((
double)a[
i] - (
double)b[
i]);
149 if(
d > worst) worst =
d;
154static void _compare_tex(
const int mode,
const float opacity,
const float radius,
const float step,
155 const int count,
const float sprinkles)
158 assert_non_null(dabs);
179 double painted = 0.0;
181 assert_true(painted > 1.0);
183 print_message(
"mode=%d opacity=%.2f r=%.1f step=%.2f n=%d sprinkles=%.2f -> "
184 "max |dpixel|=%.3e max |dmask|=%.3e\n",
185 mode, opacity, radius, step, count, sprinkles, pixel_diff, mask_diff);
191 assert_true(pixel_diff < 1e-5);
192 assert_true(mask_diff < 1e-5);
199static void _compare(
const int mode,
const float opacity,
const float radius,
const float step,
268 dabs[3].
color[1] = 0.9f;
304 const int count = 32;
306 assert_non_null(dabs);
315 omp_set_num_threads(1);
319 omp_set_num_threads(saved > 1 ? saved : 8);
323 omp_set_num_threads(saved);
349 for(
size_t i = 0;
i < px;
i++) mask[
i] = 0.0f;
354 const int count = 32;
355 const float radius = 64.0f;
356 const int plane = 512;
359 assert_non_null(dabs);
360 for(
int i = 0;
i < count;
i++)
363 .x = 160.0f + (float)
i, .y = 256.0f, .radius = radius, .dir_x = 1.0f, .dir_y = 0.0f,
364 .sample_spacing = 1.0f, .sample_opacity_scale = 1.0f, .opacity = 1.0f, .flow = 1.0f,
365 .sprinkles = sprinkles, .sprinkle_size = 3.0f, .sprinkle_coarseness = 0.5f, .hardness = 0.5f,
373 const size_t px = (size_t)plane * plane;
374 float *rgba = calloc(px * 4,
sizeof(
float));
375 float *mask = calloc(px,
sizeof(
float));
376 float *transmittance = calloc(px,
sizeof(
float));
377 float *
noise = calloc(px,
sizeof(
float));
378 assert_non_null(rgba);
379 assert_non_null(mask);
380 assert_non_null(transmittance);
381 assert_non_null(
noise);
384 .external_alloc =
TRUE };
386 .external_alloc =
TRUE };
388 const int rounds = 40;
389 struct timespec t0, t1;
392 assert_non_null(runtime);
393 clock_gettime(CLOCK_MONOTONIC, &t0);
394 for(
int r = 0;
r < rounds;
r++)
397 for(
int i = 0;
i < count;
i++)
400 clock_gettime(CLOCK_MONOTONIC, &t1);
401 const double serial_ms = ((
double)(t1.tv_sec - t0.tv_sec) * 1e3
402 + (
double)(t1.tv_nsec - t0.tv_nsec) / 1e6) / (
double)rounds;
407 clock_gettime(CLOCK_MONOTONIC, &t0);
408 for(
int r = 0;
r < rounds;
r++)
413 clock_gettime(CLOCK_MONOTONIC, &t1);
414 const double batch_ms = ((
double)(t1.tv_sec - t0.tv_sec) * 1e3
415 + (
double)(t1.tv_nsec - t0.tv_nsec) / 1e6) / (
double)rounds;
417 print_message(
"one heartbeat batch, r=%.0f spacing=1 dabs=%d sprinkles=%.2f: "
418 "per-dab %.3f ms, batch %.3f ms (%.1fx)\n",
419 radius, count, sprinkles, serial_ms, batch_ms, serial_ms / fmax(batch_ms, 1e-9));
435int main(
int argc,
char *argv[])
437 const struct CMUnitTest tests[] = {
447 return cmocka_run_group_tests(tests, NULL, NULL);
Dab-level brush rasterization API for drawlayer.
@ DT_DRAWLAYER_BRUSH_MODE_ERASE
@ DT_DRAWLAYER_BRUSH_MODE_PAINT
@ DT_DRAWLAYER_BRUSH_MODE_BLUR
@ DT_DRAWLAYER_BRUSH_MODE_SMUDGE
@ DT_DRAWLAYER_BRUSH_SHAPE_LINEAR
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
memcpy(roundtrip, origin, sizeof(roundtrip))
gboolean dt_drawlayer_brush_batch_is_uniform(const dt_drawlayer_brush_dab_t *dabs, const guint count, dt_drawlayer_brush_batch_t *out)
Decide whether a run of dabs can take the batch path, and describe it if so.
gboolean dt_drawlayer_brush_rasterize(const dt_drawlayer_cache_patch_t *sample_patch, dt_drawlayer_cache_patch_t *patch, const float scale, const dt_drawlayer_brush_dab_t *dab, const float sample_opacity_scale, dt_drawlayer_cache_patch_t *stroke_mask, dt_drawlayer_paint_stroke_t *runtime_private)
Public dab rasterization entry point.
gboolean dt_drawlayer_brush_rasterize_batch(const dt_drawlayer_brush_batch_t *batch, dt_drawlayer_cache_patch_t *patch, const float scale, dt_drawlayer_cache_patch_t *stroke_mask, float *const transmittance, float *const noise_scratch, dt_drawlayer_damaged_rect_t *batch_damage)
Rasterize a whole batch in two passes: accumulate transmittance, then composite once.
Patch/cache helpers for drawlayer process and preview buffers.
void dt_drawlayer_paint_runtime_private_destroy(dt_drawlayer_paint_stroke_t **state)
Destroy stroke runtime payload and null pointer.
dt_drawlayer_paint_stroke_t * dt_drawlayer_paint_runtime_private_create(void)
Allocate stroke runtime payload object used by paint+brush internals.
Stroke-level path sampling and runtime-state API for drawlayer.
@ DT_DRAWLAYER_PAINT_STROKE_MIDDLE
@ DT_DRAWLAYER_PAINT_STROKE_FIRST
#define omp_get_max_threads()
const float uint32_t state[4]
A run of dabs that share everything the batch composite needs to be a single step.
Fully resolved input dab descriptor.
Generic float RGBA patch stored either in malloc memory or pixel cache.
Mutable stroke runtime state owned by worker/backend code.
dt_drawlayer_cache_patch_t mask
dt_drawlayer_cache_patch_t patch
typedef double((*spd)(unsigned long int wavelength, double TempK))
static void _plane_free(plane_t *p)
static void test_batch_matches_serial_paint_capped(void **state)
The cap binds mid-batch: opacity well below 1 with many overlapping dabs.
static void _run_serial(plane_t *p, const dt_drawlayer_brush_dab_t *dabs, const int count)
Run the reference path: one dt_drawlayer_brush_rasterize per dab, in order.
static void _compare_tex(const int mode, const float opacity, const float radius, const float step, const int count, const float sprinkles)
static void test_batch_is_thread_count_independent(void **state)
The batch result must not depend on the thread count.
static void _build_dabs(dt_drawlayer_brush_dab_t *dabs, const int count, const int mode, const float opacity, const float radius, const float step)
static void test_report_batch_speedup(void **state)
static void test_batch_matches_serial_erase(void **state)
static void _clear_mask(float *const mask, const size_t px)
Time both paths on the shipped regime, so the speedup is measured and not derived.
static void _build_dabs_tex(dt_drawlayer_brush_dab_t *dabs, const int count, const int mode, const float opacity, const float radius, const float step, const float sprinkles)
A short stroke of overlapping dabs, uniform in everything the gate tests.
static void _compare(const int mode, const float opacity, const float radius, const float step, const int count)
static double _max_abs_diff(const float *a, const float *b, const size_t n)
static void test_batch_matches_serial_sprinkles(void **state)
Texture on: the batch shares ONE sprinkle field across every dab.
static void _plane_init(plane_t *p)
static void test_batch_matches_serial_paint_dense(void **state)
Heavy overlap, the shipped regime: spacing far below the diameter.
static void _run_batch(plane_t *p, const dt_drawlayer_brush_dab_t *dabs, const int count)
static void test_batch_matches_serial_paint_sparse(void **state)
Sparse dabs, barely overlapping.
static void _report_speedup(const float sprinkles)
static void test_gate_refuses_non_uniform(void **state)
The gate must refuse everything the closed form is not derived for.