constant_fold.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef __CONSTANT_FOLD_H__
  17. #define __CONSTANT_FOLD_H__
  18. #include "util/util_types.h"
  19. #include "kernel/svm/svm_types.h"
  20. CCL_NAMESPACE_BEGIN
  21. class Scene;
  22. class ShaderGraph;
  23. class ShaderInput;
  24. class ShaderNode;
  25. class ShaderOutput;
  26. class ConstantFolder {
  27. public:
  28. ShaderGraph *const graph;
  29. ShaderNode *const node;
  30. ShaderOutput *const output;
  31. Scene *scene;
  32. ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *output, Scene *scene);
  33. bool all_inputs_constant() const;
  34. /* Constant folding helpers */
  35. void make_constant(float value) const;
  36. void make_constant(float3 value) const;
  37. void make_constant_clamp(float value, bool clamp) const;
  38. void make_constant_clamp(float3 value, bool clamp) const;
  39. void make_zero() const;
  40. void make_one() const;
  41. /* Bypass node, relinking to another output socket. */
  42. void bypass(ShaderOutput *output) const;
  43. /* For closure nodes, discard node entirely or bypass to one of its inputs. */
  44. void discard() const;
  45. void bypass_or_discard(ShaderInput *input) const;
  46. /* Bypass or make constant, unless we can't due to clamp being true. */
  47. bool try_bypass_or_make_constant(ShaderInput *input, bool clamp = false) const;
  48. /* Test if shader inputs of the current nodes have fixed values. */
  49. bool is_zero(ShaderInput *input) const;
  50. bool is_one(ShaderInput *input) const;
  51. /* Specific nodes. */
  52. void fold_mix(NodeMix type, bool clamp) const;
  53. void fold_math(NodeMath type, bool clamp) const;
  54. void fold_vector_math(NodeVectorMath type) const;
  55. };
  56. CCL_NAMESPACE_END
  57. #endif /* __CONSTANT_FOLD_H__ */