diff options
Diffstat (limited to 'hiprt-sys')
-rw-r--r-- | hiprt-sys/Cargo.toml | 14 | ||||
-rw-r--r-- | hiprt-sys/Makefile.toml | 16 | ||||
-rw-r--r-- | hiprt-sys/include/hiprt.h | 714 | ||||
-rw-r--r-- | hiprt-sys/include/hiprt/hiprt_vec.h | 79 | ||||
-rw-r--r-- | hiprt-sys/lib/hiprt64.dll | bin | 0 -> 580608 bytes | |||
-rw-r--r-- | hiprt-sys/lib/hiprt64.lib | bin | 0 -> 7470 bytes | |||
-rw-r--r-- | hiprt-sys/lib/libhiprt64.so | bin | 0 -> 586056 bytes | |||
-rw-r--r-- | hiprt-sys/src/hiprt.rs | 979 | ||||
-rw-r--r-- | hiprt-sys/src/lib.rs | 84 |
9 files changed, 1886 insertions, 0 deletions
diff --git a/hiprt-sys/Cargo.toml b/hiprt-sys/Cargo.toml new file mode 100644 index 0000000..621b5d7 --- /dev/null +++ b/hiprt-sys/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "hiprt-sys" +version = "0.0.0" +authors = ["Andrzej Janik <[email protected]>"] +edition = "2018" + +[lib] + +[dependencies] +libloading = "0.8" + +[target.'cfg(windows)'.dependencies] +winapi = { version = "0.3", features = ["libloaderapi", "std"] } +widestring = "1.0" diff --git a/hiprt-sys/Makefile.toml b/hiprt-sys/Makefile.toml new file mode 100644 index 0000000..f21834a --- /dev/null +++ b/hiprt-sys/Makefile.toml @@ -0,0 +1,16 @@ +[tasks.bindgen] +command = "bindgen" +args = [ + "include/hiprt.h", + "-o", "src/hiprt.rs", + "--rust-target", "1.64", + "--no-layout-tests", + "--no-derive-debug", + "--default-enum-style=newtype", + "--dynamic-loading", "HipRt", + "--must-use-type", "hiprtError", + "--allowlist-function", "hiprt.*", + "--allowlist-type", "hiprt.*", + "--allowlist-var", "^HIPRT.*$", + "--", "-I", "include", "-x", "c++", +]
\ No newline at end of file diff --git a/hiprt-sys/include/hiprt.h b/hiprt-sys/include/hiprt.h new file mode 100644 index 0000000..af756bc --- /dev/null +++ b/hiprt-sys/include/hiprt.h @@ -0,0 +1,714 @@ +#ifndef HIPRT_H
+#define HIPRT_H
+
+#define HIPRT_API_MAJOR_VERSION 0x000001
+#define HIPRT_API_MINOR_VERSION 0x000002
+#define HIPRT_API_PATCH_VERSION 0x000000
+#define HIPRT_API_VERSION HIPRT_API_MAJOR_VERSION * 1000000 + HIPRT_API_MINOR_VERSION * 1000 + HIPRT_API_PATCH_VERSION
+
+#include <hiprt/hiprt_vec.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined( _MSC_VER )
+#ifdef HIPRT_EXPORTS
+#define HIPRT_API __declspec( dllexport )
+#else
+#define HIPRT_API __declspec( dllimport )
+#endif
+#elif defined( __GNUC__ )
+#ifdef HIPRT_EXPORTS
+#define HIPRT_API __attribute__( ( visibility( "default" ) ) )
+#else
+#define HIPRT_API
+#endif
+#else
+#define HIPRT_API
+#pragma warning Unknown dynamic link import / export semantics.
+#endif
+
+struct _hiprtGeometry;
+struct _hiprtGeometryCustom;
+struct _hiprtScene;
+struct _hiprtContext;
+struct _hiprtCustomFuncTable;
+
+typedef void* hiprtDevicePtr;
+typedef hiprtDevicePtr hiprtGeometry;
+typedef hiprtDevicePtr hiprtScene;
+typedef uint32_t hiprtBuildFlags;
+typedef uint32_t hiprtRayMask;
+typedef uint32_t hiprtCustomType;
+typedef _hiprtContext* hiprtContext;
+typedef _hiprtCustomFuncTable* hiprtCustomFuncTable;
+
+typedef int hiprtApiDevice; // hipDevice, cuDevice
+typedef void* hiprtApiCtx; // hipCtx, cuCtx
+typedef void* hiprtApiStream; // hipStream, cuStream
+typedef void* hiprtApiFunction; // hipFunction, cuFunction
+
+/** \brief Various constants.
+ *
+ */
+enum : uint32_t
+{
+ hiprtInvalidValue = ~0u,
+ hiprtMaxCustomFunctions = 65536,
+};
+
+/** \brief Error codes.
+ *
+ */
+typedef enum
+{
+ hiprtSuccess = 0,
+ hiprtErrorNotImplemented = 1,
+ hiprtErrorInternal = 2,
+ hiprtErrorOutOfHostMemory = 3,
+ hiprtErrorOutOfDeviceMemory = 4,
+ hiprtErrorInvalidApiVersion = 5,
+ hiprtErrorInvalidParameter = 6
+} hiprtError;
+
+/** \brief Type of geometry/scene build operation.
+ *
+ * hiprtBuildGeometry/hiprtBuildScene can either build or update
+ * an underlying acceleration structure.
+ */
+typedef enum
+{
+ hiprtBuildOperationBuild = 1,
+ hiprtBuildOperationUpdate = 2
+} hiprtBuildOperation;
+
+/** \brief Hint flags for geometry/scene build functions.
+ *
+ * hiprtBuildGeometry/hiprtBuildScene use these flags to choose
+ * an appropriate build format/algorithm.
+ */
+typedef enum
+{
+ hiprtBuildFlagBitPreferFastBuild = 0,
+ hiprtBuildFlagBitPreferBalancedBuild = 1,
+ hiprtBuildFlagBitPreferHighQualityBuild = 2,
+ hiprtBuildFlagBitCustomBvhImport = 3,
+ hiprtBuildFlagBitDisableSpatialSplits = 1 << 2
+} hiprtBuildFlagBits;
+
+/** \brief Geometric primitive type.
+ *
+ * hiprtGeometry can be built from multiple primitive types,
+ * such as triangle meshes, AABB lists, line lists, etc. This enum
+ * defines primitive type for hiprtBuildGeometry function.
+ */
+typedef enum
+{
+ hiprtPrimitiveTypeTriangleMesh,
+ hiprtPrimitiveTypeAABBList,
+} hiprtPrimitiveType;
+
+/** \brief Traversal state.
+ *
+ * On-device traversal can be in either hit state (and can be continued using
+ * hiprtNextHit) or finished state.
+ */
+typedef enum
+{
+ hiprtTraversalStateInit,
+ hiprtTraversalStateFinished,
+ hiprtTraversalStateHit,
+ hiprtTraversalStateStackOverflow
+} hiprtTraversalState;
+
+/** \brief Ray traversal type.
+ *
+ */
+enum hiprtTraversalType
+{
+ /*!< 0 or 1 element iterator with any hit along the ray */
+ hiprtTraversalTerminateAtAnyHit = 1,
+ /*!< 0 or 1 element iterator with a closest hit along the ray */
+ hiprtTraversalTerminateAtClosestHit = 2,
+};
+
+/** \brief Bvh node type.
+ *
+ */
+enum hiprtBvhNodeType
+{
+ /*!< Leaf node */
+ hiprtBvhNodeTypeInternal = 0,
+ /*!< Internal node */
+ hiprtBvhNodeTypeLeaf = 1,
+};
+
+/** \brief Ray data structure.
+ *
+ */
+struct hiprtRay
+{
+ /*!< Ray origin */
+ hiprtFloat3 origin;
+ /*!< Ray time for motion blur */
+ float time;
+ /*!< Ray direction */
+ hiprtFloat3 direction;
+ /*!< Ray maximum distance */
+ float maxT;
+};
+
+/** \brief Ray hit data structure.
+ *
+ */
+struct hiprtHit
+{
+ /*!< Instance ID */
+ uint32_t instanceID;
+ /*!< Primitive ID */
+ uint32_t primID;
+ /*!< Texture coordinates */
+ hiprtFloat2 uv;
+ /*!< Geeometric normal (not normalized) */
+ hiprtFloat3 normal;
+ /*!< Distance */
+ float t;
+};
+
+/** \brief Insersection function for custom primitives.
+ *
+ * \param ray Ray.
+ * \param primID Primtive ID.
+ * \param data User data.
+ * \param payload Payload for additional outputs.
+ * \param uv Output texture coordinates.
+ * \param normal Output normal.
+ * \param t Output distance.
+ * \return A flag indicating hit.
+ */
+typedef bool ( *hiprtIntersectFunc )(
+ const hiprtRay& ray,
+ uint32_t primID,
+ const void* data,
+ void* payload,
+ hiprtFloat2& uv,
+ hiprtFloat3& normal,
+ float& t );
+
+/** \brief Set of functions for custom primitives.
+ *
+ */
+typedef struct
+{
+ hiprtIntersectFunc intersectFunc;
+ const void* intersectFuncData;
+} hiprtCustomFuncSet;
+
+/** \brief Device type.
+ *
+ */
+enum hiprtDeviceType
+{
+ /*!< AMD device */
+ hiprtDeviceAMD,
+ /*!< Nvidia device */
+ hiprtDeviceNVIDIA,
+};
+
+/** \brief Context creation input.
+ *
+ */
+typedef struct
+{
+ /*!< HIPRT API context */
+ hiprtApiCtx ctxt;
+ /*!< HIPRT API device */
+ hiprtApiDevice device;
+ /*!< HIPRT API device type */
+ hiprtDeviceType deviceType;
+} hiprtContextCreationInput;
+
+/** \brief Various flags controlling scene/geometry build process.
+ *
+ */
+typedef struct
+{
+ /*!< Build flags */
+ hiprtBuildFlags buildFlags;
+} hiprtBuildOptions;
+
+/** \brief Triangle mesh primitive.
+ *
+ * Triangle mesh primitive is represented as an indexed vertex array.
+ * Vertex and index arrays are defined using device pointers and strides.
+ * Each vertex has to have 3 components: (x, y, z) coordinates.
+ * Indices are organized into triples (i0, i1, i2) - one for each triangle.
+ */
+typedef struct
+{
+ /*!< Device pointer to vertex data */
+ hiprtDevicePtr vertices;
+ /*!< Number of vertices in vertex array */
+ uint32_t vertexCount;
+ /*!< Stride in bytes between two vertices */
+ uint32_t vertexStride;
+
+ /*!< Device pointer to index data */
+ hiprtDevicePtr triangleIndices;
+ /*!< Number of trinagles in index array */
+ uint32_t triangleCount;
+ /*!< Stride in bytes between two triangles */
+ uint32_t triangleStride;
+} hiprtTriangleMeshPrimitive;
+
+/** \brief AABB list primitive.
+ *
+ * AABB list is an array of axis aligned bounding boxes, represented
+ * by device memory pointer and stride between two consequetive boxes.
+ * Each AABB is a pair of float4 values (xmin, ymin, zmin, unused), (xmax, ymax,
+ * zmax, unused).
+ */
+typedef struct
+{
+ /*!< Device pointer to AABB data */
+ hiprtDevicePtr aabbs;
+ /*!< Number of AABBs in the array */
+ uint32_t aabbCount;
+ /*!< Stride in bytes between two AABBs */
+ uint32_t aabbStride;
+} hiprtAABBListPrimitive;
+
+/** \brief Bvh node for custom import Bvh.
+ *
+ */
+typedef struct
+{
+ /*!< Child indices (empty slot needs to be marked by hiprtInvalidValue) */
+ uint32_t childIndices[4];
+ /*!< Child node types */
+ hiprtBvhNodeType childNodeTypes[4];
+ /*!< Node bounding box min */
+ hiprtFloat3 boundingBoxMin;
+ /*!< Node bounding box max */
+ hiprtFloat3 boundingBoxMax;
+
+ int pad[2];
+} hiprtBvhNode;
+
+/** \brief Bvh node list.
+ *
+ */
+typedef struct
+{
+ /*!< Array of hiprtBvhNode's */
+ hiprtDevicePtr nodes;
+ /*!< Number of nodes */
+ uint32_t nodeCount;
+} hiprtBvhNodeList;
+
+/** \brief Input for geometry build/update operation.
+ *
+ * Build input defines concrete primitive type and a pointer to an actual
+ * primitive description.
+ */
+typedef struct
+{
+ /*!< Primitive type */
+ hiprtPrimitiveType type;
+ /*!< Defines the following union */
+ union
+ {
+ struct
+ {
+ /*!< Triangle mesh */
+ hiprtTriangleMeshPrimitive* primitive;
+ } triangleMesh;
+ struct
+ {
+ /*!< Bounding boxes of custom primitives */
+ hiprtAABBListPrimitive* primitive;
+ /*!< Type of custom primitives */
+ hiprtCustomType customType;
+ } aabbList;
+ };
+ /*!< Custom Bvh nodes (optional) */
+ hiprtBvhNodeList* nodes;
+} hiprtGeometryBuildInput;
+
+/** \brief Build input for the scene.
+ *
+ * Scene consists of a set of instances. Each of the instances is defined by:
+ * - Root pointer of the corresponding geometry
+ * - Transformation header
+ * - Mask
+ *
+ * Instances can refer to the same geometry but with different transformations
+ * (essentially implementing instancing). Mask is used to implement ray
+ * masking: ray mask is bitwise &ded with an instance mask, and no intersections
+ * are evaluated with the primitive of corresponding instance if the result is
+ * 0. The transformation header defines the offset and the number of consecutive
+ * transformation frames in the frame array for each instance. More than one frame
+ * is interpreted as motion blur. If the transformation headers is NULL, it
+ * assumes one frame per instance. Optionally, it is possible to import a custom
+ * BVH by setting nodes and the corresponding build flag.
+ */
+typedef struct
+{
+ /*!< Array of instanceCount pointers to geometries */
+ hiprtDevicePtr instanceGeometries;
+ /*!< Array of instanceCount transform headers (optional: per object frame assumed if NULL) */
+ hiprtDevicePtr instanceTransformHeaders;
+ /*!< Array of frameCount frames (supposed to be ordered according to time) */
+ hiprtDevicePtr instanceFrames;
+ /*!< Per object bit masks for instance masking (optional: if NULL masks treated as 0xFFFFFFFF) */
+ hiprtDevicePtr instanceMasks;
+ /*!< Custom Bvh nodes (optional) */
+ hiprtBvhNodeList* nodes;
+ /*!< Number of instances */
+ uint32_t instanceCount;
+ /*!< Number of frames (such that instanceCount <= frameCount) */
+ uint32_t frameCount;
+} hiprtSceneBuildInput;
+
+/** \brief Transformation frame.
+ *
+ * Defines scale, translation, rotation, and time.
+ */
+typedef struct
+{
+ /*!< Rotation (axis and angle) */
+ hiprtFloat4 rotation;
+ /*!< Scale */
+ hiprtFloat3 scale;
+ /*!< Translation */
+ hiprtFloat3 translation;
+ /*!< Time */
+ float time;
+
+ int pad;
+} hiprtFrame;
+
+/** \brief Transformation header.
+ *
+ * Defines defines the index to the array of frames and the number of frames.
+ */
+typedef struct
+{
+ /*!< Frame index */
+ uint32_t frameIndex;
+ /*!< Number of frames */
+ uint32_t frameCount;
+} hiprtTransformHeader;
+
+/** \brief Create HIPRT API context.
+ *
+ * All HIPRT functions expect context as their first argument. Context
+ * keeps global data required by HIPRT session. Calls made from different
+ * threads with different HIPRT contexts are safe. Calls with the same context
+ * should be externally synchronized by the client.
+ *
+ * \param hiprtApiVersion API version.
+ * \param outContext Created context.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtCreateContext( uint32_t hiprtApiVersion, hiprtContextCreationInput& input, hiprtContext* outContext );
+
+/** \brief Destory HIPRT API context.
+ *
+ * Destroys all the global resources used by HIPRT session. Further calls
+ * with this context are prohibited.
+ *
+ * \param context API context.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtDestroyContext( hiprtContext context );
+
+/** \brief Create a geometry.
+ *
+ * This function creates
+ * hiprtGeometry representing acceleration structure topology.
+ *
+ * \param context HIPRT API context.
+ * \param buildInput Describes input primitive to build geometry from.
+ * \param buildOptions Various flags controlling build process.
+ * \param outGeometry Resulting geometry.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtCreateGeometry(
+ hiprtContext context,
+ const hiprtGeometryBuildInput* buildInput,
+ const hiprtBuildOptions* buildOptions,
+ hiprtGeometry* outGeometry );
+
+/** \brief Destroy a geometry.
+ *
+ * This function destroys
+ * hiprtGeometry representing acceleration structure topology.
+ *
+ * \param context HIPRT API context.
+ * \param outGeometry Resulting geometry.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtDestroyGeometry( hiprtContext context, hiprtGeometry outGeometry );
+
+/** \brief Build or update a geometry.
+ *
+ * Given geometry description from the client, this function builds
+ * hiprtGeometry representing acceleration structure topology (in case of a
+ * build) or updates acceleration structure keeping topology intact (update).
+ *
+ * \param context HIPRT API context.
+ * \param buildOperation Type of build operation.
+ * \param buildInput Describes input primitive to build geometry from.
+ * \param buildOptions Various flags controlling build process.
+ * \param attributeOutputs Describes additional values written into vidmem.
+ * \param attributeOutputCount Number of additional attributes, can be 0.
+ * \param temporaryBuffer Temporary buffer for build operation.
+ * \param stream to run acceleration structure build command.
+ * \param outGeometry Resulting geometry.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtBuildGeometry(
+ hiprtContext context,
+ hiprtBuildOperation buildOperation,
+ const hiprtGeometryBuildInput* buildInput,
+ const hiprtBuildOptions* buildOptions,
+ hiprtDevicePtr temporaryBuffer,
+ hiprtApiStream stream,
+ hiprtGeometry outGeometry );
+
+/** \brief Get temporary storage requirements for geometry build.
+ *
+ * \param context HIPRT API context.
+ * \param buildInput Describes input primitive to build geometry from.
+ * \param buildOptions Various flags controlling build process.
+ * \param outSize Pointer to write result to.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtGetGeometryBuildTemporaryBufferSize(
+ hiprtContext context, const hiprtGeometryBuildInput* buildInput, const hiprtBuildOptions* buildOptions, size_t* outSize );
+
+/** \brief Get temporary storage requirements for scene trace.
+ *
+ * \param context HIPRT API context.
+ * \param scene Built scene for trace.
+ * \param numRays Rays to be issued.
+ * \param outSize Pointer to write result to.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError
+hiprtGetGeometryTraceTemporaryBufferSize( hiprtContext context, hiprtGeometry scene, uint32_t numRays, size_t* outSize );
+
+/** \brief Create a scene.
+ *
+ * This function creates
+ * hiprtScene representing acceleration structure topology.
+ *
+ * \param context HIPRT API context.
+ * \param buildInput Decribes input geometires to build scene for.
+ * \param buildOptions Various flags controlling build process.
+ * \param outScene Resulting scene.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtCreateScene(
+ hiprtContext context, const hiprtSceneBuildInput* buildInput, const hiprtBuildOptions* buildOptions, hiprtScene* outScene );
+
+/** \brief Destroy a scene.
+ *
+ * This function destroys
+ * hiprtScene representing acceleration structure topology.
+ *
+ * \param context HIPRT API context.
+ * \param outScene Resulting scene.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtDestroyScene( hiprtContext context, hiprtScene outScene );
+
+/** \brief Build or update a scene.
+ *
+ * Given a number of hiprtGeometries from the client, this function builds
+ * hiprtScene representing top level acceleration structure topology (in case of
+ * a build) or updates acceleration structure keeping topology intact (update).
+ *
+ * \param context HIPRT API context.
+ * \param buildOperation Type of build operation.
+ * \param buildInput Decribes input geometires to build scene for.
+ * \param buildOptions Various flags controlling build process.
+ * \param temporaryBuffer Temporary buffer for build operation.
+ * \param stream to run acceleration structure build command.
+ * \param outScene Resulting scene.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtBuildScene(
+ hiprtContext context,
+ hiprtBuildOperation buildOperation,
+ const hiprtSceneBuildInput* buildInput,
+ const hiprtBuildOptions* buildOptions,
+ hiprtDevicePtr temporaryBuffer,
+ hiprtApiStream stream,
+ hiprtScene outScene );
+
+/** \brief Get temporary storage requirements for scene build.
+ *
+ * \param context HIPRT API context.
+ * \param buildInput Decribes input geometires to build scene for.
+ * \param buildOptions Various flags controlling build process.
+ * \param outSize Pointer to write result to.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtGetSceneBuildTemporaryBufferSize(
+ hiprtContext context, const hiprtSceneBuildInput* buildInput, const hiprtBuildOptions* buildOptions, size_t* outSize );
+
+/** \brief Get temporary storage requirements for scene trace.
+ *
+ * \param context HIPRT API context.
+ * \param scene Built scene for trace.
+ * \param numRays Rays to be issued.
+ * \param outSize Pointer to write result to.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError
+hiprtGetSceneTraceTemporaryBufferSize( hiprtContext context, hiprtScene scene, uint32_t numRays, size_t* outSize );
+
+/** \brief Creates a custom function table (for custom geometry).
+ *
+ * \param context HIPRT API context.
+ * \param outFuncTable Resulting table.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtCreateCustomFuncTable( hiprtContext context, hiprtCustomFuncTable* outFuncTable );
+
+/** \brief Sets a custom function table.
+ *
+ * \param context HIPRT API context.
+ * \param outFuncTable Resulting table.
+ * \param index Index of the set in the table.
+ * \param set Function set to be set.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError
+hiprtSetCustomFuncTable( hiprtContext context, hiprtCustomFuncTable outFuncTable, uint32_t index, hiprtCustomFuncSet set );
+
+/** \brief Destroys a custom function table.
+ *
+ * \param context HIPRT API context.
+ * \param outFuncTable Resulting table.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtDestroyCustomFuncTable( hiprtContext context, hiprtCustomFuncTable outFuncTable );
+
+/** \brief Saves hiprtGeometry to a binary file.
+ *
+ * \param context HIPRT API context.
+ * \param inGeometry Geometry to be saved.
+ * \param filename File name with full path.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtSaveGeometry( hiprtContext context, hiprtGeometry inGeometry, const char* filename );
+
+/** \brief Loads hiprtGeometry to a binary file.
+ *
+ * \param context HIPRT API context.
+ * \param outGeometry Geometry to be loaded.
+ * \param filename File name with full path.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtLoadGeometry( hiprtContext context, hiprtGeometry* outGeometry, const char* filename );
+
+/** \brief Saves hiprtScene to a binary file.
+ *
+ * \param context HIPRT API context.
+ * \param inScene Scene to be saved.
+ * \param filename File name with full path.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtSaveScene( hiprtContext context, hiprtScene inScene, const char* filename );
+
+/** \brief Loads hiprtScene to a binary file.
+ *
+ * \param context HIPRT API context.
+ * \param outScene Scene to be loaded.
+ * \param filename File name with full path.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtLoadScene( hiprtContext context, hiprtScene* outScene, const char* filename );
+
+/** \brief Output scene's AABB.
+ *
+ * \param context HIPRT API context.
+ * \param inGeometry Geometry to be queried.
+ * \param outAabbMin The bounding box min. bound.
+ * \param outAabbMax The bounding box max. bound.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtExportGeometryAabb( hiprtContext context, hiprtGeometry inGeometry, hiprtFloat3& outAabbMin, hiprtFloat3& outAabbMax );
+
+/** \brief Output scene's AABB.
+ *
+ * \param context HIPRT API context.
+ * \param inScene Scene to be queried.
+ * \param outAabbMin The bounding box min. bound.
+ * \param outAabbMax The bounding box max. bound.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtExportSceneAabb( hiprtContext context, hiprtScene inScene, hiprtFloat3& outAabbMin, hiprtFloat3& outAabbMax );
+
+/** \brief Get Program instance with HIPRT routines.
+ * \param functionName function to which handle will be returned, cannot be NULL.
+ * \param context HIPRT API context.
+ * \param src HIP program source.
+ * \param name Program source filename.
+ * \param numHeaders Number of headers, numHeaders must be greater than or equal to 0.
+ * \param headers Sources of the headers, headers can be NULL when numHeaders is 0.
+ * \param includeNames Name of each header by which they can be included in the HIP program source, includeNames can be NULL
+ * when numHeaders is 0.
+ * \param options Compiler options, can be NULL.
+ * \param progOut Output build program instance.
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtBuildTraceProgram(
+ hiprtContext context,
+ const char* functionName,
+ const char* src,
+ const char* name,
+ int numHeaders,
+ const char** headers,
+ const char** includeNames,
+ const char** options,
+ int nOptions,
+ void* progOut );
+
+/** \brief Get binary with HIPRT routines.
+ *
+ * \param prog program instance.
+ * \param size Output size of binary .
+ * \param binary Output if NULL function returns size of parameter else returned binary(application should allocate for binary)..
+ * \return HIPRT error in case of a failure, hiprtSuccess otherwise.
+ */
+HIPRT_API hiprtError hiprtBuildTraceGetBinary(
+ void* prog,
+ size_t* size,
+ void* binary);
+
+/** \brief Setting log level.
+ *
+ * \param path user defined path to cache kernels.
+ */
+HIPRT_API void hiprtSetCacheDirPath(
+ const char* path );
+
+
+/** \brief Setting log level.
+ *
+ * \param level Desired log level.
+ */
+HIPRT_API void hiprtSetLogLevel( int level = 0 );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hiprt-sys/include/hiprt/hiprt_vec.h b/hiprt-sys/include/hiprt/hiprt_vec.h new file mode 100644 index 0000000..11eb531 --- /dev/null +++ b/hiprt-sys/include/hiprt/hiprt_vec.h @@ -0,0 +1,79 @@ +#pragma once
+#if !defined( __KERNELCC__ )
+
+#if !defined( HIPRT_EXPORTS )
+#define HIPRT_HOST_DEVICE
+#define HIPRT_INLINE inline
+#else
+#include <hiprt/impl/Common.h>
+#endif
+
+struct hiprtInt2
+{
+ int x, y;
+};
+
+struct hiprtFloat2
+{
+ float x, y;
+};
+
+struct hiprtInt3
+{
+ int x, y, z;
+};
+
+struct hiprtFloat3
+{
+ float x, y, z;
+};
+
+struct hiprtInt4
+{
+ int x, y, z, w;
+};
+
+struct hiprtFloat4
+{
+ float x, y, z, w;
+};
+
+struct hiprtUint2
+{
+ unsigned int x, y;
+};
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtInt2 make_hiprtInt2( int x, int y ) { return { x, y }; }
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtFloat2 make_hiprtFloat2( float x, float y ) { return { x, y }; }
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtInt3 make_hiprtInt3( int x, int y, int z ) { return { x, y, z }; }
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtFloat3 make_hiprtFloat3( float x, float y, float z ) { return { x, y, z }; }
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtInt4 make_hiprtInt4( int x, int y, int z, int w ) { return { x, y, z, w }; }
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtFloat4 make_hiprtFloat4( float x, float y, float z, float w ) { return { x, y, z, w }; }
+
+HIPRT_HOST_DEVICE HIPRT_INLINE hiprtUint2 make_hiprtUint2( unsigned int x, unsigned int y ) { return { x, y }; }
+
+#if defined( HIPRT_EXPORTS )
+#define int2 hiprtInt2
+#define int3 hiprtInt3
+#define int4 hiprtInt4
+#define uint2 hiprtUint2
+
+#define float2 hiprtFloat2
+#define float3 hiprtFloat3
+#define float4 hiprtFloat4
+
+#define make_int2 make_hiprtInt2
+#define make_int3 make_hiprtInt3
+#define make_int4 make_hiprtInt4
+#define make_uint2 make_hiprtUint2
+
+#define make_float2 make_hiprtFloat2
+#define make_float3 make_hiprtFloat3
+#define make_float4 make_hiprtFloat4
+#endif
+#endif
diff --git a/hiprt-sys/lib/hiprt64.dll b/hiprt-sys/lib/hiprt64.dll Binary files differnew file mode 100644 index 0000000..6008127 --- /dev/null +++ b/hiprt-sys/lib/hiprt64.dll diff --git a/hiprt-sys/lib/hiprt64.lib b/hiprt-sys/lib/hiprt64.lib Binary files differnew file mode 100644 index 0000000..86653a3 --- /dev/null +++ b/hiprt-sys/lib/hiprt64.lib diff --git a/hiprt-sys/lib/libhiprt64.so b/hiprt-sys/lib/libhiprt64.so Binary files differnew file mode 100644 index 0000000..b5b6393 --- /dev/null +++ b/hiprt-sys/lib/libhiprt64.so diff --git a/hiprt-sys/src/hiprt.rs b/hiprt-sys/src/hiprt.rs new file mode 100644 index 0000000..ae32fc6 --- /dev/null +++ b/hiprt-sys/src/hiprt.rs @@ -0,0 +1,979 @@ +/* automatically generated by rust-bindgen 0.69.0 */ + +pub const HIPRT_API_MAJOR_VERSION: u32 = 1; +pub const HIPRT_API_MINOR_VERSION: u32 = 2; +pub const HIPRT_API_PATCH_VERSION: u32 = 0; +pub const HIPRT_API_VERSION: u32 = 1002000; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtInt2 { + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtFloat2 { + pub x: f32, + pub y: f32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtInt3 { + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, + pub z: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtFloat3 { + pub x: f32, + pub y: f32, + pub z: f32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtInt4 { + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, + pub z: ::std::os::raw::c_int, + pub w: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtFloat4 { + pub x: f32, + pub y: f32, + pub z: f32, + pub w: f32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtUint2 { + pub x: ::std::os::raw::c_uint, + pub y: ::std::os::raw::c_uint, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _hiprtContext { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _hiprtCustomFuncTable { + _unused: [u8; 0], +} +pub type hiprtDevicePtr = *mut ::std::os::raw::c_void; +pub type hiprtGeometry = hiprtDevicePtr; +pub type hiprtScene = hiprtDevicePtr; +pub type hiprtBuildFlags = u32; +pub type hiprtRayMask = u32; +pub type hiprtCustomType = u32; +pub type hiprtContext = *mut _hiprtContext; +pub type hiprtCustomFuncTable = *mut _hiprtCustomFuncTable; +pub type hiprtApiDevice = ::std::os::raw::c_int; +pub type hiprtApiCtx = *mut ::std::os::raw::c_void; +pub type hiprtApiStream = *mut ::std::os::raw::c_void; +pub type hiprtApiFunction = *mut ::std::os::raw::c_void; +impl hiprtError { + pub const hiprtSuccess: hiprtError = hiprtError(0); +} +impl hiprtError { + pub const hiprtErrorNotImplemented: hiprtError = hiprtError(1); +} +impl hiprtError { + pub const hiprtErrorInternal: hiprtError = hiprtError(2); +} +impl hiprtError { + pub const hiprtErrorOutOfHostMemory: hiprtError = hiprtError(3); +} +impl hiprtError { + pub const hiprtErrorOutOfDeviceMemory: hiprtError = hiprtError(4); +} +impl hiprtError { + pub const hiprtErrorInvalidApiVersion: hiprtError = hiprtError(5); +} +impl hiprtError { + pub const hiprtErrorInvalidParameter: hiprtError = hiprtError(6); +} +#[repr(transparent)] +#[doc = " \\brief Error codes.\n"] +#[must_use] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtError(pub ::std::os::raw::c_uint); +impl hiprtBuildOperation { + pub const hiprtBuildOperationBuild: hiprtBuildOperation = hiprtBuildOperation(1); +} +impl hiprtBuildOperation { + pub const hiprtBuildOperationUpdate: hiprtBuildOperation = hiprtBuildOperation(2); +} +#[repr(transparent)] +#[doc = " \\brief Type of geometry/scene build operation.\n\n hiprtBuildGeometry/hiprtBuildScene can either build or update\n an underlying acceleration structure."] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtBuildOperation(pub ::std::os::raw::c_uint); +impl hiprtBuildFlagBits { + pub const hiprtBuildFlagBitPreferFastBuild: hiprtBuildFlagBits = hiprtBuildFlagBits(0); +} +impl hiprtBuildFlagBits { + pub const hiprtBuildFlagBitPreferBalancedBuild: hiprtBuildFlagBits = hiprtBuildFlagBits(1); +} +impl hiprtBuildFlagBits { + pub const hiprtBuildFlagBitPreferHighQualityBuild: hiprtBuildFlagBits = hiprtBuildFlagBits(2); +} +impl hiprtBuildFlagBits { + pub const hiprtBuildFlagBitCustomBvhImport: hiprtBuildFlagBits = hiprtBuildFlagBits(3); +} +impl hiprtBuildFlagBits { + pub const hiprtBuildFlagBitDisableSpatialSplits: hiprtBuildFlagBits = hiprtBuildFlagBits(4); +} +#[repr(transparent)] +#[doc = " \\brief Hint flags for geometry/scene build functions.\n\n hiprtBuildGeometry/hiprtBuildScene use these flags to choose\n an appropriate build format/algorithm."] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtBuildFlagBits(pub ::std::os::raw::c_uint); +impl hiprtPrimitiveType { + pub const hiprtPrimitiveTypeTriangleMesh: hiprtPrimitiveType = hiprtPrimitiveType(0); +} +impl hiprtPrimitiveType { + pub const hiprtPrimitiveTypeAABBList: hiprtPrimitiveType = hiprtPrimitiveType(1); +} +#[repr(transparent)] +#[doc = " \\brief Geometric primitive type.\n\n hiprtGeometry can be built from multiple primitive types,\n such as triangle meshes, AABB lists, line lists, etc. This enum\n defines primitive type for hiprtBuildGeometry function."] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtPrimitiveType(pub ::std::os::raw::c_uint); +impl hiprtTraversalState { + pub const hiprtTraversalStateInit: hiprtTraversalState = hiprtTraversalState(0); +} +impl hiprtTraversalState { + pub const hiprtTraversalStateFinished: hiprtTraversalState = hiprtTraversalState(1); +} +impl hiprtTraversalState { + pub const hiprtTraversalStateHit: hiprtTraversalState = hiprtTraversalState(2); +} +impl hiprtTraversalState { + pub const hiprtTraversalStateStackOverflow: hiprtTraversalState = hiprtTraversalState(3); +} +#[repr(transparent)] +#[doc = " \\brief Traversal state.\n\n On-device traversal can be in either hit state (and can be continued using\n hiprtNextHit) or finished state."] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtTraversalState(pub ::std::os::raw::c_uint); +impl hiprtTraversalType { + pub const hiprtTraversalTerminateAtAnyHit: hiprtTraversalType = hiprtTraversalType(1); +} +impl hiprtTraversalType { + pub const hiprtTraversalTerminateAtClosestHit: hiprtTraversalType = hiprtTraversalType(2); +} +#[repr(transparent)] +#[doc = " \\brief Ray traversal type.\n"] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtTraversalType(pub ::std::os::raw::c_uint); +impl hiprtBvhNodeType { + pub const hiprtBvhNodeTypeInternal: hiprtBvhNodeType = hiprtBvhNodeType(0); +} +impl hiprtBvhNodeType { + pub const hiprtBvhNodeTypeLeaf: hiprtBvhNodeType = hiprtBvhNodeType(1); +} +#[repr(transparent)] +#[doc = " \\brief Bvh node type.\n"] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtBvhNodeType(pub ::std::os::raw::c_uint); +#[doc = " \\brief Ray data structure.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtRay { + pub origin: hiprtFloat3, + pub time: f32, + pub direction: hiprtFloat3, + pub maxT: f32, +} +#[doc = " \\brief Ray hit data structure.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtHit { + pub instanceID: u32, + pub primID: u32, + pub uv: hiprtFloat2, + pub normal: hiprtFloat3, + pub t: f32, +} +#[doc = " \\brief Insersection function for custom primitives.\n\n \\param ray Ray.\n \\param primID Primtive ID.\n \\param data User data.\n \\param payload Payload for additional outputs.\n \\param uv Output texture coordinates.\n \\param normal Output normal.\n \\param t Output distance.\n \\return A flag indicating hit."] +pub type hiprtIntersectFunc = ::std::option::Option< + unsafe extern "C" fn( + ray: *const hiprtRay, + primID: u32, + data: *const ::std::os::raw::c_void, + payload: *mut ::std::os::raw::c_void, + uv: *mut hiprtFloat2, + normal: *mut hiprtFloat3, + t: *mut f32, + ) -> bool, +>; +#[doc = " \\brief Set of functions for custom primitives.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtCustomFuncSet { + pub intersectFunc: hiprtIntersectFunc, + pub intersectFuncData: *const ::std::os::raw::c_void, +} +impl hiprtDeviceType { + pub const hiprtDeviceAMD: hiprtDeviceType = hiprtDeviceType(0); +} +impl hiprtDeviceType { + pub const hiprtDeviceNVIDIA: hiprtDeviceType = hiprtDeviceType(1); +} +#[repr(transparent)] +#[doc = " \\brief Device type.\n"] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct hiprtDeviceType(pub ::std::os::raw::c_uint); +#[doc = " \\brief Context creation input.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtContextCreationInput { + pub ctxt: hiprtApiCtx, + pub device: hiprtApiDevice, + pub deviceType: hiprtDeviceType, +} +#[doc = " \\brief Various flags controlling scene/geometry build process.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtBuildOptions { + pub buildFlags: hiprtBuildFlags, +} +#[doc = " \\brief Triangle mesh primitive.\n\n Triangle mesh primitive is represented as an indexed vertex array.\n Vertex and index arrays are defined using device pointers and strides.\n Each vertex has to have 3 components: (x, y, z) coordinates.\n Indices are organized into triples (i0, i1, i2) - one for each triangle."] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtTriangleMeshPrimitive { + pub vertices: hiprtDevicePtr, + pub vertexCount: u32, + pub vertexStride: u32, + pub triangleIndices: hiprtDevicePtr, + pub triangleCount: u32, + pub triangleStride: u32, +} +#[doc = " \\brief AABB list primitive.\n\n AABB list is an array of axis aligned bounding boxes, represented\n by device memory pointer and stride between two consequetive boxes.\n Each AABB is a pair of float4 values (xmin, ymin, zmin, unused), (xmax, ymax,\n zmax, unused)."] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtAABBListPrimitive { + pub aabbs: hiprtDevicePtr, + pub aabbCount: u32, + pub aabbStride: u32, +} +#[doc = " \\brief Bvh node for custom import Bvh.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtBvhNode { + pub childIndices: [u32; 4usize], + pub childNodeTypes: [hiprtBvhNodeType; 4usize], + pub boundingBoxMin: hiprtFloat3, + pub boundingBoxMax: hiprtFloat3, + pub pad: [::std::os::raw::c_int; 2usize], +} +#[doc = " \\brief Bvh node list.\n"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtBvhNodeList { + pub nodes: hiprtDevicePtr, + pub nodeCount: u32, +} +#[doc = " \\brief Input for geometry build/update operation.\n\n Build input defines concrete primitive type and a pointer to an actual\n primitive description."] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtGeometryBuildInput { + pub type_: hiprtPrimitiveType, + pub __bindgen_anon_1: hiprtGeometryBuildInput__bindgen_ty_1, + pub nodes: *mut hiprtBvhNodeList, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union hiprtGeometryBuildInput__bindgen_ty_1 { + pub triangleMesh: hiprtGeometryBuildInput__bindgen_ty_1__bindgen_ty_1, + pub aabbList: hiprtGeometryBuildInput__bindgen_ty_1__bindgen_ty_2, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtGeometryBuildInput__bindgen_ty_1__bindgen_ty_1 { + pub primitive: *mut hiprtTriangleMeshPrimitive, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtGeometryBuildInput__bindgen_ty_1__bindgen_ty_2 { + pub primitive: *mut hiprtAABBListPrimitive, + pub customType: hiprtCustomType, +} +#[doc = " \\brief Build input for the scene.\n\n Scene consists of a set of instances. Each of the instances is defined by:\n - Root pointer of the corresponding geometry\n - Transformation header\n - Mask\n\n Instances can refer to the same geometry but with different transformations\n (essentially implementing instancing). Mask is used to implement ray\n masking: ray mask is bitwise &ded with an instance mask, and no intersections\n are evaluated with the primitive of corresponding instance if the result is\n 0. The transformation header defines the offset and the number of consecutive\n transformation frames in the frame array for each instance. More than one frame\n is interpreted as motion blur. If the transformation headers is NULL, it\n assumes one frame per instance. Optionally, it is possible to import a custom\n BVH by setting nodes and the corresponding build flag."] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtSceneBuildInput { + pub instanceGeometries: hiprtDevicePtr, + pub instanceTransformHeaders: hiprtDevicePtr, + pub instanceFrames: hiprtDevicePtr, + pub instanceMasks: hiprtDevicePtr, + pub nodes: *mut hiprtBvhNodeList, + pub instanceCount: u32, + pub frameCount: u32, +} +#[doc = " \\brief Transformation frame.\n\n Defines scale, translation, rotation, and time."] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtFrame { + pub rotation: hiprtFloat4, + pub scale: hiprtFloat3, + pub translation: hiprtFloat3, + pub time: f32, + pub pad: ::std::os::raw::c_int, +} +#[doc = " \\brief Transformation header.\n\n Defines defines the index to the array of frames and the number of frames."] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct hiprtTransformHeader { + pub frameIndex: u32, + pub frameCount: u32, +} +extern crate libloading; +pub struct HipRt { + __library: ::libloading::Library, + pub hiprtCreateContext: Result< + unsafe extern "C" fn( + hiprtApiVersion: u32, + input: *mut hiprtContextCreationInput, + outContext: *mut hiprtContext, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtDestroyContext: + Result<unsafe extern "C" fn(context: hiprtContext) -> hiprtError, ::libloading::Error>, + pub hiprtCreateGeometry: Result< + unsafe extern "C" fn( + context: hiprtContext, + buildInput: *const hiprtGeometryBuildInput, + buildOptions: *const hiprtBuildOptions, + outGeometry: *mut hiprtGeometry, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtDestroyGeometry: Result< + unsafe extern "C" fn(context: hiprtContext, outGeometry: hiprtGeometry) -> hiprtError, + ::libloading::Error, + >, + pub hiprtBuildGeometry: Result< + unsafe extern "C" fn( + context: hiprtContext, + buildOperation: hiprtBuildOperation, + buildInput: *const hiprtGeometryBuildInput, + buildOptions: *const hiprtBuildOptions, + temporaryBuffer: hiprtDevicePtr, + stream: hiprtApiStream, + outGeometry: hiprtGeometry, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtGetGeometryBuildTemporaryBufferSize: Result< + unsafe extern "C" fn( + context: hiprtContext, + buildInput: *const hiprtGeometryBuildInput, + buildOptions: *const hiprtBuildOptions, + outSize: *mut usize, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtGetGeometryTraceTemporaryBufferSize: Result< + unsafe extern "C" fn( + context: hiprtContext, + scene: hiprtGeometry, + numRays: u32, + outSize: *mut usize, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtCreateScene: Result< + unsafe extern "C" fn( + context: hiprtContext, + buildInput: *const hiprtSceneBuildInput, + buildOptions: *const hiprtBuildOptions, + outScene: *mut hiprtScene, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtDestroyScene: Result< + unsafe extern "C" fn(context: hiprtContext, outScene: hiprtScene) -> hiprtError, + ::libloading::Error, + >, + pub hiprtBuildScene: Result< + unsafe extern "C" fn( + context: hiprtContext, + buildOperation: hiprtBuildOperation, + buildInput: *const hiprtSceneBuildInput, + buildOptions: *const hiprtBuildOptions, + temporaryBuffer: hiprtDevicePtr, + stream: hiprtApiStream, + outScene: hiprtScene, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtGetSceneBuildTemporaryBufferSize: Result< + unsafe extern "C" fn( + context: hiprtContext, + buildInput: *const hiprtSceneBuildInput, + buildOptions: *const hiprtBuildOptions, + outSize: *mut usize, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtGetSceneTraceTemporaryBufferSize: Result< + unsafe extern "C" fn( + context: hiprtContext, + scene: hiprtScene, + numRays: u32, + outSize: *mut usize, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtCreateCustomFuncTable: Result< + unsafe extern "C" fn( + context: hiprtContext, + outFuncTable: *mut hiprtCustomFuncTable, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtSetCustomFuncTable: Result< + unsafe extern "C" fn( + context: hiprtContext, + outFuncTable: hiprtCustomFuncTable, + index: u32, + set: hiprtCustomFuncSet, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtDestroyCustomFuncTable: Result< + unsafe extern "C" fn( + context: hiprtContext, + outFuncTable: hiprtCustomFuncTable, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtSaveGeometry: Result< + unsafe extern "C" fn( + context: hiprtContext, + inGeometry: hiprtGeometry, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtLoadGeometry: Result< + unsafe extern "C" fn( + context: hiprtContext, + outGeometry: *mut hiprtGeometry, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtSaveScene: Result< + unsafe extern "C" fn( + context: hiprtContext, + inScene: hiprtScene, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtLoadScene: Result< + unsafe extern "C" fn( + context: hiprtContext, + outScene: *mut hiprtScene, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtExportGeometryAabb: Result< + unsafe extern "C" fn( + context: hiprtContext, + inGeometry: hiprtGeometry, + outAabbMin: *mut hiprtFloat3, + outAabbMax: *mut hiprtFloat3, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtExportSceneAabb: Result< + unsafe extern "C" fn( + context: hiprtContext, + inScene: hiprtScene, + outAabbMin: *mut hiprtFloat3, + outAabbMax: *mut hiprtFloat3, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtBuildTraceProgram: Result< + unsafe extern "C" fn( + context: hiprtContext, + functionName: *const ::std::os::raw::c_char, + src: *const ::std::os::raw::c_char, + name: *const ::std::os::raw::c_char, + numHeaders: ::std::os::raw::c_int, + headers: *mut *const ::std::os::raw::c_char, + includeNames: *mut *const ::std::os::raw::c_char, + options: *mut *const ::std::os::raw::c_char, + nOptions: ::std::os::raw::c_int, + progOut: *mut ::std::os::raw::c_void, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtBuildTraceGetBinary: Result< + unsafe extern "C" fn( + prog: *mut ::std::os::raw::c_void, + size: *mut usize, + binary: *mut ::std::os::raw::c_void, + ) -> hiprtError, + ::libloading::Error, + >, + pub hiprtSetCacheDirPath: + Result<unsafe extern "C" fn(path: *const ::std::os::raw::c_char), ::libloading::Error>, + pub hiprtSetLogLevel: + Result<unsafe extern "C" fn(level: ::std::os::raw::c_int), ::libloading::Error>, +} +impl HipRt { + pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error> + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error> + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let hiprtCreateContext = __library.get(b"hiprtCreateContext\0").map(|sym| *sym); + let hiprtDestroyContext = __library.get(b"hiprtDestroyContext\0").map(|sym| *sym); + let hiprtCreateGeometry = __library.get(b"hiprtCreateGeometry\0").map(|sym| *sym); + let hiprtDestroyGeometry = __library.get(b"hiprtDestroyGeometry\0").map(|sym| *sym); + let hiprtBuildGeometry = __library.get(b"hiprtBuildGeometry\0").map(|sym| *sym); + let hiprtGetGeometryBuildTemporaryBufferSize = __library + .get(b"hiprtGetGeometryBuildTemporaryBufferSize\0") + .map(|sym| *sym); + let hiprtGetGeometryTraceTemporaryBufferSize = __library + .get(b"hiprtGetGeometryTraceTemporaryBufferSize\0") + .map(|sym| *sym); + let hiprtCreateScene = __library.get(b"hiprtCreateScene\0").map(|sym| *sym); + let hiprtDestroyScene = __library.get(b"hiprtDestroyScene\0").map(|sym| *sym); + let hiprtBuildScene = __library.get(b"hiprtBuildScene\0").map(|sym| *sym); + let hiprtGetSceneBuildTemporaryBufferSize = __library + .get(b"hiprtGetSceneBuildTemporaryBufferSize\0") + .map(|sym| *sym); + let hiprtGetSceneTraceTemporaryBufferSize = __library + .get(b"hiprtGetSceneTraceTemporaryBufferSize\0") + .map(|sym| *sym); + let hiprtCreateCustomFuncTable = __library + .get(b"hiprtCreateCustomFuncTable\0") + .map(|sym| *sym); + let hiprtSetCustomFuncTable = __library.get(b"hiprtSetCustomFuncTable\0").map(|sym| *sym); + let hiprtDestroyCustomFuncTable = __library + .get(b"hiprtDestroyCustomFuncTable\0") + .map(|sym| *sym); + let hiprtSaveGeometry = __library.get(b"hiprtSaveGeometry\0").map(|sym| *sym); + let hiprtLoadGeometry = __library.get(b"hiprtLoadGeometry\0").map(|sym| *sym); + let hiprtSaveScene = __library.get(b"hiprtSaveScene\0").map(|sym| *sym); + let hiprtLoadScene = __library.get(b"hiprtLoadScene\0").map(|sym| *sym); + let hiprtExportGeometryAabb = __library.get(b"hiprtExportGeometryAabb\0").map(|sym| *sym); + let hiprtExportSceneAabb = __library.get(b"hiprtExportSceneAabb\0").map(|sym| *sym); + let hiprtBuildTraceProgram = __library.get(b"hiprtBuildTraceProgram\0").map(|sym| *sym); + let hiprtBuildTraceGetBinary = __library.get(b"hiprtBuildTraceGetBinary\0").map(|sym| *sym); + let hiprtSetCacheDirPath = __library.get(b"hiprtSetCacheDirPath\0").map(|sym| *sym); + let hiprtSetLogLevel = __library.get(b"hiprtSetLogLevel\0").map(|sym| *sym); + Ok(HipRt { + __library, + hiprtCreateContext, + hiprtDestroyContext, + hiprtCreateGeometry, + hiprtDestroyGeometry, + hiprtBuildGeometry, + hiprtGetGeometryBuildTemporaryBufferSize, + hiprtGetGeometryTraceTemporaryBufferSize, + hiprtCreateScene, + hiprtDestroyScene, + hiprtBuildScene, + hiprtGetSceneBuildTemporaryBufferSize, + hiprtGetSceneTraceTemporaryBufferSize, + hiprtCreateCustomFuncTable, + hiprtSetCustomFuncTable, + hiprtDestroyCustomFuncTable, + hiprtSaveGeometry, + hiprtLoadGeometry, + hiprtSaveScene, + hiprtLoadScene, + hiprtExportGeometryAabb, + hiprtExportSceneAabb, + hiprtBuildTraceProgram, + hiprtBuildTraceGetBinary, + hiprtSetCacheDirPath, + hiprtSetLogLevel, + }) + } + #[must_use] + #[doc = " \\brief Create HIPRT API context.\n\n All HIPRT functions expect context as their first argument. Context\n keeps global data required by HIPRT session. Calls made from different\n threads with different HIPRT contexts are safe. Calls with the same context\n should be externally synchronized by the client.\n\n \\param hiprtApiVersion API version.\n \\param outContext Created context.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtCreateContext( + &self, + hiprtApiVersion: u32, + input: *mut hiprtContextCreationInput, + outContext: *mut hiprtContext, + ) -> hiprtError { + (self + .hiprtCreateContext + .as_ref() + .expect("Expected function, got error."))(hiprtApiVersion, input, outContext) + } + #[must_use] + #[doc = " \\brief Destory HIPRT API context.\n\n Destroys all the global resources used by HIPRT session. Further calls\n with this context are prohibited.\n\n \\param context API context.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtDestroyContext(&self, context: hiprtContext) -> hiprtError { + (self + .hiprtDestroyContext + .as_ref() + .expect("Expected function, got error."))(context) + } + #[must_use] + #[doc = " \\brief Create a geometry.\n\n This function creates\n hiprtGeometry representing acceleration structure topology.\n\n \\param context HIPRT API context.\n \\param buildInput Describes input primitive to build geometry from.\n \\param buildOptions Various flags controlling build process.\n \\param outGeometry Resulting geometry.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtCreateGeometry( + &self, + context: hiprtContext, + buildInput: *const hiprtGeometryBuildInput, + buildOptions: *const hiprtBuildOptions, + outGeometry: *mut hiprtGeometry, + ) -> hiprtError { + (self + .hiprtCreateGeometry + .as_ref() + .expect("Expected function, got error."))( + context, + buildInput, + buildOptions, + outGeometry, + ) + } + #[must_use] + #[doc = " \\brief Destroy a geometry.\n\n This function destroys\n hiprtGeometry representing acceleration structure topology.\n\n \\param context HIPRT API context.\n \\param outGeometry Resulting geometry.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtDestroyGeometry( + &self, + context: hiprtContext, + outGeometry: hiprtGeometry, + ) -> hiprtError { + (self + .hiprtDestroyGeometry + .as_ref() + .expect("Expected function, got error."))(context, outGeometry) + } + #[must_use] + #[doc = " \\brief Build or update a geometry.\n\n Given geometry description from the client, this function builds\n hiprtGeometry representing acceleration structure topology (in case of a\n build) or updates acceleration structure keeping topology intact (update).\n\n \\param context HIPRT API context.\n \\param buildOperation Type of build operation.\n \\param buildInput Describes input primitive to build geometry from.\n \\param buildOptions Various flags controlling build process.\n \\param attributeOutputs Describes additional values written into vidmem.\n \\param attributeOutputCount Number of additional attributes, can be 0.\n \\param temporaryBuffer Temporary buffer for build operation.\n \\param stream to run acceleration structure build command.\n \\param outGeometry Resulting geometry.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtBuildGeometry( + &self, + context: hiprtContext, + buildOperation: hiprtBuildOperation, + buildInput: *const hiprtGeometryBuildInput, + buildOptions: *const hiprtBuildOptions, + temporaryBuffer: hiprtDevicePtr, + stream: hiprtApiStream, + outGeometry: hiprtGeometry, + ) -> hiprtError { + (self + .hiprtBuildGeometry + .as_ref() + .expect("Expected function, got error."))( + context, + buildOperation, + buildInput, + buildOptions, + temporaryBuffer, + stream, + outGeometry, + ) + } + #[must_use] + #[doc = " \\brief Get temporary storage requirements for geometry build.\n\n \\param context HIPRT API context.\n \\param buildInput Describes input primitive to build geometry from.\n \\param buildOptions Various flags controlling build process.\n \\param outSize Pointer to write result to.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtGetGeometryBuildTemporaryBufferSize( + &self, + context: hiprtContext, + buildInput: *const hiprtGeometryBuildInput, + buildOptions: *const hiprtBuildOptions, + outSize: *mut usize, + ) -> hiprtError { + (self + .hiprtGetGeometryBuildTemporaryBufferSize + .as_ref() + .expect("Expected function, got error."))( + context, buildInput, buildOptions, outSize + ) + } + #[must_use] + #[doc = " \\brief Get temporary storage requirements for scene trace.\n\n \\param context HIPRT API context.\n \\param scene Built scene for trace.\n \\param numRays Rays to be issued.\n \\param outSize Pointer to write result to.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtGetGeometryTraceTemporaryBufferSize( + &self, + context: hiprtContext, + scene: hiprtGeometry, + numRays: u32, + outSize: *mut usize, + ) -> hiprtError { + (self + .hiprtGetGeometryTraceTemporaryBufferSize + .as_ref() + .expect("Expected function, got error."))(context, scene, numRays, outSize) + } + #[must_use] + #[doc = " \\brief Create a scene.\n\n This function creates\n hiprtScene representing acceleration structure topology.\n\n \\param context HIPRT API context.\n \\param buildInput Decribes input geometires to build scene for.\n \\param buildOptions Various flags controlling build process.\n \\param outScene Resulting scene.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtCreateScene( + &self, + context: hiprtContext, + buildInput: *const hiprtSceneBuildInput, + buildOptions: *const hiprtBuildOptions, + outScene: *mut hiprtScene, + ) -> hiprtError { + (self + .hiprtCreateScene + .as_ref() + .expect("Expected function, got error."))( + context, buildInput, buildOptions, outScene + ) + } + #[must_use] + #[doc = " \\brief Destroy a scene.\n\n This function destroys\n hiprtScene representing acceleration structure topology.\n\n \\param context HIPRT API context.\n \\param outScene Resulting scene.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtDestroyScene( + &self, + context: hiprtContext, + outScene: hiprtScene, + ) -> hiprtError { + (self + .hiprtDestroyScene + .as_ref() + .expect("Expected function, got error."))(context, outScene) + } + #[must_use] + #[doc = " \\brief Build or update a scene.\n\n Given a number of hiprtGeometries from the client, this function builds\n hiprtScene representing top level acceleration structure topology (in case of\n a build) or updates acceleration structure keeping topology intact (update).\n\n \\param context HIPRT API context.\n \\param buildOperation Type of build operation.\n \\param buildInput Decribes input geometires to build scene for.\n \\param buildOptions Various flags controlling build process.\n \\param temporaryBuffer Temporary buffer for build operation.\n \\param stream to run acceleration structure build command.\n \\param outScene Resulting scene.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtBuildScene( + &self, + context: hiprtContext, + buildOperation: hiprtBuildOperation, + buildInput: *const hiprtSceneBuildInput, + buildOptions: *const hiprtBuildOptions, + temporaryBuffer: hiprtDevicePtr, + stream: hiprtApiStream, + outScene: hiprtScene, + ) -> hiprtError { + (self + .hiprtBuildScene + .as_ref() + .expect("Expected function, got error."))( + context, + buildOperation, + buildInput, + buildOptions, + temporaryBuffer, + stream, + outScene, + ) + } + #[must_use] + #[doc = " \\brief Get temporary storage requirements for scene build.\n\n \\param context HIPRT API context.\n \\param buildInput Decribes input geometires to build scene for.\n \\param buildOptions Various flags controlling build process.\n \\param outSize Pointer to write result to.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtGetSceneBuildTemporaryBufferSize( + &self, + context: hiprtContext, + buildInput: *const hiprtSceneBuildInput, + buildOptions: *const hiprtBuildOptions, + outSize: *mut usize, + ) -> hiprtError { + (self + .hiprtGetSceneBuildTemporaryBufferSize + .as_ref() + .expect("Expected function, got error."))( + context, buildInput, buildOptions, outSize + ) + } + #[must_use] + #[doc = " \\brief Get temporary storage requirements for scene trace.\n\n \\param context HIPRT API context.\n \\param scene Built scene for trace.\n \\param numRays Rays to be issued.\n \\param outSize Pointer to write result to.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtGetSceneTraceTemporaryBufferSize( + &self, + context: hiprtContext, + scene: hiprtScene, + numRays: u32, + outSize: *mut usize, + ) -> hiprtError { + (self + .hiprtGetSceneTraceTemporaryBufferSize + .as_ref() + .expect("Expected function, got error."))(context, scene, numRays, outSize) + } + #[must_use] + #[doc = " \\brief Creates a custom function table (for custom geometry).\n\n \\param context HIPRT API context.\n \\param outFuncTable Resulting table.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtCreateCustomFuncTable( + &self, + context: hiprtContext, + outFuncTable: *mut hiprtCustomFuncTable, + ) -> hiprtError { + (self + .hiprtCreateCustomFuncTable + .as_ref() + .expect("Expected function, got error."))(context, outFuncTable) + } + #[must_use] + #[doc = " \\brief Sets a custom function table.\n\n \\param context HIPRT API context.\n \\param outFuncTable Resulting table.\n \\param index Index of the set in the table.\n \\param set Function set to be set.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtSetCustomFuncTable( + &self, + context: hiprtContext, + outFuncTable: hiprtCustomFuncTable, + index: u32, + set: hiprtCustomFuncSet, + ) -> hiprtError { + (self + .hiprtSetCustomFuncTable + .as_ref() + .expect("Expected function, got error."))(context, outFuncTable, index, set) + } + #[must_use] + #[doc = " \\brief Destroys a custom function table.\n\n \\param context HIPRT API context.\n \\param outFuncTable Resulting table.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtDestroyCustomFuncTable( + &self, + context: hiprtContext, + outFuncTable: hiprtCustomFuncTable, + ) -> hiprtError { + (self + .hiprtDestroyCustomFuncTable + .as_ref() + .expect("Expected function, got error."))(context, outFuncTable) + } + #[must_use] + #[doc = " \\brief Saves hiprtGeometry to a binary file.\n\n \\param context HIPRT API context.\n \\param inGeometry Geometry to be saved.\n \\param filename File name with full path.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtSaveGeometry( + &self, + context: hiprtContext, + inGeometry: hiprtGeometry, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError { + (self + .hiprtSaveGeometry + .as_ref() + .expect("Expected function, got error."))(context, inGeometry, filename) + } + #[must_use] + #[doc = " \\brief Loads hiprtGeometry to a binary file.\n\n \\param context HIPRT API context.\n \\param outGeometry Geometry to be loaded.\n \\param filename File name with full path.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtLoadGeometry( + &self, + context: hiprtContext, + outGeometry: *mut hiprtGeometry, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError { + (self + .hiprtLoadGeometry + .as_ref() + .expect("Expected function, got error."))(context, outGeometry, filename) + } + #[must_use] + #[doc = " \\brief Saves hiprtScene to a binary file.\n\n \\param context HIPRT API context.\n \\param inScene Scene to be saved.\n \\param filename File name with full path.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtSaveScene( + &self, + context: hiprtContext, + inScene: hiprtScene, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError { + (self + .hiprtSaveScene + .as_ref() + .expect("Expected function, got error."))(context, inScene, filename) + } + #[must_use] + #[doc = " \\brief Loads hiprtScene to a binary file.\n\n \\param context HIPRT API context.\n \\param outScene Scene to be loaded.\n \\param filename File name with full path.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtLoadScene( + &self, + context: hiprtContext, + outScene: *mut hiprtScene, + filename: *const ::std::os::raw::c_char, + ) -> hiprtError { + (self + .hiprtLoadScene + .as_ref() + .expect("Expected function, got error."))(context, outScene, filename) + } + #[must_use] + #[doc = " \\brief Output scene's AABB.\n\n \\param context HIPRT API context.\n \\param inGeometry Geometry to be queried.\n \\param outAabbMin The bounding box min. bound.\n \\param outAabbMax The bounding box max. bound.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtExportGeometryAabb( + &self, + context: hiprtContext, + inGeometry: hiprtGeometry, + outAabbMin: *mut hiprtFloat3, + outAabbMax: *mut hiprtFloat3, + ) -> hiprtError { + (self + .hiprtExportGeometryAabb + .as_ref() + .expect("Expected function, got error."))( + context, inGeometry, outAabbMin, outAabbMax + ) + } + #[must_use] + #[doc = " \\brief Output scene's AABB.\n\n \\param context HIPRT API context.\n \\param inScene Scene to be queried.\n \\param outAabbMin The bounding box min. bound.\n \\param outAabbMax The bounding box max. bound.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtExportSceneAabb( + &self, + context: hiprtContext, + inScene: hiprtScene, + outAabbMin: *mut hiprtFloat3, + outAabbMax: *mut hiprtFloat3, + ) -> hiprtError { + (self + .hiprtExportSceneAabb + .as_ref() + .expect("Expected function, got error."))( + context, inScene, outAabbMin, outAabbMax + ) + } + #[must_use] + #[doc = " \\brief Get Program instance with HIPRT routines.\n \\param functionName function to which handle will be returned, cannot be NULL.\n \\param context HIPRT API context.\n \\param src HIP program source.\n \\param name Program source filename.\n \\param numHeaders Number of headers, numHeaders must be greater than or equal to 0.\n \\param headers Sources of the headers, headers can be NULL when numHeaders is 0.\n \\param includeNames Name of each header by which they can be included in the HIP program source, includeNames can be NULL\n when numHeaders is 0.\n \\param options Compiler options, can be NULL.\n \\param progOut Output build program instance.\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtBuildTraceProgram( + &self, + context: hiprtContext, + functionName: *const ::std::os::raw::c_char, + src: *const ::std::os::raw::c_char, + name: *const ::std::os::raw::c_char, + numHeaders: ::std::os::raw::c_int, + headers: *mut *const ::std::os::raw::c_char, + includeNames: *mut *const ::std::os::raw::c_char, + options: *mut *const ::std::os::raw::c_char, + nOptions: ::std::os::raw::c_int, + progOut: *mut ::std::os::raw::c_void, + ) -> hiprtError { + (self + .hiprtBuildTraceProgram + .as_ref() + .expect("Expected function, got error."))( + context, + functionName, + src, + name, + numHeaders, + headers, + includeNames, + options, + nOptions, + progOut, + ) + } + #[must_use] + #[doc = " \\brief Get binary with HIPRT routines.\n\n \\param prog program instance.\n \\param size Output size of binary .\n \\param binary Output if NULL function returns size of parameter else returned binary(application should allocate for binary)..\n \\return HIPRT error in case of a failure, hiprtSuccess otherwise."] + pub unsafe fn hiprtBuildTraceGetBinary( + &self, + prog: *mut ::std::os::raw::c_void, + size: *mut usize, + binary: *mut ::std::os::raw::c_void, + ) -> hiprtError { + (self + .hiprtBuildTraceGetBinary + .as_ref() + .expect("Expected function, got error."))(prog, size, binary) + } + #[doc = " \\brief Setting log level.\n\n \\param path user defined path to cache kernels."] + pub unsafe fn hiprtSetCacheDirPath(&self, path: *const ::std::os::raw::c_char) { + (self + .hiprtSetCacheDirPath + .as_ref() + .expect("Expected function, got error."))(path) + } + #[doc = " \\brief Setting log level.\n\n \\param level Desired log level."] + pub unsafe fn hiprtSetLogLevel(&self, level: ::std::os::raw::c_int) { + (self + .hiprtSetLogLevel + .as_ref() + .expect("Expected function, got error."))(level) + } +} diff --git a/hiprt-sys/src/lib.rs b/hiprt-sys/src/lib.rs new file mode 100644 index 0000000..a931426 --- /dev/null +++ b/hiprt-sys/src/lib.rs @@ -0,0 +1,84 @@ +#![allow(warnings)]
+pub mod hiprt;
+pub use hiprt::*;
+
+use std::ffi::OsString;
+use std::mem;
+use std::path::PathBuf;
+
+impl hiprt::HipRt {
+ pub unsafe fn load() -> Result<Self, libloading::Error> {
+ Self::new(os::HIPRT_NAME).or_else(|_| {
+ let module_path = os::currently_executing().ok_or(os::UNKNOWN_ERROR)?;
+ let mut path = PathBuf::from(module_path);
+ if !path.pop() {
+ return Err(os::UNKNOWN_ERROR);
+ }
+ path.push(os::HIPRT_NAME);
+ Self::new(path)
+ })
+ }
+}
+
+#[cfg(not(target_os = "windows"))]
+mod os {
+ use std::ffi::CStr;
+ use std::os::unix::ffi::OsStringExt;
+ use std::{
+ ffi::{c_char, c_int, c_void, CString, OsString},
+ mem,
+ };
+
+ pub(crate) const HIPRT_NAME: &'static str = "libhiprt64.so";
+ pub(crate) const UNKNOWN_ERROR: libloading::Error = libloading::Error::DlOpenUnknown;
+
+ #[link(name = "dl")]
+ extern "C" {
+ fn dladdr(addr: *mut c_void, info: *mut DlInfo) -> c_int;
+ }
+
+ pub(crate) unsafe fn currently_executing() -> Option<OsString> {
+ let mut dlinfo = mem::zeroed();
+ if 0 == dladdr(currently_executing as _, &mut dlinfo) {
+ return None;
+ }
+ Some(OsString::from_vec(
+ CStr::from_ptr(dlinfo.dli_fname.cast_mut())
+ .to_bytes()
+ .to_vec(),
+ ))
+ }
+
+ #[repr(C)]
+ struct DlInfo {
+ dli_fname: *const c_char,
+ dli_fbase: *mut c_void,
+ dli_sname: *const c_char,
+ dli_saddr: *mut c_void,
+ }
+}
+
+#[cfg(target_os = "windows")]
+mod os {
+ use std::ffi::OsString;
+ use std::mem;
+ use widestring::U16CStr;
+ use winapi::shared::minwindef::HMODULE;
+ use winapi::um::libloaderapi::*;
+
+ pub(crate) const HIPRT_NAME: &'static str = "hiprt64.dll";
+ pub(crate) const UNKNOWN_ERROR: libloading::Error =
+ libloading::Error::GetModuleHandleExWUnknown;
+
+ pub(crate) unsafe fn currently_executing() -> Option<OsString> {
+ let mut module = mem::zeroed();
+ if 0 == GetModuleHandleExW(
+ GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ currently_executing as _,
+ &mut module,
+ ) {
+ return None;
+ }
+ Some(U16CStr::from_ptr_str(module.cast()).to_os_string())
+ }
+}
|