Optix7文档阅读(二):基本概念

2. 基本概念和定义

2.1. Program

In NVIDIA OptiX 7, a program is a block of executable code on the GPU that represents a particular shading operation. This is called a shader in DXR and Vulkan. For consistency with prior versions of NVIDIA OptiX 7, the term program is used in the current documentation. This term also serves as a reminder that these blocks of executable code are programmable components in the system that can do more than shading. See “Program input”.
在NVIDIA OptiX7中,一个程序(program)是一个GPU上的运行块(a block of exec code),代表了一个特定的着色操作。在DXR和Vulkan中,这称为着色器。为了与NVIDIA OptiX 7的早期版本保持一致,当前文档中依然使用了该叫法:程序。这个叫法还提醒我们,这些可执行代码块是系统中的可编程组件,而非仅是可以执行着色操作。 请参阅“Program input”。

2.2. Program and data model

NVIDIA OptiX 7 implements a single-ray programming model with ray generation, any-hit, closest-hit, miss and intersection programs.The ray tracing pipeline provided by NVIDIA OptiX 7 is implemented by eight types of programs:
NVIDIA OptiX 7实现了单光线(single-ray)编程模型。该模型具有光线生成(ray generation),任意命中(any-hit),最近命中(closest-hit),错过(miss)和相交(intersection)程序。NVIDIA OptiX 7提供的光线跟踪流程由八种程序(program)实现:

Ray generation
The entry point into the ray tracing pipeline, invoked by the system in parallel for each pixel, sample, or other user-defined work assignment. See “Ray generation launches”.
光线追踪流程的入口点,由系统针对每个像素,采样(sample)或其他用户定义的工作分配并行调用。 请参阅“Ray generation launches”。

Intersection
Implements a ray-primitive intersection test, invoked during traversal. See “Traversing the scene graph” and “Ray information”.
实现了在遍历过程中调用的光线原始相交(ray-primitive intersection test)。 请参见“Traversing the scene graph”和“Ray information”。

Any-hit
Called when a traced ray finds a new, potentially closest, intersection point, such as for shadow computation. See “Ray information”.
该程序会在 被追踪的光线 发现了一个新的可能最近相交点时调用,如阴影计算。请参阅“Ray information”。

Closest-hit
Called when a traced ray finds the closest intersection point, such as for material shading. See “Constructing a path tracer”.
该程序会在 被追踪的光线 发现了一个最近的相交点时调用,如材料着色(material shading)。请参阅“Constructing a path tracer”。

Miss
Called when a traced ray misses all scene geometry. See “Constructing a path tracer”.
该程序会在 被追踪的光线 错过(miss)了场景中所有的几何体时调用。 请参阅“Constructing a path tracer”。

Exception
Exception handler, invoked for conditions such as stack overflow and other errors. See “Exceptions”.
异常处理程序,在发生诸如堆栈溢出和其他错误时调用。请参阅“Exceptions”。

Direct callables
Similar to a regular CUDA function call, direct callables are called immediately. See “Callables”.
与常规的CUDA函数调用类似,直接可调用对象将立即被调用。 请参阅“Callables”。

Continuation callables
Unlike direct callables, continuation callables are executed by the scheduler. See “Callables”.
与直接可调用程序不同,连续可调用程序由调度程序(scheduler)执行。 请参阅“Callables”。

The ray-tracing “pipeline” is based on the interconnected calling structure of the eight programs and their relationship to the search through the geometric data in the scene, called a traversal. Figure 2.1 is a diagram of these relationships:
光线追踪流程是基于八个程序的互连调用以及它们与场景中几何数据的搜索关系(称为遍历)。 图2.1是关系示意图:

Optix7文档阅读(二):基本概念

In Figure 2.1, green represents fixed-function, hardware-accelerated operations, while gray represents user programs. The built-in or user-provided exception program may be called from any program or scene traversal in case of an exception if exceptions are enabled.
在图2.1中,绿色表示由硬件加速(hardware-accelerated)的固定功能(fixed-function)的操作,而灰色表示用户程序。 如果启用了异常(exception),则在发生异常的情况下,可以从任何程序或场景遍历中调用内置的或由用户提供的异常处理程序(exception program)。

