Blender V5.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/types.h"
12#ifdef __OSL__
14#endif
16#include "util/guiding.h" // IWYU pragma: keep
17#include "util/types_image.h" // IWYU pragma: keep
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 {
34 return data[index];
35 }
37 ccl_always_inline void write(const int index, const T &value) const
38 {
39 data[index] = value;
40 }
42 T *data = nullptr;
43 int width = 0;
44};
46/* Constant globals shared between all threads. */
48#define KERNEL_DATA_ARRAY(type, name) kernel_array<const type> name;
49#define KERNEL_DATA_ARRAY_WRITABLE(type, name) kernel_array<type> name;
52 KernelData data = {};
59/* Per-thread global state.
60 *
61 * To avoid pointer indirection, the constant globals are copied to each thread.
62 *
63 * This may not be ideal for cache pressure. Alternative would be to pass an
64 * additional thread index to every function, and potentially to make the shared
65 * part an actual global variable. That would match the GPU more closely, but
66 * also require mutex locks for multiple Cycles instances. */
69 OSLGlobals *osl_globals_memory,
70 Profiler &cpu_profiler,
71 const int thread_index);
81#ifdef __OSL__
82 OSLThreadData osl;
83#endif
85#if defined(__PATH_GUIDING__)
86 /* Pointers to shared global data structures. */
87 openpgl::cpp::SampleStorage *opgl_sample_data_storage = nullptr;
88 openpgl::cpp::Field *opgl_guiding_field = nullptr;
90 /* Local data structures owned by the thread. */
92 int opgl_path_segment_storage_size = 0;
95#endif
97 protected:
99};
103/* Abstraction macros */
104#define kernel_data_fetch(name, index) (kg->name.fetch(index))
105#define kernel_data_write(name, index, value) (kg->name.write(index, value))
106#define kernel_data_array(name) (kg->name.data)
107#define kernel_data (kg->data)
108#if defined(WITH_PATH_GUIDING)
109# define guiding_guiding_field kg->opgl_guiding_field
110# define guiding_ssd kg->opgl_surface_sampling_distribution
111# define guiding_vsd kg->opgl_volume_sampling_distribution
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
#define ccl_always_inline
const ThreadKernelGlobalsCPU * KernelGlobals
#define kernel_assert(cond)
#define CCL_NAMESPACE_END
#define index(i)
#define T
KernelImageLoadRequestedCPU image_load_requested_cpu
CCL_NAMESPACE_END KernelData data
ProfilingState profiler
ThreadKernelGlobalsCPU(const KernelGlobalsCPU &kernel_globals, OSLGlobals *osl_globals_memory, Profiler &cpu_profiler, const int thread_index)
const ccl_always_inline T & fetch(const int index) const
ccl_always_inline void write(const int index, const T &value) const
std::function< void(size_t, int, int, int, KernelTileDescriptor &tile_descriptor)> KernelImageLoadRequestedCPU