Commit: 7b7e7ac4c1a0ba0ca31a26bf3901ec184ae8930a Author: Brecht Van Lommel Date: Mon May 2 20:12:42 2016 +0200 Branches: master https://developer.blender.org/rB7b7e7ac4c1a0ba0ca31a26bf3901ec184ae8930a
Code cleanup: simplify SVM stack assignment. =================================================================== M intern/cycles/kernel/svm/svm.h M intern/cycles/kernel/svm/svm_hsv.h M intern/cycles/render/nodes.cpp M intern/cycles/render/nodes.h M intern/cycles/render/svm.cpp M intern/cycles/render/svm.h =================================================================== diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 9865da2..543e31b 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -295,7 +295,7 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ccl_a break; # endif /* NODES_FEATURE(NODE_FEATURE_BUMP) */ case NODE_HSV: - svm_node_hsv(kg, sd, stack, node.y, node.z, node.w, &offset); + svm_node_hsv(kg, sd, stack, node, &offset); break; # endif /* __EXTRA_NODES__ */ #endif /* NODES_GROUP(NODE_GROUP_LEVEL_0) */ diff --git a/intern/cycles/kernel/svm/svm_hsv.h b/intern/cycles/kernel/svm/svm_hsv.h index 1f2cad6..3a1840c 100644 --- a/intern/cycles/kernel/svm/svm_hsv.h +++ b/intern/cycles/kernel/svm/svm_hsv.h @@ -19,18 +19,20 @@ CCL_NAMESPACE_BEGIN -ccl_device void svm_node_hsv(KernelGlobals *kg, ShaderData *sd, float *stack, uint in_color_offset, uint fac_offset, uint out_color_offset, int *offset) +ccl_device void svm_node_hsv(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) { - /* read extra data */ - uint4 node1 = read_node(kg, offset); + uint in_color_offset, fac_offset, out_color_offset; + uint hue_offset, sat_offset, val_offset; + decode_node_uchar4(node.y, &in_color_offset, &fac_offset, &out_color_offset, NULL); + decode_node_uchar4(node.z, &hue_offset, &sat_offset, &val_offset, NULL); float fac = stack_load_float(stack, fac_offset); float3 in_color = stack_load_float3(stack, in_color_offset); float3 color = in_color; - float hue = stack_load_float(stack, node1.y); - float sat = stack_load_float(stack, node1.z); - float val = stack_load_float(stack, node1.w); + float hue = stack_load_float(stack, hue_offset); + float sat = stack_load_float(stack, sat_offset); + float val = stack_load_float(stack, val_offset); color = rgb_to_hsv(color); diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 8e8b99e..488673a 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -127,9 +127,6 @@ bool TextureMapping::skip() void TextureMapping::compile(SVMCompiler& compiler, int offset_in, int offset_out) { - if(offset_in == SVM_STACK_INVALID || offset_out == SVM_STACK_INVALID) - return; - compiler.add_node(NODE_MAPPING, offset_in, offset_out); Transform tfm = compute_transform(); @@ -150,6 +147,29 @@ void TextureMapping::compile(SVMCompiler& compiler, int offset_in, int offset_ou } } +/* Convenience function for texture nodes, allocating stack space to output + * a modified vector and returning its offset */ +int TextureMapping::compile_begin(SVMCompiler& compiler, ShaderInput *vector_in) +{ + if(!skip()) { + int offset_in = compiler.stack_assign(vector_in); + int offset_out = compiler.stack_find_offset(SHADER_SOCKET_VECTOR); + + compile(compiler, offset_in, offset_out); + + return offset_out; + } + + return compiler.stack_assign(vector_in); +} + +void TextureMapping::compile_end(SVMCompiler& compiler, ShaderInput *vector_in, int vector_offset) +{ + if(!skip()) { + compiler.stack_clear_offset(vector_in->type, vector_offset); + } +} + void TextureMapping::compile(OSLCompiler &compiler) { if(!skip()) { @@ -280,29 +300,17 @@ void ImageTextureNode::compile(SVMCompiler& compiler) is_float = (int)is_float_bool; } - if(!color_out->links.empty()) - compiler.stack_assign(color_out); - if(!alpha_out->links.empty()) - compiler.stack_assign(alpha_out); - if(slot != -1) { - compiler.stack_assign(vector_in); - int srgb = (is_linear || color_space != "Color")? 0: 1; - int vector_offset = vector_in->stack_offset; - - if(!tex_mapping.skip()) { - vector_offset = compiler.stack_find_offset(SHADER_SOCKET_VECTOR); - tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset); - } + int vector_offset = tex_mapping.compile_begin(compiler, vector_in); if(projection != "Box") { compiler.add_node(NODE_TEX_IMAGE, slot, compiler.encode_uchar4( vector_offset, - color_out->stack_offset, - alpha_out->stack_offset, + compiler.stack_assign_if_linked(color_out), + compiler.stack_assign_if_linked(alpha_out), srgb), projection_enum[projection]); } @@ -311,25 +319,24 @@ void ImageTextureNode::compile(SVMCompiler& compiler) slot, compiler.encode_uchar4( vector_offset, - color_out->stack_offset, - alpha_out->stack_offset, + compiler.stack_assign_if_linked(color_out), + compiler.stack_assign_if_linked(alpha_out), srgb), __float_as_int(projection_blend)); } - if(vector_offset != vector_in->stack_offset) - compiler.stack_clear_offset(vector_in->type, vector_offset); + tex_mapping.compile_end(compiler, vector_in, vector_offset); } else { /* image not found */ if(!color_out->links.empty()) { - compiler.add_node(NODE_VALUE_V, color_out->stack_offset); + compiler.add_node(NODE_VALUE_V, compiler.stack_assign(color_out)); compiler.add_node(NODE_VALUE_V, make_float3(TEX_IMAGE_MISSING_R, TEX_IMAGE_MISSING_G, TEX_IMAGE_MISSING_B)); } if(!alpha_out->links.empty()) - compiler.add_node(NODE_VALUE_F, __float_as_int(TEX_IMAGE_MISSING_A), alpha_out->stack_offset); + compiler.add_node(NODE_VALUE_F, __float_as_int(TEX_IMAGE_MISSING_A), compiler.stack_assign(alpha_out)); } } @@ -486,44 +493,31 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler) is_float = (int)is_float_bool; } - if(!color_out->links.empty()) - compiler.stack_assign(color_out); - if(!alpha_out->links.empty()) - compiler.stack_assign(alpha_out); - if(slot != -1) { - compiler.stack_assign(vector_in); - int srgb = (is_linear || color_space != "Color")? 0: 1; - int vector_offset = vector_in->stack_offset; - - if(!tex_mapping.skip()) { - vector_offset = compiler.stack_find_offset(SHADER_SOCKET_VECTOR); - tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset); - } + int vector_offset = tex_mapping.compile_begin(compiler, vector_in); compiler.add_node(NODE_TEX_ENVIRONMENT, slot, compiler.encode_uchar4( vector_offset, - color_out->stack_offset, - alpha_out->stack_offset, + compiler.stack_assign_if_linked(color_out), + compiler.stack_assign_if_linked(alpha_out), srgb), projection_enum[projection]); - if(vector_offset != vector_in->stack_offset) - compiler.stack_clear_offset(vector_in->type, vector_offset); + tex_mapping.compile_end(compiler, vector_in, vector_offset); } else { /* image not found */ if(!color_out->links.empty()) { - compiler.add_node(NODE_VALUE_V, color_out->stack_offset); + compiler.add_node(NODE_VALUE_V, compiler.stack_assign(color_out)); compiler.add_node(NODE_VALUE_V, make_float3(TEX_IMAGE_MISSING_R, TEX_IMAGE_MISSING_G, TEX_IMAGE_MISSING_B)); } if(!alpha_out->links.empty()) - compiler.add_node(NODE_VALUE_F, __float_as_int(TEX_IMAGE_MISSING_A), alpha_out->stack_offset); + compiler.add_node(NODE_VALUE_F, __float_as_int(TEX_IMAGE_MISSING_A), compiler.stack_assign(alpha_out)); } } @@ -736,19 +730,11 @@ void SkyTextureNode::compile(SVMCompiler& compiler) else assert(false); - if(vector_in->link) - compiler.stack_assign(vector_in); - - int vector_offset = vector_in->stack_offset; + int vector_offset = tex_mapping.compile_begin(compiler, vector_in); int sky_model = type_enum[type]; - if(!tex_mapping.skip()) { - vector_offset = compiler.stack_find_offset(SHADER_SOCKET_VECTOR); - tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset); - } - compiler.stack_assign(color_out); - compiler.add_node(NODE_TEX_SKY, vector_offset, color_out->stack_offset, sky_model); + compiler.add_node(NODE_TEX_SKY, vector_offset, compiler.stack_assign(color_out), sky_model); compiler.add_node(__float_as_uint(sunsky.phi), __float_as_uint(sunsky.theta), __float_as_uint(sunsky.radiance_x), __float_as_uint(sunsky.radiance_y)); compiler.add_node(__float_as_uint(sunsky.radiance_z), __float_as_uint(sunsky.config_x[0]), __float_as_uint(sunsky.config_x[1]), __float_as_uint(sunsky.config_x[2])); compiler.add_node(__float_as_uint(sunsky.config_x[3]), __float_as_uint(sunsky.config_x[4]), __float_as_uint(sunsky.config_x[5]), __float_as_uint(sunsky.config_x[6])); @@ -758,8 +744,7 @@ void SkyTextureNode::compile(SVMCompiler& compiler) compiler.add_node(__float_as_uint(sunsky.config_z[1]), __float_as_uint(sunsky.config_z[2]), __float_as_uint(sunsky.config_z[3]), __float_as_uint(sunsky.config_z[4])); compiler.add_node(__float_as_uint(sunsky.config_z[5]), __float_as_uint(sunsky.config_z[6]), __float_as_uint(sunsky.config_z[7]), __float_as_uint(sunsky.config_z[8])); - if(vector_offset != vector_in->stack_offset) - compiler.stack_clear_offset(vector_in->type, vector_offset); + tex_mapping.compile_end(compiler, vector_in, vector_offset); } void SkyTextureNode::compile(OSLCompiler& compiler) @@ -820,25 +805,16 @@ void GradientTextureNode::compile(SVMCompiler& compiler) ShaderOutput *color_out = output("Color"); ShaderOutput *fac_out = output("Fac"); - if(vector_in->link) compiler.stack_assign(vector_in); - - int vector_offset = vector_in->stack_offset; - - if(!tex_mapping.skip()) { - vector_offset = compiler.stack_find_offset(SHADER_SOCKET_VECTOR); - tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset); - } - - if(!fac_out->links.empty()) - compiler.stack_assign(fac_out); - if(!color_out->links.empty()) - compiler.stack_assign(color_out); + int vector_offset = tex_mapping.compile_begin(compiler, vector_in); compiler.add_node(NODE_TEX_GRADIENT, - compiler.encode_uchar4(type_enum[type], vector_offset, fac_out->stack_offset, color_out->stack_offset)); + compiler.encode_uchar4( + type_enum[type], + vector_offset, + compiler.stack_assign_if_linked(fac_out), + compiler.stack_assign_if_linked(color_out))); - if(vector_offset != vector_in->stack_offset) - compiler.stack_clear_offset(vector_in->type, vector_offset); + tex_mapping.compile_end(compil @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs