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 support for stream of rays in Embree #29
Comments
@mariuszhermansdorfer thanks for taking the time to provide the links. If you could let me know which configuration you think is the most beneficial speedup for you application I can make a specific function/interface for it (assuming you don't want to add one in the C++ source yourself). If it does give some meaningful performance difference i'll try to roll out the interface as you suggested into its own function (explanation below). There are a few aspects to adding these to the core API: Speed:
Explaining the above two items is difficult for most users and can end up in confusion or worse performance. From your other issue I see the application to sun study, so if there is a meaningful speedup for that type of thing we could also make a specific extension/function for it. Clarity/Flexibility:
|
Thanks for your detailed answer @cadop. As you might imagine, the reason I asked for these additional modes is speed. If it turns out that using ray streams doesn't come with any speed benefit at all, I would be the first one to remove it. Currently, I'm working on a sunlight analysis. It takes the following inputs:
From the context a bvh is created. From my understanding, this scenario could benefit from shooting rays with the Again, it'd need to be benchmarked to know for sure. |
Just to make sure, you are using this function? https://cadop.github.io/dhart/C%23%20Public%20Docs/html/class_d_h_a_r_t_a_p_i_1_1_ray_tracing_1_1_embree_raytracer.html#a1a96d5b61f43fe87e2649ef612dd63ff and only passing one direction (inverse sun vector) based on:
You could also try to duplicate the the origins into one large vector for using this version:
This would take more time in generating data in C#, but would mean there is only one call to dhart and all rays would be parallelized. I'm not sure if it would be faster. Could you also make sure that system monitor shows multiple cores being used and its not single threaded, and how much time is the raycasting 500k cells taking? The example you give does seem to be the ideal case for coherent rays. I will make an example within the next week or so to test this out. So the plan is:
|
Yes, I’m using this function and pass an array of origins (500k points) and one reverse sun vector at a time. This code runs in parallel as all the CPU get 100% load. _analysisPoints = new List<Point3d>();
_sunDirections = new List<Vector3d>();
DA.GetDataList(0, _analysisPoints);
DA.GetData(1, ref _context);
DA.GetDataList(2, _sunDirections);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
MeshInfo contextMesh = new MeshInfo(_context.Faces.ToIntArray(true), _context.Vertices.ToFloatArray());
LogTime(sw, "Initial setup");
EmbreeBVH bvh = new EmbreeBVH(contextMesh);
LogTime(sw, "Setup bvh");
Vector3D[] sunDirections = ConvertListOfVectors(_sunDirections);
Vector3D[] analysisPoints = ConvertListOfVectors(_analysisPoints);
LogTime(sw, "Data conversion");
for (int i = 0; i < sunDirections.Length; i++)
EmbreeRaytracer.IntersectOccluded(bvh, analysisPoints, new Vector3D[] { sunDirections[i] });
LogTime(sw, "Embree Ray casting"); The code is quite fast already - here is a test with 100k points and only one sun vector. Embree is 5x faster than native Rhino ray cast: Do you have Rhino on your machine? I will put this test file into the dedicated branch so that we have a common base for benchmarks. |
Hey @mariuszhermansdorfer , yes I have rhino, and thanks for showing these results. It seems the first was is 50x faster than rhino. Would you mind making a Discussion on the performance and just mention this issue. I'd like to keep the conversation going in a more longterm format instead of within the issue of ray streaming. I am not sure about getting to 30fps, which would be ~33ms. I'll followup more on the discussion post for some ways to check bottlenecks since there is some data transfer between c#, c interface, and c++. |
Currently, DHART only shoots single rays with the
rtcOccluded1
method:dhart/src/Cpp/raytracer/src/embree_raytracer.cpp
Lines 621 to 626 in d7eefe6
Embree, however, supports shooting streams of rays in various configurations:
rtcOccluded1M
rtcOccluded1Mp
rtcOccludedNp
Furthermore, 3 flags can be passed to the intersection context to speed up ray traversal:
https://spec.oneapi.io/oneart/latest/embree-spec.html#rtcinitintersectcontext
enum RTCIntersectContextFlags { RTC_INTERSECT_CONTEXT_FLAG_NONE, RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT, RTC_INTERSECT_CONTEXT_FLAG_COHERENT, };
It would be great if these could be added to the c# wrapper as well.
The text was updated successfully, but these errors were encountered: