Blender V5.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/* Constant Globals */
6
7#pragma once
8
9#include "kernel/types.h"
12#include "kernel/util/profiler.h" // IWYU pragma: export
14#include "util/color.h" // IWYU pragma: export
15#include "util/types_image.h" // IWYU pragma: export
17/* The size of global stack available to each thread (memory reserved for each thread in
18 * global_stack_buffer). */
19#define HIPRT_THREAD_STACK_SIZE 64
21/* LDS (Local Data Storage) allocation for each thread, the number is obtained empirically. */
22#define HIPRT_SHARED_STACK_SIZE 24
24/* HIPRT_THREAD_GROUP_SIZE is the number of threads per work group for intersection kernels
25 * The default number of threads per work-group is 1024, however, since HIP RT intersection kernels
26 * use local memory, and the local memory size in those kernels scales up with the number of
27 * threads, the number of threads to is scaled down to 256 to avoid going over maximum local memory
28 * and to strike a balance between memory access and the number of waves.
29 *
30 * Total local stack size would be number of threads * HIPRT_SHARED_STACK_SIZE. */
31#define HIPRT_THREAD_GROUP_SIZE 256
36 hiprtGlobalStackBuffer global_stack_buffer;
37 hiprtSharedStackBuffer shared_stack;
38};
42/* This macro allocates shared memory and to pass the shared memory down to intersection functions
43 * KernelGlobals is used. */
44#define HIPRT_INIT_KERNEL_GLOBAL() \
45 ccl_gpu_shared int shared_stack[HIPRT_SHARED_STACK_SIZE * HIPRT_THREAD_GROUP_SIZE]; \
46 ccl_global KernelGlobalsGPU kg_gpu; \
47 KernelGlobals kg = &kg_gpu; \
48 kg->shared_stack.stackData = &shared_stack[0]; \
49 kg->shared_stack.stackSize = HIPRT_SHARED_STACK_SIZE; \
50 kg->global_stack_buffer = stack_buffer;
53 KernelData data;
54#define KERNEL_DATA_ARRAY(type, name) const type *name;
55#define KERNEL_DATA_ARRAY_WRITABLE(type, name) type *name;
56 KERNEL_DATA_ARRAY(int, user_instance_id)
58#include "kernel/data_arrays.h"
60 /* Integrator state */
64 hiprtFuncTable table_shadow_intersect;
65 hiprtFuncTable table_local_intersect;
66 hiprtFuncTable table_volume_intersect;
67};
69/* Intersection_Function_Table_Index defines index values to retrieve custom intersection
70 * functions from function table. */
73 // Triangles use the intersection function provided by HIP RT and don't need custom intersection
74 // functions
75 // Custom intersection functions for closest intersect.
76 Curve_Intersect_Function = 1, // Custom intersection for curves
77 Motion_Triangle_Intersect_Function, // Custom intersection for triangles with vertex motion blur
78 // attributes.
79 Point_Intersect_Function, // Custom intersection for point cloud.
80 // Custom intersection functions for shadow rendering are the same as the function for closest
81 // intersect.
82 // However, the table indices are different
87 // Custom intersection functions for subsurface scattering.
88 // Only motion triangles have valid custom intersection function
93 // Custom intersection functions for volume rendering.
94 // Only motion triangles have valid custom intersection function
99};
101// Filter functions, filter hits, i.e. test whether a hit should be accepted or not, and whether
102// traversal should stop or continue.
104 Triangle_Filter_Closest = 0, // Filter function for triangles for closest intersect, no custom
105 // intersection function is needed.
106 Curve_Filter_Opaque_None, // No filter function is needed and everything is handled in the
107 // intersection function.
108 Motion_Triangle_Filter_Opaque_None, // No filter function is needed and everything is handled in
109 // intersection function.
110 Point_Filter_Opaque_Non, // No filter function is needed.
111 // Filter function for all primitives for shadow intersection.
112 // All primitives use the same function but each has a different index in the table.
117 // Filter functions for subsurface scattering. Triangles and motion triangles need function
118 // assignment. They indices for triangles and motion triangles point to the same function. Points
119 // and curves dont need any function since subsurface scattering is not applied on either.
120 Triangle_Filter_Local, // Filter functions for triangles
121 Curve_Filter_Local_None, // Subsurface scattering is not applied on curves, no filter function
122 // is
123 // needed.
126 // Filter functions for volume rendering.
127 // Volume rendering only applies to triangles and motion triangles.
128 // Triangles and motion triangles use the same filter functions for volume rendering
135#ifdef __KERNEL_GPU__
136__constant__ KernelParamsHIPRT kernel_params;
138typedef hiprtGlobalStack Stack;
139typedef hiprtEmptyInstanceStack Instance_Stack;
140#endif
142/* Abstraction macros */
143#define kernel_data kernel_params.data
144#define kernel_data_fetch(name, index) kernel_params.name[(index)]
145#define kernel_data_write(name, index, value) kernel_params.name[(index)] = (value)
146#define kernel_data_array(name) (kernel_params.name)
147#define kernel_integrator_state kernel_params.integrator_state
unsigned long long int uint64_t
#define CCL_NAMESPACE_END
#define ccl_restrict
#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
ccl_global KernelGlobalsGPU *ccl_restrict KernelGlobals
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
#define ccl_global
hiprtSharedStackBuffer shared_stack
hiprtGlobalStackBuffer global_stack_buffer
hiprtFuncTable table_closest_intersect
hiprtFuncTable table_volume_intersect
hiprtFuncTable table_local_intersect
CCL_NAMESPACE_END IntegratorStateGPU integrator_state
hiprtFuncTable table_shadow_intersect