2.2.1. Shader binding table

The shader binding table connects geometric data to programs and their parameters. A record is a component of the shader binding table that is selected during execution by using offsets specified when acceleration structures are created and at runtime. A record contains two data regions, header and data.
着色器绑定表(shader binding table)将几何数据和程序及其参数链接起来。 一个记录(record)是着色器绑定表的组成部分。在执行过程中,将使用创建加速结构时和运行时指定的偏移量(offset)来选择记录(还是着色器绑定表?)。 一条记录包含两个数据区域,标头(header)和数据(data)。

Record header

  • Opaque to the application, filled in by optixSbtRecordPackHeader
  • 对应用不可见,由optixSbtRecordPackHeader写入。
  • Used by NVIDIA OptiX 7 to identify programmatic behavior. For example, a primitive would identify the intersection, any-hit, and closest-hit behavior for that primitive in the header.
  • 由NVIDIA OptiX 7来指定编程行为。例如,一个图元(primitive)将会在header中标识该图元的交集,任何命中和最近命中的行为。

Record data

  • Opaque to NVIDIA OptiX 7
  • 对NVIDIA OptiX 7不可见
  • User data associated with the primitive or programs referenced in the headers can be stored here, for example, program parameter values.
  • 可以在此处存储在标头中引用的与图元或程序相关联的用户数据,例如程序参数值。

2.2.2. Ray payload

The ray payload is used to pass data between optixTrace and the programs invoked during ray traversal. Payload values are passed to and returned from optixTrace, and follow a copy-in/copy-out semantic. There is a limited number of payload values, but one or more of these values can also be a pointer to stack-based local memory, or application-managed global memory.
光线的有效载荷用于在optixTrace和光线遍历期间调用的程序之间传递数据。 有效负载值传递给optixTrace并从中返回,并遵循copy-in/copy-out的语义(semantic)。 有效负载值的数量有限,但是这些值中的一个或多个也可以是指向基于堆栈的本地内存或由应用程序管理的全局内存的指针。

2.2.3. Primitive attributes

Attributes are used to pass data from intersection programs to the any-hit and closest-hit programs. Triangle intersection provides two predefined attributes for the barycentric coordinates (U,V). User-defined intersections can define a limited number of other attributes that are specific to those primitives.
属性(attribute)用于将数据从相交程序(intersection program)传递到any-hit和closest-hit的程序中。 三角形相交为重心坐标(U,V)提供了两个预定义的属性。用户定义的相交可以定义有限数量的其他特定于这些图元的属性。

2.2.4. Buffer

NVIDIA OptiX 7 represents GPU information with a pointer to GPU memory. References to the term “buffer” in this document refer to this GPU memory pointer and the associated memory contents. Unlike NVIDIA OptiX 6, the allocation and transfer of buffers is explicitly controlled by user code.
NVIDIA OptiX 7通过指向GPU内存的指针来表示GPU信息。 本文档中,对“缓冲区”的引用是指此GPU内存指针和其关联的内存内容。 与NVIDIA OptiX 6不同,缓冲区的分配和传输由用户代码明确控制。

2.3. Acceleration structures

NVIDIA OptiX 7 acceleration structures are opaque data structures built on the device. Typically, they are based on the bounding volume hierarchy model, but implementations and the data layout of these structures may vary from one GPU architecture to another.

NVIDIA OptiX 7 provides two basic types of acceleration structures:

Geometry acceleration structures

  • Built over primitives (triangles, curves, or user-defined primitives)
    Instance acceleration structures
  • Built over other objects such as acceleration structures (either type) or motion transform nodes
  • Allow for instancing with a per-instance static transform

NVIDIA OptiX 7 加速结构是设备上构建的不透明数据结构。 通常,它们基于边界体积层次模型(bounding volume hierarchy model),但是这些结构的实现和数据布局可能因一个GPU架构而异。

