Blender V5.0
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/types.h"
12#ifdef __OSL__
14#endif
16#include "util/guiding.h" // IWYU pragma: keep
17#include "util/texture.h" // IWYU pragma: keep
22struct OSLGlobals;
24/* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
25 * the kernel, to access constant data. These are all stored as flat arrays.
26 * these are really just standard arrays. We can't use actually globals because
27 * multiple renders may be running inside the same process. */
29/* Array for kernel data, with size to be able to assert on invalid data access. */
30template<typename T> struct kernel_array {
31 const ccl_always_inline T &fetch(const int index) const
32 {
33 kernel_assert(index >= 0 && index < width);
34 return data[index];
35 }
37 T *data = nullptr;
38 int width = 0;
39};
41/* Constant globals shared between all threads. */
43#define KERNEL_DATA_ARRAY(type, name) kernel_array<type> name;
46 KernelData data = {};
51/* Per-thread global state.
52 *
53 * To avoid pointer indirection, the constant globals are copied to each thread.
54 *
55 * This may not be ideal for cache pressure. Alternative would be to pass an
56 * additional thread index to every function, and potentially to make the shared
57 * part an actual global variable. That would match the GPU more closely, but
58 * also require mutex locks for multiple Cycles instances. */
61 OSLGlobals *osl_globals_memory,
62 Profiler &cpu_profiler,
63 const int thread_index);
73#ifdef __OSL__
74 OSLThreadData osl;
75#endif
77#if defined(__PATH_GUIDING__)
78 /* Pointers to shared global data structures. */
79 openpgl::cpp::SampleStorage *opgl_sample_data_storage = nullptr;
80 openpgl::cpp::Field *opgl_guiding_field = nullptr;
82 /* Local data structures owned by the thread. */
86#endif
87
88 protected:
90};
94/* Abstraction macros */
95#define kernel_data_fetch(name, index) (kg->name.fetch(index))
96#define kernel_data_array(name) (kg->name.data)
97#define kernel_data (kg->data)
98#if defined(WITH_PATH_GUIDING)
99# define guiding_guiding_field kg->opgl_guiding_field
100# define guiding_ssd kg->opgl_surface_sampling_distribution
101# define guiding_vsd kg->opgl_volume_sampling_distribution
102#endif
#define ccl_always_inline
const ThreadKernelGlobalsCPU * KernelGlobals
#define kernel_assert(cond)
#define CCL_NAMESPACE_END
#define T
CCL_NAMESPACE_END KernelData data
ProfilingState profiler
ThreadKernelGlobalsCPU(const KernelGlobalsCPU &kernel_globals, OSLGlobals *osl_globals_memory, Profiler &cpu_profiler, const int thread_index)
ThreadKernelGlobalsCPU & operator=(const ThreadKernelGlobalsCPU &other)=delete
const ccl_always_inline T & fetch(const int index) const