Skip to content

Commit

Permalink
Rename prefs.threadCount -> prefs.thread
Browse files Browse the repository at this point in the history
Also a bunch of int -> size_t
  • Loading branch information
vkoskiv committed Nov 2, 2023
1 parent 4ba7600 commit 6e6577e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/api/c-ray.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ void cr_get_render_order(void) {
}

void cr_set_thread_count(struct renderer *r, int thread_count, int is_from_system) {
r->prefs.threadCount = thread_count;
r->prefs.threads = thread_count;
r->prefs.fromSystem = is_from_system;
cr_restart_interactive();
}

int cr_get_thread_count(struct renderer *r) {
return r->prefs.threadCount;
return r->prefs.threads;
}

void cr_set_sample_count(struct renderer *r, int sample_count) {
Expand Down Expand Up @@ -215,7 +215,7 @@ void cr_start_renderer(struct renderer *r) {
r->sceneCache = NULL;
cache_destroy(r->state.file_cache);
}
if (!r->state.clients && r->prefs.threadCount == 0) {
if (!r->state.clients && r->prefs.threads == 0) {
logr(warning, "You specified 0 local threads, and no network clients were found. Nothing to do.\n");
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/datatypes/scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int loadScene(struct renderer *r, char *input) {
cJSON_Delete(json);
logr(debug, "Deleting done\n");

if (r->prefs.threadCount > 0) {
if (r->prefs.threads > 0) {
// Do some pre-render preparations
// Compute BVH acceleration structures for all objects in the scene
compute_accels(r->scene->meshes, r->scene->meshCount);
Expand Down Expand Up @@ -241,10 +241,10 @@ int loadScene(struct renderer *r, char *input) {
r->state.uiBuffer = newTexture(char_p, cam.width, cam.height, 4);

//Print a useful warning to user if the defined tile size results in less renderThreads
if (r->state.tileCount < r->prefs.threadCount) {
if (r->state.tileCount < r->prefs.threads) {
logr(warning, "WARNING: Rendering with a less than optimal thread count due to large tile size!\n");
logr(warning, "Reducing thread count from %i to %i\n", r->prefs.threadCount, r->state.tileCount);
r->prefs.threadCount = r->state.tileCount;
logr(warning, "Reducing thread count from %zu to %zu\n", r->prefs.threads, r->state.tileCount);
r->prefs.threads = r->state.tileCount;
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/datatypes/tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct renderTile *nextTile(struct renderer *r) {
tile->tileNum = r->state.finishedTileCount++;
} else {
// If a network worker disappeared during render, finish those tiles locally here at the end
for (int t = 0; t < r->state.tileCount; ++t) {
for (size_t t = 0; t < r->state.tileCount; ++t) {
if (r->state.renderTiles[t].state == rendering && r->state.renderTiles[t].networkRenderer) {
r->state.renderTiles[t].networkRenderer = false;
tile = &r->state.renderTiles[t];
Expand Down
26 changes: 13 additions & 13 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ struct texture *renderFrame(struct renderer *r) {
struct camera camera = r->scene->cameras[r->prefs.selected_camera];
struct texture *output = newTexture(char_p, camera.width, camera.height, 3);

logr(info, "Starting c-ray renderer for frame %i\n", r->prefs.imgCount);
logr(info, "Starting c-ray renderer for frame %zu\n", r->prefs.imgCount);

// Verify we have at least a single thread rendering.
if (r->state.clientCount == 0 && r->prefs.threadCount < 1) {
if (r->state.clientCount == 0 && r->prefs.threads < 1) {
logr(warning, "No network render workers, setting thread count to 1\n");
r->prefs.threadCount = 1;
r->prefs.threads = 1;
}

bool threadsReduced = getSysCores() > r->prefs.threadCount;
bool threadsReduced = (size_t)getSysCores() > r->prefs.threads;

logr(info, "Rendering at %s%i%s x %s%i%s\n", KWHT, camera.width, KNRM, KWHT, camera.height, KNRM);
logr(info, "Rendering %s%i%s samples with %s%i%s bounces.\n", KBLU, r->prefs.sampleCount, KNRM, KGRN, r->prefs.bounces, KNRM);
logr(info, "Rendering %s%zu%s samples with %s%zu%s bounces.\n", KBLU, r->prefs.sampleCount, KNRM, KGRN, r->prefs.bounces, KNRM);
logr(info, "Rendering with %s%zu%s%s local thread%s.\n",
KRED,
r->prefs.fromSystem && !threadsReduced ? r->prefs.threadCount - 2 : r->prefs.threadCount,
r->prefs.fromSystem && !threadsReduced ? r->prefs.threads - 2 : r->prefs.threads,
r->prefs.fromSystem && !threadsReduced ? "+2" : "",
KNRM,
PLURAL(r->prefs.threadCount));
PLURAL(r->prefs.threads));

logr(info, "Pathtracing%s...\n", isSet("interactive") ? " iteratively" : "");

Expand Down Expand Up @@ -103,19 +103,19 @@ struct texture *renderFrame(struct renderer *r) {
if (interactive && !r->state.clients) localRenderThread = renderThreadInteractive;

// Local render threads + one thread for every client
size_t total_thread_count = r->prefs.threadCount + (int)r->state.clientCount;
size_t total_thread_count = r->prefs.threads + (int)r->state.clientCount;
r->state.workers = calloc(total_thread_count, sizeof(*r->state.workers));

//Create & boot workers (Nonblocking)
for (size_t t = 0; t < total_thread_count; ++t) {
r->state.workers[t] = (struct worker){
.client = t > r->prefs.threadCount - 1? &r->state.clients[t - r->prefs.threadCount] : NULL,
.client = t > r->prefs.threads - 1? &r->state.clients[t - r->prefs.threads] : NULL,
.thread_complete = false,
.renderer = r,
.output = output,
.cam = &camera,
.thread = (struct cr_thread){
.thread_fn = t > r->prefs.threadCount - 1 ? networkRenderThread : localRenderThread,
.thread_fn = t > r->prefs.threads - 1 ? networkRenderThread : localRenderThread,
.user_data = &r->state.workers[t]
}
};
Expand Down Expand Up @@ -156,9 +156,9 @@ struct texture *renderFrame(struct renderer *r) {
}
uint64_t remainingTileSamples = (r->state.tileCount * r->prefs.sampleCount) - completedSamples;
uint64_t msecTillFinished = 0.001f * (avgTimePerTilePass * remainingTileSamples);
float sps = (1000000.0f / usPerRay) * (r->prefs.threadCount + remoteThreads);
float sps = (1000000.0f / usPerRay) * (r->prefs.threads + remoteThreads);
char rem[64];
smartTime((msecTillFinished) / (r->prefs.threadCount + remoteThreads), rem);
smartTime((msecTillFinished) / (r->prefs.threads + remoteThreads), rem);
logr(info, "[%s%.0f%%%s] μs/path: %.02f, etf: %s, %.02lfMs/s %s \r",
KBLU,
interactive ? ((double)r->state.finishedPasses / (double)r->prefs.sampleCount) * 100.0 :
Expand Down Expand Up @@ -348,7 +348,7 @@ void *renderThread(void *arg) {
static struct prefs defaultPrefs() {
return (struct prefs){
.tileOrder = renderOrderFromMiddle,
.threadCount = getSysCores() + 2,
.threads = getSysCores() + 2,
.fromSystem = true,
.sampleCount = 25,
.bounces = 20,
Expand Down
20 changes: 10 additions & 10 deletions src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct worker {

//Share info about the current tile with main thread
struct renderTile *currentTile;
int completedSamples;
size_t completedSamples;

uint64_t totalSamples;

Expand All @@ -37,18 +37,18 @@ struct worker {
/// Renderer state data
struct state {
struct renderTile *renderTiles; //Array of renderTiles to render
int tileCount; //Total amount of render tiles
int finishedTileCount;
int finishedPasses; // For interactive mode
size_t tileCount; //Total amount of render tiles
size_t finishedTileCount;
size_t finishedPasses; // For interactive mode
struct texture *renderBuffer; //float-precision buffer for multisampling
struct texture *uiBuffer; //UI element buffer
int activeThreads; //Amount of threads currently rendering
size_t activeThreads; //Amount of threads currently rendering
bool rendering;
bool render_aborted; //SDL listens for X key pressed, which sets this
bool saveImage;
unsigned long long avgTileTime; //Used for render duration estimation (milliseconds)
float avgSampleRate; //In raw single pixel samples per second. (Used for benchmarking)
int timeSampleCount; //Used for render duration estimation, amount of time samples captured
size_t timeSampleCount; //Used for render duration estimation, amount of time samples captured
struct worker *workers;
struct renderClient *clients;
size_t clientCount;
Expand All @@ -69,10 +69,10 @@ struct sdl_prefs {
struct prefs {
enum renderOrder tileOrder;

size_t threadCount; //Amount of threads to render with
size_t threads; //Amount of threads to render with
bool fromSystem; //Did we ask the system for thread count
int sampleCount;
int bounces;
size_t sampleCount;
size_t bounces;
unsigned tileWidth;
unsigned tileHeight;

Expand All @@ -84,7 +84,7 @@ struct prefs {
char *imgFilePath;
char *imgFileName;
char *assetPath;
int imgCount;
size_t imgCount;
enum fileType imgType;
bool useClustering;
bool isWorker;
Expand Down
12 changes: 6 additions & 6 deletions src/utils/loaders/sceneloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ void parsePrefs(struct prefs *prefs, const cJSON *data) {
if (threads) {
if (cJSON_IsNumber(threads)) {
if (threads->valueint > 0) {
prefs->threadCount = threads->valueint;
prefs->threads = threads->valueint;
prefs->fromSystem = false;
} else {
prefs->threadCount = getSysCores() + 2;
prefs->threads = getSysCores() + 2;
prefs->fromSystem = true;
}
} else {
Expand Down Expand Up @@ -334,10 +334,10 @@ void parsePrefs(struct prefs *prefs, const cJSON *data) {

// Now check and apply potential CLI overrides.
if (isSet("thread_override")) {
int threads = intPref("thread_override");
if (prefs->threadCount != threads) {
logr(info, "Overriding thread count to %i\n", threads);
prefs->threadCount = threads;
size_t threads = intPref("thread_override");
if (prefs->threads != threads) {
logr(info, "Overriding thread count to %zu\n", threads);
prefs->threads = threads;
prefs->fromSystem = false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/protocol/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct workerThreadState {
struct renderer *renderer;
bool threadComplete;
uint64_t totalSamples;
int completedSamples;
size_t completedSamples;
long avgSampleTime;
};

Expand Down Expand Up @@ -94,7 +94,7 @@ static cJSON *receiveScene(const cJSON *json) {
// Stash in our capabilities here
//TODO: Maybe some performance value in here, so the master knows how much work to assign?
// For now just report back how many threads we've got available.
cJSON_AddNumberToObject(resp, "threadCount", g_worker_renderer->prefs.threadCount);
cJSON_AddNumberToObject(resp, "threadCount", g_worker_renderer->prefs.threads);
return resp;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ static cJSON *startRender(int connectionSocket) {
g_worker_renderer->state.saveImage = false;
logr(info, "Starting network render job\n");

size_t threadCount = g_worker_renderer->prefs.threadCount;
size_t threadCount = g_worker_renderer->prefs.threads;
struct cr_thread *worker_threads = calloc(threadCount, sizeof(*worker_threads));
struct workerThreadState *workerThreadStates = calloc(threadCount, sizeof(*workerThreadStates));

Expand Down Expand Up @@ -256,10 +256,10 @@ static cJSON *startRender(int connectionSocket) {
while (g_worker_renderer->state.rendering) {

// Gather and send statistics to master node
for(int t = 0; t < g_worker_renderer->prefs.threadCount; ++t) {
for (size_t t = 0; t < g_worker_renderer->prefs.threads; ++t) {
avgSampleTime += workerThreadStates[t].avgSampleTime;
}
avgTimePerTilePass += avgSampleTime / g_worker_renderer->prefs.threadCount;
avgTimePerTilePass += avgSampleTime / g_worker_renderer->prefs.threads;
avgTimePerTilePass /= ctr++;

// Send stats about 1x/s
Expand Down
8 changes: 4 additions & 4 deletions src/utils/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void getKeyboardInput(struct renderer *r) {
r->state.saveImage = false;
}
if (event.key.keysym.sym == SDLK_p) {
for (size_t i = 0; i < r->prefs.threadCount; ++i) {
for (size_t i = 0; i < r->prefs.threads; ++i) {
r->state.workers[i].paused = !r->state.workers[i].paused;
}
}
Expand Down Expand Up @@ -320,7 +320,7 @@ static void clearProgBar(struct renderer *r, struct renderTile temp) {
around that.
*/
static void drawProgressBars(struct renderer *r) {
for (size_t t = 0; t < r->prefs.threadCount; ++t) {
for (size_t t = 0; t < r->prefs.threads; ++t) {
if (r->state.workers[t].currentTile) {
struct renderTile *temp = r->state.workers[t].currentTile;
int completedSamples = r->state.workers[t].completedSamples;
Expand All @@ -339,7 +339,7 @@ static void drawProgressBars(struct renderer *r) {
}
}
}
for (int i = 0; i < r->state.tileCount; ++i) {
for (size_t i = 0; i < r->state.tileCount; ++i) {
if (r->state.renderTiles[i].state == finished) {
clearProgBar(r, r->state.renderTiles[i]);
}
Expand Down Expand Up @@ -380,7 +380,7 @@ static void drawFrame(struct texture *buf, struct renderTile tile, struct color

static void updateFrames(struct renderer *r) {
if (r->prefs.tileWidth < 8 || r->prefs.tileHeight < 8) return;
for (int i = 0; i < r->state.tileCount; ++i) {
for (size_t i = 0; i < r->state.tileCount; ++i) {
struct renderTile tile = r->state.renderTiles[i];
struct color c = tile.state == rendering ? g_frame_color : g_clear_color;
drawFrame(r->state.uiBuffer, tile, c);
Expand Down

0 comments on commit 6e6577e

Please sign in to comment.