pygfx / pyshader

Write modern GPU shaders in Python!
BSD 2-Clause "Simplified" License
73 stars 1 forks source link

Dev #45

Closed almarklein closed 4 years ago

almarklein commented 4 years ago
Korijn commented 4 years ago

Also test that these work the same as in Python.

Does that mean some functions work differently than documented in spir-v?

almarklein commented 4 years ago

Also test that these work the same as in Python.

Does that mean some functions work differently than documented in spir-v?

The modulo operator has different flavours, and not all programming languages implement the same one. In Python, with % the result takes the sign of the second argument, whereas math.fmod takes the sign of the first argument. The latter is also referred to as the "remainder". SpirV supports both. What I meant is that I wrote tests to make sure that using % and math.fmod both work and produce the same result as in Python :)

Korijn commented 4 years ago

Alright, thanks for clarifying. Follow up question: is the default behaviour for % in spir-v the same as the Python behaviour for %?

almarklein commented 4 years ago

is the default behaviour for % in spir-v the same as the Python behaviour for %?

SpirV simply has OpFMod and OpFRem (and corresponding instructions for integers). There is no default.

Or maybe you mean what GLSL's default is? It also uses OpFMod, like Python.