From 23508f43398520c80e7d86899c71167c7b95c006 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Sat, 25 Jul 2020 14:33:35 +0000 Subject: [PATCH] [spirv-reader] Convert from KillStatement to DiscardStatement This CL changes the SPIRV-Reader to generate DiscardStatements instead of KillStatements for an OpKill. Bug: tint:168 Change-Id: Ic4223b614c822c6ad449f61aedaddc9605c42535 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25642 Reviewed-by: David Neto --- src/reader/spirv/function.cc | 4 ++-- src/reader/spirv/function_cfg_test.cc | 10 +++++----- src/reader/spirv/namer.cc | 5 +++-- src/reader/spirv/namer_test.cc | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index cfd830e69c..46dcec216f 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -38,11 +38,11 @@ #include "src/ast/case_statement.h" #include "src/ast/cast_expression.h" #include "src/ast/continue_statement.h" +#include "src/ast/discard_statement.h" #include "src/ast/else_statement.h" #include "src/ast/fallthrough_statement.h" #include "src/ast/identifier_expression.h" #include "src/ast/if_statement.h" -#include "src/ast/kill_statement.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" #include "src/ast/return_statement.h" @@ -2194,7 +2194,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) { 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()); + AddStatement(std::make_unique()); return true; case SpvOpUnreachable: // Translate as if it's a return. This avoids the problem where WGSL diff --git a/src/reader/spirv/function_cfg_test.cc b/src/reader/spirv/function_cfg_test.cc index 8a73eb11de..42961bcb89 100644 --- a/src/reader/spirv/function_cfg_test.cc +++ b/src/reader/spirv/function_cfg_test.cc @@ -9947,7 +9947,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_TopLevel) { FunctionEmitter fe(p, *spirv_function(100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Kill{} + EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Discard{} )")) << ToString(fe.ast_body()); } @@ -9976,10 +9976,10 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideIf) { ScalarConstructor{false} ) { - Kill{} + Discard{} } } -Kill{} +Discard{} )")) << ToString(fe.ast_body()); } @@ -10010,9 +10010,9 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideLoop) { EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Loop{ - Kill{} + Discard{} } -Kill{} +Discard{} )")) << ToString(fe.ast_body()); } diff --git a/src/reader/spirv/namer.cc b/src/reader/spirv/namer.cc index 1087c64d7e..8ba38fa06f 100644 --- a/src/reader/spirv/namer.cc +++ b/src/reader/spirv/namer.cc @@ -42,6 +42,7 @@ const char* kWGSLReservedWords[] = { "constant_id", "continue", "default", + "discard", "do", "else", "elseif", @@ -62,7 +63,6 @@ const char* kWGSLReservedWords[] = { "image", "import", "in", - "kill", "let", "location", "loop", @@ -106,7 +106,8 @@ const char* kWGSLReservedWords[] = { "while", "workgroup", }; -} + +} // namespace Namer::Namer(const FailStream& fail_stream) : fail_stream_(fail_stream) { for (const auto* reserved : kWGSLReservedWords) { diff --git a/src/reader/spirv/namer_test.cc b/src/reader/spirv/namer_test.cc index 484e6f4c60..96dc0e3fad 100644 --- a/src/reader/spirv/namer_test.cc +++ b/src/reader/spirv/namer_test.cc @@ -340,6 +340,7 @@ INSTANTIATE_TEST_SUITE_P(SpvParserTest_ReservedWords, "constant_id", "continue", "default", + "discard", "do", "else", "elseif", @@ -360,7 +361,6 @@ INSTANTIATE_TEST_SUITE_P(SpvParserTest_ReservedWords, "image", "import", "in", - "kill", "let", "location", "loop",