Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/test/render_graph_finalize_test.cpp
| Show First 20 Lines • Show All 955 Lines • ▼ Show 20 Lines | TEST_F(RenderGraph, constant_fold_blackbody) | ||||
| builder.add_node(ShaderNodeBuilder<BlackbodyNode>("Blackbody").set("Temperature", 1200.0f)) | builder.add_node(ShaderNodeBuilder<BlackbodyNode>("Blackbody").set("Temperature", 1200.0f)) | ||||
| .output_color("Blackbody::Color"); | .output_color("Blackbody::Color"); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: Math with all constant inputs (clamp false). | * Tests: Math with all constant inputs. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_math) | TEST_F(RenderGraph, constant_fold_math) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math::Value to constant (1.6)."); | CORRECT_INFO_MESSAGE(log, "Folding Math::Result to constant (1.6)."); | ||||
| builder | builder | ||||
| .add_node(ShaderNodeBuilder<MathNode>("Math") | .add_node(ShaderNodeBuilder<MathNode>("Math") | ||||
| .set(&MathNode::type, NODE_MATH_ADD) | .set(&MathNode::type, NODE_MATH_ADD) | ||||
| .set(&MathNode::use_clamp, false) | .set("A", 0.7f) | ||||
| .set("Value1", 0.7f) | .set("B", 0.9f)) | ||||
| .set("Value2", 0.9f)) | .output_value("Math::Result"); | ||||
| .output_value("Math::Value"); | |||||
| graph.finalize(scene); | |||||
| } | |||||
| /* | |||||
| * Tests: Math with all constant inputs (clamp true). | |||||
| */ | |||||
| TEST_F(RenderGraph, constant_fold_math_clamp) | |||||
| { | |||||
| EXPECT_ANY_MESSAGE(log); | |||||
| CORRECT_INFO_MESSAGE(log, "Folding Math::Value to constant (1)."); | |||||
| builder | |||||
| .add_node(ShaderNodeBuilder<MathNode>("Math") | |||||
| .set(&MathNode::type, NODE_MATH_ADD) | |||||
| .set(&MathNode::use_clamp, true) | |||||
| .set("Value1", 0.7f) | |||||
| .set("Value2", 0.9f)) | |||||
| .output_value("Math::Value"); | |||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Graph for testing partial folds of Math with one constant argument. | * Graph for testing partial folds of Math with one constant argument. | ||||
| * Includes 2 tests: constant on each side. | * Includes 2 tests: constant on each side. | ||||
| */ | */ | ||||
| static void build_math_partial_test_graph(ShaderGraphBuilder &builder, | static void build_math_partial_test_graph(ShaderGraphBuilder &builder, | ||||
| NodeMath type, | NodeMathType type, | ||||
| float constval) | float constval) | ||||
| { | { | ||||
| builder | builder | ||||
| .add_attribute("Attribute") | .add_attribute("Attribute") | ||||
| /* constant on the left */ | /* constant on the left */ | ||||
| .add_node(ShaderNodeBuilder<MathNode>("Math_Cx") | .add_node( | ||||
| .set(&MathNode::type, type) | ShaderNodeBuilder<MathNode>("Math_Cx").set(&MathNode::type, type).set("A", constval)) | ||||
| .set(&MathNode::use_clamp, false) | .add_connection("Attribute::Fac", "Math_Cx::B") | ||||
| .set("Value1", constval)) | |||||
| .add_connection("Attribute::Fac", "Math_Cx::Value2") | |||||
| /* constant on the right */ | /* constant on the right */ | ||||
| .add_node(ShaderNodeBuilder<MathNode>("Math_xC") | .add_node( | ||||
| .set(&MathNode::type, type) | ShaderNodeBuilder<MathNode>("Math_xC").set(&MathNode::type, type).set("B", constval)) | ||||
| .set(&MathNode::use_clamp, false) | .add_connection("Attribute::Fac", "Math_xC::A") | ||||
| .set("Value2", constval)) | |||||
| .add_connection("Attribute::Fac", "Math_xC::Value1") | |||||
| /* output sum */ | /* output sum */ | ||||
| .add_node(ShaderNodeBuilder<MathNode>("Out") | .add_node(ShaderNodeBuilder<MathNode>("Out").set(&MathNode::type, NODE_MATH_ADD)) | ||||
| .set(&MathNode::type, NODE_MATH_ADD) | .add_connection("Math_Cx::Result", "Out::A") | ||||
| .set(&MathNode::use_clamp, true)) | .add_connection("Math_xC::Result", "Out::B") | ||||
| .add_connection("Math_Cx::Value", "Out::Value1") | .output_value("Out::Result"); | ||||
| .add_connection("Math_xC::Value", "Out::Value2") | |||||
| .output_value("Out::Value"); | |||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Add with known 0. | * Tests: partial folding for Math Add with known 0. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_add_0) | TEST_F(RenderGraph, constant_fold_part_math_add_0) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* X + 0 == 0 + X == X */ | /* X + 0 == 0 + X == X */ | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Result to socket Attribute::Fac."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to socket Attribute::Fac."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_ADD, 0.0f); | build_math_partial_test_graph(builder, NODE_MATH_ADD, 0.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Sub with known 0. | * Tests: partial folding for Math Sub with known 0. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_sub_0) | TEST_F(RenderGraph, constant_fold_part_math_sub_0) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* X - 0 == X */ | /* X - 0 == X */ | ||||
| INVALID_INFO_MESSAGE(log, "Folding Math_Cx::"); | INVALID_INFO_MESSAGE(log, "Folding Math_Cx::"); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to socket Attribute::Fac."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_SUBTRACT, 0.0f); | build_math_partial_test_graph(builder, NODE_MATH_SUBTRACT, 0.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Mul with known 1. | * Tests: partial folding for Math Mul with known 1. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_mul_1) | TEST_F(RenderGraph, constant_fold_part_math_mul_1) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* X * 1 == 1 * X == X */ | /* X * 1 == 1 * X == X */ | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Result to socket Attribute::Fac."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to socket Attribute::Fac."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_MULTIPLY, 1.0f); | build_math_partial_test_graph(builder, NODE_MATH_MULTIPLY, 1.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Div with known 1. | * Tests: partial folding for Math Div with known 1. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_div_1) | TEST_F(RenderGraph, constant_fold_part_math_div_1) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* X / 1 == X */ | /* X / 1 == X */ | ||||
| INVALID_INFO_MESSAGE(log, "Folding Math_Cx::"); | INVALID_INFO_MESSAGE(log, "Folding Math_Cx::"); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to socket Attribute::Fac."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_DIVIDE, 1.0f); | build_math_partial_test_graph(builder, NODE_MATH_DIVIDE, 1.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Mul with known 0. | * Tests: partial folding for Math Mul with known 0. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_mul_0) | TEST_F(RenderGraph, constant_fold_part_math_mul_0) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* X * 0 == 0 * X == 0 */ | /* X * 0 == 0 * X == 0 */ | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Value to constant (0)."); | CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Result to constant (0)."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to constant (0)."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to constant (0)."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Out::Value to constant (0)"); | CORRECT_INFO_MESSAGE(log, "Folding Out::Result to constant (0)"); | ||||
| CORRECT_INFO_MESSAGE(log, "Discarding closure EmissionNode."); | CORRECT_INFO_MESSAGE(log, "Discarding closure EmissionNode."); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_MULTIPLY, 0.0f); | build_math_partial_test_graph(builder, NODE_MATH_MULTIPLY, 0.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Div with known 0. | * Tests: partial folding for Math Div with known 0. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_div_0) | TEST_F(RenderGraph, constant_fold_part_math_div_0) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* 0 / X == 0 */ | /* 0 / X == 0 */ | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Value to constant (0)."); | CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Result to constant (0)."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Math_xC::"); | INVALID_INFO_MESSAGE(log, "Folding Math_xC::"); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_DIVIDE, 0.0f); | build_math_partial_test_graph(builder, NODE_MATH_DIVIDE, 0.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Power with known 0. | * Tests: partial folding for Math Power with known 0. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_pow_0) | TEST_F(RenderGraph, constant_fold_part_math_pow_0) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* X ^ 0 == 1 */ | /* X ^ 0 == 1 */ | ||||
| INVALID_INFO_MESSAGE(log, "Folding Math_Cx::"); | INVALID_INFO_MESSAGE(log, "Folding Math_Cx::"); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to constant (1)."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to constant (1)."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_POWER, 0.0f); | build_math_partial_test_graph(builder, NODE_MATH_POWER, 0.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: partial folding for Math Power with known 1. | * Tests: partial folding for Math Power with known 1. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_part_math_pow_1) | TEST_F(RenderGraph, constant_fold_part_math_pow_1) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| /* 1 ^ X == 1; X ^ 1 == X */ | /* 1 ^ X == 1; X ^ 1 == X */ | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Value to constant (1)"); | CORRECT_INFO_MESSAGE(log, "Folding Math_Cx::Result to constant (1)"); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Value to socket Attribute::Fac."); | CORRECT_INFO_MESSAGE(log, "Folding Math_xC::Result to socket Attribute::Fac."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding Out::"); | INVALID_INFO_MESSAGE(log, "Folding Out::"); | ||||
| build_math_partial_test_graph(builder, NODE_MATH_POWER, 1.0f); | build_math_partial_test_graph(builder, NODE_MATH_POWER, 1.0f); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Tests: Vector Math with all constant inputs. | * Tests: Vector Math with all constant inputs. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_vector_math) | TEST_F(RenderGraph, constant_fold_vector_math) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding VectorMath::Value to constant (1)."); | CORRECT_INFO_MESSAGE(log, "Folding VectorMath::Value to constant (1)."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding VectorMath::Vector to constant (3, 0, 0)."); | CORRECT_INFO_MESSAGE(log, "Folding VectorMath::Vector to constant (3, 0, 0)."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding convert_vector_to_float::value_float to constant (1)."); | CORRECT_INFO_MESSAGE(log, "Folding convert_vector_to_float::value_float to constant (1)."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding Math::Value to constant (2)."); | CORRECT_INFO_MESSAGE(log, "Folding Math::Result to constant (2)."); | ||||
| CORRECT_INFO_MESSAGE(log, "Folding convert_float_to_color::value_color to constant (2, 2, 2)."); | CORRECT_INFO_MESSAGE(log, "Folding convert_float_to_color::value_color to constant (2, 2, 2)."); | ||||
| builder | builder | ||||
| .add_node(ShaderNodeBuilder<VectorMathNode>("VectorMath") | .add_node(ShaderNodeBuilder<VectorMathNode>("VectorMath") | ||||
| .set(&VectorMathNode::type, NODE_VECTOR_MATH_SUBTRACT) | .set(&VectorMathNode::type, NODE_VECTOR_MATH_SUBTRACT) | ||||
| .set("Vector1", make_float3(1.3f, 0.5f, 0.7f)) | .set("Vector1", make_float3(1.3f, 0.5f, 0.7f)) | ||||
| .set("Vector2", make_float3(-1.7f, 0.5f, 0.7f))) | .set("Vector2", make_float3(-1.7f, 0.5f, 0.7f))) | ||||
| .add_node(ShaderNodeBuilder<MathNode>("Math").set(&MathNode::type, NODE_MATH_ADD)) | .add_node(ShaderNodeBuilder<MathNode>("Math").set(&MathNode::type, NODE_MATH_ADD)) | ||||
| .add_connection("VectorMath::Vector", "Math::Value1") | .add_connection("VectorMath::Vector", "Math::A") | ||||
| .add_connection("VectorMath::Value", "Math::Value2") | .add_connection("VectorMath::Value", "Math::B") | ||||
| .output_color("Math::Value"); | .output_color("Math::Result"); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| /* | /* | ||||
| * Graph for testing partial folds of Vector Math with one constant argument. | * Graph for testing partial folds of Vector Math with one constant argument. | ||||
| * Includes 2 tests: constant on each side. | * Includes 2 tests: constant on each side. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 344 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * Tests: | * Tests: | ||||
| * - NOT folding conversion of color to float to color. | * - NOT folding conversion of color to float to color. | ||||
| */ | */ | ||||
| TEST_F(RenderGraph, constant_fold_convert_color_float_color) | TEST_F(RenderGraph, constant_fold_convert_color_float_color) | ||||
| { | { | ||||
| EXPECT_ANY_MESSAGE(log); | EXPECT_ANY_MESSAGE(log); | ||||
| CORRECT_INFO_MESSAGE(log, | CORRECT_INFO_MESSAGE(log, | ||||
| "Folding MathAdd::Value to socket convert_color_to_float::value_float."); | "Folding MathAdd::Result to socket convert_color_to_float::value_float."); | ||||
| INVALID_INFO_MESSAGE(log, "Folding convert_float_to_color::"); | INVALID_INFO_MESSAGE(log, "Folding convert_float_to_color::"); | ||||
| builder.add_attribute("Attribute") | builder.add_attribute("Attribute") | ||||
| .add_node(ShaderNodeBuilder<MathNode>("MathAdd") | .add_node(ShaderNodeBuilder<MathNode>("MathAdd") | ||||
| .set(&MathNode::type, NODE_MATH_ADD) | .set(&MathNode::type, NODE_MATH_ADD) | ||||
| .set("Value2", 0.0f)) | .set("B", 0.0f)) | ||||
| .add_connection("Attribute::Color", "MathAdd::Value1") | .add_connection("Attribute::Color", "MathAdd::A") | ||||
| .output_color("MathAdd::Value"); | .output_color("MathAdd::Result"); | ||||
| graph.finalize(scene); | graph.finalize(scene); | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||