-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add round node to data libraries #1678
Add round node to data libraries #1678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, @ld-kerley, and I'm CC'ing @crydalch who brought up the need for this node in #1365.
Thanks @jstone-lucasfilm, and thank you @ld-kerley for the PR this looks great! There was some discussion previously, when the issue was first raised, about the questions of the Does Apart from the consistency question, this looks awesome. Thank you for adding this node! |
Thanks for putting this together, @ld-kerley, and in order to resolve the ambiguity of the 0.5 input case, one option would be to specify that we expect https://registry.khronos.org/OpenGL-Refpages/gl4/html/roundEven.xhtml This would then become the expected behavior for the MaterialX |
@jstone-lucasfilm are you suggesting that we would impose the |
@ld-kerley I wouldn't propose that we change the meaning of the In GLSL, for example, the The Do you know if OSL has a corresponding resolution to the issue of ambiguous behavior when the fractional component is exactly 0.5? |
To bring some of the OSL specification language into the conversation, here is how it specifies its
Do you happen to know how this function handles the case when the fractional component is exactly 0.5, so that neither the upper or lower integer is technically closer? |
Bringing another reference point into the discussion, here is how MSL (Metal Shading Language) defines their
https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf This matches the definition of
|
OSL implements it as std::roundf, which says
|
So it looks like OSL and MSL both were constructed to match C/C++ round. |
I will clarify the OSL docs to reflect what it does in practice. In general, the OSL philosophy was that whenever there is a standard library function that appears to be analogous to an identically named C stdlib function, its behavior under "safe" conditions should match C unless there is a very compelling reason to deviate. (An example of safe/unsafe deviation from C is that acos(x > 1.0) will return NaN and raise a floating point exception in C, but in OSL it will behave as if its input was clamped to [-1,1] so as to not introduce any NaNs into the shader.) |
Thanks for confirming, @lgritz, and this sounds like the right choice for MaterialX as well. Although the GLSL implementation of Later on, we can refine the GLSL implementation to exactly match the behavior of OSL and MSL, and can additionally check with NVIDIA to make sure MDL aligns with this behavior as well. |
I might have some insight about why OpenGL likes roundEven. Looking in OIIO's simd.h header, I see the following interesting comment that I wrote many years ago:
So this implies that it may be common for hardware to implement "even" rounding directly as a single instruction, but matching C is lightly more expensive by requiring multiple instructions (at least on x86, maybe on certain GPUs too?). So if you don't particularly care about the specifics of how the rounding works at i+0.5 values, "even" may be slightly more efficient. |
4caca37
to
e5cf200
Compare
I just rebased on top of the recent MDL versioning changes - it would be great if someone could just validated I updated in the way that's intended. I don't have a mechanism to validate MDL changes currently. Perhaps @krohmerNV ? |
you missed the package names (I made it more explicit with the changes you mentioned)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks @ld-kerley!
4eadb47
into
AcademySoftwareFoundation:main
Mirror the existing ceil node definition.
This is now being submitted for inclusion in
main
- previous PR (#1661) closed