A from-scratch implementation of a real-time path tracer using DirectX 12 compute shaders. Built to explore modern GPU programming, performance optimization, and the challenges of achieving interactive framerates with physically-based rendering.
Work in Progress - Currently evolving from a basic CPU ray tracer to a fully-featured GPU-accelerated real-time renderer.
I enjoy building graphics engines from the ground up to deeply understand how they work. This project explores:
- How to architect a real-time path tracer using DirectX 12
- Compute shader programming for ray tracing without DXR
- Performance optimization techniques to achieve interactive framerates
- Professional debugging and profiling workflows
- The trade-offs between quality and performance in real-time rendering
The goal is real-time performance (30-60 FPS) with progressive quality improvement, not offline high-quality renders.
- Low sample counts per frame (1-4 SPP)
- Progressive accumulation for static scenes
- Temporal reprojection for moving cameras
- Target: 30+ FPS at 1080p for moderately complex scenes
- Denoising to compensate for low sample counts
- DirectX 12 compute shaders (exploring both compute and DXR paths)
- Efficient resource and memory management
- Bounding Volume Hierarchies for acceleration
- Asynchronous compute for parallelism
- Comprehensive profiling with PIX and Windows Performance Toolkit
- GPU timeline analysis and bottleneck identification
- Memory usage optimization and budgeting
- Automated benchmarking for regression detection
- Proper error handling and validation (Debug Layer, GPU-Based Validation, DRED)
- Telemetry and metrics collection
- Security-conscious code (bounds checking, safe integer operations)
- Professional debugging infrastructure
- β Basic ray tracing foundation (ray class, sphere intersection)
- β Camera and viewport setup
- β Simple CPU-based reference implementation
- β PNG image output
- π§ DirectX 12 infrastructure (device, command queues, resources)
- π§ Compute shader ray tracing kernel
- π§ Performance profiling integration (PIX markers, GPU timestamps)
Transform the CPU path tracer to use DirectX 12 compute shaders for GPU acceleration.
Key Components:
- DX12 device initialization and resource management
- Descriptor heap management for shader resources
- Command queue and command list infrastructure
- HLSL compute shader for ray tracing
- Memory management with proper heap types (upload, default, readback)
- Synchronization using fences and resource barriers
Target: GPU-accelerated path tracer achieving 10x+ performance improvement over CPU baseline, maintaining interactive framerates.
Achieve and maintain real-time framerates with comprehensive performance measurement.
Key Components:
- Progressive accumulation system for quality convergence
- Temporal reprojection for camera movement
- Frame pacing and budget management
- PIX for Windows integration (GPU profiling and timeline analysis)
- GPU timestamp queries for precise timing
- Automated benchmark suite measuring FPS, frame time, and throughput
- Performance comparison: CPU vs GPU, naive vs optimized
Target: Consistent 30+ FPS at 1080p with progressive quality improvement for static scenes.
Scale to complex scenes while maintaining real-time performance.
Key Components:
- Bounding Volume Hierarchy (BVH) construction and traversal
- GPU-based BVH updates for dynamic scenes
- Async compute for overlapping work (compute + copy operations)
- Memory streaming and resource management under budget
- Shader optimization (thread divergence reduction, wave intrinsics, occupancy tuning)
- Comparison with DXR (DirectX Raytracing) if hardware available
Target: Handle 10K+ primitives at 30+ FPS, demonstrating O(log n) vs O(n) performance scaling.
Build reliability and maintainability into the codebase.
Key Components:
- Comprehensive error handling and validation (Debug Layer, GPU-Based Validation, DRED)
- Security best practices (bounds checking, integer overflow protection, input sanitization)
- ETW (Event Tracing for Windows) provider for system-level profiling
- Automated testing (unit tests for math/intersection, integration tests for DX12 init)
- Performance regression detection
- Documentation of architecture, API, and performance characteristics
Target: Zero warnings, zero leaks, robust error handling, professional code quality.
Push beyond basics to explore cutting-edge real-time rendering techniques.
Possible Directions:
- Denoising - Spatial and temporal denoising for low-sample-count renders (Intel OIDN integration)
- Advanced Materials - PBR materials (metallic, roughness, glass) with importance sampling
- Dynamic Scenes - BVH refitting and rebuilding for animated geometry
- Multi-GPU - Work distribution across multiple GPUs with cross-adapter synchronization
- Debugging Tools - WinDbg extension for inspecting GPU structures in crash dumps
- DXR Path - Implement parallel DXR version for comparison with compute shader approach
Target: At least one advanced feature that pushes the boundaries of real-time path tracing.
- DirectX 12 - Primary graphics API
- HLSL - Shader programming language
- C++23 - Modern C++ with latest features
- CMake - Build system
- GLM - Mathematics library for vectors and matrices
- stb_image_write - Image output (PNG format)
- vcpkg - Dependency management
- PIX for Windows - GPU profiling and debugging
- Windows Performance Toolkit - System-level performance analysis (ETW/WPA)
- WinPixEventRuntime - PIX markers in code
- Visual Studio Debugger - Primary debugger
- WinDbg - Advanced debugging scenarios
- DirectXTex (texture processing)
- D3D12 Memory Allocator (advanced memory management)
- Google Test or Catch2 (testing framework)
- Windows 10/11 (version 2004 or later)
- Visual Studio 2022 (17.8 or later)
- Windows SDK 10.0.22000.0 or later
- CMake 3.24 or later
- vcpkg (for dependency management)
# Clone the repository
git clone <repository-url>
cd pathtracer
# Configure with CMake
cmake --preset=default
# Build
cmake --build build --config Release
# Run
./build/bin/Release/pathtracer.exe- Debug - Full debug information, all validation enabled
- Release - Optimized build for performance testing
- Profile - Release optimizations with PIX integration
- Instrumented - ETW provider enabled for system-level profiling
Target metrics for a successful real-time path tracer:
| Metric | Target | Measured |
|---|---|---|
| Frame Time (1080p, 1K spheres) | < 33ms (30 FPS) | TBD |
| Frame Time (1080p, 10K spheres w/ BVH) | < 33ms (30 FPS) | TBD |
| Ray Throughput | > 1 billion rays/second | TBD |
| Memory Usage | < 512MB for typical scene | TBD |
| Startup Time | < 1 second to first frame | TBD |
| Convergence Time (static scene) | < 5 seconds to clean image | TBD |
Hardware Target: Modern gaming GPU (NVIDIA RTX 3060 / AMD RX 6600 or better)
Quality vs Performance Trade-offs:
- 1-4 samples per pixel (SPP) per frame
- Progressive accumulation when camera is static
- Denoising to maintain visual quality with low SPP
- Adaptive quality based on frame budget
- ARCHITECTURE.md (coming soon) - System architecture, design decisions, and data flow
- PERFORMANCE.md (coming soon) - Performance analysis, benchmarks, and optimization results
- BUILD.md (coming soon) - Detailed build instructions and troubleshooting guide
pathtracer/
βββ src/ # Source code
β βββ core/ # DX12 device and resource management (planned)
β βββ rendering/ # Path tracing implementation (planned)
β βββ profiling/ # PIX and ETW integration (planned)
β βββ main.cpp # Entry point
βββ include/ # Header files
β βββ interfaces/ # Abstract interfaces
β βββ ray/ # Ray and camera
β βββ shapes/ # Geometric primitives
β βββ utils/ # Utilities
βββ shaders/ # HLSL compute shaders (planned)
βββ tools/ # Benchmark and analysis tools (planned)
βββ tests/ # Unit and integration tests (planned)
βββ docs/ # Documentation (planned)
βββ scenes/ # Scene description files (planned)
βββ CMakeLists.txt # CMake configuration
βββ vcpkg.json # Dependencies
βββ README.md # This file
βββ IMPLEMENTATION.md # Detailed implementation guide
This project draws inspiration and knowledge from:
- Ray Tracing in One Weekend - Foundation for ray tracing concepts
- Microsoft DirectX 12 Documentation
- 3D Game Programming with DirectX 12 by Frank Luna
- Physically Based Rendering - Advanced rendering techniques
- Learning DirectX 12 by Jeremiah van Oosten
This is currently a personal portfolio project and is not accepting contributions. However, feedback and suggestions are welcome via issues.
This is a personal learning project and I'm not accepting pull requests at this time. However, feedback, suggestions, and discussions are always welcome! Feel free to open an issue if you spot a bug, have an optimization idea, or want to discuss rendering techniques.
MIT License - See LICENSE file for details
- Peter Shirley's "Ray Tracing in One Weekend" series for the excellent foundation
- Microsoft for comprehensive DirectX 12 documentation and PIX profiling tools
- The graphics programming community for openly sharing knowledge and techniques
- pbrt for deep insights into physically-based rendering
Note: This project is under active development and the architecture will evolve significantly as I work through the phases. Performance numbers will be updated as optimizations are implemented and measured.