This video features a "code review" of a submitted Vulkan ray tracing engine project named "Ruby." The presenter chronicles the extensive debugging process required to get the non-functional project to build and run, highlighting common pitfalls in graphics programming.
Key issues identified and resolved include incorrect shader compilation paths, misconfigured working directories, improper binary file reading, and critical logical errors within the camera's matrix calculations (e.g., the view matrix function returning the projection matrix). The presenter also addresses uninitialized variables and an incorrect aspect ratio calculation due to integer division. Debugging strategies involve visual inspection, implementing a camera debug UI, and utilizing external tools like NVIDIA Nsight Graphics to inspect GPU-side data structures.
Despite the significant initial challenges and "bodges" found in the submitted code, the video successfully demonstrates the process of identifying and rectifying these errors, ultimately achieving a functional (albeit basic) ray-traced cube visualization.
Debugging and Fixing a Vulkan Ray Tracing Engine
0:00 Initial Frustration & Series Introduction: The presenter begins by expressing disbelief that the submitted project, a Vulkan ray tracing engine, "never worked" and required significant debugging. He introduces the "code review" series and the specific project, "Ruby."
0:27 New Setup for GPU Access: A dedicated new computer is used for code reviews requiring direct GPU access (e.g., Vulkan), as setting this up in a VM is difficult.
0:48 Project Background: The "Ruby" project, created by Alexander from Sweden, is a 7-month-old open-source ray tracing engine built in C++ with Vulkan requirements, using CMake. The author specifically requested a thorough code roast.
2:46 Sponsor Spotlight: Code Rabbit: The video is sponsored by Code Rabbit, an AI-driven automatic code reviewer that provides contextual feedback, highlights bugs and security issues, and offers suggestions. It integrates with GitHub/GitLab and has a VS Code plugin for pre-commit review.
5:32 Security Precautions: Before running external code, the presenter details security measures taken, including unplugging from the internet, using a fresh Windows install, and planning to re-image the hard drive.
6:12 Initial Build Failures: The project fails to build due to incorrect output paths for compiled shaders (expecting a "release" directory in "debug" build) and the shader compiler not creating necessary folders.
9:30 Runtime Errors & Working Directory Fix: After fixing build paths, the project fails to load assets at runtime because the working directory was incorrect. The working directory was updated to match where assets and shaders were placed.
11:00 Critical Binary Read Error: A significant error is discovered where binary shader files are not being read correctly because std::ios::binary was not specified when opening the input file stream. This was a common C++ I/O mistake.
13:21 Initial Gray Screen & Shader Review: The project now runs but displays a gray screen because the "miss" shader (when a ray doesn't hit geometry) sets the color to gray. The "closest hit" shader sets the color to white.
14:15 Suspicious Ray Generation: The ray generation logic in the shader is suspected because the view and projection matrices were not inverted, a common requirement for ray tracing calculations.
18:41 Lack of Camera Control for Debugging: The inability to control the camera is identified as a major debugging hindrance, as it prevents exploring the scene to find hidden geometry.
24:40 Implementing Camera Debug UI: A simple ImGui UI element is added to allow manual adjustment of the camera's position, facilitating debugging. The automatic camera movement is commented out.
28:50 Using Nsight Graphics for GPU Debugging: NVIDIA Nsight Graphics is used to inspect the Vulkan acceleration structure, confirming that a 2x2 meter cube geometry is correctly loaded.
31:44 Major Bug: Incorrect Camera Matrix Retrieval: The most critical bug is discovered: camera.GetView() function was incorrectly returning the projection matrix instead of the view matrix.
33:05 Uninitialized Camera Variables: The camera's yaw and pitch variables were uninitialized in certain constructors, leading to an incorrect initial orientation.
33:56 Incorrect Aspect Ratio Calculation: The aspect ratio for the projection matrix was incorrectly calculated due to integer division (width / height where both are integers), resulting in a distorted image.
34:49 Project Functional: With all major issues resolved, the cube now renders correctly with the proper aspect ratio and can be viewed from different angles using the debug UI.