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