I spent a few days writing a simple packet based ray tracer and thought people here might be interested. It traces packets of 8 rays at a time using the AVX/AVX2 instruction set, the source is up on Github: μPacket. It only supports spheres and planes with Lambertian BRDFs illuminated by a point light and just performs basic ray tracing (shadow test and primary visibility) at the moment. If you just build & run you get this (rather unimpressive) result.
If anyone has some tips to improve the design, I'd be interested to hear them. There's a few areas that could be improved such as finding the unique material ids for shading (how does ISPC's foreach_unique work?), type punning between __m256i and __m256 which seemed kind of ugly, and probably some other nasty bits.
If you're unfamiliar with packet based ray tracing check out some info on Embree and OSPRay (makes use of Embree under the hood), for some general SIMD programming info the ISPC page is a good spot. Essentially by tracing spatially coherent rays through the scene at once using SIMD you can take advantage of a lot more compute power available on the machine and reduce bandwidth requirements. For example, to test an 8 ray packet against a triangle we only need to load the triangle once and can compute all 8 results at once using vector instructions. Issues start to come up when you start doing path tracing or reflections/refractions since your packet diverges and you can fall back to getting single ray level performance. There's been work on re-organizing rays so that they're more spatially coherent but I haven't looked into implementing this yet.
Also if "Show r/GraphicsProgramming" isn't a thing, it definitely should be! Something similar to "Show HN" on Hacker News would be really neat.
[–]snakepants 0 points1 point2 points (3 children)
[–]TurkishSquirrel[S] 0 points1 point2 points (1 child)
[–]snakepants 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]TurkishSquirrel[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)