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;
|
2011-05-03 18:29:11 +00:00
|
|
|
struct KernelSunSky;
|
2011-04-27 11:58:34 +00:00
|
|
|
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:
|
2011-09-16 13:14:02 +00:00
|
|
|
SVMCompiler(ShaderManager *shader_manager, ImageManager *image_manager,
|
|
|
|
bool use_multi_closure_);
|
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;
|
|
|
|
KernelSunSky *sunsky;
|
|
|
|
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 */
|
2011-04-27 11:58:34 +00:00
|
|
|
void find_dependencies(set<ShaderNode*>& dependencies, const set<ShaderNode*>& done, ShaderInput *input);
|
|
|
|
void generate_svm_nodes(const set<ShaderNode*>& nodes, set<ShaderNode*>& done);
|
2011-09-21 11:54:28 +00:00
|
|
|
void generate_closure(ShaderNode *node, set<ShaderNode*>& done);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-24 14:50:21 +00:00
|
|
|
/* multi closure */
|
2012-11-28 19:13:34 +00:00
|
|
|
void generate_multi_closure(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;
|
2011-09-16 13:14:02 +00:00
|
|
|
bool use_multi_closure;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __SVM_H__ */
|
|
|
|
|