Blender V5.0
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 "kernel/types.h"
12
13#include "util/defines.h"
14#include "util/types_float3.h"
15
17
18#if defined(__KERNEL_GPU__)
19/* Strings are represented by their hashes on the GPU. */
20using DeviceString = size_t;
21#elif defined(OPENIMAGEIO_USTRING_H)
22# if OSL_LIBRARY_VERSION_CODE >= 11400
23using DeviceString = ustringhash;
24# else
25using DeviceString = ustring;
26# endif
27#else
28using DeviceString = const char *;
29#endif
30
34struct OSLTraceData;
35
37{
38#if defined(__KERNEL_GPU__)
39 (void)str;
40 return hash;
41#elif defined(OPENIMAGEIO_USTRING_H)
42 (void)hash; /* Ignored in release builds. */
43 const DeviceString result = ustring(str);
44 kernel_assert(result.hash() == hash);
45 return result;
46#else
47 (void)hash;
48 return str;
49#endif
50}
51
52/* Closure */
53
57
59
60#define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower) OSL_CLOSURE_##Upper##_ID,
61#include "closures_template.h"
62 OSL_CLOSURE_LAYER_ID,
63};
64
68
69struct ccl_align(8) OSLClosureMul : public OSLClosure {
71 const ccl_private OSLClosure *closure;
72};
74struct 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 packed_float3 weight;
81};
82
83/* Globals */
84
85/* This structure is essentially a copy of OSL::ShaderGlobals, but with some of the
86 * opaque pointers replaced with the types that we use for them and additional members
87 * at the end.
88 * As long as the layout matches (which is must in any case, in order for the OptiX OSL
89 * code to work), this works fine since OSL doesn't do pointer arithmetic etc. on the
90 * ShaderGlobals pointer that we give it. */
92 /* This part of ShaderGlobals is shared with OSL's own struct, so the layout must match! */
98 float u, dudx, dudy;
99 float v, dvdx, dvdy;
101 float time;
102 float dtime;
105
106 /* In OSL this is an opaque pointer named render-state. */
107 ccl_private ShaderData *sd;
108
109 /* In OSL this is an opaque pointer */
110 ccl_private OSLTraceData *tracedata;
111
112 /* In OSL this is an opaque pointer named `objdata`. */
113#ifdef __KERNEL_GPU__
114 ccl_private uint8_t *closure_pool;
115#else
117#endif
118
119 void *context;
122
123 /* We use this to encode the path state on GPUs.
124 * Zero means no state, positive means path_state, negative means shadow_path_state.
125 * On CPU, we use pointers in the Cycles-specific section below. */
127
128 void *renderer;
136
137 /* This part is Cycles-specific and ignored by OSL itself. */
138#ifndef __KERNEL_GPU__
141#endif
142};
143
145
147
148#define OSL_TEXTURE_HANDLE_TYPE_IES ((uintptr_t)0x2 << 30)
149#define OSL_TEXTURE_HANDLE_TYPE_SVM ((uintptr_t)0x1 << 30)
150#define OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL ((uintptr_t)0x3 << 30)
151
152#define OSL_TEXTURE_HANDLE_TYPE(handle) \
153 ((unsigned int)((uintptr_t)(handle) & ((uintptr_t)0x3 << 30)))
154#define OSL_TEXTURE_HANDLE_SLOT(handle) \
155 ((unsigned int)((uintptr_t)(handle) & ((uintptr_t)0x3FFFFFFF)))
156
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