diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cdba309c50..f188da1488 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -741,7 +741,7 @@ if(${TINT_BUILD_TESTS}) ) endif() - if(${TINT_BUILD_SPV_READER}) + if(${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_WGSL_WRITER}) list(APPEND TINT_TEST_SRCS reader/spirv/enum_converter_test.cc reader/spirv/fail_stream_test.cc diff --git a/src/reader/spirv/function_arithmetic_test.cc b/src/reader/spirv/function_arithmetic_test.cc index 9788a5ce56..193c885be8 100644 --- a/src/reader/spirv/function_arithmetic_test.cc +++ b/src/reader/spirv/function_arithmetic_test.cc @@ -77,64 +77,28 @@ std::string Preamble() { // Returns the AST dump for a given SPIR-V assembly constant. std::string AstFor(std::string assembly) { if (assembly == "v2uint_10_20") { - return R"(TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - })"; + return "vec2(10u, 20u)"; } if (assembly == "v2uint_20_10") { - return R"(TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - })"; + return "vec2(20u, 10u)"; } if (assembly == "v2int_30_40") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - })"; + return "vec2(30, 40)"; } if (assembly == "v2int_40_30") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - })"; + return "vec2(40, 30)"; } if (assembly == "cast_int_v2uint_10_20") { - return R"(Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - })"; + return "bitcast>(vec2(10u, 20u))"; } if (assembly == "cast_uint_v2int_40_30") { - return R"(Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - })"; + return "bitcast>(vec2(40, 30))"; } if (assembly == "v2float_50_60") { - return R"(TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - })"; + return "vec2(50.0, 60.0)"; } if (assembly == "v2float_60_50") { - return R"(TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - })"; + return "vec2(60.0, 50.0)"; } return "bad case"; } @@ -155,19 +119,9 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - UnaryOp[not set]{ - negation - ScalarConstructor[not set]{30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : i32 = -(30);")); } TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { @@ -184,21 +138,9 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - UnaryOp[not set]{ - negation - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : i32 = -(bitcast(10u));")); } TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { @@ -215,21 +157,9 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - UnaryOp[not set]{ - negation - ScalarConstructor[not set]{30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = bitcast(-(30));")); } TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { @@ -246,23 +176,9 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - UnaryOp[not set]{ - negation - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = bitcast(-(bitcast(10u)));")); } TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) { @@ -279,23 +195,9 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - UnaryOp[not set]{ - negation - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = -(vec2(30, 40));")); } TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { @@ -312,25 +214,11 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - UnaryOp[not set]{ - negation - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + "let x_1 : vec2 = -(bitcast>(vec2(10u, 20u)));")); } TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { @@ -347,25 +235,11 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - UnaryOp[not set]{ - negation - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + "let x_1 : vec2 = bitcast>(-(vec2(30, 40)));")); } TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { @@ -382,27 +256,11 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - UnaryOp[not set]{ - negation - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + R"(let x_1 : vec2 = bitcast>(-(bitcast>(vec2(10u, 20u))));)")); } TEST_F(SpvUnaryArithTest, FNegate_Scalar) { @@ -419,19 +277,9 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - UnaryOp[not set]{ - negation - ScalarConstructor[not set]{50.000000} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = -(50.0);")); } TEST_F(SpvUnaryArithTest, FNegate_Vector) { @@ -448,23 +296,9 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - UnaryOp[not set]{ - negation - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = -(vec2(50.0, 60.0));")); } struct BinaryData { @@ -505,15 +339,10 @@ TEST_P(SpvBinaryArithTest, EmitExpression) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); std::ostringstream ss; - ss << R"(VariableConst{ - x_1 - none - undefined - )" - << GetParam().ast_type << "\n {\n Binary[not set]{" - << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op - << "\n " << GetParam().ast_rhs; - auto got = ToString(p->builder(), fe.ast_body()); + ss << "let x_1 : " << GetParam().ast_type << " = (" << GetParam().ast_lhs + << " " << GetParam().ast_op << " " << GetParam().ast_rhs << ");"; + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); EXPECT_THAT(got, HasSubstr(ss.str())) << "got:\n" << got << assembly; } @@ -523,11 +352,13 @@ struct BinaryDataGeneral { const std::string lhs; const std::string op; const std::string rhs; + const std::string wgsl_type; const std::string expected; }; inline std::ostream& operator<<(std::ostream& out, BinaryDataGeneral data) { out << "BinaryDataGeneral{" << data.res_type << "," << data.lhs << "," - << data.op << "," << data.rhs << "," << data.expected << "}"; + << data.op << "," << data.rhs << "," << data.wgsl_type << "," + << data.expected << "}"; return out; } @@ -551,13 +382,10 @@ TEST_P(SpvBinaryArithGeneralTest, EmitExpression) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); std::ostringstream ss; - ss << R"(VariableConst{ - x_1 - none - undefined - )" - << GetParam().expected; - auto got = ToString(p->builder(), fe.ast_body()); + ss << "let x_1 : " << GetParam().wgsl_type << " = " << GetParam().expected + << ";"; + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); EXPECT_THAT(got, HasSubstr(ss.str())) << "got:\n" << got << assembly; } @@ -566,132 +394,51 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpIAdd", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "add", - "ScalarConstructor[not set]{20u}"}, - // Both int - BinaryData{"int", "int_30", "OpIAdd", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "add", - "ScalarConstructor[not set]{40}"}, - // Both v2uint + BinaryData{"uint", "uint_10", "OpIAdd", "uint_20", "u32", "10u", "+", + "20u"}, // Both int + BinaryData{"int", "int_30", "OpIAdd", "int_40", "i32", "30", "+", + "40"}, // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpIAdd", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "add", + "vec2", AstFor("v2uint_10_20"), "+", AstFor("v2uint_20_10")}, // Both v2int - BinaryData{"v2int", "v2int_30_40", "OpIAdd", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "add", - AstFor("v2int_40_30")})); + BinaryData{"v2int", "v2int_30_40", "OpIAdd", "v2int_40_30", "vec2", + AstFor("v2int_30_40"), "+", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_IAdd_MixedSignedness, SpvBinaryArithGeneralTest, ::testing::Values( // Mixed, uint <- int uint - BinaryDataGeneral{"uint", "int_30", "OpIAdd", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - add - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })"}, + BinaryDataGeneral{"uint", "int_30", "OpIAdd", "uint_10", "u32", + "bitcast((30 + bitcast(10u)))"}, // Mixed, int <- int uint - BinaryDataGeneral{"int", "int_30", "OpIAdd", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - add - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "int_30", "OpIAdd", "uint_10", "i32", + "(30 + bitcast(10u))"}, // Mixed, uint <- uint int - BinaryDataGeneral{"uint", "uint_10", "OpIAdd", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - add - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - })"}, + BinaryDataGeneral{"uint", "uint_10", "OpIAdd", "int_30", "u32", + "(10u + bitcast(30))"}, // Mixed, int <- uint uint - BinaryDataGeneral{"int", "uint_20", "OpIAdd", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - add - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "uint_20", "OpIAdd", "uint_10", "i32", + "bitcast((20u + 10u))"}, // Mixed, returning v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpIAdd", "v2uint_10_20", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - add - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })"}, + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpIAdd", "v2uint_10_20", "vec2", + R"(bitcast>((vec2(30, 40) + bitcast>(vec2(10u, 20u)))))"}, // Mixed, returning v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpIAdd", "v2int_40_30", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - add - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpIAdd", "v2int_40_30", "vec2", + R"(bitcast>((vec2(10u, 20u) + bitcast>(vec2(40, 30)))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FAdd, SpvBinaryArithTest, ::testing::Values( // Scalar float - BinaryData{"float", "float_50", "OpFAdd", "float_60", "__f32", - "ScalarConstructor[not set]{50.000000}", "add", - "ScalarConstructor[not set]{60.000000}"}, - // Vector float + BinaryData{"float", "float_50", "OpFAdd", "float_60", "f32", "50.0", + "+", "60.0"}, // Vector float BinaryData{"v2float", "v2float_50_60", "OpFAdd", "v2float_60_50", - "__vec_2__f32", AstFor("v2float_50_60"), "add", + "vec2", AstFor("v2float_50_60"), "+", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( @@ -699,132 +446,51 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpISub", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "subtract", - "ScalarConstructor[not set]{20u}"}, - // Both int - BinaryData{"int", "int_30", "OpISub", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "subtract", - "ScalarConstructor[not set]{40}"}, - // Both v2uint + BinaryData{"uint", "uint_10", "OpISub", "uint_20", "u32", "10u", "-", + "20u"}, // Both int + BinaryData{"int", "int_30", "OpISub", "int_40", "i32", "30", "-", + "40"}, // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpISub", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "subtract", + "vec2", AstFor("v2uint_10_20"), "-", AstFor("v2uint_20_10")}, // Both v2int - BinaryData{"v2int", "v2int_30_40", "OpISub", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "subtract", - AstFor("v2int_40_30")})); + BinaryData{"v2int", "v2int_30_40", "OpISub", "v2int_40_30", "vec2", + AstFor("v2int_30_40"), "-", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ISub_MixedSignedness, SpvBinaryArithGeneralTest, ::testing::Values( // Mixed, uint <- int uint - BinaryDataGeneral{"uint", "int_30", "OpISub", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - subtract - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })"}, + BinaryDataGeneral{"uint", "int_30", "OpISub", "uint_10", "u32", + R"(bitcast((30 - bitcast(10u))))"}, // Mixed, int <- int uint - BinaryDataGeneral{"int", "int_30", "OpISub", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - subtract - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "int_30", "OpISub", "uint_10", "i32", + "(30 - bitcast(10u))"}, // Mixed, uint <- uint int - BinaryDataGeneral{"uint", "uint_10", "OpISub", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - subtract - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - })"}, + BinaryDataGeneral{"uint", "uint_10", "OpISub", "int_30", "u32", + "(10u - bitcast(30))"}, // Mixed, int <- uint uint - BinaryDataGeneral{"int", "uint_20", "OpISub", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - subtract - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "uint_20", "OpISub", "uint_10", "i32", + "bitcast((20u - 10u))"}, // Mixed, returning v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpISub", "v2uint_10_20", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - subtract - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })"}, + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpISub", "v2uint_10_20", "vec2", + R"(bitcast>((vec2(30, 40) - bitcast>(vec2(10u, 20u)))))"}, // Mixed, returning v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpISub", "v2int_40_30", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - subtract - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpISub", "v2int_40_30", "vec2", + R"(bitcast>((vec2(10u, 20u) - bitcast>(vec2(40, 30)))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FSub, SpvBinaryArithTest, ::testing::Values( // Scalar float - BinaryData{"float", "float_50", "OpFSub", "float_60", "__f32", - "ScalarConstructor[not set]{50.000000}", "subtract", - "ScalarConstructor[not set]{60.000000}"}, - // Vector float + BinaryData{"float", "float_50", "OpFSub", "float_60", "f32", "50.0", + "-", "60.0"}, // Vector float BinaryData{"v2float", "v2float_50_60", "OpFSub", "v2float_60_50", - "__vec_2__f32", AstFor("v2float_50_60"), "subtract", + "vec2", AstFor("v2float_50_60"), "-", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( @@ -832,132 +498,51 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpIMul", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "multiply", - "ScalarConstructor[not set]{20u}"}, - // Both int - BinaryData{"int", "int_30", "OpIMul", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "multiply", - "ScalarConstructor[not set]{40}"}, - // Both v2uint + BinaryData{"uint", "uint_10", "OpIMul", "uint_20", "u32", "10u", "*", + "20u"}, // Both int + BinaryData{"int", "int_30", "OpIMul", "int_40", "i32", "30", "*", + "40"}, // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpIMul", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "multiply", + "vec2", AstFor("v2uint_10_20"), "*", AstFor("v2uint_20_10")}, // Both v2int - BinaryData{"v2int", "v2int_30_40", "OpIMul", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "multiply", - AstFor("v2int_40_30")})); + BinaryData{"v2int", "v2int_30_40", "OpIMul", "v2int_40_30", "vec2", + AstFor("v2int_30_40"), "*", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_IMul_MixedSignedness, SpvBinaryArithGeneralTest, ::testing::Values( // Mixed, uint <- int uint - BinaryDataGeneral{"uint", "int_30", "OpIMul", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - multiply - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })"}, + BinaryDataGeneral{"uint", "int_30", "OpIMul", "uint_10", "u32", + "bitcast((30 * bitcast(10u)))"}, // Mixed, int <- int uint - BinaryDataGeneral{"int", "int_30", "OpIMul", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - multiply - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "int_30", "OpIMul", "uint_10", "i32", + "(30 * bitcast(10u))"}, // Mixed, uint <- uint int - BinaryDataGeneral{"uint", "uint_10", "OpIMul", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - multiply - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - })"}, + BinaryDataGeneral{"uint", "uint_10", "OpIMul", "int_30", "u32", + "(10u * bitcast(30))"}, // Mixed, int <- uint uint - BinaryDataGeneral{"int", "uint_20", "OpIMul", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - multiply - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "uint_20", "OpIMul", "uint_10", "i32", + "bitcast((20u * 10u))"}, // Mixed, returning v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpIMul", "v2uint_10_20", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - multiply - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })"}, + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpIMul", "v2uint_10_20", "vec2", + R"(bitcast>((vec2(30, 40) * bitcast>(vec2(10u, 20u)))))"}, // Mixed, returning v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpIMul", "v2int_40_30", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - multiply - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpIMul", "v2int_40_30", "vec2", + R"(bitcast>((vec2(10u, 20u) * bitcast>(vec2(40, 30)))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FMul, SpvBinaryArithTest, ::testing::Values( // Scalar float - BinaryData{"float", "float_50", "OpFMul", "float_60", "__f32", - "ScalarConstructor[not set]{50.000000}", "multiply", - "ScalarConstructor[not set]{60.000000}"}, - // Vector float + BinaryData{"float", "float_50", "OpFMul", "float_60", "f32", "50.0", + "*", "60.0"}, // Vector float BinaryData{"v2float", "v2float_50_60", "OpFMul", "v2float_60_50", - "__vec_2__f32", AstFor("v2float_50_60"), "multiply", + "vec2", AstFor("v2float_50_60"), "*", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( @@ -965,12 +550,10 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpUDiv", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "divide", - "ScalarConstructor[not set]{20u}"}, - // Both v2uint + BinaryData{"uint", "uint_10", "OpUDiv", "uint_20", "u32", "10u", "/", + "20u"}, // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpUDiv", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "divide", + "vec2", AstFor("v2uint_10_20"), "/", AstFor("v2uint_20_10")})); INSTANTIATE_TEST_SUITE_P( @@ -978,37 +561,28 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both int - BinaryData{"int", "int_30", "OpSDiv", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "divide", - "ScalarConstructor[not set]{40}"}, - // Both v2int - BinaryData{"v2int", "v2int_30_40", "OpSDiv", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "divide", - AstFor("v2int_40_30")})); + BinaryData{"int", "int_30", "OpSDiv", "int_40", "i32", "30", "/", + "40"}, // Both v2int + BinaryData{"v2int", "v2int_30_40", "OpSDiv", "v2int_40_30", "vec2", + AstFor("v2int_30_40"), "/", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_SDiv_MixedSignednessOperands, SpvBinaryArithTest, ::testing::Values( // Mixed, returning int, second arg uint - BinaryData{"int", "int_30", "OpSDiv", "uint_10", "__i32", - "ScalarConstructor[not set]{30}", "divide", - R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })"}, + BinaryData{"int", "int_30", "OpSDiv", "uint_10", "i32", "30", "/", + "bitcast(10u)"}, // Mixed, returning int, first arg uint - BinaryData{"int", "uint_10", "OpSDiv", "int_30", "__i32", - R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })", - "divide", "ScalarConstructor[not set]{30}"}, - // Mixed, returning v2int, first arg v2uint + BinaryData{"int", "uint_10", "OpSDiv", "int_30", "i32", + "bitcast(10u)", "/", + "30"}, // Mixed, returning v2int, first arg v2uint BinaryData{"v2int", "v2uint_10_20", "OpSDiv", "v2int_30_40", - "__vec_2__i32", AstFor("cast_int_v2uint_10_20"), "divide", + "vec2", AstFor("cast_int_v2uint_10_20"), "/", AstFor("v2int_30_40")}, // Mixed, returning v2int, second arg v2uint BinaryData{"v2int", "v2int_30_40", "OpSDiv", "v2uint_10_20", - "__vec_2__i32", AstFor("v2int_30_40"), "divide", + "vec2", AstFor("v2int_30_40"), "/", AstFor("cast_int_v2uint_10_20")})); TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) { @@ -1029,22 +603,9 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - divide - ScalarConstructor[not set]{40} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = bitcast((30 / 40));")); } TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) { @@ -1065,30 +626,11 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - divide - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + R"(let x_1 : vec2 = bitcast>((vec2(30, 40) / vec2(40, 30)));)")); } INSTANTIATE_TEST_SUITE_P( @@ -1096,12 +638,10 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Scalar float - BinaryData{"float", "float_50", "OpFDiv", "float_60", "__f32", - "ScalarConstructor[not set]{50.000000}", "divide", - "ScalarConstructor[not set]{60.000000}"}, - // Vector float + BinaryData{"float", "float_50", "OpFDiv", "float_60", "f32", "50.0", + "/", "60.0"}, // Vector float BinaryData{"v2float", "v2float_50_60", "OpFDiv", "v2float_60_50", - "__vec_2__f32", AstFor("v2float_50_60"), "divide", + "vec2", AstFor("v2float_50_60"), "/", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( @@ -1109,12 +649,10 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpUMod", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "modulo", - "ScalarConstructor[not set]{20u}"}, - // Both v2uint + BinaryData{"uint", "uint_10", "OpUMod", "uint_20", "u32", "10u", "%", + "20u"}, // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpUMod", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "modulo", + "vec2", AstFor("v2uint_10_20"), "%", AstFor("v2uint_20_10")})); // Currently WGSL is missing a mapping for OpSRem @@ -1125,37 +663,28 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Both int - BinaryData{"int", "int_30", "OpSMod", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "modulo", - "ScalarConstructor[not set]{40}"}, - // Both v2int - BinaryData{"v2int", "v2int_30_40", "OpSMod", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "modulo", - AstFor("v2int_40_30")})); + BinaryData{"int", "int_30", "OpSMod", "int_40", "i32", "30", "%", + "40"}, // Both v2int + BinaryData{"v2int", "v2int_30_40", "OpSMod", "v2int_40_30", "vec2", + AstFor("v2int_30_40"), "%", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_SMod_MixedSignednessOperands, SpvBinaryArithTest, ::testing::Values( // Mixed, returning int, second arg uint - BinaryData{"int", "int_30", "OpSMod", "uint_10", "__i32", - "ScalarConstructor[not set]{30}", "modulo", - R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })"}, + BinaryData{"int", "int_30", "OpSMod", "uint_10", "i32", "30", "%", + "bitcast(10u)"}, // Mixed, returning int, first arg uint - BinaryData{"int", "uint_10", "OpSMod", "int_30", "__i32", - R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })", - "modulo", "ScalarConstructor[not set]{30}"}, - // Mixed, returning v2int, first arg v2uint + BinaryData{"int", "uint_10", "OpSMod", "int_30", "i32", + "bitcast(10u)", "%", + "30"}, // Mixed, returning v2int, first arg v2uint BinaryData{"v2int", "v2uint_10_20", "OpSMod", "v2int_30_40", - "__vec_2__i32", AstFor("cast_int_v2uint_10_20"), "modulo", + "vec2", AstFor("cast_int_v2uint_10_20"), "%", AstFor("v2int_30_40")}, // Mixed, returning v2int, second arg v2uint BinaryData{"v2int", "v2int_30_40", "OpSMod", "v2uint_10_20", - "__vec_2__i32", AstFor("v2int_30_40"), "modulo", + "vec2", AstFor("v2int_30_40"), "%", AstFor("cast_int_v2uint_10_20")})); TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) { @@ -1176,22 +705,9 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - modulo - ScalarConstructor[not set]{40} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = bitcast((30 % 40));")); } TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) { @@ -1212,30 +728,11 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - modulo - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + R"(let x_1 : vec2 = bitcast>((vec2(30, 40) % vec2(40, 30)));)")); } INSTANTIATE_TEST_SUITE_P( @@ -1243,12 +740,10 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryArithTest, ::testing::Values( // Scalar float - BinaryData{"float", "float_50", "OpFRem", "float_60", "__f32", - "ScalarConstructor[not set]{50.000000}", "modulo", - "ScalarConstructor[not set]{60.000000}"}, - // Vector float + BinaryData{"float", "float_50", "OpFRem", "float_60", "f32", "50.0", + "%", "60.0"}, // Vector float BinaryData{"v2float", "v2float_50_60", "OpFRem", "v2float_60_50", - "__vec_2__f32", AstFor("v2float_50_60"), "modulo", + "vec2", AstFor("v2float_50_60"), "%", AstFor("v2float_60_50")})); TEST_F(SpvBinaryArithTestBasic, FMod_Scalar) { @@ -1265,33 +760,10 @@ TEST_F(SpvBinaryArithTestBasic, FMod_Scalar) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - subtract - Binary[not set]{ - ScalarConstructor[not set]{60.000000} - multiply - Call[not set]{ - Identifier[not set]{floor} - ( - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - divide - ScalarConstructor[not set]{60.000000} - } - ) - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = (50.0 - (60.0 * floor((50.0 / 60.0))));")); } TEST_F(SpvBinaryArithTestBasic, FMod_Vector) { @@ -1308,49 +780,11 @@ TEST_F(SpvBinaryArithTestBasic, FMod_Vector) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - subtract - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - multiply - Call[not set]{ - Identifier[not set]{floor} - ( - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - divide - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - ) - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + R"(let x_1 : vec2 = (vec2(50.0, 60.0) - (vec2(60.0, 50.0) * floor((vec2(50.0, 60.0) / vec2(60.0, 50.0)))));)")); } TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) { @@ -1368,19 +802,9 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __vec_2__f32 - { - Binary[not set]{ - Identifier[not set]{x_1} - multiply - Identifier[not set]{x_2} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : vec2 = (x_1 * x_2);")); } TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) { @@ -1398,19 +822,9 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __mat_2_2__f32 - { - Binary[not set]{ - Identifier[not set]{x_1} - multiply - Identifier[not set]{x_2} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : mat2x2 = (x_1 * x_2);")); } TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) { @@ -1428,19 +842,9 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __vec_2__f32 - { - Binary[not set]{ - Identifier[not set]{x_1} - multiply - Identifier[not set]{x_2} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : vec2 = (x_1 * x_2);")); } TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) { @@ -1458,19 +862,9 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __vec_2__f32 - { - Binary[not set]{ - Identifier[not set]{x_1} - multiply - Identifier[not set]{x_2} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : vec2 = (x_1 * x_2);")); } TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) { @@ -1488,19 +882,9 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __mat_2_2__f32 - { - Binary[not set]{ - Identifier[not set]{x_1} - multiply - Identifier[not set]{x_2} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : mat2x2 = (x_1 * x_2);")); } TEST_F(SpvBinaryArithTestBasic, Dot) { @@ -1518,21 +902,9 @@ TEST_F(SpvBinaryArithTestBasic, Dot) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_3 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{dot} - ( - Identifier[not set]{x_1} - Identifier[not set]{x_2} - ) - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_3 : f32 = dot(x_1, x_2);")); } TEST_F(SpvBinaryArithTestBasic, OuterProduct) { @@ -1552,90 +924,14 @@ TEST_F(SpvBinaryArithTestBasic, OuterProduct) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(VariableConst{ - x_3 - none - undefined - __mat_3_2__f32 - { - TypeConstructor[not set]{ - __mat_3_2__f32 - TypeConstructor[not set]{ - __vec_3__f32 - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{x} - } - multiply - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{x} - } - } - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{x} - } - multiply - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{y} - } - } - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{x} - } - multiply - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{z} - } - } - } - TypeConstructor[not set]{ - __vec_3__f32 - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{y} - } - multiply - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{x} - } - } - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{y} - } - multiply - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{y} - } - } - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{y} - } - multiply - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{z} - } - } - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT( + got, + HasSubstr( + "let x_3 : mat2x3 = mat2x3(" + "vec3((x_2.x * x_1.x), (x_2.x * x_1.y), (x_2.x * x_1.z)), " + "vec3((x_2.y * x_1.x), (x_2.y * x_1.y), (x_2.y * x_1.z)));")) << got; } @@ -1682,20 +978,10 @@ TEST_P(SpvBinaryDerivativeTest, Derivatives) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_2 - none - undefined - )" + arg.ast_type + R"( - { - Call[not set]{ - Identifier[not set]{)" + intrinsic.wgsl + R"(} - ( - Identifier[not set]{x_1} - ) - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : " + arg.ast_type + " = " + intrinsic.wgsl + + "(x_1);")); } INSTANTIATE_TEST_SUITE_P( @@ -1712,9 +998,9 @@ INSTANTIATE_TEST_SUITE_P( IntrinsicData{"OpDPdyCoarse", "dpdyCoarse"}, IntrinsicData{"OpFwidthCoarse", "fwidthCoarse"}), ::testing::Values( - ArgAndTypeData{"float", "float_50", "__f32"}, - ArgAndTypeData{"v2float", "v2float_50_60", "__vec_2__f32"}, - ArgAndTypeData{"v3float", "v3float_50_60_70", "__vec_3__f32"}))); + ArgAndTypeData{"float", "float_50", "f32"}, + ArgAndTypeData{"v2float", "v2float_50_60", "vec2"}, + ArgAndTypeData{"v3float", "v3float_50_60_70", "vec3"}))); TEST_F(SpvUnaryArithTest, Transpose_2x2) { const auto assembly = Preamble() + R"( @@ -1731,24 +1017,9 @@ TEST_F(SpvUnaryArithTest, Transpose_2x2) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto* expected = R"( -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __mat_2_2__f32 - { - Call[not set]{ - Identifier[not set]{transpose} - ( - Identifier[not set]{x_1} - ) - } - } - } -})"; - const auto got = ToString(p->builder(), fe.ast_body()); + const auto* expected = "let x_2 : mat2x2 = transpose(x_1);"; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -1769,25 +1040,10 @@ TEST_F(SpvUnaryArithTest, Transpose_2x3) { EXPECT_TRUE(fe.EmitBody()) << p->error(); // Note, in the AST dump mat_2_3 means 2 rows and 3 columns. // So the column vectors have 2 elements. - // That is, %m3v2float is __mat_2_3__f32. - const auto* expected = R"( -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __mat_2_3__f32 - { - Call[not set]{ - Identifier[not set]{transpose} - ( - Identifier[not set]{x_1} - ) - } - } - } -})"; - const auto got = ToString(p->builder(), fe.ast_body()); + // That is, %m3v2float is __mat_2_3f32. + const auto* expected = "let x_2 : mat3x2 = transpose(x_1);"; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -1806,24 +1062,9 @@ TEST_F(SpvUnaryArithTest, Transpose_3x2) { << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto* expected = R"( -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __mat_3_2__f32 - { - Call[not set]{ - Identifier[not set]{transpose} - ( - Identifier[not set]{x_1} - ) - } - } - } -})"; - const auto got = ToString(p->builder(), fe.ast_body()); + const auto* expected = "let x_2 : mat2x3 = transpose(x_1);"; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); EXPECT_THAT(got, HasSubstr(expected)) << got; } diff --git a/src/reader/spirv/function_bit_test.cc b/src/reader/spirv/function_bit_test.cc index b8bccf33a1..d7cae0b994 100644 --- a/src/reader/spirv/function_bit_test.cc +++ b/src/reader/spirv/function_bit_test.cc @@ -68,55 +68,25 @@ std::string SimplePreamble() { // Returns the AST dump for a given SPIR-V assembly constant. std::string AstFor(std::string assembly) { if (assembly == "v2uint_10_20") { - return R"(TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - })"; + return "vec2(10u, 20u)"; } if (assembly == "v2uint_20_10") { - return R"(TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - })"; + return "vec2(20u, 10u)"; } if (assembly == "v2int_30_40") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - })"; + return "vec2(30, 40)"; } if (assembly == "v2int_40_30") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - })"; + return "vec2(40, 30)"; } if (assembly == "cast_int_v2uint_10_20") { - return R"(Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - })"; + return "bitcast(vec2(10u, 20u))"; } if (assembly == "v2float_50_60") { - return R"(TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - })"; + return "vec2(50.0, 60.0))"; } if (assembly == "v2float_60_50") { - return R"(TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - })"; + return "vec2(60.0, 50.0))"; } return "bad case"; } @@ -161,15 +131,10 @@ TEST_P(SpvBinaryBitTest, EmitExpression) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); std::ostringstream ss; - ss << R"(VariableConst{ - x_1 - none - undefined - )" - << GetParam().ast_type << "\n {\n Binary[not set]{" - << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op - << "\n " << GetParam().ast_rhs; - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(ss.str())) + ss << "let x_1 : " << GetParam().ast_type << " = (" << GetParam().ast_lhs + << " " << GetParam().ast_op << " " << GetParam().ast_rhs << ");"; + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(ss.str())) << assembly; } @@ -179,11 +144,13 @@ struct BinaryDataGeneral { const std::string lhs; const std::string op; const std::string rhs; + const std::string wgsl_type; const std::string expected; }; inline std::ostream& operator<<(std::ostream& out, BinaryDataGeneral data) { out << "BinaryDataGeneral{" << data.res_type << "," << data.lhs << "," - << data.op << "," << data.rhs << "," << data.expected << "}"; + << data.op << "," << data.rhs << "," << data.wgsl_type << "," + << data.expected << "}"; return out; } @@ -207,13 +174,10 @@ TEST_P(SpvBinaryBitGeneralTest, EmitExpression) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error() << assembly; std::ostringstream ss; - ss << R"(VariableConst{ - x_1 - none - undefined - )" - << GetParam().expected; - auto got = ToString(p->builder(), fe.ast_body()); + ss << "let x_1 : " << GetParam().wgsl_type << " = " << GetParam().expected + << ";\nreturn;\n"; + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); EXPECT_THAT(got, HasSubstr(ss.str())) << "got:\n" << got << assembly; } @@ -222,20 +186,18 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryBitTest, ::testing::Values( // uint uint -> uint - BinaryData{"uint", "uint_10", "OpShiftLeftLogical", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "shift_left", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"uint", "uint_10", "OpShiftLeftLogical", "uint_20", "u32", + "10u", "<<", "20u"}, // int, uint -> int - BinaryData{"int", "int_30", "OpShiftLeftLogical", "uint_20", "__i32", - "ScalarConstructor[not set]{30}", "shift_left", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"int", "int_30", "OpShiftLeftLogical", "uint_20", "i32", + "30", "<<", "20u"}, // v2uint v2uint -> v2uint BinaryData{"v2uint", "v2uint_10_20", "OpShiftLeftLogical", - "v2uint_20_10", "__vec_2__u32", AstFor("v2uint_10_20"), - "shift_left", AstFor("v2uint_20_10")}, + "v2uint_20_10", "vec2", AstFor("v2uint_10_20"), "<<", + AstFor("v2uint_20_10")}, // v2int, v2uint -> v2int BinaryData{"v2int", "v2int_30_40", "OpShiftLeftLogical", "v2uint_20_10", - "__vec_2__i32", AstFor("v2int_30_40"), "shift_left", + "vec2", AstFor("v2int_30_40"), "<<", AstFor("v2uint_20_10")})); INSTANTIATE_TEST_SUITE_P( @@ -245,72 +207,19 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // int, int -> int BinaryDataGeneral{"int", "int_30", "OpShiftLeftLogical", "int_40", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - shift_left - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - } - } - } -)"}, + "i32", "(30 << bitcast(40))"}, // uint, int -> uint BinaryDataGeneral{"uint", "uint_10", "OpShiftLeftLogical", "int_40", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - shift_left - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - } - } - } -)"}, + "u32", "(10u << bitcast(40))"}, // v2uint, v2int -> v2uint BinaryDataGeneral{"v2uint", "v2uint_10_20", "OpShiftLeftLogical", - "v2uint_20_10", - R"(__vec_2__u32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - shift_left - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } -)"}, + "v2uint_20_10", "vec2", + "(vec2(10u, 20u) << vec2(20u, 10u))"}, // v2int, v2int -> v2int - BinaryDataGeneral{"v2int", "v2int_30_40", "OpShiftLeftLogical", - "v2int_40_30", - R"(__vec_2__i32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - shift_left - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2int", "v2int_30_40", "OpShiftLeftLogical", "v2int_40_30", + "vec2", + "(vec2(30, 40) << bitcast>(vec2(40, 30)))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftLeftLogical_BitcastResult, @@ -318,39 +227,12 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // int, int -> uint BinaryDataGeneral{"uint", "int_30", "OpShiftLeftLogical", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - shift_left - ScalarConstructor[not set]{10u} - } - } - } -)"}, + "u32", "bitcast((30 << 10u))"}, // v2uint, v2int -> v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpShiftLeftLogical", - "v2uint_20_10", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - shift_left - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpShiftLeftLogical", "v2uint_20_10", + "vec2", + "bitcast>((vec2(30, 40) << vec2(20u, 10u)))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftRightLogical_Arg2Unsigned, @@ -358,74 +240,19 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // uint, uint -> uint BinaryDataGeneral{"uint", "uint_10", "OpShiftRightLogical", "uint_20", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - shift_right - ScalarConstructor[not set]{20u} - } - } -)"}, + "u32", "(10u >> 20u)"}, // int, uint -> int BinaryDataGeneral{"int", "int_30", "OpShiftRightLogical", "uint_20", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - shift_right - ScalarConstructor[not set]{20u} - } - } - } -)"}, + "i32", "bitcast((bitcast(30) >> 20u))"}, // v2uint, v2uint -> v2uint BinaryDataGeneral{"v2uint", "v2uint_10_20", "OpShiftRightLogical", - "v2uint_20_10", - R"(__vec_2__u32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - shift_right - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } -)"}, + "v2uint_20_10", "vec2", + "(vec2(10u, 20u) >> vec2(20u, 10u))"}, // v2int, v2uint -> v2int - BinaryDataGeneral{"v2int", "v2int_30_40", "OpShiftRightLogical", - "v2uint_10_20", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - shift_right - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2int", "v2int_30_40", "OpShiftRightLogical", "v2uint_10_20", + "vec2", + R"(bitcast>((bitcast>(vec2(30, 40)) >> vec2(10u, 20u))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftRightLogical_Arg2Signed, @@ -433,82 +260,21 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // uint, int -> uint BinaryDataGeneral{"uint", "uint_10", "OpShiftRightLogical", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - shift_right - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - } -)"}, + "u32", "(10u >> bitcast(30))"}, // int, int -> int - BinaryDataGeneral{"int", "int_30", "OpShiftRightLogical", "int_40", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - shift_right - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - } - } - } - } -)"}, + BinaryDataGeneral{ + "int", "int_30", "OpShiftRightLogical", "int_40", "i32", + "bitcast((bitcast(30) >> bitcast(40)))"}, // v2uint, v2int -> v2uint - BinaryDataGeneral{"v2uint", "v2uint_10_20", "OpShiftRightLogical", - "v2int_30_40", - R"(__vec_2__u32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - shift_right - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - } -)"}, + BinaryDataGeneral{ + "v2uint", "v2uint_10_20", "OpShiftRightLogical", "v2int_30_40", + "vec2", + "(vec2(10u, 20u) >> bitcast>(vec2(30, 40)))"}, // v2int, v2int -> v2int - BinaryDataGeneral{"v2int", "v2int_40_30", "OpShiftRightLogical", - "v2int_30_40", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - shift_right - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2int", "v2int_40_30", "OpShiftRightLogical", "v2int_30_40", + "vec2", + R"(bitcast>((bitcast>(vec2(40, 30)) >> bitcast>(vec2(30, 40)))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftRightLogical_BitcastResult, @@ -516,39 +282,12 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // uint, uint -> int BinaryDataGeneral{"int", "uint_20", "OpShiftRightLogical", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - shift_right - ScalarConstructor[not set]{10u} - } - } - } -)"}, + "i32", "bitcast((20u >> 10u))"}, // v2uint, v2uint -> v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpShiftRightLogical", - "v2uint_20_10", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - shift_right - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpShiftRightLogical", "v2uint_20_10", + "vec2", + R"(bitcast>((vec2(10u, 20u) >> vec2(20u, 10u))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftRightArithmetic_Arg2Unsigned, @@ -556,158 +295,42 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // uint, uint -> uint BinaryDataGeneral{"uint", "uint_10", "OpShiftRightArithmetic", - "uint_20", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - shift_right - ScalarConstructor[not set]{20u} - } - } - } -)"}, + "uint_20", "u32", + "bitcast((bitcast(10u) >> 20u))"}, // int, uint -> int BinaryDataGeneral{"int", "int_30", "OpShiftRightArithmetic", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - shift_right - ScalarConstructor[not set]{10u} - } - } -)"}, + "i32", "(30 >> 10u)"}, // v2uint, v2uint -> v2uint - BinaryDataGeneral{"v2uint", "v2uint_10_20", "OpShiftRightArithmetic", - "v2uint_20_10", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - shift_right - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } - } -)"}, + BinaryDataGeneral{ + "v2uint", "v2uint_10_20", "OpShiftRightArithmetic", "v2uint_20_10", + "vec2", + R"(bitcast>((bitcast>(vec2(10u, 20u)) >> vec2(20u, 10u))))"}, // v2int, v2uint -> v2int BinaryDataGeneral{"v2int", "v2int_40_30", "OpShiftRightArithmetic", - "v2uint_20_10", - R"(__vec_2__i32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - shift_right - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } -)"})); + "v2uint_20_10", "vec2", + "(vec2(40, 30) >> vec2(20u, 10u))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftRightArithmetic_Arg2Signed, SpvBinaryBitGeneralTest, ::testing::Values( // uint, int -> uint - BinaryDataGeneral{"uint", "uint_10", "OpShiftRightArithmetic", "int_30", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - shift_right - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - } - } -)"}, + BinaryDataGeneral{ + "uint", "uint_10", "OpShiftRightArithmetic", "int_30", "u32", + "bitcast((bitcast(10u) >> bitcast(30)))"}, // int, int -> int BinaryDataGeneral{"int", "int_30", "OpShiftRightArithmetic", "int_40", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - shift_right - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - } - } - } -)"}, + "i32", "(30 >> bitcast(40))"}, // v2uint, v2int -> v2uint - BinaryDataGeneral{"v2uint", "v2uint_10_20", "OpShiftRightArithmetic", - "v2int_30_40", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - shift_right - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - } - } -)"}, + BinaryDataGeneral{ + "v2uint", "v2uint_10_20", "OpShiftRightArithmetic", "v2int_30_40", + "vec2", + R"(bitcast>((bitcast>(vec2(10u, 20u)) >> bitcast>(vec2(30, 40)))))"}, // v2int, v2int -> v2int - BinaryDataGeneral{"v2int", "v2int_40_30", "OpShiftRightArithmetic", - "v2int_30_40", - R"(__vec_2__i32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - shift_right - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2int", "v2int_40_30", "OpShiftRightArithmetic", "v2int_30_40", + "vec2", + "(vec2(40, 30) >> bitcast>(vec2(30, 40)))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ShiftRightArithmetic_BitcastResult, @@ -715,60 +338,31 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // int, uint -> uint BinaryDataGeneral{"uint", "int_30", "OpShiftRightArithmetic", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - shift_right - ScalarConstructor[not set]{10u} - } - } - } -)"}, + "u32", "bitcast((30 >> 10u))"}, // v2int, v2uint -> v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpShiftRightArithmetic", - "v2uint_20_10", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - shift_right - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - } - } - } -)"})); + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpShiftRightArithmetic", "v2uint_20_10", + "vec2", + "bitcast>((vec2(30, 40) >> vec2(20u, 10u)))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_BitwiseAnd, SpvBinaryBitTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpBitwiseAnd", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "and", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"uint", "uint_10", "OpBitwiseAnd", "uint_20", "u32", "10u", + "&", "20u"}, // Both int - BinaryData{"int", "int_30", "OpBitwiseAnd", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "and", - "ScalarConstructor[not set]{40}"}, + BinaryData{"int", "int_30", "OpBitwiseAnd", "int_40", "i32", "30", "&", + "40"}, // TODO(crbug.com/tint/678): Resolver fails on vector bitwise operations // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpBitwiseAnd", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "and", + "vec2", AstFor("v2uint_10_20"), "&", AstFor("v2uint_20_10")}, // Both v2int BinaryData{"v2int", "v2int_30_40", "OpBitwiseAnd", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "and", + "vec2", AstFor("v2int_30_40"), "&", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( @@ -776,122 +370,45 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryBitGeneralTest, ::testing::Values( // Mixed, uint <- int uint - BinaryDataGeneral{"uint", "int_30", "OpBitwiseAnd", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - and - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })"}, + BinaryDataGeneral{"uint", "int_30", "OpBitwiseAnd", "uint_10", "u32", + "bitcast((30 & bitcast(10u)))"}, // Mixed, int <- int uint - BinaryDataGeneral{"int", "int_30", "OpBitwiseAnd", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - and - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "int_30", "OpBitwiseAnd", "uint_10", "i32", + "(30 & bitcast(10u))"}, // Mixed, uint <- uint int - BinaryDataGeneral{"uint", "uint_10", "OpBitwiseAnd", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - and - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - })"}, + BinaryDataGeneral{"uint", "uint_10", "OpBitwiseAnd", "int_30", "u32", + "(10u & bitcast(30))"}, // Mixed, int <- uint uint - BinaryDataGeneral{"int", "uint_20", "OpBitwiseAnd", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - and - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "uint_20", "OpBitwiseAnd", "uint_10", "i32", + "bitcast((20u & 10u))"}, // Mixed, returning v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpBitwiseAnd", - "v2uint_10_20", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - and - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })"}, + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpBitwiseAnd", "v2uint_10_20", + "vec2", + R"(bitcast>((vec2(30, 40) & bitcast>(vec2(10u, 20u)))))"}, // Mixed, returning v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpBitwiseAnd", - "v2int_40_30", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - and - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpBitwiseAnd", "v2int_40_30", "vec2", + R"(bitcast>((vec2(10u, 20u) & bitcast>(vec2(40, 30)))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_BitwiseOr, SpvBinaryBitTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpBitwiseOr", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "or", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"uint", "uint_10", "OpBitwiseOr", "uint_20", "u32", "10u", + "|", "20u"}, // Both int - BinaryData{"int", "int_30", "OpBitwiseOr", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "or", - "ScalarConstructor[not set]{40}"}, + BinaryData{"int", "int_30", "OpBitwiseOr", "int_40", "i32", "30", "|", + "40"}, // TODO(crbug.com/tint/678): Resolver fails on vector bitwise operations // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpBitwiseOr", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "or", + "vec2", AstFor("v2uint_10_20"), "|", AstFor("v2uint_20_10")}, // Both v2int BinaryData{"v2int", "v2int_30_40", "OpBitwiseOr", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "or", + "vec2", AstFor("v2int_30_40"), "|", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( @@ -899,121 +416,44 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryBitGeneralTest, ::testing::Values( // Mixed, uint <- int uint - BinaryDataGeneral{"uint", "int_30", "OpBitwiseOr", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - or - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })"}, + BinaryDataGeneral{"uint", "int_30", "OpBitwiseOr", "uint_10", "u32", + "bitcast((30 | bitcast(10u)))"}, // Mixed, int <- int uint - BinaryDataGeneral{"int", "int_30", "OpBitwiseOr", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - or - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "int_30", "OpBitwiseOr", "uint_10", "i32", + "(30 | bitcast(10u))"}, // Mixed, uint <- uint int - BinaryDataGeneral{"uint", "uint_10", "OpBitwiseOr", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - or - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - })"}, + BinaryDataGeneral{"uint", "uint_10", "OpBitwiseOr", "int_30", "u32", + "(10u | bitcast(30))"}, // Mixed, int <- uint uint - BinaryDataGeneral{"int", "uint_20", "OpBitwiseOr", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - or - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "uint_20", "OpBitwiseOr", "uint_10", "i32", + "bitcast((20u | 10u))"}, // Mixed, returning v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpBitwiseOr", - "v2uint_10_20", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - or - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })"}, + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpBitwiseOr", "v2uint_10_20", "vec2", + R"(bitcast>((vec2(30, 40) | bitcast>(vec2(10u, 20u)))))"}, // Mixed, returning v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpBitwiseOr", "v2int_40_30", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - or - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpBitwiseOr", "v2int_40_30", "vec2", + R"(bitcast>((vec2(10u, 20u) | bitcast>(vec2(40, 30)))))"})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_BitwiseXor, SpvBinaryBitTest, ::testing::Values( // Both uint - BinaryData{"uint", "uint_10", "OpBitwiseXor", "uint_20", "__u32", - "ScalarConstructor[not set]{10u}", "xor", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"uint", "uint_10", "OpBitwiseXor", "uint_20", "u32", "10u", + "^", "20u"}, // Both int - BinaryData{"int", "int_30", "OpBitwiseXor", "int_40", "__i32", - "ScalarConstructor[not set]{30}", "xor", - "ScalarConstructor[not set]{40}"}, + BinaryData{"int", "int_30", "OpBitwiseXor", "int_40", "i32", "30", "^", + "40"}, // TODO(crbug.com/tint/678): Resolver fails on vector bitwise operations // Both v2uint BinaryData{"v2uint", "v2uint_10_20", "OpBitwiseXor", "v2uint_20_10", - "__vec_2__u32", AstFor("v2uint_10_20"), "xor", + "vec2", AstFor("v2uint_10_20"), "^", AstFor("v2uint_20_10")}, // Both v2int BinaryData{"v2int", "v2int_30_40", "OpBitwiseXor", "v2int_40_30", - "__vec_2__i32", AstFor("v2int_30_40"), "xor", + "vec2", AstFor("v2int_30_40"), "^", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( @@ -1021,101 +461,26 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryBitGeneralTest, ::testing::Values( // Mixed, uint <- int uint - BinaryDataGeneral{"uint", "int_30", "OpBitwiseXor", "uint_10", - R"(__u32 - { - Bitcast[not set]<__u32>{ - Binary[not set]{ - ScalarConstructor[not set]{30} - xor - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - } - })"}, + BinaryDataGeneral{"uint", "int_30", "OpBitwiseXor", "uint_10", "u32", + "bitcast((30 ^ bitcast(10u)))"}, // Mixed, int <- int uint - BinaryDataGeneral{"int", "int_30", "OpBitwiseXor", "uint_10", - R"(__i32 - { - Binary[not set]{ - ScalarConstructor[not set]{30} - xor - Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "int_30", "OpBitwiseXor", "uint_10", "i32", + "(30 ^ bitcast(10u))"}, // Mixed, uint <- uint int - BinaryDataGeneral{"uint", "uint_10", "OpBitwiseXor", "int_30", - R"(__u32 - { - Binary[not set]{ - ScalarConstructor[not set]{10u} - xor - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - } - } - })"}, + BinaryDataGeneral{"uint", "uint_10", "OpBitwiseXor", "int_30", "u32", + "(10u ^ bitcast(30))"}, // Mixed, int <- uint uint - BinaryDataGeneral{"int", "uint_20", "OpBitwiseXor", "uint_10", - R"(__i32 - { - Bitcast[not set]<__i32>{ - Binary[not set]{ - ScalarConstructor[not set]{20u} - xor - ScalarConstructor[not set]{10u} - } - } - })"}, + BinaryDataGeneral{"int", "uint_20", "OpBitwiseXor", "uint_10", "i32", + "bitcast((20u ^ 10u))"}, // Mixed, returning v2uint - BinaryDataGeneral{"v2uint", "v2int_30_40", "OpBitwiseXor", - "v2uint_10_20", - R"(__vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - xor - Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })"}, + BinaryDataGeneral{ + "v2uint", "v2int_30_40", "OpBitwiseXor", "v2uint_10_20", + "vec2", + R"(bitcast>((vec2(30, 40) ^ bitcast>(vec2(10u, 20u)))))"}, // Mixed, returning v2int - BinaryDataGeneral{"v2int", "v2uint_10_20", "OpBitwiseXor", - "v2int_40_30", - R"(__vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - xor - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - } - } - } - })"})); + BinaryDataGeneral{ + "v2int", "v2uint_10_20", "OpBitwiseXor", "v2int_40_30", "vec2", + R"(bitcast>((vec2(10u, 20u) ^ bitcast>(vec2(40, 30)))))"})); TEST_F(SpvUnaryBitTest, Not_Int_Int) { const auto assembly = SimplePreamble() + R"( @@ -1129,19 +494,9 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - UnaryOp[not set]{ - complement - ScalarConstructor[not set]{30} - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : i32 = ~(30);")); } TEST_F(SpvUnaryBitTest, Not_Int_Uint) { @@ -1156,21 +511,9 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Bitcast[not set]<__i32>{ - UnaryOp[not set]{ - complement - ScalarConstructor[not set]{10u} - } - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : i32 = bitcast(~(10u));")); } TEST_F(SpvUnaryBitTest, Not_Uint_Int) { @@ -1185,21 +528,9 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - UnaryOp[not set]{ - complement - ScalarConstructor[not set]{30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = bitcast(~(30));")); } TEST_F(SpvUnaryBitTest, Not_Uint_Uint) { @@ -1214,19 +545,9 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - UnaryOp[not set]{ - complement - ScalarConstructor[not set]{10u} - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = ~(10u);")); } TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) { @@ -1241,23 +562,9 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - UnaryOp[not set]{ - complement - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = ~(vec2(30, 40));")); } TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { @@ -1272,25 +579,12 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - UnaryOp[not set]{ - complement - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + "let x_1 : vec2 = bitcast>(~(vec2(10u, 20u)));")); } TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { @@ -1305,25 +599,12 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - UnaryOp[not set]{ - complement - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + "let x_1 : vec2 = bitcast>(~(vec2(30, 40)));")); } TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) { const auto assembly = SimplePreamble() + R"( @@ -1337,23 +618,9 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - UnaryOp[not set]{ - complement - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - })")); + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = ~(vec2(10u, 20u));")); } std::string BitTestPreamble() { @@ -1392,23 +659,9 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{u1} - ) - } - } - })")) - << body; + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = countOneBits(u1);")) << body; } TEST_F(SpvUnaryBitTest, BitCount_Uint_Int) { @@ -1421,24 +674,10 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{i1} - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, + HasSubstr("let x_1 : u32 = bitcast(countOneBits(i1));")) << body; } @@ -1452,24 +691,10 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Bitcast[not set]<__i32>{ - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{u1} - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, + HasSubstr("let x_1 : i32 = bitcast(countOneBits(u1));")) << body; } @@ -1483,23 +708,9 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{i1} - ) - } - } - })")) - << body; + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : i32 = countOneBits(i1);")) << body; } TEST_F(SpvUnaryBitTest, BitCount_UintVector_UintVector) { @@ -1512,22 +723,9 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{v2u1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = countOneBits(v2u1);")) << body; } @@ -1541,24 +739,12 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{v2i1} - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + "let x_1 : vec2 = bitcast>(countOneBits(v2i1));")) << body; } @@ -1572,24 +758,12 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{v2u1} - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + "let x_1 : vec2 = bitcast>(countOneBits(v2u1));")) << body; } @@ -1603,22 +777,9 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Call[not set]{ - Identifier[not set]{countOneBits} - ( - Identifier[not set]{v2i1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = countOneBits(v2i1);")) << body; } @@ -1632,23 +793,9 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{reverseBits} - ( - Identifier[not set]{u1} - ) - } - } - })")) - << body; + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = reverseBits(u1);")) << body; } TEST_F(SpvUnaryBitTest, BitReverse_Uint_Int) { @@ -1689,23 +836,9 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{reverseBits} - ( - Identifier[not set]{i1} - ) - } - } - })")) - << body; + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : i32 = reverseBits(i1);")) << body; } TEST_F(SpvUnaryBitTest, BitReverse_UintVector_UintVector) { @@ -1718,22 +851,9 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Call[not set]{ - Identifier[not set]{reverseBits} - ( - Identifier[not set]{v2u1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = reverseBits(v2u1);")) << body; } @@ -1775,22 +895,9 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Call[not set]{ - Identifier[not set]{reverseBits} - ( - Identifier[not set]{v2i1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = reverseBits(v2i1);")) << body; } diff --git a/src/reader/spirv/function_call_test.cc b/src/reader/spirv/function_call_test.cc index 3060d20774..c3efe3f71b 100644 --- a/src/reader/spirv/function_call_test.cc +++ b/src/reader/spirv/function_call_test.cc @@ -51,33 +51,19 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) { OpFunctionEnd )")); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); - const auto got = p->program().to_str(false); - const char* expect = R"(Module{ - Function $1 -> __void - () - { - Return{} - } - Function $2 -> __void - () - { - Call[not set]{ - Identifier[not set]{$1} - ( - ) - } - Return{} - } - Function $3 -> __void - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{$2} - ( - ) - } - } + const auto got = test::ToString(p->program()); + const char* expect = R"(fn x_50() { + return; +} + +fn x_100_1() { + x_50(); + return; +} + +[[stage(fragment)]] +fn x_100() { + x_100_1(); } )"; EXPECT_EQ(expect, got); @@ -103,37 +89,22 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) { OpFunctionEnd )")); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); + ast::StatementList f100; { auto fe = p->function_emitter(100); - EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{x_50} - ( - ) - } - } + EXPECT_TRUE(fe.EmitBody()) << p->error(); + f100 = fe.ast_body(); } -} -Return{})")); - } - + ast::StatementList f50; { auto fe = p->function_emitter(50); - EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Return{ - { - ScalarConstructor[not set]{42u} - } -})")); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + f50 = fe.ast_body(); } + auto program = p->program(); + EXPECT_THAT(test::ToString(program, f100), + HasSubstr("let x_1 : u32 = x_50();\nreturn;")); + EXPECT_THAT(test::ToString(program, f50), HasSubstr("return 42u;")); } TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) { @@ -160,55 +131,26 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) { OpFunctionEnd )")); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); + ast::StatementList f100; { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - const std::string expected = - R"(VariableDeclStatement{ - Variable{ - x_10 - none - undefined - __u32 - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{x_50} - ( - ) - } - } - } -} -Assignment{ - Identifier[not set]{x_10} - Identifier[not set]{x_1} -} -Assignment{ - Identifier[not set]{x_10} - Identifier[not set]{x_1} -} -Return{} -)"; - EXPECT_EQ(got, expected); + f100 = fe.ast_body(); } + ast::StatementList f50; { auto fe = p->function_emitter(50); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Return{ - { - ScalarConstructor[not set]{42u} - } -})")); + f50 = fe.ast_body(); } + auto program = p->program(); + EXPECT_EQ(test::ToString(program, f100), R"(var x_10 : u32; +let x_1 : u32 = x_50(); +x_10 = x_1; +x_10 = x_1; +return; +)"); + EXPECT_THAT(test::ToString(program, f50), HasSubstr("return 42u;")); } TEST_F(SpvParserTest, EmitStatement_CallWithParams) { @@ -236,66 +178,19 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) { )")); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto program_ast_str = p->program().to_str(); - const std::string expected = R"(Module{ - Function x_50 -> __u32 - ( - VariableConst{ - x_51 - none - undefined - __u32 - } - VariableConst{ - x_52 - none - undefined - __u32 - } - ) - { - Return{ - { - Binary[not set]{ - Identifier[not set]{x_51} - add - Identifier[not set]{x_52} - } - } - } - } - Function x_100_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{x_50} - ( - ScalarConstructor[not set]{42u} - ScalarConstructor[not set]{84u} - ) - } - } - } - } - Return{} - } - Function x_100 -> __void - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{x_100_1} - ( - ) - } - } + const auto program_ast_str = test::ToString(p->program()); + const std::string expected = R"(fn x_50(x_51 : u32, x_52 : u32) -> u32 { + return (x_51 + x_52); +} + +fn x_100_1() { + let x_1 : u32 = x_50(42u, 84u); + return; +} + +[[stage(fragment)]] +fn x_100() { + x_100_1(); } )"; EXPECT_EQ(program_ast_str, expected); diff --git a/src/reader/spirv/function_cfg_test.cc b/src/reader/spirv/function_cfg_test.cc index a369ac665f..bf30b47567 100644 --- a/src/reader/spirv/function_cfg_test.cc +++ b/src/reader/spirv/function_cfg_test.cc @@ -7901,83 +7901,27 @@ TEST_F(SpvParserCFGTest, EmitBody_IfBreak_FromThen_ForwardWithinThen) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -VariableDeclStatement{ - Variable{ - guard10 - none - undefined - __bool - { - ScalarConstructor[not set]{true} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +var guard10 : bool = true; +if (false) { + var_1 = 2u; + if (true) { + guard10 = false; + } + if (guard10) { + var_1 = 3u; + guard10 = false; + } +} else { + if (guard10) { + var_1 = 4u; + guard10 = false; } } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - } -} -Else{ - { - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -8014,83 +7958,27 @@ TEST_F(SpvParserCFGTest, EmitBody_IfBreak_FromElse_ForwardWithinElse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -VariableDeclStatement{ - Variable{ - guard10 - none - undefined - __bool - { - ScalarConstructor[not set]{true} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +var guard10 : bool = true; +if (false) { + var_1 = 2u; + guard10 = false; +} else { + if (guard10) { + var_1 = 3u; + if (true) { + guard10 = false; + } + if (guard10) { + var_1 = 4u; + guard10 = false; } } } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } -} -Else{ - { - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - } - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -8142,142 +8030,43 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error() << assembly; - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -VariableDeclStatement{ - Variable{ - guard10 - none - undefined - __bool - { - ScalarConstructor[not set]{true} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +var guard10 : bool = true; +if (false) { + var_1 = 2u; + if (true) { + } else { + guard10 = false; + } + if (guard10) { + var_1 = 3u; + } +} else { + if (guard10) { + var_1 = 4u; + if (true) { + guard10 = false; + } + if (guard10) { + var_1 = 5u; } } } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - } - } - Else{ - { - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - } - } +if (guard10) { + var_1 = 6u; + if (false) { + } else { + guard10 = false; + } + if (guard10) { + var_1 = 7u; + guard10 = false; } } -Else{ - { - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } - } - } - } - } - } -} -If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - If{ - ( - Identifier[not set]{guard10} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} - } - Assignment{ - Identifier[not set]{guard10} - ScalarConstructor[not set]{false} - } - } - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{8u} -} -Return{} +var_1 = 8u; +return; )"; ASSERT_EQ(expect, got); } @@ -8334,15 +8123,11 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Empty) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -8370,27 +8155,14 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Then_NoElse) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { + var_1 = 1u; } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8418,31 +8190,15 @@ TEST_F(SpvParserCFGTest, EmitBody_If_NoThen_Else) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { +} else { + var_1 = 1u; } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - } -} -Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8474,35 +8230,16 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Then_Else) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { + var_1 = 1u; +} else { + var_1 = 2u; } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } -} -Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8541,46 +8278,19 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Then_Else_Premerge) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { + var_1 = 1u; +} else { + var_1 = 2u; } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } +if (true) { + var_1 = 3u; } -Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - } -} -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8613,38 +8323,17 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Then_Premerge) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { + var_1 = 1u; } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } +if (true) { + var_1 = 3u; } -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8677,42 +8366,18 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Else_Premerge) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { +} else { + var_1 = 1u; } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - } +if (true) { + var_1 = 3u; } -Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } -} -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8762,69 +8427,25 @@ TEST_F(SpvParserCFGTest, EmitBody_If_Nest_If) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { + var_1 = 1u; + if (true) { + var_1 = 2u; } -} -Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - } - } - Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} - } + var_1 = 3u; +} else { + var_1 = 4u; + if (true) { + } else { + var_1 = 5u; } + var_1 = 6u; } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8852,34 +8473,18 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_SingleBlock_TrueBackedge) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + if (false) { + } else { + break; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8907,30 +8512,17 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_SingleBlock_FalseBackedge) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + if (false) { + break; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -8958,22 +8550,14 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_SingleBlock_BothBackedge) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; } -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -9001,22 +8585,14 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_SingleBlock_UnconditionalBackege) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; } -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -9052,32 +8628,19 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_Unconditional_Body_SingleBlockContinue) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -9117,36 +8680,20 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_Unconditional_Body_MultiBlockContinue) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 3u; + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -9191,47 +8738,23 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_Unconditional_Body_ContinueNestIf) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} + var_1 = 3u; + if (true) { + var_1 = 4u; } + var_1 = 5u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{999u} -} -Return{} +var_1 = 999u; +return; )"; ASSERT_EQ(expect, got); } @@ -9263,34 +8786,18 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_MultiBlockContinueIsEntireLoop) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (false) { + break; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} -} -Return{} +var_1 = 3u; +return; )"; ASSERT_EQ(expect, got); } @@ -9321,25 +8828,18 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_Never) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Break{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + break; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} -} -Return{} +var_1 = 3u; +return; )"; ASSERT_EQ(expect, got); } @@ -9381,40 +8881,22 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_TrueToBody_FalseBreaks) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + if (false) { + } else { + break; } + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} -} -Return{} +var_1 = 4u; +return; )"; ASSERT_EQ(expect, got); } @@ -9448,40 +8930,22 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_FalseToBody_TrueBreaks) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + if (false) { + } else { + break; } + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} -} -Return{} +var_1 = 4u; +return; )"; ASSERT_EQ(expect, got); } @@ -9522,32 +8986,20 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_NestedIfContinue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Continue{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + if (false) { + var_1 = 1u; + continue; } + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -9580,21 +9032,17 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_BodyAlwaysBreaks) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Break{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + break; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -9629,28 +9077,19 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + if (false) { + break; } + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -9685,32 +9124,20 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + if (false) { + } else { + break; } + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -9747,32 +9174,20 @@ TEST_F(SpvParserCFGTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue_Early) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + if (false) { + break; } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -9810,36 +9225,21 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + if (false) { + } else { + break; } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -9863,23 +9263,15 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_DefaultIsMerge_NoCases) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -9908,29 +9300,18 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_DefaultIsMerge_OneCase) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -9962,35 +9343,21 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_DefaultIsMerge_TwoCases) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 30u: { + var_1 = 30u; + } + case 20u: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10022,35 +9389,21 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_DefaultIsMerge_CasesWithDup) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Case 20u, 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 30u: { + var_1 = 30u; + } + case 20u, 40u: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10088,39 +9441,22 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_DefaultIsCase_NoDupCases) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - } - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 40u: { + var_1 = 40u; + } + case 20u: { + var_1 = 20u; + } + default: { + var_1 = 30u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10159,42 +9495,25 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_DefaultIsCase_WithDupCase) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - } - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - Fallthrough{} - } - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 40u: { + var_1 = 40u; + } + case 20u: { + var_1 = 20u; + } + default: { + fallthrough; + } + case 30u: { + var_1 = 30u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10231,41 +9550,24 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_Case_SintValue) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42} - { - Case -294967296{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - } - Case 2000000000{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Case 20{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42) { + case -294967296: { + var_1 = 40u; + } + case 2000000000: { + var_1 = 30u; + } + case 20: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10301,41 +9603,24 @@ TEST_F(SpvParserCFGTest, EmitBody_Switch_Case_UintValue) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 50u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - } - Case 2000000000u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 50u: { + var_1 = 40u; + } + case 2000000000u: { + var_1 = 30u; + } + case 20u: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10353,8 +9638,9 @@ TEST_F(SpvParserCFGTest, EmitBody_Return_TopLevel) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(return; )"; ASSERT_EQ(expect, got); } @@ -10379,16 +9665,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Return_InsideIf) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - Return{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { + return; } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -10419,11 +9701,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Return_InsideLoop) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + return; } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -10449,12 +9732,9 @@ TEST_F(SpvParserCFGTest, EmitBody_ReturnValue_TopLevel) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Return{ - { - ScalarConstructor[not set]{2u} - } -} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(return 2u; )"; ASSERT_EQ(expect, got); } @@ -10488,24 +9768,12 @@ TEST_F(SpvParserCFGTest, EmitBody_ReturnValue_InsideIf) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - Return{ - { - ScalarConstructor[not set]{2u} - } - } - } -} -Return{ - { - ScalarConstructor[not set]{3u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { + return 2u; } +return 3u; )"; ASSERT_EQ(expect, got); } @@ -10545,19 +9813,12 @@ TEST_F(SpvParserCFGTest, EmitBody_ReturnValue_Loop) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Return{ - { - ScalarConstructor[not set]{2u} - } - } -} -Return{ - { - ScalarConstructor[not set]{3u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + return 2u; } +return 3u; )"; ASSERT_EQ(expect, got); } @@ -10575,8 +9836,9 @@ TEST_F(SpvParserCFGTest, EmitBody_Kill_TopLevel) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Discard{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(discard; )"; ASSERT_EQ(expect, got); } @@ -10601,16 +9863,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Kill_InsideIf) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - Discard{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { + discard; } -Discard{} +discard; )"; ASSERT_EQ(expect, got); } @@ -10641,11 +9899,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Kill_InsideLoop) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Discard{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + discard; } -Discard{} +discard; )"; ASSERT_EQ(expect, got); } @@ -10663,8 +9922,9 @@ TEST_F(SpvParserCFGTest, EmitBody_Unreachable_TopLevel) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(return; )"; ASSERT_EQ(expect, got); } @@ -10689,16 +9949,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Unreachable_InsideIf) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - Return{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { + return; } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -10729,11 +9985,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Unreachable_InsideLoop) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + return; } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -10759,12 +10016,9 @@ TEST_F(SpvParserCFGTest, EmitBody_Unreachable_InNonVoidFunction) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Return{ - { - ScalarConstructor[not set]{0u} - } -} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(return 0u; )"; ASSERT_EQ(expect, got); } @@ -10793,16 +10047,15 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_BackEdge_MultiBlockLoop) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } + var_1 = 1u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -10828,14 +10081,12 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_BackEdge_SingleBlockLoop) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -10865,29 +10116,18 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_SwitchBreak_LastInCase) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10925,45 +10165,23 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_SwitchBreak_NotLastInCase) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{50u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + if (false) { + var_1 = 40u; + break; } + var_1 = 50u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -10996,21 +10214,17 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_LoopBreak_MultiBlockLoop_FromBody) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Break{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + break; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -11085,17 +10299,16 @@ TEST_F( ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Break{} + var_1 = 1u; + break; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -11125,28 +10338,19 @@ TEST_F( ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } + var_1 = 1u; + if (false) { + } else { + break; } } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -11178,20 +10382,16 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_LoopContinue_LastInLoopConstruct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var_1 = 1u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + var_1 = 2u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -11232,32 +10432,20 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_LoopContinue_BeforeLast) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Continue{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + if (false) { + var_1 = 1u; + continue; } + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -11301,50 +10489,28 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_LoopContinue_FromSwitch) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - Continue{} - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +loop { + var_1 = 2u; + var_1 = 3u; + switch(42u) { + case 40u: { + var_1 = 4u; + continue; + } + default: { } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } + var_1 = 5u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} - } + var_1 = 6u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -11371,23 +10537,13 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_IfBreak_FromThen) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { + var_1 = 1u; } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} -} -Return{} +var_1 = 2u; +return; )"; ASSERT_EQ(expect, got); } @@ -11414,27 +10570,14 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_IfBreak_FromElse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{false} - ) - { - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (false) { +} else { + var_1 = 1u; } -Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} -} -Return{} +var_1 = 2u; +return; )"; ASSERT_EQ(expect, got); } @@ -11466,36 +10609,22 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_Fallthrough) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - Fallthrough{} - } - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + fallthrough; + } + case 30u: { + var_1 = 30u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -11517,16 +10646,11 @@ TEST_F(SpvParserCFGTest, EmitBody_Branch_Forward) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} -} -Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +var_1 = 2u; +return; )"; ASSERT_EQ(expect, got); } @@ -11621,22 +10745,14 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_Back_SingleBlock_Back) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; } -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -11664,30 +10780,17 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + if (false) { + break; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -11715,34 +10818,18 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + if (false) { + } else { + break; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -11773,32 +10860,20 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + continuing { - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + if (false) { + break; } } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -11829,36 +10904,21 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + continuing { - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } + if (false) { + } else { + break; } } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -11889,29 +10949,18 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -11950,45 +10999,23 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{50u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + if (false) { + var_1 = 40u; + break; } + var_1 = 50u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -12034,57 +11061,30 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Continue{} - } - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +loop { + var_1 = 2u; + var_1 = 3u; + switch(42u) { + case 40u: { + var_1 = 40u; + if (false) { + continue; } } + default: { + } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} - } + var_1 = 6u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} - } + var_1 = 7u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{8u} -} -Return{} +var_1 = 8u; +return; )"; ASSERT_EQ(expect, got); } @@ -12130,61 +11130,31 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Continue{} - } - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +loop { + var_1 = 2u; + var_1 = 3u; + switch(42u) { + case 40u: { + var_1 = 40u; + if (false) { + } else { + continue; } } + default: { + } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} - } + var_1 = 6u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} - } + var_1 = 7u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{8u} -} -Return{} +var_1 = 8u; +return; )"; ASSERT_EQ(expect, got); } @@ -12216,45 +11186,23 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + if (false) { + } else { + break; } + var_1 = 30u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{8u} -} -Return{} +var_1 = 8u; +return; )"; ASSERT_EQ(expect, got); } @@ -12286,41 +11234,22 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + if (false) { + break; } + var_1 = 30u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{8u} -} -Return{} +var_1 = 8u; +return; )"; ASSERT_EQ(expect, got); } @@ -12353,48 +11282,26 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - Fallthrough{} - } - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + if (false) { + } else { + break; } + fallthrough; + } + case 30u: { + var_1 = 30u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -12427,44 +11334,25 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - Fallthrough{} - } - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + if (false) { + break; } + fallthrough; + } + case 30u: { + var_1 = 30u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -12496,29 +11384,19 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Break{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + break; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -12554,33 +11432,20 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Break{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + break; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -12627,56 +11492,27 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_LoopBreak_Continue_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Continue{} - } - } - Else{ - { - Break{} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + if (true) { + var_1 = 2u; + if (false) { + continue; + } else { + break; } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -12724,56 +11560,27 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - Else{ - { - Continue{} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + if (true) { + var_1 = 2u; + if (false) { + break; + } else { + continue; } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -12863,48 +11670,24 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_LoopBreak_Forward_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (false) { + } else { + break; } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -12944,44 +11727,23 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_LoopBreak_Forward_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (false) { + break; } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13013,28 +11775,18 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13070,32 +11822,19 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13142,48 +11881,24 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Continue{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (true) { + var_1 = 3u; + continue; } + var_1 = 4u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } + var_1 = 5u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} -} -Return{} +var_1 = 6u; +return; )"; ASSERT_EQ(expect, got); } @@ -13230,42 +11945,20 @@ TEST_F( ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (true) { + var_1 = 3u; + continue; + } + var_1 = 4u; } -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Continue{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} -} -Return{} +var_1 = 6u; +return; )"; ASSERT_EQ(expect, got); } @@ -13309,50 +12002,28 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_LoopContinue_FromSwitch) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } - Continue{} - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +loop { + var_1 = 2u; + var_1 = 3u; + switch(42u) { + case 40u: { + var_1 = 4u; + continue; + } + default: { } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } + var_1 = 5u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} - } + var_1 = 6u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -13397,59 +12068,27 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_Continue_IfBreak_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Continue{} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (true) { + var_1 = 3u; + if (false) { + } else { + continue; } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } + var_1 = 5u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} -} -Return{} +var_1 = 6u; +return; )"; ASSERT_EQ(expect, got); } @@ -13494,55 +12133,26 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_Continue_IfBreak_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Continue{} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (true) { + var_1 = 3u; + if (false) { + continue; } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} - } + var_1 = 5u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{6u} -} -Return{} +var_1 = 6u; +return; )"; ASSERT_EQ(expect, got); } @@ -13591,68 +12201,35 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Continue{} - } - } - Fallthrough{} - } - Case 50u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{50u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + switch(42u) { + case 40u: { + var_1 = 40u; + if (false) { + } else { + continue; } + fallthrough; + } + case 50u: { + var_1 = 50u; + } + default: { } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13701,64 +12278,34 @@ TEST_F(SpvParserCFGTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - Switch{ - ScalarConstructor[not set]{42u} - { - Case 40u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Continue{} - } - } - Fallthrough{} - } - Case 50u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{50u} - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + switch(42u) { + case 40u: { + var_1 = 40u; + if (false) { + continue; } + fallthrough; + } + case 50u: { + var_1 = 50u; + } + default: { } } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} - } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13798,48 +12345,24 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_Continue_Forward_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Continue{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (false) { + } else { + continue; } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13879,44 +12402,23 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_Continue_Forward_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Continue{} - } - } - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{3u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +loop { + var_1 = 1u; + var_1 = 2u; + if (false) { + continue; } + var_1 = 3u; + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{4u} - } + var_1 = 4u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -13943,23 +12445,13 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_IfBreak_IfBreak_Same) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{0u} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 0u; +if (false) { } -If{ - ( - ScalarConstructor[not set]{false} - ) - { - } -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{5u} -} -Return{} +var_1 = 5u; +return; )"; ASSERT_EQ(expect, got); } @@ -14029,36 +12521,22 @@ TEST_F(SpvParserCFGTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Switch{ - ScalarConstructor[not set]{42u} - { - Case 20u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - Fallthrough{} - } - Case 30u{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - } - Default{ - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +switch(42u) { + case 20u: { + var_1 = 20u; + fallthrough; + } + case 30u: { + var_1 = 30u; + } + default: { } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{7u} -} -Return{} +var_1 = 7u; +return; )"; ASSERT_EQ(expect, got); } @@ -14120,16 +12598,11 @@ TEST_F(SpvParserCFGTest, EmitBody_BranchConditional_Forward_Forward_Same) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{1u} -} -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{2u} -} -Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 1u; +var_1 = 2u; +return; )"; ASSERT_EQ(expect, got); } @@ -14401,18 +12874,14 @@ TEST_F(SpvParserCFGTest, EmitBody_IfSelection_TrueBranch_LoopBreak) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + if (false) { + break; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -14451,18 +12920,14 @@ TEST_F(SpvParserCFGTest, EmitBody_TrueBranch_LoopContinue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Continue{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + if (false) { + continue; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -14495,25 +12960,18 @@ TEST_F(SpvParserCFGTest, EmitBody_TrueBranch_SwitchBreak) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Switch{ - ScalarConstructor[not set]{20u} - { - Case 20u{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(switch(20u) { + case 20u: { + if (false) { + break; } } + default: { + } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -14552,22 +13010,15 @@ TEST_F(SpvParserCFGTest, EmitBody_FalseBranch_LoopBreak) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + if (false) { + } else { + break; } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -14606,22 +13057,15 @@ TEST_F(SpvParserCFGTest, EmitBody_FalseBranch_LoopContinue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Continue{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + if (false) { + } else { + continue; } } -Return{} +return; )"; ASSERT_EQ(expect, got) << p->error(); } @@ -14654,29 +13098,19 @@ TEST_F(SpvParserCFGTest, EmitBody_FalseBranch_SwitchBreak) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Switch{ - ScalarConstructor[not set]{20u} - { - Case 20u{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - } - } - Else{ - { - Break{} - } - } - } - Default{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(switch(20u) { + case 20u: { + if (false) { + } else { + break; } } + default: { + } } -Return{} +return; )"; ASSERT_EQ(expect, got); } @@ -14716,48 +13150,24 @@ TEST_F(SpvParserCFGTest, EmitBody_LoopInternallyDiverge_Simple) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{10u} -} -Loop{ - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{20u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{30u} - } - Continue{} - } - } - Else{ - { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{40u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var_1 = 10u; +loop { + var_1 = 20u; + if (false) { + var_1 = 30u; + continue; + } else { + var_1 = 40u; } + continuing { - Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{90u} - } + var_1 = 90u; } } -Assignment{ - Identifier[not set]{var_1} - ScalarConstructor[not set]{99u} -} -Return{} +var_1 = 99u; +return; )"; ASSERT_EQ(expect, got) << got; } diff --git a/src/reader/spirv/function_composite_test.cc b/src/reader/spirv/function_composite_test.cc index 6472b5509d..46bf2eae0e 100644 --- a/src/reader/spirv/function_composite_test.cc +++ b/src/reader/spirv/function_composite_test.cc @@ -95,52 +95,12 @@ TEST_F(SpvParserTest_Composite_Construct, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_1 : vec2 = vec2(10u, 20u); +let x_2 : vec2 = vec2(30, 40); +let x_3 : vec2 = vec2(50.0, 60.0); +)")); } TEST_F(SpvParserTest_Composite_Construct, Matrix) { @@ -155,33 +115,12 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __mat_2_3__f32 - { - TypeConstructor[not set]{ - __mat_2_3__f32 - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{70.000000} - ScalarConstructor[not set]{70.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : mat3x2 = mat3x2(" + "vec2(50.0, 60.0), " + "vec2(60.0, 50.0), " + "vec2(70.0, 70.0));")); } TEST_F(SpvParserTest_Composite_Construct, Array) { @@ -196,23 +135,11 @@ TEST_F(SpvParserTest_Composite_Construct, Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __array__u32_5 - { - TypeConstructor[not set]{ - __array__u32_5 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - ScalarConstructor[not set]{5u} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + "let x_1 : array = array(10u, 20u, 3u, 4u, 5u);")); } TEST_F(SpvParserTest_Composite_Construct, Struct) { @@ -227,25 +154,9 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - ScalarConstructor[not set]{5u} - ScalarConstructor[not set]{30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : S = S(vec2(50.0, 60.0), 5u, 30);")); } TEST_F(SpvParserTest_Composite_Construct, @@ -268,37 +179,12 @@ TEST_F(SpvParserTest_Composite_Construct, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); const auto expected = std::string( - R"(VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __type_name_S_1 - { - TypeConstructor[not set]{ - __type_name_S_1 - ScalarConstructor[not set]{10u} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __type_name_S_2 - { - TypeConstructor[not set]{ - __type_name_S_2 - ScalarConstructor[not set]{10u} - } - } - } -} -Return{} + R"(let x_2 : S_1 = S_1(10u); +let x_3 : S_2 = S_2(10u); +return; )"); EXPECT_EQ(got, expected) << got; } @@ -317,23 +203,9 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - MemberAccessor[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - Identifier[not set]{y} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = vec2(50.0, 60.0).y;")); } TEST_F(SpvParserTest_CompositeExtract, Vector_IndexTooBigError) { @@ -368,19 +240,9 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__f32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{2u} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : vec2 = x_1[2u];")); } TEST_F(SpvParserTest_CompositeExtract, Matrix_IndexTooBigError) { @@ -419,22 +281,9 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __f32 - { - MemberAccessor[not set]{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{2u} - } - Identifier[not set]{y} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : f32 = x_1[2u].y;")); } TEST_F(SpvParserTest_CompositeExtract, Array) { @@ -453,19 +302,9 @@ TEST_F(SpvParserTest_CompositeExtract, Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{3u} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : u32 = x_1[3u];")); } TEST_F(SpvParserTest_CompositeExtract, RuntimeArray_IsError) { @@ -505,19 +344,9 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __i32 - { - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field2} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : i32 = x_1.field2;")); } TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { @@ -556,34 +385,13 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); auto got = fe.ast_body(); - EXPECT_THAT(ToString(p->builder(), got), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __u32 - { - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{algo} - } - } - })")) - << ToString(p->builder(), got); - EXPECT_THAT(ToString(p->builder(), got), HasSubstr(R"( - VariableConst{ - x_4 - none - undefined - __u32 - { - MemberAccessor[not set]{ - Identifier[not set]{x_3} - Identifier[not set]{rithm} - } - } - })")) - << ToString(p->builder(), got); + auto program = p->program(); + EXPECT_THAT(test::ToString(program, got), + HasSubstr("let x_2 : u32 = x_1.algo;")) + << test::ToString(program, got); + EXPECT_THAT(test::ToString(program, got), + HasSubstr("let x_4 : u32 = x_3.rithm;")) + << test::ToString(program, got); p->SkipDumpingPending("crbug.com/tint/863"); } @@ -625,28 +433,9 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __f32 - { - MemberAccessor[not set]{ - ArrayAccessor[not set]{ - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{2u} - } - ScalarConstructor[not set]{0u} - } - Identifier[not set]{y} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : f32 = x_1.field1[2u][0u].y;")); } using SpvParserTest_CompositeInsert = SpvParserTest; @@ -663,42 +452,13 @@ TEST_F(SpvParserTest_CompositeInsert, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); const auto* expected = - R"(VariableDeclStatement{ - Variable{ - x_1_1 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - } - } -} -Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1_1} - Identifier[not set]{y} - } - ScalarConstructor[not set]{70.000000} -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Identifier[not set]{x_1_1} - } - } -} -Return{} + R"(var x_1_1 : vec2 = vec2(50.0, 60.0); +x_1_1.y = 70.0; +let x_1 : vec2 = x_1_1; +return; )"; EXPECT_EQ(got, expected); } @@ -735,40 +495,12 @@ TEST_F(SpvParserTest_CompositeInsert, Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_2_1 - none - undefined - __mat_2_3__f32 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_2_1} - ScalarConstructor[not set]{2u} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __mat_2_3__f32 - { - Identifier[not set]{x_2_1} - } - } -})")) << body_str; + auto ast_body = fe.ast_body(); + auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, HasSubstr(R"(var x_2_1 : mat3x2 = x_1; +x_2_1[2u] = vec2(50.0, 60.0); +let x_2 : mat3x2 = x_2_1; +)")) << body_str; } TEST_F(SpvParserTest_CompositeInsert, Matrix_IndexTooBigError) { @@ -807,40 +539,13 @@ TEST_F(SpvParserTest_CompositeInsert, Matrix_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_2_1 - none - undefined - __mat_2_3__f32 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_2_1} - ScalarConstructor[not set]{2u} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __mat_2_3__f32 - { - Identifier[not set]{x_2_1} - } - } -})")) << body_str; + auto ast_body = fe.ast_body(); + auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, HasSubstr(R"(var x_2_1 : mat3x2 = x_1; +x_2_1[2u] = vec2(50.0, 60.0); +let x_2 : mat3x2 = x_2_1; +return; +)")) << body_str; } TEST_F(SpvParserTest_CompositeInsert, Array) { @@ -859,36 +564,12 @@ TEST_F(SpvParserTest_CompositeInsert, Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_2_1 - none - undefined - __array__u32_5 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_2_1} - ScalarConstructor[not set]{3u} - } - ScalarConstructor[not set]{20u} -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __array__u32_5 - { - Identifier[not set]{x_2_1} - } - } -})")) << body_str; + auto ast_body = fe.ast_body(); + auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, HasSubstr(R"(var x_2_1 : array = x_1; +x_2_1[3u] = 20u; +let x_2 : array = x_2_1; +)")) << body_str; } TEST_F(SpvParserTest_CompositeInsert, RuntimeArray_IsError) { @@ -928,55 +609,14 @@ TEST_F(SpvParserTest_CompositeInsert, Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_35 - none - undefined - __type_name_S - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __type_name_S - { - Identifier[not set]{x_35} - } - } -} -VariableDeclStatement{ - Variable{ - x_2_1 - none - undefined - __type_name_S - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_2_1} - Identifier[not set]{field2} - } - ScalarConstructor[not set]{30} -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __type_name_S - { - Identifier[not set]{x_2_1} - } - } -})")) << body_str; + auto ast_body = fe.ast_body(); + auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, HasSubstr(R"(var x_35 : S; +let x_1 : S = x_35; +var x_2_1 : S = x_1; +x_2_1.field2 = 30; +let x_2 : S = x_2_1; +)")) << body_str; } TEST_F(SpvParserTest_CompositeInsert, Struct_DifferOnlyInMemberName) { @@ -1018,104 +658,19 @@ TEST_F(SpvParserTest_CompositeInsert, Struct_DifferOnlyInMemberName) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - const std::string expected = R"(VariableDeclStatement{ - Variable{ - var0 - none - undefined - __type_name_S - } -} -VariableDeclStatement{ - Variable{ - var1 - none - undefined - __type_name_S_1 - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __type_name_S - { - Identifier[not set]{var0} - } - } -} -VariableDeclStatement{ - Variable{ - x_2_1 - none - undefined - __type_name_S - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_2_1} - Identifier[not set]{algo} - } - ScalarConstructor[not set]{10u} -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __type_name_S - { - Identifier[not set]{x_2_1} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __type_name_S_1 - { - Identifier[not set]{var1} - } - } -} -VariableDeclStatement{ - Variable{ - x_4_1 - none - undefined - __type_name_S_1 - { - Identifier[not set]{x_3} - } - } -} -Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_4_1} - Identifier[not set]{rithm} - } - ScalarConstructor[not set]{11u} -} -VariableDeclStatement{ - VariableConst{ - x_4 - none - undefined - __type_name_S_1 - { - Identifier[not set]{x_4_1} - } - } -} -Return{} + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + const std::string expected = R"(var var0 : S; +var var1 : S_1; +let x_1 : S = var0; +var x_2_1 : S = x_1; +x_2_1.algo = 10u; +let x_2 : S = x_2_1; +let x_3 : S_1 = var1; +var x_4_1 : S_1 = x_3; +x_4_1.rithm = 11u; +let x_4 : S_1 = x_4_1; +return; )"; EXPECT_EQ(got, expected) << got; } @@ -1158,64 +713,14 @@ TEST_F(SpvParserTest_CompositeInsert, Struct_Array_Matrix_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_37 - none - undefined - __type_name_S_1 - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __type_name_S_1 - { - Identifier[not set]{x_37} - } - } -} -VariableDeclStatement{ - Variable{ - x_2_1 - none - undefined - __type_name_S_1 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - MemberAccessor[not set]{ - ArrayAccessor[not set]{ - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{x_2_1} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{2u} - } - ScalarConstructor[not set]{0u} - } - Identifier[not set]{y} - } - ScalarConstructor[not set]{70.000000} -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __type_name_S_1 - { - Identifier[not set]{x_2_1} - } - } -})")) << body_str; + auto ast_body = fe.ast_body(); + auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, HasSubstr(R"(var x_37 : S_1; +let x_1 : S_1 = x_37; +var x_2_1 : S_1 = x_1; +x_2_1.field1[2u][0u].y = 70.0; +let x_2 : S_1 = x_2_1; +)")) << body_str; } using SpvParserTest_CopyObject = SpvParserTest; @@ -1233,29 +738,11 @@ TEST_F(SpvParserTest_CopyObject, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - ScalarConstructor[not set]{3u} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_1 : u32 = 3u; +let x_2 : u32 = x_1; +)")); } TEST_F(SpvParserTest_CopyObject, Pointer) { @@ -1274,32 +761,11 @@ TEST_F(SpvParserTest_CopyObject, Pointer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __ptr_function__u32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_10} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __ptr_function__u32 - { - Identifier[not set]{x_1} - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_1 : ptr = &(x_10); +let x_2 : ptr = x_1; +)")); } using SpvParserTest_VectorShuffle = SpvParserTest; @@ -1320,34 +786,11 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __vec_4__u32 - { - TypeConstructor[not set]{ - __vec_4__u32 - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{y} - } - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{x} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{y} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{x} - } - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + "let x_10 : vec4 = vec4(x_2.y, x_2.x, x_1.y, x_1.x);")); } TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) { @@ -1363,49 +806,13 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __vec_4__u32 - { - TypeConstructor[not set]{ - __vec_4__u32 - MemberAccessor[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{4u} - ScalarConstructor[not set]{3u} - } - Identifier[not set]{y} - } - MemberAccessor[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{4u} - ScalarConstructor[not set]{3u} - } - Identifier[not set]{x} - } - MemberAccessor[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - Identifier[not set]{y} - } - MemberAccessor[not set]{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - Identifier[not set]{x} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : vec4 = vec4(" + "vec2(4u, 3u).y, " + "vec2(4u, 3u).x, " + "vec2(3u, 4u).y, " + "vec2(3u, 4u).x);")); } TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) { @@ -1422,22 +829,9 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{0u} - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{y} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_10 : vec2 = vec2(0u, x_1.y);")); } TEST_F(SpvParserTest_VectorShuffle, IndexTooBig_IsError) { @@ -1474,20 +868,9 @@ TEST_F(SpvParserTest_VectorExtractDynamic, SignedIndex) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} - } - } - } -})")) << got; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr("let x_10 : u32 = x_1[x_2];")) << got; } TEST_F(SpvParserTest_VectorExtractDynamic, UnsignedIndex) { @@ -1505,20 +888,9 @@ TEST_F(SpvParserTest_VectorExtractDynamic, UnsignedIndex) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(VariableConst{ - x_10 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} - } - } - } -})")) << got; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr("let x_10 : u32 = x_1[x_2];")) << got; } using SpvParserTest_VectorInsertDynamic = SpvParserTest; @@ -1539,38 +911,13 @@ TEST_F(SpvParserTest_VectorInsertDynamic, Sample) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"( -VariableDeclStatement{ - Variable{ - x_10_1 - none - undefined - __vec_2__u32 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_10_1} - Identifier[not set]{x_3} - } - Identifier[not set]{x_2} -} -VariableDeclStatement{ - VariableConst{ - x_10 - none - undefined - __vec_2__u32 - { - Identifier[not set]{x_10_1} - } - } -})")) << got - << assembly; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr(R"(var x_10_1 : vec2 = x_1; +x_10_1[x_3] = x_2; +let x_10 : vec2 = x_10_1; +)")) << got + << assembly; } TEST_F(SpvParserTest, DISABLED_WorkgroupSize_Overridable) { @@ -1607,7 +954,7 @@ TEST_F(SpvParserTest, DISABLED_WorkgroupSize_Overridable) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.Emit()) << p->error(); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); EXPECT_THAT(got, HasSubstr(R"( VariableConst{ Decorations{ diff --git a/src/reader/spirv/function_conversion_test.cc b/src/reader/spirv/function_conversion_test.cc index cdf4ff2d64..cf0777ac62 100644 --- a/src/reader/spirv/function_conversion_test.cc +++ b/src/reader/spirv/function_conversion_test.cc @@ -83,18 +83,9 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{50.000000} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = bitcast(50.0);")); } TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { @@ -109,22 +100,11 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Bitcast[not set]<__vec_2__f32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr( + "let x_1 : vec2 = bitcast>(vec2(10u, 20u));")); } TEST_F(SpvUnaryConversionTest, ConvertSToF_BadArg) { @@ -239,18 +219,9 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __f32 - { - TypeConstructor[not set]{ - __f32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = f32(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { @@ -266,20 +237,9 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __f32 - { - TypeConstructor[not set]{ - __f32 - Bitcast[not set]<__i32>{ - Identifier[not set]{x_30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = f32(bitcast(x_30));")); } TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) { @@ -295,18 +255,9 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = vec2(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { @@ -322,20 +273,10 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{x_30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = vec2(bitcast>(x_30));")); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_BadArgType) { @@ -386,20 +327,9 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __f32 - { - TypeConstructor[not set]{ - __f32 - Bitcast[not set]<__u32>{ - Identifier[not set]{x_30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = f32(bitcast(x_30));")); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) { @@ -415,18 +345,9 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __f32 - { - TypeConstructor[not set]{ - __f32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = f32(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { @@ -442,20 +363,10 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{x_30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = vec2(bitcast>(x_30));")); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) { @@ -471,18 +382,9 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = vec2(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_BadArgType) { @@ -534,18 +436,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __i32 - { - TypeConstructor[not set]{ - __i32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : i32 = i32(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { @@ -561,20 +454,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - TypeConstructor[not set]{ - __i32 - Identifier[not set]{x_30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = bitcast(i32(x_30));")); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) { @@ -590,18 +472,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = vec2(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { @@ -617,20 +490,10 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - Identifier[not set]{x_30} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = bitcast>(vec2(x_30));")); } TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_BadArgType) { @@ -698,18 +561,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __u32 - { - TypeConstructor[not set]{ - __u32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = u32(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned_IsError) { @@ -741,18 +595,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - Identifier[not set]{x_30} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = vec2(x_30);")); } TEST_F(SpvUnaryConversionTest, ConvertFToU_HoistedValue) { @@ -792,18 +637,9 @@ OpFunctionEnd ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{ - x_82 - none - undefined - __u32 - { - TypeConstructor[not set]{ - __u32 - Identifier[not set]{x_600} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_82 : u32 = u32(x_600);")); } // TODO(dneto): OpSConvert // only if multiple widths diff --git a/src/reader/spirv/function_decl_test.cc b/src/reader/spirv/function_decl_test.cc index 43808439df..f3da8926da 100644 --- a/src/reader/spirv/function_decl_test.cc +++ b/src/reader/spirv/function_decl_test.cc @@ -73,13 +73,9 @@ TEST_F(SpvParserTest, Emit_VoidFunctionWithoutParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.Emit()); - auto got = p->program().to_str(); - std::string expect = R"(Module{ - Function x_100 -> __void - () - { - Return{} - } + auto got = test::ToString(p->program()); + std::string expect = R"(fn x_100() { + return; } )"; EXPECT_EQ(got, expect); @@ -97,17 +93,9 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.Emit()); - auto got = p->program().to_str(); - std::string expect = R"(Module{ - Function x_200 -> __f32 - () - { - Return{ - { - ScalarConstructor[not set]{0.000000} - } - } - } + auto got = test::ToString(p->program()); + std::string expect = R"(fn x_200() -> f32 { + return 0.0; } )"; EXPECT_THAT(got, HasSubstr(expect)); @@ -130,32 +118,9 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.Emit()); - auto got = p->program().to_str(); - std::string expect = R"(Module{ - Function x_200 -> __void - ( - VariableConst{ - a - none - undefined - __u32 - } - VariableConst{ - b - none - undefined - __f32 - } - VariableConst{ - c - none - undefined - __i32 - } - ) - { - Return{} - } + auto got = test::ToString(p->program()); + std::string expect = R"(fn x_200(a : u32, b : f32, c : i32) { + return; } )"; EXPECT_THAT(got, HasSubstr(expect)); @@ -177,32 +142,9 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) { auto fe = p->function_emitter(200); EXPECT_TRUE(fe.Emit()); - auto got = p->program().to_str(); - std::string expect = R"(Module{ - Function x_200 -> __void - ( - VariableConst{ - x_14 - none - undefined - __u32 - } - VariableConst{ - x_15 - none - undefined - __f32 - } - VariableConst{ - x_16 - none - undefined - __i32 - } - ) - { - Return{} - } + auto got = test::ToString(p->program()); + std::string expect = R"(fn x_200(x_14 : u32, x_15 : f32, x_16 : i32) { + return; } )"; EXPECT_THAT(got, HasSubstr(expect)); diff --git a/src/reader/spirv/function_glsl_std_450_test.cc b/src/reader/spirv/function_glsl_std_450_test.cc index 2159ef0bd3..75cc71df36 100644 --- a/src/reader/spirv/function_glsl_std_450_test.cc +++ b/src/reader/spirv/function_glsl_std_450_test.cc @@ -183,24 +183,10 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, + HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + "(f1);")) << body; } @@ -215,24 +201,10 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, + HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + "(v2f1);")) << body; } @@ -247,25 +219,10 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{f1} - Identifier[not set]{f2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + "(f1, f2);")) << body; } @@ -280,25 +237,10 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2f1} - Identifier[not set]{v2f2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + + "(v2f1, v2f2);")) << body; } @@ -313,24 +255,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, + HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + "(f1);")) << body; } @@ -345,24 +273,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2f1);")) << body; } @@ -377,25 +291,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{f1} - Identifier[not set]{f2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + "(f1, f2);")) << body; } @@ -410,25 +309,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2f1} - Identifier[not set]{v2f2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2f1, v2f2);")) << body; } @@ -443,26 +327,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{f1} - Identifier[not set]{f2} - Identifier[not set]{f3} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + + "(f1, f2, f3);")) << body; } @@ -478,26 +346,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2f1} - Identifier[not set]{v2f2} - Identifier[not set]{v2f3} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2f1, v2f2, v2f3);")) << body; } @@ -512,25 +364,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{f1} - Identifier[not set]{i1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, HasSubstr("let x_1 : f32 = " + GetParam().wgsl_func + "(f1, i1);")) << body; } @@ -546,25 +383,10 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2f1} - Identifier[not set]{v2i1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2f1, v2i1);")) << body; } @@ -580,25 +402,10 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_3__f32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v3f1} - Identifier[not set]{v3f2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec3 = " + GetParam().wgsl_func + + "(v3f1, v3f2);")) << body; } @@ -682,24 +489,10 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{i1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, + HasSubstr("let x_1 : i32 = " + GetParam().wgsl_func + "(i1);")) << body; } @@ -715,24 +508,10 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2i1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2i1);")) << body; } @@ -748,25 +527,10 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{i1} - Identifier[not set]{i2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, HasSubstr("let x_1 : i32 = " + GetParam().wgsl_func + "(i1, i2);")) << body; } @@ -782,25 +546,10 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2i1} - Identifier[not set]{v2i2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2i1, v2i2);")) << body; } @@ -816,26 +565,10 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{i1} - Identifier[not set]{i2} - Identifier[not set]{i3} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : i32 = " + GetParam().wgsl_func + + "(i1, i2, i3);")) << body; } @@ -851,26 +584,10 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__i32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2i1} - Identifier[not set]{v2i2} - Identifier[not set]{v2i3} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2i1, v2i2, v2i3);")) << body; } @@ -898,25 +615,10 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{u1} - Identifier[not set]{u2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, HasSubstr("let x_1 : u32 = " + GetParam().wgsl_func + "(u1, u2);")) << body; } @@ -932,25 +634,10 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2u1} - Identifier[not set]{v2u2} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2u1, v2u2);")) << body; } @@ -965,26 +652,10 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{u1} - Identifier[not set]{u2} - Identifier[not set]{u3} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = " + GetParam().wgsl_func + + "(u1, u2, u3);")) << body; } @@ -1000,26 +671,10 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Call[not set]{ - Identifier[not set]{)" + - GetParam().wgsl_func + - R"(} - ( - Identifier[not set]{v2u1} - Identifier[not set]{v2u2} - Identifier[not set]{v2u3} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = " + GetParam().wgsl_func + + "(v2u1, v2u2, v2u3);")) << body; } @@ -1047,18 +702,9 @@ TEST_F(SpvParserTest, Normalize_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __f32 - { - ScalarConstructor[not set]{1.000000} - } - })")) - << body; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : f32 = 1.0;")) << body; } TEST_F(SpvParserTest, Normalize_Vector2) { @@ -1072,22 +718,9 @@ TEST_F(SpvParserTest, Normalize_Vector2) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{normalize} - ( - Identifier[not set]{v2f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = normalize(v2f1);")) << body; } @@ -1102,22 +735,9 @@ TEST_F(SpvParserTest, Normalize_Vector3) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_3__f32 - { - Call[not set]{ - Identifier[not set]{normalize} - ( - Identifier[not set]{v3f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec3 = normalize(v3f1);")) << body; } @@ -1132,22 +752,9 @@ TEST_F(SpvParserTest, Normalize_Vector4) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{normalize} - ( - Identifier[not set]{v4f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec4 = normalize(v4f1);")) << body; } @@ -1165,46 +772,16 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SAbs) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Call[not set]{ - Identifier[not set]{abs} - ( - Bitcast[not set]<__i32>{ - Identifier[not set]{u1} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr(R"(let x_1 : u32 = bitcast(abs(bitcast(u1)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Call[not set]{ - Identifier[not set]{abs} - ( - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u1} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(abs(bitcast>(v2u1)));)")) << body; } @@ -1219,52 +796,17 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMax) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Call[not set]{ - Identifier[not set]{max} - ( - Bitcast[not set]<__i32>{ - Identifier[not set]{u1} - } - Bitcast[not set]<__i32>{ - Identifier[not set]{u2} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + R"(let x_1 : u32 = bitcast(max(bitcast(u1), bitcast(u2)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Call[not set]{ - Identifier[not set]{max} - ( - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u1} - } - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u2} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(max(bitcast>(v2u1), bitcast>(v2u2)));)")) << body; } @@ -1279,52 +821,17 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMin) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Call[not set]{ - Identifier[not set]{min} - ( - Bitcast[not set]<__i32>{ - Identifier[not set]{u1} - } - Bitcast[not set]<__i32>{ - Identifier[not set]{u2} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + R"(let x_1 : u32 = bitcast(min(bitcast(u1), bitcast(u2)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Call[not set]{ - Identifier[not set]{min} - ( - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u1} - } - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u2} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(min(bitcast>(v2u1), bitcast>(v2u2)));)")) << body; } @@ -1339,54 +846,17 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SClamp) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Bitcast[not set]<__u32>{ - Call[not set]{ - Identifier[not set]{clamp} - ( - Bitcast[not set]<__i32>{ - Identifier[not set]{u1} - } - Identifier[not set]{i2} - Bitcast[not set]<__i32>{ - Identifier[not set]{u3} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + R"(let x_1 : u32 = bitcast(clamp(bitcast(u1), i2, bitcast(u3)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__u32 - { - Bitcast[not set]<__vec_2__u32>{ - Call[not set]{ - Identifier[not set]{clamp} - ( - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u1} - } - Identifier[not set]{v2i2} - Bitcast[not set]<__vec_2__i32>{ - Identifier[not set]{v2u3} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(clamp(bitcast>(v2u1), v2i2, bitcast>(v2u3)));)")) << body; } @@ -1401,52 +871,17 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMax) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Bitcast[not set]<__i32>{ - Call[not set]{ - Identifier[not set]{max} - ( - Bitcast[not set]<__u32>{ - Identifier[not set]{i1} - } - Bitcast[not set]<__u32>{ - Identifier[not set]{i2} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + R"(let x_1 : i32 = bitcast(max(bitcast(i1), bitcast(i2)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Call[not set]{ - Identifier[not set]{max} - ( - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{v2i1} - } - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{v2i2} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(max(bitcast>(v2i1), bitcast>(v2i2)));)")) << body; } @@ -1461,52 +896,17 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMin) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Bitcast[not set]<__i32>{ - Call[not set]{ - Identifier[not set]{min} - ( - Bitcast[not set]<__u32>{ - Identifier[not set]{i1} - } - Bitcast[not set]<__u32>{ - Identifier[not set]{i2} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + R"(let x_1 : i32 = bitcast(min(bitcast(i1), bitcast(i2)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Call[not set]{ - Identifier[not set]{min} - ( - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{v2i1} - } - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{v2i2} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(min(bitcast>(v2i1), bitcast>(v2i2)));)")) << body; } @@ -1521,54 +921,17 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UClamp) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __i32 - { - Bitcast[not set]<__i32>{ - Call[not set]{ - Identifier[not set]{clamp} - ( - Bitcast[not set]<__u32>{ - Identifier[not set]{i1} - } - Identifier[not set]{u2} - Bitcast[not set]<__u32>{ - Identifier[not set]{i3} - } - ) - } - } - } - })")) + auto ast_body = fe.ast_body(); + auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT( + body, + HasSubstr( + R"(let x_1 : i32 = bitcast(clamp(bitcast(i1), u2, bitcast(i3)));)")) << body; - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __vec_2__i32 - { - Bitcast[not set]<__vec_2__i32>{ - Call[not set]{ - Identifier[not set]{clamp} - ( - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{v2i1} - } - Identifier[not set]{v2u2} - Bitcast[not set]<__vec_2__u32>{ - Identifier[not set]{v2i3} - } - ) - } - } - } - })")) + EXPECT_THAT( + body, + HasSubstr( + R"(let x_2 : vec2 = bitcast>(clamp(bitcast>(v2i1), v2u2, bitcast>(v2i3)));)")) << body; } @@ -1599,24 +962,10 @@ TEST_P(SpvParserTest_GlslStd450_DataPacking, Valid) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{)" + - param.wgsl_func + R"(} - ( - Identifier[not set]{v)" + - std::to_string(param.vec_size) + R"(f1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = " + param.wgsl_func + "(v" + + std::to_string(param.vec_size) + "f1);")) << body; } @@ -1644,24 +993,13 @@ TEST_P(SpvParserTest_GlslStd450_DataUnpacking, Valid) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body, HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - )" + std::string(param.vec_size == 2 ? "__vec_2__f32" : "__vec_4__f32") + - R"( - { - Call[not set]{ - Identifier[not set]{)" + - param.wgsl_func + R"(} - ( - Identifier[not set]{u1} - ) - } - } - })")) + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : " + + std::string(param.vec_size == 2 ? "vec2" + : "vec4") + + + +" = " + param.wgsl_func + "(u1);")) << body; } @@ -1684,34 +1022,10 @@ TEST_F(SpvParserTest, GlslStd450_Refract_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableConst{ - x_1 - none - undefined - __f32 - { - MemberAccessor[not set]{ - Call[not set]{ - Identifier[not set]{refract} - ( - TypeConstructor[not set]{ - __vec_2__f32 - Identifier[not set]{f1} - ScalarConstructor[not set]{0.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - Identifier[not set]{f2} - ScalarConstructor[not set]{0.000000} - } - Identifier[not set]{f3} - ) - } - Identifier[not set]{x} - } - } - })"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = + R"(let x_1 : f32 = refract(vec2(f1, 0.0), vec2(f2, 0.0), f3).x;)"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -1726,24 +1040,11 @@ TEST_F(SpvParserTest, GlslStd450_Refract_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{refract} - ( - Identifier[not set]{v2f1} - Identifier[not set]{v2f2} - Identifier[not set]{f3} - ) - } - })"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = R"(let x_1 : vec2 = refract(v2f1, v2f2, f3);)"; - EXPECT_THAT(body, HasSubstr(expected)); + EXPECT_THAT(body, HasSubstr(expected)) << body; } TEST_F(SpvParserTest, GlslStd450_FaceForward_Scalar) { @@ -1757,54 +1058,13 @@ TEST_F(SpvParserTest, GlslStd450_FaceForward_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); // The %99 sum only has one use. Ensure it is evaluated only once by // making a let-declaration for it, since it is the normal operand to // the builtin function, and code generation uses it twice. - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __f32 - { - Binary[not set]{ - Identifier[not set]{f1} - add - Identifier[not set]{f1} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{select} - ( - UnaryOp[not set]{ - negation - Identifier[not set]{x_99} - } - Identifier[not set]{x_99} - Binary[not set]{ - Binary[not set]{ - Identifier[not set]{f2} - multiply - Identifier[not set]{f3} - } - less_than - ScalarConstructor[not set]{0.000000} - } - ) - } - } - } -})"; + const auto* expected = + R"(let x_1 : f32 = select(-(x_99), x_99, ((f2 * f3) < 0.0));)"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -1820,24 +1080,12 @@ TEST_F(SpvParserTest, GlslStd450_FaceForward_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{faceForward} - ( - Identifier[not set]{v2f1} - Identifier[not set]{v2f2} - Identifier[not set]{v2f3} - ) - } - })"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = + R"(let x_1 : vec2 = faceForward(v2f1, v2f2, v2f3);)"; - EXPECT_THAT(body, HasSubstr(expected)); + EXPECT_THAT(body, HasSubstr(expected)) << body; } TEST_F(SpvParserTest, GlslStd450_Reflect_Scalar) { @@ -1852,67 +1100,13 @@ TEST_F(SpvParserTest, GlslStd450_Reflect_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); // The %99 sum only has one use. Ensure it is evaluated only once by // making a let-declaration for it, since it is the normal operand to // the builtin function, and code generation uses it twice. - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_98 - none - undefined - __f32 - { - Binary[not set]{ - Identifier[not set]{f1} - add - Identifier[not set]{f1} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __f32 - { - Binary[not set]{ - Identifier[not set]{f2} - add - Identifier[not set]{f2} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __f32 - { - Binary[not set]{ - Identifier[not set]{x_98} - subtract - Binary[not set]{ - ScalarConstructor[not set]{2.000000} - multiply - Binary[not set]{ - Identifier[not set]{x_99} - multiply - Binary[not set]{ - Identifier[not set]{x_99} - multiply - Identifier[not set]{x_98} - } - } - } - } - } - } -})"; + const auto* expected = + R"(let x_1 : f32 = (x_98 - (2.0 * (x_99 * (x_99 * x_98))));)"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -1929,52 +1123,13 @@ TEST_F(SpvParserTest, GlslStd450_Reflect_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_98 - none - undefined - __vec_2__f32 - { - Binary[not set]{ - Identifier[not set]{v2f1} - add - Identifier[not set]{v2f1} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__f32 - { - Binary[not set]{ - Identifier[not set]{v2f2} - add - Identifier[not set]{v2f2} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{reflect} - ( - Identifier[not set]{x_98} - Identifier[not set]{x_99} - ) - } - })"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = R"( +let x_98 : vec2 = (v2f1 + v2f1); +let x_99 : vec2 = (v2f2 + v2f2); +let x_1 : vec2 = reflect(x_98, x_99); +)"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -1989,22 +1144,9 @@ TEST_F(SpvParserTest, GlslStd450_Degrees_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __f32 - { - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - multiply - ScalarConstructor[not set]{57.295780} - } - } - } -})"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = "let x_1 : f32 = (50.0 * 57.295780182);"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -2019,30 +1161,10 @@ TEST_F(SpvParserTest, GlslStd450_Degrees_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_3__f32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_3__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{70.000000} - ScalarConstructor[not set]{50.000000} - } - multiply - TypeConstructor[not set]{ - __vec_3__f32 - ScalarConstructor[not set]{57.295780} - } - } - } - } -})"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = + R"(let x_1 : vec3 = (vec3(60.0, 70.0, 50.0) * vec3(57.295780182));)"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -2057,22 +1179,9 @@ TEST_F(SpvParserTest, GlslStd450_Radians_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __f32 - { - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - multiply - ScalarConstructor[not set]{0.017453} - } - } - } -})"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = "let x_1 : f32 = (50.0 * 0.017453292);"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -2087,30 +1196,10 @@ TEST_F(SpvParserTest, GlslStd450_Radians_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_3__f32 - { - Binary[not set]{ - TypeConstructor[not set]{ - __vec_3__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{70.000000} - ScalarConstructor[not set]{50.000000} - } - multiply - TypeConstructor[not set]{ - __vec_3__f32 - ScalarConstructor[not set]{0.017453} - } - } - } - } -})"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = + R"(let x_1 : vec3 = (vec3(60.0, 70.0, 50.0) * vec3(0.017453292));)"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -2126,27 +1215,9 @@ TEST_F(SpvParserTest, GlslStd450_Ldexp_Scalar_Float_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{ldexp} - ( - Identifier[not set]{f1} - TypeConstructor[not set]{ - __i32 - Identifier[not set]{u1} - } - ) - } - } - } -})"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = "let x_1 : f32 = ldexp(f1, i32(u1));"; EXPECT_THAT(body, HasSubstr(expected)) << body; } @@ -2161,27 +1232,9 @@ TEST_F(SpvParserTest, GlslStd450_Ldexp_Vector_Floatvec_Uintvec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__f32 - { - Call[not set]{ - Identifier[not set]{ldexp} - ( - Identifier[not set]{v2f1} - TypeConstructor[not set]{ - __vec_2__i32 - Identifier[not set]{v2u1} - } - ) - } - } - } -})"; + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + const auto* expected = "let x_1 : vec2 = ldexp(v2f1, vec2(v2u1));"; EXPECT_THAT(body, HasSubstr(expected)) << body; } diff --git a/src/reader/spirv/function_logical_test.cc b/src/reader/spirv/function_logical_test.cc index bb0005b2cd..a230c7113a 100644 --- a/src/reader/spirv/function_logical_test.cc +++ b/src/reader/spirv/function_logical_test.cc @@ -72,123 +72,52 @@ std::string Preamble() { // Returns the AST dump for a given SPIR-V assembly constant. std::string AstFor(std::string assembly) { if (assembly == "v2bool_t_f") { - return R"(TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{true} - ScalarConstructor[not set]{false} - })"; + return "vec2(true, false)"; } if (assembly == "v2bool_f_t") { - return R"(TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{false} - ScalarConstructor[not set]{true} - })"; + return "vec2(false, true)"; } if (assembly == "v2uint_10_20") { - return R"(TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - })"; + return "vec2(10u, 20u)"; } if (assembly == "cast_uint_10") { - return R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })"; + return "bitcast(10u)"; } if (assembly == "cast_uint_20") { - return R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{20u} - })"; + return "bitcast(20u)"; } if (assembly == "cast_v2uint_10_20") { - return R"(Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - })"; + return "bitcast>(vec2(10u, 20u))"; } if (assembly == "v2uint_20_10") { - return R"(TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - })"; + return "vec2(20u, 10u)"; } if (assembly == "cast_v2uint_20_10") { - return R"(Bitcast[not set]<__vec_2__i32>{ - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - })"; + return "bitcast>(vec2(20u, 10u))"; } if (assembly == "cast_int_30") { - return R"(Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{30} - })"; + return "bitcast(30)"; } if (assembly == "cast_int_40") { - return R"(Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - })"; + return "bitcast(40)"; } if (assembly == "v2int_30_40") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - })"; + return "vec2(30, 40)"; } if (assembly == "cast_v2int_30_40") { - return R"(Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{30} - ScalarConstructor[not set]{40} - } - })"; + return "bitcast>(vec2(30, 40))"; } if (assembly == "v2int_40_30") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - })"; + return "vec2(40, 30)"; } if (assembly == "cast_v2int_40_30") { - return R"(Bitcast[not set]<__vec_2__u32>{ - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - } - })"; - } - if (assembly == "v2int_40_30") { - return R"(TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{40} - ScalarConstructor[not set]{30} - })"; + return "bitcast>(vec2(40, 30))"; } if (assembly == "v2float_50_60") { - return R"(TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - })"; + return "vec2(50.0, 60.0)"; } if (assembly == "v2float_60_50") { - return R"(TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - })"; + return "vec2(60.0, 50.0)"; } return "bad case"; } @@ -207,19 +136,9 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - ScalarConstructor[not set]{true} - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !(true);")); } TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) { @@ -234,23 +153,9 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{true} - ScalarConstructor[not set]{false} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = !(vec2(true, false));")); } struct BinaryData { @@ -290,15 +195,10 @@ TEST_P(SpvBinaryLogicalTest, EmitExpression) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); std::ostringstream ss; - ss << R"(VariableConst{ - x_1 - none - undefined - )" - << GetParam().ast_type << "\n {\n Binary[not set]{" - << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op - << "\n " << GetParam().ast_rhs; - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(ss.str())) + ss << "let x_1 : " << GetParam().ast_type << " = (" << GetParam().ast_lhs + << " " << GetParam().ast_op << " " << GetParam().ast_rhs << ");"; + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(ss.str())) << assembly; } @@ -307,206 +207,175 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryLogicalTest, ::testing::Values( // uint uint - BinaryData{"bool", "uint_10", "OpIEqual", "uint_20", "__bool", - "ScalarConstructor[not set]{10u}", "equal", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "uint_10", "OpIEqual", "uint_20", "bool", "10u", + "==", "20u"}, // int int - BinaryData{"bool", "int_30", "OpIEqual", "int_40", "__bool", - "ScalarConstructor[not set]{30}", "equal", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "int_30", "OpIEqual", "int_40", "bool", "30", + "==", "40"}, // uint int - BinaryData{"bool", "uint_10", "OpIEqual", "int_40", "__bool", - "ScalarConstructor[not set]{10u}", "equal", - R"(Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - })"}, + BinaryData{"bool", "uint_10", "OpIEqual", "int_40", "bool", "10u", + "==", "bitcast(40)"}, // int uint - BinaryData{"bool", "int_40", "OpIEqual", "uint_10", "__bool", - "ScalarConstructor[not set]{40}", "equal", - R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })"}, + BinaryData{"bool", "int_40", "OpIEqual", "uint_10", "bool", "40", + "==", "bitcast(10u)"}, // v2uint v2uint BinaryData{"v2bool", "v2uint_10_20", "OpIEqual", "v2uint_20_10", - "__vec_2__bool", AstFor("v2uint_10_20"), "equal", - AstFor("v2uint_20_10")}, + "vec2", AstFor("v2uint_10_20"), + "==", AstFor("v2uint_20_10")}, // v2int v2int BinaryData{"v2bool", "v2int_30_40", "OpIEqual", "v2int_40_30", - "__vec_2__bool", AstFor("v2int_30_40"), "equal", - AstFor("v2int_40_30")})); + "vec2", AstFor("v2int_30_40"), + "==", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FOrdEqual, SpvBinaryLogicalTest, - ::testing::Values( - BinaryData{"bool", "float_50", "OpFOrdEqual", "float_60", "__bool", - "ScalarConstructor[not set]{50.000000}", "equal", - "ScalarConstructor[not set]{60.000000}"}, - BinaryData{"v2bool", "v2float_50_60", "OpFOrdEqual", "v2float_60_50", - "__vec_2__bool", AstFor("v2float_50_60"), "equal", - AstFor("v2float_60_50")})); + ::testing::Values(BinaryData{"bool", "float_50", "OpFOrdEqual", "float_60", + "bool", "50.0", "==", "60.0"}, + BinaryData{"v2bool", "v2float_50_60", "OpFOrdEqual", + "v2float_60_50", "vec2", + AstFor("v2float_50_60"), + "==", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_INotEqual, SpvBinaryLogicalTest, ::testing::Values( // Both uint - BinaryData{"bool", "uint_10", "OpINotEqual", "uint_20", "__bool", - "ScalarConstructor[not set]{10u}", "not_equal", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "uint_10", "OpINotEqual", "uint_20", "bool", "10u", + "!=", "20u"}, // Both int - BinaryData{"bool", "int_30", "OpINotEqual", "int_40", "__bool", - "ScalarConstructor[not set]{30}", "not_equal", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "int_30", "OpINotEqual", "int_40", "bool", "30", + "!=", "40"}, // uint int - BinaryData{"bool", "uint_10", "OpINotEqual", "int_40", "__bool", - "ScalarConstructor[not set]{10u}", "not_equal", - R"(Bitcast[not set]<__u32>{ - ScalarConstructor[not set]{40} - })"}, + BinaryData{"bool", "uint_10", "OpINotEqual", "int_40", "bool", "10u", + "!=", "bitcast(40)"}, // int uint - BinaryData{"bool", "int_40", "OpINotEqual", "uint_10", "__bool", - "ScalarConstructor[not set]{40}", "not_equal", - R"(Bitcast[not set]<__i32>{ - ScalarConstructor[not set]{10u} - })"}, + BinaryData{"bool", "int_40", "OpINotEqual", "uint_10", "bool", "40", + "!=", "bitcast(10u)"}, // Both v2uint BinaryData{"v2bool", "v2uint_10_20", "OpINotEqual", "v2uint_20_10", - "__vec_2__bool", AstFor("v2uint_10_20"), "not_equal", - AstFor("v2uint_20_10")}, + "vec2", AstFor("v2uint_10_20"), + "!=", AstFor("v2uint_20_10")}, // Both v2int BinaryData{"v2bool", "v2int_30_40", "OpINotEqual", "v2int_40_30", - "__vec_2__bool", AstFor("v2int_30_40"), "not_equal", - AstFor("v2int_40_30")})); + "vec2", AstFor("v2int_30_40"), + "!=", AstFor("v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FOrdNotEqual, SpvBinaryLogicalTest, - ::testing::Values( - BinaryData{"bool", "float_50", "OpFOrdNotEqual", "float_60", "__bool", - "ScalarConstructor[not set]{50.000000}", "not_equal", - "ScalarConstructor[not set]{60.000000}"}, - BinaryData{"v2bool", "v2float_50_60", "OpFOrdNotEqual", "v2float_60_50", - "__vec_2__bool", AstFor("v2float_50_60"), "not_equal", - AstFor("v2float_60_50")})); + ::testing::Values(BinaryData{"bool", "float_50", "OpFOrdNotEqual", + "float_60", "bool", "50.0", "!=", "60.0"}, + BinaryData{"v2bool", "v2float_50_60", "OpFOrdNotEqual", + "v2float_60_50", "vec2", + AstFor("v2float_50_60"), + "!=", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FOrdLessThan, SpvBinaryLogicalTest, - ::testing::Values( - BinaryData{"bool", "float_50", "OpFOrdLessThan", "float_60", "__bool", - "ScalarConstructor[not set]{50.000000}", "less_than", - "ScalarConstructor[not set]{60.000000}"}, - BinaryData{"v2bool", "v2float_50_60", "OpFOrdLessThan", "v2float_60_50", - "__vec_2__bool", AstFor("v2float_50_60"), "less_than", - AstFor("v2float_60_50")})); + ::testing::Values(BinaryData{"bool", "float_50", "OpFOrdLessThan", + "float_60", "bool", "50.0", "<", "60.0"}, + BinaryData{"v2bool", "v2float_50_60", "OpFOrdLessThan", + "v2float_60_50", "vec2", + AstFor("v2float_50_60"), "<", + AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FOrdLessThanEqual, SpvBinaryLogicalTest, - ::testing::Values( - BinaryData{"bool", "float_50", "OpFOrdLessThanEqual", "float_60", - "__bool", "ScalarConstructor[not set]{50.000000}", - "less_than_equal", "ScalarConstructor[not set]{60.000000}"}, - BinaryData{"v2bool", "v2float_50_60", "OpFOrdLessThanEqual", - "v2float_60_50", "__vec_2__bool", AstFor("v2float_50_60"), - "less_than_equal", AstFor("v2float_60_50")})); + ::testing::Values(BinaryData{"bool", "float_50", "OpFOrdLessThanEqual", + "float_60", "bool", "50.0", "<=", "60.0"}, + BinaryData{"v2bool", "v2float_50_60", + "OpFOrdLessThanEqual", "v2float_60_50", + "vec2", AstFor("v2float_50_60"), + "<=", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FOrdGreaterThan, SpvBinaryLogicalTest, - ::testing::Values( - BinaryData{"bool", "float_50", "OpFOrdGreaterThan", "float_60", - "__bool", "ScalarConstructor[not set]{50.000000}", - "greater_than", "ScalarConstructor[not set]{60.000000}"}, - BinaryData{"v2bool", "v2float_50_60", "OpFOrdGreaterThan", - "v2float_60_50", "__vec_2__bool", AstFor("v2float_50_60"), - "greater_than", AstFor("v2float_60_50")})); + ::testing::Values(BinaryData{"bool", "float_50", "OpFOrdGreaterThan", + "float_60", "bool", "50.0", ">", "60.0"}, + BinaryData{"v2bool", "v2float_50_60", "OpFOrdGreaterThan", + "v2float_60_50", "vec2", + AstFor("v2float_50_60"), ">", + AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_FOrdGreaterThanEqual, SpvBinaryLogicalTest, - ::testing::Values( - BinaryData{"bool", "float_50", "OpFOrdGreaterThanEqual", "float_60", - "__bool", "ScalarConstructor[not set]{50.000000}", - "greater_than_equal", - "ScalarConstructor[not set]{60.000000}"}, - BinaryData{"v2bool", "v2float_50_60", "OpFOrdGreaterThanEqual", - "v2float_60_50", "__vec_2__bool", AstFor("v2float_50_60"), - "greater_than_equal", AstFor("v2float_60_50")})); + ::testing::Values(BinaryData{"bool", "float_50", "OpFOrdGreaterThanEqual", + "float_60", "bool", "50.0", ">=", "60.0"}, + BinaryData{"v2bool", "v2float_50_60", + "OpFOrdGreaterThanEqual", "v2float_60_50", + "vec2", AstFor("v2float_50_60"), + ">=", AstFor("v2float_60_50")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_LogicalAnd, SpvBinaryLogicalTest, ::testing::Values(BinaryData{"bool", "true", "OpLogicalAnd", "false", - "__bool", "ScalarConstructor[not set]{true}", - "and", "ScalarConstructor[not set]{false}"}, + "bool", "true", "&", "false"}, BinaryData{"v2bool", "v2bool_t_f", "OpLogicalAnd", - "v2bool_f_t", "__vec_2__bool", - AstFor("v2bool_t_f"), "and", + "v2bool_f_t", "vec2", + AstFor("v2bool_t_f"), "&", AstFor("v2bool_f_t")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_LogicalOr, SpvBinaryLogicalTest, - ::testing::Values(BinaryData{"bool", "true", "OpLogicalOr", "false", - "__bool", "ScalarConstructor[not set]{true}", - "or", "ScalarConstructor[not set]{false}"}, + ::testing::Values(BinaryData{"bool", "true", "OpLogicalOr", "false", "bool", + "true", "|", "false"}, BinaryData{"v2bool", "v2bool_t_f", "OpLogicalOr", - "v2bool_f_t", "__vec_2__bool", - AstFor("v2bool_t_f"), "or", + "v2bool_f_t", "vec2", + AstFor("v2bool_t_f"), "|", AstFor("v2bool_f_t")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_LogicalEqual, SpvBinaryLogicalTest, ::testing::Values(BinaryData{"bool", "true", "OpLogicalEqual", "false", - "__bool", "ScalarConstructor[not set]{true}", - "equal", "ScalarConstructor[not set]{false}"}, + "bool", "true", "==", "false"}, BinaryData{"v2bool", "v2bool_t_f", "OpLogicalEqual", - "v2bool_f_t", "__vec_2__bool", - AstFor("v2bool_t_f"), "equal", - AstFor("v2bool_f_t")})); + "v2bool_f_t", "vec2", + AstFor("v2bool_t_f"), + "==", AstFor("v2bool_f_t")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_LogicalNotEqual, SpvBinaryLogicalTest, ::testing::Values(BinaryData{"bool", "true", "OpLogicalNotEqual", "false", - "__bool", "ScalarConstructor[not set]{true}", - "not_equal", - "ScalarConstructor[not set]{false}"}, + "bool", "true", "!=", "false"}, BinaryData{"v2bool", "v2bool_t_f", "OpLogicalNotEqual", - "v2bool_f_t", "__vec_2__bool", - AstFor("v2bool_t_f"), "not_equal", - AstFor("v2bool_f_t")})); + "v2bool_f_t", "vec2", + AstFor("v2bool_t_f"), + "!=", AstFor("v2bool_f_t")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_UGreaterThan, SpvBinaryLogicalTest, ::testing::Values( // Both unsigned - BinaryData{"bool", "uint_10", "OpUGreaterThan", "uint_20", "__bool", - "ScalarConstructor[not set]{10u}", "greater_than", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "uint_10", "OpUGreaterThan", "uint_20", "bool", + "10u", ">", "20u"}, // First arg signed - BinaryData{"bool", "int_30", "OpUGreaterThan", "uint_20", "__bool", - AstFor("cast_int_30"), "greater_than", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "int_30", "OpUGreaterThan", "uint_20", "bool", + AstFor("cast_int_30"), ">", "20u"}, // Second arg signed - BinaryData{"bool", "uint_10", "OpUGreaterThan", "int_40", "__bool", - "ScalarConstructor[not set]{10u}", "greater_than", - AstFor("cast_int_40")}, + BinaryData{"bool", "uint_10", "OpUGreaterThan", "int_40", "bool", "10u", + ">", AstFor("cast_int_40")}, // Vector, both unsigned BinaryData{"v2bool", "v2uint_10_20", "OpUGreaterThan", "v2uint_20_10", - "__vec_2__bool", AstFor("v2uint_10_20"), "greater_than", + "vec2", AstFor("v2uint_10_20"), ">", AstFor("v2uint_20_10")}, // First arg signed BinaryData{"v2bool", "v2int_30_40", "OpUGreaterThan", "v2uint_20_10", - "__vec_2__bool", AstFor("cast_v2int_30_40"), "greater_than", + "vec2", AstFor("cast_v2int_30_40"), ">", AstFor("v2uint_20_10")}, // Second arg signed BinaryData{"v2bool", "v2uint_10_20", "OpUGreaterThan", "v2int_40_30", - "__vec_2__bool", AstFor("v2uint_10_20"), "greater_than", + "vec2", AstFor("v2uint_10_20"), ">", AstFor("cast_v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( @@ -514,57 +383,51 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryLogicalTest, ::testing::Values( // Both unsigned - BinaryData{"bool", "uint_10", "OpUGreaterThanEqual", "uint_20", - "__bool", "ScalarConstructor[not set]{10u}", - "greater_than_equal", "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "uint_10", "OpUGreaterThanEqual", "uint_20", "bool", + "10u", ">=", "20u"}, // First arg signed - BinaryData{"bool", "int_30", "OpUGreaterThanEqual", "uint_20", "__bool", - AstFor("cast_int_30"), "greater_than_equal", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "int_30", "OpUGreaterThanEqual", "uint_20", "bool", + AstFor("cast_int_30"), ">=", "20u"}, // Second arg signed - BinaryData{"bool", "uint_10", "OpUGreaterThanEqual", "int_40", "__bool", - "ScalarConstructor[not set]{10u}", "greater_than_equal", - AstFor("cast_int_40")}, + BinaryData{"bool", "uint_10", "OpUGreaterThanEqual", "int_40", "bool", + "10u", ">=", AstFor("cast_int_40")}, // Vector, both unsigned BinaryData{"v2bool", "v2uint_10_20", "OpUGreaterThanEqual", - "v2uint_20_10", "__vec_2__bool", AstFor("v2uint_10_20"), - "greater_than_equal", AstFor("v2uint_20_10")}, + "v2uint_20_10", "vec2", AstFor("v2uint_10_20"), + ">=", AstFor("v2uint_20_10")}, // First arg signed BinaryData{"v2bool", "v2int_30_40", "OpUGreaterThanEqual", - "v2uint_20_10", "__vec_2__bool", AstFor("cast_v2int_30_40"), - "greater_than_equal", AstFor("v2uint_20_10")}, + "v2uint_20_10", "vec2", AstFor("cast_v2int_30_40"), + ">=", AstFor("v2uint_20_10")}, // Second arg signed BinaryData{"v2bool", "v2uint_10_20", "OpUGreaterThanEqual", - "v2int_40_30", "__vec_2__bool", AstFor("v2uint_10_20"), - "greater_than_equal", AstFor("cast_v2int_40_30")})); + "v2int_40_30", "vec2", AstFor("v2uint_10_20"), + ">=", AstFor("cast_v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_ULessThan, SpvBinaryLogicalTest, ::testing::Values( // Both unsigned - BinaryData{"bool", "uint_10", "OpULessThan", "uint_20", "__bool", - "ScalarConstructor[not set]{10u}", "less_than", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "uint_10", "OpULessThan", "uint_20", "bool", "10u", + "<", "20u"}, // First arg signed - BinaryData{"bool", "int_30", "OpULessThan", "uint_20", "__bool", - AstFor("cast_int_30"), "less_than", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "int_30", "OpULessThan", "uint_20", "bool", + AstFor("cast_int_30"), "<", "20u"}, // Second arg signed - BinaryData{"bool", "uint_10", "OpULessThan", "int_40", "__bool", - "ScalarConstructor[not set]{10u}", "less_than", - AstFor("cast_int_40")}, + BinaryData{"bool", "uint_10", "OpULessThan", "int_40", "bool", "10u", + "<", AstFor("cast_int_40")}, // Vector, both unsigned BinaryData{"v2bool", "v2uint_10_20", "OpULessThan", "v2uint_20_10", - "__vec_2__bool", AstFor("v2uint_10_20"), "less_than", + "vec2", AstFor("v2uint_10_20"), "<", AstFor("v2uint_20_10")}, // First arg signed BinaryData{"v2bool", "v2int_30_40", "OpULessThan", "v2uint_20_10", - "__vec_2__bool", AstFor("cast_v2int_30_40"), "less_than", + "vec2", AstFor("cast_v2int_30_40"), "<", AstFor("v2uint_20_10")}, // Second arg signed BinaryData{"v2bool", "v2uint_10_20", "OpULessThan", "v2int_40_30", - "__vec_2__bool", AstFor("v2uint_10_20"), "less_than", + "vec2", AstFor("v2uint_10_20"), "<", AstFor("cast_v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( @@ -572,57 +435,51 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryLogicalTest, ::testing::Values( // Both unsigned - BinaryData{"bool", "uint_10", "OpULessThanEqual", "uint_20", "__bool", - "ScalarConstructor[not set]{10u}", "less_than_equal", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "uint_10", "OpULessThanEqual", "uint_20", "bool", + "10u", "<=", "20u"}, // First arg signed - BinaryData{"bool", "int_30", "OpULessThanEqual", "uint_20", "__bool", - AstFor("cast_int_30"), "less_than_equal", - "ScalarConstructor[not set]{20u}"}, + BinaryData{"bool", "int_30", "OpULessThanEqual", "uint_20", "bool", + AstFor("cast_int_30"), "<=", "20u"}, // Second arg signed - BinaryData{"bool", "uint_10", "OpULessThanEqual", "int_40", "__bool", - "ScalarConstructor[not set]{10u}", "less_than_equal", - AstFor("cast_int_40")}, + BinaryData{"bool", "uint_10", "OpULessThanEqual", "int_40", "bool", + "10u", "<=", AstFor("cast_int_40")}, // Vector, both unsigned BinaryData{"v2bool", "v2uint_10_20", "OpULessThanEqual", "v2uint_20_10", - "__vec_2__bool", AstFor("v2uint_10_20"), "less_than_equal", - AstFor("v2uint_20_10")}, + "vec2", AstFor("v2uint_10_20"), + "<=", AstFor("v2uint_20_10")}, // First arg signed BinaryData{"v2bool", "v2int_30_40", "OpULessThanEqual", "v2uint_20_10", - "__vec_2__bool", AstFor("cast_v2int_30_40"), - "less_than_equal", AstFor("v2uint_20_10")}, + "vec2", AstFor("cast_v2int_30_40"), + "<=", AstFor("v2uint_20_10")}, // Second arg signed BinaryData{"v2bool", "v2uint_10_20", "OpULessThanEqual", "v2int_40_30", - "__vec_2__bool", AstFor("v2uint_10_20"), "less_than_equal", - AstFor("cast_v2int_40_30")})); + "vec2", AstFor("v2uint_10_20"), + "<=", AstFor("cast_v2int_40_30")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_SGreaterThan, SpvBinaryLogicalTest, ::testing::Values( // Both signed - BinaryData{"bool", "int_30", "OpSGreaterThan", "int_40", "__bool", - "ScalarConstructor[not set]{30}", "greater_than", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "int_30", "OpSGreaterThan", "int_40", "bool", "30", + ">", "40"}, // First arg unsigned - BinaryData{"bool", "uint_10", "OpSGreaterThan", "int_40", "__bool", - AstFor("cast_uint_10"), "greater_than", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "uint_10", "OpSGreaterThan", "int_40", "bool", + AstFor("cast_uint_10"), ">", "40"}, // Second arg unsigned - BinaryData{"bool", "int_30", "OpSGreaterThan", "uint_20", "__bool", - "ScalarConstructor[not set]{30}", "greater_than", - AstFor("cast_uint_20")}, + BinaryData{"bool", "int_30", "OpSGreaterThan", "uint_20", "bool", "30", + ">", AstFor("cast_uint_20")}, // Vector, both signed BinaryData{"v2bool", "v2int_30_40", "OpSGreaterThan", "v2int_40_30", - "__vec_2__bool", AstFor("v2int_30_40"), "greater_than", + "vec2", AstFor("v2int_30_40"), ">", AstFor("v2int_40_30")}, // First arg unsigned BinaryData{"v2bool", "v2uint_10_20", "OpSGreaterThan", "v2int_40_30", - "__vec_2__bool", AstFor("cast_v2uint_10_20"), "greater_than", + "vec2", AstFor("cast_v2uint_10_20"), ">", AstFor("v2int_40_30")}, // Second arg unsigned BinaryData{"v2bool", "v2int_30_40", "OpSGreaterThan", "v2uint_20_10", - "__vec_2__bool", AstFor("v2int_30_40"), "greater_than", + "vec2", AstFor("v2int_30_40"), ">", AstFor("cast_v2uint_20_10")})); INSTANTIATE_TEST_SUITE_P( @@ -630,57 +487,51 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryLogicalTest, ::testing::Values( // Both signed - BinaryData{"bool", "int_30", "OpSGreaterThanEqual", "int_40", "__bool", - "ScalarConstructor[not set]{30}", "greater_than_equal", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "int_30", "OpSGreaterThanEqual", "int_40", "bool", + "30", ">=", "40"}, // First arg unsigned - BinaryData{"bool", "uint_10", "OpSGreaterThanEqual", "int_40", "__bool", - AstFor("cast_uint_10"), "greater_than_equal", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "uint_10", "OpSGreaterThanEqual", "int_40", "bool", + AstFor("cast_uint_10"), ">=", "40"}, // Second arg unsigned - BinaryData{"bool", "int_30", "OpSGreaterThanEqual", "uint_20", "__bool", - "ScalarConstructor[not set]{30}", "greater_than_equal", - AstFor("cast_uint_20")}, + BinaryData{"bool", "int_30", "OpSGreaterThanEqual", "uint_20", "bool", + "30", ">=", AstFor("cast_uint_20")}, // Vector, both signed BinaryData{"v2bool", "v2int_30_40", "OpSGreaterThanEqual", - "v2int_40_30", "__vec_2__bool", AstFor("v2int_30_40"), - "greater_than_equal", AstFor("v2int_40_30")}, + "v2int_40_30", "vec2", AstFor("v2int_30_40"), + ">=", AstFor("v2int_40_30")}, // First arg unsigned BinaryData{"v2bool", "v2uint_10_20", "OpSGreaterThanEqual", - "v2int_40_30", "__vec_2__bool", AstFor("cast_v2uint_10_20"), - "greater_than_equal", AstFor("v2int_40_30")}, + "v2int_40_30", "vec2", AstFor("cast_v2uint_10_20"), + ">=", AstFor("v2int_40_30")}, // Second arg unsigned BinaryData{"v2bool", "v2int_30_40", "OpSGreaterThanEqual", - "v2uint_20_10", "__vec_2__bool", AstFor("v2int_30_40"), - "greater_than_equal", AstFor("cast_v2uint_20_10")})); + "v2uint_20_10", "vec2", AstFor("v2int_30_40"), + ">=", AstFor("cast_v2uint_20_10")})); INSTANTIATE_TEST_SUITE_P( SpvParserTest_SLessThan, SpvBinaryLogicalTest, ::testing::Values( // Both signed - BinaryData{"bool", "int_30", "OpSLessThan", "int_40", "__bool", - "ScalarConstructor[not set]{30}", "less_than", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "int_30", "OpSLessThan", "int_40", "bool", "30", "<", + "40"}, // First arg unsigned - BinaryData{"bool", "uint_10", "OpSLessThan", "int_40", "__bool", - AstFor("cast_uint_10"), "less_than", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "uint_10", "OpSLessThan", "int_40", "bool", + AstFor("cast_uint_10"), "<", "40"}, // Second arg unsigned - BinaryData{"bool", "int_30", "OpSLessThan", "uint_20", "__bool", - "ScalarConstructor[not set]{30}", "less_than", - AstFor("cast_uint_20")}, + BinaryData{"bool", "int_30", "OpSLessThan", "uint_20", "bool", "30", + "<", AstFor("cast_uint_20")}, // Vector, both signed BinaryData{"v2bool", "v2int_30_40", "OpSLessThan", "v2int_40_30", - "__vec_2__bool", AstFor("v2int_30_40"), "less_than", + "vec2", AstFor("v2int_30_40"), "<", AstFor("v2int_40_30")}, // First arg unsigned BinaryData{"v2bool", "v2uint_10_20", "OpSLessThan", "v2int_40_30", - "__vec_2__bool", AstFor("cast_v2uint_10_20"), "less_than", + "vec2", AstFor("cast_v2uint_10_20"), "<", AstFor("v2int_40_30")}, // Second arg unsigned BinaryData{"v2bool", "v2int_30_40", "OpSLessThan", "v2uint_20_10", - "__vec_2__bool", AstFor("v2int_30_40"), "less_than", + "vec2", AstFor("v2int_30_40"), "<", AstFor("cast_v2uint_20_10")})); INSTANTIATE_TEST_SUITE_P( @@ -688,29 +539,26 @@ INSTANTIATE_TEST_SUITE_P( SpvBinaryLogicalTest, ::testing::Values( // Both signed - BinaryData{"bool", "int_30", "OpSLessThanEqual", "int_40", "__bool", - "ScalarConstructor[not set]{30}", "less_than_equal", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "int_30", "OpSLessThanEqual", "int_40", "bool", "30", + "<=", "40"}, // First arg unsigned - BinaryData{"bool", "uint_10", "OpSLessThanEqual", "int_40", "__bool", - AstFor("cast_uint_10"), "less_than_equal", - "ScalarConstructor[not set]{40}"}, + BinaryData{"bool", "uint_10", "OpSLessThanEqual", "int_40", "bool", + AstFor("cast_uint_10"), "<=", "40"}, // Second arg unsigned - BinaryData{"bool", "int_30", "OpSLessThanEqual", "uint_20", "__bool", - "ScalarConstructor[not set]{30}", "less_than_equal", - AstFor("cast_uint_20")}, + BinaryData{"bool", "int_30", "OpSLessThanEqual", "uint_20", "bool", + "30", "<=", AstFor("cast_uint_20")}, // Vector, both signed BinaryData{"v2bool", "v2int_30_40", "OpSLessThanEqual", "v2int_40_30", - "__vec_2__bool", AstFor("v2int_30_40"), "less_than_equal", - AstFor("v2int_40_30")}, + "vec2", AstFor("v2int_30_40"), + "<=", AstFor("v2int_40_30")}, // First arg unsigned BinaryData{"v2bool", "v2uint_10_20", "OpSLessThanEqual", "v2int_40_30", - "__vec_2__bool", AstFor("cast_v2uint_10_20"), - "less_than_equal", AstFor("v2int_40_30")}, + "vec2", AstFor("cast_v2uint_10_20"), + "<=", AstFor("v2int_40_30")}, // Second arg unsigned BinaryData{"v2bool", "v2int_30_40", "OpSLessThanEqual", "v2uint_20_10", - "__vec_2__bool", AstFor("v2int_30_40"), "less_than_equal", - AstFor("cast_v2uint_20_10")})); + "vec2", AstFor("v2int_30_40"), + "<=", AstFor("cast_v2uint_20_10")})); using SpvFUnordTest = SpvParserTestBase<::testing::Test>; @@ -726,23 +574,9 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - not_equal - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !((50.0 != 60.0));")); } TEST_F(SpvFUnordTest, FUnordEqual_Vector) { @@ -757,31 +591,11 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - not_equal - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = " + "!((vec2(50.0, 60.0) != vec2(60.0, 50.0)));")); } TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) { @@ -796,23 +610,9 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - equal - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !((50.0 == 60.0));")); } TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) { @@ -827,31 +627,11 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - equal - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = " + "!((vec2(50.0, 60.0) == vec2(60.0, 50.0)));")); } TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) { @@ -866,23 +646,9 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - greater_than_equal - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !((50.0 >= 60.0));")); } TEST_F(SpvFUnordTest, FUnordLessThan_Vector) { @@ -897,31 +663,11 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - greater_than_equal - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = " + "!((vec2(50.0, 60.0) >= vec2(60.0, 50.0)));")); } TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) { @@ -936,23 +682,9 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - greater_than - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !((50.0 > 60.0));")); } TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) { @@ -967,31 +699,10 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - greater_than - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = " + "!((vec2(50.0, 60.0) > vec2(60.0, 50.0)));")); } TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) { @@ -1006,23 +717,9 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - less_than_equal - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !((50.0 <= 60.0));")); } TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) { @@ -1037,31 +734,11 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - less_than_equal - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = " + "!((vec2(50.0, 60.0) <= vec2(60.0, 50.0)));")); } TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) { @@ -1076,23 +753,9 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - ScalarConstructor[not set]{50.000000} - less_than - ScalarConstructor[not set]{60.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = !((50.0 < 60.0));")); } TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) { @@ -1107,31 +770,11 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - UnaryOp[not set]{ - not - Binary[not set]{ - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - less_than - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - } - } - } - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = !((" + "vec2(50.0, 60.0) < vec2(60.0, 50.0)" + "));")); } using SpvLogicalTest = SpvParserTestBase<::testing::Test>; @@ -1148,25 +791,9 @@ TEST_F(SpvLogicalTest, Select_BoolCond_BoolParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __bool - { - Call[not set]{ - Identifier[not set]{select} - ( - ScalarConstructor[not set]{false} - ScalarConstructor[not set]{true} - ScalarConstructor[not set]{true} - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = select(false, true, true);")); } TEST_F(SpvLogicalTest, Select_BoolCond_IntScalarParams) { @@ -1181,25 +808,9 @@ TEST_F(SpvLogicalTest, Select_BoolCond_IntScalarParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{select} - ( - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{true} - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : u32 = select(20u, 10u, true);")); } TEST_F(SpvLogicalTest, Select_BoolCond_FloatScalarParams) { @@ -1214,25 +825,9 @@ TEST_F(SpvLogicalTest, Select_BoolCond_FloatScalarParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{select} - ( - ScalarConstructor[not set]{60.000000} - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{true} - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : f32 = select(60.0, 50.0, true);")); } TEST_F(SpvLogicalTest, Select_BoolCond_VectorParams) { @@ -1250,33 +845,12 @@ TEST_F(SpvLogicalTest, Select_BoolCond_VectorParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Call[not set]{ - Identifier[not set]{select} - ( - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - ScalarConstructor[not set]{true} - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = select(" + "vec2(20u, 10u), " + "vec2(10u, 20u), " + "true);")); // Fails validation prior to SPIR-V 1.4: If the value operands are vectors, // then the condition must be a vector. @@ -1297,37 +871,12 @@ TEST_F(SpvLogicalTest, Select_VecBoolCond_VectorParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__u32 - { - Call[not set]{ - Identifier[not set]{select} - ( - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{20u} - ScalarConstructor[not set]{10u} - } - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{10u} - ScalarConstructor[not set]{20u} - } - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{true} - ScalarConstructor[not set]{false} - } - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = select(" + "vec2(20u, 10u), " + "vec2(10u, 20u), " + "vec2(true, false));")); } TEST_F(SpvLogicalTest, Any) { @@ -1342,27 +891,9 @@ TEST_F(SpvLogicalTest, Any) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __bool - { - Call[not set]{ - Identifier[not set]{any} - ( - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{true} - ScalarConstructor[not set]{false} - } - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = any(vec2(true, false));")); } TEST_F(SpvLogicalTest, All) { @@ -1377,27 +908,9 @@ TEST_F(SpvLogicalTest, All) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __bool - { - Call[not set]{ - Identifier[not set]{all} - ( - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{true} - ScalarConstructor[not set]{false} - } - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = all(vec2(true, false));")); } TEST_F(SpvLogicalTest, IsNan_Scalar) { @@ -1412,23 +925,9 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __bool - { - Call[not set]{ - Identifier[not set]{isNan} - ( - ScalarConstructor[not set]{50.000000} - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = isNan(50.0);")); } TEST_F(SpvLogicalTest, IsNan_Vector) { @@ -1443,27 +942,10 @@ TEST_F(SpvLogicalTest, IsNan_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - Call[not set]{ - Identifier[not set]{isNan} - ( - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = isNan(vec2(50.0, 60.0));")); } TEST_F(SpvLogicalTest, IsInf_Scalar) { @@ -1478,23 +960,9 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __bool - { - Call[not set]{ - Identifier[not set]{isInf} - ( - ScalarConstructor[not set]{50.000000} - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : bool = isInf(50.0);")); } TEST_F(SpvLogicalTest, IsInf_Vector) { @@ -1509,27 +977,10 @@ TEST_F(SpvLogicalTest, IsInf_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __vec_2__bool - { - Call[not set]{ - Identifier[not set]{isInf} - ( - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{50.000000} - ScalarConstructor[not set]{60.000000} - } - ) - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("let x_1 : vec2 = isInf(vec2(50.0, 60.0));")); } // TODO(dneto): Kernel-guarded instructions. diff --git a/src/reader/spirv/function_memory_test.cc b/src/reader/spirv/function_memory_test.cc index e8af52be4d..c68521e7df 100644 --- a/src/reader/spirv/function_memory_test.cc +++ b/src/reader/spirv/function_memory_test.cc @@ -57,18 +57,11 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreBoolConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{true} -} -Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{false} -} -Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{false} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = true; +x_1 = false; +x_1 = false; +)")); } TEST_F(SpvParserMemoryTest, EmitStatement_StoreUintConst) { @@ -90,14 +83,10 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreUintConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{42u} -} -Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0u} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = 42u; +x_1 = 0u; +)")); } TEST_F(SpvParserMemoryTest, EmitStatement_StoreIntConst) { @@ -119,14 +108,10 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreIntConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{42} -} -Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = 42; +x_1 = 0; +)")); } TEST_F(SpvParserMemoryTest, EmitStatement_StoreFloatConst) { @@ -148,14 +133,10 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreFloatConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{42.000000} -} -Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0.000000} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = 42.0; +x_1 = 0.0; +)")); } TEST_F(SpvParserMemoryTest, EmitStatement_LoadBool) { @@ -177,16 +158,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_LoadBool) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( - VariableConst{ - x_2 - none - undefined - __bool - { - Identifier[not set]{x_1} - } - })")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_2 : bool = x_1;")); } TEST_F(SpvParserMemoryTest, EmitStatement_LoadScalar) { @@ -207,29 +181,11 @@ TEST_F(SpvParserMemoryTest, EmitStatement_LoadScalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_2 : u32 = x_1; +let x_3 : u32 = x_1; +)")); } TEST_F(SpvParserMemoryTest, EmitStatement_UseLoadedScalarTwice) { @@ -251,26 +207,11 @@ TEST_F(SpvParserMemoryTest, EmitStatement_UseLoadedScalarTwice) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} -} -Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} -} + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_2 : u32 = x_1; +x_1 = x_2; +x_1 = x_2; )")); } @@ -291,10 +232,8 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreToModuleScopeVar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{42u} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr("x_1 = 42u;")); } TEST_F(SpvParserMemoryTest, @@ -317,11 +256,9 @@ TEST_F(SpvParserMemoryTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - const auto got = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(Assignment{ - Identifier[not set]{x_2} - Identifier[not set]{x_1} -})"; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + const auto* expected = "x_2 = x_1;"; EXPECT_THAT(got, HasSubstr(expected)); } @@ -386,13 +323,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_VectorSwizzle) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{z} - } - ScalarConstructor[not set]{42u} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar.z = 42u;")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_VectorConstOutOfBounds) { @@ -452,13 +385,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_VectorNonConstIndex) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{a_dynamic_index} - } - ScalarConstructor[not set]{42u} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar[a_dynamic_index] = 42u;")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Matrix) { @@ -489,19 +418,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Matrix) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{myvar} - ScalarConstructor[not set]{2u} - } - TypeConstructor[not set]{ - __vec_4__f32 - ScalarConstructor[not set]{42.000000} - ScalarConstructor[not set]{42.000000} - ScalarConstructor[not set]{42.000000} - ScalarConstructor[not set]{42.000000} - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar[2u] = vec4(42.0, 42.0, 42.0, 42.0);")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Array) { @@ -532,19 +451,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Array) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{myvar} - ScalarConstructor[not set]{2u} - } - TypeConstructor[not set]{ - __vec_4__f32 - ScalarConstructor[not set]{42.000000} - ScalarConstructor[not set]{42.000000} - ScalarConstructor[not set]{42.000000} - ScalarConstructor[not set]{42.000000} - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar[2u] = vec4(42.0, 42.0, 42.0, 42.0);")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Struct) { @@ -574,13 +483,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Struct) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{age} - } - ScalarConstructor[not set]{42.000000} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar.age = 42.0;")); } TEST_F(SpvParserMemoryTest, @@ -623,20 +528,11 @@ TEST_F(SpvParserMemoryTest, << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{age} - } - ScalarConstructor[not set]{42.000000} -} -Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{myvar2} - Identifier[not set]{ancientness} - } - ScalarConstructor[not set]{420.000000} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(myvar.age = 42.0; +myvar2.ancientness = 420.0; +)")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_StructNonConstIndex) { @@ -741,16 +637,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Struct_RuntimeArray) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{age} - } - ScalarConstructor[not set]{2u} - } - ScalarConstructor[not set]{42.000000} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar.age[2u] = 42.0;")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Compound_Matrix_Vector) { @@ -781,16 +670,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Compound_Matrix_Vector) { << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - MemberAccessor[not set]{ - ArrayAccessor[not set]{ - Identifier[not set]{myvar} - ScalarConstructor[not set]{2u} - } - Identifier[not set]{w} - } - ScalarConstructor[not set]{42.000000} -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar[2u].w = 42.0;")); } TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_InvalidPointeeType) { @@ -853,52 +735,19 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_DereferenceBase) { )"; auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Function x_200 -> __void - ( - VariableConst{ - x_1 - none - undefined - __ptr_private__vec_2__u32 - } - ) - { - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - MemberAccessor[not set]{ - UnaryOp[not set]{ - indirection - Identifier[not set]{x_1} - } - Identifier[not set]{x} - } - } - } - } - Return{} - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __void - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(fn x_200(x_1 : ptr>) { + let x_3 : u32 = (*(x_1)).x; + return; +} + +fn main_1() { + return; +} + +[[stage(fragment)]] +fn main() { + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -930,45 +779,16 @@ OpExecutionMode %main OriginUpperLeft )"; auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly; - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Function main_1 -> __void - () - { - VariableDeclStatement{ - Variable{ - x_1 - none - undefined - __u32 - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __ptr_function__u32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(fn main_1() { + var x_1 : u32; + let x_2 : ptr = &(x_1); + return; +} + +[[stage(fragment)]] +fn main() { + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -1016,24 +836,17 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_TypesAndVarDeclarations) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly << p->error(); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - RTArr -> __array__u32_stride_4 - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __u32} - StructMember{[[ offset 4 ]] field1: __type_name_RTArr} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - myvar - storage - read_write - __type_name_S - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"(type RTArr = [[stride(4)]] array; + +[[block]] +struct S { + field0 : u32; + field1 : RTArr; +}; + +[[group(0), binding(0)]] var myvar : S; +)")); } TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) { @@ -1056,24 +869,11 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field0} - } - ScalarConstructor[not set]{0u} -} -Assignment{ - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{1u} - } - ScalarConstructor[not set]{0u} -})")); + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr(R"(myvar.field0 = 0u; +myvar.field1[1u] = 0u; +)")); } TEST_F(SpvParserMemoryTest, @@ -1098,25 +898,12 @@ TEST_F(SpvParserMemoryTest, ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field0} - } - ScalarConstructor[not set]{0u} -} -Assignment{ - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{1u} - } - ScalarConstructor[not set]{0u} -})")) << got - << p->error(); + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr(R"(myvar.field0 = 0u; +myvar.field1[1u] = 0u; +)")) << got + << p->error(); } TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) { @@ -1138,16 +925,10 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{ - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{1u} - } - ScalarConstructor[not set]{0u} -})")) << p->error(); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("myvar.field1[1u] = 0u;")) + << p->error(); } TEST_F(SpvParserMemoryTest, @@ -1171,34 +952,11 @@ TEST_F(SpvParserMemoryTest, ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __ptr_storage__u32 - { - UnaryOp[not set]{ - address-of - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{1u} - } - } - } - } -} -Assignment{ - UnaryOp[not set]{ - indirection - Identifier[not set]{x_2} - } - ScalarConstructor[not set]{0u} -})")) << p->error(); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_2 : ptr = &(myvar.field1[1u]); +*(x_2) = 0u; +)")) << p->error(); p->SkipDumpingPending( "crbug.com/tint/1041 track access mode in spirv-reader parser type"); @@ -1240,45 +998,16 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughCopyObject_WithHoisting) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_EQ(ToString(p->builder(), fe.ast_body()), - R"(VariableDeclStatement{ - Variable{ - x_2 - none - undefined - __ptr_storage__u32 - } + auto ast_body = fe.ast_body(); + EXPECT_EQ(test::ToString(p->program(), ast_body), + R"(var x_2 : ptr; +if (true) { + x_2 = &(myvar.field1[1u]); +} else { + return; } -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_2} - UnaryOp[not set]{ - address-of - ArrayAccessor[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{field1} - } - ScalarConstructor[not set]{1u} - } - } - } - } -} -Else{ - { - Return{} - } -} -Assignment{ - Identifier[not set]{x_2} - ScalarConstructor[not set]{0u} -} -Return{} +x_2 = 0u; +return; )") << p->error(); p->SkipDumpingPending("crbug.com/tint/98"); } @@ -1340,30 +1069,11 @@ TEST_F(SpvParserMemoryTest, ArrayLength_FromVar) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{arrayLength} - ( - UnaryOp[not set]{ - address-of - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{rtarr} - } - } - ) - } - } - } -} -)")) << body_str; + auto ast_body = fe.ast_body(); + const auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, + HasSubstr("let x_1 : u32 = arrayLength(&(myvar.rtarr));")) + << body_str; } TEST_F(SpvParserMemoryTest, ArrayLength_FromCopyObject) { @@ -1381,46 +1091,10 @@ TEST_F(SpvParserMemoryTest, ArrayLength_FromCopyObject) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __ptr_storage__type_name_S - { - UnaryOp[not set]{ - address-of - Identifier[not set]{myvar} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{arrayLength} - ( - UnaryOp[not set]{ - address-of - MemberAccessor[not set]{ - UnaryOp[not set]{ - indirection - Identifier[not set]{x_2} - } - Identifier[not set]{rtarr} - } - } - ) - } - } - } -} + auto ast_body = fe.ast_body(); + const auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, HasSubstr(R"(let x_2 : ptr = &(myvar); +let x_1 : u32 = arrayLength(&((*(x_2)).rtarr)); )")) << body_str; p->SkipDumpingPending( @@ -1442,30 +1116,11 @@ TEST_F(SpvParserMemoryTest, ArrayLength_FromAccessChain) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body_str = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{arrayLength} - ( - UnaryOp[not set]{ - address-of - MemberAccessor[not set]{ - Identifier[not set]{myvar} - Identifier[not set]{rtarr} - } - } - ) - } - } - } -} -)")) << body_str; + auto ast_body = fe.ast_body(); + const auto body_str = test::ToString(p->program(), ast_body); + EXPECT_THAT(body_str, + HasSubstr("let x_1 : u32 = arrayLength(&(myvar.rtarr));")) + << body_str; } std::string InvalidPointerPreamble() { diff --git a/src/reader/spirv/function_misc_test.cc b/src/reader/spirv/function_misc_test.cc index 59d957f9ab..45cd5de5a7 100644 --- a/src/reader/spirv/function_misc_test.cc +++ b/src/reader/spirv/function_misc_test.cc @@ -73,51 +73,13 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_12 - none - undefined - __u32 - { - ScalarConstructor[not set]{0u} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_13 - none - undefined - __i32 - { - ScalarConstructor[not set]{0} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __f32 - { - ScalarConstructor[not set]{0.000000} - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_11 : bool = false; +let x_12 : u32 = 0u; +let x_13 : i32 = 0; +let x_14 : f32 = 0.0; +)")); } TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) { @@ -141,67 +103,13 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __vec_2__bool - { - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{false} - ScalarConstructor[not set]{false} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_12 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_13 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_14 : vec2 = vec2(false, false); +let x_11 : vec2 = vec2(0u, 0u); +let x_12 : vec2 = vec2(0, 0); +let x_13 : vec2 = vec2(0.0, 0.0); +)")); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) { @@ -224,51 +132,13 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_12 - none - undefined - __u32 - { - ScalarConstructor[not set]{0u} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_13 - none - undefined - __i32 - { - ScalarConstructor[not set]{0} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __f32 - { - ScalarConstructor[not set]{0.000000} - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_11 : bool = false; +let x_12 : u32 = 0u; +let x_13 : i32 = 0; +let x_14 : f32 = 0.0; +)")); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { @@ -289,52 +159,12 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_12 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_13 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(let x_11 : vec2 = vec2(0u, 0u); +let x_12 : vec2 = vec2(0, 0); +let x_13 : vec2 = vec2(0.0, 0.0); +)")); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { @@ -353,30 +183,11 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __mat_2_2__f32 - { - TypeConstructor[not set]{ - __mat_2_2__f32 - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_11 : mat2x2 = mat2x2(" + "vec2(0.0, 0.0), " + "vec2(0.0, 0.0));")); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { @@ -396,22 +207,9 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __array__u32_2 - { - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_11 : array = array(0u, 0u);")); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { @@ -430,24 +228,9 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - ScalarConstructor[not set]{false} - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0.000000} - } - } - } -})")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("let x_11 : S = S(false, 0u, 0, 0.0);")); } TEST_F(SpvParserTestMiscInstruction, OpNop) { @@ -463,8 +246,8 @@ TEST_F(SpvParserTestMiscInstruction, OpNop) { << p->error() << assembly; auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), Eq(R"(Return{} -)")); + auto ast_body = fe.ast_body(); + EXPECT_EQ(test::ToString(p->program(), ast_body), "return;\n"); } // Test swizzle generation. @@ -494,7 +277,7 @@ TEST_P(SpvParserSwizzleTest, Sample) { Program program(p->program()); EXPECT_TRUE(fe.success()); ASSERT_NE(result, nullptr); - auto got = program.str(result); + auto got = test::ToString(program, result); EXPECT_EQ(got, GetParam().expected_expr); } else { EXPECT_EQ(result, nullptr); @@ -507,10 +290,10 @@ INSTANTIATE_TEST_SUITE_P( ValidIndex, SpvParserSwizzleTest, ::testing::ValuesIn(std::vector{ - {0, "Identifier[not set]{x}\n", ""}, - {1, "Identifier[not set]{y}\n", ""}, - {2, "Identifier[not set]{z}\n", ""}, - {3, "Identifier[not set]{w}\n", ""}, + {0, "x", ""}, + {1, "y", ""}, + {2, "z", ""}, + {3, "w", ""}, {4, "", "vector component index is larger than 3: 4"}, {99999, "", "vector component index is larger than 3: 99999"}})); @@ -554,22 +337,9 @@ TEST_F(SpvParserTest, ValueFromBlockNotInBlockOrder) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(VariableDeclStatement{ - VariableConst{ - x_81 - none - undefined - __f32 - { - Binary[not set]{ - ScalarConstructor[not set]{0.000000} - multiply - ScalarConstructor[not set]{42.000000} - } - } - } - })")); + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr("let x_81 : f32 = (0.0 * 42.0);")); } // TODO(dneto): OpSizeof : requires Kernel (OpenCL) diff --git a/src/reader/spirv/function_var_test.cc b/src/reader/spirv/function_var_test.cc index d78d1ca14a..15f6349143 100644 --- a/src/reader/spirv/function_var_test.cc +++ b/src/reader/spirv/function_var_test.cc @@ -116,31 +116,11 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_AnonymousVars) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_1 - none - undefined - __u32 - } -} -VariableDeclStatement{ - Variable{ - x_2 - none - undefined - __u32 - } -} -VariableDeclStatement{ - Variable{ - x_3 - none - undefined - __u32 - } -} + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(var x_1 : u32; +var x_2 : u32; +var x_3 : u32; )")); } @@ -158,31 +138,10 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_NamedVars) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - a - none - undefined - __u32 - } -} -VariableDeclStatement{ - Variable{ - b - none - undefined - __u32 - } -} -VariableDeclStatement{ - Variable{ - c - none - undefined - __u32 - } -} + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(var a : u32; +var b : u32; +var c : u32; )")); } @@ -200,31 +159,10 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_MixedTypes) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - a - none - undefined - __u32 - } -} -VariableDeclStatement{ - Variable{ - b - none - undefined - __i32 - } -} -VariableDeclStatement{ - Variable{ - c - none - undefined - __f32 - } -} + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(var a : u32; +var b : i32; +var c : f32; )")); } @@ -244,62 +182,13 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ScalarInitializers) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - a - none - undefined - __bool - { - ScalarConstructor[not set]{true} - } - } -} -VariableDeclStatement{ - Variable{ - b - none - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } -} -VariableDeclStatement{ - Variable{ - c - none - undefined - __i32 - { - ScalarConstructor[not set]{-1} - } - } -} -VariableDeclStatement{ - Variable{ - d - none - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } -} -VariableDeclStatement{ - Variable{ - e - none - undefined - __f32 - { - ScalarConstructor[not set]{1.500000} - } - } -} + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(var a : bool = true; +var b : bool = false; +var c : i32 = -1; +var d : u32 = 1u; +var e : f32 = 1.5; )")); } @@ -323,51 +212,12 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ScalarNullInitializers) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - a - none - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } -} -VariableDeclStatement{ - Variable{ - b - none - undefined - __i32 - { - ScalarConstructor[not set]{0} - } - } -} -VariableDeclStatement{ - Variable{ - c - none - undefined - __u32 - { - ScalarConstructor[not set]{0u} - } - } -} -VariableDeclStatement{ - Variable{ - d - none - undefined - __f32 - { - ScalarConstructor[not set]{0.000000} - } - } -} + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr(R"(var a : bool = false; +var b : i32 = 0; +var c : u32 = 0u; +var d : f32 = 0.0; )")); } @@ -387,23 +237,9 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_VectorInitializer) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{1.500000} - ScalarConstructor[not set]{2.000000} - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : vec2 = vec2(1.5, 2.0);")); } TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_MatrixInitializer) { @@ -427,36 +263,12 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_MatrixInitializer) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __mat_2_3__f32 - { - TypeConstructor[not set]{ - __mat_2_3__f32 - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{1.500000} - ScalarConstructor[not set]{2.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{2.000000} - ScalarConstructor[not set]{3.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{3.000000} - ScalarConstructor[not set]{4.000000} - } - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : mat3x2 = mat3x2(" + "vec2(1.5, 2.0), " + "vec2(2.0, 3.0), " + "vec2(3.0, 4.0));")); } TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ArrayInitializer) { @@ -475,23 +287,10 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ArrayInitializer) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __array__u32_2 - { - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{2u} - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : array = array(1u, 2u);")); } TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ArrayInitializer_Alias) { @@ -516,23 +315,9 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ArrayInitializer_Alias) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - auto got = ToString(p->builder(), fe.ast_body()); - const char* expect = R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __type_name_Arr - { - TypeConstructor[not set]{ - __type_name_Arr - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{2u} - } - } - } -} -)"; + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + const char* expect = "var x_200 : Arr = Arr(1u, 2u);\n"; EXPECT_EQ(expect, got); } @@ -552,23 +337,10 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_ArrayInitializer_Null) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __array__u32_2 - { - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT( + test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : array = array(0u, 0u);")); } TEST_F(SpvParserFunctionVarTest, @@ -594,23 +366,9 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __type_name_Arr - { - TypeConstructor[not set]{ - __type_name_Arr - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : Arr = Arr(0u, 0u);")); } TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_StructInitializer) { @@ -630,28 +388,9 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_StructInitializer) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{1.500000} - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{2u} - } - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : S = S(1u, 1.5, array(1u, 2u));")); } TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_StructInitializer_Null) { @@ -671,28 +410,9 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_StructInitializer_Null) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->builder(), fe.ast_body()), - HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } - } -} -)")); + auto ast_body = fe.ast_body(); + EXPECT_THAT(test::ToString(p->program(), ast_body), + HasSubstr("var x_200 : S = S(0u, 0.0, array(0u, 0u));")); } TEST_F(SpvParserFunctionVarTest, @@ -718,16 +438,9 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_EQ(got, R"(VariableDeclStatement{ - Variable{ - myvar - none - undefined - __f32 - } -} -)") << got; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_EQ(got, "var myvar : f32;\n") << got; } TEST_F(SpvParserFunctionVarTest, @@ -755,16 +468,9 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_EQ(got, R"(VariableDeclStatement{ - Variable{ - myvar - none - undefined - __type_name_strct - } -} -)") << got; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_EQ(got, "var myvar : strct;\n") << got; } TEST_F(SpvParserFunctionVarTest, @@ -797,23 +503,10 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitFunctionVariables()); - const auto got = ToString(p->builder(), fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(VariableDeclStatement{ - Variable{ - x_40 - none - undefined - __type_name_S - } -} -VariableDeclStatement{ - Variable{ - x_41 - none - undefined - __type_name_S_1 - } -} + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + EXPECT_THAT(got, HasSubstr(R"(var x_40 : S; +var x_41 : S_1; )")); } @@ -839,29 +532,13 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); auto* expect = - R"(VariableDeclStatement{ - Variable{ - x_25 - none - undefined - __u32 - } -} -Assignment{ - Identifier[not set]{x_25} - ScalarConstructor[not set]{1u} -} -Assignment{ - Identifier[not set]{x_25} - Binary[not set]{ - ScalarConstructor[not set]{1u} - add - ScalarConstructor[not set]{1u} - } -} -Return{} + R"(var x_25 : u32; +x_25 = 1u; +x_25 = (1u + 1u); +return; )"; EXPECT_EQ(expect, got); } @@ -889,43 +566,14 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - Variable{ - x_25 - none - undefined - __u32 - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Binary[not set]{ - ScalarConstructor[not set]{1u} - add - ScalarConstructor[not set]{1u} - } - } - } -} -Assignment{ - Identifier[not set]{x_25} - ScalarConstructor[not set]{1u} -} -Assignment{ - Identifier[not set]{x_25} - Identifier[not set]{x_2} -} -Assignment{ - Identifier[not set]{x_25} - Identifier[not set]{x_2} -} -Return{} + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var x_25 : u32; +let x_2 : u32 = (1u + 1u); +x_25 = 1u; +x_25 = x_2; +x_25 = x_2; +return; )"; EXPECT_EQ(expect, got); } @@ -963,47 +611,19 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - Variable{ - x_25 - none - undefined - __u32 - } -} -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Binary[not set]{ - ScalarConstructor[not set]{1u} - add - ScalarConstructor[not set]{1u} - } - } - } -} -Assignment{ - Identifier[not set]{x_25} - ScalarConstructor[not set]{1u} -} -Loop{ + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var x_25 : u32; +let x_2 : u32 = (1u + 1u); +x_25 = 1u; +loop { + continuing { - Assignment{ - Identifier[not set]{x_25} - Identifier[not set]{x_2} - } + x_25 = x_2; } } -Assignment{ - Identifier[not set]{x_25} - ScalarConstructor[not set]{2u} -} -Return{} +x_25 = 2u; +return; )"; EXPECT_EQ(expect, got); } @@ -1064,80 +684,32 @@ TEST_F( auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0u} -} -Loop{ - VariableDeclStatement{ - Variable{ - x_2 - none - undefined - __u32 - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(x_1 = 0u; +loop { + var x_2 : u32; + x_1 = 1u; + if (false) { + break; } - Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } - } - Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{3u} - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_2} - Binary[not set]{ - ScalarConstructor[not set]{1u} - add - ScalarConstructor[not set]{1u} - } - } - } - } - Else{ - { - Return{} - } - } - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} + x_1 = 3u; + if (true) { + x_2 = (1u + 1u); + } else { + return; } + x_1 = x_2; + continuing { - Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{4u} - } - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + x_1 = 4u; + if (false) { + break; } } } -Assignment{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{5u} -} -Return{} +x_1 = 5u; +return; )"; EXPECT_EQ(expect, got); } @@ -1183,41 +755,14 @@ TEST_F( // We don't hoist x_1 into its own mutable variable. It is emitted as // a const definition. - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(let x_1 : u32 = 1u; +if (true) { } -If{ - ( - ScalarConstructor[not set]{true} - ) - { - } -} -VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } -} -Assignment{ - Identifier[not set]{x_200} - Identifier[not set]{x_3} -} -Return{} +let x_3 : u32 = x_1; +x_200 = x_3; +return; )"; EXPECT_EQ(expect, got); } @@ -1270,48 +815,16 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{true} - ) - { - VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } - } - If{ - ( - ScalarConstructor[not set]{true} - ) - { - } - } - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Assignment{ - Identifier[not set]{x_200} - Identifier[not set]{x_3} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (true) { + let x_1 : u32 = 1u; + if (true) { } + let x_3 : u32 = x_1; + x_200 = x_3; } -Return{} +return; )"; EXPECT_EQ(expect, got); } @@ -1359,50 +872,20 @@ TEST_F( auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(If{ - ( - ScalarConstructor[not set]{true} - ) - { - VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(if (true) { + let x_1 : u32 = 1u; + switch(1u) { + case 0u: { } - Switch{ - ScalarConstructor[not set]{1u} - { - Case 0u{ - } - Default{ - } - } - } - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Assignment{ - Identifier[not set]{x_200} - Identifier[not set]{x_3} + default: { } } + let x_3 : u32 = x_1; + x_200 = x_3; } -Return{} +return; )"; EXPECT_EQ(expect, got); } @@ -1444,37 +927,13 @@ TEST_F(SpvParserFunctionVarTest, // We don't hoist x_1 into its own mutable variable. It is emitted as // a const definition. - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - VariableConst{ - x_1 - none - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(let x_1 : u32 = 1u; +let x_2 : u32 = x_1; +if (true) { } -VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } -} -If{ - ( - ScalarConstructor[not set]{true} - ) - { - } -} -Return{} +return; )"; EXPECT_EQ(expect, got); } @@ -1523,108 +982,29 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Phi_SingleBlockLoopIndex) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - VariableDeclStatement{ - Variable{ - x_2_phi - none - undefined - __u32 - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var x_2_phi : u32; + var x_3_phi : u32; + let x_101 : bool = x_7; + let x_102 : bool = x_8; + x_2_phi = 0u; + x_3_phi = 1u; + if (x_101) { + break; } - VariableDeclStatement{ - Variable{ - x_3_phi - none - undefined - __u32 - } - } - VariableDeclStatement{ - VariableConst{ - x_101 - none - undefined - __bool - { - Identifier[not set]{x_7} - } - } - } - VariableDeclStatement{ - VariableConst{ - x_102 - none - undefined - __bool - { - Identifier[not set]{x_8} - } - } - } - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{0u} - } - Assignment{ - Identifier[not set]{x_3_phi} - ScalarConstructor[not set]{1u} - } - If{ - ( - Identifier[not set]{x_101} - ) - { - Break{} - } - } - Loop{ - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_2_phi} - } - } - } - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - Identifier[not set]{x_3_phi} - } - } - } - Assignment{ - Identifier[not set]{x_2_phi} - Binary[not set]{ - Identifier[not set]{x_2} - add - ScalarConstructor[not set]{1u} - } - } - Assignment{ - Identifier[not set]{x_3_phi} - Identifier[not set]{x_3} - } - If{ - ( - Identifier[not set]{x_102} - ) - { - Break{} - } + loop { + let x_2 : u32 = x_2_phi; + let x_3 : u32 = x_3_phi; + x_2_phi = (x_2 + 1u); + x_3_phi = x_3; + if (x_102) { + break; } } } -Return{} +return; )"; EXPECT_EQ(expect, got); } @@ -1676,122 +1056,34 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Phi_MultiBlockLoopIndex) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(Loop{ - VariableDeclStatement{ - Variable{ - x_2_phi - none - undefined - __u32 - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(loop { + var x_2_phi : u32; + var x_3_phi : u32; + let x_101 : bool = x_7; + let x_102 : bool = x_8; + x_2_phi = 0u; + x_3_phi = 1u; + if (x_101) { + break; } - VariableDeclStatement{ - Variable{ - x_3_phi - none - undefined - __u32 - } - } - VariableDeclStatement{ - VariableConst{ - x_101 - none - undefined - __bool - { - Identifier[not set]{x_7} - } - } - } - VariableDeclStatement{ - VariableConst{ - x_102 - none - undefined - __bool - { - Identifier[not set]{x_8} - } - } - } - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{0u} - } - Assignment{ - Identifier[not set]{x_3_phi} - ScalarConstructor[not set]{1u} - } - If{ - ( - Identifier[not set]{x_101} - ) - { - Break{} - } - } - Loop{ - VariableDeclStatement{ - Variable{ - x_4 - none - undefined - __u32 - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_2_phi} - } - } - } - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - Identifier[not set]{x_3_phi} - } - } - } - If{ - ( - Identifier[not set]{x_102} - ) - { - Break{} - } + loop { + var x_4 : u32; + let x_2 : u32 = x_2_phi; + let x_3 : u32 = x_3_phi; + if (x_102) { + break; } + continuing { - Assignment{ - Identifier[not set]{x_4} - Binary[not set]{ - Identifier[not set]{x_2} - add - ScalarConstructor[not set]{1u} - } - } - Assignment{ - Identifier[not set]{x_2_phi} - Identifier[not set]{x_4} - } - Assignment{ - Identifier[not set]{x_3_phi} - Identifier[not set]{x_3} - } + x_4 = (x_2 + 1u); + x_2_phi = x_4; + x_3_phi = x_3; } } } -Return{} +return; )"; EXPECT_EQ(expect, got); } @@ -1845,133 +1137,32 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - VariableConst{ - x_101 - none - undefined - __bool - { - Identifier[not set]{x_17} - } - } -} -Loop{ - VariableDeclStatement{ - Variable{ - x_2_phi - none - undefined - __u32 - } - } - VariableDeclStatement{ - Variable{ - x_5_phi - none - undefined - __u32 - } - } - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{0u} - } - Assignment{ - Identifier[not set]{x_5_phi} - ScalarConstructor[not set]{1u} - } - Loop{ - VariableDeclStatement{ - Variable{ - x_7 - none - undefined - __u32 - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_2_phi} - } - } - } - VariableDeclStatement{ - VariableConst{ - x_5 - none - undefined - __u32 - { - Identifier[not set]{x_5_phi} - } - } - } - VariableDeclStatement{ - VariableConst{ - x_4 - none - undefined - __u32 - { - Binary[not set]{ - Identifier[not set]{x_2} - add - ScalarConstructor[not set]{1u} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_6 - none - undefined - __u32 - { - Binary[not set]{ - Identifier[not set]{x_4} - add - ScalarConstructor[not set]{1u} - } - } - } - } - If{ - ( - Identifier[not set]{x_101} - ) - { - Break{} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(let x_101 : bool = x_17; +loop { + var x_2_phi : u32; + var x_5_phi : u32; + x_2_phi = 0u; + x_5_phi = 1u; + loop { + var x_7 : u32; + let x_2 : u32 = x_2_phi; + let x_5 : u32 = x_5_phi; + let x_4 : u32 = (x_2 + 1u); + let x_6 : u32 = (x_4 + 1u); + if (x_101) { + break; } + continuing { - Assignment{ - Identifier[not set]{x_7} - Binary[not set]{ - Identifier[not set]{x_4} - add - Identifier[not set]{x_6} - } - } - Assignment{ - Identifier[not set]{x_2_phi} - Identifier[not set]{x_4} - } - Assignment{ - Identifier[not set]{x_5_phi} - Identifier[not set]{x_7} - } + x_7 = (x_4 + x_6); + x_2_phi = x_4; + x_5_phi = x_7; } } } -Return{} +return; )"; EXPECT_EQ(expect, got); } @@ -2025,90 +1216,30 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Phi_FromElseAndThen) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - VariableConst{ - x_101 - none - undefined - __bool - { - Identifier[not set]{x_7} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(let x_101 : bool = x_7; +let x_102 : bool = x_8; +loop { + var x_2_phi : u32; + if (x_101) { + break; } -} -VariableDeclStatement{ - VariableConst{ - x_102 - none - undefined - __bool - { - Identifier[not set]{x_8} - } - } -} -Loop{ - VariableDeclStatement{ - Variable{ - x_2_phi - none - undefined - __u32 - } - } - If{ - ( - Identifier[not set]{x_101} - ) - { - Break{} - } - } - If{ - ( - Identifier[not set]{x_102} - ) - { - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{0u} - } - Continue{} - } - } - Else{ - { - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{1u} - } - Continue{} - } - } - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{0u} + if (x_102) { + x_2_phi = 0u; + continue; + } else { + x_2_phi = 1u; + continue; } + x_2_phi = 0u; + continuing { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_2_phi} - } - } - } - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} - } + let x_2 : u32 = x_2_phi; + x_1 = x_2; } } -Return{} +return; )"; EXPECT_EQ(expect, got) << got; } @@ -2159,87 +1290,30 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Phi_FromHeaderAndThen) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - VariableConst{ - x_101 - none - undefined - __bool - { - Identifier[not set]{x_7} - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(let x_101 : bool = x_7; +let x_102 : bool = x_8; +loop { + var x_2_phi : u32; + if (x_101) { + break; } -} -VariableDeclStatement{ - VariableConst{ - x_102 - none - undefined - __bool - { - Identifier[not set]{x_8} - } + x_2_phi = 0u; + if (x_102) { + x_2_phi = 1u; + continue; + } else { + continue; } -} -Loop{ - VariableDeclStatement{ - Variable{ - x_2_phi - none - undefined - __u32 - } - } - If{ - ( - Identifier[not set]{x_101} - ) - { - Break{} - } - } - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{0u} - } - If{ - ( - Identifier[not set]{x_102} - ) - { - Assignment{ - Identifier[not set]{x_2_phi} - ScalarConstructor[not set]{1u} - } - Continue{} - } - } - Else{ - { - Continue{} - } - } - Return{} + return; + continuing { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_2_phi} - } - } - } - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_2} - } + let x_2 : u32 = x_2_phi; + x_1 = x_2; } } -Return{} +return; )"; EXPECT_EQ(expect, got) << got; } @@ -2289,60 +1363,27 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - Variable{ - x_41_phi - none - undefined - __u32 + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var x_41_phi : u32; +switch(1u) { + default: { + fallthrough; + } + case 0u: { + fallthrough; + } + case 1u: { + if (true) { + } else { + x_41_phi = 0u; + break; + } + x_41_phi = 1u; } } -Switch{ - ScalarConstructor[not set]{1u} - { - Default{ - Fallthrough{} - } - Case 0u{ - Fallthrough{} - } - Case 1u{ - If{ - ( - ScalarConstructor[not set]{true} - ) - { - } - } - Else{ - { - Assignment{ - Identifier[not set]{x_41_phi} - ScalarConstructor[not set]{0u} - } - Break{} - } - } - Assignment{ - Identifier[not set]{x_41_phi} - ScalarConstructor[not set]{1u} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_41 - none - undefined - __u32 - { - Identifier[not set]{x_41_phi} - } - } -} -Return{} +let x_41 : u32 = x_41_phi; +return; )"; EXPECT_EQ(expect, got) << got << assembly; } @@ -2381,71 +1422,17 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_UseInPhiCountsAsUse) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - Variable{ - x_101_phi - none - undefined - __bool - } + auto ast_body = fe.ast_body(); + auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var x_101_phi : bool; +let x_11 : bool = (true & true); +let x_12 : bool = !(x_11); +x_101_phi = x_11; +if (true) { + x_101_phi = x_12; } -VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __bool - { - Binary[not set]{ - ScalarConstructor[not set]{true} - and - ScalarConstructor[not set]{true} - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_12 - none - undefined - __bool - { - UnaryOp[not set]{ - not - Identifier[not set]{x_11} - } - } - } -} -Assignment{ - Identifier[not set]{x_101_phi} - Identifier[not set]{x_11} -} -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_101_phi} - Identifier[not set]{x_12} - } - } -} -VariableDeclStatement{ - VariableConst{ - x_101 - none - undefined - __bool - { - Identifier[not set]{x_101_phi} - } - } -} -Return{} +let x_101 : bool = x_101_phi; +return; )"; EXPECT_EQ(expect, got); } @@ -2492,41 +1479,21 @@ TEST_F(SpvParserFunctionVarTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto* expected = R"(Loop{ - If{ - ( - ScalarConstructor[not set]{false} - ) - { - Break{} - } + const auto* expected = R"(loop { + if (false) { + break; } - Break{} + break; + continuing { - VariableDeclStatement{ - Variable{ - x_81_phi_1 - none - undefined - __f32 - } - } - VariableDeclStatement{ - VariableConst{ - x_81 - none - undefined - __f32 - { - Identifier[not set]{x_81_phi_1} - } - } - } + var x_81_phi_1 : f32; + let x_81 : f32 = x_81_phi_1; } } -Return{} +return; )"; - const auto got = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); EXPECT_EQ(got, expected); } @@ -2556,55 +1523,18 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Hoist_CompositeInsert) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto* expected = R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __vec_2__i32 - } + const auto* expected = R"(var x_200 : vec2; +if (true) { + x_200 = vec2(0, 0); + x_200.x = 0; +} else { + return; } -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_200} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_200} - Identifier[not set]{x} - } - ScalarConstructor[not set]{0} - } - } -} -Else{ - { - Return{} - } -} -VariableDeclStatement{ - VariableConst{ - x_201 - none - undefined - __vec_2__i32 - { - Identifier[not set]{x_200} - } - } -} -Return{} +let x_201 : vec2 = x_200; +return; )"; - const auto got = ToString(p->builder(), fe.ast_body()); + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); EXPECT_EQ(got, expected); } @@ -2634,54 +1564,17 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Hoist_VectorInsertDynamic) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __vec_2__i32 - } + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + const auto* expected = R"(var x_200 : vec2; +if (true) { + x_200 = vec2(0, 0); + x_200[1] = 3; +} else { + return; } -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_200} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - } - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_200} - ScalarConstructor[not set]{1} - } - ScalarConstructor[not set]{3} - } - } -} -Else{ - { - Return{} - } -} -VariableDeclStatement{ - VariableConst{ - x_201 - none - undefined - __vec_2__i32 - { - Identifier[not set]{x_200} - } - } -} -Return{} +let x_201 : vec2 = x_200; +return; )"; EXPECT_EQ(got, expected) << got; } @@ -2720,38 +1613,16 @@ TEST_F(SpvParserFunctionVarTest, EmitStatement_Hoist_UsedAsNonPtrArg) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __i32 - } + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + const auto* expected = R"(var x_200 : i32; +if (true) { + x_200 = 1; +} else { + return; } -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_200} - ScalarConstructor[not set]{1} - } - } -} -Else{ - { - Return{} - } -} -Call[not set]{ - Identifier[not set]{x_500} - ( - Identifier[not set]{x_200} - ) -} -Return{} +x_500(x_200); +return; )"; EXPECT_EQ(got, expected) << got; } @@ -2793,45 +1664,9 @@ TEST_F(SpvParserFunctionVarTest, DISABLED_EmitStatement_Hoist_UsedAsPtrArg) { auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - const auto* expected = R"(VariableDeclStatement{ - Variable{ - x_200 - none - undefined - __i32 - } - Variable{ - x_199 - none - undefined - __i32 - } -} -If{ - ( - ScalarConstructor[not set]{true} - ) - { - Assignment{ - Identifier[not set]{x_200} - ScalarConstructor[not set]{1} - } - } -} -Else{ - { - Return{} - } -} -Call[not set]{ - Identifier[not set]{x_500} - ( - Identifier[not set]{x_200} - ) -} -Return{} -)"; + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + const auto* expected = R"(xxxxxxxxxxxxxxxxxxxxx)"; EXPECT_EQ(got, expected) << got; } diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 8f102e107f..ae37f47963 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -2131,8 +2131,8 @@ TypedExpression ParserImpl::RectifyOperandSignedness( } auto* type = expr.type; if (!type) { - Fail() << "internal error: unmapped type for: " << builder_.str(expr.expr) - << "\n"; + Fail() << "internal error: unmapped type for: " + << expr.expr->TypeInfo().name << "\n"; return {}; } if (requires_unsigned) { diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index d7ab594ac2..1828362001 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -596,7 +596,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) { auto* str = type->Build(p->builder()); Program program = p->program(); - EXPECT_THAT(program.str(str), Eq(R"(__type_name_S)")); + EXPECT_EQ(test::ToString(program, str), "S"); } TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) { @@ -614,7 +614,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) { auto* str = type->Build(p->builder()); Program program = p->program(); - EXPECT_THAT(program.str(str), Eq(R"(__type_name_S)")); + EXPECT_EQ(test::ToString(program, str), "S"); } TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) { @@ -636,7 +636,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) { auto* str = type->Build(p->builder()); Program program = p->program(); - EXPECT_THAT(program.str(str), Eq(R"(__type_name_S)")); + EXPECT_EQ(test::ToString(program, str), "S"); } TEST_F(SpvParserTest, ConvertType_Struct_NoDeduplication) { diff --git a/src/reader/spirv/parser_impl_function_decl_test.cc b/src/reader/spirv/parser_impl_function_decl_test.cc index b4ea30d9eb..47563d1f9b 100644 --- a/src/reader/spirv/parser_impl_function_decl_test.cc +++ b/src/reader/spirv/parser_impl_function_decl_test.cc @@ -88,7 +88,7 @@ TEST_F(SpvParserTest, EmitFunctions_NoFunctions) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, Not(HasSubstr("Function{"))); p->SkipDumpingPending("Not valid for Vulkan: needs an entry point"); } @@ -102,7 +102,7 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, Not(HasSubstr("Function{"))); p->SkipDumpingPending("Missing an entry point body requires Linkage"); } @@ -121,19 +121,18 @@ OpFunctionEnd)"; ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Struct $3 { - StructMember{[[ BuiltinDecoration{position} - ]] $4: __vec_4__f32})")) - << program_ast; +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; +)")) << program_ast; EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("main").to_str() + - R"( -> __type_name_$3 - StageDecoration{vertex} - () - {)")); +[[stage(vertex)]] +fn main() -> main_out { +)")); } TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_Fragment) { @@ -147,13 +146,11 @@ TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_Fragment) { ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("main").to_str() + - R"( -> __void - StageDecoration{fragment} - () - {)")); +[[stage(fragment)]] +fn main() { +)")); } TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_GLCompute) { @@ -167,18 +164,11 @@ TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_GLCompute) { ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("main").to_str() + - R"( -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - } - () - {)")); +[[stage(compute), workgroup_size(1, 1, 1)]] +fn main() { +)")); } TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_MultipleEntryPoints) { @@ -194,19 +184,15 @@ OpExecutionMode %main OriginUpperLeft ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("first_shader").to_str() + - R"( -> __void - StageDecoration{fragment} - () - {)")); +[[stage(fragment)]] +fn first_shader() { +)")); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("second_shader").to_str() + - R"( -> __void - StageDecoration{fragment} - () - {)")); +[[stage(fragment)]] +fn second_shader() { +)")); } TEST_F(SpvParserTest, @@ -225,19 +211,11 @@ OpFunctionEnd)"; ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("comp_main").to_str() + - R"( -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{2} - ScalarConstructor[not set]{4} - ScalarConstructor[not set]{8} - } - () - {)")) - << program_ast; +[[stage(compute), workgroup_size(2, 4, 8)]] +fn comp_main() { +)")) << program_ast; } TEST_F(SpvParserTest, @@ -259,19 +237,11 @@ OpFunctionEnd)"; ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("comp_main").to_str() + - R"( -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{5} - ScalarConstructor[not set]{7} - } - () - {)")) - << program_ast; +[[stage(compute), workgroup_size(3, 5, 7)]] +fn comp_main() { +)")) << program_ast; } TEST_F( @@ -298,19 +268,11 @@ OpFunctionEnd)"; ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("comp_main").to_str() + - R"( -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{5} - ScalarConstructor[not set]{7} - } - () - {)")) - << program_ast; +[[stage(compute), workgroup_size(3, 5, 7)]] +fn comp_main() { +)")) << program_ast; } TEST_F( @@ -336,19 +298,11 @@ OpFunctionEnd)"; ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("comp_main").to_str() + - R"( -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{5} - ScalarConstructor[not set]{7} - } - () - {)")) - << program_ast; +[[stage(compute), workgroup_size(3, 5, 7)]] +fn comp_main() { +)")) << program_ast; } TEST_F( @@ -378,19 +332,11 @@ OpFunctionEnd)"; ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); Program program = p->program(); - const auto program_ast = program.to_str(false); + const auto program_ast = test::ToString(program); EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("comp_main").to_str() + - R"( -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{5} - ScalarConstructor[not set]{7} - } - () - {)")) - << program_ast; +[[stage(compute), workgroup_size(3, 5, 7)]] +fn comp_main() { +)")) << program_ast; } TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) { @@ -404,12 +350,9 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(false); - EXPECT_THAT(program_ast, HasSubstr(R"( - Function )" + program.Symbols().Get("another_function").to_str() + - R"( -> __void - () - {)")); + const auto program_ast = test::ToString(program); + EXPECT_THAT(program_ast, HasSubstr(R"(fn another_function() { +)")); } TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) { @@ -440,61 +383,21 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(); - EXPECT_THAT(program_ast, HasSubstr(R"( - Function leaf -> __u32 - () - { - Return{ - { - ScalarConstructor[not set]{0u} - } - } - } - Function branch -> __u32 - () - { - VariableDeclStatement{ - VariableConst{ - leaf_result - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{leaf} - ( - ) - } - } - } - } - Return{ - { - Identifier[not set]{leaf_result} - } - } - } - Function root -> __void - () - { - VariableDeclStatement{ - VariableConst{ - branch_result - none - undefined - __u32 - { - Call[not set]{ - Identifier[not set]{branch} - ( - ) - } - } - } - } - Return{} - })")) << program_ast; + const auto program_ast = test::ToString(program); + EXPECT_THAT(program_ast, HasSubstr(R"(fn leaf() -> u32 { + return 0u; +} + +fn branch() -> u32 { + let leaf_result : u32 = leaf(); + return leaf_result; +} + +fn root() { + let branch_result : u32 = branch(); + return; +} +)")) << program_ast; } TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) { @@ -511,18 +414,11 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(); - EXPECT_THAT(program_ast, HasSubstr(R"( - Function ret_float -> __f32 - () - { - Return{ - { - ScalarConstructor[not set]{0.000000} - } - } - })")) - << program_ast; + const auto program_ast = test::ToString(program); + EXPECT_THAT(program_ast, HasSubstr(R"(fn ret_float() -> f32 { + return 0.0; +} +)")) << program_ast; } TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) { @@ -541,32 +437,12 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(); - EXPECT_THAT(program_ast, HasSubstr(R"( - Function mixed_params -> __void - ( - VariableConst{ - a - none - undefined - __u32 - } - VariableConst{ - b - none - undefined - __f32 - } - VariableConst{ - c - none - undefined - __i32 - } - ) - { - Return{} - })")); + const auto program_ast = test::ToString(program); + EXPECT_THAT(program_ast, + HasSubstr(R"(fn mixed_params(a : u32, b : f32, c : i32) { + return; +} +)")); } TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) { @@ -585,33 +461,12 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto program_ast = program.to_str(); - EXPECT_THAT(program_ast, HasSubstr(R"( - Function mixed_params -> __void - ( - VariableConst{ - x_14 - none - undefined - __u32 - } - VariableConst{ - x_15 - none - undefined - __f32 - } - VariableConst{ - x_16 - none - undefined - __i32 - } - ) - { - Return{} - })")) - << program_ast; + const auto program_ast = test::ToString(program); + EXPECT_THAT(program_ast, + HasSubstr(R"(fn mixed_params(x_14 : u32, x_15 : f32, x_16 : i32) { + return; +} +)")) << program_ast; } } // namespace diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 89fdf69ee9..b121e93e7a 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -1252,82 +1252,48 @@ TEST_P(SpvParserHandleTest_DeclUnderspecifiedHandle, Variable) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()) << p->error(); - const auto program = p->program().to_str(); + const auto program = test::ToString(p->program()); EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) << program; } -INSTANTIATE_TEST_SUITE_P(Samplers, - SpvParserHandleTest_DeclUnderspecifiedHandle, - ::testing::Values( +INSTANTIATE_TEST_SUITE_P( + Samplers, + SpvParserHandleTest_DeclUnderspecifiedHandle, + ::testing::Values( - DeclUnderspecifiedHandleCase{"", R"( + DeclUnderspecifiedHandleCase{ + "", R"( %ptr = OpTypePointer UniformConstant %sampler %10 = OpVariable %ptr UniformConstant )", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - })"})); + R"([[group(0), binding(0)]] var x_10 : sampler;)"})); -INSTANTIATE_TEST_SUITE_P(Images, - SpvParserHandleTest_DeclUnderspecifiedHandle, - ::testing::Values( +INSTANTIATE_TEST_SUITE_P( + Images, + SpvParserHandleTest_DeclUnderspecifiedHandle, + ::testing::Values( - DeclUnderspecifiedHandleCase{"", R"( + DeclUnderspecifiedHandleCase{ + "", R"( %10 = OpVariable %ptr_f_texture_1d UniformConstant )", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampled_texture_1d__f32 - })"}, - DeclUnderspecifiedHandleCase{R"( + R"([[group(0), binding(0)]] var x_10 : texture_1d;)"}, + DeclUnderspecifiedHandleCase{ + R"( OpDecorate %10 NonWritable )", - R"( + R"( %10 = OpVariable %ptr_f_storage_1d UniformConstant )", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampled_texture_1d__f32 - })"}, - DeclUnderspecifiedHandleCase{R"( + R"([[group(0), binding(0)]] var x_10 : texture_1d;)"}, + DeclUnderspecifiedHandleCase{ + R"( OpDecorate %10 NonReadable )", - R"( + R"( %10 = OpVariable %ptr_f_storage_1d UniformConstant )", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __storage_texture_1d_rg32float_write - })"})); + R"([[group(0), binding(0)]] var x_10 : texture_storage_1d;)"})); // Test handle declaration or error, when there is an image access. @@ -1434,7 +1400,7 @@ TEST_P(SpvParserHandleTest_ImageDeclTest, DeclareAndUseHandle) { const bool succeeded = p->BuildAndParseInternalModule(); if (succeeded) { EXPECT_TRUE(GetParam().expected_error.empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); EXPECT_THAT(got, HasSubstr(GetParam().expected_decl)); } else { EXPECT_FALSE(GetParam().expected_error.empty()); @@ -1451,18 +1417,8 @@ INSTANTIATE_TEST_SUITE_P( {"%float 1D 0 1 1 1 Unknown", "%result = OpImageQuerySamples %uint %im", "WGSL arrayed textures must be 2d_array or cube_array: ", ""}, {"%float 2D 0 0 1 1 Unknown", "%result = OpImageQuerySamples %uint %im", - "", R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __multisampled_texture_2d__f32 - } -)"}, + "", + "[[group(2), binding(1)]] var x_20 : texture_multisampled_2d;"}, {"%float 2D 0 1 1 1 Unknown", "%result = OpImageQuerySamples %uint %im", "WGSL multisampled textures must be 2d and non-arrayed: ", ""}, {"%float 3D 0 0 1 1 Unknown", "%result = OpImageQuerySamples %uint %im", @@ -1588,7 +1544,7 @@ TEST_P(SpvParserHandleTest_SampledImageAccessTest, Variable) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()) << p->error(); - const auto program = p->program().to_str(); + const auto program = test::ToString(p->program()); EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) << "DECLARATIONS ARE BAD " << program; EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin)) @@ -1638,394 +1594,92 @@ INSTANTIATE_TEST_SUITE_P( ImageAccessCase{"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod " "%v4float %sampled_image %coords12", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + "textureSample(x_20, x_10, coords12)"}, // OpImageSampleImplicitLod arrayed - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleImplicitLod " - "%v4float %sampled_image %coords123", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleImplicitLod " + "%v4float %sampled_image %coords123", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + "textureSample(x_20, x_10, coords123.xy, i32(coords123.z))"}, // OpImageSampleImplicitLod with ConstOffset ImageAccessCase{ "%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod " "%v4float %sampled_image %coords12 ConstOffset %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + "textureSample(x_20, x_10, coords12, vec2(3, 4))"}, // OpImageSampleImplicitLod arrayed with ConstOffset ImageAccessCase{ "%float 2D 0 1 0 1 Unknown", "%result = OpImageSampleImplicitLod " "%v4float %sampled_image %coords123 ConstOffset %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSample(x_20, x_10, coords123.xy, i32(coords123.z), vec2(3, 4)))"}, // OpImageSampleImplicitLod with Bias ImageAccessCase{"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod " "%v4float %sampled_image %coords12 Bias %float_7", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{7.000000} - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + "textureSampleBias(x_20, x_10, coords12, 7.0)"}, // OpImageSampleImplicitLod arrayed with Bias - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleImplicitLod " - "%v4float %sampled_image %coords123 Bias %float_7", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{7.000000} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleImplicitLod " + "%v4float %sampled_image %coords123 Bias %float_7", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleBias(x_20, x_10, coords123.xy, i32(coords123.z), 7.0))"}, // OpImageSampleImplicitLod with Bias and signed ConstOffset - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleImplicitLod " - "%v4float %sampled_image %coords12 Bias|ConstOffset " - "%float_7 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{7.000000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleImplicitLod " + "%v4float %sampled_image %coords12 Bias|ConstOffset " + "%float_7 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleBias(x_20, x_10, coords12, 7.0, vec2(3, 4))"}, // OpImageSampleImplicitLod with Bias and unsigned ConstOffset // Convert ConstOffset to signed - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleImplicitLod " - "%v4float %sampled_image %coords12 Bias|ConstOffset " - "%float_7 %u_offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{7.000000} - TypeConstructor[not set]{ - __vec_2__i32 - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleImplicitLod " + "%v4float %sampled_image %coords12 Bias|ConstOffset " + "%float_7 %u_offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleBias(x_20, x_10, coords12, 7.0, vec2(vec2(3u, 4u)))"}, // OpImageSampleImplicitLod arrayed with Bias - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleImplicitLod " - "%v4float %sampled_image %coords123 Bias|ConstOffset " - "%float_7 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{7.000000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleImplicitLod " + "%v4float %sampled_image %coords123 Bias|ConstOffset " + "%float_7 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleBias(x_20, x_10, coords123.xy, i32(coords123.z), 7.0, vec2(3, 4))"})); INSTANTIATE_TEST_SUITE_P( // This test shows the use of a sampled image used with both regular @@ -2042,259 +1696,60 @@ INSTANTIATE_TEST_SUITE_P( %200 = OpImageSampleImplicitLod %v4float %sampled_image %coords12 %210 = OpImageSampleDrefImplicitLod %float %sampled_dref_image %coords12 %depth +)", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; + +[[group(0), binding(1)]] var x_30 : sampler_comparison; )", R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{1} - } - x_30 - none - undefined - __sampler_comparison - })", - R"( - VariableDeclStatement{ - VariableConst{ - x_200 - none - undefined - __vec_4__f32 - { - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_210 - none - undefined - __f32 - { - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_30} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.200000} - ) - } - } - } - })"})); + let x_200 : vec4 = vec4(textureSample(x_20, x_10, coords12), 0.0, 0.0, 0.0); + let x_210 : f32 = textureSampleCompare(x_20, x_30, coords12, 0.200000003); +)"})); INSTANTIATE_TEST_SUITE_P( ImageSampleDrefImplicitLod, SpvParserHandleTest_SampledImageAccessTest, ::testing::Values( // ImageSampleDrefImplicitLod - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleDrefImplicitLod " - "%float %sampled_image %coords12 %depth", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.200000} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleDrefImplicitLod " + "%float %sampled_image %coords12 %depth", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompare(x_20, x_10, coords12, 0.200000003))"}, // ImageSampleDrefImplicitLod - arrayed - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleDrefImplicitLod " - "%float %sampled_image %coords123 %depth", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d_array - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.200000} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleDrefImplicitLod " + "%float %sampled_image %coords123 %depth", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d_array;)", + R"(textureSampleCompare(x_20, x_10, coords123.xy, i32(coords123.z), 0.200000003))"}, // ImageSampleDrefImplicitLod with ConstOffset ImageAccessCase{ "%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleDrefImplicitLod %float " "%sampled_image %coords12 %depth ConstOffset %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.200000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompare(x_20, x_10, coords12, 0.200000003, vec2(3, 4)))"}, // ImageSampleDrefImplicitLod arrayed with ConstOffset ImageAccessCase{ "%float 2D 0 1 0 1 Unknown", "%result = OpImageSampleDrefImplicitLod %float " "%sampled_image %coords123 %depth ConstOffset %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d_array - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.200000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d_array;)", + R"(textureSampleCompare(x_20, x_10, coords123.xy, i32(coords123.z), 0.200000003, vec2(3, 4)))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleDrefExplicitLod, @@ -2303,257 +1758,63 @@ INSTANTIATE_TEST_SUITE_P( // Another test checks cases where the Lod is not float constant 0. ::testing::Values( // 2D - ImageAccessCase{"%float 2D 1 0 0 1 Unknown", - "%result = OpImageSampleDrefExplicitLod " - "%float %sampled_image %coords12 %depth Lod %float_0", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.200000} - ) - })"}, + ImageAccessCase{ + "%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod " + "%float %sampled_image %coords12 %depth Lod %float_0", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompareLevel(x_20, x_10, coords12, 0.200000003))"}, // 2D array - ImageAccessCase{"%float 2D 1 1 0 1 Unknown", - "%result = OpImageSampleDrefExplicitLod " - "%float %sampled_image %coords123 %depth Lod %float_0", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d_array - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.200000} - ) - })"}, + ImageAccessCase{ + "%float 2D 1 1 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod " + "%float %sampled_image %coords123 %depth Lod %float_0", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d_array;)", + R"(textureSampleCompareLevel(x_20, x_10, coords123.xy, i32(coords123.z), 0.200000003))"}, // 2D, ConstOffset - ImageAccessCase{"%float 2D 1 0 0 1 Unknown", - "%result = OpImageSampleDrefExplicitLod %float " - "%sampled_image %coords12 %depth Lod|ConstOffset " - "%float_0 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.200000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod %float " + "%sampled_image %coords12 %depth Lod|ConstOffset " + "%float_0 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompareLevel(x_20, x_10, coords12, 0.200000003, vec2(3, 4)))"}, // 2D array, ConstOffset - ImageAccessCase{"%float 2D 1 1 0 1 Unknown", - "%result = OpImageSampleDrefExplicitLod %float " - "%sampled_image %coords123 %depth Lod|ConstOffset " - "%float_0 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d_array - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.200000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 1 1 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod %float " + "%sampled_image %coords123 %depth Lod|ConstOffset " + "%float_0 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d_array;)", + R"(textureSampleCompareLevel(x_20, x_10, coords123.xy, i32(coords123.z), 0.200000003, vec2(3, 4)))"}, // Cube - ImageAccessCase{"%float Cube 1 0 0 1 Unknown", - "%result = OpImageSampleDrefExplicitLod " - "%float %sampled_image %coords123 %depth Lod %float_0", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_cube - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords123} - ScalarConstructor[not set]{0.200000} - ) - })"}, + ImageAccessCase{ + "%float Cube 1 0 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod " + "%float %sampled_image %coords123 %depth Lod %float_0", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_cube;)", + R"(textureSampleCompareLevel(x_20, x_10, coords123, 0.200000003))"}, // Cube array - ImageAccessCase{"%float Cube 1 1 0 1 Unknown", - "%result = OpImageSampleDrefExplicitLod " - "%float %sampled_image %coords1234 %depth Lod %float_0", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_cube_array - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords1234} - Identifier[not set]{xyz} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords1234} - Identifier[not set]{w} - } - } - ScalarConstructor[not set]{0.200000} - ) - })"})); + ImageAccessCase{ + "%float Cube 1 1 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod " + "%float %sampled_image %coords1234 %depth Lod %float_0", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_cube_array;)", + R"(textureSampleCompareLevel(x_20, x_10, coords1234.xyz, i32(coords1234.w), 0.200000003))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleExplicitLod_UsingLod, @@ -2564,223 +1825,54 @@ INSTANTIATE_TEST_SUITE_P( ImageAccessCase{"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleExplicitLod " "%v4float %sampled_image %coords12 Lod %float_null", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.000000} - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleLevel(x_20, x_10, coords12, 0.0))"}, // OpImageSampleExplicitLod arrayed - using Lod - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords123 Lod %float_null", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.000000} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords123 Lod %float_null", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleLevel(x_20, x_10, coords123.xy, i32(coords123.z), 0.0))"}, // OpImageSampleExplicitLod - using Lod and ConstOffset - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords12 Lod|ConstOffset " - "%float_null %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords12 Lod|ConstOffset " + "%float_null %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleLevel(x_20, x_10, coords12, 0.0, vec2(3, 4)))"}, // OpImageSampleExplicitLod - using Lod and unsigned ConstOffset // Convert the ConstOffset operand to signed - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords12 Lod|ConstOffset " - "%float_null %u_offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __vec_2__i32 - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords12 Lod|ConstOffset " + "%float_null %u_offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleLevel(x_20, x_10, coords12, 0.0, vec2(vec2(3u, 4u)))"}, // OpImageSampleExplicitLod arrayed - using Lod and ConstOffset - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords123 Lod|ConstOffset " - "%float_null %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords123 Lod|ConstOffset " + "%float_null %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleLevel(x_20, x_10, coords123.xy, i32(coords123.z), 0.0, vec2(3, 4)))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleExplicitLod_UsingGrad, @@ -2788,287 +1880,69 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // OpImageSampleExplicitLod - using Grad - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords12 Grad %vf12 %vf21", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - Identifier[not set]{vf12} - Identifier[not set]{vf21} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords12 Grad %vf12 %vf21", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21))"}, // OpImageSampleExplicitLod arrayed - using Grad - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords123 Grad %vf12 %vf21", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{vf12} - Identifier[not set]{vf21} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords123 Grad %vf12 %vf21", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(coords123.z), vf12, vf21))"}, // OpImageSampleExplicitLod - using Grad and ConstOffset - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords12 Grad|ConstOffset " - "%vf12 %vf21 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - Identifier[not set]{vf12} - Identifier[not set]{vf21} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords12 Grad|ConstOffset " + "%vf12 %vf21 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21, vec2(3, 4)))"}, // OpImageSampleExplicitLod - using Grad and unsigned ConstOffset - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords12 Grad|ConstOffset " - "%vf12 %vf21 %u_offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{coords12} - Identifier[not set]{vf12} - Identifier[not set]{vf21} - TypeConstructor[not set]{ - __vec_2__i32 - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords12 Grad|ConstOffset " + "%vf12 %vf21 %u_offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21, vec2(vec2(3u, 4u)))"}, // OpImageSampleExplicitLod arrayed - using Grad and ConstOffset - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords123 Grad|ConstOffset " - "%vf12 %vf21 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{vf12} - Identifier[not set]{vf21} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords123 Grad|ConstOffset " + "%vf12 %vf21 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(coords123.z), vf12, vf21, vec2(3, 4)))"}, // OpImageSampleExplicitLod arrayed - using Grad and unsigned // ConstOffset - ImageAccessCase{"%float 2D 0 1 0 1 Unknown", - "%result = OpImageSampleExplicitLod " - "%v4float %sampled_image %coords123 Grad|ConstOffset " - "%vf12 %vf21 %u_offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{vf12} - Identifier[not set]{vf21} - TypeConstructor[not set]{ - __vec_2__i32 - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - } - ) - })"})); + ImageAccessCase{ + "%float 2D 0 1 0 1 Unknown", + "%result = OpImageSampleExplicitLod " + "%v4float %sampled_image %coords123 Grad|ConstOffset " + "%vf12 %vf21 %u_offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(coords123.z), vf12, vf21, vec2(vec2(3u, 4u))))"})); // Test crbug.com/378: // In WGSL, sampling from depth texture with explicit level of detail @@ -3084,81 +1958,19 @@ INSTANTIATE_TEST_SUITE_P( {"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleExplicitLod %v4float " "%sampled_image %vf12 Lod %f1", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{vf12} - Identifier[not set]{f1} - ) - })"}, + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleLevel(x_20, x_10, vf12, f1))"}, // Test a depth case {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleExplicitLod %v4float " "%sampled_image %vf12 Lod %f1", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{vf12} - TypeConstructor[not set]{ - __i32 - Identifier[not set]{f1} - } - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - })"}})); + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(vec4(textureSampleLevel(x_20, x_10, vf12, i32(f1)), 0.0, 0.0, 0.0))"}})); ///// // Projection sampling @@ -3191,139 +2003,34 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // OpImageSampleProjImplicitLod 1D - ImageAccessCase{"%float 1D 0 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords12", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_1d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords12} - Identifier[not set]{x} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords12} - Identifier[not set]{y} - } - } - ) - })"}, + ImageAccessCase{ + "%float 1D 0 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords12", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_1d;)", + R"(textureSample(x_20, x_10, (coords12.x / coords12.y)))"}, // OpImageSampleProjImplicitLod 2D - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords123", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords123", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSample(x_20, x_10, (coords123.xy / coords123.z)))"}, // OpImageSampleProjImplicitLod 3D - ImageAccessCase{"%float 3D 0 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords1234", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_3d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords1234} - Identifier[not set]{xyz} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords1234} - Identifier[not set]{w} - } - } - ) - })"}, + ImageAccessCase{ + "%float 3D 0 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords1234", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_3d;)", + R"(textureSample(x_20, x_10, (coords1234.xyz / coords1234.w)))"}, // OpImageSampleProjImplicitLod 2D with ConstOffset // (Don't need to test with 1D or 3D, as the hard part was the splatted @@ -3332,51 +2039,10 @@ INSTANTIATE_TEST_SUITE_P( "%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleProjImplicitLod " "%v4float %sampled_image %coords123 ConstOffset %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSample(x_20, x_10, (coords123.xy / coords123.z), vec2(3, 4)))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleProjImplicitLod_Bias, @@ -3385,364 +2051,86 @@ INSTANTIATE_TEST_SUITE_P( // OpImageSampleProjImplicitLod with Bias // Only testing 2D - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords123 Bias %float_7", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{7.000000} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords123 Bias %float_7", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0))"}, // OpImageSampleProjImplicitLod with Bias and signed ConstOffset - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords123 Bias|ConstOffset " - "%float_7 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{7.000000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords123 Bias|ConstOffset " + "%float_7 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0, vec2(3, 4)))"}, // OpImageSampleProjImplicitLod with Bias and unsigned ConstOffset // Convert ConstOffset to signed - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords123 Bias|ConstOffset " - "%float_7 %u_offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleBias} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{7.000000} - TypeConstructor[not set]{ - __vec_2__i32 - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{3u} - ScalarConstructor[not set]{4u} - } - } - ) - })"})); + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords123 Bias|ConstOffset " + "%float_7 %u_offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0, vec2(vec2(3u, 4u))))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleProjExplicitLod_Lod, SpvParserHandleTest_SampledImageAccessTest, ::testing::Values( // OpImageSampleProjExplicitLod 2D - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjExplicitLod " - "%v4float %sampled_image %coords123 Lod %f1", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{f1} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjExplicitLod " + "%v4float %sampled_image %coords123 Lod %f1", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleLevel(x_20, x_10, (coords123.xy / coords123.z), f1))"}, // OpImageSampleProjExplicitLod 2D Lod with ConstOffset ImageAccessCase{ "%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleProjExplicitLod " "%v4float %sampled_image %coords123 Lod|ConstOffset %f1 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{f1} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleLevel(x_20, x_10, (coords123.xy / coords123.z), f1, vec2(3, 4)))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleProjExplicitLod_Grad, SpvParserHandleTest_SampledImageAccessTest, ::testing::Values( // OpImageSampleProjExplicitLod 2D Grad - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjExplicitLod " - "%v4float %sampled_image %coords123 Grad %vf12 %vf21", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{vf12} - Identifier[not set]{vf21} - ) - })"}, + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjExplicitLod " + "%v4float %sampled_image %coords123 Grad %vf12 %vf21", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleGrad(x_20, x_10, (coords123.xy / coords123.z), vf12, vf21))"}, // OpImageSampleProjExplicitLod 2D Lod Grad ConstOffset - ImageAccessCase{"%float 2D 0 0 0 1 Unknown", - "%result = OpImageSampleProjExplicitLod " - "%v4float %sampled_image %coords123 Grad|ConstOffset " - "%vf12 %vf21 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleGrad} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{vf12} - Identifier[not set]{vf21} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + ImageAccessCase{ + "%float 2D 0 0 0 1 Unknown", + "%result = OpImageSampleProjExplicitLod " + "%v4float %sampled_image %coords123 Grad|ConstOffset " + "%vf12 %vf21 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(textureSampleGrad(x_20, x_10, (coords123.xy / coords123.z), vf12, vf21, vec2(3, 4)))"})); INSTANTIATE_TEST_SUITE_P( // Ordinary (non-comparison) sampling on a depth texture. @@ -3750,58 +2138,18 @@ INSTANTIATE_TEST_SUITE_P( SpvParserHandleTest_SampledImageAccessTest, ::testing::Values( // OpImageSampleProjImplicitLod 2D depth - ImageAccessCase{"%float 2D 1 0 0 1 Unknown", - "%result = OpImageSampleProjImplicitLod " - "%v4float %sampled_image %coords123", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - // Sampling the depth texture yields an f32, but the - // SPIR-V operation yiedls vec4, so fill out the - // remaining components with 0. - R"( - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - })"})); + ImageAccessCase{ + "%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleProjImplicitLod " + "%v4float %sampled_image %coords123", + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + // Sampling the depth texture yields an f32, but the + // SPIR-V operation yiedls vec4, so fill out the + // remaining components with 0. + R"(vec4(textureSample(x_20, x_10, (coords123.xy / coords123.z)), 0.0, 0.0, 0.0))"})); INSTANTIATE_TEST_SUITE_P( ImageSampleProjDrefImplicitLod, @@ -3809,102 +2157,26 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( // OpImageSampleProjDrefImplicitLod 2D depth-texture - ImageAccessCase{"%float 2D 1 0 0 1 Unknown", - "%result = OpImageSampleProjDrefImplicitLod " - "%float %sampled_image %coords123 %f1", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{f1} - ) - })"}, + ImageAccessCase{ + "%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleProjDrefImplicitLod " + "%float %sampled_image %coords123 %f1", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompare(x_20, x_10, (coords123.xy / coords123.z), f1))"}, // OpImageSampleProjDrefImplicitLod 2D depth-texture, ConstOffset ImageAccessCase{ "%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleProjDrefImplicitLod " "%float %sampled_image %coords123 %f1 ConstOffset %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - Identifier[not set]{f1} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompare(x_20, x_10, (coords123.xy / coords123.z), f1, vec2(3, 4)))"})); INSTANTIATE_TEST_SUITE_P( DISABLED_ImageSampleProjDrefExplicitLod_Lod, @@ -3915,104 +2187,27 @@ INSTANTIATE_TEST_SUITE_P( // Another test checks cases where the Lod is not float constant 0. // OpImageSampleProjDrefExplicitLod 2D depth-texture Lod - ImageAccessCase{"%float 2D 1 0 0 1 Unknown", - "%result = OpImageSampleProjDrefExplicitLod " - "%float %sampled_image %coords123 %depth Lod %float_0", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompare} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.200000} - ScalarConstructor[not set]{0.000000} - ) - })"}, + ImageAccessCase{ + "%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleProjDrefExplicitLod " + "%float %sampled_image %coords123 %depth Lod %float_0", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompare(x_20, x_10, (coords123.xy / coords123.z), 0.200000003, 0.0))"}, // OpImageSampleProjDrefImplicitLod 2D depth-texture, Lod ConstOffset - ImageAccessCase{"%float 2D 1 0 0 1 Unknown", - "%result = OpImageSampleProjDrefExplicitLod " - "%float %sampled_image %coords123 %depth " - "Lod|ConstOffset %float_0 %offsets2d", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_comparison - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"( - Call[not set]{ - Identifier[not set]{textureSampleCompareLevel} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{coords123} - Identifier[not set]{z} - } - } - ScalarConstructor[not set]{0.200000} - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{3} - ScalarConstructor[not set]{4} - } - ) - })"})); + ImageAccessCase{ + "%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleProjDrefExplicitLod " + "%float %sampled_image %coords123 %depth " + "Lod|ConstOffset %float_0 %offsets2d", + R"([[group(0), binding(0)]] var x_10 : sampler_comparison; + +[[group(2), binding(1)]] var x_20 : texture_depth_2d; +)", + R"(textureSampleCompareLevel(x_20, x_10, (coords123.xy / coords123.z), 0.200000003, 0.0, vec2(3, 4)))"})); ///// // End projection sampling @@ -4078,7 +2273,7 @@ TEST_P(SpvParserHandleTest_ImageAccessTest, Variable) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()) << p->error(); - const auto program = p->program().to_str(); + const auto program = test::ToString(p->program()); EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) << "DECLARATIONS ARE BAD " << program; EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin)) @@ -4091,25 +2286,9 @@ INSTANTIATE_TEST_SUITE_P(ImageWrite_OptionalParams, // OpImageWrite with no extra params {"%float 2D 0 0 0 2 Rgba32f", "OpImageWrite %im %vi12 %vf1234", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{vf1234} - ) - })"}})); + "[[group(2), binding(1)]] var x_20 : " + "texture_storage_2d;", + "textureStore(x_20, vi12, vf1234);"}})); INSTANTIATE_TEST_SUITE_P( // SPIR-V's texel parameter is a scalar or vector with at least as many @@ -4122,197 +2301,38 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(std::vector{ // Source 1 component {"%float 2D 0 0 0 2 R32f", "OpImageWrite %im %vi12 %f1", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_r32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__f32 - Identifier[not set]{f1} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vec4(f1, 0.0, 0.0, 0.0));"}, // Source 2 component, dest 1 component {"%float 2D 0 0 0 2 R32f", "OpImageWrite %im %vi12 %vf12", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_r32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__f32 - Identifier[not set]{vf12} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vec4(vf12, 0.0, 0.0));"}, // Source 3 component, dest 1 component {"%float 2D 0 0 0 2 R32f", "OpImageWrite %im %vi12 %vf123", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_r32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__f32 - Identifier[not set]{vf123} - ScalarConstructor[not set]{0.000000} - } - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vec4(vf123, 0.0));"}, // Source 4 component, dest 1 component {"%float 2D 0 0 0 2 R32f", "OpImageWrite %im %vi12 %vf1234", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_r32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{vf1234} - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vf1234);"}, // Source 2 component, dest 2 component {"%float 2D 0 0 0 2 Rg32f", "OpImageWrite %im %vi12 %vf12", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rg32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__f32 - Identifier[not set]{vf12} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vec4(vf12, 0.0, 0.0));"}, // Source 3 component, dest 2 component {"%float 2D 0 0 0 2 Rg32f", "OpImageWrite %im %vi12 %vf123", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rg32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__f32 - Identifier[not set]{vf123} - ScalarConstructor[not set]{0.000000} - } - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vec4(vf123, 0.0));"}, // Source 4 component, dest 2 component {"%float 2D 0 0 0 2 Rg32f", "OpImageWrite %im %vi12 %vf1234", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rg32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{vf1234} - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + "textureStore(x_20, vi12, vf1234);"}, // WGSL does not support 3-component storage textures. // Source 4 component, dest 4 component {"%float 2D 0 0 0 2 Rgba32f", "OpImageWrite %im %vi12 %vf1234", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32float_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{vf1234} - ) - })"}})); + "[[group(2), binding(1)]] var x_20 : " + "texture_storage_2d;", + "textureStore(x_20, vi12, vf1234);"}})); TEST_F(SpvParserHandleTest, ImageWrite_TooFewSrcTexelComponents_1_vs_4) { const auto assembly = Preamble() + R"( @@ -4391,46 +2411,12 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(std::vector{ // Sampled type is unsigned int, texel is unsigned int {"%uint 2D 0 0 0 2 Rgba32ui", "OpImageWrite %im %vi12 %vu1234", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32uint_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{vu1234} - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + R"(textureStore(x_20, vi12, vu1234))"}, // Sampled type is signed int, texel is signed int {"%int 2D 0 0 0 2 Rgba32i", "OpImageWrite %im %vi12 %vi1234", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32sint_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{vi1234} - ) - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + R"(textureStore(x_20, vi12, vi1234))"}})); INSTANTIATE_TEST_SUITE_P( // Error out when OpImageWrite write texel differ in float vs. integral @@ -4443,64 +2429,25 @@ INSTANTIATE_TEST_SUITE_P( "invalid texel type for storage texture write: component must be " "float, signed integer, or unsigned integer to match the texture " "channel type: OpImageWrite", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32float_write - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)"}, // Sampled type is float, texel is unsigned int {"%int 2D 0 0 0 2 Rgba32f", "OpImageWrite %im %vi12 %vu1234", "invalid texel type for storage texture write: component must be " "float, signed integer, or unsigned integer to match the texture " "channel type: OpImageWrite", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32float_write - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)"}, // Sampled type is unsigned int, texel is float {"%uint 2D 0 0 0 2 Rgba32ui", "OpImageWrite %im %vi12 %vf1234", "invalid texel type for storage texture write: component must be " "float, signed integer, or unsigned integer to match the texture " "channel type: OpImageWrite", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32uint_write - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)"}, // Sampled type is signed int, texel is float {"%int 2D 0 0 0 2 Rgba32i", "OpImageWrite %im %vi12 %vf1234", "invalid texel type for storage texture write: component must be " "float, signed integer, or unsigned integer to match the texture " "channel type: OpImageWrite", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32sint_write + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d; })"}})); INSTANTIATE_TEST_SUITE_P( @@ -4514,32 +2461,13 @@ INSTANTIATE_TEST_SUITE_P( "invalid texel type for storage texture write: component must be " "float, signed integer, or unsigned integer to match the texture " "channel type: OpImageWrite", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32uint_write - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)"}, // Sampled type is signed int, texel is unsigned int {"%int 2D 0 0 0 2 Rgba32i", "OpImageWrite %im %vi12 %vu1234", "invalid texel type for storage texture write: component must be " "float, signed integer, or unsigned integer to match the texture " "channel type: OpImageWrite", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_rgba32sint_write + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d; })"}})); INSTANTIATE_TEST_SUITE_P( @@ -4550,91 +2478,12 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(std::vector{ // Source unsigned, dest unsigned {"%uint 2D 0 0 0 2 R32ui", "OpImageWrite %im %vi12 %vu12", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_r32uint_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__u32 - Identifier[not set]{vu12} - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - ) - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + R"(textureStore(x_20, vi12, vec4(vu12, 0u, 0u)))"}, // Source signed, dest signed {"%int 2D 0 0 0 2 R32i", "OpImageWrite %im %vi12 %vi12", - R"( - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __storage_texture_2d_r32sint_write - })", - R"(Call[not set]{ - Identifier[not set]{textureStore} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __vec_4__i32 - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - ) - })"}})); - -INSTANTIATE_TEST_SUITE_P(ImageRead_OptionalParams, - SpvParserHandleTest_ImageAccessTest, - ::testing::ValuesIn(std::vector{ - // OpImageRead with no extra params - {"%float 2D 0 0 0 2 Rgba32f", - "%99 = OpImageRead %v4float %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_storage_2d;)", + R"(textureStore(x_20, vi12, vec4(vi12, 0, 0)))"}})); INSTANTIATE_TEST_SUITE_P( ImageFetch_OptionalParams, @@ -4643,184 +2492,36 @@ INSTANTIATE_TEST_SUITE_P( // OpImageFetch with no extra params, on sampled texture // Level of detail is injected for sampled texture {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageFetch with explicit level, on sampled texture {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12 Lod %int_3", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{3} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 3);)"}, // OpImageFetch with no extra params, on depth texture // Level of detail is injected for depth texture {"%float 2D 1 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d;)", + R"(let x_99 : vec4 = vec4(textureLoad(x_20, vi12, 0), 0.0, 0.0, 0.0);)"}, // OpImageFetch with extra params, on depth texture {"%float 2D 1 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12 Lod %int_3", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{3} - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d;)", + R"(let x_99 : vec4 = vec4(textureLoad(x_20, vi12, 3), 0.0, 0.0, 0.0);)"}})); -INSTANTIATE_TEST_SUITE_P(ImageFetch_Depth, - // In SPIR-V OpImageFetch always yields a vector of 4 - // elements, even for depth images. But in WGSL, - // textureLoad on a depth image yields f32. - // crbug.com/tint/439 - SpvParserHandleTest_ImageAccessTest, - ::testing::ValuesIn(std::vector{ - // ImageFetch on depth image. - {"%float 2D 1 0 0 1 Unknown", - "%99 = OpImageFetch %v4float %im %vi12 ", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - })"}})); +INSTANTIATE_TEST_SUITE_P( + ImageFetch_Depth, + // In SPIR-V OpImageFetch always yields a vector of 4 + // elements, even for depth images. But in WGSL, + // textureLoad on a depth image yields f32. + // crbug.com/tint/439 + SpvParserHandleTest_ImageAccessTest, + ::testing::ValuesIn(std::vector{ + // ImageFetch on depth image. + {"%float 2D 1 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12 ", + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d;)", + R"(let x_99 : vec4 = vec4(textureLoad(x_20, vi12, 0), 0.0, 0.0, 0.0);)"}})); INSTANTIATE_TEST_SUITE_P( ImageFetch_DepthMultisampled, @@ -4833,40 +2534,8 @@ INSTANTIATE_TEST_SUITE_P( // ImageFetch on multisampled depth image. {"%float 2D 1 0 1 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12 Sample %i1", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_multisampled_texture_2d - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - TypeConstructor[not set]{ - __vec_4__f32 - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{i1} - ) - } - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_depth_multisampled_2d;)", + R"(let x_99 : vec4 = vec4(textureLoad(x_20, vi12, i1), 0.0, 0.0, 0.0);)"}})); INSTANTIATE_TEST_SUITE_P( ImageFetch_Multisampled, @@ -4881,34 +2550,8 @@ INSTANTIATE_TEST_SUITE_P( // ImageFetch non-arrayed {"%float 2D 0 0 1 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12 Sample %i1", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __multisampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - Identifier[not set]{i1} - ) - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_multisampled_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, i1);)"}})); INSTANTIATE_TEST_SUITE_P( ImageFetch_Multisampled_ConvertSampleOperand, @@ -4916,37 +2559,8 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(std::vector{ {"%float 2D 0 0 1 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12 Sample %u1", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __multisampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - TypeConstructor[not set]{ - __i32 - Identifier[not set]{u1} - } - ) - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_multisampled_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, i32(u1));)"}})); INSTANTIATE_TEST_SUITE_P( ConvertResultSignedness, @@ -4968,64 +2582,12 @@ INSTANTIATE_TEST_SUITE_P( // OpImageFetch requires no conversion, float -> v4float {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageFetch requires no conversion, uint -> v4uint {"%uint 2D 0 0 0 1 Unknown", "%99 = OpImageFetch %v4uint %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__u32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__u32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageFetch requires conversion, uint -> v4int // is invalid SPIR-V: // "Expected Image 'Sampled Type' to be the same as Result Type @@ -5033,34 +2595,8 @@ INSTANTIATE_TEST_SUITE_P( // OpImageFetch requires no conversion, int -> v4int {"%int 2D 0 0 0 1 Unknown", "%99 = OpImageFetch %v4int %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__i32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__i32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageFetch requires conversion, int -> v4uint // is invalid SPIR-V: // "Expected Image 'Sampled Type' to be the same as Result Type @@ -5072,64 +2608,12 @@ INSTANTIATE_TEST_SUITE_P( // OpImageRead requires no conversion, float -> v4float {"%float 2D 0 0 0 2 Rgba32f", "%99 = OpImageRead %v4float %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageRead requires no conversion, uint -> v4uint {"%uint 2D 0 0 0 2 Rgba32ui", "%99 = OpImageRead %v4uint %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__u32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__u32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageRead requires conversion, uint -> v4int // is invalid SPIR-V: @@ -5138,34 +2622,8 @@ INSTANTIATE_TEST_SUITE_P( // OpImageRead requires no conversion, int -> v4int {"%int 2D 0 0 0 2 Rgba32i", "%99 = OpImageRead %v4int %im %vi12", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__i32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__i32 - { - Call[not set]{ - Identifier[not set]{textureLoad} - ( - Identifier[not set]{x_20} - Identifier[not set]{vi12} - ScalarConstructor[not set]{0} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureLoad(x_20, vi12, 0);)"}, // OpImageRead requires conversion, int -> v4uint // is invalid SPIR-V: @@ -5181,45 +2639,10 @@ INSTANTIATE_TEST_SUITE_P( // OpImageSampleImplicitLod requires no conversion, float -> v4float {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageSampleImplicitLod %v4float %sampled_image %vf12", - R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_10 - none - undefined - __sampler_sampler - } - Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_20} - Identifier[not set]{x_10} - Identifier[not set]{vf12} - ) - } - } - } - })"}})); + R"([[group(0), binding(0)]] var x_10 : sampler; + +[[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec4 = textureSample(x_20, x_10, vf12);)"}})); INSTANTIATE_TEST_SUITE_P( ImageQuerySize_NonArrayed_SignedResult, @@ -5233,135 +2656,27 @@ INSTANTIATE_TEST_SUITE_P( "%99 = OpImageQuerySize %int %im \n" "%98 = OpImageRead %v4float %im %i1\n", // Implicitly mark as // NonWritable - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_1d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - TypeConstructor[not set]{ - __i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_1d;)", + R"(let x_99 : i32 = i32(textureDimensions(x_20));)"}, // 2D storage image {"%float 2D 0 0 0 2 Rgba32f", "%99 = OpImageQuerySize %v2int %im \n" "%98 = OpImageRead %v4float %im %vi12\n", // Implicitly mark as // NonWritable - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec2 = vec2(textureDimensions(x_20))"}, // 3D storage image {"%float 3D 0 0 0 2 Rgba32f", "%99 = OpImageQuerySize %v3int %im \n" "%98 = OpImageRead %v4float %im %vi123\n", // Implicitly mark as // NonWritable - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_3d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_3d;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20));)"}, // Multisampled {"%float 2D 0 0 1 1 Unknown", "%99 = OpImageQuerySize %v2int %im \n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __multisampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_multisampled_2d;)", + R"(let x_99 : vec2 = vec2(textureDimensions(x_20));)"}})); INSTANTIATE_TEST_SUITE_P( ImageQuerySize_Arrayed_SignedResult, @@ -5376,261 +2691,55 @@ INSTANTIATE_TEST_SUITE_P( {"%float 2D 0 1 0 2 Rgba32f", "%99 = OpImageQuerySize %v3int %im \n" "%98 = OpImageRead %v4float %im %vi123\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - ) - } - Call[not set]{ - Identifier[not set]{textureNumLayers} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"} + R"([[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20), textureNumLayers(x_20));)"} // 3D array storage image doesn't exist. // Multisampled array // Not in WebGPU })); -INSTANTIATE_TEST_SUITE_P(ImageQuerySizeLod_NonArrayed_SignedResult_SignedLevel, - // From VUID-StandaloneSpirv-OpImageQuerySizeLod-04659: - // ImageQuerySizeLod requires Sampled=1 - SpvParserHandleTest_SampledImageAccessTest, - ::testing::ValuesIn(std::vector{ - // 1D - {"%float 1D 0 0 0 1 Unknown", - "%99 = OpImageQuerySizeLod %int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_1d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - TypeConstructor[not set]{ - __i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - } - } - } - })"}, +INSTANTIATE_TEST_SUITE_P( + ImageQuerySizeLod_NonArrayed_SignedResult_SignedLevel, + // From VUID-StandaloneSpirv-OpImageQuerySizeLod-04659: + // ImageQuerySizeLod requires Sampled=1 + SpvParserHandleTest_SampledImageAccessTest, + ::testing::ValuesIn(std::vector{ + // 1D + {"%float 1D 0 0 0 1 Unknown", + "%99 = OpImageQuerySizeLod %int %im %i1\n", + R"([[group(2), binding(1)]] var x_20 : texture_1d;)", + R"(let x_99 : i32 = i32(textureDimensions(x_20, i1)))"}, - // 2D - {"%float 2D 0 0 0 1 Unknown", - "%99 = OpImageQuerySizeLod %v2int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - } - } - } - })"}, + // 2D + {"%float 2D 0 0 0 1 Unknown", + "%99 = OpImageQuerySizeLod %v2int %im %i1\n", + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : vec2 = vec2(textureDimensions(x_20, i1));)"}, - // 3D - {"%float 3D 0 0 0 1 Unknown", - "%99 = OpImageQuerySizeLod %v3int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_3d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - } - } - } - })"}, + // 3D + {"%float 3D 0 0 0 1 Unknown", + "%99 = OpImageQuerySizeLod %v3int %im %i1\n", + R"([[group(2), binding(1)]] var x_20 : texture_3d;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20, i1));)"}, - // Cube - {"%float Cube 0 0 0 1 Unknown", - "%99 = OpImageQuerySizeLod %v2int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_cube__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - MemberAccessor[not set]{ - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - Identifier[not set]{xy} - } - } - } - } - })"}, + // Cube + {"%float Cube 0 0 0 1 Unknown", + "%99 = OpImageQuerySizeLod %v2int %im %i1\n", + R"([[group(2), binding(1)]] var x_20 : texture_cube;)", + R"(let x_99 : vec2 = vec2(textureDimensions(x_20, i1).xy);)"}, - // Depth 2D - {"%float 2D 1 0 0 1 Unknown", - "%99 = OpImageQuerySizeLod %v2int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - } - } - } - })"}, + // Depth 2D + {"%float 2D 1 0 0 1 Unknown", + "%99 = OpImageQuerySizeLod %v2int %im %i1\n", + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d;)", + R"(let x_99 : vec2 = vec2(textureDimensions(x_20, i1));)"}, - // Depth Cube - {"%float Cube 1 0 0 1 Unknown", - "%99 = OpImageQuerySizeLod %v2int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_cube - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - MemberAccessor[not set]{ - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - Identifier[not set]{xy} - } - } - } - } - })"}})); + // Depth Cube + {"%float Cube 1 0 0 1 Unknown", + "%99 = OpImageQuerySizeLod %v2int %im %i1\n", + R"([[group(2), binding(1)]] var x_20 : texture_depth_cube;)", + R"(let x_99 : vec2 = vec2(textureDimensions(x_20, i1).xy);)"}})); INSTANTIATE_TEST_SUITE_P( ImageQuerySizeLod_Arrayed_SignedResult_SignedLevel, @@ -5645,42 +2754,8 @@ INSTANTIATE_TEST_SUITE_P( // 2D array {"%float 2D 0 1 0 1 Unknown", "%99 = OpImageQuerySizeLod %v3int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - Call[not set]{ - Identifier[not set]{textureNumLayers} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20, i1), textureNumLayers(x_20));)"}, // There is no 3D array @@ -5691,85 +2766,14 @@ INSTANTIATE_TEST_SUITE_P( // https://github.com/gpuweb/gpuweb/issues/1345 {"%float Cube 0 1 0 1 Unknown", "%99 = OpImageQuerySizeLod %v3int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_cube_array__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - MemberAccessor[not set]{ - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - Identifier[not set]{xy} - } - Call[not set]{ - Identifier[not set]{textureNumLayers} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_cube_array;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20, i1).xy, textureNumLayers(x_20));)"}, // Depth 2D array {"%float 2D 1 1 0 1 Unknown", "%99 = OpImageQuerySizeLod %v3int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d_array - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - Call[not set]{ - Identifier[not set]{textureNumLayers} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d_array;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20, i1), textureNumLayers(x_20));)"}, // Depth Cube Array // @@ -5778,45 +2782,8 @@ INSTANTIATE_TEST_SUITE_P( // https://github.com/gpuweb/gpuweb/issues/1345 {"%float Cube 1 1 0 1 Unknown", "%99 = OpImageQuerySizeLod %v3int %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_cube_array - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __vec_3__i32 - { - TypeConstructor[not set]{ - __vec_3__i32 - MemberAccessor[not set]{ - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - Identifier[not set]{xy} - } - Call[not set]{ - Identifier[not set]{textureNumLayers} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_depth_cube_array;)", + R"(let x_99 : vec3 = vec3(textureDimensions(x_20, i1).xy, textureNumLayers(x_20));)"}})); INSTANTIATE_TEST_SUITE_P( // When the level-of-detail value is given as an unsigned @@ -5828,39 +2795,8 @@ INSTANTIATE_TEST_SUITE_P( {"%float 1D 0 0 0 1 Unknown", "%99 = OpImageQuerySizeLod %int %im %u1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_1d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - TypeConstructor[not set]{ - __i32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - TypeConstructor[not set]{ - __i32 - Identifier[not set]{u1} - } - ) - } - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_1d;)", + R"(let x_99 : i32 = i32(textureDimensions(x_20, i32(u1)));)"}})); INSTANTIATE_TEST_SUITE_P( // When SPIR-V wants the result type to be unsigned, we have to @@ -5873,36 +2809,8 @@ INSTANTIATE_TEST_SUITE_P( {"%float 1D 0 0 0 1 Unknown", "%99 = OpImageQuerySizeLod %uint %im %i1\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_1d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __u32 - { - TypeConstructor[not set]{ - __u32 - Call[not set]{ - Identifier[not set]{textureDimensions} - ( - Identifier[not set]{x_20} - Identifier[not set]{i1} - ) - } - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_1d;)", + R"(let x_99 : u32 = u32(textureDimensions(x_20, i1));)"}})); INSTANTIATE_TEST_SUITE_P( ImageQueryLevels_SignedResult, @@ -5915,264 +2823,48 @@ INSTANTIATE_TEST_SUITE_P( // 2D {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // 2D array {"%float 2D 0 1 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d_array__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_2d_array;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // 3D {"%float 3D 0 0 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_3d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_3d;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // Cube {"%float Cube 0 0 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_cube__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_cube;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // Cube array {"%float Cube 0 1 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_cube_array__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_cube_array;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // depth 2d {"%float 2D 1 0 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // depth 2d array {"%float 2D 1 1 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_2d_array - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_depth_2d_array;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // depth cube {"%float Cube 1 0 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_cube - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}, + R"([[group(2), binding(1)]] var x_20 : texture_depth_cube;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}, // depth cube array {"%float Cube 1 1 0 1 Unknown", "%99 = OpImageQueryLevels %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __depth_texture_cube_array - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_depth_cube_array;)", + R"(let x_99 : i32 = textureNumLevels(x_20);)"}})); INSTANTIATE_TEST_SUITE_P( // Spot check that a type conversion is inserted when SPIR-V asks for @@ -6181,72 +2873,21 @@ INSTANTIATE_TEST_SUITE_P( SpvParserHandleTest_SampledImageAccessTest, ::testing::ValuesIn(std::vector{ {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageQueryLevels %uint %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __sampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __u32 - { - TypeConstructor[not set]{ - __u32 - Call[not set]{ - Identifier[not set]{textureNumLevels} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"}})); + R"([[group(2), binding(1)]] var x_20 : texture_2d;)", + R"(let x_99 : u32 = u32(textureNumLevels(x_20));)"}})); -INSTANTIATE_TEST_SUITE_P(ImageQuerySamples_SignedResult, - SpvParserHandleTest_SampledImageAccessTest, - ::testing::ValuesIn(std::vector{ - // Multsample 2D - {"%float 2D 0 0 1 1 Unknown", - "%99 = OpImageQuerySamples %int %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __multisampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __i32 - { - Call[not set]{ - Identifier[not set]{textureNumSamples} - ( - Identifier[not set]{x_20} - ) - } - } - } - })"} +INSTANTIATE_TEST_SUITE_P( + ImageQuerySamples_SignedResult, + SpvParserHandleTest_SampledImageAccessTest, + ::testing::ValuesIn(std::vector{ + // Multsample 2D + {"%float 2D 0 0 1 1 Unknown", "%99 = OpImageQuerySamples %int %im\n", + R"([[group(2), binding(1)]] var x_20 : texture_multisampled_2d;)", + R"(let x_99 : i32 = textureNumSamples(x_20);)"} // namespace - // Multisample 2D array - // Not in WebGPU - })); + // Multisample 2D array + // Not in WebGPU + })); INSTANTIATE_TEST_SUITE_P( // Translation must inject a type coersion from signed to unsigned. @@ -6255,35 +2896,8 @@ INSTANTIATE_TEST_SUITE_P( ::testing::ValuesIn(std::vector{ // Multsample 2D {"%float 2D 0 0 1 1 Unknown", "%99 = OpImageQuerySamples %uint %im\n", - R"(Variable{ - Decorations{ - GroupDecoration{2} - BindingDecoration{1} - } - x_20 - none - undefined - __multisampled_texture_2d__f32 - })", - R"(VariableDeclStatement{ - VariableConst{ - x_99 - none - undefined - __u32 - { - TypeConstructor[not set]{ - __u32 - Call[not set]{ - Identifier[not set]{textureNumSamples} - ( - Identifier[not set]{x_20} - ) - } - } - } - } - })"} + R"([[group(2), binding(1)]] var x_20 : texture_multisampled_2d;)", + R"(let x_99 : u32 = u32(textureNumSamples(x_20));)"} // Multisample 2D array // Not in WebGPU @@ -6416,7 +3030,7 @@ TEST_P(SpvParserHandleTest_ImageCoordsTest, Program program = p->program(); for (auto* expr : result) { ASSERT_NE(expr, nullptr); - result_strings.push_back(program.str(expr)); + result_strings.push_back(test::ToString(program, expr)); } EXPECT_THAT(result_strings, ::testing::ContainerEq(GetParam().expected_expressions)); @@ -6450,34 +3064,22 @@ INSTANTIATE_TEST_SUITE_P(Good_1D, "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %f1", "", - {"Identifier[not set]{f1}\n"}}, + {"f1"}}, {"%float 1D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf12", // one excess arg "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf12} - Identifier[not set]{x} -} -)"}}, + {"vf12.x"}}, {"%float 1D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf123", // two excess args "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{x} -} -)"}}, + {"vf123.x"}}, {"%float 1D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf1234", // three excess args "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{x} -} -)"}}})); + {"vf1234.x"}}})); INSTANTIATE_TEST_SUITE_P(Good_1DArray, SpvParserHandleTest_ImageCoordsTest, @@ -6486,56 +3088,17 @@ INSTANTIATE_TEST_SUITE_P(Good_1DArray, "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf12", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf12} - Identifier[not set]{x} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf12} - Identifier[not set]{y} - } -} -)"}}, + {"vf12.x", "i32(vf12.y)"}}, {"%float 1D 0 1 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf123", // one excess arg "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{x} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{y} - } -} -)"}}, + {"vf123.x", "i32(vf123.y)"}}, {"%float 1D 0 1 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf1234", // two excess args "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{x} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{y} - } -} -)"}}})); + {"vf1234.x", "i32(vf1234.y)"}}})); INSTANTIATE_TEST_SUITE_P(Good_2D, SpvParserHandleTest_ImageCoordsTest, @@ -6544,25 +3107,17 @@ INSTANTIATE_TEST_SUITE_P(Good_2D, "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf12", "", - {"Identifier[not set]{vf12}\n"}}, + {"vf12"}}, {"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf123", // one excess arg "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{xy} -} -)"}}, + {"vf123.xy"}}, {"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf1234", // two excess args "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xy} -} -)"}}})); + {"vf1234.xy"}}})); INSTANTIATE_TEST_SUITE_P(Good_2DArray, SpvParserHandleTest_ImageCoordsTest, @@ -6571,38 +3126,12 @@ INSTANTIATE_TEST_SUITE_P(Good_2DArray, "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf123", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{xy} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{z} - } -} -)"}}, + {"vf123.xy", "i32(vf123.z)"}}, {"%float 2D 0 1 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float " "%sampled_image %vf1234", // one excess arg "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xy} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{z} - } -} -)"}}})); + {"vf1234.xy", "i32(vf1234.z)"}}})); INSTANTIATE_TEST_SUITE_P(Good_3D, SpvParserHandleTest_ImageCoordsTest, @@ -6612,18 +3141,14 @@ INSTANTIATE_TEST_SUITE_P(Good_3D, "%v4float " "%sampled_image %vf123", "", - {"Identifier[not set]{vf123}\n"}}, + {"vf123"}}, {"%float 3D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod " "%v4float " "%sampled_image %vf1234", // one excess // arg "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xyz} -} -)"}}})); + {"vf1234.xyz"}}})); INSTANTIATE_TEST_SUITE_P(Good_Cube, SpvParserHandleTest_ImageCoordsTest, @@ -6633,18 +3158,14 @@ INSTANTIATE_TEST_SUITE_P(Good_Cube, "%v4float " "%sampled_image %vf123", "", - {"Identifier[not set]{vf123}\n"}}, + {"vf123"}}, {"%float Cube 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod " "%v4float " "%sampled_image %vf1234", // one excess // arg "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xyz} -} -)"}}})); + {"vf1234.xyz"}}})); INSTANTIATE_TEST_SUITE_P(Good_CubeArray, SpvParserHandleTest_ImageCoordsTest, @@ -6654,19 +3175,7 @@ INSTANTIATE_TEST_SUITE_P(Good_CubeArray, "%v4float " "%sampled_image %vf1234", "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xyz} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{w} - } -} -)"}}})); + {"vf1234.xyz", "i32(vf1234.w)"}}})); INSTANTIATE_TEST_SUITE_P( PreserveFloatCoords_NonArrayed, @@ -6679,33 +3188,33 @@ INSTANTIATE_TEST_SUITE_P( {"%float 1D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float %sampled_image %f1", "", - {"Identifier[not set]{f1}\n"}}, + {"f1"}}, {"%float 1D 0 0 0 1 Unknown", "%result = OpImageSampleExplicitLod %v4float %sampled_image %f1 Lod " "%f1", "", - {"Identifier[not set]{f1}\n"}}, + {"f1"}}, // WGSL does not support depth textures with 1D coordinates // Vector cases {"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float %sampled_image %vf12", "", - {"Identifier[not set]{vf12}\n"}}, + {"vf12"}}, {"%float 2D 0 0 0 1 Unknown", "%result = OpImageSampleExplicitLod %v4float %sampled_image %vf12 Lod " "%f1", "", - {"Identifier[not set]{vf12}\n"}}, + {"vf12"}}, {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleDrefImplicitLod %float %sampled_image %vf12 " "%depth", "", - {"Identifier[not set]{vf12}\n"}}, + {"vf12"}}, {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleDrefExplicitLod %float %sampled_image %vf12 " "%depth Lod %float_0", "", - {"Identifier[not set]{vf12}\n"}}, + {"vf12"}}, })); INSTANTIATE_TEST_SUITE_P( @@ -6719,75 +3228,23 @@ INSTANTIATE_TEST_SUITE_P( {"%float 2D 0 1 0 1 Unknown", "%result = OpImageSampleImplicitLod %v4float %sampled_image %vf123", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{xy} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{z} - } -} -)"}}, + {"vf123.xy", "i32(vf123.z)"}}, {"%float 2D 0 1 0 1 Unknown", "%result = OpImageSampleExplicitLod %v4float %sampled_image %vf123 " "Lod %f1", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{xy} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{z} - } -} -)"}}, + {"vf123.xy", "i32(vf123.z)"}}, {"%float 2D 1 1 0 1 Unknown", "%result = OpImageSampleDrefImplicitLod %float %sampled_image " "%vf123 %depth", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{xy} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{z} - } -} -)"}}, + {"vf123.xy", "i32(vf123.z)"}}, {"%float 2D 1 1 0 1 Unknown", "%result = OpImageSampleDrefExplicitLod %float %sampled_image " "%vf123 %depth Lod %float_0", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{xy} -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vf123} - Identifier[not set]{z} - } -} -)"}}})); + {"vf123.xy", "i32(vf123.z)"}}})); INSTANTIATE_TEST_SUITE_P( PreserveIntCoords_NonArrayed, @@ -6799,28 +3256,25 @@ INSTANTIATE_TEST_SUITE_P( {"%float 1D 0 0 0 1 Unknown", "%result = OpImageFetch %v4float %im %i1", "", - {"Identifier[not set]{i1}\n"}}, + {"i1"}}, {"%float 1D 0 0 0 2 R32f", "%result = OpImageRead %v4float %im %i1", "", - {"Identifier[not set]{i1}\n"}}, - {"%float 1D 0 0 0 2 R32f", - "OpImageWrite %im %i1 %vf1234", - "", - {"Identifier[not set]{i1}\n"}}, + {"i1"}}, + {"%float 1D 0 0 0 2 R32f", "OpImageWrite %im %i1 %vf1234", "", {"i1"}}, // Vector cases {"%float 2D 0 0 0 1 Unknown", "%result = OpImageFetch %v4float %im %vi12", "", - {"Identifier[not set]{vi12}\n"}}, + {"vi12"}}, {"%float 2D 0 0 0 2 R32f", "%result = OpImageRead %v4float %im %vi12", "", - {"Identifier[not set]{vi12}\n"}}, + {"vi12"}}, {"%float 2D 0 0 0 2 R32f", "OpImageWrite %im %vi12 %vf1234", "", - {"Identifier[not set]{vi12}\n"}}})); + {"vi12"}}})); INSTANTIATE_TEST_SUITE_P( PreserveIntCoords_Arrayed, @@ -6831,45 +3285,15 @@ INSTANTIATE_TEST_SUITE_P( {"%float 2D 0 1 0 1 Unknown", "%result = OpImageFetch %v4float %im %vi123", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vi123} - Identifier[not set]{xy} -} -)", - R"(MemberAccessor[not set]{ - Identifier[not set]{vi123} - Identifier[not set]{z} -} -)"}}, + {"vi123.xy", "vi123.z"}}, {"%float 2D 0 1 0 2 R32f", "%result = OpImageRead %v4float %im %vi123", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vi123} - Identifier[not set]{xy} -} -)", - R"(MemberAccessor[not set]{ - Identifier[not set]{vi123} - Identifier[not set]{z} -} -)"}}, + {"vi123.xy", "vi123.z"}}, {"%float 2D 0 1 0 2 R32f", "OpImageWrite %im %vi123 %vf1234", "", - { - R"(MemberAccessor[not set]{ - Identifier[not set]{vi123} - Identifier[not set]{xy} -} -)", - R"(MemberAccessor[not set]{ - Identifier[not set]{vi123} - Identifier[not set]{z} -} -)"}}})); + {"vi123.xy", "vi123.z"}}})); INSTANTIATE_TEST_SUITE_P( ConvertUintCoords_NonArrayed, @@ -6881,52 +3305,28 @@ INSTANTIATE_TEST_SUITE_P( {"%float 1D 0 0 0 1 Unknown", "%result = OpImageFetch %v4float %im %u1", "", - {R"(TypeConstructor[not set]{ - __i32 - Identifier[not set]{u1} -} -)"}}, + {"i32(u1)"}}, {"%float 1D 0 0 0 2 R32f", "%result = OpImageRead %v4float %im %u1", "", - {R"(TypeConstructor[not set]{ - __i32 - Identifier[not set]{u1} -} -)"}}, + {"i32(u1)"}}, {"%float 1D 0 0 0 2 R32f", "OpImageWrite %im %u1 %vf1234", "", - {R"(TypeConstructor[not set]{ - __i32 - Identifier[not set]{u1} -} -)"}}, + {"i32(u1)"}}, // Vector cases {"%float 2D 0 0 0 1 Unknown", "%result = OpImageFetch %v4float %im %vu12", "", - {R"(TypeConstructor[not set]{ - __vec_2__i32 - Identifier[not set]{vu12} -} -)"}}, + {"vec2(vu12)"}}, {"%float 2D 0 0 0 2 R32f", "%result = OpImageRead %v4float %im %vu12", "", - {R"(TypeConstructor[not set]{ - __vec_2__i32 - Identifier[not set]{vu12} -} -)"}}, + {"vec2(vu12)"}}, {"%float 2D 0 0 0 2 R32f", "OpImageWrite %im %vu12 %vf1234", "", - {R"(TypeConstructor[not set]{ - __vec_2__i32 - Identifier[not set]{vu12} -} -)"}}})); + {"vec2(vu12)"}}})); INSTANTIATE_TEST_SUITE_P( ConvertUintCoords_Arrayed, @@ -6937,63 +3337,15 @@ INSTANTIATE_TEST_SUITE_P( {"%float 2D 0 1 0 1 Unknown", "%result = OpImageFetch %v4float %im %vu123", "", - { - R"(TypeConstructor[not set]{ - __vec_2__i32 - MemberAccessor[not set]{ - Identifier[not set]{vu123} - Identifier[not set]{xy} - } -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vu123} - Identifier[not set]{z} - } -} -)"}}, + {"vec2(vu123.xy)", "i32(vu123.z)"}}, {"%float 2D 0 1 0 2 R32f", "%result = OpImageRead %v4float %im %vu123", "", - { - R"(TypeConstructor[not set]{ - __vec_2__i32 - MemberAccessor[not set]{ - Identifier[not set]{vu123} - Identifier[not set]{xy} - } -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vu123} - Identifier[not set]{z} - } -} -)"}}, + {"vec2(vu123.xy)", "i32(vu123.z)"}}, {"%float 2D 0 1 0 2 R32f", "OpImageWrite %im %vu123 %vf1234", "", - { - R"(TypeConstructor[not set]{ - __vec_2__i32 - MemberAccessor[not set]{ - Identifier[not set]{vu123} - Identifier[not set]{xy} - } -} -)", - R"(TypeConstructor[not set]{ - __i32 - MemberAccessor[not set]{ - Identifier[not set]{vu123} - Identifier[not set]{z} - } -} -)"}}})); + {"vec2(vu123.xy)", "i32(vu123.z)"}}})); INSTANTIATE_TEST_SUITE_P( BadInstructions, @@ -7196,21 +3548,13 @@ INSTANTIATE_TEST_SUITE_P( "%result = OpImageSampleDrefExplicitLod %float %sampled_image %vf1234 " "%depth Lod %float_0", "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xy} -} -)"}}, + {"vf1234.xy"}}, // float null works {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleDrefExplicitLod %float %sampled_image %vf1234 " "%depth Lod %float_0", "", - {R"(MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xy} -} -)"}}, + {"vf1234.xy"}}, // float 1.0 fails. {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleDrefExplicitLod %float %sampled_image %vf1234 " @@ -7235,35 +3579,13 @@ INSTANTIATE_TEST_SUITE_P( "%result = OpImageSampleProjDrefExplicitLod %float %sampled_image " "%vf1234 %depth Lod %float_0", "", - {R"(Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{z} - } -} -)"}}, + {"(vf1234.xy / vf1234.z)"}}, // float null works {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleProjDrefExplicitLod %float %sampled_image " "%vf1234 %depth Lod %float_0", "", - {R"(Binary[not set]{ - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{xy} - } - divide - MemberAccessor[not set]{ - Identifier[not set]{vf1234} - Identifier[not set]{z} - } -} -)"}}, + {"(vf1234.xy / vf1234.z)"}}, // float 1.0 fails. {"%float 2D 1 0 0 1 Unknown", "%result = OpImageSampleProjDrefExplicitLod %float %sampled_image " @@ -7371,68 +3693,13 @@ TEST_F(SpvParserHandleTest, auto fe = p->function_emitter(100); EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(p->error().empty()) << p->error(); - const auto got = ToString(p->builder(), fe.ast_body()); - auto* expect = R"(VariableDeclStatement{ - Variable{ - var_1 - none - undefined - __vec_4__f32 - } -} -VariableDeclStatement{ - VariableConst{ - x_22 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_2} - Identifier[not set]{x_3} - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - ) - } - } - } -} -VariableDeclStatement{ - VariableConst{ - x_26 - none - undefined - __vec_4__f32 - { - Call[not set]{ - Identifier[not set]{textureSample} - ( - Identifier[not set]{x_2} - Identifier[not set]{x_3} - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - ) - } - } - } -} -Assignment{ - Identifier[not set]{var_1} - Binary[not set]{ - Identifier[not set]{x_22} - add - Identifier[not set]{x_26} - } -} -Return{} + auto ast_body = fe.ast_body(); + const auto got = test::ToString(p->program(), ast_body); + auto* expect = R"(var var_1 : vec4; +let x_22 : vec4 = textureSample(x_2, x_3, vec2(0.0, 0.0)); +let x_26 : vec4 = textureSample(x_2, x_3, vec2(0.0, 0.0)); +var_1 = (x_22 + x_26); +return; )"; ASSERT_EQ(expect, got); } diff --git a/src/reader/spirv/parser_impl_import_test.cc b/src/reader/spirv/parser_impl_import_test.cc index ec7b869f72..9995b0ec98 100644 --- a/src/reader/spirv/parser_impl_import_test.cc +++ b/src/reader/spirv/parser_impl_import_test.cc @@ -33,7 +33,7 @@ TEST_F(SpvParserImportTest, Import_NoImport) { auto p = parser(test::Assemble("%1 = OpTypeVoid")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto program_ast = p->program().to_str(); + const auto program_ast = test::ToString(p->program()); EXPECT_THAT(program_ast, Not(HasSubstr("Import"))); p->DeliberatelyInvalidSpirv(); diff --git a/src/reader/spirv/parser_impl_module_var_test.cc b/src/reader/spirv/parser_impl_module_var_test.cc index e8b9993042..27bca8b7f5 100644 --- a/src/reader/spirv/parser_impl_module_var_test.cc +++ b/src/reader/spirv/parser_impl_module_var_test.cc @@ -16,6 +16,7 @@ #include "src/reader/spirv/function.h" #include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/spirv_tools_helpers_test.h" +#include "src/utils/string.h" namespace tint { namespace reader { @@ -116,7 +117,7 @@ TEST_F(SpvModuleScopeVarParserTest, NoVar) { auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()) << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_ast = p->program().to_str(); + const auto module_ast = test::ToString(p->program()); EXPECT_THAT(module_ast, Not(HasSubstr("Variable"))) << module_ast; } @@ -199,14 +200,8 @@ TEST_F(SpvModuleScopeVarParserTest, AnonWorkgroupVar) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - x_52 - workgroup - undefined - __f32 - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("var x_52 : f32;")); } TEST_F(SpvModuleScopeVarParserTest, NamedWorkgroupVar) { @@ -221,14 +216,8 @@ TEST_F(SpvModuleScopeVarParserTest, NamedWorkgroupVar) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - the_counter - workgroup - undefined - __f32 - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("var the_counter : f32;")); } TEST_F(SpvModuleScopeVarParserTest, PrivateVar) { @@ -243,14 +232,9 @@ TEST_F(SpvModuleScopeVarParserTest, PrivateVar) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - my_own_private_idaho - private - undefined - __f32 - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var my_own_private_idaho : f32;")); } TEST_F(SpvModuleScopeVarParserTest, BuiltinVertexIndex) { @@ -276,14 +260,8 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinVertexIndex) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - x_52 - private - undefined - __u32 - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("var x_52 : u32;")); } std::string PerVertexPreamble() { @@ -377,18 +355,9 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_StorePosition) { auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Assignment{ - Identifier[not set]{gl_Position} - TypeConstructor[not set]{ - __vec_4__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("gl_Position = vec4(0.0, 0.0, 0.0, 0.0);")) << module_str; } @@ -430,18 +399,9 @@ TEST_F(SpvModuleScopeVarParserTest, auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Assignment{ - Identifier[not set]{gl_Position} - TypeConstructor[not set]{ - __vec_4__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("gl_Position = vec4(0.0, 0.0, 0.0, 0.0);")) << module_str; } @@ -461,16 +421,8 @@ TEST_F(SpvModuleScopeVarParserTest, auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{gl_Position} - Identifier[not set]{y} - } - ScalarConstructor[not set]{0.000000} - })")) - << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("gl_Position.y = 0.0;")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, @@ -492,19 +444,8 @@ TEST_F(SpvModuleScopeVarParserTest, auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - { - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{gl_Position} - Identifier[not set]{y} - } - ScalarConstructor[not set]{0.000000} - } - Return{} - })")) - << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("gl_Position.y = 0.0;")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Write1_IsErased) { @@ -522,41 +463,22 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Write1_IsErased) { auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] gl_Position: __vec_4__f32} - } - Variable{ - gl_Position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{gl_Position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var gl_Position : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + gl_Position : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(gl_Position); } )") << module_str; } @@ -598,51 +520,25 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_ReadReplaced) { auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] gl_Position: __vec_4__f32} - } - Variable{ - x_900 - private - undefined - __f32 - } - Variable{ - gl_Position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Assignment{ - Identifier[not set]{x_900} - ScalarConstructor[not set]{1.000000} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{gl_Position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var x_900 : f32; + +var gl_Position : vec4; + +fn main_1() { + x_900 = 1.0; + return; +} + +struct main_out { + [[builtin(position)]] + gl_Position : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(gl_Position); } )") << module_str; } @@ -686,41 +582,22 @@ TEST_F(SpvModuleScopeVarParserTest, auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] gl_Position: __vec_4__f32} - } - Variable{ - gl_Position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{gl_Position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var gl_Position : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + gl_Position : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(gl_Position); } )") << module_str; } @@ -764,41 +641,22 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_Write1_IsErased) { auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_2); } )") << module_str; } @@ -838,51 +696,25 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Variable{ - x_900 - private - undefined - __f32 - } - Function main_1 -> __void - () - { - Assignment{ - Identifier[not set]{x_900} - ScalarConstructor[not set]{1.000000} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var x_2 : vec4; + +var x_900 : f32; + +fn main_1() { + x_900 = 1.0; + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_2); } )") << module_str; } @@ -925,41 +757,22 @@ TEST_F(SpvModuleScopeVarParserTest, auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_2); } )") << module_str; } @@ -980,41 +793,22 @@ TEST_F(SpvModuleScopeVarParserTest, auto p = parser(test::Assemble(assembly)); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()) << p->error(); - const auto module_str = p->program().to_str(); - EXPECT_EQ(module_str, R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto module_str = test::ToString(p->program()); + EXPECT_EQ(module_str, R"(var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_2); } )") << module_str; } @@ -1112,52 +906,17 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarInitializers) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_1 - private - undefined - __bool - { - ScalarConstructor[not set]{true} - } - } - Variable{ - x_2 - private - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } - Variable{ - x_3 - private - undefined - __i32 - { - ScalarConstructor[not set]{-1} - } - } - Variable{ - x_4 - private - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } - Variable{ - x_5 - private - undefined - __f32 - { - ScalarConstructor[not set]{1.500000} - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"(var x_1 : bool = true; + +var x_2 : bool = false; + +var x_3 : i32 = -1; + +var x_4 : u32 = 1u; + +var x_5 : f32 = 1.5; +)")); } TEST_F(SpvModuleScopeVarParserTest, ScalarNullInitializers) { @@ -1174,43 +933,15 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarNullInitializers) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_1 - private - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } - Variable{ - x_2 - private - undefined - __i32 - { - ScalarConstructor[not set]{0} - } - } - Variable{ - x_3 - private - undefined - __u32 - { - ScalarConstructor[not set]{0u} - } - } - Variable{ - x_4 - private - undefined - __f32 - { - ScalarConstructor[not set]{0.000000} - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"(var x_1 : bool = false; + +var x_2 : i32 = 0; + +var x_3 : u32 = 0u; + +var x_4 : f32 = 0.0; +)")); } TEST_F(SpvModuleScopeVarParserTest, ScalarUndefInitializers) { @@ -1227,43 +958,15 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarUndefInitializers) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_1 - private - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } - Variable{ - x_2 - private - undefined - __i32 - { - ScalarConstructor[not set]{0} - } - } - Variable{ - x_3 - private - undefined - __u32 - { - ScalarConstructor[not set]{0u} - } - } - Variable{ - x_4 - private - undefined - __f32 - { - ScalarConstructor[not set]{0.000000} - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"(var x_1 : bool = false; + +var x_2 : i32 = 0; + +var x_3 : u32 = 0u; + +var x_4 : f32 = 0.0; +)")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1278,20 +981,10 @@ TEST_F(SpvModuleScopeVarParserTest, VectorInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{1.500000} - ScalarConstructor[not set]{2.000000} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : vec2 = vec2(1.5, 2.0);")); } TEST_F(SpvModuleScopeVarParserTest, VectorBoolNullInitializer) { @@ -1302,20 +995,10 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__bool - { - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{false} - ScalarConstructor[not set]{false} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : vec2 = vec2(false, false);")); } TEST_F(SpvModuleScopeVarParserTest, VectorBoolUndefInitializer) { @@ -1326,20 +1009,10 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolUndefInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__bool - { - TypeConstructor[not set]{ - __vec_2__bool - ScalarConstructor[not set]{false} - ScalarConstructor[not set]{false} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : vec2 = vec2(false, false);")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1353,20 +1026,9 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : vec2 = vec2(0u, 0u);")); } TEST_F(SpvModuleScopeVarParserTest, VectorUintUndefInitializer) { @@ -1377,20 +1039,9 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintUndefInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__u32 - { - TypeConstructor[not set]{ - __vec_2__u32 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : vec2 = vec2(0u, 0u);")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1404,20 +1055,9 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : vec2 = vec2(0, 0);")); } TEST_F(SpvModuleScopeVarParserTest, VectorIntUndefInitializer) { @@ -1428,20 +1068,9 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntUndefInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__i32 - { - TypeConstructor[not set]{ - __vec_2__i32 - ScalarConstructor[not set]{0} - ScalarConstructor[not set]{0} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : vec2 = vec2(0, 0);")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1455,20 +1084,10 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : vec2 = vec2(0.0, 0.0);")); } TEST_F(SpvModuleScopeVarParserTest, VectorFloatUndefInitializer) { @@ -1479,20 +1098,10 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatUndefInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __vec_2__f32 - { - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : vec2 = vec2(0.0, 0.0);")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1512,33 +1121,12 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __mat_2_3__f32 - { - TypeConstructor[not set]{ - __mat_2_3__f32 - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{1.500000} - ScalarConstructor[not set]{2.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{2.000000} - ScalarConstructor[not set]{3.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{3.000000} - ScalarConstructor[not set]{4.000000} - } - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : mat3x2 = mat3x2(" + "vec2(1.5, 2.0), " + "vec2(2.0, 3.0), " + "vec2(3.0, 4.0));")); } TEST_F(SpvModuleScopeVarParserTest, MatrixNullInitializer) { @@ -1549,33 +1137,12 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __mat_2_3__f32 - { - TypeConstructor[not set]{ - __mat_2_3__f32 - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : mat3x2 = mat3x2(" + "vec2(0.0, 0.0), " + "vec2(0.0, 0.0), " + "vec2(0.0, 0.0));")); } TEST_F(SpvModuleScopeVarParserTest, MatrixUndefInitializer) { @@ -1586,33 +1153,12 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixUndefInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __mat_2_3__f32 - { - TypeConstructor[not set]{ - __mat_2_3__f32 - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - TypeConstructor[not set]{ - __vec_2__f32 - ScalarConstructor[not set]{0.000000} - ScalarConstructor[not set]{0.000000} - } - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("var x_200 : mat3x2 = mat3x2(" + "vec2(0.0, 0.0), " + "vec2(0.0, 0.0), " + "vec2(0.0, 0.0));")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1627,20 +1173,11 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __array__u32_2 - { - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{2u} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr( + "var x_200 : array = array(1u, 2u);")); } TEST_F(SpvModuleScopeVarParserTest, ArrayNullInitializer) { @@ -1651,20 +1188,11 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __array__u32_2 - { - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr( + "var x_200 : array = array(0u, 0u);")); } TEST_F(SpvModuleScopeVarParserTest, ArrayUndefInitializer) { @@ -1675,20 +1203,11 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayUndefInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __array__u32_2 - { - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - })")); + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr( + "var x_200 : array = array(0u, 0u);")); // This example module emits ok, but is not valid SPIR-V in the first place. p->DeliberatelyInvalidSpirv(); @@ -1705,25 +1224,10 @@ TEST_F(SpvModuleScopeVarParserTest, StructInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{1.500000} - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{1u} - ScalarConstructor[not set]{2u} - } - } - } - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : S = S(1u, 1.5, array(1u, 2u));")) << module_str; } @@ -1736,25 +1240,10 @@ TEST_F(SpvModuleScopeVarParserTest, StructNullInitializer) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : S = S(0u, 0.0, array(0u, 0u));")) << module_str; } @@ -1766,28 +1255,12 @@ TEST_F(SpvModuleScopeVarParserTest, StructUndefInitializer) { %200 = OpVariable %ptr Private %const )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); - ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"(Variable{ - x_200 - private - undefined - __type_name_S - { - TypeConstructor[not set]{ - __type_name_S - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0.000000} - TypeConstructor[not set]{ - __array__u32_2 - ScalarConstructor[not set]{0u} - ScalarConstructor[not set]{0u} - } - } - } - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("var x_200 : S = S(0u, 0.0, array(0u, 0u));")) << module_str; // This example module emits ok, but is not valid SPIR-V in the first place. @@ -1834,18 +1307,10 @@ TEST_F(SpvModuleScopeVarParserTest, DescriptorGroupDecoration_Valid) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - Decorations{ - GroupDecoration{3} - BindingDecoration{9} - } - x_1 - storage - read_write - __type_name_S - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("[[group(3), binding(9)]] var x_1 : S;")) << module_str; } @@ -1893,18 +1358,10 @@ TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_Valid) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{3} - } - x_1 - storage - read_write - __type_name_S - })")) + const auto module_str = test::ToString(p->program()); + EXPECT_THAT( + module_str, + HasSubstr("[[group(0), binding(3)]] var x_1 : S;")) << module_str; } @@ -1953,25 +1410,17 @@ TEST_F(SpvModuleScopeVarParserTest, )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Arr -> __array__u32_2_stride_4 - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __u32} - StructMember{[[ offset 4 ]] field1: __f32} - StructMember{[[ offset 8 ]] field2: __type_name_Arr} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_1 - storage - read_write - __type_name_S - } + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"(type Arr = [[stride(4)]] array; + +[[block]] +struct S { + field0 : u32; + field1 : f32; + field2 : Arr; +}; + +[[group(0), binding(0)]] var x_1 : S; )")) << module_str; } @@ -1996,23 +1445,14 @@ TEST_F(SpvModuleScopeVarParserTest, ColMajorDecoration_Dropped) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __mat_2_3__f32} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - myvar - storage - read_write - __type_name_S - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"([[block]] +struct S { + field0 : mat3x2; +}; + +[[group(0), binding(0)]] var myvar : S; +)")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Natural_Dropped) { @@ -2035,23 +1475,14 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Natural_Dropped) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __mat_2_3__f32} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - myvar - storage - read_write - __type_name_S - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"([[block]] +struct S { + field0 : mat3x2; +}; + +[[group(0), binding(0)]] var myvar : S; +)")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration) { @@ -2074,23 +1505,15 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Struct S { - [[block]] - StructMember{[[ stride 64 tint_internal(disable_validation__ignore_stride) offset 0 ]] field0: __mat_2_3__f32} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - myvar - storage - read_write - __type_name_S - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"([[block]] +struct S { + [[stride(64), internal(disable_validation__ignore_stride)]] + field0 : mat3x2; +}; + +[[group(0), binding(0)]] var myvar : S; +)")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, RowMajorDecoration_IsError) { @@ -2136,24 +1559,15 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_AllMembers) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __f32} - StructMember{[[ offset 4 ]] field1: __f32} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_1 - storage - read - __type_name_S - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"([[block]] +struct S { + field0 : f32; + field1 : f32; +}; + +[[group(0), binding(0)]] var x_1 : S; +)")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) { @@ -2175,24 +1589,15 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __f32} - StructMember{[[ offset 4 ]] field1: __f32} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_1 - storage - read_write - __type_name_S - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"([[block]] +struct S { + field0 : f32; + field1 : f32; +}; + +[[group(0), binding(0)]] var x_1 : S; +)")) << module_str; } TEST_F( @@ -2217,24 +1622,15 @@ TEST_F( )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - Struct S { - [[block]] - StructMember{[[ offset 0 ]] field0: __f32} - StructMember{[[ offset 4 ]] field1: __f32} - } - Variable{ - Decorations{ - GroupDecoration{0} - BindingDecoration{0} - } - x_1 - storage - read_write - __type_name_S - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr(R"([[block]] +struct S { + field0 : f32; + field1 : f32; +}; + +[[group(0), binding(0)]] var x_1 : S; +)")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_Id_TooBig) { @@ -2277,21 +1673,10 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_True) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - VariableConst{ - Decorations{ - OverrideDecoration{12} - } - myconst - none - undefined - __bool - { - ScalarConstructor[not set]{true} - } - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("[[override(12)]] let myconst : bool = true;")) + << module_str; } TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_False) { @@ -2305,21 +1690,10 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_False) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - VariableConst{ - Decorations{ - OverrideDecoration{12} - } - myconst - none - undefined - __bool - { - ScalarConstructor[not set]{false} - } - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("[[override(12)]] let myconst : bool = false;")) + << module_str; } TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_U32) { @@ -2333,21 +1707,10 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_U32) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - VariableConst{ - Decorations{ - OverrideDecoration{12} - } - myconst - none - undefined - __u32 - { - ScalarConstructor[not set]{42u} - } - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("[[override(12)]] let myconst : u32 = 42u;")) + << module_str; } TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_I32) { @@ -2361,21 +1724,9 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_I32) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - VariableConst{ - Decorations{ - OverrideDecoration{12} - } - myconst - none - undefined - __i32 - { - ScalarConstructor[not set]{42} - } - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("[[override(12)]] let myconst : i32 = 42;")) + << module_str; } TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_F32) { @@ -2389,21 +1740,10 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_F32) { )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - VariableConst{ - Decorations{ - OverrideDecoration{12} - } - myconst - none - undefined - __f32 - { - ScalarConstructor[not set]{2.500000} - } - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, + HasSubstr("[[override(12)]] let myconst : f32 = 2.5;")) + << module_str; } TEST_F(SpvModuleScopeVarParserTest, @@ -2418,18 +1758,8 @@ TEST_F(SpvModuleScopeVarParserTest, )" + MainBody())); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - EXPECT_THAT(module_str, HasSubstr(R"( - VariableConst{ - myconst - none - undefined - __f32 - { - ScalarConstructor[not set]{2.500000} - } - } -})")) << module_str; + const auto module_str = test::ToString(p->program()); + EXPECT_THAT(module_str, HasSubstr("let myconst : f32 = 2.5;")) << module_str; } TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_UsedInFunction) { @@ -2453,17 +1783,9 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_UsedInFunction) { EXPECT_TRUE(p->error().empty()); Program program = p->program(); - const auto got = ToString(program, fe.ast_body()); + const auto got = test::ToString(program, fe.ast_body()); - EXPECT_THAT(got, HasSubstr(R"(Return{ - { - Binary[not set]{ - Identifier[not set]{myconst} - add - Identifier[not set]{myconst} - } - } -})")) << got; + EXPECT_THAT(got, HasSubstr("return (myconst + myconst);")) << got; } // Returns the start of a shader for testing SampleId, @@ -2498,57 +1820,19 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); + const auto module_str = test::ToString(p->program()); const std::string expected = - R"(Module{ - Variable{ - x_1 - private - undefined - __i32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + R"(var x_1 : i32; + +fn main_1() { + let x_2 : i32 = x_1; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_index)]] x_1_param : u32) { + x_1 = bitcast(x_1_param); + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -2566,7 +1850,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); + const auto module_str = test::ToString(p->program()); const std::string expected = R"(Module{ Variable{ @@ -2650,55 +1934,21 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; - // Correct declaration - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - x_1 - private - undefined - __i32 - })")) - << module_str; +fn main_1() { + let x_2 : i32 = x_1; + return; +} - // Correct creation of value - EXPECT_THAT(module_str, HasSubstr(R"( - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - })")); - - // Correct parameter on entry point - EXPECT_THAT(module_str, HasSubstr(R"( - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - })")) - << module_str; +[[stage(fragment)]] +fn main([[builtin(sample_index)]] x_1_param : u32) { + x_1 = bitcast(x_1_param); + main_1(); +} +)"; + EXPECT_EQ(module_str, expected); } TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_FunctParam) { @@ -2738,54 +1988,18 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __u32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_index)]] x_1_param : u32) { + x_1 = x_1_param; + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -2803,71 +2017,19 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __u32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_11 - none - undefined - __ptr_private__u32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - UnaryOp[not set]{ - indirection - Identifier[not set]{x_11} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +fn main_1() { + let x_11 : ptr = &(x_1); + let x_2 : u32 = *(x_11); + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_index)]] x_1_param : u32) { + x_1 = x_1_param; + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -2885,54 +2047,18 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __u32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_index)]] x_1_param : u32) { + x_1 = x_1_param; + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -3037,59 +2163,21 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_U32_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; - // Correct declaration - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - x_1 - private - undefined - __array__u32_1 - })")) - << module_str; +fn main_1() { + let x_3 : u32 = x_1[0]; + return; +} - // Correct creation of value - EXPECT_THAT(module_str, HasSubstr(R"( - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - })")); - - // Correct parameter on entry point - EXPECT_THAT(module_str, HasSubstr(R"( - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - })")) - << module_str; +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = x_1_param; + main_1(); +} +)"; + EXPECT_EQ(module_str, expected); } TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_U32_CopyObject) { @@ -3107,60 +2195,18 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_U32_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __array__u32_1 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_4 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + let x_4 : u32 = x_1[0]; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = x_1_param; + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -3181,59 +2227,21 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_U32_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; - // Correct declaration - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - x_1 - private - undefined - __array__u32_1 - })")) - << module_str; +fn main_1() { + let x_4 : u32 = x_1[0]; + return; +} - // Correct creation of value - EXPECT_THAT(module_str, HasSubstr(R"( - VariableDeclStatement{ - VariableConst{ - x_4 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - })")); - - // Correct parameter on entry point - EXPECT_THAT(module_str, HasSubstr(R"( - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - })")) - << module_str; +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = x_1_param; + main_1(); +} +)"; + EXPECT_EQ(module_str, expected); } TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_I32_Direct) { @@ -3250,62 +2258,18 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_I32_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __i32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + let x_3 : i32 = x_1[0]; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = bitcast(x_1_param); + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -3326,62 +2290,18 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_I32_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_4 - none - undefined - __i32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + let x_4 : i32 = x_1[0]; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = bitcast(x_1_param); + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -3402,62 +2322,18 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_I32_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_4 - none - undefined - __i32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + let x_4 : i32 = x_1[0]; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = bitcast(x_1_param); + main_1(); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -3496,51 +2372,23 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_U32_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__u32_1 - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{0u} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + x_1[0] = 0u; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0]); } )"; EXPECT_EQ(module_str, expected); @@ -3561,51 +2409,23 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_U32_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__u32_1 - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{0u} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + x_1[0] = 0u; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0]); } )"; EXPECT_EQ(module_str, expected); @@ -3626,51 +2446,23 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_U32_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__u32_1 - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{0u} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + x_1[0] = 0u; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0]); } )"; EXPECT_EQ(module_str, expected); @@ -3690,53 +2482,23 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_I32_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{12} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Bitcast[not set]<__u32>{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + x_1[0] = 12; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(bitcast(x_1[0])); } )"; EXPECT_EQ(module_str, expected); @@ -3757,53 +2519,23 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_I32_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{12} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Bitcast[not set]<__u32>{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + x_1[0] = 12; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(bitcast(x_1[0])); } )"; EXPECT_EQ(module_str, expected); @@ -3824,53 +2556,23 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_I32_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{12} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Bitcast[not set]<__u32>{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + x_1[0] = 12; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(bitcast(x_1[0])); } )"; EXPECT_EQ(module_str, expected); @@ -3890,63 +2592,29 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_In_WithStride) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(type Arr = [[stride(4)]] array; - EXPECT_THAT(module_str, HasSubstr(R"( - Arr -> __array__u32_1_stride_4 -)")) << module_str; +type Arr_1 = [[stride(4)]] array; - // Correct declaration - EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - x_1 - private - undefined - __type_name_Arr - })")) - << module_str; +type Arr_2 = [[stride(4)]] array; - // Correct creation of value - EXPECT_THAT(module_str, HasSubstr(R"( - VariableDeclStatement{ - VariableConst{ - x_3 - none - undefined - __u32 - { - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - })")); +type Arr_3 = [[stride(4)]] array; - // Correct parameter on entry point - EXPECT_THAT(module_str, HasSubstr(R"( - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - })")) - << module_str; +var x_1 : Arr; + +fn main_1() { + let x_3 : u32 = x_1[0]; + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = x_1_param; + main_1(); +} +)"; + EXPECT_EQ(module_str, expected); } TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_WithStride) { @@ -3963,55 +2631,31 @@ TEST_F(SpvModuleScopeVarParserTest, SampleMask_Out_WithStride) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Arr -> __array__u32_1_stride_4 - Arr_1 -> __array__u32_2_stride_4 - Arr_2 -> __array__i32_1_stride_4 - Arr_3 -> __array__i32_2_stride_4 - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __type_name_Arr - } - Function main_1 -> __void - () - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{0u} - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(type Arr = [[stride(4)]] array; + +type Arr_1 = [[stride(4)]] array; + +type Arr_2 = [[stride(4)]] array; + +type Arr_3 = [[stride(4)]] array; + +var x_1 : Arr; + +fn main_1() { + x_1[0] = 0u; + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0]); } )"; EXPECT_EQ(module_str, expected); @@ -4051,74 +2695,26 @@ TEST_F(SpvModuleScopeVarParserTest, VertexIndex_I32_Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{vertex_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var x_4 : vec4; + +fn main_1() { + let x_2 : i32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(vertex_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -4136,91 +2732,27 @@ TEST_F(SpvModuleScopeVarParserTest, VertexIndex_I32_Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __ptr_private__i32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - UnaryOp[not set]{ - indirection - Identifier[not set]{x_14} - } - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{vertex_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var x_4 : vec4; + +fn main_1() { + let x_14 : ptr = &(x_1); + let x_2 : i32 = *(x_14); + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(vertex_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(module_str, expected); @@ -4238,74 +2770,26 @@ TEST_F(SpvModuleScopeVarParserTest, VertexIndex_I32_Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{vertex_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var x_4 : vec4; + +fn main_1() { + let x_2 : i32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(vertex_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(module_str, expected); @@ -4322,72 +2806,26 @@ TEST_F(SpvModuleScopeVarParserTest, VertexIndex_U32_Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{vertex_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var x_4 : vec4; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(vertex_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(module_str, expected); @@ -4405,89 +2843,27 @@ TEST_F(SpvModuleScopeVarParserTest, VertexIndex_U32_Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __ptr_private__u32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - UnaryOp[not set]{ - indirection - Identifier[not set]{x_14} - } - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{vertex_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var x_4 : vec4; + +fn main_1() { + let x_14 : ptr = &(x_1); + let x_2 : u32 = *(x_14); + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(vertex_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(module_str, expected); @@ -4505,72 +2881,26 @@ TEST_F(SpvModuleScopeVarParserTest, VertexIndex_U32_Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{vertex_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var x_4 : vec4; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(vertex_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(module_str, expected); @@ -4636,74 +2966,26 @@ TEST_F(SpvModuleScopeVarParserTest, InstanceIndex_I32_Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] position_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var position : vec4; + +fn main_1() { + let x_2 : i32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + position_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(position); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -4721,91 +3003,27 @@ TEST_F(SpvModuleScopeVarParserTest, InstanceIndex_I32_Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] position_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __ptr_private__i32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - UnaryOp[not set]{ - indirection - Identifier[not set]{x_14} - } - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var position : vec4; + +fn main_1() { + let x_14 : ptr = &(x_1); + let x_2 : i32 = *(x_14); + return; +} + +struct main_out { + [[builtin(position)]] + position_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(position); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -4823,74 +3041,26 @@ TEST_F(SpvModuleScopeVarParserTest, InstanceIndex_I32_Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] position_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var position : vec4; + +fn main_1() { + let x_2 : i32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + position_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(position); } )"; EXPECT_EQ(module_str, expected) << module_str; @@ -4931,72 +3101,26 @@ TEST_F(SpvModuleScopeVarParserTest, InstanceIndex_U32_Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] position_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var position : vec4; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + position_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(position); } )"; EXPECT_EQ(module_str, expected); @@ -5014,89 +3138,27 @@ TEST_F(SpvModuleScopeVarParserTest, InstanceIndex_U32_Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] position_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_14 - none - undefined - __ptr_private__u32 - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - UnaryOp[not set]{ - indirection - Identifier[not set]{x_14} - } - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var position : vec4; + +fn main_1() { + let x_14 : ptr = &(x_1); + let x_2 : u32 = *(x_14); + return; +} + +struct main_out { + [[builtin(position)]] + position_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(position); } )"; EXPECT_EQ(module_str, expected); @@ -5114,72 +3176,26 @@ TEST_F(SpvModuleScopeVarParserTest, InstanceIndex_U32_Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] position_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{position} - } - } - } - } + const auto module_str = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var position : vec4; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + position_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(position); } )"; EXPECT_EQ(module_str, expected); @@ -5245,48 +3261,48 @@ inline std::ostream& operator<<(std::ostream& o, ComputeBuiltinInputCase c) { std::string WgslType(std::string spirv_type) { if (spirv_type == "%uint") { - return "__u32"; + return "u32"; } if (spirv_type == "%int") { - return "__i32"; + return "i32"; } if (spirv_type == "%v3uint") { - return "__vec_3__u32"; + return "vec3"; } if (spirv_type == "%v3int") { - return "__vec_3__i32"; + return "vec3"; } return "error"; } std::string UnsignedWgslType(std::string wgsl_type) { - if (wgsl_type == "__u32") { - return "__u32"; + if (wgsl_type == "u32") { + return "u32"; } - if (wgsl_type == "__i32") { - return "__u32"; + if (wgsl_type == "i32") { + return "u32"; } - if (wgsl_type == "__vec_3__u32") { - return "__vec_3__u32"; + if (wgsl_type == "vec3") { + return "vec3"; } - if (wgsl_type == "__vec_3__i32") { - return "__vec_3__u32"; + if (wgsl_type == "vec3") { + return "vec3"; } return "error"; } std::string SignedWgslType(std::string wgsl_type) { - if (wgsl_type == "__u32") { - return "__i32"; + if (wgsl_type == "u32") { + return "i32"; } - if (wgsl_type == "__i32") { - return "__i32"; + if (wgsl_type == "i32") { + return "i32"; } - if (wgsl_type == "__vec_3__u32") { - return "__vec_3__i32"; + if (wgsl_type == "vec3") { + return "vec3"; } - if (wgsl_type == "__vec_3__i32") { - return "__vec_3__i32"; + if (wgsl_type == "vec3") { + return "vec3"; } return "error"; } @@ -5296,6 +3312,7 @@ using SpvModuleScopeVarParserTest_ComputeBuiltin = TEST_P(SpvModuleScopeVarParserTest_ComputeBuiltin, Load_Direct) { const auto wgsl_type = WgslType(GetParam().spirv_store_type); + const auto wgsl_builtin = GetParam().wgsl_builtin; const auto unsigned_wgsl_type = UnsignedWgslType(wgsl_type); const auto signed_wgsl_type = SignedWgslType(wgsl_type); const std::string assembly = @@ -5312,74 +3329,37 @@ TEST_P(SpvModuleScopeVarParserTest_ComputeBuiltin, Load_Direct) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - )" + wgsl_type + R"( - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - )" + wgsl_type + R"( - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - } - ( - VariableConst{ - Decorations{ - BuiltinDecoration{)" + GetParam().wgsl_builtin + - R"(} - } - x_1_param - none - undefined - )" + unsigned_wgsl_type + R"( - } - ) - { - Assignment{ - Identifier[not set]{x_1})" + - (wgsl_type == unsigned_wgsl_type ? - R"( - Identifier[not set]{x_1_param})" - : - R"( - Bitcast[not set]<)" + signed_wgsl_type + R"(>{ - Identifier[not set]{x_1_param} - })") + R"( - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + std::string expected = R"(var x_1 : ${wgsl_type}; + +fn main_1() { + let x_2 : ${wgsl_type} = x_1; + return; +} + +[[stage(compute), workgroup_size(1, 1, 1)]] +fn main([[builtin(${wgsl_builtin})]] x_1_param : ${unsigned_wgsl_type}) { + x_1 = ${assignment_value}; + main_1(); } )"; + + expected = utils::ReplaceAll(expected, "${wgsl_type}", wgsl_type); + expected = + utils::ReplaceAll(expected, "${unsigned_wgsl_type}", unsigned_wgsl_type); + expected = utils::ReplaceAll(expected, "${wgsl_builtin}", wgsl_builtin); + expected = + utils::ReplaceAll(expected, "${assignment_value}", + (wgsl_type == unsigned_wgsl_type) + ? "x_1_param" + : "bitcast<" + signed_wgsl_type + ">(x_1_param)"); + EXPECT_EQ(module_str, expected) << module_str; } TEST_P(SpvModuleScopeVarParserTest_ComputeBuiltin, Load_CopyObject) { const auto wgsl_type = WgslType(GetParam().spirv_store_type); + const auto wgsl_builtin = GetParam().wgsl_builtin; const auto unsigned_wgsl_type = UnsignedWgslType(wgsl_type); const auto signed_wgsl_type = SignedWgslType(wgsl_type); const std::string assembly = @@ -5397,92 +3377,38 @@ TEST_P(SpvModuleScopeVarParserTest_ComputeBuiltin, Load_CopyObject) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - )" + wgsl_type + R"( - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_13 - none - undefined - __ptr_private)" + wgsl_type + - R"( - { - UnaryOp[not set]{ - address-of - Identifier[not set]{x_1} - } - } - } - } - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - )" + wgsl_type + R"( - { - UnaryOp[not set]{ - indirection - Identifier[not set]{x_13} - } - } - } - } - Return{} - } - Function main -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - } - ( - VariableConst{ - Decorations{ - BuiltinDecoration{)" + GetParam().wgsl_builtin + - R"(} - } - x_1_param - none - undefined - )" + unsigned_wgsl_type + R"( - } - ) - { - Assignment{ - Identifier[not set]{x_1})" + - (wgsl_type == unsigned_wgsl_type ? - R"( - Identifier[not set]{x_1_param})" - : - R"( - Bitcast[not set]<)" + signed_wgsl_type + R"(>{ - Identifier[not set]{x_1_param} - })") + R"( - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + std::string expected = R"(var x_1 : ${wgsl_type}; + +fn main_1() { + let x_13 : ptr = &(x_1); + let x_2 : ${wgsl_type} = *(x_13); + return; +} + +[[stage(compute), workgroup_size(1, 1, 1)]] +fn main([[builtin(${wgsl_builtin})]] x_1_param : ${unsigned_wgsl_type}) { + x_1 = ${assignment_value}; + main_1(); } )"; + + expected = utils::ReplaceAll(expected, "${wgsl_type}", wgsl_type); + expected = + utils::ReplaceAll(expected, "${unsigned_wgsl_type}", unsigned_wgsl_type); + expected = utils::ReplaceAll(expected, "${wgsl_builtin}", wgsl_builtin); + expected = + utils::ReplaceAll(expected, "${assignment_value}", + (wgsl_type == unsigned_wgsl_type) + ? "x_1_param" + : "bitcast<" + signed_wgsl_type + ">(x_1_param)"); + EXPECT_EQ(module_str, expected) << module_str; } TEST_P(SpvModuleScopeVarParserTest_ComputeBuiltin, Load_AccessChain) { const auto wgsl_type = WgslType(GetParam().spirv_store_type); + const auto wgsl_builtin = GetParam().wgsl_builtin; const auto unsigned_wgsl_type = UnsignedWgslType(wgsl_type); const auto signed_wgsl_type = SignedWgslType(wgsl_type); const std::string assembly = @@ -5500,69 +3426,31 @@ TEST_P(SpvModuleScopeVarParserTest_ComputeBuiltin, Load_AccessChain) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto module_str = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - )" + wgsl_type + R"( - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - )" + wgsl_type + R"( - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __void - StageDecoration{compute} - WorkgroupDecoration{ - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - ScalarConstructor[not set]{1} - } - ( - VariableConst{ - Decorations{ - BuiltinDecoration{)" + GetParam().wgsl_builtin + - R"(} - } - x_1_param - none - undefined - )" + unsigned_wgsl_type + R"( - } - ) - { - Assignment{ - Identifier[not set]{x_1})" + - (wgsl_type == unsigned_wgsl_type ? - R"( - Identifier[not set]{x_1_param})" - : - R"( - Bitcast[not set]<)" + signed_wgsl_type + R"(>{ - Identifier[not set]{x_1_param} - })") + R"( - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto module_str = test::ToString(p->program()); + std::string expected = R"(var x_1 : ${wgsl_type}; + +fn main_1() { + let x_2 : ${wgsl_type} = x_1; + return; +} + +[[stage(compute), workgroup_size(1, 1, 1)]] +fn main([[builtin(${wgsl_builtin})]] x_1_param : ${unsigned_wgsl_type}) { + x_1 = ${assignment_value}; + main_1(); } )"; + + expected = utils::ReplaceAll(expected, "${wgsl_type}", wgsl_type); + expected = + utils::ReplaceAll(expected, "${unsigned_wgsl_type}", unsigned_wgsl_type); + expected = utils::ReplaceAll(expected, "${wgsl_builtin}", wgsl_builtin); + expected = + utils::ReplaceAll(expected, "${assignment_value}", + (wgsl_type == unsigned_wgsl_type) + ? "x_1_param" + : "bitcast<" + signed_wgsl_type + ">(x_1_param)"); + EXPECT_EQ(module_str, expected) << module_str; } @@ -5708,15 +3596,8 @@ TEST_F(SpvModuleScopeVarParserTest, InputVarsConvertedToPrivate) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = - R"(Variable{ - x_1 - private - undefined - __u32 - } -)"; + const auto got = test::ToString(p->program()); + const std::string expected = "var x_1 : u32;"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5729,15 +3610,8 @@ TEST_F(SpvModuleScopeVarParserTest, OutputVarsConvertedToPrivate) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = - R"(Variable{ - x_1 - private - undefined - __u32 - } -)"; + const auto got = test::ToString(p->program()); + const std::string expected = "var x_1 : u32;"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5751,18 +3625,8 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = - R"(Variable{ - x_1 - private - undefined - __u32 - { - ScalarConstructor[not set]{1u} - } - } -)"; + const auto got = test::ToString(p->program()); + const std::string expected = "var x_1 : u32 = 1u;"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5782,21 +3646,9 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Variable{ - x_1 - private - undefined - __array__u32_1 - { - TypeConstructor[not set]{ - __array__u32_1 - ScalarConstructor[not set]{2u} - } - } - } -)"; + "var x_1 : array = array(2u);"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5816,21 +3668,9 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Variable{ - x_1 - private - undefined - __array__i32_1 - { - TypeConstructor[not set]{ - __array__i32_1 - ScalarConstructor[not set]{14} - } - } - } -)"; + "var x_1 : array = array(14);"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5846,15 +3686,8 @@ TEST_F(SpvModuleScopeVarParserTest, Builtin_Input_SameSignednessAsWGSL) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = - R"(Variable{ - x_1 - private - undefined - __u32 - } -)"; + const auto got = test::ToString(p->program()); + const std::string expected = "var x_1 : u32;"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5870,15 +3703,8 @@ TEST_F(SpvModuleScopeVarParserTest, Builtin_Input_OppositeSignednessAsWGSL) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = - R"(Variable{ - x_1 - private - undefined - __i32 - } -)"; + const auto got = test::ToString(p->program()); + const std::string expected = "var x_1 : i32;"; EXPECT_THAT(got, HasSubstr(expected)) << got; } @@ -5908,90 +3734,33 @@ TEST_F(SpvModuleScopeVarParserTest, EntryPointWrapping_IOLocations) { ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"( - Struct main_out { - StructMember{[[ LocationDecoration{0} - ]] x_2_1: __u32} - StructMember{[[ LocationDecoration{6} - ]] x_4_1: __u32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_2 - private - undefined - __u32 - } - Variable{ - x_3 - private - undefined - __u32 - } - Variable{ - x_4 - private - undefined - __u32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - LocationDecoration{0} - } - x_1_param - none - undefined - __u32 - } - VariableConst{ - Decorations{ - LocationDecoration{30} - } - x_3_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Assignment{ - Identifier[not set]{x_3} - Identifier[not set]{x_3_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - Identifier[not set]{x_4} - } - } - } - } + R"(var x_1 : u32; + +var x_2 : u32; + +var x_3 : u32; + +var x_4 : u32; + +fn main_1() { + return; +} + +struct main_out { + [[location(0)]] + x_2_1 : u32; + [[location(6)]] + x_4_1 : u32; +}; + +[[stage(fragment)]] +fn main([[location(0)]] x_1_param : u32, [[location(30)]] x_3_param : u32) -> main_out { + x_1 = x_1_param; + x_3 = x_3_param; + main_1(); + return main_out(x_2, x_4); } )"; EXPECT_THAT(got, HasSubstr(expected)) << got; @@ -6023,72 +3792,26 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __u32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : u32; + +var x_4 : vec4; + +fn main_1() { + let x_2 : u32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = x_1_param; + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(got, expected) << got; @@ -6119,74 +3842,26 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_4_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __i32 - } - Variable{ - x_4 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - VariableDeclStatement{ - VariableConst{ - x_2 - none - undefined - __i32 - { - Identifier[not set]{x_1} - } - } - } - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{instance_index} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_4} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : i32; + +var x_4 : vec4; + +fn main_1() { + let x_2 : i32 = x_1; + return; +} + +struct main_out { + [[builtin(position)]] + x_4_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[builtin(instance_index)]] x_1_param : u32) -> main_out { + x_1 = bitcast(x_1_param); + main_1(); + return main_out(x_4); } )"; EXPECT_EQ(got, expected) << got; @@ -6216,46 +3891,17 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __array__u32_1 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = x_1_param; + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -6284,48 +3930,17 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Variable{ - x_1 - private - undefined - __array__i32_1 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - BuiltinDecoration{sample_mask} - } - x_1_param - none - undefined - __u32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Bitcast[not set]<__i32>{ - Identifier[not set]{x_1_param} - } - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +fn main_1() { + return; +} + +[[stage(fragment)]] +fn main([[builtin(sample_mask)]] x_1_param : u32) { + x_1[0] = bitcast(x_1_param); + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -6355,50 +3970,23 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__u32_1 - { - TypeConstructor[not set]{ - __array__u32_1 - ScalarConstructor[not set]{0u} - } - } - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = + R"(var x_1 : array = array(0u); + +fn main_1() { + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0]); } )"; EXPECT_EQ(got, expected) << got; @@ -6428,52 +4016,23 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{sample_mask} - ]] x_1_1: __u32} - } - Variable{ - x_1 - private - undefined - __array__i32_1 - { - TypeConstructor[not set]{ - __array__i32_1 - ScalarConstructor[not set]{0} - } - } - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Bitcast[not set]<__u32>{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - } - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = + R"(var x_1 : array = array(0); + +fn main_1() { + return; +} + +struct main_out { + [[builtin(sample_mask)]] + x_1_1 : u32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(bitcast(x_1[0])); } )"; EXPECT_EQ(got, expected) << got; @@ -6502,44 +4061,22 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{frag_depth} - ]] x_1_1: __f32} - } - Variable{ - x_1 - private - undefined - __f32 - { - ScalarConstructor[not set]{0.000000} - } - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_1} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : f32 = 0.0; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(frag_depth)]] + x_1_1 : f32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1); } )"; EXPECT_EQ(got, expected) << got; @@ -6558,41 +4095,22 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_BuiltIn_Position) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] gl_Position: __vec_4__f32} - } - Variable{ - gl_Position - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{gl_Position} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var gl_Position : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + gl_Position : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(gl_Position); } )"; EXPECT_EQ(got, expected) << got; @@ -6645,50 +4163,23 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] gl_Position: __vec_4__f32} - } - Variable{ - gl_Position - private - undefined - __vec_4__f32 - { - TypeConstructor[not set]{ - __vec_4__f32 - ScalarConstructor[not set]{1.000000} - ScalarConstructor[not set]{2.000000} - ScalarConstructor[not set]{3.000000} - ScalarConstructor[not set]{4.000000} - } - } - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{gl_Position} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = + R"(var gl_Position : vec4 = vec4(1.0, 2.0, 3.0, 4.0); + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + gl_Position : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(gl_Position); } )"; EXPECT_EQ(got, expected) << got; @@ -6728,96 +4219,27 @@ TEST_F(SpvModuleScopeVarParserTest, Input_FlattenArray_OneLevel) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __array__f32_3 - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - LocationDecoration{4} - } - x_1_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{5} - } - x_1_param_1 - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{6} - } - x_1_param_2 - none - undefined - __f32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - } - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - Identifier[not set]{x_1_param_1} - } - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{2} - } - Identifier[not set]{x_1_param_2} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[location(4)]] x_1_param : f32, [[location(5)]] x_1_param_1 : f32, [[location(6)]] x_1_param_2 : f32) -> main_out { + x_1[0] = x_1_param; + x_1[1] = x_1_param_1; + x_1[2] = x_1_param_2; + main_1(); + return main_out(x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -6855,80 +4277,26 @@ TEST_F(SpvModuleScopeVarParserTest, Input_FlattenMatrix) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __mat_4_2__f32 - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - LocationDecoration{9} - } - x_1_param - none - undefined - __vec_4__f32 - } - VariableConst{ - Decorations{ - LocationDecoration{10} - } - x_1_param_1 - none - undefined - __vec_4__f32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - } - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - Identifier[not set]{x_1_param_1} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : mat2x4; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[location(9)]] x_1_param : vec4, [[location(10)]] x_1_param_1 : vec4) -> main_out { + x_1[0] = x_1_param; + x_1[1] = x_1_param_1; + main_1(); + return main_out(x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -6971,84 +4339,31 @@ TEST_F(SpvModuleScopeVarParserTest, Input_FlattenStruct_LocOnVariable) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct Communicators { - StructMember{alice: __f32} - StructMember{bob: __vec_4__f32} - } - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __type_name_Communicators - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - LocationDecoration{9} - } - x_1_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{10} - } - x_1_param_1 - none - undefined - __vec_4__f32 - } - ) - { - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{alice} - } - Identifier[not set]{x_1_param} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{bob} - } - Identifier[not set]{x_1_param_1} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(struct Communicators { + alice : f32; + bob : vec4; +}; + +var x_1 : Communicators; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[location(9)]] x_1_param : f32, [[location(10)]] x_1_param_1 : vec4) -> main_out { + x_1.alice = x_1_param; + x_1.bob = x_1_param_1; + main_1(); + return main_out(x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -7088,124 +4403,28 @@ TEST_F(SpvModuleScopeVarParserTest, Input_FlattenNested) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __array__mat_4_2__f32_2 - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - LocationDecoration{7} - } - x_1_param - none - undefined - __vec_4__f32 - } - VariableConst{ - Decorations{ - LocationDecoration{8} - } - x_1_param_1 - none - undefined - __vec_4__f32 - } - VariableConst{ - Decorations{ - LocationDecoration{9} - } - x_1_param_2 - none - undefined - __vec_4__f32 - } - VariableConst{ - Decorations{ - LocationDecoration{10} - } - x_1_param_3 - none - undefined - __vec_4__f32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - } - Assignment{ - ArrayAccessor[not set]{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ScalarConstructor[not set]{1} - } - Identifier[not set]{x_1_param_1} - } - Assignment{ - ArrayAccessor[not set]{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param_2} - } - Assignment{ - ArrayAccessor[not set]{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - ScalarConstructor[not set]{1} - } - Identifier[not set]{x_1_param_3} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array, 2u>; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[location(7)]] x_1_param : vec4, [[location(8)]] x_1_param_1 : vec4, [[location(9)]] x_1_param_2 : vec4, [[location(10)]] x_1_param_3 : vec4) -> main_out { + x_1[0][0] = x_1_param; + x_1[0][1] = x_1_param_1; + x_1[1][0] = x_1_param_2; + x_1[1][1] = x_1_param_3; + main_1(); + return main_out(x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -7245,65 +4464,30 @@ TEST_F(SpvModuleScopeVarParserTest, Output_FlattenArray_OneLevel) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ LocationDecoration{4} - ]] x_1_1: __f32} - StructMember{[[ LocationDecoration{5} - ]] x_1_2: __f32} - StructMember{[[ LocationDecoration{6} - ]] x_1_3: __f32} - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __array__f32_3 - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{2} - } - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : array; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[location(4)]] + x_1_1 : f32; + [[location(5)]] + x_1_2 : f32; + [[location(6)]] + x_1_3 : f32; + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0], x_1[1], x_1[2], x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -7341,59 +4525,28 @@ TEST_F(SpvModuleScopeVarParserTest, Output_FlattenMatrix) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct main_out { - StructMember{[[ LocationDecoration{9} - ]] x_1_1: __vec_4__f32} - StructMember{[[ LocationDecoration{10} - ]] x_1_2: __vec_4__f32} - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __mat_4_2__f32 - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(var x_1 : mat2x4; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[location(9)]] + x_1_1 : vec4; + [[location(10)]] + x_1_2 : vec4; + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_1[0], x_1[1], x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -7436,63 +4589,33 @@ TEST_F(SpvModuleScopeVarParserTest, Output_FlattenStruct_LocOnVariable) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct Communicators { - StructMember{alice: __f32} - StructMember{bob: __vec_4__f32} - } - Struct main_out { - StructMember{[[ LocationDecoration{9} - ]] x_1_1: __f32} - StructMember{[[ LocationDecoration{10} - ]] x_1_2: __vec_4__f32} - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __type_name_Communicators - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{alice} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{bob} - } - Identifier[not set]{x_2} - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(struct Communicators { + alice : f32; + bob : vec4; +}; + +var x_1 : Communicators; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[location(9)]] + x_1_1 : f32; + [[location(10)]] + x_1_2 : vec4; + [[builtin(position)]] + x_2_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_1.alice, x_1.bob, x_2); } )"; EXPECT_EQ(got, expected) << got; @@ -7539,102 +4662,37 @@ TEST_F(SpvModuleScopeVarParserTest, FlattenStruct_LocOnMembers) { ASSERT_TRUE(p->Parse()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); - const std::string expected = R"(Module{ - Struct Communicators { - StructMember{alice: __f32} - StructMember{bob: __vec_4__f32} - } - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_2_1: __vec_4__f32} - StructMember{[[ LocationDecoration{9} - ]] x_3_1: __f32} - StructMember{[[ LocationDecoration{11} - ]] x_3_2: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __type_name_Communicators - } - Variable{ - x_3 - private - undefined - __type_name_Communicators - } - Variable{ - x_2 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - LocationDecoration{9} - } - x_1_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{11} - } - x_1_param_1 - none - undefined - __vec_4__f32 - } - ) - { - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{alice} - } - Identifier[not set]{x_1_param} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{bob} - } - Identifier[not set]{x_1_param_1} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_2} - MemberAccessor[not set]{ - Identifier[not set]{x_3} - Identifier[not set]{alice} - } - MemberAccessor[not set]{ - Identifier[not set]{x_3} - Identifier[not set]{bob} - } - } - } - } - } + const auto got = test::ToString(p->program()); + const std::string expected = R"(struct Communicators { + alice : f32; + bob : vec4; +}; + +var x_1 : Communicators; + +var x_3 : Communicators; + +var x_2 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_2_1 : vec4; + [[location(9)]] + x_3_1 : f32; + [[location(11)]] + x_3_2 : vec4; +}; + +[[stage(vertex)]] +fn main([[location(9)]] x_1_param : f32, [[location(11)]] x_1_param_1 : vec4) -> main_out { + x_1.alice = x_1_param; + x_1.bob = x_1_param_1; + main_1(); + return main_out(x_2, x_3.alice, x_3.bob); } )"; EXPECT_EQ(got, expected) << got; @@ -7729,159 +4787,41 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Struct main_out { - StructMember{[[ BuiltinDecoration{position} - ]] x_10_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_2 - private - undefined - __vec_2__u32 - } - Variable{ - x_3 - private - undefined - __i32 - } - Variable{ - x_4 - private - undefined - __vec_2__i32 - } - Variable{ - x_5 - private - undefined - __f32 - } - Variable{ - x_6 - private - undefined - __vec_2__f32 - } - Variable{ - x_10 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - ( - VariableConst{ - Decorations{ - LocationDecoration{1} - } - x_1_param - none - undefined - __u32 - } - VariableConst{ - Decorations{ - LocationDecoration{2} - } - x_2_param - none - undefined - __vec_2__u32 - } - VariableConst{ - Decorations{ - LocationDecoration{3} - } - x_3_param - none - undefined - __i32 - } - VariableConst{ - Decorations{ - LocationDecoration{4} - } - x_4_param - none - undefined - __vec_2__i32 - } - VariableConst{ - Decorations{ - LocationDecoration{5} - InterpolateDecoration{flat none} - } - x_5_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{6} - InterpolateDecoration{flat none} - } - x_6_param - none - undefined - __vec_2__f32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Assignment{ - Identifier[not set]{x_2} - Identifier[not set]{x_2_param} - } - Assignment{ - Identifier[not set]{x_3} - Identifier[not set]{x_3_param} - } - Assignment{ - Identifier[not set]{x_4} - Identifier[not set]{x_4_param} - } - Assignment{ - Identifier[not set]{x_5} - Identifier[not set]{x_5_param} - } - Assignment{ - Identifier[not set]{x_6} - Identifier[not set]{x_6_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_10} - } - } - } - } + R"(var x_1 : u32; + +var x_2 : vec2; + +var x_3 : i32; + +var x_4 : vec2; + +var x_5 : f32; + +var x_6 : vec2; + +var x_10 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[builtin(position)]] + x_10_1 : vec4; +}; + +[[stage(vertex)]] +fn main([[location(1)]] x_1_param : u32, [[location(2)]] x_2_param : vec2, [[location(3)]] x_3_param : i32, [[location(4)]] x_4_param : vec2, [[location(5), interpolate(flat)]] x_5_param : f32, [[location(6), interpolate(flat)]] x_6_param : vec2) -> main_out { + x_1 = x_1_param; + x_2 = x_2_param; + x_3 = x_3_param; + x_4 = x_4_param; + x_5 = x_5_param; + x_6 = x_6_param; + main_1(); + return main_out(x_10); } )"; EXPECT_EQ(got, expected) << got; @@ -7932,98 +4872,47 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Struct main_out { - StructMember{[[ LocationDecoration{1} - ]] x_1_1: __u32} - StructMember{[[ LocationDecoration{2} - ]] x_2_1: __vec_2__u32} - StructMember{[[ LocationDecoration{3} - ]] x_3_1: __i32} - StructMember{[[ LocationDecoration{4} - ]] x_4_1: __vec_2__i32} - StructMember{[[ LocationDecoration{5} - InterpolateDecoration{flat none} - ]] x_5_1: __f32} - StructMember{[[ LocationDecoration{6} - InterpolateDecoration{flat none} - ]] x_6_1: __vec_2__f32} - StructMember{[[ BuiltinDecoration{position} - ]] x_10_1: __vec_4__f32} - } - Variable{ - x_1 - private - undefined - __u32 - } - Variable{ - x_2 - private - undefined - __vec_2__u32 - } - Variable{ - x_3 - private - undefined - __i32 - } - Variable{ - x_4 - private - undefined - __vec_2__i32 - } - Variable{ - x_5 - private - undefined - __f32 - } - Variable{ - x_6 - private - undefined - __vec_2__f32 - } - Variable{ - x_10 - private - undefined - __vec_4__f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{vertex} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_1} - Identifier[not set]{x_2} - Identifier[not set]{x_3} - Identifier[not set]{x_4} - Identifier[not set]{x_5} - Identifier[not set]{x_6} - Identifier[not set]{x_10} - } - } - } - } + R"(var x_1 : u32; + +var x_2 : vec2; + +var x_3 : i32; + +var x_4 : vec2; + +var x_5 : f32; + +var x_6 : vec2; + +var x_10 : vec4; + +fn main_1() { + return; +} + +struct main_out { + [[location(1)]] + x_1_1 : u32; + [[location(2)]] + x_2_1 : vec2; + [[location(3)]] + x_3_1 : i32; + [[location(4)]] + x_4_1 : vec2; + [[location(5), interpolate(flat)]] + x_5_1 : f32; + [[location(6), interpolate(flat)]] + x_6_1 : vec2; + [[builtin(position)]] + x_10_1 : vec4; +}; + +[[stage(vertex)]] +fn main() -> main_out { + main_1(); + return main_out(x_1, x_2, x_3, x_4, x_5, x_6, x_10); } )"; EXPECT_EQ(got, expected) << got; @@ -8057,109 +4946,28 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Struct S { - StructMember{field0: __f32} - StructMember{field1: __f32} - } - Variable{ - x_1 - private - undefined - __array__f32_2 - } - Variable{ - x_2 - private - undefined - __type_name_S - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - LocationDecoration{1} - InterpolateDecoration{flat none} - } - x_1_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{2} - InterpolateDecoration{flat none} - } - x_1_param_1 - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{5} - InterpolateDecoration{flat none} - } - x_2_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{6} - InterpolateDecoration{flat none} - } - x_2_param_1 - none - undefined - __f32 - } - ) - { - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{0} - } - Identifier[not set]{x_1_param} - } - Assignment{ - ArrayAccessor[not set]{ - Identifier[not set]{x_1} - ScalarConstructor[not set]{1} - } - Identifier[not set]{x_1_param_1} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{field0} - } - Identifier[not set]{x_2_param} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_2} - Identifier[not set]{field1} - } - Identifier[not set]{x_2_param_1} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + R"(struct S { + field0 : f32; + field1 : f32; +}; + +var x_1 : array; + +var x_2 : S; + +fn main_1() { + return; +} + +[[stage(fragment)]] +fn main([[location(1), interpolate(flat)]] x_1_param : f32, [[location(2), interpolate(flat)]] x_1_param_1 : f32, [[location(5), interpolate(flat)]] x_2_param : f32, [[location(6), interpolate(flat)]] x_2_param_1 : f32) { + x_1[0] = x_1_param; + x_1[1] = x_1_param_1; + x_2.field0 = x_2_param; + x_2.field1 = x_2_param_1; + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -8211,144 +5019,33 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Variable{ - x_1 - private - undefined - __f32 - } - Variable{ - x_2 - private - undefined - __f32 - } - Variable{ - x_3 - private - undefined - __f32 - } - Variable{ - x_4 - private - undefined - __f32 - } - Variable{ - x_5 - private - undefined - __f32 - } - Variable{ - x_6 - private - undefined - __f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - LocationDecoration{1} - } - x_1_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{2} - InterpolateDecoration{perspective centroid} - } - x_2_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{3} - InterpolateDecoration{perspective sample} - } - x_3_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{4} - InterpolateDecoration{linear none} - } - x_4_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{5} - InterpolateDecoration{linear centroid} - } - x_5_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{6} - InterpolateDecoration{linear sample} - } - x_6_param - none - undefined - __f32 - } - ) - { - Assignment{ - Identifier[not set]{x_1} - Identifier[not set]{x_1_param} - } - Assignment{ - Identifier[not set]{x_2} - Identifier[not set]{x_2_param} - } - Assignment{ - Identifier[not set]{x_3} - Identifier[not set]{x_3_param} - } - Assignment{ - Identifier[not set]{x_4} - Identifier[not set]{x_4_param} - } - Assignment{ - Identifier[not set]{x_5} - Identifier[not set]{x_5_param} - } - Assignment{ - Identifier[not set]{x_6} - Identifier[not set]{x_6_param} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + R"(var x_1 : f32; + +var x_2 : f32; + +var x_3 : f32; + +var x_4 : f32; + +var x_5 : f32; + +var x_6 : f32; + +fn main_1() { + return; +} + +[[stage(fragment)]] +fn main([[location(1)]] x_1_param : f32, [[location(2), interpolate(perspective, centroid)]] x_2_param : f32, [[location(3), interpolate(perspective, sample)]] x_3_param : f32, [[location(4), interpolate(linear)]] x_4_param : f32, [[location(5), interpolate(linear, centroid)]] x_5_param : f32, [[location(6), interpolate(linear, sample)]] x_6_param : f32) { + x_1 = x_1_param; + x_2 = x_2_param; + x_3 = x_3_param; + x_4 = x_4_param; + x_5 = x_5_param; + x_6 = x_6_param; + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -8391,140 +5088,32 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Struct S { - StructMember{field0: __f32} - StructMember{field1: __f32} - StructMember{field2: __f32} - StructMember{field3: __f32} - StructMember{field4: __f32} - StructMember{field5: __f32} - } - Variable{ - x_1 - private - undefined - __type_name_S - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __void - StageDecoration{fragment} - ( - VariableConst{ - Decorations{ - LocationDecoration{1} - } - x_1_param - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{2} - InterpolateDecoration{perspective centroid} - } - x_1_param_1 - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{3} - InterpolateDecoration{perspective sample} - } - x_1_param_2 - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{4} - InterpolateDecoration{linear none} - } - x_1_param_3 - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{5} - InterpolateDecoration{linear centroid} - } - x_1_param_4 - none - undefined - __f32 - } - VariableConst{ - Decorations{ - LocationDecoration{6} - InterpolateDecoration{linear sample} - } - x_1_param_5 - none - undefined - __f32 - } - ) - { - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field0} - } - Identifier[not set]{x_1_param} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field1} - } - Identifier[not set]{x_1_param_1} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field2} - } - Identifier[not set]{x_1_param_2} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field3} - } - Identifier[not set]{x_1_param_3} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field4} - } - Identifier[not set]{x_1_param_4} - } - Assignment{ - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field5} - } - Identifier[not set]{x_1_param_5} - } - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - } + R"(struct S { + field0 : f32; + field1 : f32; + field2 : f32; + field3 : f32; + field4 : f32; + field5 : f32; +}; + +var x_1 : S; + +fn main_1() { + return; +} + +[[stage(fragment)]] +fn main([[location(1)]] x_1_param : f32, [[location(2), interpolate(perspective, centroid)]] x_1_param_1 : f32, [[location(3), interpolate(perspective, sample)]] x_1_param_2 : f32, [[location(4), interpolate(linear)]] x_1_param_3 : f32, [[location(5), interpolate(linear, centroid)]] x_1_param_4 : f32, [[location(6), interpolate(linear, sample)]] x_1_param_5 : f32) { + x_1.field0 = x_1_param; + x_1.field1 = x_1_param_1; + x_1.field2 = x_1_param_2; + x_1.field3 = x_1_param_3; + x_1.field4 = x_1_param_4; + x_1.field5 = x_1_param_5; + main_1(); } )"; EXPECT_EQ(got, expected) << got; @@ -8576,92 +5165,43 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Struct main_out { - StructMember{[[ LocationDecoration{1} - ]] x_1_1: __f32} - StructMember{[[ LocationDecoration{2} - InterpolateDecoration{perspective centroid} - ]] x_2_1: __f32} - StructMember{[[ LocationDecoration{3} - InterpolateDecoration{perspective sample} - ]] x_3_1: __f32} - StructMember{[[ LocationDecoration{4} - InterpolateDecoration{linear none} - ]] x_4_1: __f32} - StructMember{[[ LocationDecoration{5} - InterpolateDecoration{linear centroid} - ]] x_5_1: __f32} - StructMember{[[ LocationDecoration{6} - InterpolateDecoration{linear sample} - ]] x_6_1: __f32} - } - Variable{ - x_1 - private - undefined - __f32 - } - Variable{ - x_2 - private - undefined - __f32 - } - Variable{ - x_3 - private - undefined - __f32 - } - Variable{ - x_4 - private - undefined - __f32 - } - Variable{ - x_5 - private - undefined - __f32 - } - Variable{ - x_6 - private - undefined - __f32 - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - Identifier[not set]{x_1} - Identifier[not set]{x_2} - Identifier[not set]{x_3} - Identifier[not set]{x_4} - Identifier[not set]{x_5} - Identifier[not set]{x_6} - } - } - } - } + R"(var x_1 : f32; + +var x_2 : f32; + +var x_3 : f32; + +var x_4 : f32; + +var x_5 : f32; + +var x_6 : f32; + +fn main_1() { + return; +} + +struct main_out { + [[location(1)]] + x_1_1 : f32; + [[location(2), interpolate(perspective, centroid)]] + x_2_1 : f32; + [[location(3), interpolate(perspective, sample)]] + x_3_1 : f32; + [[location(4), interpolate(linear)]] + x_4_1 : f32; + [[location(5), interpolate(linear, centroid)]] + x_5_1 : f32; + [[location(6), interpolate(linear, sample)]] + x_6_1 : f32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1, x_2, x_3, x_4, x_5, x_6); } )"; EXPECT_EQ(got, expected) << got; @@ -8705,88 +5245,42 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto got = p->program().to_str(); + const auto got = test::ToString(p->program()); const std::string expected = - R"(Module{ - Struct S { - StructMember{field0: __f32} - StructMember{field1: __f32} - StructMember{field2: __f32} - StructMember{field3: __f32} - StructMember{field4: __f32} - StructMember{field5: __f32} - } - Struct main_out { - StructMember{[[ LocationDecoration{1} - ]] x_1_1: __f32} - StructMember{[[ LocationDecoration{2} - InterpolateDecoration{perspective centroid} - ]] x_1_2: __f32} - StructMember{[[ LocationDecoration{3} - InterpolateDecoration{perspective sample} - ]] x_1_3: __f32} - StructMember{[[ LocationDecoration{4} - InterpolateDecoration{linear none} - ]] x_1_4: __f32} - StructMember{[[ LocationDecoration{5} - InterpolateDecoration{linear centroid} - ]] x_1_5: __f32} - StructMember{[[ LocationDecoration{6} - InterpolateDecoration{linear sample} - ]] x_1_6: __f32} - } - Variable{ - x_1 - private - undefined - __type_name_S - } - Function main_1 -> __void - () - { - Return{} - } - Function main -> __type_name_main_out - StageDecoration{fragment} - () - { - Call[not set]{ - Identifier[not set]{main_1} - ( - ) - } - Return{ - { - TypeConstructor[not set]{ - __type_name_main_out - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field0} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field1} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field2} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field3} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field4} - } - MemberAccessor[not set]{ - Identifier[not set]{x_1} - Identifier[not set]{field5} - } - } - } - } - } + R"(struct S { + field0 : f32; + field1 : f32; + field2 : f32; + field3 : f32; + field4 : f32; + field5 : f32; +}; + +var x_1 : S; + +fn main_1() { + return; +} + +struct main_out { + [[location(1)]] + x_1_1 : f32; + [[location(2), interpolate(perspective, centroid)]] + x_1_2 : f32; + [[location(3), interpolate(perspective, sample)]] + x_1_3 : f32; + [[location(4), interpolate(linear)]] + x_1_4 : f32; + [[location(5), interpolate(linear, centroid)]] + x_1_5 : f32; + [[location(6), interpolate(linear, sample)]] + x_1_6 : f32; +}; + +[[stage(fragment)]] +fn main() -> main_out { + main_1(); + return main_out(x_1.field0, x_1.field1, x_1.field2, x_1.field3, x_1.field4, x_1.field5); } )"; EXPECT_EQ(got, expected) << got; diff --git a/src/reader/spirv/parser_impl_named_types_test.cc b/src/reader/spirv/parser_impl_named_types_test.cc index bdaadc66b7..c9a951c6c3 100644 --- a/src/reader/spirv/parser_impl_named_types_test.cc +++ b/src/reader/spirv/parser_impl_named_types_test.cc @@ -29,7 +29,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) { %s = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), HasSubstr("Struct S")); + EXPECT_THAT(test::ToString(p->program()), HasSubstr("struct S")); p->DeliberatelyInvalidSpirv(); } @@ -41,7 +41,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) { %s = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), HasSubstr("Struct mystruct")); + EXPECT_THAT(test::ToString(p->program()), HasSubstr("struct mystruct")); p->DeliberatelyInvalidSpirv(); } @@ -53,14 +53,15 @@ TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) { %s2 = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); - EXPECT_THAT(p->program().to_str(), HasSubstr(R"(Struct S { - StructMember{field0: __u32} - StructMember{field1: __u32} - } - Struct S_1 { - StructMember{field0: __u32} - StructMember{field1: __u32} - })")); + EXPECT_THAT(test::ToString(p->program()), HasSubstr(R"(struct S { + field0 : u32; + field1 : u32; +}; + +struct S_1 { + field0 : u32; + field1 : u32; +})")); p->DeliberatelyInvalidSpirv(); } @@ -76,8 +77,8 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArrayWithDecoration) { %arr = OpTypeRuntimeArray %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), - HasSubstr("RTArr -> __array__u32_stride_8\n")); + EXPECT_THAT(test::ToString(p->program()), + HasSubstr("RTArr = [[stride(8)]] array;\n")); p->DeliberatelyInvalidSpirv(); } @@ -91,9 +92,11 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArray_Dup_EmitBoth) { %arr2 = OpTypeRuntimeArray %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), - HasSubstr("RTArr -> __array__u32_stride_8\n RTArr_1 -> " - "__array__u32_stride_8\n")); + EXPECT_THAT(test::ToString(p->program()), + HasSubstr(R"(type RTArr = [[stride(8)]] array; + +type RTArr_1 = [[stride(8)]] array; +)")); p->DeliberatelyInvalidSpirv(); } @@ -106,8 +109,8 @@ TEST_F(SpvParserTest, NamedTypes_NamedRTArray) { %arr = OpTypeRuntimeArray %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), - HasSubstr("myrtarr -> __array__u32_stride_8\n")); + EXPECT_THAT(test::ToString(p->program()), + HasSubstr("myrtarr = [[stride(8)]] array;\n")); p->DeliberatelyInvalidSpirv(); } @@ -122,8 +125,8 @@ TEST_F(SpvParserTest, NamedTypes_NamedArray) { %arr2 = OpTypeArray %uint %uint_5 )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), - HasSubstr("myarr -> __array__u32_5_stride_8")); + EXPECT_THAT(test::ToString(p->program()), + HasSubstr("myarr = [[stride(8)]] array;")); p->DeliberatelyInvalidSpirv(); } @@ -138,9 +141,11 @@ TEST_F(SpvParserTest, NamedTypes_AnonArray_Dup_EmitBoth) { %arr2 = OpTypeArray %uint %uint_5 )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(p->program().to_str(), - HasSubstr("Arr -> __array__u32_5_stride_8\n Arr_1 -> " - "__array__u32_5_stride_8")); + EXPECT_THAT(test::ToString(p->program()), + HasSubstr(R"(type Arr = [[stride(8)]] array; + +type Arr_1 = [[stride(8)]] array; +)")); p->DeliberatelyInvalidSpirv(); } diff --git a/src/reader/spirv/parser_impl_test_helper.cc b/src/reader/spirv/parser_impl_test_helper.cc index 234c869e58..79ea5d012d 100644 --- a/src/reader/spirv/parser_impl_test_helper.cc +++ b/src/reader/spirv/parser_impl_test_helper.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/reader/spirv/parser_impl_test_helper.h" +#include "src/writer/wgsl/generator_impl.h" namespace tint { namespace reader { @@ -35,6 +36,49 @@ ParserImplWrapperForTest::~ParserImplWrapperForTest() { } } +std::string ToString(const Program& program) { + writer::wgsl::GeneratorImpl writer(&program); + if (!writer.Generate()) { + return "WGSL writer error: " + writer.error(); + } + return writer.result(); +} + +std::string ToString(const Program& program, const ast::StatementList& stmts) { + writer::wgsl::GeneratorImpl writer(&program); + for (const auto* stmt : stmts) { + if (!writer.EmitStatement(const_cast(stmt))) { + return "WGSL writer error: " + writer.error(); + } + } + return writer.result(); +} + +std::string ToString(const Program& program, const ast::Node* node) { + writer::wgsl::GeneratorImpl writer(&program); + if (auto* expr = node->As()) { + std::stringstream out; + if (!writer.EmitExpression(out, const_cast(expr))) { + return "WGSL writer error: " + writer.error(); + } + return out.str(); + } else if (auto* stmt = node->As()) { + if (!writer.EmitStatement(const_cast(stmt))) { + return "WGSL writer error: " + writer.error(); + } + } else if (auto* ty = node->As()) { + std::stringstream out; + if (!writer.EmitType(out, const_cast(ty))) { + return "WGSL writer error: " + writer.error(); + } + return out.str(); + } else { + return "TypeInfo().name) + + ">"; + } + return writer.result(); +} + } // namespace test } // namespace spirv } // namespace reader diff --git a/src/reader/spirv/parser_impl_test_helper.h b/src/reader/spirv/parser_impl_test_helper.h index 640f172097..26b91360a8 100644 --- a/src/reader/spirv/parser_impl_test_helper.h +++ b/src/reader/spirv/parser_impl_test_helper.h @@ -269,6 +269,23 @@ inline void DumpSuccessfullyConvertedSpirv() { ParserImplWrapperForTest::DumpSuccessfullyConvertedSpirv(); } +/// Returns the WGSL printed string of a program. +/// @param program the Program +/// @returns the WGSL printed string the program. +std::string ToString(const Program& program); + +/// Returns the WGSL printed string of a statement list. +/// @param program the Program +/// @param stmts the statement list +/// @returns the WGSL printed string of a statement list. +std::string ToString(const Program& program, const ast::StatementList& stmts); + +/// Returns the WGSL printed string of an AST node. +/// @param program the Program +/// @param node the AST node +/// @returns the WGSL printed string of the AST node. +std::string ToString(const Program& program, const ast::Node* node); + } // namespace test /// SPIR-V Parser test class @@ -295,32 +312,6 @@ class SpvParserTestBase : public T { // Use this form when you don't need to template any further. using SpvParserTest = SpvParserTestBase<::testing::Test>; -/// Returns the string dump of a statement list. -/// @param program the Program -/// @param stmts the statement list -/// @returns the string dump of a statement list. -inline std::string ToString(const Program& program, - const ast::StatementList& stmts) { - std::ostringstream outs; - for (const auto* stmt : stmts) { - program.to_str(stmt, outs, 0); - } - return Demangler().Demangle(program.Symbols(), outs.str()); -} - -/// Returns the string dump of a statement list. -/// @param builder the ProgramBuilder -/// @param stmts the statement list -/// @returns the string dump of a statement list. -inline std::string ToString(ProgramBuilder& builder, - const ast::StatementList& stmts) { - std::ostringstream outs; - for (const auto* stmt : stmts) { - builder.to_str(stmt, outs, 0); - } - return Demangler().Demangle(builder.Symbols(), outs.str()); -} - } // namespace spirv } // namespace reader } // namespace tint