A Hardware Ray Tracer Datapath with Generalized Features

Fangjia Shen,Timothy G. Rogers
2024-09-10
Abstract:This article documents an open-source hardware ray tracer datapath pipeline module implemented with the Chisel hardware construction language. The module implements a unified fix-latency pipeline for Ray-Box and Ray-Triangle intersection tests which are the two core, compute-intensive tasks involved in Ray Tracing workloads. Furthermore, the module offers the flexibility of supporting two additional compute modes that can accelerate the computation of Euclidean distance and angular distance (aka cosine similarity) between two vectors, at the cost of minimal additional hardware overhead. Several design choices are made in favor of creating a composable and easily-modifiable Chisel module. This document also explains the trade-offs of these choices.
Hardware Architecture,Graphics
What problem does this paper attempt to address?
The main problem that this paper attempts to solve is to expand the functionality of the hardware ray tracer, enabling it to not only handle the traditional intersection tests between rays and geometries (such as boxes and triangles), but also efficiently calculate the Euclidean distance and angular distance (i.e., cosine similarity) between two vectors. Through these expansions, the author hopes to improve the versatility and flexibility of the hardware ray tracer, making it applicable to a wider range of computational tasks. Specifically, the paper has achieved the following goals: 1. **Unified Fixed - Latency Pipeline**: A unified fixed - latency pipeline has been designed to handle the intersection tests between rays and boxes (Ray - Box) and between rays and triangles (Ray - Triangle). These are two core and computationally intensive tasks in ray - tracing workloads. 2. **Support for Additional Computational Modes**: Two additional computational modes have been added without significantly increasing the hardware overhead: - **Euclidean Distance Calculation**: Calculate the square of the Euclidean distance between two vectors of arbitrary dimensions. - **Angular Distance Calculation**: Calculate the cosine similarity (i.e., angular distance) between two vectors of arbitrary dimensions. 3. **Modularity and Modifiability**: For the convenience of combination and modification, it is implemented in the Chisel hardware construction language, and multiple design choices have been made to ensure the flexibility and maintainability of the modules. ### Formula Summary 1. **Euclidean Distance**: \[ d_{\text{Euclidean}}=\sqrt{(\vec{a}-\vec{b})\cdot(\vec{a}-\vec{b})} \] where: \[ \vec{a}=(a_1,a_2,\ldots,a_n)\quad\text{and}\quad\vec{b}=(b_1,b_2,\ldots,b_n) \] The data path output is: \[ \text{datapath output}=(\vec{a}-\vec{b})\cdot(\vec{a}-\vec{b})=\sum_{i = 1}^{n}(a_i - b_i)^2 \] 2. **Angular Distance (Cosine Similarity)**: \[ d_{\text{angular}}=\cos(\theta)=\frac{\vec{q}\cdot\vec{c}}{\|\vec{q}\|\|\vec{c}\|} \] where: \[ \vec{q}=(q_1,q_2,\ldots,q_n)\quad\text{and}\quad\vec{c}=(c_1,c_2,\ldots,c_n) \] The data path output a is: \[ \text{datapath output a}=\vec{q}\cdot\vec{c}=\sum_{i = 1}^{n}(q_i\times c_i) \] \[ \text{datapath output b}=\|\vec{c}\|^2=\sum_{i = 1}^{n}c_i^2 \] Through these improvements, the hardware ray tracer can not only play an important role in graphics rendering, but also be applied to other fields that require efficient vector operations, such as machine learning and data analysis.