floooh / sokol-nim

nim bindings for https://github.com/floooh/sokol
MIT License
76 stars 14 forks source link

Todo Brain Dump #14

Closed floooh closed 2 years ago

floooh commented 2 years ago

NOTE: slices in Nim are quite useless for efficiently "slicing out" an array range, because the slice operation creates a copy. Maybe experimental views can help somehow: https://nim-lang.org/docs/manual_experimental.html#view-types

floooh commented 2 years ago

Rendering problems on my Ubuntu laptop (specific to Nim, doesn't happen in the C version):

In blend demo, the background is sometimes black, and sometimes the expected quads are shown but are not moving: Screenshot from 2022-06-27 20-59-50

In the MRT sample, the composed cube looks wrong (there composed cube doesn't have the RGB render targets shifted by offset): Screenshot from 2022-06-27 21-02-10

...looks like a problem with shader uniforms? => check code-generated structs!

floooh commented 2 years ago

...the shader uniform problem on Linux is somehow caused by the to_Range converter.

Basically this works:

sg.Range(pointer: vsparams.unsafeAddr, size: vsparams.sizeof.uint)

...but this doesn't:

sg.Range(fsqParams)

The second statement goes through the to_Range() converter function. This somehow results in a range struct with a pointer pointing to invalid data (dangling?).

...it's interesting that this is only a problem in rare cases... only on Linux, and only on small structs, maybe 16 bytes threshold?

Yep confirmed. Adding uniform block members so that the structs grows > 16 bytes changes the behaviour of

sg.Range(fsqParams)

Now the struct is no longer copied, and range pointer points to valid data :/

PS: Windows has the exact same problem in Release mode, but not in Debug mode (compiled with --cc:vcc, others not tested)

PPS: ...aaand it's also broken on macOS when compiling in release mode. The to_Range() converter needs to go :)