OptiX
3.9
NVIDIA OptiX Acceleration Engine
|
OptiX Prime public API.
Go to the source code of this file.
Macros | |
#define | OPTIX_PRIME_VERSION |
#define | RTPAPI __declspec(dllimport) |
Typedefs | |
typedef unsigned int | RTPsize |
typedef struct RTPcontext_api * | RTPcontext |
typedef struct RTPmodel_api * | RTPmodel |
typedef struct RTPquery_api * | RTPquery |
typedef struct RTPbufferdesc_api * | RTPbufferdesc |
typedef struct CUstream_st * | cudaStream_t |
#define OPTIX_PRIME_VERSION |
typedef struct RTPbufferdesc_api* RTPbufferdesc |
Opaque type. Note that the *_api type should never be used directly. Only the typedef target name will be guaranteed to remain unchanged.
typedef struct RTPcontext_api* RTPcontext |
Opaque type. Note that the *_api type should never be used directly. Only the typedef target name will be guaranteed to remain unchanged.
typedef struct RTPmodel_api* RTPmodel |
Opaque type. Note that the *_api type should never be used directly. Only the typedef target name will be guaranteed to remain unchanged.
typedef struct RTPquery_api* RTPquery |
Opaque type. Note that the *_api type should never be used directly. Only the typedef target name will be guaranteed to remain unchanged.
RTPresult RTPAPI rtpBufferDescCreate | ( | RTPcontext | context, |
RTPbufferformat | format, | ||
RTPbuffertype | type, | ||
void * | buffer, | ||
RTPbufferdesc * | desc | ||
) |
Create a buffer descriptor.
This function creates a buffer descriptor with the specified element format and buffertype. A buffer of type RTP_BUFFER_TYPE_CUDA_LINEAR is assumed to reside on the current device. The device number can be changed by calling rtpBufferDescSetCudaDeviceNumber.
[in] | context | OptiX Prime context |
[in] | format | Format of the buffer |
[in] | type | Type of the buffer |
[in] | buffer | Pointer to buffer data |
[out] | desc | Pointer to the new buffer descriptor |
Return values
Relevant return values:
Example Usage:
RTPresult RTPAPI rtpBufferDescDestroy | ( | RTPbufferdesc | desc | ) |
Destroys a buffer descriptor.
Buffer descriptors can be destroyed immediately after it is used as a function parameter. The buffer contents associated with a buffer descriptor, however, must remain valid until they are no longer used by any OptiX Prime objects.
[in] | desc | Buffer descriptor |
Return values
Relevant return values:
RTPresult RTPAPI rtpBufferDescGetContext | ( | RTPbufferdesc | desc, |
RTPcontext * | context | ||
) |
Gets the context object associated with the provided buffer descriptor.
[in] | desc | Buffer descriptor |
[out] | context | Returned context |
Return values
Relevant return values:
RTPresult RTPAPI rtpBufferDescSetCudaDeviceNumber | ( | RTPbufferdesc | desc, |
unsigned | deviceNumber | ||
) |
Sets the CUDA device number for a buffer.
A buffer of type RTP_BUFFER_TYPE_CUDA_LINEAR is assumed to reside on the device that was current when its buffer descriptor was created unless otherwise specified using this function.
[in] | desc | Buffer descriptor |
[in] | deviceNumber | CUDA device number |
Return values
Relevant return values:
RTPresult RTPAPI rtpBufferDescSetRange | ( | RTPbufferdesc | desc, |
RTPsize | begin, | ||
RTPsize | end | ||
) |
Sets the element range of a buffer to use.
The range is specified in terms of number of elements. By default, the range for a buffer is 0 to the number of elements in the buffer.
[in] | desc | Buffer descriptor |
[in] | begin | Start index of the range |
[in] | end | End index of the range (exclusive, one past the index of the last element) |
Return values
Relevant return values:
RTPresult RTPAPI rtpBufferDescSetStride | ( | RTPbufferdesc | desc, |
unsigned | strideBytes | ||
) |
Sets the stride for elements in a buffer.
This function is only valid for buffers of format RTP_BUFFER_FORMAT_VERTEX_FLOAT3. This function is useful for vertex buffers that contain interleaved vertex attributes. For buffers that are transferred between the host and a device it is recommended that only buffers with default stride be used to avoid transferring data that will not be used.
[in] | desc | Buffer descriptor |
[in] | strideBytes | Stride in bytes. The default value of 0 indicates that elements are contiguous in memory. |
Return values
Relevant return values:
Example Usage:
RTPresult RTPAPI rtpContextCreate | ( | RTPcontexttype | type, |
RTPcontext * | context | ||
) |
Creates an OptiX Prime context.
By default, a context created with type RTP_CONTEXT_TYPE_CUDA will use all available CUDA devices. Specific devices can be selected using rtpContextSetCudaDeviceNumbers. One device will be selected as the primary device and will be set as the current device when the function returns. If no available device has compute capability 2.0 or greater the created context will not be able to build acceleration structures.
[in] | type | The type of context to create |
[out] | context | Pointer to the new OptiX Prime context |
Return values
Relevant return values:
Example Usage:
RTPresult RTPAPI rtpContextDestroy | ( | RTPcontext | context | ) |
Destroys an OptiX Prime context.
Ongoing work is finished before context is destroyed. All OptiX Prime objects associated with context are aslo destroyed when context is destroyed.
[in] | context | OptiX Prime context to destroy |
Return values
Relevant return values:
RTPresult RTPAPI rtpContextGetLastErrorString | ( | RTPcontext | context, |
const char ** | return_string | ||
) |
Returns a string describing last error encountered.
This function returns an error string for the last error encountered in context that may contain invocation-specific details beyond the simple RTPresult error code. Note that this function may return errors from previous asynchronous launches or from calls by other threads.
[in] | context | OptiX Prime context |
[out] | return_string | String with error details |
Return values
Relevant return values:
See also rtpGetErrorString
RTPresult RTPAPI rtpContextSetCpuThreads | ( | RTPcontext | context, |
unsigned | numThreads | ||
) |
Sets the number of CPU threads used by a CPU context.
This function will return an error if the provided context is not of type RTP_CONTEXT_TYPE_CPU.
By default, one ray tracing thread is created per CPU core.
[in] | context | OptiX Prime context |
[in] | numThreads | Number of threads used for the CPU context |
Return values
Relevant return values:
RTPresult RTPAPI rtpContextSetCudaDeviceNumbers | ( | RTPcontext | context, |
unsigned | deviceCount, | ||
const unsigned * | deviceNumbers | ||
) |
Sets the CUDA devices used by a context.
The first device provided in deviceNumbers will be used as the primary device. Acceleration structures will be built on the primary device and copied to the others. To build the acceleration structures the primary device must be of compute capability 2.0 or greater. The current device will be set to the primary device when this function returns.
If deviceCount==0, then the primary device is selected automatically and all available devices are selected for use. deviceNumbers is ignored.
[in] | context | OptiX Prime context |
[in] | deviceCount | Number of devices supplied in deviceNumbers or 0 |
[in] | deviceNumbers | Array of integer device indices, or NULL if deviceCount==0 |
This function will return an error if the provided context is not of type RTP_CONTEXT_TYPE_CUDA
Return values
Relevant return values:
Translates an RTPresult error code to a string.
Translates an RTPresult error code to a string describing the error.
[in] | errorCode | Error code to be translated |
[out] | errorString | Returned error string |
Return values
Relevant return values:
See also rtpContextGetLastErrorString
RTPresult RTPAPI rtpGetVersion | ( | unsigned * | version | ) |
Gets OptiX Prime version number.
The encoding for the version number is major*1000 + minor*10 + micro. For example, for version 3.5.1 this function would return 3051.
[out] | version | Returned version |
Return values
Relevant return values:
RTPresult RTPAPI rtpGetVersionString | ( | const char ** | versionString | ) |
Gets OptiX Prime version string.
Returns OptiX Prime version string and other information in a human-readable format.
[in] | versionString | Returned version information |
Return values
Relevant return values:
RTPresult RTPAPI rtpHostBufferLock | ( | void * | buffer, |
RTPsize | size | ||
) |
Page-locks a host buffer.
Transfers between the host and device are faster if the host buffers are page-locked. However, page-locked memory is a limited resource and should be used judiciously.
[in] | buffer | Buffer on the host |
[in] | size | Size of the buffer |
Return values
Relevant return values:
RTPresult RTPAPI rtpHostBufferUnlock | ( | void * | buffer | ) |
Unlocks a previously page-locked host buffer.
Transfers between the host and device are faster if the host buffers are page-locked. However, page-locked memory is a limited resource and should be used judiciously. Use this function on buffers previous page-locked with rtpHostBufferLock.
[in] | buffer | Buffer on the host |
Return values
Relevant return values:
Copies one model to another.
This function copies a model from one OptiX Prime context to another for user-managed multi-GPU operation where one context is allocated per device. Only triangle models can be copied, not instance models. Furthermore, when a srcModel has the RTP_BUILDER_PARAM_USE_CALLER_TRIANGLES build parameter set to 1, and it is intended that the triangle data is automatically transfered to the other context, the destination (model) should have the build parameter set to 0 before the copy call. If the destination model also has the has the build parameter set to 1, its triangles must be set by calling rtpModelSetTriangles followed by rtpModelUpdate using RTP_MODEL_HINT_USER_TRIANGLES_AFTER_COPY_SET.
[in] | model | Destination model |
[in] | srcModel | Source model |
Return values
Relevant return values:
RTPresult RTPAPI rtpModelCreate | ( | RTPcontext | context, |
RTPmodel * | model | ||
) |
Creates a model.
[in] | context | OptiX Prime context |
[out] | model | Pointer to the new model |
Return values
Relevant return values:
Destroys a model.
Any queries created on the model are also destroyed with the model. The queries are allowed to finish before they are destroyed.
[in] | model | Model |
Return values
Relevant return values:
Blocks current thread until model update is finished.
This function can be called multiple times. It will return immediately if the previous update has already finished.
[in] | model | Model |
Return values
Relevant return values:
RTPresult RTPAPI rtpModelGetContext | ( | RTPmodel | model, |
RTPcontext * | context | ||
) |
Gets the context object associated with the model.
[in] | model | Model to obtain the context from |
[out] | context | Returned context |
Return values
Relevant return values:
Polls the status of a model update.
[in] | model | Model |
[out] | isFinished | Returns finished status |
Return values
Relevant return values:
RTPresult RTPAPI rtpModelSetBuilderParameter | ( | RTPmodel | model_api, |
RTPbuilderparam | param, | ||
RTPsize | size, | ||
const void * | ptr | ||
) |
Specifies a builder parameter for a model.
The following builder parameters are supported:
RTP_BUILDER_PARAM_USE_CALLER_TRIANGLES : int
If the value for RTP_BUILDER_PARAM_USE_CALLER_TRIANGLES is set to 0 (default), Prime uses an internal representation for triangles (which requires additional memory) to improve query performance and does not reference the user's vertex buffer during a query. If set to 1, Prime uses the provided triangle data as-is, which may result in slower query performance, but reduces memory usage.
RTP_BUILDER_PARAM_CHUNK_SIZE : RTPsize
Acceleration structures are built in chunks to reduce the amount of scratch memory needed. The size of the scratch memory chunk is specified in bytes by RTP_BUILDER_PARAM_CHUNK_SIZE. If set to -1, the chunk size has no limit. If set to 0 (default) the chunk size is chosen automatically, currently as 10% of the total available video memory for GPU builds and 512MB for CPU builds.
[in] | model_api | Model |
[in] | param | Builder parameter to set |
[in] | size | Size in bytes of the parameter being set |
[in] | ptr | Pointer to where the value of the attribute will be copied from. This must point to at least size bytes of memory |
Return values
Relevant return values:
RTPresult RTPAPI rtpModelSetInstances | ( | RTPmodel | model, |
RTPbufferdesc | instances, | ||
RTPbufferdesc | transforms | ||
) |
Sets the instance data for a model.
The instances buffer specifies a list of model instances, and the transforms buffer holds a transformation matrix for each instance. The instance buffer type must be RTP_BUFFER_TYPE_HOST.
Instance buffers must be of format RTP_BUFFER_FORMAT_INSTANCE_MODEL, and transform buffers of format RTP_BUFFER_FORMAT_TRANSFORM_FLOAT4x4 or RTP_BUFFER_FORMAT_TRANSFORM_FLOAT4x3. If a stride is specified for the transformations, it must be a multiple of 16 bytes. Furthermore, the matrices must be stored in row-major order. Only affine transformations are supported, and the last row is always assumed to be [0.0, 0.0, 0.0, 1.0].
All instance models in the instances buffer must belong to the same context as the model itself. Additionally, the build parameter RTP_BUILDER_PARAM_USE_CALLER_TRIANGLES must be the same for all models (if applied). Setting RTP_BUILDER_PARAM_USE_CALLER_TRIANGLES for a model which contains instances has no effect.
The buffers are not used until rtpModelUpdate is called.
[in] | model | Model |
[in] | instances | Buffer descriptor for instances |
[in] | transforms | Buffer descriptor for 4x4 transform matrices |
Return values
Relevant return values:
RTPresult RTPAPI rtpModelSetTriangles | ( | RTPmodel | model, |
RTPbufferdesc | indices, | ||
RTPbufferdesc | vertices | ||
) |
Sets the triangle data for a model.
The index buffer specifies triplet of vertex indices. If the index buffer descriptor is not specified (e.g. indices==NULL), the vertex buffer is considered to be a flat list of triangles, with every three vertices forming a triangle. The buffers are not used until rtpModelUpdate is called.
[in] | model | Model |
[in] | indices | Buffer descriptor for triangle vertex indices, or NULL |
[in] | vertices | Buffer descriptor for triangle vertices |
Return values
Relevant return values:
Updates data, or creates an acceleration structure over triangles or instances.
Depending on the specified hints, rtpModelUpdate performs different operations:
If the flag RTP_MODEL_HINT_ASYNC is specified, some or all of the acceleration structure update may run asynchronously and rtpModelUpdate may return before the update is finished. In the case of RTP_MODEL_HINT_NONE, the acceleration structure build is blocking. It is important that buffers specified in rtpModelSetTriangles and rtpModelSetInstances not be modified until the update has finished. rtpModelFinish blocks the current thread until the update is finished. rtpModelGetFinished can be used to poll until the update is finished. Once the update has finished the input buffers can be modified.
The acceleration structure build performed by rtpModelUpdate uses a fast, high quality algorithm, but has the cost of requiring additional working memory. The amount of working memory is controlled by RTP_BUILDER_PARAM_CHUNK_SIZE.
The flag RTP_MODEL_HINT_MASK_UPDATE should be used to inform Prime when visibility mask data changed (after calling rtpModelSetTriangles with the updated values), e.g. when the indices format RTP_BUFFER_FORMAT_INDICES_INT3_MASK_INT is used. RTP_MODEL_HINT_MASK_UPDATE can be combined with RTP_MODEL_HINT_ASYNC to perform asynchronous data updates.
Hint RTP_MODEL_HINT_USER_TRIANGLES_AFTER_COPY_SET should be used when a triangle model has been copied (with the user triangle build flag set), and new user triangles have been set (by calling rtpModelSetTriangles again with the updated values). RTP_MODEL_HINT_USER_TRIANGLES_AFTER_COPY_SET can be combined with RTP_MODEL_HINT_ASYNC to perform asynchronous data updates.
[in] | model | Model |
[in] | hints | A combination of flags from RTPmodelhint |
Return values
Relevant return values:
Example Usage:
RTPresult RTPAPI rtpQueryCreate | ( | RTPmodel | model, |
RTPquerytype | queryType, | ||
RTPquery * | query | ||
) |
Creates a query on a model.
If the model to which a query is bound destroyed with rtpModelDestroy() the query will be destroyed as well.
[in] | model | Model to use for this query |
[in] | queryType | Type of the query |
[out] | query | Pointer to the new query |
Return values
Relevant return values:
Destroys a query.
The query is finished before it is destroyed
[in] | query | Query to be destroyed |
Return values
Relevant return values:
Executes a raytracing query.
If the flag RTP_QUERY_HINT_ASYNC is specified, rtpQueryExecute may return before the query is actually finished. rtpQueryFinish can be called to block the current thread until the query is finished, or rtpQueryGetFinished can be used to poll until the query is finished.
[in] | query | Query |
[in] | hints | A combination of flags from RTPqueryhint |
Once the query has finished all of the hits are guaranteed to have been returned, and it is safe to modify the ray buffer.
Return values
Relevant return values:
Example Usage:
Blocks current thread until query is finished.
This function can be called multiple times. It will return immediately if the query has already finished.
[in] | query | Query |
Return values
Relevant return values:
RTPresult RTPAPI rtpQueryGetContext | ( | RTPquery | query, |
RTPcontext * | context | ||
) |
Gets the context object associated with a query.
[in] | query | Query to obtain the context from |
[out] | context | Returned context |
Return values
Relevant return values:
Polls the status of a query.
[in] | query | Query |
[out] | isFinished | Returns finished status |
Return values
Relevant return values:
Sets a sync stream for a query.
Specify a Cuda stream used for synchronization. If no stream is specified, the default 0-stream is used. A stream can only be specified for contexts with type RTP_CONTEXT_TYPE_CUDA.
[in] | query | Query |
[in] | stream | A cuda stream |
Return values
Relevant return values:
RTPresult RTPAPI rtpQuerySetHits | ( | RTPquery | query, |
RTPbufferdesc | hits | ||
) |
Sets the hits buffer for a query.
A hit is reported for every ray in the query. Therefore the size of the range in the hit buffer must match that of the ray buffer.
[in] | query | Query |
[in] | hits | Buffer descriptor for hits |
Return values
Relevant return values:
RTPresult RTPAPI rtpQuerySetRays | ( | RTPquery | query, |
RTPbufferdesc | rays | ||
) |
Sets the rays buffer for a query.
The rays buffer is not accessed until rtpQueryExecute() is called.
[in] | query | Query |
[in] | rays | Buffer descriptor for rays |
Return values
Relevant return values: