Commit: c2387f35636136cf2a154805a70c3ff16b1aea8c
Parent: 34818d846b483c0f013258250bd902cd3e71f384
Author: Randy Palamar
Date: Fri, 21 Mar 2025 20:50:16 -0600
os: rename Platform -> OS
It is too much typing and the naming was inconsistent.
Diffstat:
M | beamformer.c | | | 45 | +++++++++++++++++++++------------------------ |
M | beamformer.h | | | 6 | +++--- |
M | main_linux.c | | | 28 | ++++++++++++++-------------- |
M | main_w32.c | | | 38 | +++++++++++++++++++------------------- |
M | os_unix.c | | | 22 | +++++++++++----------- |
M | os_win32.c | | | 24 | ++++++++++++------------ |
M | static.c | | | 52 | ++++++++++++++++++++++++++-------------------------- |
M | util.h | | | 64 | ++++++++++++++++++++++++++++++++-------------------------------- |
8 files changed, 138 insertions(+), 141 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -173,7 +173,7 @@ alloc_shader_storage(BeamformerCtx *ctx, Arena a)
cs->raw_data_arena.end = cs->raw_data_arena.beg + rf_raw_size;
break;
case GL_VENDOR_NVIDIA:
- cs->raw_data_arena = ctx->platform.alloc_arena(cs->raw_data_arena, rf_raw_size);
+ cs->raw_data_arena = ctx->os.alloc_arena(cs->raw_data_arena, rf_raw_size);
ctx->cuda_lib.register_cuda_buffers(cs->rf_data_ssbos, ARRAY_COUNT(cs->rf_data_ssbos),
cs->raw_data_ssbo);
ctx->cuda_lib.init_cuda_configuration(bp->rf_raw_dim.E, bp->dec_data_dim.E,
@@ -265,12 +265,12 @@ export_frame(BeamformerCtx *ctx, iptr handle, BeamformFrame *frame)
{
uv3 dim = frame->dim;
size out_size = dim.x * dim.y * dim.z * 2 * sizeof(f32);
- ctx->export_buffer = ctx->platform.alloc_arena(ctx->export_buffer, out_size);
+ ctx->export_buffer = ctx->os.alloc_arena(ctx->export_buffer, out_size);
glGetTextureImage(frame->texture, 0, GL_RG, GL_FLOAT, out_size, ctx->export_buffer.beg);
s8 raw = {.len = out_size, .data = ctx->export_buffer.beg};
- if (!ctx->platform.write_file(handle, raw))
- ctx->platform.write_file(ctx->platform.error_file_handle, s8("failed to export frame\n"));
- ctx->platform.close(handle);
+ if (!ctx->os.write_file(handle, raw))
+ ctx->os.write_file(ctx->os.stderr, s8("failed to export frame\n"));
+ ctx->os.close(handle);
}
static void
@@ -462,7 +462,7 @@ do_compute_shader(BeamformerCtx *ctx, Arena arena, BeamformFrame *frame, Compute
}
static u32
-compile_shader(Platform *platform, Arena a, u32 type, s8 shader, s8 name)
+compile_shader(OS *os, Arena a, u32 type, s8 shader, s8 name)
{
u32 sid = glCreateShader(type);
glShaderSource(sid, 1, (const char **)&shader.data, (int *)&shader.len);
@@ -481,7 +481,7 @@ compile_shader(Platform *platform, Arena a, u32 type, s8 shader, s8 name)
glGetShaderInfoLog(sid, len, &out_len, (char *)(buf.data + buf.widx));
stream_commit(&buf, out_len);
glDeleteShader(sid);
- platform->write_file(platform->error_file_handle, stream_to_s8(&buf));
+ os->write_file(os->stderr, stream_to_s8(&buf));
sid = 0;
}
@@ -490,7 +490,7 @@ compile_shader(Platform *platform, Arena a, u32 type, s8 shader, s8 name)
}
static u32
-link_program(Platform *platform, Arena a, u32 shader_id)
+link_program(OS *os, Arena a, u32 shader_id)
{
i32 success = 0;
u32 result = glCreateProgram();
@@ -504,7 +504,7 @@ link_program(Platform *platform, Arena a, u32 shader_id)
glGetProgramInfoLog(result, buf.cap - buf.widx, &len, (c8 *)(buf.data + buf.widx));
stream_reset(&buf, len);
stream_append_byte(&buf, '\n');
- platform->write_file(platform->error_file_handle, stream_to_s8(&buf));
+ os->write_file(os->stderr, stream_to_s8(&buf));
glDeleteProgram(result);
result = 0;
}
@@ -553,21 +553,20 @@ reload_compute_shader(BeamformerCtx *ctx, s8 path, ComputeShaderReloadContext *c
if (csr->needs_header)
header = push_compute_shader_header(&tmp, csr->shader);
- s8 shader_text = ctx->platform.read_whole_file(&tmp, (c8 *)path.data);
+ s8 shader_text = ctx->os.read_whole_file(&tmp, (c8 *)path.data);
shader_text.data -= header.len;
shader_text.len += header.len;
if (shader_text.data == header.data) {
- u32 shader_id = compile_shader(&ctx->platform, tmp, GL_COMPUTE_SHADER, shader_text, path);
+ u32 shader_id = compile_shader(&ctx->os, tmp, GL_COMPUTE_SHADER, shader_text, path);
if (shader_id) {
- u32 new_program = link_program(&ctx->platform, tmp, shader_id);
+ u32 new_program = link_program(&ctx->os, tmp, shader_id);
if (new_program) {
Stream buf = arena_stream(&tmp);
stream_append_s8(&buf, s8("loaded: "));
stream_append_s8(&buf, path);
stream_append_byte(&buf, '\n');
- ctx->platform.write_file(ctx->platform.error_file_handle,
- stream_to_s8(&buf));
+ ctx->os.write_file(ctx->os.stderr, stream_to_s8(&buf));
glDeleteProgram(cs->programs[csr->shader]);
cs->programs[csr->shader] = new_program;
glUseProgram(cs->programs[csr->shader]);
@@ -583,7 +582,7 @@ reload_compute_shader(BeamformerCtx *ctx, s8 path, ComputeShaderReloadContext *c
stream_append_s8(&buf, s8("failed to load: "));
stream_append_s8(&buf, path);
stream_append_byte(&buf, '\n');
- ctx->platform.write_file(ctx->platform.error_file_handle, stream_to_s8(&buf));
+ ctx->os.write_file(ctx->os.stderr, stream_to_s8(&buf));
}
return result;
@@ -630,16 +629,14 @@ DEBUG_EXPORT BEAMFORMER_COMPLETE_COMPUTE_FN(beamformer_complete_compute)
}
void *rf_data_buf = cs->raw_data_arena.beg;
- size rlen = ctx->platform.read_file(work->file_handle, rf_data_buf,
- cs->rf_raw_size);
+ size rlen = ctx->os.read_file(work->file_handle, rf_data_buf, cs->rf_raw_size);
if (rlen != cs->rf_raw_size) {
stream_append_s8(&ctx->error_stream, s8("Partial Read Occurred: "));
stream_append_i64(&ctx->error_stream, rlen);
stream_append_byte(&ctx->error_stream, '/');
stream_append_i64(&ctx->error_stream, cs->rf_raw_size);
stream_append_byte(&ctx->error_stream, '\n');
- ctx->platform.write_file(ctx->platform.error_file_handle,
- stream_to_s8(&ctx->error_stream));
+ ctx->os.write_file(ctx->os.stderr, stream_to_s8(&ctx->error_stream));
ctx->error_stream.widx = 0;
} else {
switch (ctx->gl.vendor_id) {
@@ -655,7 +652,7 @@ DEBUG_EXPORT BEAMFORMER_COMPLETE_COMPUTE_FN(beamformer_complete_compute)
} break;
case BW_COMPUTE: {
atomic_store(&cs->processing_compute, 1);
- start_renderdoc_capture(&ctx->platform, gl_context);
+ start_renderdoc_capture(&ctx->os, gl_context);
BeamformerWorkFrame *frame = &work->frame;
if (ctx->params->upload) {
@@ -713,7 +710,7 @@ DEBUG_EXPORT BEAMFORMER_COMPLETE_COMPUTE_FN(beamformer_complete_compute)
frame->store->ready_to_present = 1;
cs->processing_compute = 0;
- end_renderdoc_capture(&ctx->platform, gl_context);
+ end_renderdoc_capture(&ctx->os, gl_context);
} break;
case BW_SAVE_FRAME: {
BeamformFrame *frame = work->output_frame_ctx.frame.store;
@@ -749,7 +746,7 @@ DEBUG_EXPORT BEAMFORMER_FRAME_STEP_FN(beamformer_frame_step)
BeamformWork *work = beamform_work_queue_push(ctx->beamform_work_queue);
if (fill_frame_compute_work(ctx, work)) {
beamform_work_queue_push_commit(ctx->beamform_work_queue);
- ctx->platform.wake_thread(ctx->platform.compute_worker.sync_handle);
+ ctx->os.wake_thread(ctx->os.compute_worker.sync_handle);
ctx->start_compute = 0;
}
}
@@ -774,7 +771,7 @@ DEBUG_EXPORT BEAMFORMER_FRAME_STEP_FN(beamformer_frame_step)
BeamformWork *export = beamform_work_queue_push(ctx->beamform_work_queue);
if (export) {
/* TODO: we don't really want the beamformer opening/closing files */
- iptr f = ctx->platform.open_for_write(ctx->params->export_pipe_name);
+ iptr f = ctx->os.open_for_write(ctx->params->export_pipe_name);
export->type = BW_SAVE_FRAME;
export->output_frame_ctx.file_handle = f;
if (ctx->params->raw.output_points.w > 1) {
@@ -809,7 +806,7 @@ DEBUG_EXPORT BEAMFORMER_FRAME_STEP_FN(beamformer_frame_step)
if (ctx->start_compute) {
ctx->start_compute = 0;
- ctx->platform.wake_thread(ctx->platform.compute_worker.sync_handle);
+ ctx->os.wake_thread(ctx->os.compute_worker.sync_handle);
}
/* NOTE: draw output image texture using render fragment shader */
diff --git a/beamformer.h b/beamformer.h
@@ -238,9 +238,9 @@ typedef struct BeamformerCtx {
Arena export_buffer;
- CudaLib cuda_lib;
- Platform platform;
- Stream error_stream;
+ CudaLib cuda_lib;
+ OS os;
+ Stream error_stream;
BeamformWorkQueue *beamform_work_queue;
diff --git a/main_linux.c b/main_linux.c
@@ -23,9 +23,9 @@
#include "static.c"
static void
-dispatch_file_watch_events(Platform *platform, Arena arena)
+dispatch_file_watch_events(OS *os, Arena arena)
{
- FileWatchContext *fwctx = &platform->file_watch_context;
+ FileWatchContext *fwctx = &os->file_watch_context;
u8 *mem = alloc_(&arena, 4096, 64, 1);
Stream path = stream_alloc(&arena, 256);
struct inotify_event *event;
@@ -49,7 +49,7 @@ dispatch_file_watch_events(Platform *platform, Arena arena)
stream_append_s8(&path, file);
stream_append_byte(&path, 0);
stream_commit(&path, -1);
- fw->callback(platform, stream_to_s8(&path),
+ fw->callback(os, stream_to_s8(&path),
fw->user_data, arena);
stream_reset(&path, 0);
break;
@@ -68,27 +68,27 @@ main(void)
Arena temp_memory = os_alloc_arena((Arena){0}, MB(16));
ctx.error_stream = stream_alloc(&temp_memory, MB(1));
- ctx.ui_backing_store = sub_arena(&temp_memory, MB(2), KB(4));
- ctx.platform.compute_worker.arena = sub_arena(&temp_memory, MB(2), KB(4));
+ ctx.ui_backing_store = sub_arena(&temp_memory, MB(2), KB(4));
+ ctx.os.compute_worker.arena = sub_arena(&temp_memory, MB(2), KB(4));
Pipe data_pipe = os_open_named_pipe(OS_PIPE_NAME);
input.pipe_handle = data_pipe.file;
ASSERT(data_pipe.file != INVALID_FILE);
- #define X(name) ctx.platform.name = os_ ## name;
- PLATFORM_FNS
+ #define X(name) ctx.os.name = os_ ## name;
+ OS_FNS
#undef X
- ctx.platform.file_watch_context.handle = inotify_init1(O_NONBLOCK|O_CLOEXEC);
- ctx.platform.compute_worker.asleep = 1;
- ctx.platform.error_file_handle = STDERR_FILENO;
+ ctx.os.file_watch_context.handle = inotify_init1(O_NONBLOCK|O_CLOEXEC);
+ ctx.os.compute_worker.asleep = 1;
+ ctx.os.stderr = STDERR_FILENO;
- debug_init(&ctx.platform, (iptr)&input, &temp_memory);
+ debug_init(&ctx.os, (iptr)&input, &temp_memory);
setup_beamformer(&ctx, &temp_memory);
- os_wake_thread(ctx.platform.compute_worker.sync_handle);
+ os_wake_thread(ctx.os.compute_worker.sync_handle);
struct pollfd fds[2] = {{0}, {0}};
- fds[0].fd = ctx.platform.file_watch_context.handle;
+ fds[0].fd = ctx.os.file_watch_context.handle;
fds[0].events = POLLIN;
fds[1].fd = data_pipe.file;
fds[1].events = POLLIN;
@@ -96,7 +96,7 @@ main(void)
while (!ctx.should_exit) {
poll(fds, 2, 0);
if (fds[0].revents & POLLIN)
- dispatch_file_watch_events(&ctx.platform, temp_memory);
+ dispatch_file_watch_events(&ctx.os, temp_memory);
input.pipe_data_available = !!(fds[1].revents & POLLIN);
input.last_mouse = input.mouse;
diff --git a/main_w32.c b/main_w32.c
@@ -37,7 +37,7 @@ typedef struct {
#include "static.c"
static void
-dispatch_file_watch(Platform *platform, FileWatchDirectory *fw_dir, u8 *buf, Arena arena)
+dispatch_file_watch(OS *os, FileWatchDirectory *fw_dir, u8 *buf, Arena arena)
{
i64 offset = 0;
TempArena save_point = {0};
@@ -52,7 +52,7 @@ dispatch_file_watch(Platform *platform, FileWatchDirectory *fw_dir, u8 *buf, Are
stream_append_s8(&path, s8("unknown file watch event: "));
stream_append_u64(&path, fni->action);
stream_append_byte(&path, '\n');
- platform->write_file(platform->error_file_handle, stream_to_s8(&path));
+ os->write_file(os->stderr, stream_to_s8(&path));
stream_reset(&path, 0);
}
@@ -69,7 +69,7 @@ dispatch_file_watch(Platform *platform, FileWatchDirectory *fw_dir, u8 *buf, Are
for (u32 i = 0; i < fw_dir->file_watch_count; i++) {
FileWatch *fw = fw_dir->file_watches + i;
if (fw->hash == hash) {
- fw->callback(platform, stream_to_s8(&path), fw->user_data, arena);
+ fw->callback(os, stream_to_s8(&path), fw->user_data, arena);
break;
}
}
@@ -80,9 +80,9 @@ dispatch_file_watch(Platform *platform, FileWatchDirectory *fw_dir, u8 *buf, Are
}
static void
-clear_io_queue(Platform *platform, BeamformerInput *input, Arena arena)
+clear_io_queue(OS *os, BeamformerInput *input, Arena arena)
{
- w32_context *ctx = (w32_context *)platform->os_context;
+ w32_context *ctx = (w32_context *)os->context;
iptr handle = ctx->io_completion_handle;
w32_overlapped *overlapped;
@@ -93,7 +93,7 @@ clear_io_queue(Platform *platform, BeamformerInput *input, Arena arena)
switch (event->tag) {
case W32_IO_FILE_WATCH: {
FileWatchDirectory *dir = (FileWatchDirectory *)event->context;
- dispatch_file_watch(platform, dir, dir->buffer.beg, arena);
+ dispatch_file_watch(os, dir, dir->buffer.beg, arena);
zero_struct(overlapped);
ReadDirectoryChangesW(dir->handle, dir->buffer.beg, 4096, 0,
FILE_NOTIFY_CHANGE_LAST_WRITE, 0, overlapped, 0);
@@ -104,7 +104,7 @@ clear_io_queue(Platform *platform, BeamformerInput *input, Arena arena)
}
static b32
-poll_pipe(Pipe *p, Stream *e, Platform *platform)
+poll_pipe(Pipe *p, Stream *e, OS *os)
{
u8 data;
i32 total_read = 0;
@@ -125,7 +125,7 @@ poll_pipe(Pipe *p, Stream *e, Platform *platform)
stream_append_s8(e, s8("poll_pipe: failed to reopen pipe: error: "));
stream_append_i64(e, GetLastError());
stream_append_byte(e, '\n');
- platform->write_file(platform->error_file_handle, stream_to_s8(e));
+ os->write_file(os->stderr, stream_to_s8(e));
stream_reset(e, 0);
}
}
@@ -141,35 +141,35 @@ main(void)
Arena temp_memory = os_alloc_arena((Arena){0}, MB(16));
ctx.error_stream = stream_alloc(&temp_memory, MB(1));
- ctx.ui_backing_store = sub_arena(&temp_memory, MB(2), KB(4));
- ctx.platform.compute_worker.arena = sub_arena(&temp_memory, MB(2), KB(4));
+ ctx.ui_backing_store = sub_arena(&temp_memory, MB(2), KB(4));
+ ctx.os.compute_worker.arena = sub_arena(&temp_memory, MB(2), KB(4));
Pipe data_pipe = os_open_named_pipe(OS_PIPE_NAME);
input.pipe_handle = data_pipe.file;
ASSERT(data_pipe.file != INVALID_FILE);
- #define X(name) ctx.platform.name = os_ ## name;
- PLATFORM_FNS
+ #define X(name) ctx.os.name = os_ ## name;
+ OS_FNS
#undef X
w32_context w32_ctx = {0};
w32_ctx.io_completion_handle = CreateIoCompletionPort(INVALID_FILE, 0, 0, 0);
- ctx.platform.os_context = (iptr)&w32_ctx;
- ctx.platform.compute_worker.asleep = 1;
- ctx.platform.error_file_handle = GetStdHandle(STD_ERROR_HANDLE);
+ ctx.os.context = (iptr)&w32_ctx;
+ ctx.os.compute_worker.asleep = 1;
+ ctx.os.stderr = GetStdHandle(STD_ERROR_HANDLE);
- debug_init(&ctx.platform, (iptr)&input, &temp_memory);
+ debug_init(&ctx.os, (iptr)&input, &temp_memory);
setup_beamformer(&ctx, &temp_memory);
- os_wake_thread(ctx.platform.compute_worker.sync_handle);
+ os_wake_thread(ctx.os.compute_worker.sync_handle);
while (!ctx.should_exit) {
- clear_io_queue(&ctx.platform, &input, temp_memory);
+ clear_io_queue(&ctx.os, &input, temp_memory);
input.last_mouse = input.mouse;
input.mouse.rl = GetMousePosition();
- input.pipe_data_available = poll_pipe(&data_pipe, &ctx.error_stream, &ctx.platform);
+ input.pipe_data_available = poll_pipe(&data_pipe, &ctx.error_stream, &ctx.os);
beamformer_frame_step(&ctx, &temp_memory, &input);
diff --git a/os_unix.c b/os_unix.c
@@ -29,7 +29,7 @@ os_get_module(char *name, Stream *e)
}
#endif
-static PLATFORM_WRITE_FILE_FN(os_write_file)
+static OS_WRITE_FILE_FN(os_write_file)
{
while (raw.len) {
size r = write(file, raw.data, raw.len);
@@ -47,7 +47,7 @@ os_fatal(s8 msg)
unreachable();
}
-static PLATFORM_ALLOC_ARENA_FN(os_alloc_arena)
+static OS_ALLOC_ARENA_FN(os_alloc_arena)
{
Arena result;
size pagesize = sysconf(_SC_PAGESIZE);
@@ -68,12 +68,12 @@ static PLATFORM_ALLOC_ARENA_FN(os_alloc_arena)
return result;
}
-static PLATFORM_CLOSE_FN(os_close)
+static OS_CLOSE_FN(os_close)
{
close(file);
}
-static PLATFORM_OPEN_FOR_WRITE_FN(os_open_for_write)
+static OS_OPEN_FOR_WRITE_FN(os_open_for_write)
{
iptr result = open(fname, O_WRONLY|O_TRUNC);
if (result == -1)
@@ -81,7 +81,7 @@ static PLATFORM_OPEN_FOR_WRITE_FN(os_open_for_write)
return result;
}
-static PLATFORM_READ_WHOLE_FILE_FN(os_read_whole_file)
+static OS_READ_WHOLE_FILE_FN(os_read_whole_file)
{
s8 result = {0};
@@ -98,7 +98,7 @@ static PLATFORM_READ_WHOLE_FILE_FN(os_read_whole_file)
return result;
}
-static PLATFORM_WRITE_NEW_FILE_FN(os_write_new_file)
+static OS_WRITE_NEW_FILE_FN(os_write_new_file)
{
iptr fd = open(fname, O_WRONLY|O_TRUNC|O_CREAT, 0600);
if (fd == INVALID_FILE)
@@ -123,7 +123,7 @@ os_open_named_pipe(char *name)
return (Pipe){.file = open(name, O_RDONLY|O_NONBLOCK), .name = name};
}
-static PLATFORM_READ_FILE_FN(os_read_file)
+static OS_READ_FILE_FN(os_read_file)
{
size r = 0, total_read = 0;
do {
@@ -229,14 +229,14 @@ os_unload_library(void *h)
dlclose(h);
}
-static PLATFORM_ADD_FILE_WATCH_FN(os_add_file_watch)
+static OS_ADD_FILE_WATCH_FN(os_add_file_watch)
{
s8 directory = path;
directory.len = s8_scan_backwards(path, '/');
ASSERT(directory.len > 0);
u64 hash = s8_hash(directory);
- FileWatchContext *fwctx = &platform->file_watch_context;
+ FileWatchContext *fwctx = &os->file_watch_context;
FileWatchDirectory *dir = lookup_file_watch_directory(fwctx, hash);
if (!dir) {
ASSERT(path.data[directory.len] == '/');
@@ -253,7 +253,7 @@ static PLATFORM_ADD_FILE_WATCH_FN(os_add_file_watch)
i32 pthread_setname_np(pthread_t, char *);
static iptr
-os_create_thread(Arena arena, iptr user_context, s8 name, platform_thread_entry_point_fn *fn)
+os_create_thread(Arena arena, iptr user_context, s8 name, os_thread_entry_point_fn *fn)
{
pthread_t result;
pthread_create(&result, 0, (void *(*)(void *))fn, (void *)user_context);
@@ -275,7 +275,7 @@ os_sleep_thread(iptr sync_handle)
sem_wait((sem_t *)sync_handle);
}
-static PLATFORM_WAKE_THREAD_FN(os_wake_thread)
+static OS_WAKE_THREAD_FN(os_wake_thread)
{
sem_post((sem_t *)sync_handle);
}
diff --git a/os_win32.c b/os_win32.c
@@ -130,7 +130,7 @@ os_get_module(char *name, Stream *e)
}
#endif
-static PLATFORM_WRITE_FILE_FN(os_write_file)
+static OS_WRITE_FILE_FN(os_write_file)
{
i32 wlen = 0;
if (raw.len) WriteFile(file, raw.data, raw.len, &wlen, 0);
@@ -145,7 +145,7 @@ os_fatal(s8 msg)
unreachable();
}
-static PLATFORM_ALLOC_ARENA_FN(os_alloc_arena)
+static OS_ALLOC_ARENA_FN(os_alloc_arena)
{
Arena result;
w32_sys_info Info;
@@ -168,18 +168,18 @@ static PLATFORM_ALLOC_ARENA_FN(os_alloc_arena)
return result;
}
-static PLATFORM_CLOSE_FN(os_close)
+static OS_CLOSE_FN(os_close)
{
CloseHandle(file);
}
-static PLATFORM_OPEN_FOR_WRITE_FN(os_open_for_write)
+static OS_OPEN_FOR_WRITE_FN(os_open_for_write)
{
iptr result = CreateFileA(fname, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
return result;
}
-static PLATFORM_READ_WHOLE_FILE_FN(os_read_whole_file)
+static OS_READ_WHOLE_FILE_FN(os_read_whole_file)
{
s8 result = {0};
@@ -201,14 +201,14 @@ static PLATFORM_READ_WHOLE_FILE_FN(os_read_whole_file)
return result;
}
-static PLATFORM_READ_FILE_FN(os_read_file)
+static OS_READ_FILE_FN(os_read_file)
{
i32 total_read = 0;
ReadFile(file, buf, len, &total_read, 0);
return total_read;
}
-static PLATFORM_WRITE_NEW_FILE_FN(os_write_new_file)
+static OS_WRITE_NEW_FILE_FN(os_write_new_file)
{
if (raw.len > (size)U32_MAX) {
os_write_file(GetStdHandle(STD_ERROR_HANDLE),
@@ -295,14 +295,14 @@ os_unload_library(void *h)
FreeLibrary(h);
}
-static PLATFORM_ADD_FILE_WATCH_FN(os_add_file_watch)
+static OS_ADD_FILE_WATCH_FN(os_add_file_watch)
{
s8 directory = path;
directory.len = s8_scan_backwards(path, '\\');
ASSERT(directory.len > 0);
u64 hash = s8_hash(directory);
- FileWatchContext *fwctx = &platform->file_watch_context;
+ FileWatchContext *fwctx = &os->file_watch_context;
FileWatchDirectory *dir = lookup_file_watch_directory(fwctx, hash);
if (!dir) {
ASSERT(path.data[directory.len] == '\\');
@@ -314,7 +314,7 @@ static PLATFORM_ADD_FILE_WATCH_FN(os_add_file_watch)
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OVERLAPPED, 0);
- w32_context *ctx = (w32_context *)platform->os_context;
+ w32_context *ctx = (w32_context *)os->context;
w32_io_completion_event *event = push_struct(a, typeof(*event));
event->tag = W32_IO_FILE_WATCH;
event->context = (iptr)dir;
@@ -332,7 +332,7 @@ static PLATFORM_ADD_FILE_WATCH_FN(os_add_file_watch)
}
static iptr
-os_create_thread(Arena arena, iptr user_context, s8 name, platform_thread_entry_point_fn *fn)
+os_create_thread(Arena arena, iptr user_context, s8 name, os_thread_entry_point_fn *fn)
{
iptr result = CreateThread(0, 0, (iptr)fn, user_context, 0, 0);
SetThreadDescription(result, s8_to_s16(&arena, name).data);
@@ -352,7 +352,7 @@ os_sleep_thread(iptr sync_handle)
WaitForSingleObjectEx(sync_handle, 0xFFFFFFFF, 0);
}
-static PLATFORM_WAKE_THREAD_FN(os_wake_thread)
+static OS_WAKE_THREAD_FN(os_wake_thread)
{
ReleaseSemaphore(sync_handle, 1, 0);
}
diff --git a/static.c b/static.c
@@ -24,7 +24,7 @@ static FILE_WATCH_CALLBACK_FN(debug_reload)
/* NOTE(rnp): spin until compute thread finishes its work (we will probably
* never reload while compute is in progress but just incase). */
- while (!atomic_load(&platform->compute_worker.asleep));
+ while (!atomic_load(&os->compute_worker.asleep));
os_unload_library(debug_lib);
debug_lib = os_load_library(OS_DEBUG_LIB_NAME, OS_DEBUG_LIB_TEMP_NAME, &err);
@@ -34,7 +34,7 @@ static FILE_WATCH_CALLBACK_FN(debug_reload)
#undef X
stream_append_s8(&err, s8("Reloaded Main Executable\n"));
- platform->write_file(platform->error_file_handle, stream_to_s8(&err));
+ os->write_file(os->stderr, stream_to_s8(&err));
input->executable_reloaded = 1;
@@ -42,10 +42,10 @@ static FILE_WATCH_CALLBACK_FN(debug_reload)
}
static void
-debug_init(Platform *p, iptr input, Arena *arena)
+debug_init(OS *os, iptr input, Arena *arena)
{
- p->add_file_watch(p, arena, s8(OS_DEBUG_LIB_NAME), debug_reload, input);
- debug_reload(p, (s8){0}, input, *arena);
+ os->add_file_watch(os, arena, s8(OS_DEBUG_LIB_NAME), debug_reload, input);
+ debug_reload(os, (s8){0}, input, *arena);
Arena tmp = *arena;
Stream err = arena_stream(&tmp);
@@ -55,14 +55,14 @@ debug_init(Platform *p, iptr input, Arena *arena)
if (get_api) {
RenderDocAPI *api = 0;
if (get_api(10600, (void **)&api)) {
- p->start_frame_capture = RENDERDOC_START_FRAME_CAPTURE(api);
- p->end_frame_capture = RENDERDOC_END_FRAME_CAPTURE(api);
+ os->start_frame_capture = RENDERDOC_START_FRAME_CAPTURE(api);
+ os->end_frame_capture = RENDERDOC_END_FRAME_CAPTURE(api);
stream_append_s8(&err, s8("loaded: " OS_RENDERDOC_SONAME "\n"));
}
}
}
- p->write_file(p->error_file_handle, stream_to_s8(&err));
+ os->write_file(os->stderr, stream_to_s8(&err));
}
#endif /* _DEBUG */
@@ -70,8 +70,8 @@ debug_init(Platform *p, iptr input, Arena *arena)
#define static_path_join(a, b) (a OS_PATH_SEPERATOR b)
struct gl_debug_ctx {
- Stream stream;
- Platform *platform;
+ Stream stream;
+ OS *os;
};
static void
@@ -91,7 +91,7 @@ gl_debug_logger(u32 src, u32 type, u32 id, u32 lvl, i32 len, const char *msg, co
}
stream_append(e, (char *)msg, len);
stream_append_byte(e, '\n');
- ctx->platform->write_file(ctx->platform->error_file_handle, stream_to_s8(e));
+ ctx->os->write_file(ctx->os->stderr, stream_to_s8(e));
stream_reset(e, 0);
}
@@ -153,7 +153,7 @@ validate_gl_requirements(GLParams *gl, Arena a)
}
static void
-dump_gl_params(GLParams *gl, Arena a, Platform *p)
+dump_gl_params(GLParams *gl, Arena a, OS *os)
{
(void)gl; (void)a;
#ifdef _DEBUG
@@ -180,7 +180,7 @@ dump_gl_params(GLParams *gl, Arena a, Platform *p)
stream_append_s8(&s, s8("\nMax Server Wait Time [ns]: "));
stream_append_i64(&s, gl->max_server_wait_time);
stream_append_s8(&s, s8("\n-----------------------\n"));
- p->write_file(p->error_file_handle, stream_to_s8(&s));
+ os->write_file(os->stderr, stream_to_s8(&s));
#endif
}
@@ -211,7 +211,7 @@ static FILE_WATCH_CALLBACK_FN(queue_compute_shader_reload)
work->type = BW_RELOAD_SHADER;
work->reload_shader_ctx = csr;
beamform_work_queue_push_commit(ctx->beamform_work_queue);
- ctx->platform.wake_thread(ctx->platform.compute_worker.sync_handle);
+ ctx->os.wake_thread(ctx->os.compute_worker.sync_handle);
}
return 1;
}
@@ -230,7 +230,7 @@ static FILE_WATCH_CALLBACK_FN(load_cuda_lib)
CUDA_LIB_FNS
#undef X
- platform->write_file(platform->error_file_handle, stream_to_s8(&err));
+ os->write_file(os->stderr, stream_to_s8(&err));
}
#define X(name) if (!cl->name) cl->name = name ## _stub;
@@ -246,7 +246,7 @@ void glfwWindowHint(i32, i32);
iptr glfwCreateWindow(i32, i32, char *, iptr, iptr);
void glfwMakeContextCurrent(iptr);
-static PLATFORM_THREAD_ENTRY_POINT_FN(compute_worker_thread_entry_point)
+static OS_THREAD_ENTRY_POINT_FN(compute_worker_thread_entry_point)
{
GLWorkerThreadContext *ctx = (GLWorkerThreadContext *)_ctx;
@@ -278,12 +278,12 @@ setup_beamformer(BeamformerCtx *ctx, Arena *memory)
/* NOTE: Gather information about the GPU */
get_gl_params(&ctx->gl, &ctx->error_stream);
- dump_gl_params(&ctx->gl, *memory, &ctx->platform);
+ dump_gl_params(&ctx->gl, *memory, &ctx->os);
validate_gl_requirements(&ctx->gl, *memory);
glfwWindowHint(GLFW_VISIBLE, 0);
iptr raylib_window_handle = (iptr)GetPlatformWindowHandle();
- GLWorkerThreadContext *worker = &ctx->platform.compute_worker;
+ GLWorkerThreadContext *worker = &ctx->os.compute_worker;
worker->window_handle = glfwCreateWindow(320, 240, "", 0, raylib_window_handle);
worker->sync_handle = os_create_sync_object(memory);
worker->handle = os_create_thread(*memory, (iptr)worker, s8("[compute]"),
@@ -308,9 +308,9 @@ setup_beamformer(BeamformerCtx *ctx, Arena *memory)
ctx->params->compute_stages_count = 2;
if (ctx->gl.vendor_id == GL_VENDOR_NVIDIA
- && load_cuda_lib(&ctx->platform, s8(OS_CUDA_LIB_NAME), (iptr)&ctx->cuda_lib, *memory))
+ && load_cuda_lib(&ctx->os, s8(OS_CUDA_LIB_NAME), (iptr)&ctx->cuda_lib, *memory))
{
- os_add_file_watch(&ctx->platform, memory, s8(OS_CUDA_LIB_NAME), load_cuda_lib,
+ os_add_file_watch(&ctx->os, memory, s8(OS_CUDA_LIB_NAME), load_cuda_lib,
(iptr)&ctx->cuda_lib);
} else {
#define X(name) if (!ctx->cuda_lib.name) ctx->cuda_lib.name = name ## _stub;
@@ -320,8 +320,8 @@ setup_beamformer(BeamformerCtx *ctx, Arena *memory)
/* NOTE: set up OpenGL debug logging */
struct gl_debug_ctx *gl_debug_ctx = push_struct(memory, typeof(*gl_debug_ctx));
- gl_debug_ctx->stream = stream_alloc(memory, 1024);
- gl_debug_ctx->platform = &ctx->platform;
+ gl_debug_ctx->stream = stream_alloc(memory, 1024);
+ gl_debug_ctx->os = &ctx->os;
glDebugMessageCallback(gl_debug_logger, gl_debug_ctx);
#ifdef _DEBUG
glEnable(GL_DEBUG_OUTPUT);
@@ -339,16 +339,16 @@ setup_beamformer(BeamformerCtx *ctx, Arena *memory)
csr->shader = sn; \
csr->needs_header = nh; \
csr->path = s8(static_path_join("shaders", f ".glsl")); \
- os_add_file_watch(&ctx->platform, memory, csr->path, queue_compute_shader_reload, (iptr)csr); \
- queue_compute_shader_reload(&ctx->platform, csr->path, (iptr)csr, *memory); \
+ os_add_file_watch(&ctx->os, memory, csr->path, queue_compute_shader_reload, (iptr)csr); \
+ queue_compute_shader_reload(&ctx->os, csr->path, (iptr)csr, *memory); \
} while (0);
COMPUTE_SHADERS
#undef X
os_wake_thread(worker->sync_handle);
s8 render = s8(static_path_join("shaders", "render.glsl"));
- reload_render_shader(&ctx->platform, render, (iptr)&ctx->fsctx, *memory);
- os_add_file_watch(&ctx->platform, memory, render, reload_render_shader, (iptr)&ctx->fsctx);
+ reload_render_shader(&ctx->os, render, (iptr)&ctx->fsctx, *memory);
+ os_add_file_watch(&ctx->os, memory, render, reload_render_shader, (iptr)&ctx->fsctx);
ctx->fsctx.gen_mipmaps = 0;
ctx->ready_for_rf = 1;
diff --git a/util.h b/util.h
@@ -176,7 +176,7 @@ typedef struct {
b32 errors;
} Stream;
-typedef struct Platform Platform;
+typedef struct OS OS;
typedef struct {
Arena arena;
@@ -188,7 +188,7 @@ typedef struct {
b32 asleep;
} GLWorkerThreadContext;
-#define FILE_WATCH_CALLBACK_FN(name) b32 name(Platform *platform, s8 path, iptr user_data, Arena tmp)
+#define FILE_WATCH_CALLBACK_FN(name) b32 name(OS *os, s8 path, iptr user_data, Arena tmp)
typedef FILE_WATCH_CALLBACK_FN(file_watch_callback);
typedef struct {
@@ -213,41 +213,41 @@ typedef struct {
u32 directory_watch_count;
} FileWatchContext;
-#define PLATFORM_ALLOC_ARENA_FN(name) Arena name(Arena old, size capacity)
-typedef PLATFORM_ALLOC_ARENA_FN(platform_alloc_arena_fn);
+#define OS_ALLOC_ARENA_FN(name) Arena name(Arena old, size capacity)
+typedef OS_ALLOC_ARENA_FN(os_alloc_arena_fn);
-#define PLATFORM_ADD_FILE_WATCH_FN(name) void name(Platform *platform, Arena *a, s8 path, \
- file_watch_callback *callback, iptr user_data)
-typedef PLATFORM_ADD_FILE_WATCH_FN(platform_add_file_watch_fn);
+#define OS_ADD_FILE_WATCH_FN(name) void name(OS *os, Arena *a, s8 path, \
+ file_watch_callback *callback, iptr user_data)
+typedef OS_ADD_FILE_WATCH_FN(os_add_file_watch_fn);
-#define PLATFORM_WAKE_WORKER_FN(name) void name(GLWorkerThreadContext *ctx)
-typedef PLATFORM_WAKE_WORKER_FN(platform_wake_worker_fn);
+#define OS_WAKE_WORKER_FN(name) void name(GLWorkerThreadContext *ctx)
+typedef OS_WAKE_WORKER_FN(os_wake_worker_fn);
-#define PLATFORM_CLOSE_FN(name) void name(iptr file)
-typedef PLATFORM_CLOSE_FN(platform_close_fn);
+#define OS_CLOSE_FN(name) void name(iptr file)
+typedef OS_CLOSE_FN(os_close_fn);
-#define PLATFORM_OPEN_FOR_WRITE_FN(name) iptr name(c8 *fname)
-typedef PLATFORM_OPEN_FOR_WRITE_FN(platform_open_for_write_fn);
+#define OS_OPEN_FOR_WRITE_FN(name) iptr name(c8 *fname)
+typedef OS_OPEN_FOR_WRITE_FN(os_open_for_write_fn);
-#define PLATFORM_READ_WHOLE_FILE_FN(name) s8 name(Arena *arena, char *file)
-typedef PLATFORM_READ_WHOLE_FILE_FN(platform_read_whole_file_fn);
+#define OS_READ_WHOLE_FILE_FN(name) s8 name(Arena *arena, char *file)
+typedef OS_READ_WHOLE_FILE_FN(os_read_whole_file_fn);
-#define PLATFORM_READ_FILE_FN(name) size name(iptr file, void *buf, size len)
-typedef PLATFORM_READ_FILE_FN(platform_read_file_fn);
+#define OS_READ_FILE_FN(name) size name(iptr file, void *buf, size len)
+typedef OS_READ_FILE_FN(os_read_file_fn);
-#define PLATFORM_WAKE_THREAD_FN(name) void name(iptr sync_handle)
-typedef PLATFORM_WAKE_THREAD_FN(platform_wake_thread_fn);
+#define OS_WAKE_THREAD_FN(name) void name(iptr sync_handle)
+typedef OS_WAKE_THREAD_FN(os_wake_thread_fn);
-#define PLATFORM_WRITE_NEW_FILE_FN(name) b32 name(char *fname, s8 raw)
-typedef PLATFORM_WRITE_NEW_FILE_FN(platform_write_new_file_fn);
+#define OS_WRITE_NEW_FILE_FN(name) b32 name(char *fname, s8 raw)
+typedef OS_WRITE_NEW_FILE_FN(os_write_new_file_fn);
-#define PLATFORM_WRITE_FILE_FN(name) b32 name(iptr file, s8 raw)
-typedef PLATFORM_WRITE_FILE_FN(platform_write_file_fn);
+#define OS_WRITE_FILE_FN(name) b32 name(iptr file, s8 raw)
+typedef OS_WRITE_FILE_FN(os_write_file_fn);
-#define PLATFORM_THREAD_ENTRY_POINT_FN(name) iptr name(iptr _ctx)
-typedef PLATFORM_THREAD_ENTRY_POINT_FN(platform_thread_entry_point_fn);
+#define OS_THREAD_ENTRY_POINT_FN(name) iptr name(iptr _ctx)
+typedef OS_THREAD_ENTRY_POINT_FN(os_thread_entry_point_fn);
-#define PLATFORM_FNS \
+#define OS_FNS \
X(add_file_watch) \
X(alloc_arena) \
X(close) \
@@ -272,18 +272,18 @@ typedef __attribute__((aligned(16))) u8 RenderDocAPI[216];
#define RENDERDOC_START_FRAME_CAPTURE(a) (renderdoc_start_frame_capture_fn *)RENDERDOC_API_FN_ADDR(a, 152)
#define RENDERDOC_END_FRAME_CAPTURE(a) (renderdoc_end_frame_capture_fn *) RENDERDOC_API_FN_ADDR(a, 168)
-#define X(name) platform_ ## name ## _fn *name;
-struct Platform {
- PLATFORM_FNS
+struct OS {
+#define X(name) os_ ## name ## _fn *name;
+ OS_FNS
+#undef X
FileWatchContext file_watch_context;
- iptr os_context;
- iptr error_file_handle;
+ iptr context;
+ iptr stderr;
GLWorkerThreadContext compute_worker;
DEBUG_DECL(renderdoc_start_frame_capture_fn *start_frame_capture);
DEBUG_DECL(renderdoc_end_frame_capture_fn *end_frame_capture);
};
-#undef X
#include "util.c"