Code cleanup: simplify SVM stack assignment.
This commit is contained in:
@@ -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) */
|
||||
|
@@ -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);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,9 @@ public:
|
||||
void compile(SVMCompiler& compiler, int offset_in, int offset_out);
|
||||
void compile(OSLCompiler &compiler);
|
||||
|
||||
int compile_begin(SVMCompiler& compiler, ShaderInput *vector_in);
|
||||
void compile_end(SVMCompiler& compiler, ShaderInput *vector_in, int vector_offset);
|
||||
|
||||
float3 translation;
|
||||
float3 rotation;
|
||||
float3 scale;
|
||||
|
@@ -185,7 +185,7 @@ void SVMCompiler::stack_clear_offset(ShaderSocketType type, int offset)
|
||||
active_stack.users[offset + i]--;
|
||||
}
|
||||
|
||||
void SVMCompiler::stack_assign(ShaderInput *input)
|
||||
int SVMCompiler::stack_assign(ShaderInput *input)
|
||||
{
|
||||
/* stack offset assign? */
|
||||
if(input->stack_offset == SVM_STACK_INVALID) {
|
||||
@@ -216,13 +216,33 @@ void SVMCompiler::stack_assign(ShaderInput *input)
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
return input->stack_offset;
|
||||
}
|
||||
|
||||
void SVMCompiler::stack_assign(ShaderOutput *output)
|
||||
int SVMCompiler::stack_assign(ShaderOutput *output)
|
||||
{
|
||||
/* if no stack offset assigned yet, find one */
|
||||
if(output->stack_offset == SVM_STACK_INVALID)
|
||||
output->stack_offset = stack_find_offset(output->type);
|
||||
|
||||
return output->stack_offset;
|
||||
}
|
||||
|
||||
int SVMCompiler::stack_assign_if_linked(ShaderInput *input)
|
||||
{
|
||||
if(input->link)
|
||||
return stack_assign(input);
|
||||
|
||||
return SVM_STACK_INVALID;
|
||||
}
|
||||
|
||||
int SVMCompiler::stack_assign_if_linked(ShaderOutput *output)
|
||||
{
|
||||
if(!output->links.empty())
|
||||
return stack_assign(output);
|
||||
|
||||
return SVM_STACK_INVALID;
|
||||
}
|
||||
|
||||
void SVMCompiler::stack_link(ShaderInput *input, ShaderOutput *output)
|
||||
@@ -434,10 +454,8 @@ void SVMCompiler::generate_closure_node(ShaderNode *node,
|
||||
const char *weight_name = (current_type == SHADER_TYPE_VOLUME)? "VolumeMixWeight": "SurfaceMixWeight";
|
||||
ShaderInput *weight_in = node->input(weight_name);
|
||||
|
||||
if(weight_in && (weight_in->link || weight_in->value.x != 1.0f)) {
|
||||
stack_assign(weight_in);
|
||||
mix_weight_offset = weight_in->stack_offset;
|
||||
}
|
||||
if(weight_in && (weight_in->link || weight_in->value.x != 1.0f))
|
||||
mix_weight_offset = stack_assign(weight_in);
|
||||
else
|
||||
mix_weight_offset = SVM_STACK_INVALID;
|
||||
|
||||
@@ -504,8 +522,6 @@ void SVMCompiler::generate_multi_closure(ShaderNode *root_node,
|
||||
find_dependencies(dependencies, state->nodes_done, facin);
|
||||
generate_svm_nodes(dependencies, state);
|
||||
|
||||
stack_assign(facin);
|
||||
|
||||
/* execute shared dependencies. this is needed to allow skipping
|
||||
* of zero weight closures and their dependencies later, so we
|
||||
* ensure that they only skip dependencies that are unique to them */
|
||||
@@ -559,7 +575,7 @@ void SVMCompiler::generate_multi_closure(ShaderNode *root_node,
|
||||
/* generate instructions for input closure 1 */
|
||||
if(cl1in->link) {
|
||||
/* add instruction to skip closure and its dependencies if mix weight is zero */
|
||||
svm_nodes.push_back(make_int4(NODE_JUMP_IF_ONE, 0, facin->stack_offset, 0));
|
||||
svm_nodes.push_back(make_int4(NODE_JUMP_IF_ONE, 0, stack_assign(facin), 0));
|
||||
int node_jump_skip_index = svm_nodes.size() - 1;
|
||||
|
||||
generate_multi_closure(root_node, cl1in->link->parent, state);
|
||||
@@ -571,7 +587,7 @@ void SVMCompiler::generate_multi_closure(ShaderNode *root_node,
|
||||
/* generate instructions for input closure 2 */
|
||||
if(cl2in->link) {
|
||||
/* add instruction to skip closure and its dependencies if mix weight is zero */
|
||||
svm_nodes.push_back(make_int4(NODE_JUMP_IF_ZERO, 0, facin->stack_offset, 0));
|
||||
svm_nodes.push_back(make_int4(NODE_JUMP_IF_ZERO, 0, stack_assign(facin), 0));
|
||||
int node_jump_skip_index = svm_nodes.size() - 1;
|
||||
|
||||
generate_multi_closure(root_node, cl2in->link->parent, state);
|
||||
|
@@ -95,8 +95,10 @@ public:
|
||||
int index,
|
||||
Summary *summary = NULL);
|
||||
|
||||
void stack_assign(ShaderOutput *output);
|
||||
void stack_assign(ShaderInput *input);
|
||||
int stack_assign(ShaderOutput *output);
|
||||
int stack_assign(ShaderInput *input);
|
||||
int stack_assign_if_linked(ShaderInput *input);
|
||||
int stack_assign_if_linked(ShaderOutput *output);
|
||||
int stack_find_offset(ShaderSocketType type);
|
||||
void stack_clear_offset(ShaderSocketType type, int offset);
|
||||
void stack_link(ShaderInput *input, ShaderOutput *output);
|
||||
|
Reference in New Issue
Block a user