-
Notifications
You must be signed in to change notification settings - Fork 368
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
Modify testrender to work with triangle meshes #1865
Modify testrender to work with triangle meshes #1865
Conversation
Signed-off-by: Chris Kulla <[email protected]>
…inimal set of functions to have lit renders Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
… existing materials Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…of all triangles that share the same shader Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…de version which is not implemented in testrender Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…bals to visualize several fields of the shader globals, add basic dPdu and dPdv math Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…ntation for sphere primitives in previous version Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…ay bounces growing to infinity Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…p assist in manual scene setup Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
…s contain the ray origin Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
db90714
to
aa3ed58
Compare
…noise level Signed-off-by: Chris Kulla <[email protected]>
Signed-off-by: Chris Kulla <[email protected]>
Line 62 in src/testrender/CMakeLists.txt has Could you add (Probably not needed, but for purposes of debug only, you could add |
Signed-off-by: Chris Kulla <[email protected]>
Crossing my fingers that this will fix the icx issue. Chris, can you also look at the GPU test failure? (It's a build failure, not a run failure.) |
Oh, N/M, the GPU one is where you said that Tim's fix immediately after will address it, right? |
Yes, I'll open a PR for the OptiX fixes after this PR is merged. |
looks like it's still hitting assertions |
I am very tempted to merge this as-is, knowing that there will be icx test failures (or maybe you'd prefer to disable the render tests just for icx, for now?) and assume that we'll get to the bottom of it and soon have what will probably be a very small follow-on PR to directly address the issue. I think failing tests for one compiler is a lesser evil that entering Dev Days with this unmerged, since I think some people want to do work on testrender and it seems pointless for them to start with the obsolete code. What do you think, @fpsunflower ? |
I agree. I think its worth merging now and we can investigate further as a follow up. |
Signed-off-by: Chris Kulla <[email protected]>
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.
LGTM.
OK, merging! As a reminder, there are two outstanding issues here:
|
78e5392
into
AcademySoftwareFoundation:main
@timgrant You're up next! |
for (int y = 0; y < H; y++) { | ||
float t = float(y + 0.5f) / float(H); | ||
float z = cosf(t * float(M_PI)); | ||
float q = sqrtf(1 - z * z); |
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.
float q = sqrtf(1 - z * z);
So if z > 1.0 by even 1ulp, then sqrtf could result in a NAN.
The result of cosf could allow a certain # of bits accuracy which means it could have results slightly greater than 1.0f.
Please try clamping the input to 0.f
float q = sqrtf(std::max(0.f, 1 - z * z));
and see if you NAN issues go away.
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.
Sometimes in C++ I really miss OSL's "debug_nan" feature that will insert extra code around all math to 100% guarantee identifying the line in which a NaN first creeps in.
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.
I was just did source code review to find that, C library does not guarantee perfect accuracy, so some clamping is needed if feeding values into a NaN producing operation.
Would someone be willing to try that and re-enable icpx CI?
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.
Yeah, I will try right now!
This is a lesson we know well, that's why OIIO::safe_sqrt() exists!
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.
running now...
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.
I believe this is a smart change regardless, so I will submit the PR.
But I'm afraid it doesn't solve the problem. A number of tests still either time out (800 seconds!) or hit assertions. Only for icx.
Diagnosed the issue to be undefined behavior in the [] operator in |
Thanks for tracking that down! It's too bad that icx miscompiles this particular idiom. Also, I believe the same operator is used in the ray/triangle test, so perhaps there are more bugs lurking once this first one is fixed? |
I'm also wondering what the ideal way of expressing this idiom would be for icx? Is there a solution we could recommend for the Imath folks that would make all compilers happy? |
Wow, great detective work! That idiom is unfortunately used in a number of places in OpenEXR. I feel like I've run into that problem before, back when we were realizing that it had a hard time vectorizing those classes. I thought I remembered fixing it on the openexr side, but maybe not? What's the best way to fix that will not be UB? We should fix it in OpenEXR for sure. |
I mean Imath, not OpenEXR. |
Unfortunately, we also need a workaround on the OSL side, since we can't count on an Imath version being newer than whenever we can get it fixed there. |
It was an interesting experience! XD. I examined values of all locals in In it's current form, Imath's I will do a pass on all testrender files (including ray/triangle tests) to replace all occurrences of |
Replacing that memory access with a switch statement (I'm guessing?) seems like it will make things slower. I'll be curious to see the performance impact of the change. Is there any flag we could pass to icx for it to match the aliasing rules of the other compilers? |
Could you use a trick like
Or is that also the same kind of UB? |
@fpsunflower , Imath breaks C/C++ language aliasing rules, so its not an icx specific issue.
When an address of an object is taken, it is illegal/undefined behavior to use that pointer to access memory outside the sizeof the object. In this case the object is float x, yes it happens to be a data member, but the object type that lifetime is marked for is 4 bytes of a float. In practice what this means is a temporary Vec3 with x, y, z is considered as only having x be used and y and z might be removed. Later when &x[i] happens with i > 0, the data being accessed won't be there, undefined behavior. A simple correctness fix for this would be to take the address of the Vec3 object itself to mark all 12 bytes as potentially used, then cast to float to index.
There are many good reasons to not use dynamic indices, but that is a longer conversation |
We are literally talking about this and looking at this ticket at this moment in the OpenEXR/Imath TSC meeting. |
The As far as this particular issue goes, we could switch from using |
Belatedly catching up on this. I reposted the issue at AcademySoftwareFoundation/Imath#446 for wider discussion, comments there are welcome! |
Description
testrender was originally envisioned as a tiny example renderer that should only handle spheres/planes. Over time several groups have expressed the wish for it to handle arbitrary geometry instead. This PR replaces the sphere and quad primitives with triangle meshes.
I am making use of the (embedded) rapidobj library to load models in the
.obj
format. The original.xml
scene format remains, so that you can combine several models together as well as declare and assign the osl shader networks you want to these meshes. For backwards compatibility, spheres and planes are still supported via tessellation (you specify how many subdivisions you want). In the case of.obj
scenes, the shader assignment can be done either by the mesh name or the material name.I am submitting this to get the review kickstarted. The history of commits includes some fairly large test scenes that should be squashed away to go into the main repo. Files over 50Mb are recommended to use git lfs, but we probably want to figure that out as a different task (possibly handle it via a separate repo).
The handling of derivatives is not totally correct yet, but the behavior is compatible with the previous (incorrect) handling of derivatives we had before.
Tests
Existing tests are passing (I will push updated reference images shortly).
Checklist:
already run clang-format v17 before submitting, I definitely will look at
the CI test that runs clang-format and fix anything that it highlights as
being nonconforming.