[spirv-reader] Support kill

Bug: tint:3
Change-Id: I91472b98c9977a5bdce6fc2ab4880e8312881fcf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22500
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
David Neto 2020-06-02 19:56:07 +00:00
parent 1d69915155
commit 91332dc475
2 changed files with 92 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "src/ast/else_statement.h" #include "src/ast/else_statement.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/kill_statement.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/member_accessor_expression.h" #include "src/ast/member_accessor_expression.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
@ -1766,6 +1767,11 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
std::make_unique<ast::ReturnStatement>(std::move(value.expr))); std::make_unique<ast::ReturnStatement>(std::move(value.expr)));
} }
return true; return true;
case SpvOpKill:
// For now, assume SPIR-V OpKill has same semantics as WGSL kill.
// TODO(dneto): https://github.com/gpuweb/gpuweb/issues/676
AddStatement(std::make_unique<ast::KillStatement>());
return true;
default: default:
break; break;
} }

View File

@ -7861,6 +7861,92 @@ Return{
)")) << ToString(fe.ast_body()); )")) << ToString(fe.ast_body());
} }
TEST_F(SpvParserTest, EmitBody_Kill_TopLevel) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
%10 = OpLabel
OpKill
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p, *spirv_function(100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Kill{}
)")) << ToString(fe.ast_body());
}
TEST_F(SpvParserTest, EmitBody_Kill_InsideIf) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
%10 = OpLabel
OpSelectionMerge %99 None
OpBranchConditional %cond %20 %99
%20 = OpLabel
OpKill
%99 = OpLabel
OpKill
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p, *spirv_function(100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(If{
(
ScalarConstructor{false}
)
{
Kill{}
}
}
Else{
{
}
}
Kill{}
)")) << ToString(fe.ast_body());
}
TEST_F(SpvParserTest, EmitBody_Kill_InsideLoop) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
%10 = OpLabel
OpBranch %20
%20 = OpLabel
OpLoopMerge %99 %80 None
OpBranchConditional %cond %30 %30
%30 = OpLabel
OpKill
%80 = OpLabel
OpBranch %20
%99 = OpLabel
OpKill
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p, *spirv_function(100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Loop{
Kill{}
}
Kill{}
)")) << ToString(fe.ast_body());
}
} // namespace } // namespace
} // namespace spirv } // namespace spirv
} // namespace reader } // namespace reader