Blender V4.5
kernel/osl/types.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#pragma once
6
7#if !defined(__KERNEL_GPU__)
8# include <OSL/oslversion.h>
9#endif
10
11#include "util/defines.h"
12#include "util/types_float3.h"
13
15
16#if defined(__KERNEL_GPU__)
17/* Strings are represented by their hashes on the GPU. */
18using DeviceString = size_t;
19#elif defined(OPENIMAGEIO_USTRING_H)
20# if OSL_LIBRARY_VERSION_CODE >= 11400
21using DeviceString = ustringhash;
22# else
23using DeviceString = ustring;
24# endif
25#else
26using DeviceString = const char *;
27#endif
28
32struct OSLTraceData;
33
35{
36#if defined(__KERNEL_GPU__)
37 (void)str;
38 return hash;
39#elif defined(OPENIMAGEIO_USTRING_H)
40 (void)hash; /* Ignored in release builds. */
41 const DeviceString result = ustring(str);
42 kernel_assert(result.hash() == hash);
43 return result;
44#else
45 (void)hash;
46 return str;
47#endif
48}
49
50/* Closure */
51
55
57
58#define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower) OSL_CLOSURE_##Upper##_ID,
59#include "closures_template.h"
60 OSL_CLOSURE_LAYER_ID,
61};
62
66
67struct ccl_align(8) OSLClosureMul : public OSLClosure
69 packed_float3 weight;
70 const ccl_private OSLClosure *closure;
71};
72
73struct ccl_align(8) OSLClosureAdd : public OSLClosure
75 const ccl_private OSLClosure *closureA;
76 const ccl_private OSLClosure *closureB;
77};
78
79struct ccl_align(8) OSLClosureComponent : public OSLClosure
80{
81 packed_float3 weight;
82};
83
84/* Globals */
85
86/* This structure is essentially a copy of OSL::ShaderGlobals, but with some of the
87 * opaque pointers replaced with the types that we use for them and additional members
88 * at the end.
89 * As long as the layout matches (which is must in any case, in order for the OptiX OSL
90 * code to work), this works fine since OSL doesn't do pointer arithmetic etc. on the
91 * ShaderGlobals pointer that we give it. */
93 /* This part of ShaderGlobals is shared with OSL's own struct, so the layout must match! */
99 float u, dudx, dudy;
100 float v, dvdx, dvdy;
102 float time;
103 float dtime;
106
107 /* In OSL this is an opaque pointer named render-state. */
108 ccl_private ShaderData *sd;
109
110 /* In OSL this is an opaque pointer */
111 ccl_private OSLTraceData *tracedata;
112
113 /* In OSL this is an opaque pointer named `objdata`. */
114#ifdef __KERNEL_GPU__
115 ccl_private uint8_t *closure_pool;
116#else
118#endif
119
120 void *context;
123
124 /* We use this to encode the path state on GPUs.
125 * Zero means no state, positive means path_state, negative means shadow_path_state.
126 * On CPU, we use pointers in the Cycles-specific section below. */
128
129 void *renderer;
137
138 /* This part is Cycles-specific and ignored by OSL itself. */
139#ifndef __KERNEL_GPU__
142#endif
143};
144
148
149#define OSL_TEXTURE_HANDLE_TYPE_IES ((uintptr_t)0x2 << 30)
150#define OSL_TEXTURE_HANDLE_TYPE_SVM ((uintptr_t)0x1 << 30)
151#define OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL ((uintptr_t)0x3 << 30)
152
153#define OSL_TEXTURE_HANDLE_TYPE(handle) \
154 ((unsigned int)((uintptr_t)(handle) & ((uintptr_t)0x3 << 30)))
155#define OSL_TEXTURE_HANDLE_SLOT(handle) \
156 ((unsigned int)((uintptr_t)(handle) & ((uintptr_t)0x3FFFFFFF)))
157
blender::float3 packed_float3
#define kernel_assert(cond)
#define ccl_private
#define ccl_device_inline
#define ccl_align(...)
#define CCL_NAMESPACE_END
#define str(s)
ccl_device_inline DeviceString make_string(const char *str, const size_t hash)
OSLClosureType
@ OSL_CLOSURE_NONE_ID
@ OSL_CLOSURE_MUL_ID
@ OSL_CLOSURE_ADD_ID
const char * DeviceString
#define hash
Definition noise_c.cc:154
OSLClosureType id
packed_float3 dIdx
packed_float3 dPdu
packed_float3 dIdy
packed_float3 Ng
ccl_private void * object2common
packed_float3 dPsdx
packed_float3 dPdv
ccl_private ShaderData * sd
const ThreadKernelGlobalsCPU * kg
packed_float3 dPdz
ccl_private OSLClosure * Ci
ccl_private void * shader2common
packed_float3 dPdtime
packed_float3 dPsdy
ccl_private OSLTraceData * tracedata
const struct IntegratorStateCPU * path_state
packed_float3 dPdx
packed_float3 I
packed_float3 Ps
const struct IntegratorShadowStateCPU * shadow_path_state
packed_float3 N
packed_float3 dPdy
packed_float3 P