Ray Tracing with HIP on AMD GPUs
- Ray tracing using HIP is a technique for photorealistic rendering that couples AMD's HIP programming model with HIPRT's hardware-accelerated ray tracing.
- It employs robust acceleration structures like BVH and AABB to optimize primitive intersection calculations and enhance scalability.
- Advanced memory management and hardware-specific optimizations on AMD GPUs yield significant performance improvements, achieving up to 2× faster traversal.
Ray tracing using HIP refers to the implementation of high-performance ray-tracing algorithms on AMD GPUs through the Heterogeneous-compute Interface for Portability (HIP), with additional acceleration via the HIP Ray Tracing (HIPRT) framework. HIP provides a platform-agnostic, C++-like API for direct GPU programming, while HIPRT exposes hardware raytracing support in newer AMD architectures. The workflow covers foundational geometric computations, BVH construction and traversal, and device-specific optimization techniques for scalable photorealistic rendering (Yoshimura et al., 27 Feb 2026).
1. Geometric Fundamentals of Ray Tracing
Ray tracing is founded on mathematical formalisms for modeling ray–primitive intersections. A ray is defined parametrically as
where is the origin and the direction (typically unit length).
Primitive Intersection:
- Sphere: For a sphere centered at with radius , the condition
yields a quadratic in when substituting . The discriminant
with
determines the presence of real intersections: 0.
- Triangle: For triangle vertices 1, using the normal 2, the intersection parameter is
3
and point-in-triangle is verified with three edge tests:
4
with 5. Listing 1 in the source report provides the device implementation.
2. Hierarchical Acceleration Structures
Efficient ray tracing depends critically on robust acceleration structures. The principal data structure is the Bounding Volume Hierarchy (BVH).
- AABB: Each node comprises 6 and 7. Ray–AABB intersection is performed in 8 via the slab method.
- BVH Construction: Typically binary or 9–0-ary; leaf nodes store primitives, internal nodes encapsulate child AABBs.
- Split Strategy: The Surface Area Heuristic (SAH) guides node splitting to minimize
1
where 2 is surface area. The standard top-down recursive build (see pseudocode in the data) partitions primitives at each node by choosing a split minimizing 3.
- Traversal: Closest-hit traversal evaluates intersections recursively, always descending into children whose AABBs intersect the ray, visiting leaf nodes to test primitives directly.
3. HIP Programming Model and Memory Semantics
HIP exposes explicit control over GPU memory and kernel launch configuration.
- Memory Allocation and Transfer:
- Allocate device memory:
hipMalloc(&d_ptr, size) - Copy to device:
hipMemcpy(d_ptr, h_ptr, size, hipMemcpyHostToDevice) - Free device memory:
hipFree(d_ptr)
- Allocate device memory:
- Kernel Dispatch and Synchronization:
- Create streams:
hipStreamCreate(&stream) - Launch kernels:
hipLaunchKernelGGL(kernel,..., stream,...) - Synchronize:
hipStreamSynchronize(stream)orhipDeviceSynchronize()
- Create streams:
- Device Query:
- Get device count:
hipGetDeviceCount(&n) - Get properties:
hipGetDeviceProperties(&props,dev)
- Get device count:
Orochi wrappers may be used for raw context/device queries, relevant when interoperating with HIPRT.
4. HIPRT Framework and API Workflows
HIPRT provides high-performance ray tracing on AMD hardware, abstracting BVH construction and leveraging the ray accelerator units on RDNA2/3 GPUs.
- Context Creation:
0
- BVH Building:
- Bottom-level: Fill
hiprtTriangleMeshPrimitivewith device pointers to vertex/index arrays, set build input type, query buffer size, create and build geometry. - Top-level: Define
hiprtInstancearray (hiprtInstanceTypeGeometry), provide transforms, upload withoroMallocandoroMemcpyHtoD, then create and build scene BVH.
- Bottom-level: Fill
- Custom Primitives:
- Use
hiprtAABBListPrimitivewith user AABB arrays; implement custom intersection in device code and register viahiprtFuncTable/hiprtFuncDataSet.
- Use
- Traversal and Stack Management:
- Shared and global stack buffers enable efficient traversal across threads and thread blocks (detailed in Listing 3). Support exists for both any-hit (shadow rays, early termination) and closest-hit traversals.
- Kernel Compilation and Invocation:
- Use
hiprtBuildTraceKernelswith ahiprtFuncNameSetreferencing custom functions, producing anhiprtApiFunctioninvocable as a standard HIP kernel.
- Use
5. End-to-End Pipeline and Use Cases
The stepwise workflow proceeds as follows:
- On the host, allocate geometry and parameter buffers.
- Instantiate the HIPRT context, build geometry/scene BVHs.
- Compile the ray tracing kernel with
hiprtBuildTraceKernels. - Launch the kernel per pixel or sample, generating primary rays, traversing BVHs for intersections, and shading as appropriate for direct lighting or a full path-tracing loop.
- Copy result buffers back to host for image output.
The architecture supports rendering triangles, spheres, and arbitrary custom primitives. The use of the any-hit device traversal accelerates shadow ray computation, while the closest-hit routine enables path tracing, next-event estimation, and related algorithms.
6. AMD Hardware Optimizations
Several best practices directly target the architectural features of AMD GPUs:
- Workgroup Sizing: For RDNA2/3, optimal performance is observed at wavefronts of 4 threads, thus block dimensions should be multiples of 5.
- Memory Coalescing: Structuring AABB and triangle data as Structure-of-Arrays, 6-byte aligned, ensures maximal memory throughput.
- Hardware Acceleration: HIPRT auto-targets the DPS units; setting
buildFlags=PreferBalancedBuildresults in near-optimal runtime vs. build-time trade-off. - Benchmarks:
- HIPRT balanced BVHs yield approximately 7 faster traversal relative to naive BVH structures.
- On AMD MI100, throughput of roughly 8 million primary rays per second is achieved with 9 million triangles.
7. Best Practices and Troubleshooting
Robust operational guidelines include:
- Monitoring HIP/HIPRT error codes using
hipGetErrorString. - Setting log levels (
hiprtLogLevelWarn|Error) for diagnostic insight during BVH build and traversal. - Retaining temporary buffers until all build operations complete.
- For dynamic scenes, updating the top-level BVH while marking bottom-level BVHs as static enhances update efficiency.
- Employing any-hit traversal for shadow computations, which terminate at the first occluding primitive.
- For deeper studies: “HIPRT: A Ray Tracing Framework in HIP”, “A Survey on Bounding Volume Hierarchies for Ray Tracing”, and “Physically Based Rendering” are foundational references.
This comprehensive HIPRT pipeline enables researchers to implement HIP-only ray tracers spanning triangle meshes, explicit primitives, and hybrid schemes, directly utilizable for modern physically based rendering and interactive applications (Yoshimura et al., 27 Feb 2026).