[msl-writer] Emit kill statement.

This Cl adds emission of the Kill statement as `discard_fragment`. This
may need to be revised when the semantics of Kill are agreed upon.

Bug: tint:8
Change-Id: I2d09f09143b2acd0139d876e873e3c70abbc84a3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23841
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-06-26 21:27:59 +00:00 committed by David Neto
parent 28d4a94bee
commit 24a46e8e69
5 changed files with 56 additions and 0 deletions

View File

@ -892,6 +892,7 @@ source_set("tint_unittests_msl_writer_src") {
"src/writer/msl/generator_impl_function_test.cc",
"src/writer/msl/generator_impl_identifier_test.cc",
"src/writer/msl/generator_impl_if_test.cc",
"src/writer/msl/generator_impl_kill_test.cc",
"src/writer/msl/generator_impl_return_test.cc",
"src/writer/msl/generator_impl_test.cc",
"src/writer/msl/generator_impl_type_test.cc",

View File

@ -500,6 +500,7 @@ if(${TINT_BUILD_MSL_WRITER})
writer/msl/generator_impl_function_test.cc
writer/msl/generator_impl_identifier_test.cc
writer/msl/generator_impl_if_test.cc
writer/msl/generator_impl_kill_test.cc
writer/msl/generator_impl_return_test.cc
writer/msl/generator_impl_test.cc
writer/msl/generator_impl_type_test.cc

View File

@ -347,6 +347,14 @@ bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
return true;
}
bool GeneratorImpl::EmitKill(ast::KillStatement*) {
make_indent();
// TODO(dsinclair): Verify this is correct when the kill semantics are defined
// for WGSL (https://github.com/gpuweb/gpuweb/issues/361)
out_ << "discard_fragment();" << std::endl;
return true;
}
bool GeneratorImpl::EmitElse(ast::ElseStatement* stmt) {
if (stmt->HasCondition()) {
out_ << " else if (";
@ -431,6 +439,9 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
if (stmt->IsIf()) {
return EmitIf(stmt->AsIf());
}
if (stmt->IsKill()) {
return EmitKill(stmt->AsKill());
}
if (stmt->IsReturn()) {
return EmitReturn(stmt->AsReturn());
}

View File

@ -80,6 +80,10 @@ class GeneratorImpl : public TextGenerator {
/// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted
bool EmitIf(ast::IfStatement* stmt);
/// Handles generating a kill statement
/// @param stmt the kill statement
/// @returns true if the statement was successfully emitted
bool EmitKill(ast::KillStatement* stmt);
/// Handles a literal
/// @param lit the literal to emit
/// @returns true if the literal was successfully emitted

View File

@ -0,0 +1,39 @@
// 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/kill_statement.h"
#include "src/writer/msl/generator_impl.h"
namespace tint {
namespace writer {
namespace msl {
namespace {
using MslGeneratorImplTest = testing::Test;
TEST_F(MslGeneratorImplTest, Emit_Kill) {
ast::KillStatement k;
GeneratorImpl g;
g.increment_indent();
ASSERT_TRUE(g.EmitStatement(&k)) << g.error();
EXPECT_EQ(g.result(), " discard_fragment();\n");
}
} // namespace
} // namespace msl
} // namespace writer
} // namespace tint