Blender V4.3
device/hiprt/globals.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "kernel/types.h"
8
10
12
13#define HIPRT_SHARED_STACK
14
15/* The size of global stack available to each thread (memory reserved for each thread in
16 * global_stack_buffer). */
17#define HIPRT_THREAD_STACK_SIZE 64
18
19/* LDS (Local Data Storage) allocation for each thread, the number is obtained empirically. */
20#define HIPRT_SHARED_STACK_SIZE 24
21
22/* HIPRT_THREAD_GROUP_SIZE is the number of threads per work group for intersection kernels
23 * The default number of threads per work-group is 1024, however, since HIP RT intersection kernels
24 * use local memory, and the local memory size in those kernels scales up with the number of
25 * threads, the number of threads to is scaled down to 256 to avoid going over maximum local memory
26 * and to strike a balance between memory access and the number of waves.
27 *
28 * Total local stack size would be number of threads * HIPRT_SHARED_STACK_SIZE. */
29#define HIPRT_THREAD_GROUP_SIZE 256
30
32
33struct KernelGlobalsGPU {
34 hiprtGlobalStackBuffer global_stack_buffer;
35#ifdef HIPRT_SHARED_STACK
36 hiprtSharedStackBuffer shared_stack;
37#endif
38};
39
41
42#if defined(HIPRT_SHARED_STACK)
43
44/* This macro allocates shared memory and to pass the shared memory down to intersection functions
45 * KernelGlobals is used. */
46# define HIPRT_INIT_KERNEL_GLOBAL() \
47 ccl_gpu_shared int shared_stack[HIPRT_SHARED_STACK_SIZE * HIPRT_THREAD_GROUP_SIZE]; \
48 ccl_global KernelGlobalsGPU kg_gpu; \
49 KernelGlobals kg = &kg_gpu; \
50 kg->shared_stack.stackData = &shared_stack[0]; \
51 kg->shared_stack.stackSize = HIPRT_SHARED_STACK_SIZE; \
52 kg->global_stack_buffer = stack_buffer;
53#else
54# define HIPRT_INIT_KERNEL_GLOBAL() \
55 KernelGlobals kg = NULL; \
56 kg->global_stack_buffer = stack_buffer;
57#endif
58
61#define KERNEL_DATA_ARRAY(type, name) const type *name;
62 KERNEL_DATA_ARRAY(int, user_instance_id)
64 KERNEL_DATA_ARRAY(int2, custom_prim_info)
65 KERNEL_DATA_ARRAY(int2, custom_prim_info_offset)
66 KERNEL_DATA_ARRAY(float2, prims_time)
67 KERNEL_DATA_ARRAY(int, prim_time_offset)
68#include "kernel/data_arrays.h"
69
70 /* Integrator state */
72
74 hiprtFuncTable table_shadow_intersect;
75 hiprtFuncTable table_local_intersect;
76 hiprtFuncTable table_volume_intersect;
77};
78
79/* Intersection_Function_Table_Index defines index values to retrieve custom intersection
80 * functions from function table. */
81
83 // Triangles use the intersection function provided by HIP RT and don't need custom intersection
84 // functions
85 // Custom intersection functions for closest intersect.
86 Curve_Intersect_Function = 1, // Custom intersection for curves
87 Motion_Triangle_Intersect_Function, // Custom intersection for triangles with vertex motion blur
88 // attributes.
89 Point_Intersect_Function, // Custom intersection for point cloud.
90 // Custom intersection functions for shadow rendering are the same as the function for closest
91 // intersect.
92 // However, the table indices are different
97 // Custom intersection functions for subsurface scattering.
98 // Only motion triangles have valid custom intersection function
103 // Custom intersection functions for volume rendering.
104 // Only motion triangles have valid custom intersection function
109};
110
111// Filter functions, filter hits, i.e. test whether a hit should be accepted or not, and whether
112// traversal should stop or continue.
114 Triangle_Filter_Closest = 0, // Filter function for triangles for closest intersect, no custom
115 // intersection function is needed.
116 Curve_Filter_Opaque_None, // No filter function is needed and everything is handled in the
117 // intersection function.
118 Motion_Triangle_Filter_Opaque_None, // No filter function is needed and everything is handled in
119 // intersection function.
120 Point_Filter_Opaque_Non, // No filter function is needed.
121 // Filter function for all primitives for shadow intersection.
122 // All primitives use the same function but each has a different index in the table.
127 // Filter functions for subsurface scattering. Triangles and motion triangles need function
128 // assignment. They indices for triangles and motion triangles point to the same function. Points
129 // and curves dont need any function since subsurface scattering is not applied on either.
130 Triangle_Filter_Local, // Filter functions for triangles
131 Curve_Filter_Local_None, // Subsurface scattering is not applied on curves, no filter function
132 // is
133 // needed.
136 // Filter functions for volume rendering.
137 // Volume rendering only applies to triangles and motion triangles.
138 // Triangles and motion triangles use the same filter functions for volume rendering
143};
144
145#ifdef __KERNEL_GPU__
146__constant__ KernelParamsHIPRT kernel_params;
147
148# ifdef HIPRT_SHARED_STACK
149typedef hiprtGlobalStack Stack;
150typedef hiprtEmptyInstanceStack Instance_Stack;
151# endif
152
153#endif
154
155/* Abstraction macros */
156#define kernel_data kernel_params.data
157#define kernel_data_fetch(name, index) kernel_params.name[(index)]
158#define kernel_data_array(name) (kernel_params.name)
159#define kernel_integrator_state kernel_params.integrator_state
160
#define ccl_restrict
#define ccl_global
#define CCL_NAMESPACE_END
ccl_global KernelGlobalsGPU *ccl_restrict KernelGlobals
#define KERNEL_DATA_ARRAY(type, name)
Filter_Function_Table_Index
@ Curve_Filter_Local_None
@ Point_Filter_Opaque_Non
@ Motion_Triangle_Filter_Volume
@ Motion_Triangle_Filter_Local
@ Point_Filter_Local_None
@ Triangle_Filter_Closest
@ Curve_Filter_Volume_None
@ Curve_Filter_Shadow
@ Motion_Triangle_Filter_Opaque_None
@ Point_Filter_Volume_None
@ Motion_Triangle_Filter_Shadow
@ Curve_Filter_Opaque_None
@ Point_Filter_Shadow
@ Triangle_Filter_Local
@ Triangle_Filter_Volume
@ Triangle_Filter_Shadow
Intersection_Function_Table_Index
@ Motion_Triangle_Intersect_Shadow
@ Curve_Intersect_Local_None
@ Curve_Intersect_Function
@ Triangle_Intersect_Local_None
@ Point_Intersect_Volume_None
@ Motion_Triangle_Intersect_Function
@ Point_Intersect_Shadow
@ Curve_Intersect_Shadow
@ Triangle_Intersect_Volume_None
@ Point_Intersect_Function
@ Curve_Intersect_Volume_None
@ Motion_Triangle_Intersect_Volume
@ Motion_Triangle_Intersect_Local
@ Triangle_Intersect_Shadow_None
@ Point_Intersect_Local_None
KernelData
unsigned __int64 uint64_t
Definition stdint.h:90
hiprtSharedStackBuffer shared_stack
hiprtGlobalStackBuffer global_stack_buffer
hiprtFuncTable table_closest_intersect
hiprtFuncTable table_volume_intersect
hiprtFuncTable table_local_intersect
IntegratorStateGPU integrator_state
hiprtFuncTable table_shadow_intersect