Blender V4.5
hiprt/device_impl.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#ifdef WITH_HIPRT
8
10# include "device/hip/kernel.h"
11# include "device/hip/queue.h"
12# include "device/hiprt/queue.h"
13
14# ifdef WITH_HIP_DYNLOAD
15# include <hiprtew.h>
16# else
17# include <hiprt/hiprt_types.h>
18# endif
19
21
22class Mesh;
23class Hair;
24class PointCloud;
25class Geometry;
26class Object;
27class BVHHIPRT;
28
29class HIPRTDevice : public HIPDevice {
30
31 public:
32 BVHLayoutMask get_bvh_layout_mask(const uint kernel_features) const override;
33
34 HIPRTDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless);
35
36 ~HIPRTDevice() override;
37 unique_ptr<DeviceQueue> gpu_queue_create() override;
38 string compile_kernel_get_common_cflags(const uint kernel_features) override;
39 string compile_kernel(const uint kernel_features,
40 const char *name,
41 const char *base = "hiprt") override;
42
43 bool load_kernels(const uint kernel_features) override;
44
45 void const_copy_to(const char *name, void *host, const size_t size) override;
46
47 void build_bvh(BVH *bvh, Progress &progress, bool refit) override;
48
49 hiprtContext get_hiprt_context()
50 {
51 return hiprt_context;
52 }
53
54 hiprtGlobalStackBuffer global_stack_buffer;
55
56 protected:
57 enum Filter_Function { Closest = 0, Shadows, Local, Volume, Max_Intersect_Filter_Function };
58 enum Primitive_Type { Triangle = 0, Curve, Motion_Triangle, Point, Max_Primitive_Type };
59
60 hiprtGeometryBuildInput prepare_triangle_blas(BVHHIPRT *bvh, Mesh *mesh);
61 hiprtGeometryBuildInput prepare_curve_blas(BVHHIPRT *bvh, Hair *hair);
62 hiprtGeometryBuildInput prepare_point_blas(BVHHIPRT *bvh, PointCloud *pointcloud);
63 void build_blas(BVHHIPRT *bvh, Geometry *geom, hiprtBuildOptions options);
64 hiprtScene build_tlas(BVHHIPRT *bvh,
65 const vector<Object *> &objects,
66 hiprtBuildOptions options,
67 bool refit);
68
69 hiprtContext hiprt_context;
70 hiprtScene scene;
71 hiprtFuncTable functions_table;
72
73 thread_mutex hiprt_mutex;
74 size_t scratch_buffer_size;
75 device_vector<char> scratch_buffer;
76
77 /* Is this scene using motion blur? Note there might exist motion data even if
78 * motion blur is disabled, for render passes. */
79 bool use_motion_blur = false;
80
81 /* The following vectors are to transfer scene information available on the host to the GPU
82 * visibility, instance_transform_matrix, transform_headers, and hiprt_blas_ptr are passed to
83 * hiprt to build bvh the rest are directly used in traversal functions/intersection kernels and
84 * are defined on the GPU side as members of KernelParamsHIPRT struct the host memory is copied
85 * to GPU through const_copy_to() function. */
86
87 /* Originally, visibility was only passed to HIP RT but after a bug report it was noted it was
88 * required for custom primitives (i.e., motion triangles). This buffer, however, has visibility
89 * per object not per primitive so the same buffer as the one that is passed to HIP RT can be
90 * used. */
91 device_vector<uint32_t> prim_visibility;
92
93 /* instance_transform_matrix passes transform matrix of instances converted from Cycles Transform
94 * format to instanceFrames member of hiprtSceneBuildInput. */
95 device_vector<hiprtFrameMatrix> instance_transform_matrix;
96 /* Movement over a time interval for motion blur is captured through multiple transform matrices.
97 * In this case transform matrix of an instance cannot be directly retrieved by looking up
98 * instance_transform_matrix give the instance id. transform_headers maps the instance id to the
99 * appropriate index to retrieve instance transform matrix (frameIndex member of
100 * hiprtTransformHeader). transform_headers also has the information on how many transform
101 * matrices are associated with an instance (frameCount member of hiprtTransformHeader)
102 * transform_headers is passed to hiprt through instanceTransformHeaders member of
103 * hiprtSceneBuildInput. */
104 device_vector<hiprtTransformHeader> transform_headers;
105
106 /* Instance/object ids are not explicitly passed to hiprt.
107 * HIP RT assigns the ids based on the order blas pointers are passed to it (through
108 * instanceGeometries member of hiprtSceneBuildInput). If blas is absent for a particular
109 * geometry (e.g. a plane), HIP RT removes that entry and in scenes with objects with no blas,
110 * the instance id that hiprt returns for a hit point will not necessarily match the instance id
111 * of the application. user_instance_id provides a map for retrieving original instance id from
112 * what HIP RT returns as instance id. hiprt_blas_ptr is the list of all the valid blas pointers.
113 * blas_ptr has all the valid pointers and null pointers and blas for any geometry can be
114 * directly retrieved from this array (used in subsurface scattering). */
115 device_vector<int> user_instance_id;
116 device_vector<hiprtInstance> hiprt_blas_ptr;
117 device_vector<uint64_t> blas_ptr;
118
119 /* custom_prim_info stores custom information for custom primitives for all the primitives in a
120 * scene. Primitive id that HIP RT returns is local to the geometry that was hit.
121 * custom_prim_info_offset returns the offset required to add to the primitive id to retrieve
122 * primitive info from custom_prim_info. */
123 device_vector<int2> custom_prim_info;
124 device_vector<int2> custom_prim_info_offset;
125
126 /* prims_time stores primitive time for geometries with motion blur.
127 * prim_time_offset returns the offset to add to primitive id to retrieve primitive time. */
128 device_vector<float2> prims_time;
129 device_vector<int> prim_time_offset;
130};
132
133#endif
unsigned int uint
struct Curve Curve
struct Mesh Mesh
struct PointCloud PointCloud
struct Volume Volume
float progress
Definition WM_types.hh:1019
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void refit(btStridingMeshInterface *triangles, const btVector3 &aabbMin, const btVector3 &aabbMax)
Definition hair.h:13
CCL_NAMESPACE_BEGIN struct Options options
#define CCL_NAMESPACE_END
ccl_device bool BVH_FUNCTION_FULL_NAME BVH(KernelGlobals kg, const ccl_private Ray *ray, ccl_private LocalIntersection *local_isect, const int local_object, ccl_private uint *lcg_state, const int max_hits)
Definition local.h:28
int BVHLayoutMask
Definition params.h:50
std::mutex thread_mutex
Definition thread.h:27