45 assert(shader->
graph);
50 compiler.
compile(shader, *svm_nodes, 0, &summary);
53 <<
"Shader name: " << shader->
name <<
"\n"
67 scene->update_stats->svm.times.add_entry({
"device_update", time});
73 VLOG_INFO <<
"Total " << num_shaders <<
" shaders.";
78 device_free(device, dscene,
scene);
83 for (
int i = 0; i < num_shaders; i++) {
89 &shader_svm_nodes[i]));
93 if (progress.get_cancel()) {
99 int svm_nodes_size = num_shaders;
100 for (
int i = 0; i < num_shaders; i++) {
102 svm_nodes_size += shader_svm_nodes[i].size() - 1;
105 int4 *svm_nodes = dscene->svm_nodes.alloc(svm_nodes_size);
107 int node_offset = num_shaders;
108 for (
int i = 0; i < num_shaders; i++) {
119 int4 &global_jump_node = svm_nodes[shader->
id];
120 int4 &local_jump_node = shader_svm_nodes[i][0];
122 global_jump_node.
x = NODE_SHADER_JUMP;
123 global_jump_node.
y = local_jump_node.
y - 1 + node_offset;
124 global_jump_node.
z = local_jump_node.
z - 1 + node_offset;
125 global_jump_node.
w = local_jump_node.
w - 1 + node_offset;
127 node_offset += shader_svm_nodes[i].size() - 1;
131 svm_nodes += num_shaders;
132 for (
int i = 0; i < num_shaders; i++) {
133 int shader_size = shader_svm_nodes[i].size() - 1;
135 memcpy(svm_nodes, &shader_svm_nodes[i][1],
sizeof(
int4) * shader_size);
136 svm_nodes += shader_size;
139 if (progress.get_cancel()) {
143 dscene->svm_nodes.copy_to_device();
145 device_update_common(device, dscene,
scene, progress);
147 update_flags = UPDATE_NONE;
149 VLOG_INFO <<
"Shader manager updated " << num_shaders <<
" shaders in " <<
time_dt() - start_time
213 if (num_unused ==
size) {
227 "Cycles: out of SVM stack space, shader \"%s\" too big.\n",
243 for (
int i = 0; i <
size; i++)
254 input->stack_offset =
input->link->stack_offset;
265 input->stack_offset);
281 return input->stack_offset;
290 return output->stack_offset;
303 if (!
output->links.empty())
319 for (
int i = 0; i <
size; i++)
337 bool all_done =
true;
341 if (in->parent !=
node && done.find(in->parent) == done.end())
372 return (
x) | (
y << 8) | (
z << 16) | (
w << 24);
422 dependencies.find(
node) == dependencies.end()) {
426 dependencies.insert(
node);
432 node->compile(*
this);
437 if (
node->has_spatial_varying())
443 if (
node->has_spatial_varying())
445 if (
node->has_attribute_dependency())
449 if (
node->has_integrator_dependency()) {
464 if (!done_flag[
node->id]) {
465 bool inputs_done =
true;
468 if (
input->link && !done_flag[
input->link->parent->id]) {
475 done_flag[
node->id] =
true;
482 }
while (!nodes_done);
489 const int node_feature =
node->get_feature();
490 if ((
state->node_feature_mask & node_feature) != node_feature) {
496 if (in->link !=
NULL) {
519 if (
node->has_surface_emission())
521 if (
node->has_surface_transparent())
523 if (
node->has_surface_bssrdf()) {
525 if (
node->has_bssrdf_bump())
528 if (
node->has_bump()) {
539 if (shared.find(
node) != shared.end()) {
557 if (aov_node->
offset >= 0) {
558 aov_nodes.insert(aov_node);
560 if (in->link !=
NULL) {
589 if (facin && facin->
link) {
604 set_intersection(cl1deps.begin(),
608 std::inserter(shareddeps, shareddeps.begin()),
615 if (root_node !=
node) {
619 set_intersection(rootdeps.begin(),
623 std::inserter(shareddeps, shareddeps.begin()),
625 set_intersection(rootdeps.begin(),
629 std::inserter(shareddeps, shareddeps.begin()),
638 if (
state->aov_nodes.size()) {
639 set_intersection(
state->aov_nodes.begin(),
640 state->aov_nodes.end(),
643 std::inserter(shareddeps, shareddeps.begin()),
645 set_intersection(
state->aov_nodes.begin(),
646 state->aov_nodes.end(),
649 std::inserter(shareddeps, shareddeps.begin()),
653 if (!shareddeps.empty()) {
677 node_jump_skip_index - 1;
693 node_jump_skip_index - 1;
744 clin =
output->input(
"Surface");
747 clin =
output->input(
"Volume");
750 clin =
output->input(
"Displacement");
753 clin =
output->input(
"Normal");
775 if (need_bump_state) {
777 add_node(NODE_ENTER_BUMP_EVAL, bump_state_offset);
820 if (!
state.aov_nodes.empty()) {
833 if (need_bump_state) {
834 add_node(NODE_LEAVE_BUMP_EVAL, bump_state_offset);
857 int start_num_svm_nodes = svm_nodes.
size();
859 const double time_start =
time_dt();
861 bool has_bump = (shader->get_displacement_method() !=
DISPLACE_TRUE) &&
862 output->input(
"Surface")->link &&
output->input(
"Displacement")->link;
893 svm_nodes[index].y = svm_nodes.
size();
904 svm_nodes[index].y = svm_nodes.
size();
913 svm_nodes[index].z = svm_nodes.
size();
921 svm_nodes[index].w = svm_nodes.
size();
926 if (summary !=
NULL) {
939 time_generate_surface(0.0),
940 time_generate_bump(0.0),
941 time_generate_volume(0.0),
942 time_generate_displacement(0.0),
950 report +=
string_printf(
"Number of SVM nodes: %d\n", num_svm_nodes);
951 report +=
string_printf(
"Peak stack usage: %d\n", peak_stack_usage);
955 report +=
string_printf(
" Surface: %f\n", time_generate_surface);
957 report +=
string_printf(
" Volume: %f\n", time_generate_volume);
958 report +=
string_printf(
" Displacement: %f\n", time_generate_displacement);
960 time_generate_surface + time_generate_bump + time_generate_volume +
961 time_generate_displacement);
973 max_id =
max(
node->id, max_id);
975 nodes_done_flag.resize(max_id + 1,
false);
976 node_feature_mask = 0;
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static AttributeStandard name_standard(const char *name)
Shader * get_shader(const Scene *scene)
device_vector< int4 > svm_nodes
void tag_update(Scene *scene, uint32_t flag)
ShaderGraph * current_graph
void compile_type(Shader *shader, ShaderGraph *graph, ShaderType type)
void find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes, ShaderGraph *graph, CompilerState *state)
void add_node(ShaderNodeType type, int a=0, int b=0, int c=0)
SVMCompiler(Scene *scene)
array< int4 > current_svm_nodes
void generate_closure_node(ShaderNode *node, CompilerState *state)
void stack_clear_offset(SocketType::Type type, int offset)
void generate_node(ShaderNode *node, ShaderNodeSet &done)
int stack_assign_if_linked(ShaderInput *input)
void stack_clear_users(ShaderNode *node, ShaderNodeSet &done)
int stack_size(SocketType::Type type)
void stack_clear_temporary(ShaderNode *node)
uint encode_uchar4(uint x, uint y=0, uint z=0, uint w=0)
uint attribute_standard(ustring name)
void stack_link(ShaderInput *input, ShaderOutput *output)
void find_dependencies(ShaderNodeSet &dependencies, const ShaderNodeSet &done, ShaderInput *input, ShaderNode *skip_node=NULL)
void generate_svm_nodes(const ShaderNodeSet &nodes, CompilerState *state)
void generate_multi_closure(ShaderNode *root_node, ShaderNode *node, CompilerState *state)
uint attribute(ustring name)
std::atomic_int * svm_node_types_used
int stack_find_offset(int size)
void compile(Shader *shader, array< int4 > &svm_nodes, int index, Summary *summary=NULL)
void generated_shared_closure_nodes(ShaderNode *root_node, ShaderNode *node, CompilerState *state, const ShaderNodeSet &shared)
int stack_assign(ShaderOutput *output)
void reset(Scene *scene) override
void device_free(Device *device, DeviceScene *dscene, Scene *scene) override
void device_update_specific(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress) override
void device_update_shader(Scene *scene, Shader *shader, Progress *progress, array< int4 > *svm_nodes)
void finalize(Scene *scene, bool do_bump=false, bool do_simplify=false, bool bump_in_object_space=false)
uint get_attribute_id(ustring name)
void device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
vector< ShaderInput * > inputs
bool has_surface_spatial_varying
bool has_volume_attribute_dependency
NODE_DECLARE ShaderGraph * graph
bool has_integrator_dependency
bool has_surface_emission
bool has_surface_raytrace
bool has_surface_transparent
bool has_volume_spatial_varying
void append(const array< T > &from)
void push_back_slow(const T &t)
#define CCL_NAMESPACE_END
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_global KernelShaderEvalInput * input
@ SHADER_TYPE_DISPLACEMENT
#define SVM_BUMP_EVAL_STATE_SIZE
#define SVM_STACK_INVALID
#define KERNEL_FEATURE_NODE_MASK_DISPLACEMENT
@ KERNEL_FEATURE_NODE_RAYTRACE
#define KERNEL_FEATURE_NODE_MASK_BUMP
#define KERNEL_FEATURE_NODE_MASK_VOLUME
#define KERNEL_FEATURE_NODE_MASK_SURFACE
static char * generate(GHash *messages, size_t *r_output_size)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
@ SHADER_SPECIAL_TYPE_OUTPUT_AOV
@ SHADER_SPECIAL_TYPE_COMBINE_CLOSURE
set< ShaderNode *, ShaderNodeIDComparator > ShaderNodeSet
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
int reference_count() const
CompilerState(ShaderGraph *graph)
int users[SVM_STACK_SIZE]
double time_generate_volume
double time_generate_surface
double time_generate_bump
string full_report() const
double time_generate_displacement
vector< Shader * > shaders
ShaderManager * shader_manager
LightManager * light_manager
SceneUpdateStats * update_stats
void push(TaskRunFunction &&task)
void wait_work(Summary *stats=NULL)
CCL_NAMESPACE_BEGIN double time_dt()
ccl_device_inline int __float_as_int(float f)