Skip to content

Commit

Permalink
Remove useless thread global
Browse files Browse the repository at this point in the history
  • Loading branch information
vkoskiv committed Dec 1, 2023
1 parent 5a65430 commit 7f6b23c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
22 changes: 8 additions & 14 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ void *renderThreadInteractive(void *arg) {

struct timeval timer = {0};

threadState->completedSamples = 1;

while (tile && r->state.rendering) {
long total_us = 0;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +45,6 @@ struct state {
bool saveImage;
struct worker_arr workers;
struct render_client_arr clients;

struct cr_renderer_callbacks cb;
};

Expand Down

0 comments on commit 7f6b23c

Please sign in to comment.