[hlsl-writer] Emit discard.
This CL adds the discard statement to the HLSL writer. Bug: tint:7, tint:166 Change-Id: I292e9b97a1246c9b79a9660ec229ff7855aeb2a9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25842 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
ec007b98c7
commit
cda5af0fa2
1
BUILD.gn
1
BUILD.gn
|
@ -1049,6 +1049,7 @@ source_set("tint_unittests_hlsl_writer_src") {
|
|||
"src/writer/hlsl/generator_impl_case_test.cc",
|
||||
"src/writer/hlsl/generator_impl_constructor_test.cc",
|
||||
"src/writer/hlsl/generator_impl_continue_test.cc",
|
||||
"src/writer/hlsl/generator_impl_discard_test.cc",
|
||||
"src/writer/hlsl/generator_impl_identifier_test.cc",
|
||||
"src/writer/hlsl/generator_impl_return_test.cc",
|
||||
"src/writer/hlsl/generator_impl_switch_test.cc",
|
||||
|
|
|
@ -557,6 +557,7 @@ if (${TINT_BUILD_HLSL_WRITER})
|
|||
writer/hlsl/generator_impl_case_test.cc
|
||||
writer/hlsl/generator_impl_constructor_test.cc
|
||||
writer/hlsl/generator_impl_continue_test.cc
|
||||
writer/hlsl/generator_impl_discard_test.cc
|
||||
writer/hlsl/generator_impl_identifier_test.cc
|
||||
writer/hlsl/generator_impl_return_test.cc
|
||||
writer/hlsl/generator_impl_switch_test.cc
|
||||
|
|
|
@ -325,6 +325,14 @@ bool GeneratorImpl::EmitContinue(ast::ContinueStatement*) {
|
|||
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;" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
||||
if (expr->IsArrayAccessor()) {
|
||||
return EmitArrayAccessor(expr->AsArrayAccessor());
|
||||
|
@ -450,6 +458,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;
|
||||
|
|
|
@ -66,6 +66,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param expr the constructor expression
|
||||
/// @returns true if the expression was emitted
|
||||
bool EmitConstructor(ast::ConstructorExpression* expr);
|
||||
/// 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 a scalar constructor
|
||||
/// @param expr the scalar constructor expression
|
||||
/// @returns true if the scalar constructor is 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/hlsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace hlsl {
|
||||
namespace {
|
||||
|
||||
using HlslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest, 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;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace hlsl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
Loading…
Reference in New Issue