Blender V4.3
osl/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#ifndef __OSL_GLOBALS_H__
6#define __OSL_GLOBALS_H__
7
8#ifdef WITH_OSL
9
10# include <OSL/oslexec.h>
11
12# include <OpenImageIO/refcnt.h>
13# include <OpenImageIO/unordered_map_concurrent.h>
14
15# include "kernel/osl/compat.h"
16
17# include "util/map.h"
18# include "util/param.h"
19# include "util/thread.h"
20# include "util/unique_ptr.h"
21# include "util/vector.h"
22
23# ifndef WIN32
24using std::isfinite;
25# endif
26
28
30class ColorSpaceProcessor;
31
32/* OSL Globals
33 *
34 * Data needed by OSL render services, that is global to a rendering session.
35 * This includes all OSL shaders, name to attribute mapping and texture handles.
36 */
37
38struct OSLGlobals {
39 OSLGlobals()
40 {
41 ss = NULL;
42 ts = NULL;
43 services = NULL;
44 use = false;
45 }
46
47 /* per thread data */
48 static void thread_init(struct KernelGlobalsCPU *kg,
49 OSLGlobals *osl_globals,
50 const int thread_init);
51 static void thread_free(struct KernelGlobalsCPU *kg);
52
53 bool use;
54
55 /* shading system */
56 OSL::ShadingSystem *ss;
57 OSL::TextureSystem *ts;
58 OSLRenderServices *services;
59
60 /* shader states */
61 vector<OSL::ShaderGroupRef> surface_state;
62 vector<OSL::ShaderGroupRef> volume_state;
63 vector<OSL::ShaderGroupRef> displacement_state;
65 OSL::ShaderGroupRef background_state;
66
67 /* attributes */
68 typedef unordered_map<OSLUStringHash, int> ObjectNameMap;
69
70 ObjectNameMap object_name_map;
71 vector<ustring> object_names;
72};
73
74/* trace() call result */
75struct OSLTraceData {
76 Ray ray;
77 Intersection isect;
78 ShaderData sd;
79 bool setup;
80 bool init;
81 bool hit;
82};
83
84/* thread key for thread specific data lookup */
85struct OSLThreadData {
86 OSL::ShaderGlobals globals;
87 OSL::PerThreadInfo *osl_thread_info;
88 OSLTraceData tracedata;
89 OSL::ShadingContext *context;
90 OIIO::TextureSystem::Perthread *oiio_thread_info;
91};
92
94
95#endif
96
97#endif /* __OSL_GLOBALS_H__ */
void init()
#define CCL_NAMESPACE_END
#define NULL
ShaderData