Blender V4.3
scene/svm.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 __SVM_H__
6#define __SVM_H__
7
8#include "scene/attribute.h"
9#include "scene/shader.h"
10#include "scene/shader_graph.h"
11
12#include "util/array.h"
13#include "util/set.h"
14#include "util/string.h"
15#include "util/thread.h"
16
18
19class Device;
20class DeviceScene;
21class ImageManager;
22class Scene;
23class ShaderGraph;
24class ShaderInput;
25class ShaderNode;
26class ShaderOutput;
27
28/* Shader Manager */
29
31 public:
34
35 void reset(Scene *scene) override;
36
37 void device_update_specific(Device *device,
38 DeviceScene *dscene,
39 Scene *scene,
40 Progress &progress) override;
41 void device_free(Device *device, DeviceScene *dscene, Scene *scene) override;
42
43 protected:
44 void device_update_shader(Scene *scene,
45 Shader *shader,
46 Progress *progress,
47 array<int4> *svm_nodes);
48};
49
50/* Graph Compiler */
51
53 public:
54 struct Summary {
55 Summary();
56
57 /* Number of SVM nodes shader was compiled into. */
59
60 /* Peak stack usage during shader evaluation. */
62
63 /* Time spent on surface graph finalization. */
65
66 /* Time spent on generating SVM nodes for surface shader. */
68
69 /* Time spent on generating SVM nodes for bump shader. */
71
72 /* Time spent on generating SVM nodes for volume shader. */
74
75 /* Time spent on generating SVM nodes for displacement shader. */
77
78 /* Total time spent on all routines. */
79 double time_total;
80
81 /* A full multi-line description of the state of the compiler after compilation. */
82 string full_report() const;
83 };
84
85 SVMCompiler(Scene *scene);
86 void compile(Shader *shader, array<int4> &svm_nodes, int index, Summary *summary = NULL);
87
88 int stack_assign(ShaderOutput *output);
89 int stack_assign(ShaderInput *input);
90 bool is_linked(ShaderInput *input);
93 int stack_find_offset(int size);
95 void stack_clear_offset(SocketType::Type type, int offset);
96 void stack_link(ShaderInput *input, ShaderOutput *output);
97
98 void add_node(ShaderNodeType type, int a = 0, int b = 0, int c = 0);
99 void add_node(int a = 0, int b = 0, int c = 0, int d = 0);
100 void add_node(ShaderNodeType type, const float3 &f);
101 void add_node(const float4 &f);
102 uint attribute(ustring name);
104 uint attribute_standard(ustring name);
105 uint encode_uchar4(uint x, uint y = 0, uint z = 0, uint w = 0);
114
116 {
117 return current_type;
118 }
119
123
124 protected:
125 /* stack */
126 struct Stack {
128 {
129 memset(users, 0, sizeof(users));
130 }
131 Stack(const Stack &other)
132 {
133 memcpy(users, other.users, sizeof(users));
134 }
135 Stack &operator=(const Stack &other)
136 {
137 memcpy(users, other.users, sizeof(users));
138 return *this;
139 }
140
141 bool empty()
142 {
143 for (int i = 0; i < SVM_STACK_SIZE; i++) {
144 if (users[i]) {
145 return false;
146 }
147 }
148
149 return true;
150 }
151
152 void print()
153 {
154 printf("stack <");
155
156 for (int i = 0; i < SVM_STACK_SIZE; i++) {
157 printf((users[i]) ? "*" : " ");
158 }
159
160 printf(">\n");
161 }
162
164 };
165
166 /* Global state of the compiler accessible from the compilation routines. */
168 explicit CompilerState(ShaderGraph *graph);
169
170 /* ** Global state, used by various compilation steps. ** */
171
172 /* Set of nodes which were already compiled. */
174
175 /* Set of closures which were already compiled. */
177
178 /* Set of nodes used for writing AOVs. */
180
181 /* ** SVM nodes generation state ** */
182
183 /* Flag whether the node with corresponding ID was already compiled or
184 * not. Array element with index i corresponds to a node with such if.
185 *
186 * TODO(sergey): This is actually a copy of nodes_done just in another
187 * notation. We can de-duplicate this storage actually after switching
188 * all areas to use this flags array.
189 */
191
192 /* Node features that can be compiled. */
194 };
195
198 void stack_clear_users(ShaderNode *node, ShaderNodeSet &done);
199
200 /* single closure */
201 void find_dependencies(ShaderNodeSet &dependencies,
202 const ShaderNodeSet &done,
203 ShaderInput *input,
204 ShaderNode *skip_node = NULL);
206 ShaderGraph *graph,
208 void generate_node(ShaderNode *node, ShaderNodeSet &done);
212 ShaderNode *node,
214 const ShaderNodeSet &shared);
216
217 /* multi closure */
219
220 /* compile */
221 void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type);
222
223 std::atomic_int *svm_node_types_used;
232};
233
235
236#endif /* __SVM_H__ */
unsigned int uint
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color attribute
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
void reset()
clear internal cached data and reset random seed
ShaderGraph * current_graph
Definition scene/svm.h:121
void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type)
Definition svm.cpp:738
int max_stack_use
Definition scene/svm.h:228
void find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes, ShaderGraph *graph, CompilerState *state)
Definition svm.cpp:567
void add_node(ShaderNodeType type, int a=0, int b=0, int c=0)
Definition svm.cpp:393
bool background
Definition scene/svm.h:122
SVMCompiler(Scene *scene)
Definition svm.cpp:158
array< int4 > current_svm_nodes
Definition scene/svm.h:224
void generate_closure_node(ShaderNode *node, CompilerState *state)
Definition svm.cpp:499
void stack_clear_offset(SocketType::Type type, int offset)
Definition svm.cpp:239
ShaderType current_type
Definition scene/svm.h:225
uint bump_state_offset
Definition scene/svm.h:230
void generate_node(ShaderNode *node, ShaderNodeSet &done)
Definition svm.cpp:444
int stack_assign_if_linked(ShaderInput *input)
Definition svm.cpp:302
Shader * current_shader
Definition scene/svm.h:226
void stack_clear_users(ShaderNode *node, ShaderNodeSet &done)
Definition svm.cpp:336
int stack_size(SocketType::Type type)
Definition svm.cpp:173
void stack_clear_temporary(ShaderNode *node)
Definition svm.cpp:368
uint encode_uchar4(uint x, uint y=0, uint z=0, uint w=0)
Definition svm.cpp:378
uint attribute_standard(ustring name)
Definition svm.cpp:422
Stack active_stack
Definition scene/svm.h:227
void stack_link(ShaderInput *input, ShaderOutput *output)
Definition svm.cpp:320
void find_dependencies(ShaderNodeSet &dependencies, const ShaderNodeSet &done, ShaderInput *input, ShaderNode *skip_node=NULL)
Definition svm.cpp:428
void generate_aov_node(ShaderNode *node, CompilerState *state)
ShaderType output_type()
Definition scene/svm.h:115
void generate_svm_nodes(const ShaderNodeSet &nodes, CompilerState *state)
Definition svm.cpp:468
uint closure_mix_weight_offset()
Definition scene/svm.h:106
bool is_linked(ShaderInput *input)
Definition svm.cpp:297
void generate_multi_closure(ShaderNode *root_node, ShaderNode *node, CompilerState *state)
Definition svm.cpp:586
uint get_bump_state_offset()
Definition scene/svm.h:110
std::atomic_int * svm_node_types_used
Definition scene/svm.h:223
Scene * scene
Definition scene/svm.h:120
uint mix_weight_offset
Definition scene/svm.h:229
bool compile_failed
Definition scene/svm.h:231
int stack_find_offset(int size)
Definition svm.cpp:199
void compile(Shader *shader, array< int4 > &svm_nodes, int index, Summary *summary=NULL)
Definition svm.cpp:870
void generated_shared_closure_nodes(ShaderNode *root_node, ShaderNode *node, CompilerState *state, const ShaderNodeSet &shared)
Definition svm.cpp:550
int stack_assign(ShaderOutput *output)
Definition svm.cpp:287
void device_free(Device *device, DeviceScene *dscene, Scene *scene) override
Definition svm.cpp:149
~SVMShaderManager()
Definition svm.cpp:28
void device_update_specific(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress) override
Definition svm.cpp:52
void device_update_shader(Scene *scene, Shader *shader, Progress *progress, array< int4 > *svm_nodes)
Definition svm.cpp:32
local_group_size(16, 16) .push_constant(Type b
#define printf
#define CCL_NAMESPACE_END
#define NULL
#define SVM_STACK_SIZE
ShaderNodeType
AttributeStandard
static ulong state[N]
set< ShaderNode *, ShaderNodeIDComparator > ShaderNodeSet
ShaderNodeSet closure_done
Definition scene/svm.h:176
vector< bool > nodes_done_flag
Definition scene/svm.h:190
CompilerState(ShaderGraph *graph)
Definition svm.cpp:987
Stack & operator=(const Stack &other)
Definition scene/svm.h:135
int users[SVM_STACK_SIZE]
Definition scene/svm.h:163
Stack(const Stack &other)
Definition scene/svm.h:131
double time_generate_volume
Definition scene/svm.h:73
double time_generate_surface
Definition scene/svm.h:67
double time_generate_bump
Definition scene/svm.h:70
string full_report() const
Definition svm.cpp:965
double time_generate_displacement
Definition scene/svm.h:76