Blender  V2.93
constant_fold.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 __CONSTANT_FOLD_H__
18 #define __CONSTANT_FOLD_H__
19 
20 #include "kernel/svm/svm_types.h"
21 #include "util/util_types.h"
22 
24 
25 class Scene;
26 class ShaderGraph;
27 class ShaderInput;
28 class ShaderNode;
29 class ShaderOutput;
30 
32  public:
34  ShaderNode *const node;
36 
38 
40 
41  bool all_inputs_constant() const;
42 
43  /* Constant folding helpers */
44  void make_constant(float value) const;
45  void make_constant(float3 value) const;
46  void make_constant_clamp(float value, bool clamp) const;
47  void make_constant_clamp(float3 value, bool clamp) const;
48  void make_zero() const;
49  void make_one() const;
50 
51  /* Bypass node, relinking to another output socket. */
52  void bypass(ShaderOutput *output) const;
53 
54  /* For closure nodes, discard node entirely or bypass to one of its inputs. */
55  void discard() const;
56  void bypass_or_discard(ShaderInput *input) const;
57 
58  /* Bypass or make constant, unless we can't due to clamp being true. */
59  bool try_bypass_or_make_constant(ShaderInput *input, bool clamp = false) const;
60 
61  /* Test if shader inputs of the current nodes have fixed values. */
62  bool is_zero(ShaderInput *input) const;
63  bool is_one(ShaderInput *input) const;
64 
65  /* Specific nodes. */
66  void fold_mix(NodeMix type, bool clamp) const;
67  void fold_math(NodeMathType type) const;
69  void fold_mapping(NodeMappingType type) const;
70 };
71 
73 
74 #endif /* __CONSTANT_FOLD_H__ */
_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
void make_one() const
void make_constant_clamp(float value, bool clamp) const
void discard() const
void bypass(ShaderOutput *output) const
void bypass_or_discard(ShaderInput *input) const
void fold_mapping(NodeMappingType type) const
ShaderGraph *const graph
Definition: constant_fold.h:33
bool all_inputs_constant() const
ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *output, Scene *scene)
bool try_bypass_or_make_constant(ShaderInput *input, bool clamp=false) const
void make_zero() const
bool is_zero(ShaderInput *input) const
bool is_one(ShaderInput *input) const
void fold_math(NodeMathType type) const
void make_constant(float value) const
ShaderOutput *const output
Definition: constant_fold.h:35
void fold_mix(NodeMix type, bool clamp) const
void fold_vector_math(NodeVectorMathType type) const
ShaderNode *const node
Definition: constant_fold.h:34
#define CCL_NAMESPACE_END
NodeMathType
Definition: svm_types.h:271
NodeMappingType
Definition: svm_types.h:358
NodeMix
Definition: svm_types.h:249
NodeVectorMathType
Definition: svm_types.h:314
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util_math.h:283