[msl-writer] Emit DiscardStatement.
This CL adds the DiscardStatement to the MSL backend. Bug: tint:164 Change-Id: I1e201d3b6a167690af7bb799e1c93e48232f4a0a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25602 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
6a61d4127e
commit
a9696b511f
1
BUILD.gn
1
BUILD.gn
|
@ -994,6 +994,7 @@ source_set("tint_unittests_msl_writer_src") {
|
|||
"src/writer/msl/generator_impl_cast_test.cc",
|
||||
"src/writer/msl/generator_impl_constructor_test.cc",
|
||||
"src/writer/msl/generator_impl_continue_test.cc",
|
||||
"src/writer/msl/generator_impl_discard_test.cc",
|
||||
"src/writer/msl/generator_impl_entry_point_test.cc",
|
||||
"src/writer/msl/generator_impl_function_test.cc",
|
||||
"src/writer/msl/generator_impl_identifier_test.cc",
|
||||
|
|
|
@ -525,6 +525,7 @@ if(${TINT_BUILD_MSL_WRITER})
|
|||
writer/msl/generator_impl_cast_test.cc
|
||||
writer/msl/generator_impl_constructor_test.cc
|
||||
writer/msl/generator_impl_continue_test.cc
|
||||
writer/msl/generator_impl_discard_test.cc
|
||||
writer/msl/generator_impl_entry_point_test.cc
|
||||
writer/msl/generator_impl_function_test.cc
|
||||
writer/msl/generator_impl_identifier_test.cc
|
||||
|
|
|
@ -1389,6 +1389,14 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitDiscard(ast::DiscardStatement*) {
|
||||
make_indent();
|
||||
// TODO(dsinclair): Verify this is correct when the discard semantics are
|
||||
// defined for WGSL (https://github.com/gpuweb/gpuweb/issues/361)
|
||||
out_ << "discard_fragment();" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitKill(ast::KillStatement*) {
|
||||
make_indent();
|
||||
// TODO(dsinclair): Verify this is correct when the kill semantics are defined
|
||||
|
@ -1509,6 +1517,9 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
|
|||
if (stmt->IsContinue()) {
|
||||
return EmitContinue(stmt->AsContinue());
|
||||
}
|
||||
if (stmt->IsDiscard()) {
|
||||
return EmitDiscard(stmt->AsDiscard());
|
||||
}
|
||||
if (stmt->IsFallthrough()) {
|
||||
make_indent();
|
||||
out_ << "/* fallthrough */" << std::endl;
|
||||
|
|
|
@ -97,6 +97,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted successfully
|
||||
bool EmitContinue(ast::ContinueStatement* stmt);
|
||||
/// Handles generating a discard statement
|
||||
/// @param stmt the discard statement
|
||||
/// @returns true if the statement was successfully emitted
|
||||
bool EmitDiscard(ast::DiscardStatement* stmt);
|
||||
/// Handles generating an else statement
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/discard_statement.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Discard) {
|
||||
ast::DiscardStatement stmt;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " discard_fragment();\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
Loading…
Reference in New Issue