mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-15 17:45:58 +00:00
[spirv-reader] Add OpFNegate
Bug: tint:3 Change-Id: I081df8fd37750917ae15667954d1b3fabb799010 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19883 Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
parent
6584028bb4
commit
6eb498d669
@ -47,6 +47,7 @@ namespace {
|
|||||||
bool GetUnaryOp(SpvOp opcode, ast::UnaryOp* ast_unary_op) {
|
bool GetUnaryOp(SpvOp opcode, ast::UnaryOp* ast_unary_op) {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case SpvOpSNegate:
|
case SpvOpSNegate:
|
||||||
|
case SpvOpFNegate:
|
||||||
*ast_unary_op = ast::UnaryOp::kNegation;
|
*ast_unary_op = ast::UnaryOp::kNegation;
|
||||||
return true;
|
return true;
|
||||||
// TODO(dneto): SpvOpNegate SpvOpNot SpvLogicalNot
|
// TODO(dneto): SpvOpNegate SpvOpNot SpvLogicalNot
|
||||||
|
@ -334,6 +334,64 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
|
|||||||
<< ToString(fe.ast_body());
|
<< ToString(fe.ast_body());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
|
||||||
|
const auto assembly = CommonTypes() + R"(
|
||||||
|
%100 = OpFunction %void None %voidfn
|
||||||
|
%entry = OpLabel
|
||||||
|
%1 = OpFNegate %float %float_50
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
auto p = parser(test::Assemble(assembly));
|
||||||
|
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||||
|
FunctionEmitter fe(p, *spirv_function(100));
|
||||||
|
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||||
|
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(
|
||||||
|
Variable{
|
||||||
|
x_1
|
||||||
|
none
|
||||||
|
__f32
|
||||||
|
{
|
||||||
|
UnaryOp{
|
||||||
|
negation
|
||||||
|
ScalarConstructor{50.000000}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})"))
|
||||||
|
<< ToString(fe.ast_body());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvUnaryArithTest, FNegate_Vector) {
|
||||||
|
const auto assembly = CommonTypes() + R"(
|
||||||
|
%100 = OpFunction %void None %voidfn
|
||||||
|
%entry = OpLabel
|
||||||
|
%1 = OpFNegate %v2float %v2float_50_60
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
auto p = parser(test::Assemble(assembly));
|
||||||
|
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||||
|
FunctionEmitter fe(p, *spirv_function(100));
|
||||||
|
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||||
|
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(
|
||||||
|
Variable{
|
||||||
|
x_1
|
||||||
|
none
|
||||||
|
__vec_2__f32
|
||||||
|
{
|
||||||
|
UnaryOp{
|
||||||
|
negation
|
||||||
|
TypeConstructor{
|
||||||
|
__vec_2__f32
|
||||||
|
ScalarConstructor{50.000000}
|
||||||
|
ScalarConstructor{60.000000}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})"))
|
||||||
|
<< ToString(fe.ast_body());
|
||||||
|
}
|
||||||
|
|
||||||
struct BinaryData {
|
struct BinaryData {
|
||||||
const std::string res_type;
|
const std::string res_type;
|
||||||
const std::string lhs;
|
const std::string lhs;
|
||||||
@ -1022,9 +1080,6 @@ INSTANTIATE_TEST_SUITE_P(
|
|||||||
"__vec_2__i32", AstFor("v2int_40_30"), "xor",
|
"__vec_2__i32", AstFor("v2int_40_30"), "xor",
|
||||||
AstFor("v2uint_20_10")}));
|
AstFor("v2uint_20_10")}));
|
||||||
|
|
||||||
// TODO(dneto): OpSNegate
|
|
||||||
// TODO(dneto): OpFNegate
|
|
||||||
|
|
||||||
// TODO(dneto): OpSRem. Missing from WGSL
|
// TODO(dneto): OpSRem. Missing from WGSL
|
||||||
// https://github.com/gpuweb/gpuweb/issues/702
|
// https://github.com/gpuweb/gpuweb/issues/702
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user