From 1523c065c8d1a25417c08b45fc299d6743cd7fc3 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 28 Feb 2015 16:25:00 +0100 Subject: Drop progress printing from rendering thread --- flam3.c | 9 --- flam3.h | 2 - main.c | 6 +- palettes.c | 4 +- private.h | 33 ----------- rect.c | 181 ++++++++++--------------------------------------------------- rect.h | 4 +- 7 files changed, 36 insertions(+), 203 deletions(-) diff --git a/flam3.c b/flam3.c index 38d41b1..3bb89cd 100644 --- a/flam3.c +++ b/flam3.c @@ -3080,12 +3080,3 @@ int flam3_estimate_bounding_box(flam3_genome *cp, double eps, int nsamples, return(bv); } -int flam3_render(flam3_frame *spec, void *out, - stat_struct *stats) { - - int retval; - - retval = render_rectangle (spec, out, stats); - return(retval); -} - diff --git a/flam3.h b/flam3.h index 3c7b860..3c17ffd 100644 --- a/flam3.h +++ b/flam3.h @@ -182,7 +182,6 @@ typedef struct { double badvals; long int num_iters; - int render_seconds; } stat_struct; @@ -571,7 +570,6 @@ typedef struct { double pixel_aspect_ratio; /* width over height of each pixel */ flam3_genome *genomes; int ngenomes; - int verbose; int bytes_per_channel; int earlyclip; double time; diff --git a/main.c b/main.c index 63384e3..931fee0 100644 --- a/main.c +++ b/main.c @@ -25,6 +25,7 @@ #include "random.h" #include "private.h" #include "img.h" +#include "rect.h" #define streq(a,b) (strcmp (a, b) == 0) @@ -32,7 +33,6 @@ const char *argp_program_version = "vlam3-pre"; typedef struct { - bool verbose; unsigned int threads, bpc, quality; float scale; } render_arguments; @@ -118,7 +118,6 @@ static void do_render (const render_arguments * const arguments) { flam3_frame f; f.genomes = genome; f.ngenomes = 1; - f.verbose = arguments->verbose; f.time = 0.0; f.pixel_aspect_ratio = 1.0; f.progress = 0; @@ -133,7 +132,7 @@ static void do_render (const render_arguments * const arguments) { void *image = (void *) calloc(this_size, sizeof(char)); stat_struct stats; - if (flam3_render (&f, image, &stats)) { + if (render_parallel (&f, image, &stats)) { fprintf(stderr,"error rendering image: aborting.\n"); exit(1); } @@ -512,7 +511,6 @@ int main (int argc, char **argv) { .bpc = 8, .scale = 1.0, .quality = 100, - .verbose = true, }; argp_parse (&argp, argc, argv, 0, NULL, &arguments); diff --git a/palettes.c b/palettes.c index 77f3142..f73bd24 100644 --- a/palettes.c +++ b/palettes.c @@ -18,6 +18,7 @@ #include "private.h" #include "palettes.h" +#include "rect.h" lib_palette *the_palettes = NULL; int npalettes; @@ -372,7 +373,6 @@ static double try_colors(flam3_genome *g, int color_resolution) { // g->pixels_per_unit = 50; f.bytes_per_channel=1; - f.verbose = 0; f.genomes = g; f.ngenomes = 1; f.earlyclip = 1; @@ -382,7 +382,7 @@ static double try_colors(flam3_genome *g, int color_resolution) { f.sub_batch_size = 10000; image = (unsigned char *) calloc(g->width * g->height, 3); - if (flam3_render(&f, image, &stats)) { + if (render_parallel (&f, image, &stats)) { fprintf(stderr,"Error rendering test image for trycolors. Aborting.\n"); return(-1); } diff --git a/private.h b/private.h index e86c43f..ff0d1c1 100644 --- a/private.h +++ b/private.h @@ -43,39 +43,6 @@ #define max_specified_vars (100) #define vlen(x) (sizeof(x)/sizeof(*x)) -/* Structures for passing parameters to iteration threads */ -typedef struct { - unsigned short *xform_distrib; /* Distribution of xforms based on weights */ - flam3_frame *spec; /* Frame contains timing information */ - double bounds[4]; /* Corner coords of viewable area */ - double2 rot[3]; /* Rotation transformation */ - double size[2]; - int width, height; /* buffer width/height */ - double ws0, wb0s0, hs1, hb1s1; /* shortcuts for indexing */ - flam3_palette_entry *dmap; /* palette */ - double color_scalar; /* <1.0 if non-uniform motion blur is set */ - double4 *buckets; /* Points to the first accumulator */ - double badvals; /* accumulates all badvalue resets */ - double batch_size; - int aborted, cmap_size; - time_t *progress_timer; - time_t *progress_timer_history; - double *progress_history; - int *progress_history_mark; - /* mutex for bucket accumulator */ - pthread_mutex_t bucket_mutex; - -} flam3_iter_constants; - - - -typedef struct { - flam3_genome cp; /* Full copy of genome for use by the thread */ - int first_thread; - int timer_initialize; - flam3_iter_constants *fic; /* Constants for render */ -} flam3_thread_helper; - double flam3_sinc(double x); #define flam3_mitchell_b (1.0 / 3.0) diff --git a/rect.c b/rect.c index e2197f4..5432e53 100644 --- a/rect.c +++ b/rect.c @@ -23,11 +23,38 @@ #include "variations.h" #include "palettes.h" #include "math.h" +#include "rect.h" /* allow this many iterations for settling into attractor */ #define FUSE_27 15 #define FUSE_28 100 +/* Structures for passing parameters to iteration threads */ +typedef struct { + unsigned short *xform_distrib; /* Distribution of xforms based on weights */ + flam3_frame *spec; /* Frame contains timing information */ + double bounds[4]; /* Corner coords of viewable area */ + double2 rot[3]; /* Rotation transformation */ + double size[2]; + int width, height; /* buffer width/height */ + double ws0, wb0s0, hs1, hb1s1; /* shortcuts for indexing */ + flam3_palette_entry *dmap; /* palette */ + double color_scalar; /* <1.0 if non-uniform motion blur is set */ + double4 *buckets; /* Points to the first accumulator */ + double badvals; /* accumulates all badvalue resets */ + double batch_size; + int aborted, cmap_size; + /* mutex for bucket accumulator */ + pthread_mutex_t bucket_mutex; +} flam3_iter_constants; + +typedef struct { + flam3_genome cp; /* Full copy of genome for use by the thread */ + flam3_iter_constants *fic; /* Constants for render */ + /* thread number */ + size_t i; +} flam3_thread_helper; + /* Lookup color [0,1] */ static double4 color_palette_lookup (const double color, @@ -68,11 +95,9 @@ static void *iter_thread(void *fth) { int j; flam3_thread_helper *fthp = (flam3_thread_helper *)fth; flam3_iter_constants *ficp = fthp->fic; - struct timespec pauset; int SBS = ficp->spec->sub_batch_size; int fuse; int cmap_size = ficp->cmap_size; - double eta = 0.0; double4 *iter_storage; randctx rc; @@ -85,112 +110,11 @@ static void *iter_thread(void *fth) { fuse = (ficp->spec->earlyclip) ? FUSE_28 : FUSE_27; - pauset.tv_sec = 0; - pauset.tv_nsec = 100000000; - - - if (fthp->timer_initialize) { - *(ficp->progress_timer) = 0; - memset(ficp->progress_timer_history,0,64*sizeof(time_t)); - memset(ficp->progress_history,0,64*sizeof(double)); - *(ficp->progress_history_mark) = 0; - } - for (sub_batch = 0; sub_batch < ficp->batch_size; sub_batch+=SBS) { int sub_batch_size, badcount; - time_t newt = time(NULL); /* sub_batch is double so this is sketchy */ sub_batch_size = (sub_batch + SBS > ficp->batch_size) ? (ficp->batch_size - sub_batch) : SBS; - - if (fthp->first_thread && newt != *(ficp->progress_timer)) { - double percent = 100.0 * - ((((sub_batch / (double) ficp->batch_size)))); - int old_mark = 0; - int ticker; - - if (ficp->spec->verbose) - fprintf(stderr, "\rchaos: %5.1f%%", percent); - - *(ficp->progress_timer) = newt; - if (ficp->progress_timer_history[*(ficp->progress_history_mark)] && - ficp->progress_history[*(ficp->progress_history_mark)] < percent) - old_mark = *(ficp->progress_history_mark); - - if (percent > 0) { - eta = (100 - percent) * (*(ficp->progress_timer) - ficp->progress_timer_history[old_mark]) - / (percent - ficp->progress_history[old_mark]); - - if (ficp->spec->verbose) { - ticker = (*(ficp->progress_timer)&1)?':':'.'; - if (eta < 1000) - ticker = ':'; - if (eta > 100) - fprintf(stderr, " ETA%c %.1f minutes", ticker, eta / 60); - else - fprintf(stderr, " ETA%c %ld seconds ", ticker, (long) ceil(eta)); - fprintf(stderr, " \r"); - fflush(stderr); - } - } - - ficp->progress_timer_history[*(ficp->progress_history_mark)] = *(ficp->progress_timer); - ficp->progress_history[*(ficp->progress_history_mark)] = percent; - *(ficp->progress_history_mark) = (*(ficp->progress_history_mark) + 1) % 64; - } - - /* Custom progress function */ - if (ficp->spec->progress) { - if (fthp->first_thread) { - - int rv; - - /* Recalculate % done, as the other calculation only updates once per second */ - double percent = 100.0 * - (((sub_batch / (double) ficp->batch_size))); - - rv = (*ficp->spec->progress)(ficp->spec->progress_parameter, percent, 0, eta); - - if (rv==2) { /* PAUSE */ - - time_t tnow = time(NULL); - time_t tend; - int lastpt; - - ficp->aborted = -1; - - do { - nanosleep(&pauset,NULL); - rv = (*ficp->spec->progress)(ficp->spec->progress_parameter, percent, 0, eta); - } while (rv==2); - - /* modify the timer history to compensate for the pause */ - tend = time(NULL)-tnow; - - ficp->aborted = 0; - - for (lastpt=0;lastpt<64;lastpt++) { - if (ficp->progress_timer_history[lastpt]) { - ficp->progress_timer_history[lastpt] += tend; - } - } - - } - - if (rv==1) { /* ABORT */ - ficp->aborted = 1; - goto done; - } - } else { - if (ficp->aborted<0) { - - do { - nanosleep(&pauset,NULL); - } while (ficp->aborted==-1); - } - if (ficp->aborted>0) goto done; - } - } /* Seed iterations */ const double4 start = (double4) { @@ -250,7 +174,6 @@ static void *iter_thread(void *fth) { } -done: free (iter_storage); return NULL; } @@ -283,8 +206,7 @@ static double4 clip (const double4 in, const double g, const double linrange, return newrgb; } -int render_rectangle(flam3_frame *spec, void *out, - stat_struct *stats) { +int render_parallel (flam3_frame *spec, void *out, stat_struct *stats) { long nbuckets; int i, j, k; double ppux=0, ppuy=0; @@ -296,8 +218,6 @@ int render_rectangle(flam3_frame *spec, void *out, double vibrancy = 0.0; double gamma = 0.0; int vib_gam_n = 0; - time_t progress_began=0; - int verbose = spec->verbose; flam3_genome cp; unsigned short *xform_distrib; flam3_iter_constants fic; @@ -305,17 +225,8 @@ int render_rectangle(flam3_frame *spec, void *out, pthread_attr_t pt_attr; pthread_t *myThreads=NULL; int thi; - time_t tstart,tend; int cmap_size; - /* Per-render progress timers */ - time_t progress_timer=0; - time_t progress_timer_history[64]; - double progress_history[64]; - int progress_history_mark = 0; - - tstart = time(NULL); - fic.badvals = 0; fic.aborted = 0; @@ -358,12 +269,6 @@ int render_rectangle(flam3_frame *spec, void *out, assert (ret == 0); assert (accumulate != NULL); - - if (verbose) { - fprintf(stderr, "chaos: "); - progress_began = time(NULL); - } - memset(accumulate, 0, sizeof(*accumulate) * nbuckets); @@ -447,29 +352,11 @@ int render_rectangle(flam3_frame *spec, void *out, fic.dmap = (flam3_palette_entry *)dmap; fic.buckets = (void *)buckets; - /* Need a timer per job */ - fic.progress_timer = &progress_timer; - fic.progress_timer_history = &(progress_timer_history[0]); - fic.progress_history = &(progress_history[0]); - fic.progress_history_mark = &progress_history_mark; - /* Initialize the thread helper structures */ for (thi = 0; thi < spec->nthreads; thi++) { - - - if (0==thi) { - - fth[thi].first_thread=1; - fth[thi].timer_initialize = 1; - - } else { - fth[thi].first_thread=0; - fth[thi].timer_initialize = 0; - } - fth[thi].fic = &fic; + fth[thi].i = thi; flam3_copy(&(fth[thi].cp),&cp); - } /* Let's make some threads */ @@ -497,7 +384,6 @@ int render_rectangle(flam3_frame *spec, void *out, free(xform_distrib); if (fic.aborted) { - if (verbose) fprintf(stderr, "\naborted!\n"); goto done; } @@ -535,12 +421,6 @@ int render_rectangle(flam3_frame *spec, void *out, } - if (verbose) { - fprintf(stderr, "\rchaos: 100.0%% took: %ld seconds \n", time(NULL) - progress_began); - fprintf(stderr, "filtering..."); - } - - /* filter the accumulation buffer down into the image */ if (1) { int x, y; @@ -613,9 +493,6 @@ int render_rectangle(flam3_frame *spec, void *out, free(fth); clear_cp(&cp,0); - tend = time(NULL); - stats->render_seconds = (int)(tend-tstart); - return(0); } diff --git a/rect.h b/rect.h index 7ec2a3b..3def002 100644 --- a/rect.h +++ b/rect.h @@ -1,4 +1,6 @@ #pragma once +#include + +int render_parallel (flam3_frame *spec, void *out, stat_struct *stats); -int render_rectangle(flam3_frame *spec, void *out, stat_struct *stats); -- cgit v1.2.3