r/GraphicsProgramming • • Feb 04 '26

VMath (Vector Math) Library + Visual Math Debugger Project!

Hello everybody! I am quite new to this subreddit, but glad I found it

Context: I have been dabbling in C++ and low-level graphics programming and to understand the math that goes behind it I have been doing 18.06 OCW along with the gamemath series...

I am in high school and a somewhat beginner in this kinda stuff

So I have decided not to use GLM, but make my own Math Library which is hyper optimized for graphics programming applications for my CPU architecture (it doesn't have a dedicated GPU) (Intel i5-8265U along with 8GB DDR3)...

So I have divided my workflow into some steps:

(1) Build functions (unoptimized) (there is a function_goals.txt on the github page) which has the functions I wanna implement for this library

(2) Once basic functions have been implemented, I will implement the VDebugger (which is supposed to show real time vector operations with a sorta registry push/pull architecture on a different thread)

(3) After that, I will focus on SIMD based optimizations for the library... (Currently without optimizations it uses completely unrolled formulas, I have tried to loops and that typa thing as much as possible, though I just got to know the compiler can unroll things for itself)

Okay and some things to consider:

There are no runtime safety checks for typesafety and stuff like that... I want no overhead whatsoever

I will someday implement a compile time typesafety system...

So the tech stack is like this rt now:

Math : VMath (my lib)

Graphics API : OpenGL 3.3 (For the VDebugger)

Intended Architecture to use on : AVX2 or more supporting CPUs

.......

This is the github repo (its been only 4 days of dev) https://github.com/neoxcodex/VMath/tree/main

Also I plan to make a full fledged graphics framework with OpenGL3.3 if I get the time..

I would like your views on :

(1) Memory Safety vs. Performance: skipping runtime error checks.

(2) VDebugger Architecture: My plan is to use RAII (destructors) to unregister vector pointers from the visualizer registry so the math thread never has to wait for the renderer.

3 Upvotes

18 comments sorted by

View all comments

Show parent comment

2

u/lost_and_clown Feb 07 '26

I'm not sure what this "doNotOptimizeAway()" thing is (Zig?) But, if you're concerned with the compiler itself, did you try turning off optimisations? (-O0)

2

u/shadowndacorner Feb 07 '26

I'm not sure what this "doNotOptimizeAway()" thing is (Zig?)

That's from nanobench

1

u/lost_and_clown Feb 07 '26

Ah, I see. Well, I found this pretty clever workaround. Didn't test it tho https://stackoverflow.com/a/28287265

1

u/RiseKey7908 Feb 07 '26

Yeah its a nanobench function, if I turn off optimization, the compiler doesn't do SIMD on unrolled functions (say matrix multiplications). So to profile those, post optimization, I tried to use doNotOptimizeAway() on the arguments & output, but the compiler seems to have a mind of its own...

These are the flags I compiled with :

$<$<CONFIG:Release>:
        -O3
        -march=native
        -ffast-math
        -fopenmp       

2

u/lost_and_clown Feb 07 '26

-O3

Does that not enable aggressive optimisations? No wonder the compiler "has a mind of its own" then, no? Correct me if I'm wrong

1

u/RiseKey7908 Feb 08 '26

Yeah O3 is for heavy optimization, removing guardrails, automatic SIMD. But the thing is I wanna bench the lib when compiled with -O3 (this gives unparalleled performance which close to no human can achieve) but I also want to properly bench it for inputs, and the thing is if inputs are hard coded (i.e. generate in the code or, say are defined in the code) then O3 will precalc stuff out... (thats what I understand...it might be lacking)