NVIDIA OptiX 7提供两种基本类型的加速结构:

  • 几何(Geometry)加速结构
    • 建立在图元上(三角形,曲线或用户定义的基本体)
  • 实例(Instance)加速结构
    • 建立在其他对象上,例如加速结构(类型)或运动变换节点(
    • 允许预实例静态转换(per-instance static transform)的实例化(

2.4. Traversing the scene graph

To determine the intersection of geometric data by a ray, NVIDIA OptiX 7 searches a graph of nodes composed of acceleration structures and transformations. This search is called a traversal; the nodes in the graph are called traversable objects or traversables.

NVIDIA OptiX 7通过搜索由加速结构和变换(transformations)组成的节点图以确定几何数据和光线的相交点。这个搜索过程被称为遍历(traversal);在图中的节点被称为可遍历对象或traversables。

Traversable objects consist of the two acceleration structure types and three types of transformations:

  • An instance acceleration structure
  • A geometry acceleration structure (as a root for graph with a single geometry acceleration structure (see “Traversal of a single geometry acceleration structure”)
  • Static transform
  • Matrix motion transform
  • Scaling, rotation, translation (SRT) motion transform

The two motion transformations provide the required positional information for dynamic transformations used in motion blur calculation. Dynamic and static transformations can be combined in a graph. For example, Figure 2.2 combines both types:

可遍历对象包括两个加速结构类型和三种转换类型:

  • 一个实例加速结构
  • 一个几何加速结构(作为具有单个几何加速结构的图的根(请参阅“单个几何加速结构的遍历”))
  • 静态变换
  • 矩阵运动变换
  • 缩放,旋转,平移(即SRT)运动变换

这两个运动转换为在运动模糊计算中使用的动态转换提供了所需的位置信息。 动态和静态转换可以组合在图中。 例如,图2.2结合了两种类型:
Optix7文档阅读(二):基本概念
Traversable handles are 64-bit opaque values that are generated from device memory pointers for the graph objects. The handles identify the connectivity of these objects. All calls to optixTrace begin at a traversable handle.

可遍历句柄(traversable handles)是由对图形对象的设备内存指针生成的64位大小的不透明值。 句柄标识这些对象的连通性。 所有对optixTrace的调用均始于可遍历的句柄。

2.5. Ray tracing with NVIDIA OptiX 7

A functional ray tracing system is implemented by combining four components as described in the following steps:

  1. Create one or more acceleration structures that represent a geometry mesh in the scene and select one or more records in the shader binding table for each mesh. See “Acceleration structures”.
  2. Create a pipeline of programs that contains all programs that will be invoked during a ray tracing launch. See “Program pipeline creation”.
  3. Create a shader binding table that includes references to these programs and their parameters. See “Shader binding table”.
  4. Launch a device-side kernel that will invoke a ray generation program with a multitude of threads calling optixTrace to begin traversal and the execution of the other programs. See “Ray generation launches”. Device-side functionality is described in “Device-side functions”.

Ray tracing work can be interleaved with other CUDA work to generate data, move data to and from the device, and move data to other graphics APIs. It is the application’s responsibility to coordinate all work on the GPU. NVIDIA OptiX 7 does not synchronize with any other work.

通过结合以下步骤中描述的四个组件来实现光线追踪系统:

  1. 创建一个或多个表示场景中几何网格(geometry mesh)(是否可以把这个网格理解为模型(model))的加速结构,并在着色器绑定表中为每个网格选择一个或多个记录。请参阅“Acceleration structures”。
  2. 创建一个程序管道(pipeline of program),其中包含在光线追踪启动(ray tracing launch)期间将被调用的所有程序。请参阅“Program pipeline creation”。
  3. 创建一个着色器绑定表,其中包含对这些程序及其参数的引用。请参见“Shader binding table”。
  4. 启动设备端内核,该内核将调用带有optixTrace的多个线程的光线生成程序,以开始遍历和执行其他程序。请参阅“Ray generation launches”。设备端功能在“Device-side functions”中介绍。

光线跟踪工作可以与其他CUDA工作交错在一起以生成数据,在设备之间来回移动数据以及将数据移动到其他图形API。协调GPU上的所有工作是应用程序的责任。 NVIDIA OptiX 7不与任何其他作品同步。