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