2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SVM_H__
|
|
|
|
#define __SVM_H__
|
|
|
|
|
|
|
|
#include "attribute.h"
|
|
|
|
#include "graph.h"
|
|
|
|
#include "shader.h"
|
|
|
|
|
|
|
|
#include "util_set.h"
|
2011-09-12 13:13:56 +00:00
|
|
|
#include "util_string.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Device;
|
|
|
|
class DeviceScene;
|
|
|
|
class ImageManager;
|
|
|
|
class Scene;
|
|
|
|
class ShaderGraph;
|
|
|
|
class ShaderInput;
|
|
|
|
class ShaderNode;
|
|
|
|
class ShaderOutput;
|
|
|
|
|
|
|
|
/* Shader Manager */
|
|
|
|
|
|
|
|
class SVMShaderManager : public ShaderManager {
|
|
|
|
public:
|
|
|
|
SVMShaderManager();
|
|
|
|
~SVMShaderManager();
|
|
|
|
|
2013-02-14 16:11:47 +00:00
|
|
|
void reset(Scene *scene);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
|
2013-04-01 20:26:52 +00:00
|
|
|
void device_free(Device *device, DeviceScene *dscene, Scene *scene);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Graph Compiler */
|
|
|
|
|
|
|
|
class SVMCompiler {
|
|
|
|
public:
|
2014-04-21 13:53:20 +00:00
|
|
|
SVMCompiler(ShaderManager *shader_manager, ImageManager *image_manager);
|
2011-04-27 11:58:34 +00:00
|
|
|
void compile(Shader *shader, vector<int4>& svm_nodes, int index);
|
|
|
|
|
|
|
|
void stack_assign(ShaderOutput *output);
|
|
|
|
void stack_assign(ShaderInput *input);
|
2012-03-08 19:52:58 +00:00
|
|
|
int stack_find_offset(ShaderSocketType type);
|
|
|
|
void stack_clear_offset(ShaderSocketType type, int offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
void stack_link(ShaderInput *input, ShaderOutput *output);
|
2012-03-08 19:52:58 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void add_node(NodeType type, int a = 0, int b = 0, int c = 0);
|
|
|
|
void add_node(int a = 0, int b = 0, int c = 0, int d = 0);
|
|
|
|
void add_node(NodeType type, const float3& f);
|
|
|
|
void add_node(const float4& f);
|
2012-03-26 12:45:14 +00:00
|
|
|
void add_array(float4 *f, int num);
|
2011-04-27 11:58:34 +00:00
|
|
|
uint attribute(ustring name);
|
2012-04-30 12:49:26 +00:00
|
|
|
uint attribute(AttributeStandard std);
|
2011-04-27 11:58:34 +00:00
|
|
|
uint encode_uchar4(uint x, uint y = 0, uint z = 0, uint w = 0);
|
2011-09-12 13:13:56 +00:00
|
|
|
uint closure_mix_weight_offset() { return mix_weight_offset; }
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
ShaderType output_type() { return current_type; }
|
|
|
|
|
|
|
|
ImageManager *image_manager;
|
|
|
|
ShaderManager *shader_manager;
|
|
|
|
bool background;
|
|
|
|
|
|
|
|
protected:
|
2012-11-24 14:50:21 +00:00
|
|
|
/* stack */
|
2011-04-27 11:58:34 +00:00
|
|
|
struct Stack {
|
2011-09-12 13:13:56 +00:00
|
|
|
Stack() { memset(users, 0, sizeof(users)); }
|
2011-09-16 13:00:09 +00:00
|
|
|
Stack(const Stack& other) { memcpy(users, other.users, sizeof(users)); }
|
|
|
|
Stack& operator=(const Stack& other) { memcpy(users, other.users, sizeof(users)); return *this; }
|
|
|
|
|
|
|
|
bool empty()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < SVM_STACK_SIZE; i++)
|
|
|
|
if(users[i])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print()
|
|
|
|
{
|
|
|
|
printf("stack <");
|
|
|
|
|
|
|
|
for(int i = 0; i < SVM_STACK_SIZE; i++)
|
|
|
|
printf((users[i])? "*": " ");
|
|
|
|
|
|
|
|
printf(">\n");
|
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
int users[SVM_STACK_SIZE];
|
|
|
|
};
|
|
|
|
|
2011-09-21 11:54:28 +00:00
|
|
|
struct StackBackup {
|
|
|
|
Stack stack;
|
|
|
|
vector<int> offsets;
|
|
|
|
set<ShaderNode*> done;
|
|
|
|
};
|
|
|
|
|
|
|
|
void stack_backup(StackBackup& backup, set<ShaderNode*>& done);
|
|
|
|
void stack_restore(StackBackup& backup, set<ShaderNode*>& done);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void stack_clear_temporary(ShaderNode *node);
|
|
|
|
int stack_size(ShaderSocketType type);
|
|
|
|
void stack_clear_users(ShaderNode *node, set<ShaderNode*>& done);
|
|
|
|
|
|
|
|
bool node_skip_input(ShaderNode *node, ShaderInput *input);
|
|
|
|
|
2012-11-24 14:50:21 +00:00
|
|
|
/* single closure */
|
2014-04-21 15:17:24 +00:00
|
|
|
void find_dependencies(set<ShaderNode*>& dependencies,
|
2014-07-11 12:19:14 +00:00
|
|
|
const set<ShaderNode*>& done,
|
|
|
|
ShaderInput *input,
|
|
|
|
ShaderNode *skip_node = NULL);
|
2014-04-03 20:04:39 +00:00
|
|
|
void generate_node(ShaderNode *node, set<ShaderNode*>& done);
|
2014-04-21 15:17:24 +00:00
|
|
|
void generate_closure_node(ShaderNode *node, set<ShaderNode*>& done);
|
2014-07-11 12:19:14 +00:00
|
|
|
void generated_shared_closure_nodes(ShaderNode *root_node, ShaderNode *node,
|
|
|
|
set<ShaderNode*>& done,
|
2014-04-21 15:17:24 +00:00
|
|
|
set<ShaderNode*>& closure_done, const set<ShaderNode*>& shared);
|
2011-04-27 11:58:34 +00:00
|
|
|
void generate_svm_nodes(const set<ShaderNode*>& nodes, set<ShaderNode*>& done);
|
|
|
|
|
2012-11-24 14:50:21 +00:00
|
|
|
/* multi closure */
|
2014-07-11 12:19:14 +00:00
|
|
|
void generate_multi_closure(ShaderNode *root_node,
|
|
|
|
ShaderNode *node,
|
|
|
|
set<ShaderNode*>& done,
|
|
|
|
set<ShaderNode*>& closure_done);
|
2012-11-24 14:50:21 +00:00
|
|
|
|
|
|
|
/* compile */
|
2011-04-27 11:58:34 +00:00
|
|
|
void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type);
|
|
|
|
|
|
|
|
vector<int4> svm_nodes;
|
|
|
|
ShaderType current_type;
|
|
|
|
Shader *current_shader;
|
2011-09-21 11:54:28 +00:00
|
|
|
ShaderGraph *current_graph;
|
2011-04-27 11:58:34 +00:00
|
|
|
Stack active_stack;
|
|
|
|
int max_stack_use;
|
2011-09-12 13:13:56 +00:00
|
|
|
uint mix_weight_offset;
|
2014-01-16 21:36:30 +00:00
|
|
|
bool compile_failed;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __SVM_H__ */
|
|
|
|
|