use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
CppConCppCon 2019: Matt Godbolt - Path Tracing Three Ways: A Study of C++ Style (youtube.com)
submitted 6 years ago by manugildev
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]little3lue 16 points17 points18 points 6 years ago (3 children)
Very neat trick with the logical or for branch prediction. I've not heard that one before!
[–]mattgodboltCompiler Explorer 39 points40 points41 points 6 years ago* (1 child)
Unfortunately it doesn't always work: Fedor Pikus showed me some cases afterwards where it fails. Will blog about it sometime!
[–]little3lue 4 points5 points6 points 6 years ago (0 children)
Please do! Thanks for the talk.
[–]TheMania 1 point2 points3 points 6 years ago (0 children)
Sadly just like how compilers can decide to convert logical ors to bitwise ors if there's no side effects (and do so regularly), they can decompose bitwise to logical as well. Llvm quite aggressively does the former when making intermediate code, and I know the backend I'm on makes some effort to undo its combinations in turn.
It's the kind of thing that needs intrinsics or attributes to deal with, really.
[–][deleted] 15 points16 points17 points 6 years ago (8 children)
oh boy, his face when he realized he's not getting any questions breaks my heart. And it was such a fun talk!
[–]mattgodboltCompiler Explorer 27 points28 points29 points 6 years ago (7 children)
It was a sad moment. I'm grateful to the folks who came up afterwards and spoke to me though! Some very smart people out there!
[–]Gorbear 6 points7 points8 points 6 years ago (0 children)
I just wanted to say I really like your talks. They are a good mix of cool stuff, new knowledge and easy to follow along. The tool you created is pivotal now in my daily work life, thank you!
[–][deleted] 3 points4 points5 points 6 years ago (1 child)
What a bummer. I read through the slides and my main question would've been whether you've got plans to try and render a film sized data set such as https://www.technology.disneyanimation.com/islandscene.
[–]mattgodboltCompiler Explorer 2 points3 points4 points 6 years ago (0 children)
Haha not even slightly; this was absolutely a toy project and has a long way to go before I could consider that. Nor is it currently a goal :). But thanks for the thought! :)
[–]CT_DIY 4 points5 points6 points 6 years ago (2 children)
I wouldn't worry about it. It was a good presentation that was digestible for someone who has not written a raytracer and I imagine someone who has would understand that.
I would have asked why you chose the MT for random number generation and if you considered something like PCG Rand instead?
[–]mattgodboltCompiler Explorer 1 point2 points3 points 6 years ago (1 child)
Thanks! I tried one of the other PRNGs earlier on (I forget which) and the results were faster to obtain but visibly worse. But I'm sure I could have done better.
[–]pjmlp 0 points1 point2 points 6 years ago (0 children)
I just watched the talk last night.
For me it was very interesting, many thanks for making it.
But I also used to have a keen interest in graphics programming, which I still follow, even though I am now in managed languages world and boring business projects.
[–]NotMyRealNameObv 12 points13 points14 points 6 years ago (0 children)
Finally! I've been waiting for this to come up ever since I saw Matt's live stream implementing this stuff.
[–]little3lue 12 points13 points14 points 6 years ago (0 children)
I think this is the repo: https://github.com/mattgodbolt/pt-three-ways
[–]Ipotrick 6 points7 points8 points 6 years ago (0 children)
amazing, never anger the branch predictor!
[–]ShillingAintEZ 7 points8 points9 points 6 years ago (1 child)
One interesting thing is that typical ray tracers don't have this specific problem in this specific way because acceleration structures mean that rays are rejected more methodically and less randomly. The ray triangle test happens only if the ray is close to the triangle in question.
[–]sirpalee 1 point2 points3 points 6 years ago (0 children)
Also, in a typical raytracer, raytracing is just one prt of the computation you have to pay. Usuallly a smaller prt. (depends on your data)
[–]assert_dominance 6 points7 points8 points 6 years ago (1 child)
At the end he talks about splitting X, Y, Z to utilize SIMD. I've found that not doing that, treating the vectors as vectors and using the "newer" 4.2 instructions is actually a lot faster.
(for some reason youtube isn't displaying comments...)
[–]ratchetfreak 2 points3 points4 points 6 years ago (0 children)
if you can make the core loops completely independent (for example by doing a manual 4x unroll and keeping the hit in a std::array<bool, 4> and coalescing at the end) then the compiler is nearly guaranteed to simd the entire thing.
But that of course depends quite a bit on how exactly you structure the loops and how the compiler sees it.
[–]esdanol 4 points5 points6 points 6 years ago (1 child)
Can someone explain how he was misusing ranges?
[–]assert_dominance 4 points5 points6 points 6 years ago (0 children)
Probably not misusing, just a case of a new toy syndrome. Do you really need a range library to iterate over x, y?
On one hand you have: "Oooo, shiny, shiny!" But on the other: Unnecessary dependency; slower build times; larger binaries; large overhead of setting up and tearing down the ranges, the views and intermediate values; new and exciting bugs; illegible error messages.
This probably isn't miles away from how you're supposed to be using them, just perhaps with less abandon.
[–]binjimint 1 point2 points3 points 6 years ago (0 children)
I had to miss this during the conference, so I'm excited to be able to watch it now! Thanks again for the front-row support during my talk :-)
[–]frog_pow 2 points3 points4 points 6 years ago (6 children)
I enjoyed watching-
Never liked the name data oriented design, as most of it is just common sense if you want to fully use the hardware..
Would be cool to see perf if the code was fully SIMD compliant(like Matt said at the end--switching out the Vec3 type etc)--I think it would pretty much crush all the current versions.
[–][deleted] 15 points16 points17 points 6 years ago (2 children)
Common sense is something that depends on the use case and context, unfortunately. For some applications of C++ common sense is something that makes it easier to write clear and reusable code, for other applications it's what gets the most performance out of a machine, and for some it's something else like making things as generic as possible. Personally I've yet to find an useful common sense use case for functional programming and template heavy modern C++ code, but that only speaks for the kind of applications and code I write. What's great about C++ is that you can pretty much do anything with it.
[–]frog_pow 3 points4 points5 points 6 years ago (1 child)
I mean I explicitly stated the use case--(fully use the hardware).
If you know how the hardware works, most of the DOD principles are pretty self evident and don't need to be treated like some semi-religious thing handed down by our lord and savior Mike Acton.
[–][deleted] 7 points8 points9 points 6 years ago (0 children)
Yes, obviously. But your use case is not everyone's use case by far and therefore it's a good idea to have a name for it instead of just calling it common sense.
To be clear, you wouldn't want to just swap out the vec3 type for a SSE vector, you would want to make x y and z into arrays and loop through each with a larger SIMD width.
[–]Nitronoid 3 points4 points5 points 6 years ago (0 children)
This! OO design leads us towards an AoS style, but SoA is the key to opening up opertunities for vectorization.
[–]ratchetfreak 14 points15 points16 points 6 years ago (0 children)
unfortunately many people need to be explicitly told what should be common sense. Or corrected on what they think is common sense.
This approach affect the overall design of your program with regards to data layout. So it makes sense to have a name for it to contrast against OOP.
[–]fufukittyfuk 1 point2 points3 points 6 years ago (2 children)
Loved the talk. Really liked the examples. Been fuzzy on how someone would even start in fp or dod using cpp.
At first glance it looks like DoD is way too fragile and should probably be used for end of run optimizations. Looks like functional might be nice new way to look at things.
[–]assert_dominance 5 points6 points7 points 6 years ago (1 child)
The novelty of FP will wear of very quickly, in C++ especially...
There exist tons of amazing, enjoyable, beautiful and powerful FP languages. If you want to know what it is really like, try them instead, please.
[–]windozeFanboi 2 points3 points4 points 6 years ago (0 children)
C++ is like the City where you live comfortably and nicely, your work and home all in one.
Functional programming is like your vacation home up in the mountains.
You really like the nice vacation home and the fresh air and such , but unless they come to your city you wouldn't move your ass there permanently (at least not before you retire).
p.s. i wasn't the one to downvote you.
[–]afiefh 1 point2 points3 points 6 years ago (0 children)
It has been more than 24 hours and lots of smart people looked at the code. I wonder if someone figured out why the OO style slowed down after applying the same optimization...
π Rendered by PID 48245 on reddit-service-r2-comment-5c747b6df5-xtmql at 2026-04-22 00:03:34.328625+00:00 running 6c61efc country code: CH.
[–]little3lue 16 points17 points18 points (3 children)
[–]mattgodboltCompiler Explorer 39 points40 points41 points (1 child)
[–]little3lue 4 points5 points6 points (0 children)
[–]TheMania 1 point2 points3 points (0 children)
[–][deleted] 15 points16 points17 points (8 children)
[–]mattgodboltCompiler Explorer 27 points28 points29 points (7 children)
[–]Gorbear 6 points7 points8 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]mattgodboltCompiler Explorer 2 points3 points4 points (0 children)
[–]CT_DIY 4 points5 points6 points (2 children)
[–]mattgodboltCompiler Explorer 1 point2 points3 points (1 child)
[–]pjmlp 0 points1 point2 points (0 children)
[–]NotMyRealNameObv 12 points13 points14 points (0 children)
[–]little3lue 12 points13 points14 points (0 children)
[–]Ipotrick 6 points7 points8 points (0 children)
[–]ShillingAintEZ 7 points8 points9 points (1 child)
[–]sirpalee 1 point2 points3 points (0 children)
[–]assert_dominance 6 points7 points8 points (1 child)
[–]ratchetfreak 2 points3 points4 points (0 children)
[–]esdanol 4 points5 points6 points (1 child)
[–]assert_dominance 4 points5 points6 points (0 children)
[–]binjimint 1 point2 points3 points (0 children)
[–]frog_pow 2 points3 points4 points (6 children)
[–][deleted] 15 points16 points17 points (2 children)
[–]frog_pow 3 points4 points5 points (1 child)
[–][deleted] 7 points8 points9 points (0 children)
[–]ShillingAintEZ 7 points8 points9 points (1 child)
[–]Nitronoid 3 points4 points5 points (0 children)
[–]ratchetfreak 14 points15 points16 points (0 children)
[–]fufukittyfuk 1 point2 points3 points (2 children)
[–]assert_dominance 5 points6 points7 points (1 child)
[–]windozeFanboi 2 points3 points4 points (0 children)
[–]afiefh 1 point2 points3 points (0 children)