Blender V4.3
device/cpu/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/tables.h"
10#include "kernel/types.h"
12
13#include "util/guiding.h"
14
16
17/* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
18 * the kernel, to access constant data. These are all stored as flat arrays.
19 * these are really just standard arrays. We can't use actually globals because
20 * multiple renders may be running inside the same process. */
21
22#ifdef __OSL__
23struct OSLGlobals;
24struct OSLThreadData;
25struct OSLShadingSystem;
26#endif
27
28/* Array for kernel data, with size to be able to assert on invalid data access. */
29template<typename T> struct kernel_array {
30 ccl_always_inline const T &fetch(int index) const
31 {
32 kernel_assert(index >= 0 && index < width);
33 return data[index];
34 }
35
36 T *data;
37 int width;
38};
39
40typedef struct KernelGlobalsCPU {
41#define KERNEL_DATA_ARRAY(type, name) kernel_array<type> name;
42#include "kernel/data_arrays.h"
43
45
46#ifdef __OSL__
47 /* On the CPU, we also have the OSL globals here. Most data structures are shared
48 * with SVM, the difference is in the shaders and object/mesh attributes. */
49 OSLGlobals *osl = nullptr;
50 OSLShadingSystem *osl_ss = nullptr;
51 OSLThreadData *osl_tdata = nullptr;
52 int osl_thread_index = 0;
53#endif
54
55#ifdef __PATH_GUIDING__
56 /* Pointers to global data structures. */
57 openpgl::cpp::SampleStorage *opgl_sample_data_storage = nullptr;
58 openpgl::cpp::Field *opgl_guiding_field = nullptr;
59
60 /* Local data structures owned by the thread. */
61 openpgl::cpp::PathSegmentStorage *opgl_path_segment_storage = nullptr;
62 openpgl::cpp::SurfaceSamplingDistribution *opgl_surface_sampling_distribution = nullptr;
63 openpgl::cpp::VolumeSamplingDistribution *opgl_volume_sampling_distribution = nullptr;
64#endif
65
66 /* **** Run-time data **** */
67
70
72
73/* Abstraction macros */
74#define kernel_data_fetch(name, index) (kg->name.fetch(index))
75#define kernel_data_array(name) (kg->name.data)
76#define kernel_data (kg->data)
77
#define kernel_assert(cond)
struct KernelGlobalsCPU KernelGlobalsCPU
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_restrict
#define CCL_NAMESPACE_END
#define ccl_always_inline
KernelData
ProfilingState profiler
ccl_always_inline const T & fetch(int index) const