ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: f11ad1c1b018ab2d164c47b7564d38db61dc049b
Parent: c2387f35636136cf2a154805a70c3ff16b1aea8c
Author: Randy Palamar
Date:   Fri, 21 Mar 2025 21:50:09 -0600

rename size -> iz

iz is a better name so that I can use size when that is what the
variable should be named

Diffstat:
Mbeamformer.c | 16++++++++--------
Mmain_linux.c | 2+-
Mos_unix.c | 20++++++++++----------
Mos_win32.c | 26+++++++++++++-------------
Mui.c | 4++--
Mutil.c | 56++++++++++++++++++++++++++++----------------------------
Mutil.h | 12++++++------
7 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -12,11 +12,11 @@ static u32 cycle_t; #define end_renderdoc_capture(p, gl) if ((p)->end_frame_capture) (p)->end_frame_capture(gl, 0) #endif -static size +static iz decoded_data_size(ComputeShaderCtx *cs) { - uv4 dim = cs->dec_data_dim; - size result = 2 * sizeof(f32) * dim.x * dim.y * dim.z; + uv4 dim = cs->dec_data_dim; + iz result = 2 * sizeof(f32) * dim.x * dim.y * dim.z; return result; } @@ -151,7 +151,7 @@ alloc_shader_storage(BeamformerCtx *ctx, Arena a) glNamedBufferStorage(cs->raw_data_ssbo, rf_raw_size, 0, storage_flags); LABEL_GL_OBJECT(GL_BUFFER, cs->raw_data_ssbo, s8("Raw_RF_SSBO")); - size rf_decoded_size = decoded_data_size(cs); + iz rf_decoded_size = decoded_data_size(cs); Stream label = stream_alloc(&a, 256); stream_append_s8(&label, s8("Decoded_RF_SSBO_")); u32 s_widx = label.widx; @@ -182,7 +182,7 @@ alloc_shader_storage(BeamformerCtx *ctx, Arena a) } /* NOTE: store hadamard in GPU once; it won't change for a particular imaging session */ - size hadamard_elements = dec_data_dim.z * dec_data_dim.z; + iz hadamard_elements = dec_data_dim.z * dec_data_dim.z; i32 *hadamard = alloc(&a, i32, hadamard_elements); i32 *tmp = alloc(&a, i32, hadamard_elements); fill_hadamard_transpose(hadamard, tmp, dec_data_dim.z); @@ -264,7 +264,7 @@ static void export_frame(BeamformerCtx *ctx, iptr handle, BeamformFrame *frame) { uv3 dim = frame->dim; - size out_size = dim.x * dim.y * dim.z * 2 * sizeof(f32); + iz out_size = dim.x * dim.y * dim.z * 2 * sizeof(f32); 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}; @@ -629,7 +629,7 @@ DEBUG_EXPORT BEAMFORMER_COMPLETE_COMPUTE_FN(beamformer_complete_compute) } void *rf_data_buf = cs->raw_data_arena.beg; - size rlen = ctx->os.read_file(work->file_handle, rf_data_buf, cs->rf_raw_size); + iz 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); @@ -666,7 +666,7 @@ DEBUG_EXPORT BEAMFORMER_COMPLETE_COMPUTE_FN(beamformer_complete_compute) uv3 try_dim = ctx->params->raw.output_points.xyz; if (!uv3_equal(try_dim, frame->store->dim)) { - size frame_index = frame->store - ctx->beamform_frames; + iz frame_index = frame->store - ctx->beamform_frames; alloc_beamform_frame(&ctx->gl, frame->store, frame->stats, try_dim, frame_index, s8("Beamformed_Data")); } diff --git a/main_linux.c b/main_linux.c @@ -30,7 +30,7 @@ dispatch_file_watch_events(OS *os, Arena arena) Stream path = stream_alloc(&arena, 256); struct inotify_event *event; - size rlen; + iz rlen; while ((rlen = read(fwctx->handle, mem, 4096)) > 0) { for (u8 *data = mem; data < mem + rlen; data += sizeof(*event) + event->len) { event = (struct inotify_event *)data; diff --git a/os_unix.c b/os_unix.c @@ -32,7 +32,7 @@ os_get_module(char *name, Stream *e) static OS_WRITE_FILE_FN(os_write_file) { while (raw.len) { - size r = write(file, raw.data, raw.len); + iz r = write(file, raw.data, raw.len); if (r < 0) return 0; raw = s8_cut_head(raw, r); } @@ -50,11 +50,11 @@ os_fatal(s8 msg) static OS_ALLOC_ARENA_FN(os_alloc_arena) { Arena result; - size pagesize = sysconf(_SC_PAGESIZE); + iz pagesize = sysconf(_SC_PAGESIZE); if (capacity % pagesize != 0) capacity += pagesize - capacity % pagesize; - size oldsize = old.end - old.beg; + iz oldsize = old.end - old.beg; if (oldsize > capacity) return old; @@ -89,7 +89,7 @@ static OS_READ_WHOLE_FILE_FN(os_read_whole_file) i32 fd = open(file, O_RDONLY); if (fd >= 0 && fstat(fd, &sb) >= 0) { result = s8_alloc(arena, sb.st_size); - size rlen = read(fd, result.data, result.len); + iz rlen = read(fd, result.data, result.len); if (rlen != result.len) result = (s8){0}; } @@ -125,17 +125,17 @@ os_open_named_pipe(char *name) static OS_READ_FILE_FN(os_read_file) { - size r = 0, total_read = 0; + iz r = 0, total_read = 0; do { if (r != -1) total_read += r; - r = read(file, buf + total_read, len - total_read); + r = read(file, buf + total_read, size - total_read); } while (r); return total_read; } static void * -os_open_shared_memory_area(char *name, size cap) +os_open_shared_memory_area(char *name, iz cap) { i32 fd = shm_open(name, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR); if (fd == -1) @@ -170,11 +170,11 @@ os_copy_file(char *name, char *new) if (fd_old < 0 || fd_new < 0) goto ret; u8 buf[4096]; - size copied = 0; + iz copied = 0; while (copied != sb.st_size) { - size r = read(fd_old, buf, ARRAY_COUNT(buf)); + iz r = read(fd_old, buf, ARRAY_COUNT(buf)); if (r < 0) goto ret; - size w = write(fd_new, buf, r); + iz w = write(fd_new, buf, r); if (w < 0) goto ret; copied += w; } diff --git a/os_win32.c b/os_win32.c @@ -40,8 +40,8 @@ typedef struct { u16 wProcessorArchitecture; u16 _pad1; u32 dwPageSize; - size lpMinimumApplicationAddress; - size lpMaximumApplicationAddress; + iz lpMinimumApplicationAddress; + iz lpMaximumApplicationAddress; u64 dwActiveProcessorMask; u32 dwNumberOfProcessors; u32 dwProcessorType; @@ -91,7 +91,7 @@ W32(iptr) CreateFileMappingA(iptr, void *, u32, u32, u32, c8 *); W32(iptr) CreateIoCompletionPort(iptr, iptr, uptr, u32); W32(iptr) CreateNamedPipeA(c8 *, u32, u32, u32, u32, u32, u32, void *); W32(iptr) CreateSemaphoreA(iptr, i64, i64, c8 *); -W32(iptr) CreateThread(iptr, usize, iptr, iptr, u32, u32 *); +W32(iptr) CreateThread(iptr, uz, iptr, iptr, u32, u32 *); W32(b32) DeleteFileA(c8 *); W32(b32) DisconnectNamedPipe(iptr); W32(void) ExitProcess(i32); @@ -112,8 +112,8 @@ W32(b32) ReleaseSemaphore(iptr, i64, i64 *); W32(i32) SetThreadDescription(iptr, u16 *); W32(u32) WaitForSingleObjectEx(iptr, u32, b32); W32(b32) WriteFile(iptr, u8 *, i32, i32 *, void *); -W32(void *) VirtualAlloc(u8 *, size, u32, u32); -W32(b32) VirtualFree(u8 *, size, u32); +W32(void *) VirtualAlloc(u8 *, iz, u32, u32); +W32(b32) VirtualFree(u8 *, iz, u32); #ifdef _DEBUG static void * @@ -154,7 +154,7 @@ static OS_ALLOC_ARENA_FN(os_alloc_arena) if (capacity % Info.dwPageSize != 0) capacity += (Info.dwPageSize - capacity % Info.dwPageSize); - size oldsize = old.end - old.beg; + iz oldsize = old.end - old.beg; if (oldsize > capacity) return old; @@ -186,11 +186,11 @@ static OS_READ_WHOLE_FILE_FN(os_read_whole_file) w32_file_info fileinfo; iptr h = CreateFileA(file, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); if (h >= 0 && GetFileInformationByHandle(h, &fileinfo)) { - size filesize = (size)fileinfo.nFileSizeHigh << 32; - filesize |= (size)fileinfo.nFileSizeLow; - result = s8_alloc(arena, filesize); + iz filesize = (iz)fileinfo.nFileSizeHigh << 32; + filesize |= (iz)fileinfo.nFileSizeLow; + result = s8_alloc(arena, filesize); - ASSERT(filesize <= (size)U32_MAX); + ASSERT(filesize <= (iz)U32_MAX); i32 rlen; if (!ReadFile(h, result.data, result.len, &rlen, 0) || rlen != result.len) @@ -204,13 +204,13 @@ static OS_READ_WHOLE_FILE_FN(os_read_whole_file) static OS_READ_FILE_FN(os_read_file) { i32 total_read = 0; - ReadFile(file, buf, len, &total_read, 0); + ReadFile(file, buf, size, &total_read, 0); return total_read; } static OS_WRITE_NEW_FILE_FN(os_write_new_file) { - if (raw.len > (size)U32_MAX) { + if (raw.len > (iz)U32_MAX) { os_write_file(GetStdHandle(STD_ERROR_HANDLE), s8("os_write_file: files >4GB are not yet handled on win32\n")); return 0; @@ -242,7 +242,7 @@ os_open_named_pipe(char *name) } static void * -os_open_shared_memory_area(char *name, size cap) +os_open_shared_memory_area(char *name, iz cap) { iptr h = CreateFileMappingA(-1, 0, PAGE_READWRITE, 0, cap, name); if (h == INVALID_FILE) diff --git a/ui.c b/ui.c @@ -228,7 +228,7 @@ static v2 measure_text(Font font, s8 text) { v2 result = {.y = font.baseSize}; - for (size i = 0; i < text.len; i++) { + for (iz i = 0; i < text.len; i++) { /* NOTE: assumes font glyphs are ordered ASCII */ i32 idx = (i32)text.data[i] - 0x20; result.x += font.glyphs[idx].advanceX; @@ -499,7 +499,7 @@ static v2 draw_text(Font font, s8 text, v2 pos, Color colour) { v2 off = pos; - for (size i = 0; i < text.len; i++) { + for (iz i = 0; i < text.len; i++) { /* NOTE: assumes font glyphs are ordered ASCII */ i32 idx = text.data[i] - 0x20; Rectangle dst = { diff --git a/util.c b/util.c @@ -16,15 +16,15 @@ static i32 hadamard_12_12_transpose[] = { #define zero_struct(s) mem_clear(s, 0, sizeof(*s)); static void * -mem_clear(void *p_, u8 c, size len) +mem_clear(void *p_, u8 c, iz size) { u8 *p = p_; - while (len) p[--len] = c; + while (size > 0) p[--size] = c; return p; } static void -mem_copy(void *restrict src, void *restrict dest, size n) +mem_copy(void *restrict src, void *restrict dest, uz n) { ASSERT(n >= 0); u8 *s = src, *d = dest; @@ -32,7 +32,7 @@ mem_copy(void *restrict src, void *restrict dest, size n) } static void -mem_move(u8 *src, u8 *dest, size n) +mem_move(u8 *src, u8 *dest, iz n) { if (dest < src) mem_copy(src, dest, n); else while (n) { n--; dest[n] = src[n]; } @@ -40,7 +40,7 @@ mem_move(u8 *src, u8 *dest, size n) static u8 * -arena_commit(Arena *a, size size) +arena_commit(Arena *a, iz size) { ASSERT(a->end - a->beg >= size); u8 *result = a->beg; @@ -49,7 +49,7 @@ arena_commit(Arena *a, size size) } static void -arena_pop(Arena *a, size length) +arena_pop(Arena *a, iz length) { a->beg -= length; } @@ -57,14 +57,14 @@ arena_pop(Arena *a, size length) #define alloc(a, t, n) (t *)alloc_(a, sizeof(t), _Alignof(t), n) #define push_struct(a, t) (t *)alloc_(a, sizeof(t), _Alignof(t), 1) static void * -alloc_(Arena *a, size len, size align, size count) +alloc_(Arena *a, iz len, iz align, iz count) { /* NOTE: special case 0 arena */ if (a->beg == 0) return 0; - size padding = -(uintptr_t)a->beg & (align - 1); - size available = a->end - a->beg - padding; + iz padding = -(uintptr_t)a->beg & (align - 1); + iz available = a->end - a->beg - padding; if (available < 0 || count > available / len) ASSERT(0 && "arena OOM\n"); void *p = a->beg + padding; @@ -74,11 +74,11 @@ alloc_(Arena *a, size len, size align, size count) } static Arena -sub_arena(Arena *a, size len, size align) +sub_arena(Arena *a, iz len, iz align) { Arena result = {0}; - size padding = -(uintptr_t)a->beg & (align - 1); + iz padding = -(uintptr_t)a->beg & (align - 1); result.beg = a->beg + padding; result.end = result.beg + len; arena_commit(a, len + padding); @@ -131,7 +131,7 @@ utf8_encode(u8 *out, u32 cp) } static UnicodeDecode -utf16_decode(u16 *data, size length) +utf16_decode(u16 *data, iz length) { UnicodeDecode result = {.cp = U32_MAX}; if (length) { @@ -175,7 +175,7 @@ arena_stream(Arena *a) } static Stream -stream_alloc(Arena *a, size cap) +stream_alloc(Arena *a, iz cap) { Stream result = {.cap = cap}; result.data = alloc(a, u8, cap); @@ -190,7 +190,7 @@ stream_to_s8(Stream *s) } static void -stream_reset(Stream *s, size index) +stream_reset(Stream *s, iz index) { s->errors = s->cap <= index; if (!s->errors) @@ -198,7 +198,7 @@ stream_reset(Stream *s, size index) } static void -stream_commit(Stream *s, size count) +stream_commit(Stream *s, iz count) { s->errors |= !BETWEEN(s->widx + count, 0, s->cap); if (!s->errors) @@ -206,7 +206,7 @@ stream_commit(Stream *s, size count) } static void -stream_append(Stream *s, void *data, size count) +stream_append(Stream *s, void *data, iz count) { s->errors |= (s->cap - s->widx) < count; if (!s->errors) { @@ -228,9 +228,9 @@ stream_append_s8(Stream *s, s8 str) } static void -stream_append_s8_array(Stream *s, s8 *strs, size count) +stream_append_s8_array(Stream *s, s8 *strs, iz count) { - for (size i = 0; i < count; i++) + for (iz i = 0; i < count; i++) stream_append(s, strs[i].data, strs[i].len); } @@ -347,17 +347,17 @@ c_str_to_s8(char *cstr) } /* NOTE(rnp): returns < 0 if byte is not found */ -static size +static iz s8_scan_backwards(s8 s, u8 byte) { - size result = s.len; + iz result = s.len; while (result && s.data[result - 1] != byte) result--; result--; return result; } static s8 -s8_cut_head(s8 s, size cut) +s8_cut_head(s8 s, iz cut) { s8 result = s; if (cut > 0) { @@ -368,7 +368,7 @@ s8_cut_head(s8 s, size cut) } static s8 -s8_alloc(Arena *a, size len) +s8_alloc(Arena *a, iz len) { return (s8){ .data = alloc(a, u8, len), .len = len }; } @@ -378,8 +378,8 @@ s16_to_s8(Arena *a, s16 in) { s8 result = {0}; if (in.len) { - size commit = in.len * 4; - size length = 0; + iz commit = in.len * 4; + iz length = 0; u8 *data = arena_commit(a, commit + 1); u16 *beg = in.data; u16 *end = in.data + in.len; @@ -400,11 +400,11 @@ s8_to_s16(Arena *a, s8 in) { s16 result = {0}; if (in.len) { - size required = 2 * in.len + 1; - u16 *data = alloc(a, u16, required); - size length = 0; + iz required = 2 * in.len + 1; + u16 *data = alloc(a, u16, required); + iz length = 0; /* TODO(rnp): utf8_decode */ - for (size i = 0; i < in.len; i++) { + for (iz i = 0; i < in.len; i++) { u32 cp = in.data[i]; length += utf16_encode(data + length, cp); } diff --git a/util.h b/util.h @@ -73,8 +73,8 @@ typedef uint64_t u64; typedef uint32_t b32; typedef float f32; typedef double f64; -typedef ptrdiff_t size; -typedef size_t usize; +typedef ptrdiff_t iz; +typedef size_t uz; typedef ptrdiff_t iptr; typedef size_t uptr; @@ -83,10 +83,10 @@ typedef size_t uptr; typedef struct { u8 *beg, *end; } Arena; typedef struct { Arena *arena; u8 *old_beg; } TempArena; -typedef struct { size len; u8 *data; } s8; +typedef struct { iz len; u8 *data; } s8; #define s8(s) (s8){.len = ARRAY_COUNT(s) - 1, .data = (u8 *)s} -typedef struct { size len; u16 *data; } s16; +typedef struct { iz len; u16 *data; } s16; typedef struct { u32 cp, consumed; } UnicodeDecode; @@ -213,7 +213,7 @@ typedef struct { u32 directory_watch_count; } FileWatchContext; -#define OS_ALLOC_ARENA_FN(name) Arena name(Arena old, size capacity) +#define OS_ALLOC_ARENA_FN(name) Arena name(Arena old, iz capacity) typedef OS_ALLOC_ARENA_FN(os_alloc_arena_fn); #define OS_ADD_FILE_WATCH_FN(name) void name(OS *os, Arena *a, s8 path, \ @@ -232,7 +232,7 @@ typedef OS_OPEN_FOR_WRITE_FN(os_open_for_write_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 OS_READ_FILE_FN(name) size name(iptr file, void *buf, size len) +#define OS_READ_FILE_FN(name) iz name(iptr file, void *buf, iz size) typedef OS_READ_FILE_FN(os_read_file_fn); #define OS_WAKE_THREAD_FN(name) void name(iptr sync_handle)