Performance Speed Up (~5x): Implement adaptive step raytracing & stabilize N-body physics - #45
Open
Quercius wants to merge 2 commits into
Open
Performance Speed Up (~5x): Implement adaptive step raytracing & stabilize N-body physics #45Quercius wants to merge 2 commits into
Quercius wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR significantly improves the overall performance of the simulation. By replacing the fixed-step integration in the compute shader with an adaptive approach and fixing the$O(N^2)$ gravity hot loop on the CPU, the rendering time has been cut by ~79%, yielding a ~4.7x speedup.
Key Changes
1. GPU Compute Shader (
geodesic.comp)D_LAMBDAstep with a dynamically scaled step (current_dL). Rays far from the black hole take massive leaps, clamping to high-precision microscopic values (MIN_STEP) only when approaching extreme curvature.ESCAPE_Rto a realistic bound (1e12) and implemented an early exit for escaping rays (ray.r > ESCAPE_R && ray.dr > 0.0). This instantly kills rays heading into deep space, massively reducing Warp/Thread divergence.2. CPU Physics Engine (
black_hole.cpp)totalAccelvector before applying velocities/positions.dt): Physics updates are now scaled by delta time, making the simulation framerate-independent.std::vector) and blocking I/O (std::cout) from the gravity hot loop, replacing them with stack-allocatedglm::dvec3.Performance & Benchmarks
Based on a 60-second weighted average sampling: