Blender  V3.3
device/cpu/globals.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 /* Constant Globals */
5 
6 #pragma once
7 
8 #include "kernel/tables.h"
9 #include "kernel/types.h"
10 #include "kernel/util/profiling.h"
11 
13 
14 /* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
15  * the kernel, to access constant data. These are all stored as flat arrays.
16  * these are really just standard arrays. We can't use actually globals because
17  * multiple renders may be running inside the same process. */
18 
19 #ifdef __OSL__
20 struct OSLGlobals;
21 struct OSLThreadData;
22 struct OSLShadingSystem;
23 #endif
24 
25 /* Array for kernel data, with size to be able to assert on invalid data access. */
26 template<typename T> struct kernel_array {
27  ccl_always_inline const T &fetch(int index) const
28  {
29  kernel_assert(index >= 0 && index < width);
30  return data[index];
31  }
32 
33  T *data;
34  int width;
35 };
36 
37 typedef struct KernelGlobalsCPU {
38 #define KERNEL_DATA_ARRAY(type, name) kernel_array<type> name;
39 #include "kernel/data_arrays.h"
40 
42 
43 #ifdef __OSL__
44  /* On the CPU, we also have the OSL globals here. Most data structures are shared
45  * with SVM, the difference is in the shaders and object/mesh attributes. */
46  OSLGlobals *osl;
47  OSLShadingSystem *osl_ss;
48  OSLThreadData *osl_tdata;
49 #endif
50 
51  /* **** Run-time data **** */
52 
55 
57 
58 /* Abstraction macros */
59 #define kernel_data_fetch(name, index) (kg->name.fetch(index))
60 #define kernel_data_array(name) (kg->name.data)
61 #define kernel_data (kg->data)
62 
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define ccl_restrict
Definition: cuda/compat.h:50
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
struct KernelGlobalsCPU KernelGlobalsCPU
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define T
#define ccl_always_inline
Definition: oneapi/compat.h:31
ProfilingState profiler
ccl_always_inline const T & fetch(int index) const