From 7f6b23c27cbc83568e208b20b2570a10b8389b77 Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Fri, 1 Dec 2023 23:22:42 +0200 Subject: [PATCH] Remove useless thread global --- src/renderer/renderer.c | 22 ++++++++-------------- src/renderer/renderer.h | 2 -- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/renderer/renderer.c b/src/renderer/renderer.c index e87bded6..3184fdf8 100644 --- a/src/renderer/renderer.c +++ b/src/renderer/renderer.c @@ -286,8 +286,6 @@ void *renderThreadInteractive(void *arg) { struct timeval timer = {0}; - threadState->completedSamples = 1; - while (tile && r->state.rendering) { long total_us = 0; @@ -325,7 +323,6 @@ void *renderThreadInteractive(void *arg) { //For performance metrics total_us += timer_get_us(timer); threadState->totalSamples++; - threadState->completedSamples++; //Pause rendering when bool is set while (threadState->paused && !r->state.render_aborted) { timer_sleep_ms(100); @@ -335,7 +332,6 @@ void *renderThreadInteractive(void *arg) { //Tile has finished rendering, get a new one and start rendering it. tile->state = finished; threadState->currentTile = NULL; - threadState->completedSamples = r->state.finishedPasses; tile = tile_next_interactive(r, threadState->tiles); threadState->currentTile = tile; } @@ -367,20 +363,19 @@ void *renderThread(void *arg) { struct render_tile *tile = tile_next(threadState->tiles); threadState->currentTile = tile; - struct timeval timer = {0}; - threadState->completedSamples = 1; + struct timeval timer = { 0 }; + size_t samples = 1; while (tile && r->state.rendering) { long total_us = 0; - long samples = 0; - while (threadState->completedSamples < r->prefs.sampleCount + 1 && r->state.rendering) { + while (samples < r->prefs.sampleCount + 1 && r->state.rendering) { timer_start(&timer); for (int y = tile->end.y - 1; y > tile->begin.y - 1; --y) { for (int x = tile->begin.x; x < tile->end.x; ++x) { if (r->state.render_aborted) goto exit; uint32_t pixIdx = (uint32_t)(y * image->width + x); - initSampler(sampler, SAMPLING_STRATEGY, threadState->completedSamples - 1, r->prefs.sampleCount, pixIdx); + initSampler(sampler, SAMPLING_STRATEGY, samples - 1, r->prefs.sampleCount, pixIdx); struct color output = textureGetPixel(buf, x, y, false); struct color sample = path_trace(cam_get_ray(cam, x, y, sampler), r->scene, r->prefs.bounces, sampler); @@ -389,9 +384,9 @@ void *renderThread(void *arg) { nan_clamp(&sample, &output); //And process the running average - output = colorCoef((float)(threadState->completedSamples - 1), output); + output = colorCoef((float)(samples - 1), output); output = colorAdd(output, sample); - float t = 1.0f / threadState->completedSamples; + float t = 1.0f / samples; output = colorCoef(t, output); //Store internal render buffer (float precision) @@ -405,10 +400,9 @@ void *renderThread(void *arg) { } } //For performance metrics - samples++; total_us += timer_get_us(timer); threadState->totalSamples++; - threadState->completedSamples++; + samples++; tile->completed_samples++; //Pause rendering when bool is set while (threadState->paused && !r->state.render_aborted) { @@ -419,7 +413,7 @@ void *renderThread(void *arg) { //Tile has finished rendering, get a new one and start rendering it. tile->state = finished; threadState->currentTile = NULL; - threadState->completedSamples = 1; + samples = 1; tile = tile_next(threadState->tiles); threadState->currentTile = tile; } diff --git a/src/renderer/renderer.h b/src/renderer/renderer.h index 3d91cbf2..5cd6e3c4 100644 --- a/src/renderer/renderer.h +++ b/src/renderer/renderer.h @@ -24,7 +24,6 @@ struct worker { //Share info about the current tile with main thread struct tile_set *tiles; struct render_tile *currentTile; - size_t completedSamples; //FIXME: Remove uint64_t totalSamples; long avg_per_sample_us; //Single tile pass @@ -46,7 +45,6 @@ struct state { bool saveImage; struct worker_arr workers; struct render_client_arr clients; - struct cr_renderer_callbacks cb; };