Blender  V2.93
render/svm.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __SVM_H__
18 #define __SVM_H__
19 
20 #include "render/attribute.h"
21 #include "render/graph.h"
22 #include "render/shader.h"
23 
24 #include "util/util_array.h"
25 #include "util/util_set.h"
26 #include "util/util_string.h"
27 #include "util/util_thread.h"
28 
30 
31 class Device;
32 class DeviceScene;
33 class ImageManager;
34 class Scene;
35 class ShaderGraph;
36 class ShaderInput;
37 class ShaderNode;
38 class ShaderOutput;
39 
40 /* Shader Manager */
41 
43  public:
46 
47  void reset(Scene *scene);
48 
49  void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
50  void device_free(Device *device, DeviceScene *dscene, Scene *scene);
51 
52  protected:
54  Shader *shader,
55  Progress *progress,
56  array<int4> *svm_nodes);
57 };
58 
59 /* Graph Compiler */
60 
61 class SVMCompiler {
62  public:
63  struct Summary {
64  Summary();
65 
66  /* Number of SVM nodes shader was compiled into. */
68 
69  /* Peak stack usage during shader evaluation. */
71 
72  /* Time spent on surface graph finalization. */
73  double time_finalize;
74 
75  /* Time spent on generating SVM nodes for surface shader. */
77 
78  /* Time spent on generating SVM nodes for bump shader. */
80 
81  /* Time spent on generating SVM nodes for volume shader. */
83 
84  /* Time spent on generating SVM nodes for displacement shader. */
86 
87  /* Total time spent on all routines. */
88  double time_total;
89 
90  /* A full multi-line description of the state of the compiler after compilation. */
91  string full_report() const;
92  };
93 
95  void compile(Shader *shader, array<int4> &svm_nodes, int index, Summary *summary = NULL);
96 
98  int stack_assign(ShaderInput *input);
101  int stack_find_offset(int size);
103  void stack_clear_offset(SocketType::Type type, int offset);
104  void stack_link(ShaderInput *input, ShaderOutput *output);
105 
106  void add_node(ShaderNodeType type, int a = 0, int b = 0, int c = 0);
107  void add_node(int a = 0, int b = 0, int c = 0, int d = 0);
108  void add_node(ShaderNodeType type, const float3 &f);
109  void add_node(const float4 &f);
110  uint attribute(ustring name);
112  uint attribute_standard(ustring name);
113  uint encode_uchar4(uint x, uint y = 0, uint z = 0, uint w = 0);
115  {
116  return mix_weight_offset;
117  }
118 
120  {
121  return current_type;
122  }
123 
127 
128  protected:
129  /* stack */
130  struct Stack {
132  {
133  memset(users, 0, sizeof(users));
134  }
135  Stack(const Stack &other)
136  {
137  memcpy(users, other.users, sizeof(users));
138  }
139  Stack &operator=(const Stack &other)
140  {
141  memcpy(users, other.users, sizeof(users));
142  return *this;
143  }
144 
145  bool empty()
146  {
147  for (int i = 0; i < SVM_STACK_SIZE; i++)
148  if (users[i])
149  return false;
150 
151  return true;
152  }
153 
154  void print()
155  {
156  printf("stack <");
157 
158  for (int i = 0; i < SVM_STACK_SIZE; i++)
159  printf((users[i]) ? "*" : " ");
160 
161  printf(">\n");
162  }
163 
165  };
166 
167  /* Global state of the compiler accessible from the compilation routines. */
168  struct CompilerState {
169  explicit CompilerState(ShaderGraph *graph);
170 
171  /* ** Global state, used by various compilation steps. ** */
172 
173  /* Set of nodes which were already compiled. */
175 
176  /* Set of closures which were already compiled. */
178 
179  /* Set of nodes used for writing AOVs. */
181 
182  /* ** SVM nodes generation state ** */
183 
184  /* Flag whether the node with corresponding ID was already compiled or
185  * not. Array element with index i corresponds to a node with such if.
186  *
187  * TODO(sergey): This is actually a copy of nodes_done just in another
188  * notation. We can de-duplicate this storage actually after switching
189  * all areas to use this flags array.
190  */
192  };
193 
197 
198  /* single closure */
199  void find_dependencies(ShaderNodeSet &dependencies,
200  const ShaderNodeSet &done,
201  ShaderInput *input,
202  ShaderNode *skip_node = NULL);
210  ShaderNode *node,
212  const ShaderNodeSet &shared);
214 
215  /* multi closure */
217 
218  /* compile */
220 
228 };
229 
231 
232 #endif /* __SVM_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
#define output
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
Definition: device.h:293
ShaderGraph * current_graph
Definition: render/svm.h:125
void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type)
Definition: svm.cpp:716
int max_stack_use
Definition: render/svm.h:225
void find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes, ShaderGraph *graph, CompilerState *state)
Definition: svm.cpp:551
void add_node(ShaderNodeType type, int a=0, int b=0, int c=0)
Definition: svm.cpp:392
bool background
Definition: render/svm.h:126
SVMCompiler(Scene *scene)
Definition: svm.cpp:177
array< int4 > current_svm_nodes
Definition: render/svm.h:221
void generate_closure_node(ShaderNode *node, CompilerState *state)
Definition: svm.cpp:493
void stack_clear_offset(SocketType::Type type, int offset)
Definition: svm.cpp:251
ShaderType current_type
Definition: render/svm.h:222
void generate_node(ShaderNode *node, ShaderNodeSet &done)
Definition: svm.cpp:440
int stack_assign_if_linked(ShaderInput *input)
Definition: svm.cpp:305
Shader * current_shader
Definition: render/svm.h:223
void stack_clear_users(ShaderNode *node, ShaderNodeSet &done)
Definition: svm.cpp:336
int stack_size(SocketType::Type type)
Definition: svm.cpp:188
void stack_clear_temporary(ShaderNode *node)
Definition: svm.cpp:367
uint encode_uchar4(uint x, uint y=0, uint z=0, uint w=0)
Definition: svm.cpp:377
uint attribute_standard(ustring name)
Definition: svm.cpp:419
Stack active_stack
Definition: render/svm.h:224
void stack_link(ShaderInput *input, ShaderOutput *output)
Definition: svm.cpp:321
void find_dependencies(ShaderNodeSet &dependencies, const ShaderNodeSet &done, ShaderInput *input, ShaderNode *skip_node=NULL)
Definition: svm.cpp:425
void generate_aov_node(ShaderNode *node, CompilerState *state)
ShaderType output_type()
Definition: render/svm.h:119
void generate_svm_nodes(const ShaderNodeSet &nodes, CompilerState *state)
Definition: svm.cpp:462
uint closure_mix_weight_offset()
Definition: render/svm.h:114
void generate_multi_closure(ShaderNode *root_node, ShaderNode *node, CompilerState *state)
Definition: svm.cpp:570
uint attribute(ustring name)
Definition: svm.cpp:409
Scene * scene
Definition: render/svm.h:124
uint mix_weight_offset
Definition: render/svm.h:226
bool compile_failed
Definition: render/svm.h:227
int stack_find_offset(int size)
Definition: svm.cpp:214
void compile(Shader *shader, array< int4 > &svm_nodes, int index, Summary *summary=NULL)
Definition: svm.cpp:845
void generated_shared_closure_nodes(ShaderNode *root_node, ShaderNode *node, CompilerState *state, const ShaderNodeSet &shared)
Definition: svm.cpp:535
int stack_assign(ShaderOutput *output)
Definition: svm.cpp:296
void reset(Scene *scene)
Definition: svm.cpp:46
void device_free(Device *device, DeviceScene *dscene, Scene *scene)
Definition: svm.cpp:168
SVMShaderManager()
Definition: svm.cpp:38
~SVMShaderManager()
Definition: svm.cpp:42
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
Definition: svm.cpp:72
void device_update_shader(Scene *scene, Shader *shader, Progress *progress, array< int4 > *svm_nodes)
Definition: svm.cpp:50
Definition: shader.h:80
OperationNode * node
Depsgraph * graph
Scene scene
set< ShaderNode *, ShaderNodeIDComparator > ShaderNodeSet
Definition: graph.h:307
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
AttributeStandard
Definition: kernel_types.h:744
static ulong state[N]
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
ShaderNodeSet nodes_done
Definition: render/svm.h:174
ShaderNodeSet closure_done
Definition: render/svm.h:177
vector< bool > nodes_done_flag
Definition: render/svm.h:191
CompilerState(ShaderGraph *graph)
Definition: svm.cpp:960
Stack & operator=(const Stack &other)
Definition: render/svm.h:139
int users[SVM_STACK_SIZE]
Definition: render/svm.h:164
Stack(const Stack &other)
Definition: render/svm.h:135
double time_generate_volume
Definition: render/svm.h:82
double time_generate_surface
Definition: render/svm.h:76
double time_generate_bump
Definition: render/svm.h:79
string full_report() const
Definition: svm.cpp:938
double time_generate_displacement
Definition: render/svm.h:85
#define SVM_STACK_SIZE
Definition: svm_types.h:25
ShaderNodeType
Definition: svm_types.h:64
ShaderType
Definition: svm_types.h:511