Using DOTS/Havoc Physic for multithreaded raycasts

Hi.
My game has a built-in level editor with a visibility system.
To bake visibility it casts millions of rays in all directions.
I already know that UnityEngine PhysX is not thread-safe and Raycast can be called only from main thread.
So my question: is it possible to use DOTS or Havoc physic to create GameObject’s world clone only for performing ray casts using Burst Jobs (or any multithreaded) solution?

Sounds like you are building your own BSP (binary space partition) tree?

You can jobify this with RaycastCommand.

But since it’s your own level editor I would also suggest looking into other ways of optimizing. Particularly if the editor is grid-based or uses snapping you can significantly reduce the load by reasoning about your data.

Say you have a piece that’s a T junction then you know it only has certain directions where it can attach to other parts, and you can enforce the T junction design in such a way that it guarantees that one can’t see the vertical part of the “T” from the two horizontal entrances. Things like that can go a long way over multithreading a brute force solution.

Lastly, Havok is not available for free:

Havok Physics for Unity can be downloaded from the Unity Package Manager, but only Pro, Enterprise and UIC users have access to use the features at runtime.

Thanks a lot! It’s strange that RaycastCommand is not mentioned in the documentation of Raycast.
By the way - using it in the right way isn’t easy. Found solution here: Run RaycastCommand on multipleThreads?
In the synthetic test performance increase from 3 millions of raycasts per second to 15 on my Ryzen 9 7945HX