Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef __SVM_H__ 00020 #define __SVM_H__ 00021 00022 #include "attribute.h" 00023 #include "graph.h" 00024 #include "shader.h" 00025 00026 #include "util_set.h" 00027 #include "util_string.h" 00028 00029 CCL_NAMESPACE_BEGIN 00030 00031 class Device; 00032 class DeviceScene; 00033 class ImageManager; 00034 struct KernelSunSky; 00035 class Scene; 00036 class ShaderGraph; 00037 class ShaderInput; 00038 class ShaderNode; 00039 class ShaderOutput; 00040 00041 /* Shader Manager */ 00042 00043 class SVMShaderManager : public ShaderManager { 00044 public: 00045 SVMShaderManager(); 00046 ~SVMShaderManager(); 00047 00048 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); 00049 void device_free(Device *device, DeviceScene *dscene); 00050 }; 00051 00052 /* Graph Compiler */ 00053 00054 class SVMCompiler { 00055 public: 00056 SVMCompiler(ShaderManager *shader_manager, ImageManager *image_manager, 00057 bool use_multi_closure_); 00058 void compile(Shader *shader, vector<int4>& svm_nodes, int index); 00059 00060 void stack_assign(ShaderOutput *output); 00061 void stack_assign(ShaderInput *input); 00062 void stack_link(ShaderInput *input, ShaderOutput *output); 00063 void add_node(NodeType type, int a = 0, int b = 0, int c = 0); 00064 void add_node(int a = 0, int b = 0, int c = 0, int d = 0); 00065 void add_node(NodeType type, const float3& f); 00066 void add_node(const float4& f); 00067 uint attribute(ustring name); 00068 uint attribute(Attribute::Standard std); 00069 uint encode_uchar4(uint x, uint y = 0, uint z = 0, uint w = 0); 00070 uint closure_mix_weight_offset() { return mix_weight_offset; } 00071 00072 ShaderType output_type() { return current_type; } 00073 00074 ImageManager *image_manager; 00075 ShaderManager *shader_manager; 00076 KernelSunSky *sunsky; 00077 bool background; 00078 00079 protected: 00080 struct Stack { 00081 Stack() { memset(users, 0, sizeof(users)); } 00082 Stack(const Stack& other) { memcpy(users, other.users, sizeof(users)); } 00083 Stack& operator=(const Stack& other) { memcpy(users, other.users, sizeof(users)); return *this; } 00084 00085 bool empty() 00086 { 00087 for(int i = 0; i < SVM_STACK_SIZE; i++) 00088 if(users[i]) 00089 return false; 00090 00091 return true; 00092 } 00093 00094 void print() 00095 { 00096 printf("stack <"); 00097 00098 for(int i = 0; i < SVM_STACK_SIZE; i++) 00099 printf((users[i])? "*": " "); 00100 00101 printf(">\n"); 00102 } 00103 00104 int users[SVM_STACK_SIZE]; 00105 }; 00106 00107 struct StackBackup { 00108 Stack stack; 00109 vector<int> offsets; 00110 set<ShaderNode*> done; 00111 }; 00112 00113 void stack_backup(StackBackup& backup, set<ShaderNode*>& done); 00114 void stack_restore(StackBackup& backup, set<ShaderNode*>& done); 00115 00116 void stack_clear_temporary(ShaderNode *node); 00117 int stack_size(ShaderSocketType type); 00118 int stack_find_offset(ShaderSocketType type); 00119 void stack_clear_users(ShaderNode *node, set<ShaderNode*>& done); 00120 00121 bool node_skip_input(ShaderNode *node, ShaderInput *input); 00122 00123 void find_dependencies(set<ShaderNode*>& dependencies, const set<ShaderNode*>& done, ShaderInput *input); 00124 void generate_svm_nodes(const set<ShaderNode*>& nodes, set<ShaderNode*>& done); 00125 void generate_closure(ShaderNode *node, set<ShaderNode*>& done); 00126 void generate_multi_closure(ShaderNode *node, set<ShaderNode*>& done, uint in_offset); 00127 00128 void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type); 00129 00130 vector<int4> svm_nodes; 00131 ShaderType current_type; 00132 Shader *current_shader; 00133 ShaderGraph *current_graph; 00134 Stack active_stack; 00135 int max_stack_use; 00136 uint mix_weight_offset; 00137 bool use_multi_closure; 00138 }; 00139 00140 CCL_NAMESPACE_END 00141 00142 #endif /* __SVM_H__ */ 00143