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
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __SVM_H__
|
|
|
|
|
#define __SVM_H__
|
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/attribute.h"
|
|
|
|
|
#include "render/graph.h"
|
|
|
|
|
#include "render/shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-11-09 11:54:24 +01:00
|
|
|
#include "util/util_array.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_set.h"
|
|
|
|
|
#include "util/util_string.h"
|
|
|
|
|
#include "util/util_thread.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();
|
|
|
|
|
|
2021-05-12 10:27:37 +05:30
|
|
|
void reset(Scene *scene) override;
|
2013-02-14 16:11:47 +00:00
|
|
|
|
2021-05-02 02:34:56 +02:00
|
|
|
void device_update_specific(Device *device,
|
|
|
|
|
DeviceScene *dscene,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
Progress &progress) override;
|
2021-05-12 10:27:37 +05:30
|
|
|
void device_free(Device *device, DeviceScene *dscene, Scene *scene) override;
|
2016-09-09 12:27:51 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void device_update_shader(Scene *scene,
|
|
|
|
|
Shader *shader,
|
|
|
|
|
Progress *progress,
|
2019-07-30 23:29:18 -07:00
|
|
|
array<int4> *svm_nodes);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Graph Compiler */
|
|
|
|
|
|
|
|
|
|
class SVMCompiler {
|
|
|
|
|
public:
|
2015-12-28 19:30:43 +05:00
|
|
|
struct Summary {
|
|
|
|
|
Summary();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-28 19:30:43 +05:00
|
|
|
/* Number of SVM nodes shader was compiled into. */
|
|
|
|
|
int num_svm_nodes;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-28 19:30:43 +05:00
|
|
|
/* Peak stack usage during shader evaluation. */
|
|
|
|
|
int peak_stack_usage;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 21:20:10 +05:00
|
|
|
/* Time spent on surface graph finalization. */
|
|
|
|
|
double time_finalize;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 21:20:10 +05:00
|
|
|
/* Time spent on generating SVM nodes for surface shader. */
|
|
|
|
|
double time_generate_surface;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 21:20:10 +05:00
|
|
|
/* Time spent on generating SVM nodes for bump shader. */
|
|
|
|
|
double time_generate_bump;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 21:20:10 +05:00
|
|
|
/* Time spent on generating SVM nodes for volume shader. */
|
|
|
|
|
double time_generate_volume;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 21:20:10 +05:00
|
|
|
/* Time spent on generating SVM nodes for displacement shader. */
|
|
|
|
|
double time_generate_displacement;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 21:20:10 +05:00
|
|
|
/* Total time spent on all routines. */
|
|
|
|
|
double time_total;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-10 09:45:25 +10:00
|
|
|
/* A full multi-line description of the state of the compiler after compilation. */
|
2015-12-28 19:30:43 +05:00
|
|
|
string full_report() const;
|
|
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
SVMCompiler(Scene *scene);
|
|
|
|
|
void compile(Shader *shader, array<int4> &svm_nodes, int index, Summary *summary = NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-02 20:12:42 +02:00
|
|
|
int stack_assign(ShaderOutput *output);
|
|
|
|
|
int stack_assign(ShaderInput *input);
|
|
|
|
|
int stack_assign_if_linked(ShaderInput *input);
|
|
|
|
|
int stack_assign_if_linked(ShaderOutput *output);
|
2016-08-14 11:44:25 -04:00
|
|
|
int stack_find_offset(int size);
|
2016-05-08 01:32:09 +02:00
|
|
|
int stack_find_offset(SocketType::Type type);
|
|
|
|
|
void stack_clear_offset(SocketType::Type type, int offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
void stack_link(ShaderInput *input, ShaderOutput *output);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-07 19:47:37 +02:00
|
|
|
void add_node(ShaderNodeType type, int a = 0, int b = 0, int c = 0);
|
2011-04-27 11:58:34 +00:00
|
|
|
void add_node(int a = 0, int b = 0, int c = 0, int d = 0);
|
2016-05-07 19:47:37 +02:00
|
|
|
void add_node(ShaderNodeType type, const float3 &f);
|
2011-04-27 11:58:34 +00:00
|
|
|
void add_node(const float4 &f);
|
|
|
|
|
uint attribute(ustring name);
|
2012-04-30 12:49:26 +00:00
|
|
|
uint attribute(AttributeStandard std);
|
2018-02-18 03:20:39 +01:00
|
|
|
uint attribute_standard(ustring name);
|
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;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
ShaderType output_type()
|
|
|
|
|
{
|
|
|
|
|
return current_type;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
Scene *scene;
|
|
|
|
|
ShaderGraph *current_graph;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool background;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
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)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2011-09-16 13:00:09 +00:00
|
|
|
memcpy(users, other.users, sizeof(users));
|
|
|
|
|
return *this;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:00:09 +00:00
|
|
|
bool empty()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < SVM_STACK_SIZE; i++)
|
|
|
|
|
if (users[i])
|
|
|
|
|
return false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-16 13:00:09 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-16 13:00:09 +00:00
|
|
|
void print()
|
|
|
|
|
{
|
|
|
|
|
printf("stack <");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-16 13:00:09 +00:00
|
|
|
for (int i = 0; i < SVM_STACK_SIZE; i++)
|
|
|
|
|
printf((users[i]) ? "*" : " ");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-16 13:00:09 +00:00
|
|
|
printf(">\n");
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
int users[SVM_STACK_SIZE];
|
|
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-30 19:21:19 +05:00
|
|
|
/* Global state of the compiler accessible from the compilation routines. */
|
|
|
|
|
struct CompilerState {
|
2016-05-11 16:50:10 +02:00
|
|
|
explicit CompilerState(ShaderGraph *graph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 20:42:20 +05:00
|
|
|
/* ** Global state, used by various compilation steps. ** */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-30 19:21:19 +05:00
|
|
|
/* Set of nodes which were already compiled. */
|
|
|
|
|
ShaderNodeSet nodes_done;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-30 19:21:19 +05:00
|
|
|
/* Set of closures which were already compiled. */
|
|
|
|
|
ShaderNodeSet closure_done;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-22 00:50:22 +01:00
|
|
|
/* Set of nodes used for writing AOVs. */
|
|
|
|
|
ShaderNodeSet aov_nodes;
|
|
|
|
|
|
2015-12-29 20:42:20 +05:00
|
|
|
/* ** SVM nodes generation state ** */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-29 20:42:20 +05:00
|
|
|
/* Flag whether the node with corresponding ID was already compiled or
|
|
|
|
|
* not. Array element with index i corresponds to a node with such if.
|
|
|
|
|
*
|
|
|
|
|
* TODO(sergey): This is actually a copy of nodes_done just in another
|
|
|
|
|
* notation. We can de-duplicate this storage actually after switching
|
|
|
|
|
* all areas to use this flags array.
|
|
|
|
|
*/
|
|
|
|
|
vector<bool> nodes_done_flag;
|
2015-12-30 19:21:19 +05:00
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void stack_clear_temporary(ShaderNode *node);
|
2016-05-08 01:32:09 +02:00
|
|
|
int stack_size(SocketType::Type type);
|
2015-11-25 13:07:29 +05:00
|
|
|
void stack_clear_users(ShaderNode *node, ShaderNodeSet &done);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-24 14:50:21 +00:00
|
|
|
/* single closure */
|
2015-11-25 13:07:29 +05:00
|
|
|
void find_dependencies(ShaderNodeSet &dependencies,
|
|
|
|
|
const ShaderNodeSet &done,
|
2014-07-11 18:19:14 +06:00
|
|
|
ShaderInput *input,
|
|
|
|
|
ShaderNode *skip_node = NULL);
|
2020-12-22 00:50:22 +01:00
|
|
|
void find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes,
|
|
|
|
|
ShaderGraph *graph,
|
|
|
|
|
CompilerState *state);
|
2015-11-25 13:07:29 +05:00
|
|
|
void generate_node(ShaderNode *node, ShaderNodeSet &done);
|
2019-12-04 19:57:28 +01:00
|
|
|
void generate_aov_node(ShaderNode *node, CompilerState *state);
|
2015-12-30 19:21:19 +05:00
|
|
|
void generate_closure_node(ShaderNode *node, CompilerState *state);
|
|
|
|
|
void generated_shared_closure_nodes(ShaderNode *root_node,
|
|
|
|
|
ShaderNode *node,
|
|
|
|
|
CompilerState *state,
|
2015-11-25 13:07:29 +05:00
|
|
|
const ShaderNodeSet &shared);
|
2015-12-30 19:21:19 +05:00
|
|
|
void generate_svm_nodes(const ShaderNodeSet &nodes, CompilerState *state);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-24 14:50:21 +00:00
|
|
|
/* multi closure */
|
2014-07-11 18:19:14 +06:00
|
|
|
void generate_multi_closure(ShaderNode *root_node, ShaderNode *node, CompilerState *state);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-20 04:32:29 +02:00
|
|
|
array<int4> current_svm_nodes;
|
2011-04-27 11:58:34 +00:00
|
|
|
ShaderType current_type;
|
|
|
|
|
Shader *current_shader;
|
|
|
|
|
Stack active_stack;
|
|
|
|
|
int max_stack_use;
|
2011-09-12 13:13:56 +00:00
|
|
|
uint mix_weight_offset;
|
2014-01-16 22:36:30 +01:00
|
|
|
bool compile_failed;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
#endif /* __SVM_H__ */
|