diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index 74d39f9a39..33f2bdbe86 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -386,6 +386,7 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) { case GLSLstd450Pow: return "pow"; case GLSLstd450FSign: + case GLSLstd450SSign: return "sign"; case GLSLstd450Radians: return "radians"; @@ -427,8 +428,6 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) { // TODO(dneto) - The following are not implemented. // They are grouped semantically, as in GLSL.std.450.h. - case GLSLstd450SSign: - case GLSLstd450Asinh: case GLSLstd450Acosh: case GLSLstd450Atanh: diff --git a/src/tint/reader/spirv/function_glsl_std_450_test.cc b/src/tint/reader/spirv/function_glsl_std_450_test.cc index 584ec2ad56..f0e7e2a74a 100644 --- a/src/tint/reader/spirv/function_glsl_std_450_test.cc +++ b/src/tint/reader/spirv/function_glsl_std_450_test.cc @@ -175,6 +175,8 @@ using SpvParserTest_GlslStd450_Float3_Float3Float3 = using SpvParserTest_GlslStd450_Inting_Inting = SpvParserTestBase<::testing::TestWithParam>; +using SpvParserTest_GlslStd450_Inting_Inting_SignednessCoercing = + SpvParserTestBase<::testing::TestWithParam>; using SpvParserTest_GlslStd450_Inting_IntingInting = SpvParserTestBase<::testing::TestWithParam>; using SpvParserTest_GlslStd450_Inting_IntingIntingInting = @@ -490,6 +492,42 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) { EXPECT_THAT(body, HasSubstr("let x_1 : i32 = " + GetParam().wgsl_func + "(i1);")) << body; } +TEST_P(SpvParserTest_GlslStd450_Inting_Inting_SignednessCoercing, Scalar_UnsignedArg) { + const auto assembly = Preamble() + R"( + %1 = OpExtInst %int %glsl )" + + GetParam().opcode + + R"( %u1 + OpReturn + OpFunctionEnd + )"; + auto p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); + auto fe = p->function_emitter(100); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + 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 + "(bitcast(u1));")) + << body; +} + +TEST_P(SpvParserTest_GlslStd450_Inting_Inting_SignednessCoercing, Scalar_UnsignedResult) { + const auto assembly = Preamble() + R"( + %1 = OpExtInst %uint %glsl )" + + GetParam().opcode + + R"( %i1 + OpReturn + OpFunctionEnd + )"; + auto p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); + auto fe = p->function_emitter(100); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : u32 = bitcast(" + GetParam().wgsl_func + "(i1));")) + << body; +} + TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { const auto assembly = Preamble() + R"( %1 = OpExtInst %v2int %glsl )" + @@ -508,6 +546,44 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { << body; } +TEST_P(SpvParserTest_GlslStd450_Inting_Inting_SignednessCoercing, Vector_UnsignedArg) { + const auto assembly = Preamble() + R"( + %1 = OpExtInst %v2int %glsl )" + + GetParam().opcode + + R"( %v2u1 + OpReturn + OpFunctionEnd + )"; + auto p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); + auto fe = p->function_emitter(100); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + 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 + + "(bitcast>(v2u1));")) + << body; +} + +TEST_P(SpvParserTest_GlslStd450_Inting_Inting_SignednessCoercing, Vector_UnsignedResult) { + const auto assembly = Preamble() + R"( + %1 = OpExtInst %v2uint %glsl )" + + GetParam().opcode + + R"( %v2i1 + OpReturn + OpFunctionEnd + )"; + auto p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); + auto fe = p->function_emitter(100); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + auto ast_body = fe.ast_body(); + const auto body = test::ToString(p->program(), ast_body); + EXPECT_THAT(body, HasSubstr("let x_1 : vec2 = bitcast>(" + GetParam().wgsl_func + + "(v2i1));")) + << body; +} + TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { const auto assembly = Preamble() + R"( %1 = OpExtInst %int %glsl )" + @@ -584,7 +660,12 @@ INSTANTIATE_TEST_SUITE_P(Samples, SpvParserTest_GlslStd450_Inting_Inting, ::testing::Values(GlslStd450Case{"SAbs", "abs"}, GlslStd450Case{"FindILsb", "firstTrailingBit"}, - GlslStd450Case{"FindSMsb", "firstLeadingBit"})); + GlslStd450Case{"FindSMsb", "firstLeadingBit"}, + GlslStd450Case{"SSign", "sign"})); + +INSTANTIATE_TEST_SUITE_P(Samples, + SpvParserTest_GlslStd450_Inting_Inting_SignednessCoercing, + ::testing::Values(GlslStd450Case{"SSign", "sign"})); INSTANTIATE_TEST_SUITE_P(Samples, SpvParserTest_GlslStd450_Inting_IntingInting,