tint: Use "demote-to-helper" semantics for discard

Discard statements no longer affect the behavior or uniformity
analysis. Update the resolver, validator, and several tests to reflect
this.

Some E2E tests were removed as they had loops that are now considered
to be infinite.

Use the DemoteToHelper transform to emulate the correct semantics on
platforms where discard is (or may) terminate the invocation in a
manner that would affect derivative operations.

We no longer need the UnwindDiscardFunctions transform for HLSL, which
already implements the correct semantics. However, we still run the
DemoteToHelper transform for the HLSL backend due to issues with FXC's
handling of discard statements (see crbug.com/tint/1118).

Fixed: tint:1723
Change-Id: Ib49ff187919ae81c4af8675e1b66acd57e2ff7d2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109003
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price 2022-11-09 19:58:59 +00:00 committed by Dawn LUCI CQ
parent 78ae4c243b
commit 744d0eb4aa
89 changed files with 1944 additions and 5513 deletions

View File

@ -554,8 +554,6 @@ libtint_source_set("libtint_core_all_src") {
"transform/transform.h", "transform/transform.h",
"transform/unshadow.cc", "transform/unshadow.cc",
"transform/unshadow.h", "transform/unshadow.h",
"transform/unwind_discard_functions.cc",
"transform/unwind_discard_functions.h",
"transform/utils/get_insertion_point.cc", "transform/utils/get_insertion_point.cc",
"transform/utils/get_insertion_point.h", "transform/utils/get_insertion_point.h",
"transform/utils/hoist_to_decl_before.cc", "transform/utils/hoist_to_decl_before.cc",
@ -1253,7 +1251,6 @@ if (tint_build_unittests) {
"transform/test_helper.h", "transform/test_helper.h",
"transform/transform_test.cc", "transform/transform_test.cc",
"transform/unshadow_test.cc", "transform/unshadow_test.cc",
"transform/unwind_discard_functions_test.cc",
"transform/utils/get_insertion_point_test.cc", "transform/utils/get_insertion_point_test.cc",
"transform/utils/hoist_to_decl_before_test.cc", "transform/utils/hoist_to_decl_before_test.cc",
"transform/var_for_dynamic_index_test.cc", "transform/var_for_dynamic_index_test.cc",

View File

@ -479,8 +479,6 @@ list(APPEND TINT_LIB_SRCS
transform/transform.h transform/transform.h
transform/unshadow.cc transform/unshadow.cc
transform/unshadow.h transform/unshadow.h
transform/unwind_discard_functions.cc
transform/unwind_discard_functions.h
transform/utils/get_insertion_point.cc transform/utils/get_insertion_point.cc
transform/utils/get_insertion_point.h transform/utils/get_insertion_point.h
transform/utils/hoist_to_decl_before.cc transform/utils/hoist_to_decl_before.cc
@ -1213,7 +1211,6 @@ if(TINT_BUILD_TESTS)
transform/substitute_override_test.cc transform/substitute_override_test.cc
transform/test_helper.h transform/test_helper.h
transform/unshadow_test.cc transform/unshadow_test.cc
transform/unwind_discard_functions_test.cc
transform/var_for_dynamic_index_test.cc transform/var_for_dynamic_index_test.cc
transform/vectorize_matrix_conversions_test.cc transform/vectorize_matrix_conversions_test.cc
transform/vectorize_scalar_matrix_initializers_test.cc transform/vectorize_scalar_matrix_initializers_test.cc

View File

@ -29,7 +29,7 @@
namespace tint::fuzzers::ast_fuzzer { namespace tint::fuzzers::ast_fuzzer {
JumpTracker::JumpTracker(const Program& program) { JumpTracker::JumpTracker(const Program& program) {
// Consider every AST node, looking for break, return and discard statements. // Consider every AST node, looking for break and return statements.
for (auto* node : program.ASTNodes().Objects()) { for (auto* node : program.ASTNodes().Objects()) {
auto* stmt = node->As<ast::Statement>(); auto* stmt = node->As<ast::Statement>();
if (stmt == nullptr) { if (stmt == nullptr) {
@ -63,14 +63,12 @@ JumpTracker::JumpTracker(const Program& program) {
} }
candidate_statements.insert(current); candidate_statements.insert(current);
} }
} else if (stmt->As<ast::ReturnStatement>() || stmt->As<ast::DiscardStatement>()) { } else if (stmt->As<ast::ReturnStatement>()) {
// Walk up the AST from the return or discard statement, recording that every node // Walk up the AST from the return statement, recording that every node encountered
// encountered along the way contains a return/discard. // along the way contains a return.
auto& target_set = stmt->As<ast::ReturnStatement>() ? contains_return_
: contains_intraprocedural_discard_;
const ast::Statement* current = stmt; const ast::Statement* current = stmt;
while (true) { while (true) {
target_set.insert(current); contains_return_.insert(current);
auto* parent = program.Sem().Get(current)->Parent(); auto* parent = program.Sem().Get(current)->Parent();
if (parent == nullptr) { if (parent == nullptr) {
break; break;

View File

@ -22,7 +22,7 @@
namespace tint::fuzzers::ast_fuzzer { namespace tint::fuzzers::ast_fuzzer {
/// This class computes information on which statements contain loop breaks, returns and discards. /// This class computes information on which statements contain loop breaks and returns.
/// It could be extended to handle other jumps, such as switch breaks and loop continues, should /// It could be extended to handle other jumps, such as switch breaks and loop continues, should
/// such information prove useful. /// such information prove useful.
class JumpTracker { class JumpTracker {
@ -47,20 +47,9 @@ class JumpTracker {
return contains_return_.count(&statement) > 0; return contains_return_.count(&statement) > 0;
} }
/// Indicates whether a statement contains a discard statement.
/// @param statement - the statement of interest.
/// @return true if and only if the statement is, or contains, a discard statement. This is
/// determined in an intraprocedural fashion: the answer will be "false" if no discard occurs
/// inside the statement, even if the statement calls a function that may lead to a discard
/// being performed.
bool ContainsIntraproceduralDiscard(const ast::Statement& statement) const {
return contains_intraprocedural_discard_.count(&statement) > 0;
}
private: private:
std::unordered_set<const ast::Statement*> contains_break_for_innermost_loop_; std::unordered_set<const ast::Statement*> contains_break_for_innermost_loop_;
std::unordered_set<const ast::Statement*> contains_return_; std::unordered_set<const ast::Statement*> contains_return_;
std::unordered_set<const ast::Statement*> contains_intraprocedural_discard_;
}; };
} // namespace tint::fuzzers::ast_fuzzer } // namespace tint::fuzzers::ast_fuzzer

View File

@ -200,93 +200,6 @@ fn main() {
} }
} }
TEST(JumpTrackerTest, Discards) {
std::string content = R"(
fn main() {
var x : u32;
for (var i : i32 = 0; i < 100; i++) {
if (i == 40) {
{
discard;
}
}
for (var j : i32 = 0; j < 10; j++) {
loop {
if (i > j) {
discard;
}
continuing {
i++;
j-=2;
}
}
switch (j) {
case 0: {
if (i == j) {
break;
}
i = i + 1;
continue;
}
default: {
discard;
}
}
}
}
}
)";
Source::File file("test.wgsl", content);
auto program = reader::wgsl::Parse(&file);
ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str();
JumpTracker jump_tracker(program);
const auto* function_body = program.AST().Functions()[0]->body;
const auto* outer_loop = function_body->statements[1]->As<ast::ForLoopStatement>();
const auto* outer_loop_body = outer_loop->body;
const auto* first_if = outer_loop_body->statements[0]->As<ast::IfStatement>();
const auto* first_if_body = first_if->body;
const auto* block_in_first_if = first_if_body->statements[0]->As<ast::BlockStatement>();
const auto* discard_in_first_if = block_in_first_if->statements[0]->As<ast::DiscardStatement>();
const auto* inner_for_loop = outer_loop_body->statements[1]->As<ast::ForLoopStatement>();
const auto* inner_for_loop_body = inner_for_loop->body;
const auto* innermost_loop = inner_for_loop_body->statements[0]->As<ast::LoopStatement>();
const auto* innermost_loop_body = innermost_loop->body;
const auto* innermost_loop_if = innermost_loop_body->statements[0]->As<ast::IfStatement>();
const auto* innermost_loop_if_body = innermost_loop_if->body;
const auto* discard_in_innermost_loop =
innermost_loop_if_body->statements[0]->As<ast::DiscardStatement>();
const auto* switch_statement = inner_for_loop_body->statements[1]->As<ast::SwitchStatement>();
const auto* default_statement = switch_statement->body[1];
const auto* default_statement_body = default_statement->body;
const auto* discard_in_default_statement =
default_statement_body->statements[0]->As<ast::DiscardStatement>();
std::unordered_set<const ast::Statement*> containing_discard = {
function_body, outer_loop,
outer_loop_body, first_if,
first_if_body, block_in_first_if,
discard_in_first_if, inner_for_loop,
inner_for_loop_body, innermost_loop,
innermost_loop_body, innermost_loop_if,
innermost_loop_if_body, discard_in_innermost_loop,
switch_statement, default_statement,
default_statement_body, discard_in_default_statement};
for (auto* node : program.ASTNodes().Objects()) {
auto* stmt = node->As<ast::Statement>();
if (stmt == nullptr) {
continue;
}
if (containing_discard.count(stmt) > 0) {
ASSERT_TRUE(jump_tracker.ContainsIntraproceduralDiscard(*stmt));
} else {
ASSERT_FALSE(jump_tracker.ContainsIntraproceduralDiscard(*stmt));
}
}
}
TEST(JumpTrackerTest, WhileLoop) { TEST(JumpTrackerTest, WhileLoop) {
std::string content = R"( std::string content = R"(
fn main() { fn main() {

View File

@ -135,10 +135,9 @@ bool MutationDeleteStatement::CanBeDeleted(const ast::Statement& statement_node,
return false; return false;
} }
if (jump_tracker.ContainsReturn(statement_node) || if (jump_tracker.ContainsReturn(statement_node)) {
jump_tracker.ContainsIntraproceduralDiscard(statement_node)) { // This is conservative. It would be possible to delete a return statement as long as there
// This is conservative. It would be possible to delete a return/discard statement as long // is still a return on every control flow path.
// as there is still a return/discard on every control flow path.
return false; return false;
} }

View File

@ -606,48 +606,6 @@ fn foo() -> i32 {
CheckStatementDeletionNotAllowed(original, statement_finder); CheckStatementDeletionNotAllowed(original, statement_finder);
} }
TEST(DeleteStatementTest, DoNotRemoveDiscard) {
auto original = R"(
fn main() {
discard;
})";
auto statement_finder = [](const Program& program) -> const ast::Statement* {
return program.AST().Functions()[0]->body->statements[0]->As<ast::DiscardStatement>();
};
CheckStatementDeletionNotAllowed(original, statement_finder);
}
TEST(DeleteStatementTest, DoNotRemoveStatementContainingDiscard) {
auto original = R"(
fn foo() -> i32 {
if (true) {
discard;
} else {
discard;
}
})";
auto statement_finder = [](const Program& program) -> const ast::Statement* {
return program.AST().Functions()[0]->body->statements[0]->As<ast::IfStatement>();
};
CheckStatementDeletionNotAllowed(original, statement_finder);
}
TEST(DeleteStatementTest, DoNotRemoveLoopBody) {
auto original = R"(
fn foo() {
discard;
}
fn main() {
loop {
foo();
}
})";
auto statement_finder = [](const Program& program) -> const ast::Statement* {
return program.AST().Functions()[1]->body->statements[0]->As<ast::LoopStatement>()->body;
};
CheckStatementDeletionNotAllowed(original, statement_finder);
}
TEST(DeleteStatementTest, DoNotRemoveForLoopBody) { TEST(DeleteStatementTest, DoNotRemoveForLoopBody) {
auto original = R"( auto original = R"(
fn main() { fn main() {

View File

@ -161,7 +161,7 @@ TEST_F(ResolverFunctionValidationTest, UnreachableCode_return_InBlocks) {
EXPECT_FALSE(Sem().Get(assign_a)->IsReachable()); EXPECT_FALSE(Sem().Get(assign_a)->IsReachable());
} }
TEST_F(ResolverFunctionValidationTest, UnreachableCode_discard) { TEST_F(ResolverFunctionValidationTest, UnreachableCode_discard_nowarning) {
// fn func() -> { // fn func() -> {
// var a : i32; // var a : i32;
// discard; // discard;
@ -175,38 +175,17 @@ TEST_F(ResolverFunctionValidationTest, UnreachableCode_discard) {
Func("func", utils::Empty, ty.void_(), utils::Vector{decl_a, discard, assign_a}); Func("func", utils::Empty, ty.void_(), utils::Vector{decl_a, discard, assign_a});
ASSERT_TRUE(r()->Resolve()); ASSERT_TRUE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 warning: code is unreachable");
EXPECT_TRUE(Sem().Get(decl_a)->IsReachable()); EXPECT_TRUE(Sem().Get(decl_a)->IsReachable());
EXPECT_TRUE(Sem().Get(discard)->IsReachable()); EXPECT_TRUE(Sem().Get(discard)->IsReachable());
EXPECT_FALSE(Sem().Get(assign_a)->IsReachable()); EXPECT_TRUE(Sem().Get(assign_a)->IsReachable());
}
TEST_F(ResolverFunctionValidationTest, UnreachableCode_discard_InBlocks) {
// fn func() -> {
// var a : i32;
// {{{discard;}}}
// a = 2i;
//}
auto* decl_a = Decl(Var("a", ty.i32()));
auto* discard = Discard();
auto* assign_a = Assign(Source{{12, 34}}, "a", 2_i);
Func("func", utils::Empty, ty.void_(),
utils::Vector{decl_a, Block(Block(Block(discard))), assign_a});
ASSERT_TRUE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 warning: code is unreachable");
EXPECT_TRUE(Sem().Get(decl_a)->IsReachable());
EXPECT_TRUE(Sem().Get(discard)->IsReachable());
EXPECT_FALSE(Sem().Get(assign_a)->IsReachable());
} }
TEST_F(ResolverFunctionValidationTest, DiscardCalledDirectlyFromVertexEntryPoint) { TEST_F(ResolverFunctionValidationTest, DiscardCalledDirectlyFromVertexEntryPoint) {
// @vertex() fn func() -> @position(0) vec4<f32> { discard; } // @vertex() fn func() -> @position(0) vec4<f32> { discard; return; }
Func(Source{{1, 2}}, "func", utils::Empty, ty.vec4<f32>(), Func(Source{{1, 2}}, "func", utils::Empty, ty.vec4<f32>(),
utils::Vector{ utils::Vector{
Discard(Source{{12, 34}}), Discard(Source{{12, 34}}),
Return(Construct(ty.vec4<f32>())),
}, },
utils::Vector{Stage(ast::PipelineStage::kVertex)}, utils::Vector{Stage(ast::PipelineStage::kVertex)},
utils::Vector{Builtin(ast::BuiltinValue::kPosition)}); utils::Vector{Builtin(ast::BuiltinValue::kPosition)});

View File

@ -3295,10 +3295,8 @@ sem::Statement* Resolver::DiscardStatement(const ast::DiscardStatement* stmt) {
auto* sem = auto* sem =
builder_->create<sem::Statement>(stmt, current_compound_statement_, current_function_); builder_->create<sem::Statement>(stmt, current_compound_statement_, current_function_);
return StatementScope(stmt, sem, [&] { return StatementScope(stmt, sem, [&] {
sem->Behaviors() = sem::Behavior::kDiscard;
current_function_->SetDiscardStatement(sem); current_function_->SetDiscardStatement(sem);
return true;
return validator_.DiscardStatement(sem, current_statement_);
}); });
} }

View File

@ -30,10 +30,11 @@ namespace {
class ResolverBehaviorTest : public ResolverTest { class ResolverBehaviorTest : public ResolverTest {
protected: protected:
void SetUp() override { void SetUp() override {
// Create a function called 'DiscardOrNext' which returns an i32, and has // Create a function called 'Next' which returns an i32, and has the behavior of {Return},
// the behavior of {Discard, Return}, which when called, will have the // which when called, will have the behavior {Next}.
// behavior {Discard, Next}. // It contains a discard statement, which should not affect the behavior analysis or any
Func("DiscardOrNext", utils::Empty, ty.i32(), // related validation.
Func("Next", utils::Empty, ty.i32(),
utils::Vector{ utils::Vector{
If(true, Block(Discard())), If(true, Block(Discard())),
Return(1_i), Return(1_i),
@ -42,7 +43,7 @@ class ResolverBehaviorTest : public ResolverTest {
}; };
TEST_F(ResolverBehaviorTest, ExprBinaryOp_LHS) { TEST_F(ResolverBehaviorTest, ExprBinaryOp_LHS) {
auto* stmt = Decl(Var("lhs", ty.i32(), Add(Call("DiscardOrNext"), 1_i))); auto* stmt = Decl(Var("lhs", ty.i32(), Add(Call("Next"), 1_i)));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -50,11 +51,11 @@ TEST_F(ResolverBehaviorTest, ExprBinaryOp_LHS) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, ExprBinaryOp_RHS) { TEST_F(ResolverBehaviorTest, ExprBinaryOp_RHS) {
auto* stmt = Decl(Var("lhs", ty.i32(), Add(1_i, Call("DiscardOrNext")))); auto* stmt = Decl(Var("lhs", ty.i32(), Add(1_i, Call("Next"))));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -62,11 +63,11 @@ TEST_F(ResolverBehaviorTest, ExprBinaryOp_RHS) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, ExprBitcastOp) { TEST_F(ResolverBehaviorTest, ExprBitcastOp) {
auto* stmt = Decl(Var("lhs", ty.u32(), Bitcast<u32>(Call("DiscardOrNext")))); auto* stmt = Decl(Var("lhs", ty.u32(), Bitcast<u32>(Call("Next"))));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -74,7 +75,7 @@ TEST_F(ResolverBehaviorTest, ExprBitcastOp) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, ExprIndex_Arr) { TEST_F(ResolverBehaviorTest, ExprIndex_Arr) {
@ -92,11 +93,11 @@ TEST_F(ResolverBehaviorTest, ExprIndex_Arr) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, ExprIndex_Idx) { TEST_F(ResolverBehaviorTest, ExprIndex_Idx) {
auto* stmt = Decl(Var("lhs", ty.i32(), IndexAccessor("arr", Call("DiscardOrNext")))); auto* stmt = Decl(Var("lhs", ty.i32(), IndexAccessor("arr", Call("Next"))));
Func("F", utils::Empty, ty.void_(), Func("F", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -108,13 +109,12 @@ TEST_F(ResolverBehaviorTest, ExprIndex_Idx) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, ExprUnaryOp) { TEST_F(ResolverBehaviorTest, ExprUnaryOp) {
auto* stmt = auto* stmt = Decl(Var("lhs", ty.i32(),
Decl(Var("lhs", ty.i32(), create<ast::UnaryOpExpression>(ast::UnaryOp::kComplement, Call("Next"))));
create<ast::UnaryOpExpression>(ast::UnaryOp::kComplement, Call("DiscardOrNext"))));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -122,7 +122,7 @@ TEST_F(ResolverBehaviorTest, ExprUnaryOp) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtAssign) { TEST_F(ResolverBehaviorTest, StmtAssign) {
@ -138,7 +138,7 @@ TEST_F(ResolverBehaviorTest, StmtAssign) {
} }
TEST_F(ResolverBehaviorTest, StmtAssign_LHSDiscardOrNext) { TEST_F(ResolverBehaviorTest, StmtAssign_LHSDiscardOrNext) {
auto* stmt = Assign(IndexAccessor("lhs", Call("DiscardOrNext")), 1_i); auto* stmt = Assign(IndexAccessor("lhs", Call("Next")), 1_i);
Func("F", utils::Empty, ty.void_(), Func("F", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -150,11 +150,11 @@ TEST_F(ResolverBehaviorTest, StmtAssign_LHSDiscardOrNext) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtAssign_RHSDiscardOrNext) { TEST_F(ResolverBehaviorTest, StmtAssign_RHSDiscardOrNext) {
auto* stmt = Assign("lhs", Call("DiscardOrNext")); auto* stmt = Assign("lhs", Call("Next"));
Func("F", utils::Empty, ty.void_(), Func("F", utils::Empty, ty.void_(),
utils::Vector{ utils::Vector{
@ -166,7 +166,7 @@ TEST_F(ResolverBehaviorTest, StmtAssign_RHSDiscardOrNext) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtBlockEmpty) { TEST_F(ResolverBehaviorTest, StmtBlockEmpty) {
@ -180,7 +180,7 @@ TEST_F(ResolverBehaviorTest, StmtBlockEmpty) {
} }
TEST_F(ResolverBehaviorTest, StmtBlockSingleStmt) { TEST_F(ResolverBehaviorTest, StmtBlockSingleStmt) {
auto* stmt = Block(Discard()); auto* stmt = Block(Return());
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -188,7 +188,7 @@ TEST_F(ResolverBehaviorTest, StmtBlockSingleStmt) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kReturn);
} }
TEST_F(ResolverBehaviorTest, StmtCallReturn) { TEST_F(ResolverBehaviorTest, StmtCallReturn) {
@ -212,12 +212,11 @@ TEST_F(ResolverBehaviorTest, StmtCallFuncDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtCallFuncMayDiscard) { TEST_F(ResolverBehaviorTest, StmtCallFuncMayDiscard) {
auto* stmt = auto* stmt = For(Decl(Var("v", ty.i32(), Call("Next"))), nullptr, nullptr, Block(Break()));
For(Decl(Var("v", ty.i32(), Call("DiscardOrNext"))), nullptr, nullptr, Block(Break()));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -225,7 +224,7 @@ TEST_F(ResolverBehaviorTest, StmtCallFuncMayDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtBreak) { TEST_F(ResolverBehaviorTest, StmtBreak) {
@ -258,7 +257,7 @@ TEST_F(ResolverBehaviorTest, StmtDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_NoExit) { TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_NoExit) {
@ -288,7 +287,7 @@ TEST_F(ResolverBehaviorTest, StmtForLoopContinue_NoExit) {
} }
TEST_F(ResolverBehaviorTest, StmtForLoopDiscard) { TEST_F(ResolverBehaviorTest, StmtForLoopDiscard) {
auto* stmt = For(nullptr, nullptr, nullptr, Block(Discard())); auto* stmt = For(nullptr, nullptr, nullptr, Block(Discard(), Break()));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -296,7 +295,7 @@ TEST_F(ResolverBehaviorTest, StmtForLoopDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtForLoopReturn) { TEST_F(ResolverBehaviorTest, StmtForLoopReturn) {
@ -310,8 +309,7 @@ TEST_F(ResolverBehaviorTest, StmtForLoopReturn) {
} }
TEST_F(ResolverBehaviorTest, StmtForLoopBreak_InitCallFuncMayDiscard) { TEST_F(ResolverBehaviorTest, StmtForLoopBreak_InitCallFuncMayDiscard) {
auto* stmt = auto* stmt = For(Decl(Var("v", ty.i32(), Call("Next"))), nullptr, nullptr, Block(Break()));
For(Decl(Var("v", ty.i32(), Call("DiscardOrNext"))), nullptr, nullptr, Block(Break()));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -319,11 +317,11 @@ TEST_F(ResolverBehaviorTest, StmtForLoopBreak_InitCallFuncMayDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_InitCallFuncMayDiscard) { TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_InitCallFuncMayDiscard) {
auto* stmt = For(Decl(Var("v", ty.i32(), Call("DiscardOrNext"))), nullptr, nullptr, Block()); auto* stmt = For(Decl(Var("v", ty.i32(), Call("Next"))), nullptr, nullptr, Block(Break()));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -331,7 +329,7 @@ TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_InitCallFuncMayDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_CondTrue) { TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_CondTrue) {
@ -345,7 +343,7 @@ TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_CondTrue) {
} }
TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_CondCallFuncMayDiscard) { TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_CondCallFuncMayDiscard) {
auto* stmt = For(nullptr, Equal(Call("DiscardOrNext"), 1_i), nullptr, Block()); auto* stmt = For(nullptr, Equal(Call("Next"), 1_i), nullptr, Block());
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -353,7 +351,7 @@ TEST_F(ResolverBehaviorTest, StmtForLoopEmpty_CondCallFuncMayDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtWhileBreak) { TEST_F(ResolverBehaviorTest, StmtWhileBreak) {
@ -375,7 +373,7 @@ TEST_F(ResolverBehaviorTest, StmtWhileDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtWhileReturn) { TEST_F(ResolverBehaviorTest, StmtWhileReturn) {
@ -399,7 +397,7 @@ TEST_F(ResolverBehaviorTest, StmtWhileEmpty_CondTrue) {
} }
TEST_F(ResolverBehaviorTest, StmtWhileEmpty_CondCallFuncMayDiscard) { TEST_F(ResolverBehaviorTest, StmtWhileEmpty_CondCallFuncMayDiscard) {
auto* stmt = While(Equal(Call("DiscardOrNext"), 1_i), Block()); auto* stmt = While(Equal(Call("Next"), 1_i), Block());
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -407,7 +405,7 @@ TEST_F(ResolverBehaviorTest, StmtWhileEmpty_CondCallFuncMayDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock) { TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock) {
@ -429,7 +427,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseDiscard) { TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseDiscard) {
@ -441,7 +439,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenDiscard_ElseDiscard) { TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenDiscard_ElseDiscard) {
@ -453,11 +451,11 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenDiscard_ElseDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtIfCallFuncMayDiscard_ThenEmptyBlock) { TEST_F(ResolverBehaviorTest, StmtIfCallFuncMayDiscard_ThenEmptyBlock) {
auto* stmt = If(Equal(Call("DiscardOrNext"), 1_i), Block()); auto* stmt = If(Equal(Call("Next"), 1_i), Block());
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -465,12 +463,12 @@ TEST_F(ResolverBehaviorTest, StmtIfCallFuncMayDiscard_ThenEmptyBlock) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseCallFuncMayDiscard) { TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseCallFuncMayDiscard) {
auto* stmt = If(true, Block(), // auto* stmt = If(true, Block(), //
Else(If(Equal(Call("DiscardOrNext"), 1_i), Block()))); Else(If(Equal(Call("Next"), 1_i), Block())));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -478,7 +476,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseCallFuncMayDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtLetDecl) { TEST_F(ResolverBehaviorTest, StmtLetDecl) {
@ -492,7 +490,7 @@ TEST_F(ResolverBehaviorTest, StmtLetDecl) {
} }
TEST_F(ResolverBehaviorTest, StmtLetDecl_RHSDiscardOrNext) { TEST_F(ResolverBehaviorTest, StmtLetDecl_RHSDiscardOrNext) {
auto* stmt = Decl(Let("lhs", ty.i32(), Call("DiscardOrNext"))); auto* stmt = Decl(Let("lhs", ty.i32(), Call("Next")));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -500,7 +498,7 @@ TEST_F(ResolverBehaviorTest, StmtLetDecl_RHSDiscardOrNext) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtLoopEmpty_NoExit) { TEST_F(ResolverBehaviorTest, StmtLoopEmpty_NoExit) {
@ -530,7 +528,7 @@ TEST_F(ResolverBehaviorTest, StmtLoopContinue_NoExit) {
} }
TEST_F(ResolverBehaviorTest, StmtLoopDiscard) { TEST_F(ResolverBehaviorTest, StmtLoopDiscard) {
auto* stmt = Loop(Block(Discard())); auto* stmt = Loop(Block(Discard(), Break()));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -538,7 +536,7 @@ TEST_F(ResolverBehaviorTest, StmtLoopDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtLoopReturn) { TEST_F(ResolverBehaviorTest, StmtLoopReturn) {
@ -590,14 +588,14 @@ TEST_F(ResolverBehaviorTest, StmtReturn) {
} }
TEST_F(ResolverBehaviorTest, StmtReturn_DiscardOrNext) { TEST_F(ResolverBehaviorTest, StmtReturn_DiscardOrNext) {
auto* stmt = Return(Call("DiscardOrNext")); auto* stmt = Return(Call("Next"));
Func("F", utils::Empty, ty.i32(), utils::Vector{stmt}); Func("F", utils::Empty, ty.i32(), utils::Vector{stmt});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kReturn, sem::Behavior::kDiscard)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kReturn));
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondTrue_DefaultEmpty) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondTrue_DefaultEmpty) {
@ -629,7 +627,7 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_DefaultDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_DefaultReturn) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_DefaultReturn) {
@ -661,7 +659,7 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Empty_DefaultDiscard) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext, sem::Behavior::kDiscard)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Empty_DefaultReturn) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Empty_DefaultReturn) {
@ -683,7 +681,7 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultEmpty) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultDiscard) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultDiscard) {
@ -696,7 +694,7 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultDiscard)
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kDiscard); EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultReturn) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultReturn) {
@ -709,7 +707,7 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_DefaultReturn)
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kReturn)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kReturn, sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_Case1Return_DefaultEmpty) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_Case1Return_DefaultEmpty) {
@ -724,12 +722,11 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondLiteral_Case0Discard_Case1Return_Def
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext, EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext, sem::Behavior::kReturn));
sem::Behavior::kReturn));
} }
TEST_F(ResolverBehaviorTest, StmtSwitch_CondCallFuncMayDiscard_DefaultEmpty) { TEST_F(ResolverBehaviorTest, StmtSwitch_CondCallFuncMayDiscard_DefaultEmpty) {
auto* stmt = Switch(Call("DiscardOrNext"), DefaultCase(Block())); auto* stmt = Switch(Call("Next"), DefaultCase(Block()));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -737,7 +734,7 @@ TEST_F(ResolverBehaviorTest, StmtSwitch_CondCallFuncMayDiscard_DefaultEmpty) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
TEST_F(ResolverBehaviorTest, StmtVarDecl) { TEST_F(ResolverBehaviorTest, StmtVarDecl) {
@ -751,7 +748,7 @@ TEST_F(ResolverBehaviorTest, StmtVarDecl) {
} }
TEST_F(ResolverBehaviorTest, StmtVarDecl_RHSDiscardOrNext) { TEST_F(ResolverBehaviorTest, StmtVarDecl_RHSDiscardOrNext) {
auto* stmt = Decl(Var("lhs", ty.i32(), Call("DiscardOrNext"))); auto* stmt = Decl(Var("lhs", ty.i32(), Call("Next")));
Func("F", utils::Empty, ty.void_(), utils::Vector{stmt}, Func("F", utils::Empty, ty.void_(), utils::Vector{stmt},
utils::Vector{Stage(ast::PipelineStage::kFragment)}); utils::Vector{Stage(ast::PipelineStage::kFragment)});
@ -759,7 +756,7 @@ TEST_F(ResolverBehaviorTest, StmtVarDecl_RHSDiscardOrNext) {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(stmt); auto* sem = Sem().Get(stmt);
EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kDiscard, sem::Behavior::kNext)); EXPECT_EQ(sem->Behaviors(), sem::Behaviors(sem::Behavior::kNext));
} }
} // namespace } // namespace

View File

@ -736,7 +736,6 @@ enum ControlFlowInterrupt {
kBreak, kBreak,
kContinue, kContinue,
kReturn, kReturn,
kDiscard,
}; };
enum Condition { enum Condition {
kNone, kNone,
@ -754,8 +753,6 @@ static std::string ToStr(ControlFlowInterrupt interrupt) {
return "continue"; return "continue";
case kReturn: case kReturn:
return "return"; return "return";
case kDiscard:
return "discard";
} }
return ""; return "";
} }
@ -790,7 +787,7 @@ class LoopTest : public UniformityAnalysisTestBase,
INSTANTIATE_TEST_SUITE_P(UniformityAnalysisTest, INSTANTIATE_TEST_SUITE_P(UniformityAnalysisTest,
LoopTest, LoopTest,
::testing::Combine(::testing::Range<int>(0, kDiscard + 1), ::testing::Combine(::testing::Range<int>(0, kReturn + 1),
::testing::Range<int>(0, kNonUniform + 1)), ::testing::Range<int>(0, kNonUniform + 1)),
[](const ::testing::TestParamInfo<LoopTestParams>& p) { [](const ::testing::TestParamInfo<LoopTestParams>& p) {
ControlFlowInterrupt interrupt = ControlFlowInterrupt interrupt =
@ -1025,7 +1022,7 @@ class LoopDeadCodeTest : public UniformityAnalysisTestBase, public ::testing::Te
INSTANTIATE_TEST_SUITE_P(UniformityAnalysisTest, INSTANTIATE_TEST_SUITE_P(UniformityAnalysisTest,
LoopDeadCodeTest, LoopDeadCodeTest,
::testing::Range<int>(0, kDiscard + 1), ::testing::Range<int>(0, kReturn + 1),
[](const ::testing::TestParamInfo<LoopDeadCodeTest::ParamType>& p) { [](const ::testing::TestParamInfo<LoopDeadCodeTest::ParamType>& p) {
return ToStr(static_cast<ControlFlowInterrupt>(p.param)); return ToStr(static_cast<ControlFlowInterrupt>(p.param));
}); });
@ -2890,36 +2887,6 @@ test:5:7 note: reading from read_write storage buffer 'non_uniform' may result i
)"); )");
} }
TEST_F(UniformityAnalysisTest, IfElse_NonUniformDiscard_NoReconverge) {
// If statements should not reconverge after non-uniform discards.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn foo() {
if (non_uniform == 42) {
discard;
} else {
}
workgroupBarrier();
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:9:3 warning: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:5:3 note: control flow depends on non-uniform value
if (non_uniform == 42) {
^^
test:5:7 note: reading from read_write storage buffer 'non_uniform' may result in a non-uniform value
if (non_uniform == 42) {
^^^^^^^^^^^
)");
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Switch statement tests. /// Switch statement tests.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -6749,6 +6716,22 @@ fn foo() {
/// Miscellaneous statement and expression tests. /// Miscellaneous statement and expression tests.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TEST_F(UniformityAnalysisTest, NonUniformDiscard) {
// Non-uniform discard statements should not cause uniformity issues.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn foo() {
if (non_uniform == 42) {
discard;
}
_ = dpdx(1.0);
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, FunctionReconvergesOnExit) { TEST_F(UniformityAnalysisTest, FunctionReconvergesOnExit) {
// Call a function that has returns during non-uniform control flow, and test that the analysis // Call a function that has returns during non-uniform control flow, and test that the analysis
// reconverges when returning to the caller. // reconverges when returning to the caller.
@ -6775,29 +6758,6 @@ fn main() {
RunTest(src, true); RunTest(src, true);
} }
TEST_F(UniformityAnalysisTest, FunctionRequiresUniformFlowAndCausesNonUniformFlow) {
// Test that a function that requires uniform flow and then causes non-uniform flow can be
// called without error.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
fn foo() {
_ = dpdx(0.5);
if (non_uniform_global == 0) {
discard;
}
}
@fragment
fn main() {
foo();
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, TypeInitializer) { TEST_F(UniformityAnalysisTest, TypeInitializer) {
std::string src = R"( std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32; @group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@ -7031,22 +6991,6 @@ fn foo() {
RunTest(src, true); RunTest(src, true);
} }
TEST_F(UniformityAnalysisTest, DeadCode_AfterDiscard) {
// Dead code after a discard statement shouldn't cause uniformity errors.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn foo() {
discard;
if (non_uniform == 42) {
workgroupBarrier();
}
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, ArrayLength) { TEST_F(UniformityAnalysisTest, ArrayLength) {
std::string src = R"( std::string src = R"(
@group(0) @binding(0) var<storage, read_write> arr : array<f32>; @group(0) @binding(0) var<storage, read_write> arr : array<f32>;

View File

@ -766,69 +766,17 @@ TEST_F(ResolverTest, Stmt_Loop_DiscardInContinuing_Direct) {
// loop { // loop {
// continuing { // continuing {
// discard; // discard;
// breakif true;
// } // }
// } // }
WrapInFunction(Loop( // loop Func("my_func", utils::Empty, ty.void_(),
utils::Vector{Loop( // loop
Block(), // loop block Block(), // loop block
Block( // loop continuing block Block( // loop continuing block
Discard(Source{{12, 34}})))); Discard(Source{{12, 34}}), BreakIf(true)))});
EXPECT_FALSE(r()->Resolve()); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(r()->error(),
R"(12:34 error: continuing blocks must not contain a discard statement)");
}
TEST_F(ResolverTest, Stmt_Loop_DiscardInContinuing_Indirect) {
// loop {
// if (false) { break; }
// continuing {
// loop { discard; }
// }
// }
WrapInFunction(Loop( // outer loop
Block(If(false, Block(Break()))), // outer loop block
Block(Source{{56, 78}}, // outer loop continuing block
Loop( // inner loop
Block( // inner loop block
Discard(Source{{12, 34}}))))));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
R"(12:34 error: continuing blocks must not contain a discard statement
56:78 note: see continuing block here)");
}
TEST_F(ResolverTest, Stmt_Loop_DiscardInContinuing_Indirect_ViaCall) {
// fn MayDiscard() { if (true) { discard; } }
// fn F() { MayDiscard(); }
// loop {
// continuing {
// loop { F(); }
// }
// }
Func("MayDiscard", utils::Empty, ty.void_(),
utils::Vector{
If(true, Block(Discard())),
});
Func("SomeFunc", utils::Empty, ty.void_(),
utils::Vector{
CallStmt(Call("MayDiscard")),
});
WrapInFunction(Loop( // outer loop
Block(), // outer loop block
Block(Source{{56, 78}}, // outer loop continuing block
Loop( // inner loop
Block( // inner loop block
CallStmt(Call(Source{{12, 34}}, "SomeFunc")))))));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
R"(12:34 error: cannot call a function that may discard inside a continuing block
56:78 note: see continuing block here)");
} }
TEST_F(ResolverTest, Stmt_Loop_ContinueInContinuing_Direct) { TEST_F(ResolverTest, Stmt_Loop_ContinueInContinuing_Direct) {
@ -973,55 +921,11 @@ TEST_F(ResolverTest, Stmt_ForLoop_DiscardInContinuing_Direct) {
// break; // break;
// } // }
WrapInFunction(For(nullptr, nullptr, Discard(Source{{12, 34}}), // Func("my_func", utils::Empty, ty.void_(),
Block(Break()))); utils::Vector{For(nullptr, nullptr, Discard(Source{{12, 34}}), //
Block(Break()))});
EXPECT_FALSE(r()->Resolve()); EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(r()->error(),
R"(12:34 error: continuing blocks must not contain a discard statement)");
}
TEST_F(ResolverTest, Stmt_ForLoop_DiscardInContinuing_Indirect) {
// for(;; loop { discard }) {
// break;
// }
WrapInFunction(For(nullptr, nullptr,
Loop(Source{{56, 78}}, //
Block(Discard(Source{{12, 34}}))), //
Block(Break())));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
R"(12:34 error: continuing blocks must not contain a discard statement
56:78 note: see continuing block here)");
}
TEST_F(ResolverTest, Stmt_ForLoop_DiscardInContinuing_Indirect_ViaCall) {
// fn MayDiscard() { if (true) { discard; } }
// fn F() { MayDiscard(); }
// for(;; loop { F() }) {
// break;
// }
Func("MayDiscard", utils::Empty, ty.void_(),
utils::Vector{
If(true, Block(Discard())),
});
Func("F", utils::Empty, ty.void_(),
utils::Vector{
CallStmt(Call("MayDiscard")),
});
WrapInFunction(For(nullptr, nullptr,
Loop(Source{{56, 78}}, //
Block(CallStmt(Call(Source{{12, 34}}, "F")))), //
Block(Break())));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
R"(12:34 error: cannot call a function that may discard inside a continuing block
56:78 note: see continuing block here)");
} }
TEST_F(ResolverTest, Stmt_ForLoop_ContinueInContinuing_Direct) { TEST_F(ResolverTest, Stmt_ForLoop_ContinueInContinuing_Direct) {

View File

@ -1076,12 +1076,8 @@ bool Validator::Function(const sem::Function* func, ast::PipelineStage stage) co
} }
// https://www.w3.org/TR/WGSL/#behaviors-rules // https://www.w3.org/TR/WGSL/#behaviors-rules
// a function behavior is always one of {}, {Next}, {Discard}, or // a function behavior is always one of {}, or {Next}.
// {Next, Discard}. if (func->Behaviors() != sem::Behaviors{} && func->Behaviors() != sem::Behavior::kNext) {
if (func->Behaviors() != sem::Behaviors{} && // NOLINT: bad warning
func->Behaviors() != sem::Behavior::kNext && func->Behaviors() != sem::Behavior::kDiscard &&
func->Behaviors() != sem::Behaviors{sem::Behavior::kNext, //
sem::Behavior::kDiscard}) {
auto name = symbols_.NameFor(decl->symbol); auto name = symbols_.NameFor(decl->symbol);
TINT_ICE(Resolver, diagnostics_) TINT_ICE(Resolver, diagnostics_)
<< "function '" << name << "' behaviors are: " << func->Behaviors(); << "function '" << name << "' behaviors are: " << func->Behaviors();
@ -1544,19 +1540,6 @@ bool Validator::Call(const sem::Call* call, sem::Statement* current_statement) c
return true; return true;
} }
bool Validator::DiscardStatement(const sem::Statement* stmt,
sem::Statement* current_statement) const {
if (auto* continuing = ClosestContinuing(/*stop_at_loop*/ false, current_statement)) {
AddError("continuing blocks must not contain a discard statement",
stmt->Declaration()->source);
if (continuing != stmt->Declaration() && continuing != stmt->Parent()->Declaration()) {
AddNote("see continuing block here", continuing->source);
}
return false;
}
return true;
}
bool Validator::FallthroughStatement(const sem::Statement* stmt) const { bool Validator::FallthroughStatement(const sem::Statement* stmt) const {
if (auto* block = As<sem::BlockStatement>(stmt->Parent())) { if (auto* block = As<sem::BlockStatement>(stmt->Parent())) {
if (auto* c = As<sem::CaseStatement>(block->Parent())) { if (auto* c = As<sem::CaseStatement>(block->Parent())) {
@ -1843,18 +1826,6 @@ bool Validator::FunctionCall(const sem::Call* call, sem::Statement* current_stat
} }
} }
if (call->Behaviors().Contains(sem::Behavior::kDiscard)) {
if (auto* continuing = ClosestContinuing(/*stop_at_loop*/ false, current_statement)) {
AddError("cannot call a function that may discard inside a continuing block",
call->Declaration()->source);
if (continuing != call->Stmt()->Declaration() &&
continuing != call->Stmt()->Parent()->Declaration()) {
AddNote("see continuing block here", continuing->source);
}
return false;
}
}
return true; return true;
} }

View File

@ -199,12 +199,6 @@ class Validator {
/// @returns true on success, false otherwise /// @returns true on success, false otherwise
bool Call(const sem::Call* call, sem::Statement* current_statement) const; bool Call(const sem::Call* call, sem::Statement* current_statement) const;
/// Validates a discard statement
/// @param stmt the statement to validate
/// @param current_statement the current statement being resolved
/// @returns true on success, false otherwise
bool DiscardStatement(const sem::Statement* stmt, sem::Statement* current_statement) const;
/// Validates an entry point /// Validates an entry point
/// @param func the entry point function to validate /// @param func the entry point function to validate
/// @param stage the pipeline stage for the entry point /// @param stage the pipeline stage for the entry point

View File

@ -20,8 +20,6 @@ std::ostream& operator<<(std::ostream& out, Behavior behavior) {
switch (behavior) { switch (behavior) {
case Behavior::kReturn: case Behavior::kReturn:
return out << "Return"; return out << "Return";
case Behavior::kDiscard:
return out << "Discard";
case Behavior::kBreak: case Behavior::kBreak:
return out << "Break"; return out << "Break";
case Behavior::kContinue: case Behavior::kContinue:

View File

@ -23,7 +23,6 @@ namespace tint::sem {
/// @see https://www.w3.org/TR/WGSL/#behaviors /// @see https://www.w3.org/TR/WGSL/#behaviors
enum class Behavior { enum class Behavior {
kReturn, kReturn,
kDiscard,
kBreak, kBreak,
kContinue, kContinue,
kFallthrough, kFallthrough,

View File

@ -25,6 +25,10 @@ namespace tint::transform {
/// program to ensure that discarding the fragment does not affect uniformity with respect to /// program to ensure that discarding the fragment does not affect uniformity with respect to
/// derivative operations. We do this by setting a global flag and masking all writes to storage /// derivative operations. We do this by setting a global flag and masking all writes to storage
/// buffers and textures. /// buffers and textures.
///
/// @note Depends on the following transforms to have been run first:
/// * PromoteSideEffectsToDecl
/// * ExpandCompoundAssignment
class DemoteToHelper final : public Castable<DemoteToHelper, Transform> { class DemoteToHelper final : public Castable<DemoteToHelper, Transform> {
public: public:
/// Constructor /// Constructor

View File

@ -76,7 +76,7 @@ TEST_F(ForLoopToLoopTest, Body) {
auto* src = R"( auto* src = R"(
fn f() { fn f() {
for (;;) { for (;;) {
discard; return;
} }
} }
)"; )";
@ -84,7 +84,7 @@ fn f() {
auto* expect = R"( auto* expect = R"(
fn f() { fn f() {
loop { loop {
discard; return;
} }
} }
)"; )";

View File

@ -113,187 +113,23 @@ fn f() {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
// Discard has "demote-to-helper" semantics, and so code following a discard statement is not
// considered unreachable.
TEST_F(RemoveUnreachableStatementsTest, Discard) { TEST_F(RemoveUnreachableStatementsTest, Discard) {
auto* src = R"( auto* src = R"(
fn f() { fn f() {
discard; discard;
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn f() {
discard;
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, NestedDiscard) {
auto* src = R"(
fn f() {
{
{
discard;
}
}
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn f() {
{
{
discard;
}
}
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, CallToFuncWithDiscard) {
auto* src = R"(
fn DISCARD() {
discard;
}
fn f() {
DISCARD();
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn DISCARD() {
discard;
}
fn f() {
DISCARD();
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, CallToFuncWithIfDiscard) {
auto* src = R"(
fn DISCARD() {
if (true) {
discard;
}
}
fn f() {
DISCARD();
var preserve_me = 1; var preserve_me = 1;
if (true) {
var preserve_me_too = 1;
}
}
)";
auto* expect = src;
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, IfDiscardElseDiscard) {
auto* src = R"(
fn f() {
if (true) {
discard;
} else {
discard;
}
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
} }
)"; )";
auto* expect = R"( auto* expect = R"(
fn f() { fn f() {
if (true) {
discard; discard;
} else {
discard;
}
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, IfDiscardElseReturn) {
auto* src = R"(
fn f() {
if (true) {
discard;
} else {
return;
}
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn f() {
if (true) {
discard;
} else {
return;
}
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, IfDiscard) {
auto* src = R"(
fn f() {
if (true) {
discard;
}
var preserve_me = 1; var preserve_me = 1;
if (true) {
var preserve_me_too = 1;
}
} }
)"; )";
auto* expect = src;
auto got = Run<RemoveUnreachableStatements>(src); auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
@ -319,27 +155,6 @@ fn f() {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
TEST_F(RemoveUnreachableStatementsTest, IfElseDiscard) {
auto* src = R"(
fn f() {
if (true) {
} else {
discard;
}
var preserve_me = 1;
if (true) {
var preserve_me_too = 1;
}
}
)";
auto* expect = src;
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, IfElseReturn) { TEST_F(RemoveUnreachableStatementsTest, IfElseReturn) {
auto* src = R"( auto* src = R"(
fn f() { fn f() {
@ -361,42 +176,6 @@ fn f() {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
TEST_F(RemoveUnreachableStatementsTest, LoopWithDiscard) {
auto* src = R"(
fn f() {
loop {
var a = 1;
discard;
continuing {
var b = 2;
}
}
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn f() {
loop {
var a = 1;
discard;
continuing {
var b = 2;
}
}
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, LoopWithConditionalBreak) { TEST_F(RemoveUnreachableStatementsTest, LoopWithConditionalBreak) {
auto* src = R"( auto* src = R"(
fn f() { fn f() {
@ -449,97 +228,6 @@ fn f() {
EXPECT_EQ(expect, str(got)); EXPECT_EQ(expect, str(got));
} }
TEST_F(RemoveUnreachableStatementsTest, SwitchDefaultDiscard) {
auto* src = R"(
fn f() {
switch(1) {
default: {
discard;
}
}
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn f() {
switch(1) {
default: {
discard;
}
}
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, SwitchCaseReturnDefaultDiscard) {
auto* src = R"(
fn f() {
switch(1) {
case 0: {
return;
}
default: {
discard;
}
}
var remove_me = 1;
if (true) {
var remove_me_too = 1;
}
}
)";
auto* expect = R"(
fn f() {
switch(1) {
case 0: {
return;
}
default: {
discard;
}
}
}
)";
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, SwitchCaseBreakDefaultDiscard) {
auto* src = R"(
fn f() {
switch(1) {
case 0: {
break;
}
default: {
discard;
}
}
var preserve_me = 1;
if (true) {
var preserve_me_too = 1;
}
}
)";
auto* expect = src;
auto got = Run<RemoveUnreachableStatements>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RemoveUnreachableStatementsTest, SwitchCaseReturnDefaultBreak) { TEST_F(RemoveUnreachableStatementsTest, SwitchCaseReturnDefaultBreak) {
auto* src = R"( auto* src = R"(
fn f() { fn f() {

View File

@ -1,374 +0,0 @@
// Copyright 2022 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 "src/tint/transform/unwind_discard_functions.h"
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "src/tint/ast/discard_statement.h"
#include "src/tint/ast/return_statement.h"
#include "src/tint/ast/traverse_expressions.h"
#include "src/tint/sem/block_statement.h"
#include "src/tint/sem/call.h"
#include "src/tint/sem/for_loop_statement.h"
#include "src/tint/sem/function.h"
#include "src/tint/sem/if_statement.h"
#include "src/tint/transform/utils/get_insertion_point.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::UnwindDiscardFunctions);
namespace tint::transform {
namespace {
bool ShouldRun(const Program* program) {
auto& sem = program->Sem();
for (auto* f : program->AST().Functions()) {
if (sem.Get(f)->Behaviors().Contains(sem::Behavior::kDiscard)) {
return true;
}
}
return false;
}
} // namespace
/// PIMPL state for the transform
struct UnwindDiscardFunctions::State {
/// Constructor
/// @param ctx_in the context
explicit State(CloneContext& ctx_in) : ctx(ctx_in), b(*ctx_in.dst), sem(ctx_in.src->Sem()) {}
/// Runs the transform
void Run() {
ctx.ReplaceAll([&](const ast::BlockStatement* block) -> const ast::Statement* {
// Iterate block statements and replace them as needed.
for (auto* stmt : block->statements) {
if (auto* new_stmt = Statement(stmt)) {
ctx.Replace(stmt, new_stmt);
}
// Handle for loops, as they are the only other AST node that
// contains statements outside of BlockStatements.
if (auto* fl = stmt->As<ast::ForLoopStatement>()) {
if (auto* new_stmt = Statement(fl->initializer)) {
ctx.Replace(fl->initializer, new_stmt);
}
if (auto* new_stmt = Statement(fl->continuing)) {
// NOTE: Should never reach here as we cannot discard in a
// continuing block.
ctx.Replace(fl->continuing, new_stmt);
}
}
}
return nullptr;
});
}
private:
CloneContext& ctx;
ProgramBuilder& b;
const sem::Info& sem;
Symbol module_discard_var_name; // Use ModuleDiscardVarName() to read
Symbol module_discard_func_name; // Use ModuleDiscardFuncName() to read
// Returns true if `sem_expr` contains a call expression that may
// (transitively) execute a discard statement.
bool MayDiscard(const sem::Expression* sem_expr) {
return sem_expr && sem_expr->Behaviors().Contains(sem::Behavior::kDiscard);
}
// Lazily creates and returns the name of the module bool variable for whether
// to discard: "tint_discard".
Symbol ModuleDiscardVarName() {
if (!module_discard_var_name.IsValid()) {
module_discard_var_name = b.Symbols().New("tint_discard");
ctx.dst->GlobalVar(module_discard_var_name, b.ty.bool_(), b.Expr(false),
ast::AddressSpace::kPrivate);
}
return module_discard_var_name;
}
// Lazily creates and returns the name of the function that contains a single
// discard statement: "tint_discard_func".
// We do this to avoid having multiple discard statements in a single program,
// which causes problems in certain backends (see crbug.com/1118).
Symbol ModuleDiscardFuncName() {
if (!module_discard_func_name.IsValid()) {
module_discard_func_name = b.Symbols().New("tint_discard_func");
b.Func(module_discard_func_name, tint::utils::Empty, b.ty.void_(),
tint::utils::Vector{b.Discard()});
}
return module_discard_func_name;
}
// Creates "return <default return value>;" based on the return type of
// `stmt`'s owning function.
const ast::ReturnStatement* Return(const ast::Statement* stmt) {
const ast::Expression* ret_val = nullptr;
auto* ret_type = sem.Get(stmt)->Function()->Declaration()->return_type;
if (!ret_type->Is<ast::Void>()) {
ret_val = b.Construct(ctx.Clone(ret_type));
}
return b.Return(ret_val);
}
// Returns true if the function `stmt` is in is an entry point
bool IsInEntryPointFunc(const ast::Statement* stmt) {
return sem.Get(stmt)->Function()->Declaration()->IsEntryPoint();
}
// Creates "tint_discard_func();"
const ast::CallStatement* CallDiscardFunc() {
auto func_name = ModuleDiscardFuncName();
return b.CallStmt(b.Call(func_name));
}
// Creates and returns a new if-statement of the form:
//
// if (tint_discard) {
// return <default value>;
// }
//
// or if `stmt` is in a entry point function:
//
// if (tint_discard) {
// tint_discard_func();
// return <default value>;
// }
//
const ast::IfStatement* IfDiscardReturn(const ast::Statement* stmt) {
tint::utils::Vector<const ast::Statement*, 2> stmts;
// For entry point functions, also emit the discard statement
if (IsInEntryPointFunc(stmt)) {
stmts.Push(CallDiscardFunc());
}
stmts.Push(Return(stmt));
auto var_name = ModuleDiscardVarName();
return b.If(var_name, b.Block(stmts));
}
// Hoists `sem_expr` to a let followed by an `IfDiscardReturn` before `stmt`.
// For example, if `stmt` is:
//
// return f();
//
// This function will transform this to:
//
// let t1 = f();
// if (tint_discard) {
// return;
// }
// return t1;
//
const ast::Statement* HoistAndInsertBefore(const ast::Statement* stmt,
const sem::Expression* sem_expr) {
auto* expr = sem_expr->Declaration();
auto ip = utils::GetInsertionPoint(ctx, stmt);
auto var_name = b.Sym();
auto* decl = b.Decl(b.Var(var_name, ctx.Clone(expr)));
ctx.InsertBefore(ip.first->Declaration()->statements, ip.second, decl);
ctx.InsertBefore(ip.first->Declaration()->statements, ip.second, IfDiscardReturn(stmt));
auto* var_expr = b.Expr(var_name);
// Special handling for CallStatement as we can only replace its expression
// with a CallExpression.
if (stmt->Is<ast::CallStatement>()) {
// We could replace the call statement with no statement, but we can't do
// that with transforms (yet), so just return a phony assignment.
return b.Assign(b.Phony(), var_expr);
}
ctx.Replace(expr, var_expr);
return ctx.CloneWithoutTransform(stmt);
}
// Returns true if `stmt` is a for-loop initializer statement.
bool IsForLoopInitStatement(const ast::Statement* stmt) {
if (auto* sem_stmt = sem.Get(stmt)) {
if (auto* sem_fl = tint::As<sem::ForLoopStatement>(sem_stmt->Parent())) {
return sem_fl->Declaration()->initializer == stmt;
}
}
return false;
}
// Inserts an `IfDiscardReturn` after `stmt` if possible (i.e. `stmt` is not
// in a for-loop init), otherwise falls back to HoistAndInsertBefore, hoisting
// `sem_expr` to a let followed by an `IfDiscardReturn` before `stmt`.
//
// For example, if `stmt` is:
//
// let r = f();
//
// This function will transform this to:
//
// let r = f();
// if (tint_discard) {
// return;
// }
const ast::Statement* TryInsertAfter(const ast::Statement* stmt,
const sem::Expression* sem_expr) {
// If `stmt` is the init of a for-loop, hoist and insert before instead.
if (IsForLoopInitStatement(stmt)) {
return HoistAndInsertBefore(stmt, sem_expr);
}
auto ip = utils::GetInsertionPoint(ctx, stmt);
ctx.InsertAfter(ip.first->Declaration()->statements, ip.second, IfDiscardReturn(stmt));
return nullptr; // Don't replace current statement
}
// Replaces the input discard statement with either setting the module level
// discard bool ("tint_discard = true"), or calling the discard function
// ("tint_discard_func()"), followed by a default return statement.
//
// Replaces "discard;" with:
//
// tint_discard = true;
// return;
//
// Or if `stmt` is a entry point function, replaces with:
//
// tint_discard_func();
// return;
//
const ast::Statement* ReplaceDiscardStatement(const ast::DiscardStatement* stmt) {
const ast::Statement* to_insert = nullptr;
if (IsInEntryPointFunc(stmt)) {
to_insert = CallDiscardFunc();
} else {
auto var_name = ModuleDiscardVarName();
to_insert = b.Assign(var_name, true);
}
auto ip = utils::GetInsertionPoint(ctx, stmt);
ctx.InsertBefore(ip.first->Declaration()->statements, ip.second, to_insert);
return Return(stmt);
}
// Handle statement
const ast::Statement* Statement(const ast::Statement* stmt) {
return Switch(
stmt,
[&](const ast::DiscardStatement* s) -> const ast::Statement* {
return ReplaceDiscardStatement(s);
},
[&](const ast::AssignmentStatement* s) -> const ast::Statement* {
auto* sem_lhs = sem.Get(s->lhs);
auto* sem_rhs = sem.Get(s->rhs);
if (MayDiscard(sem_lhs)) {
if (MayDiscard(sem_rhs)) {
TINT_ICE(Transform, b.Diagnostics())
<< "Unexpected: both sides of assignment statement may "
"discard. Make sure transform::PromoteSideEffectsToDecl "
"was run first.";
}
return TryInsertAfter(s, sem_lhs);
} else if (MayDiscard(sem_rhs)) {
return TryInsertAfter(s, sem_rhs);
}
return nullptr;
},
[&](const ast::CallStatement* s) -> const ast::Statement* {
auto* sem_expr = sem.Get(s->expr);
if (!MayDiscard(sem_expr)) {
return nullptr;
}
return TryInsertAfter(s, sem_expr);
},
[&](const ast::ForLoopStatement* s) -> const ast::Statement* {
if (MayDiscard(sem.Get(s->condition))) {
TINT_ICE(Transform, b.Diagnostics())
<< "Unexpected ForLoopStatement condition that may discard. "
"Make sure transform::PromoteSideEffectsToDecl was run "
"first.";
}
return nullptr;
},
[&](const ast::WhileStatement* s) -> const ast::Statement* {
if (MayDiscard(sem.Get(s->condition))) {
TINT_ICE(Transform, b.Diagnostics())
<< "Unexpected WhileStatement condition that may discard. "
"Make sure transform::PromoteSideEffectsToDecl was run "
"first.";
}
return nullptr;
},
[&](const ast::IfStatement* s) -> const ast::Statement* {
auto* sem_expr = sem.Get(s->condition);
if (!MayDiscard(sem_expr)) {
return nullptr;
}
return HoistAndInsertBefore(s, sem_expr);
},
[&](const ast::ReturnStatement* s) -> const ast::Statement* {
auto* sem_expr = sem.Get(s->value);
if (!MayDiscard(sem_expr)) {
return nullptr;
}
return HoistAndInsertBefore(s, sem_expr);
},
[&](const ast::SwitchStatement* s) -> const ast::Statement* {
auto* sem_expr = sem.Get(s->condition);
if (!MayDiscard(sem_expr)) {
return nullptr;
}
return HoistAndInsertBefore(s, sem_expr);
},
[&](const ast::VariableDeclStatement* s) -> const ast::Statement* {
auto* var = s->variable;
if (!var->initializer) {
return nullptr;
}
auto* sem_expr = sem.Get(var->initializer);
if (!MayDiscard(sem_expr)) {
return nullptr;
}
return TryInsertAfter(s, sem_expr);
});
}
};
UnwindDiscardFunctions::UnwindDiscardFunctions() = default;
UnwindDiscardFunctions::~UnwindDiscardFunctions() = default;
Transform::ApplyResult UnwindDiscardFunctions::Apply(const Program* src,
const DataMap&,
DataMap&) const {
if (!ShouldRun(src)) {
return SkipTransform;
}
ProgramBuilder b;
CloneContext ctx{&b, src, /* auto_clone_symbols */ true};
State state(ctx);
state.Run();
ctx.Clone();
return Program(std::move(b));
}
} // namespace tint::transform

View File

@ -1,58 +0,0 @@
// Copyright 2022 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.
#ifndef SRC_TINT_TRANSFORM_UNWIND_DISCARD_FUNCTIONS_H_
#define SRC_TINT_TRANSFORM_UNWIND_DISCARD_FUNCTIONS_H_
#include "src/tint/transform/transform.h"
namespace tint::transform {
/// This transform is responsible for implementing discard semantics as per the
/// WGSL specification: https://gpuweb.github.io/gpuweb/wgsl/#discard-statement
///
/// Not all backend languages implement discard this way (e.g. HLSL), so this
/// transform does the following:
///
/// * Replaces discard statements with setting a module-level boolean
/// "tint_discard" to true and returning immediately.
/// * Wherever calls are made to discarding functions (directly or
/// transitively), it inserts a check afterwards for if "tint_discard" is true,
/// to return immediately.
/// * Finally, entry point functions that call discarding functions
/// emit a call to "tint_discard_func()" that contains the sole discard
/// statement.
///
/// @note Depends on the following transforms to have been run first:
/// * PromoteSideEffectsToDecl
class UnwindDiscardFunctions final : public Castable<UnwindDiscardFunctions, Transform> {
public:
/// Constructor
UnwindDiscardFunctions();
/// Destructor
~UnwindDiscardFunctions() override;
/// @copydoc Transform::Apply
ApplyResult Apply(const Program* program,
const DataMap& inputs,
DataMap& outputs) const override;
private:
struct State;
};
} // namespace tint::transform
#endif // SRC_TINT_TRANSFORM_UNWIND_DISCARD_FUNCTIONS_H_

File diff suppressed because it is too large Load Diff

View File

@ -54,6 +54,7 @@
#include "src/tint/transform/canonicalize_entry_point_io.h" #include "src/tint/transform/canonicalize_entry_point_io.h"
#include "src/tint/transform/combine_samplers.h" #include "src/tint/transform/combine_samplers.h"
#include "src/tint/transform/decompose_memory_access.h" #include "src/tint/transform/decompose_memory_access.h"
#include "src/tint/transform/demote_to_helper.h"
#include "src/tint/transform/disable_uniformity_analysis.h" #include "src/tint/transform/disable_uniformity_analysis.h"
#include "src/tint/transform/expand_compound_assignment.h" #include "src/tint/transform/expand_compound_assignment.h"
#include "src/tint/transform/manager.h" #include "src/tint/transform/manager.h"
@ -66,7 +67,6 @@
#include "src/tint/transform/single_entry_point.h" #include "src/tint/transform/single_entry_point.h"
#include "src/tint/transform/std140.h" #include "src/tint/transform/std140.h"
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/unwind_discard_functions.h"
#include "src/tint/transform/zero_init_workgroup_memory.h" #include "src/tint/transform/zero_init_workgroup_memory.h"
#include "src/tint/utils/defer.h" #include "src/tint/utils/defer.h"
#include "src/tint/utils/map.h" #include "src/tint/utils/map.h"
@ -217,7 +217,9 @@ SanitizedResult Sanitize(const Program* in,
manager.Add<transform::ExpandCompoundAssignment>(); manager.Add<transform::ExpandCompoundAssignment>();
manager.Add<transform::PromoteSideEffectsToDecl>(); manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::PadStructs>(); manager.Add<transform::PadStructs>();
manager.Add<transform::UnwindDiscardFunctions>();
// DemoteToHelper must come after PromoteSideEffectsToDecl and ExpandCompoundAssignment.
manager.Add<transform::DemoteToHelper>();
manager.Add<transform::RemovePhonies>(); manager.Add<transform::RemovePhonies>();

View File

@ -23,7 +23,7 @@ namespace {
using GlslGeneratorImplTest_Loop = TestHelper; using GlslGeneratorImplTest_Loop = TestHelper;
TEST_F(GlslGeneratorImplTest_Loop, Emit_Loop) { TEST_F(GlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(); auto* continuing = Block();
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -36,7 +36,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_Loop) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard; break;
} }
)"); )");
} }
@ -44,7 +44,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_Loop) {
TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -57,7 +57,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard; break;
{ {
a_statement(); a_statement();
} }
@ -68,7 +68,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) { TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) {
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement")), BreakIf(true)); auto* continuing = Block(CallStmt(Call("a_statement")), BreakIf(true));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -81,7 +81,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard; break;
{ {
a_statement(); a_statement();
if (true) { break; } if (true) { break; }
@ -96,7 +96,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
GlobalVar("lhs", ty.f32(), ast::AddressSpace::kPrivate); GlobalVar("lhs", ty.f32(), ast::AddressSpace::kPrivate);
GlobalVar("rhs", ty.f32(), ast::AddressSpace::kPrivate); GlobalVar("rhs", ty.f32(), ast::AddressSpace::kPrivate);
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* inner = Loop(body, continuing); auto* inner = Loop(body, continuing);
@ -105,7 +105,7 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
auto* lhs = Expr("lhs"); auto* lhs = Expr("lhs");
auto* rhs = Expr("rhs"); auto* rhs = Expr("rhs");
continuing = Block(Assign(lhs, rhs)); continuing = Block(Assign(lhs, rhs), BreakIf(true));
auto* outer = Loop(body, continuing); auto* outer = Loop(body, continuing);
@ -119,13 +119,14 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
while (true) { while (true) {
discard; break;
{ {
a_statement(); a_statement();
} }
} }
{ {
lhs = rhs; lhs = rhs;
if (true) { break; }
} }
} }
)"); )");

View File

@ -54,6 +54,7 @@
#include "src/tint/transform/calculate_array_length.h" #include "src/tint/transform/calculate_array_length.h"
#include "src/tint/transform/canonicalize_entry_point_io.h" #include "src/tint/transform/canonicalize_entry_point_io.h"
#include "src/tint/transform/decompose_memory_access.h" #include "src/tint/transform/decompose_memory_access.h"
#include "src/tint/transform/demote_to_helper.h"
#include "src/tint/transform/disable_uniformity_analysis.h" #include "src/tint/transform/disable_uniformity_analysis.h"
#include "src/tint/transform/expand_compound_assignment.h" #include "src/tint/transform/expand_compound_assignment.h"
#include "src/tint/transform/localize_struct_array_assignment.h" #include "src/tint/transform/localize_struct_array_assignment.h"
@ -65,7 +66,6 @@
#include "src/tint/transform/remove_phonies.h" #include "src/tint/transform/remove_phonies.h"
#include "src/tint/transform/simplify_pointers.h" #include "src/tint/transform/simplify_pointers.h"
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/unwind_discard_functions.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h" #include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
#include "src/tint/transform/zero_init_workgroup_memory.h" #include "src/tint/transform/zero_init_workgroup_memory.h"
#include "src/tint/utils/defer.h" #include "src/tint/utils/defer.h"
@ -213,10 +213,15 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
manager.Add<transform::NumWorkgroupsFromUniform>(); manager.Add<transform::NumWorkgroupsFromUniform>();
manager.Add<transform::ExpandCompoundAssignment>(); manager.Add<transform::ExpandCompoundAssignment>();
manager.Add<transform::PromoteSideEffectsToDecl>(); manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::UnwindDiscardFunctions>();
manager.Add<transform::VectorizeScalarMatrixInitializers>(); manager.Add<transform::VectorizeScalarMatrixInitializers>();
manager.Add<transform::SimplifyPointers>(); manager.Add<transform::SimplifyPointers>();
manager.Add<transform::RemovePhonies>(); manager.Add<transform::RemovePhonies>();
// DemoteToHelper must come after CanonicalizeEntryPointIO, PromoteSideEffectsToDecl, and
// ExpandCompoundAssignment.
// TODO(crbug.com/tint/1752): This is only necessary when FXC is being used.
manager.Add<transform::DemoteToHelper>();
// ArrayLengthFromUniform must come after InlinePointerLets and Simplify, as // ArrayLengthFromUniform must come after InlinePointerLets and Simplify, as
// it assumes that the form of the array length argument is &var.array. // it assumes that the form of the array length argument is &var.array.
manager.Add<transform::ArrayLengthFromUniform>(); manager.Add<transform::ArrayLengthFromUniform>();

View File

@ -23,7 +23,7 @@ namespace {
using HlslGeneratorImplTest_Loop = TestHelper; using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(); auto* continuing = Block();
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -36,7 +36,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard; break;
} }
)"); )");
} }
@ -44,7 +44,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -57,7 +57,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard; break;
{ {
a_statement(); a_statement();
} }
@ -68,7 +68,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) {
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement")), BreakIf(true)); auto* continuing = Block(CallStmt(Call("a_statement")), BreakIf(true));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -81,7 +81,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard; break;
{ {
a_statement(); a_statement();
if (true) { break; } if (true) { break; }
@ -96,7 +96,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
GlobalVar("lhs", ty.f32(), ast::AddressSpace::kPrivate); GlobalVar("lhs", ty.f32(), ast::AddressSpace::kPrivate);
GlobalVar("rhs", ty.f32(), ast::AddressSpace::kPrivate); GlobalVar("rhs", ty.f32(), ast::AddressSpace::kPrivate);
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* inner = Loop(body, continuing); auto* inner = Loop(body, continuing);
@ -105,7 +105,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
auto* lhs = Expr("lhs"); auto* lhs = Expr("lhs");
auto* rhs = Expr("rhs"); auto* rhs = Expr("rhs");
continuing = Block(Assign(lhs, rhs)); continuing = Block(Assign(lhs, rhs), BreakIf(true));
auto* outer = Loop(body, continuing); auto* outer = Loop(body, continuing);
@ -119,13 +119,14 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
while (true) { while (true) {
discard; break;
{ {
a_statement(); a_statement();
} }
} }
{ {
lhs = rhs; lhs = rhs;
if (true) { break; }
} }
} }
)"); )");

View File

@ -62,6 +62,7 @@
#include "src/tint/transform/array_length_from_uniform.h" #include "src/tint/transform/array_length_from_uniform.h"
#include "src/tint/transform/builtin_polyfill.h" #include "src/tint/transform/builtin_polyfill.h"
#include "src/tint/transform/canonicalize_entry_point_io.h" #include "src/tint/transform/canonicalize_entry_point_io.h"
#include "src/tint/transform/demote_to_helper.h"
#include "src/tint/transform/disable_uniformity_analysis.h" #include "src/tint/transform/disable_uniformity_analysis.h"
#include "src/tint/transform/expand_compound_assignment.h" #include "src/tint/transform/expand_compound_assignment.h"
#include "src/tint/transform/manager.h" #include "src/tint/transform/manager.h"
@ -72,7 +73,6 @@
#include "src/tint/transform/remove_phonies.h" #include "src/tint/transform/remove_phonies.h"
#include "src/tint/transform/simplify_pointers.h" #include "src/tint/transform/simplify_pointers.h"
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/unwind_discard_functions.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h" #include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
#include "src/tint/transform/zero_init_workgroup_memory.h" #include "src/tint/transform/zero_init_workgroup_memory.h"
#include "src/tint/utils/defer.h" #include "src/tint/utils/defer.h"
@ -226,9 +226,12 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
manager.Add<transform::CanonicalizeEntryPointIO>(); manager.Add<transform::CanonicalizeEntryPointIO>();
manager.Add<transform::ExpandCompoundAssignment>(); manager.Add<transform::ExpandCompoundAssignment>();
manager.Add<transform::PromoteSideEffectsToDecl>(); manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::UnwindDiscardFunctions>();
manager.Add<transform::PromoteInitializersToLet>(); manager.Add<transform::PromoteInitializersToLet>();
// DemoteToHelper must come after PromoteSideEffectsToDecl and ExpandCompoundAssignment.
// TODO(crbug.com/tint/1752): This is only necessary for Metal versions older than 2.3.
manager.Add<transform::DemoteToHelper>();
manager.Add<transform::VectorizeScalarMatrixInitializers>(); manager.Add<transform::VectorizeScalarMatrixInitializers>();
manager.Add<transform::RemovePhonies>(); manager.Add<transform::RemovePhonies>();
manager.Add<transform::SimplifyPointers>(); manager.Add<transform::SimplifyPointers>();

View File

@ -23,7 +23,7 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Loop) { TEST_F(MslGeneratorImplTest, Emit_Loop) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(); auto* continuing = Block();
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -36,7 +36,7 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard_fragment(); break;
} }
)"); )");
} }
@ -44,7 +44,7 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
Func("a_statement", {}, ty.void_(), utils::Empty); Func("a_statement", {}, ty.void_(), utils::Empty);
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard_fragment(); break;
{ {
a_statement(); a_statement();
} }
@ -68,7 +68,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing_BreakIf) { TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing_BreakIf) {
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement")), BreakIf(true)); auto* continuing = Block(CallStmt(Call("a_statement")), BreakIf(true));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -81,7 +81,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing_BreakIf) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
discard_fragment(); break;
{ {
a_statement(); a_statement();
if (true) { break; } if (true) { break; }
@ -96,13 +96,13 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
GlobalVar("lhs", ty.f32(), ast::AddressSpace::kPrivate); GlobalVar("lhs", ty.f32(), ast::AddressSpace::kPrivate);
GlobalVar("rhs", ty.f32(), ast::AddressSpace::kPrivate); GlobalVar("rhs", ty.f32(), ast::AddressSpace::kPrivate);
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* inner = Loop(body, continuing); auto* inner = Loop(body, continuing);
body = Block(inner); body = Block(inner);
continuing = Block(Assign("lhs", "rhs")); continuing = Block(Assign("lhs", "rhs"), BreakIf(true));
auto* outer = Loop(body, continuing); auto* outer = Loop(body, continuing);
@ -116,13 +116,14 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) { EXPECT_EQ(gen.result(), R"( while (true) {
while (true) { while (true) {
discard_fragment(); break;
{ {
a_statement(); a_statement();
} }
} }
{ {
lhs = rhs; lhs = rhs;
if (true) { break; }
} }
} }
)"); )");

View File

@ -21,6 +21,7 @@
#include "src/tint/transform/add_empty_entry_point.h" #include "src/tint/transform/add_empty_entry_point.h"
#include "src/tint/transform/builtin_polyfill.h" #include "src/tint/transform/builtin_polyfill.h"
#include "src/tint/transform/canonicalize_entry_point_io.h" #include "src/tint/transform/canonicalize_entry_point_io.h"
#include "src/tint/transform/demote_to_helper.h"
#include "src/tint/transform/disable_uniformity_analysis.h" #include "src/tint/transform/disable_uniformity_analysis.h"
#include "src/tint/transform/expand_compound_assignment.h" #include "src/tint/transform/expand_compound_assignment.h"
#include "src/tint/transform/for_loop_to_loop.h" #include "src/tint/transform/for_loop_to_loop.h"
@ -32,7 +33,6 @@
#include "src/tint/transform/simplify_pointers.h" #include "src/tint/transform/simplify_pointers.h"
#include "src/tint/transform/std140.h" #include "src/tint/transform/std140.h"
#include "src/tint/transform/unshadow.h" #include "src/tint/transform/unshadow.h"
#include "src/tint/transform/unwind_discard_functions.h"
#include "src/tint/transform/var_for_dynamic_index.h" #include "src/tint/transform/var_for_dynamic_index.h"
#include "src/tint/transform/vectorize_matrix_conversions.h" #include "src/tint/transform/vectorize_matrix_conversions.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h" #include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
@ -82,7 +82,6 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
manager.Add<transform::RemoveUnreachableStatements>(); manager.Add<transform::RemoveUnreachableStatements>();
manager.Add<transform::ExpandCompoundAssignment>(); manager.Add<transform::ExpandCompoundAssignment>();
manager.Add<transform::PromoteSideEffectsToDecl>(); manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::UnwindDiscardFunctions>();
manager.Add<transform::SimplifyPointers>(); // Required for arrayLength() manager.Add<transform::SimplifyPointers>(); // Required for arrayLength()
manager.Add<transform::RemovePhonies>(); manager.Add<transform::RemovePhonies>();
manager.Add<transform::VectorizeScalarMatrixInitializers>(); manager.Add<transform::VectorizeScalarMatrixInitializers>();
@ -93,6 +92,11 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
manager.Add<transform::AddEmptyEntryPoint>(); manager.Add<transform::AddEmptyEntryPoint>();
manager.Add<transform::AddBlockAttribute>(); manager.Add<transform::AddBlockAttribute>();
// DemoteToHelper must come after CanonicalizeEntryPointIO, PromoteSideEffectsToDecl, and
// ExpandCompoundAssignment.
// TODO(crbug.com/tint/1752): Use SPV_EXT_demote_to_helper_invocation if available.
manager.Add<transform::DemoteToHelper>();
// Std140 must come after PromoteSideEffectsToDecl. // Std140 must come after PromoteSideEffectsToDecl.
// Std140 must come before VarForDynamicIndex and ForLoopToLoop. // Std140 must come before VarForDynamicIndex and ForLoopToLoop.
manager.Add<transform::Std140>(); manager.Add<transform::Std140>();

View File

@ -22,7 +22,7 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Loop) { TEST_F(WgslGeneratorImplTest, Emit_Loop) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(); auto* continuing = Block();
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -35,7 +35,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( loop { EXPECT_EQ(gen.result(), R"( loop {
discard; break;
} }
)"); )");
} }
@ -43,7 +43,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) {
TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
Func("a_statement", {}, ty.void_(), {}); Func("a_statement", {}, ty.void_(), {});
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(Break());
auto* continuing = Block(CallStmt(Call("a_statement"))); auto* continuing = Block(CallStmt(Call("a_statement")));
auto* l = Loop(body, continuing); auto* l = Loop(body, continuing);
@ -56,7 +56,7 @@ TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( loop { EXPECT_EQ(gen.result(), R"( loop {
discard; break;
continuing { continuing {
a_statement(); a_statement();

View File

@ -1,3 +1,5 @@
static bool tint_discarded = false;
cbuffer cbuffer_uniforms : register(b0, space0) { cbuffer cbuffer_uniforms : register(b0, space0) {
uint4 uniforms[1]; uint4 uniforms[1];
}; };
@ -45,30 +47,21 @@ struct tint_symbol_5 {
float4 value : SV_Target0; float4 value : SV_Target0;
}; };
static bool tint_discard = false;
float4 fs_main_inner(float2 texcoord) { float4 fs_main_inner(float2 texcoord) {
float2 clampedTexcoord = clamp(texcoord, (0.0f).xx, (1.0f).xx); float2 clampedTexcoord = clamp(texcoord, (0.0f).xx, (1.0f).xx);
if (!(all((clampedTexcoord == texcoord)))) { if (!(all((clampedTexcoord == texcoord)))) {
tint_discard = true; tint_discarded = true;
return (0.0f).xxxx;
} }
float4 srcColor = (0.0f).xxxx; float4 srcColor = (0.0f).xxxx;
return srcColor; return srcColor;
} }
void tint_discard_func() {
discard;
}
tint_symbol_5 fs_main(tint_symbol_4 tint_symbol_3) { tint_symbol_5 fs_main(tint_symbol_4 tint_symbol_3) {
const float4 inner_result_1 = fs_main_inner(tint_symbol_3.texcoord); const float4 inner_result_1 = fs_main_inner(tint_symbol_3.texcoord);
if (tint_discard) {
tint_discard_func();
const tint_symbol_5 tint_symbol_8 = (tint_symbol_5)0;
return tint_symbol_8;
}
tint_symbol_5 wrapper_result_1 = (tint_symbol_5)0; tint_symbol_5 wrapper_result_1 = (tint_symbol_5)0;
wrapper_result_1.value = inner_result_1; wrapper_result_1.value = inner_result_1;
if (tint_discarded) {
discard;
}
return wrapper_result_1; return wrapper_result_1;
} }

View File

@ -1,3 +1,5 @@
static bool tint_discarded = false;
cbuffer cbuffer_uniforms : register(b0, space0) { cbuffer cbuffer_uniforms : register(b0, space0) {
uint4 uniforms[1]; uint4 uniforms[1];
}; };
@ -45,30 +47,21 @@ struct tint_symbol_5 {
float4 value : SV_Target0; float4 value : SV_Target0;
}; };
static bool tint_discard = false;
float4 fs_main_inner(float2 texcoord) { float4 fs_main_inner(float2 texcoord) {
float2 clampedTexcoord = clamp(texcoord, (0.0f).xx, (1.0f).xx); float2 clampedTexcoord = clamp(texcoord, (0.0f).xx, (1.0f).xx);
if (!(all((clampedTexcoord == texcoord)))) { if (!(all((clampedTexcoord == texcoord)))) {
tint_discard = true; tint_discarded = true;
return (0.0f).xxxx;
} }
float4 srcColor = (0.0f).xxxx; float4 srcColor = (0.0f).xxxx;
return srcColor; return srcColor;
} }
void tint_discard_func() {
discard;
}
tint_symbol_5 fs_main(tint_symbol_4 tint_symbol_3) { tint_symbol_5 fs_main(tint_symbol_4 tint_symbol_3) {
const float4 inner_result_1 = fs_main_inner(tint_symbol_3.texcoord); const float4 inner_result_1 = fs_main_inner(tint_symbol_3.texcoord);
if (tint_discard) {
tint_discard_func();
const tint_symbol_5 tint_symbol_8 = (tint_symbol_5)0;
return tint_symbol_8;
}
tint_symbol_5 wrapper_result_1 = (tint_symbol_5)0; tint_symbol_5 wrapper_result_1 = (tint_symbol_5)0;
wrapper_result_1.value = inner_result_1; wrapper_result_1.value = inner_result_1;
if (tint_discarded) {
discard;
}
return wrapper_result_1; return wrapper_result_1;
} }

View File

@ -40,6 +40,7 @@ void main() {
#version 310 es #version 310 es
precision mediump float; precision mediump float;
bool tint_discarded = false;
layout(location = 0) in vec2 texcoord_1; layout(location = 0) in vec2 texcoord_1;
layout(location = 0) out vec4 value; layout(location = 0) out vec4 value;
struct Uniforms { struct Uniforms {
@ -52,27 +53,20 @@ struct VertexOutputs {
vec4 position; vec4 position;
}; };
bool tint_discard = false;
vec4 fs_main(vec2 texcoord) { vec4 fs_main(vec2 texcoord) {
vec2 clampedTexcoord = clamp(texcoord, vec2(0.0f), vec2(1.0f)); vec2 clampedTexcoord = clamp(texcoord, vec2(0.0f), vec2(1.0f));
if (!(all(equal(clampedTexcoord, texcoord)))) { if (!(all(equal(clampedTexcoord, texcoord)))) {
tint_discard = true; tint_discarded = true;
return vec4(0.0f);
} }
vec4 srcColor = vec4(0.0f); vec4 srcColor = vec4(0.0f);
return srcColor; return srcColor;
} }
void tint_discard_func() {
discard;
}
void main() { void main() {
vec4 inner_result = fs_main(texcoord_1); vec4 inner_result = fs_main(texcoord_1);
if (tint_discard) {
tint_discard_func();
return;
}
value = inner_result; value = inner_result;
if (tint_discarded) {
discard;
}
return; return;
} }

View File

@ -29,21 +29,21 @@ struct tint_symbol {
float4 position [[position]]; float4 position [[position]];
}; };
VertexOutputs vs_main_inner(uint VertexIndex, const constant Uniforms* const tint_symbol_5) { VertexOutputs vs_main_inner(uint VertexIndex, const constant Uniforms* const tint_symbol_4) {
tint_array<float2, 3> texcoord = tint_array<float2, 3>{float2(-0.5f, 0.0f), float2(1.5f, 0.0f), float2(0.5f, 2.0f)}; tint_array<float2, 3> texcoord = tint_array<float2, 3>{float2(-0.5f, 0.0f), float2(1.5f, 0.0f), float2(0.5f, 2.0f)};
VertexOutputs output = {}; VertexOutputs output = {};
output.position = float4(((texcoord[VertexIndex] * 2.0f) - float2(1.0f)), 0.0f, 1.0f); output.position = float4(((texcoord[VertexIndex] * 2.0f) - float2(1.0f)), 0.0f, 1.0f);
bool flipY = ((*(tint_symbol_5)).u_scale[1] < 0.0f); bool flipY = ((*(tint_symbol_4)).u_scale[1] < 0.0f);
if (flipY) { if (flipY) {
output.texcoords = ((((texcoord[VertexIndex] * (*(tint_symbol_5)).u_scale) + (*(tint_symbol_5)).u_offset) * float2(1.0f, -1.0f)) + float2(0.0f, 1.0f)); output.texcoords = ((((texcoord[VertexIndex] * (*(tint_symbol_4)).u_scale) + (*(tint_symbol_4)).u_offset) * float2(1.0f, -1.0f)) + float2(0.0f, 1.0f));
} else { } else {
output.texcoords = ((((texcoord[VertexIndex] * float2(1.0f, -1.0f)) + float2(0.0f, 1.0f)) * (*(tint_symbol_5)).u_scale) + (*(tint_symbol_5)).u_offset); output.texcoords = ((((texcoord[VertexIndex] * float2(1.0f, -1.0f)) + float2(0.0f, 1.0f)) * (*(tint_symbol_4)).u_scale) + (*(tint_symbol_4)).u_offset);
} }
return output; return output;
} }
vertex tint_symbol vs_main(const constant Uniforms* tint_symbol_6 [[buffer(0)]], uint VertexIndex [[vertex_id]]) { vertex tint_symbol vs_main(const constant Uniforms* tint_symbol_5 [[buffer(0)]], uint VertexIndex [[vertex_id]]) {
VertexOutputs const inner_result = vs_main_inner(VertexIndex, tint_symbol_6); VertexOutputs const inner_result = vs_main_inner(VertexIndex, tint_symbol_5);
tint_symbol wrapper_result = {}; tint_symbol wrapper_result = {};
wrapper_result.texcoords = inner_result.texcoords; wrapper_result.texcoords = inner_result.texcoords;
wrapper_result.position = inner_result.position; wrapper_result.position = inner_result.position;
@ -58,30 +58,23 @@ struct tint_symbol_3 {
float4 value [[color(0)]]; float4 value [[color(0)]];
}; };
float4 fs_main_inner(float2 texcoord, thread bool* const tint_symbol_7) { float4 fs_main_inner(float2 texcoord, thread bool* const tint_symbol_6) {
float2 clampedTexcoord = clamp(texcoord, float2(0.0f), float2(1.0f)); float2 clampedTexcoord = clamp(texcoord, float2(0.0f), float2(1.0f));
if (!(all((clampedTexcoord == texcoord)))) { if (!(all((clampedTexcoord == texcoord)))) {
*(tint_symbol_7) = true; *(tint_symbol_6) = true;
return float4(0.0f);
} }
float4 srcColor = float4(0.0f); float4 srcColor = float4(0.0f);
return srcColor; return srcColor;
} }
void tint_discard_func() {
discard_fragment();
}
fragment tint_symbol_3 fs_main(tint_symbol_2 tint_symbol_1 [[stage_in]]) { fragment tint_symbol_3 fs_main(tint_symbol_2 tint_symbol_1 [[stage_in]]) {
thread bool tint_symbol_8 = false; thread bool tint_symbol_7 = false;
float4 const inner_result_1 = fs_main_inner(tint_symbol_1.texcoord, &(tint_symbol_8)); float4 const inner_result_1 = fs_main_inner(tint_symbol_1.texcoord, &(tint_symbol_7));
if (tint_symbol_8) {
tint_discard_func();
tint_symbol_3 const tint_symbol_4 = tint_symbol_3{};
return tint_symbol_4;
}
tint_symbol_3 wrapper_result_1 = {}; tint_symbol_3 wrapper_result_1 = {};
wrapper_result_1.value = inner_result_1; wrapper_result_1.value = inner_result_1;
if (tint_symbol_7) {
discard_fragment();
}
return wrapper_result_1; return wrapper_result_1;
} }

View File

@ -1,7 +1,7 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 134 ; Bound: 137
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
%118 = OpExtInstImport "GLSL.std.450" %118 = OpExtInstImport "GLSL.std.450"
@ -9,6 +9,7 @@
OpEntryPoint Vertex %vs_main "vs_main" %VertexIndex_1 %texcoords_1 %position_1 %vertex_point_size OpEntryPoint Vertex %vs_main "vs_main" %VertexIndex_1 %texcoords_1 %position_1 %vertex_point_size
OpEntryPoint Fragment %fs_main "fs_main" %texcoord_1 %value OpEntryPoint Fragment %fs_main "fs_main" %texcoord_1 %value
OpExecutionMode %fs_main OriginUpperLeft OpExecutionMode %fs_main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %VertexIndex_1 "VertexIndex_1" OpName %VertexIndex_1 "VertexIndex_1"
OpName %texcoords_1 "texcoords_1" OpName %texcoords_1 "texcoords_1"
OpName %position_1 "position_1" OpName %position_1 "position_1"
@ -32,7 +33,6 @@
OpName %output "output" OpName %output "output"
OpName %flipY "flipY" OpName %flipY "flipY"
OpName %vs_main "vs_main" OpName %vs_main "vs_main"
OpName %tint_discard_func "tint_discard_func"
OpName %fs_main_inner "fs_main_inner" OpName %fs_main_inner "fs_main_inner"
OpName %texcoord_0 "texcoord" OpName %texcoord_0 "texcoord"
OpName %clampedTexcoord "clampedTexcoord" OpName %clampedTexcoord "clampedTexcoord"
@ -58,144 +58,143 @@
OpMemberDecorate %VertexOutputs 0 Offset 0 OpMemberDecorate %VertexOutputs 0 Offset 0
OpMemberDecorate %VertexOutputs 1 Offset 16 OpMemberDecorate %VertexOutputs 1 Offset 16
OpDecorate %_arr_v2float_uint_3 ArrayStride 8 OpDecorate %_arr_v2float_uint_3 ArrayStride 8
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%uint = OpTypeInt 32 0 %uint = OpTypeInt 32 0
%_ptr_Input_uint = OpTypePointer Input %uint %_ptr_Input_uint = OpTypePointer Input %uint
%VertexIndex_1 = OpVariable %_ptr_Input_uint Input %VertexIndex_1 = OpVariable %_ptr_Input_uint Input
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%v2float = OpTypeVector %float 2 %v2float = OpTypeVector %float 2
%_ptr_Output_v2float = OpTypePointer Output %v2float %_ptr_Output_v2float = OpTypePointer Output %v2float
%8 = OpConstantNull %v2float %12 = OpConstantNull %v2float
%texcoords_1 = OpVariable %_ptr_Output_v2float Output %8 %texcoords_1 = OpVariable %_ptr_Output_v2float Output %12
%v4float = OpTypeVector %float 4 %v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float %_ptr_Output_v4float = OpTypePointer Output %v4float
%12 = OpConstantNull %v4float %16 = OpConstantNull %v4float
%position_1 = OpVariable %_ptr_Output_v4float Output %12 %position_1 = OpVariable %_ptr_Output_v4float Output %16
%_ptr_Output_float = OpTypePointer Output %float %_ptr_Output_float = OpTypePointer Output %float
%15 = OpConstantNull %float %19 = OpConstantNull %float
%vertex_point_size = OpVariable %_ptr_Output_float Output %15 %vertex_point_size = OpVariable %_ptr_Output_float Output %19
%_ptr_Input_v2float = OpTypePointer Input %v2float %_ptr_Input_v2float = OpTypePointer Input %v2float
%texcoord_1 = OpVariable %_ptr_Input_v2float Input %texcoord_1 = OpVariable %_ptr_Input_v2float Input
%value = OpVariable %_ptr_Output_v4float Output %12 %value = OpVariable %_ptr_Output_v4float Output %16
%Uniforms = OpTypeStruct %v2float %v2float %Uniforms = OpTypeStruct %v2float %v2float
%uniforms_block = OpTypeStruct %Uniforms %uniforms_block = OpTypeStruct %Uniforms
%_ptr_Uniform_uniforms_block = OpTypePointer Uniform %uniforms_block %_ptr_Uniform_uniforms_block = OpTypePointer Uniform %uniforms_block
%uniforms = OpVariable %_ptr_Uniform_uniforms_block Uniform %uniforms = OpVariable %_ptr_Uniform_uniforms_block Uniform
%25 = OpTypeSampler %29 = OpTypeSampler
%_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25 %_ptr_UniformConstant_29 = OpTypePointer UniformConstant %29
%mySampler = OpVariable %_ptr_UniformConstant_25 UniformConstant %mySampler = OpVariable %_ptr_UniformConstant_29 UniformConstant
%28 = OpTypeImage %float 2D 0 0 0 1 Unknown %32 = OpTypeImage %float 2D 0 0 0 1 Unknown
%_ptr_UniformConstant_28 = OpTypePointer UniformConstant %28 %_ptr_UniformConstant_32 = OpTypePointer UniformConstant %32
%myTexture = OpVariable %_ptr_UniformConstant_28 UniformConstant %myTexture = OpVariable %_ptr_UniformConstant_32 UniformConstant
%VertexOutputs = OpTypeStruct %v2float %v4float %VertexOutputs = OpTypeStruct %v2float %v4float
%29 = OpTypeFunction %VertexOutputs %uint %33 = OpTypeFunction %VertexOutputs %uint
%uint_3 = OpConstant %uint 3 %uint_3 = OpConstant %uint 3
%_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3 %_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3
%float_n0_5 = OpConstant %float -0.5 %float_n0_5 = OpConstant %float -0.5
%37 = OpConstantComposite %v2float %float_n0_5 %15 %41 = OpConstantComposite %v2float %float_n0_5 %19
%float_1_5 = OpConstant %float 1.5 %float_1_5 = OpConstant %float 1.5
%39 = OpConstantComposite %v2float %float_1_5 %15 %43 = OpConstantComposite %v2float %float_1_5 %19
%float_0_5 = OpConstant %float 0.5 %float_0_5 = OpConstant %float 0.5
%float_2 = OpConstant %float 2 %float_2 = OpConstant %float 2
%42 = OpConstantComposite %v2float %float_0_5 %float_2 %46 = OpConstantComposite %v2float %float_0_5 %float_2
%43 = OpConstantComposite %_arr_v2float_uint_3 %37 %39 %42 %47 = OpConstantComposite %_arr_v2float_uint_3 %41 %43 %46
%_ptr_Function__arr_v2float_uint_3 = OpTypePointer Function %_arr_v2float_uint_3 %_ptr_Function__arr_v2float_uint_3 = OpTypePointer Function %_arr_v2float_uint_3
%46 = OpConstantNull %_arr_v2float_uint_3 %50 = OpConstantNull %_arr_v2float_uint_3
%_ptr_Function_VertexOutputs = OpTypePointer Function %VertexOutputs %_ptr_Function_VertexOutputs = OpTypePointer Function %VertexOutputs
%49 = OpConstantNull %VertexOutputs %53 = OpConstantNull %VertexOutputs
%uint_1 = OpConstant %uint 1 %uint_1 = OpConstant %uint 1
%_ptr_Function_v4float = OpTypePointer Function %v4float %_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Function_v2float = OpTypePointer Function %v2float %_ptr_Function_v2float = OpTypePointer Function %v2float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%58 = OpConstantComposite %v2float %float_1 %float_1 %62 = OpConstantComposite %v2float %float_1 %float_1
%uint_0 = OpConstant %uint 0 %uint_0 = OpConstant %uint 0
%_ptr_Uniform_float = OpTypePointer Uniform %float %_ptr_Uniform_float = OpTypePointer Uniform %float
%bool = OpTypeBool
%_ptr_Function_bool = OpTypePointer Function %bool %_ptr_Function_bool = OpTypePointer Function %bool
%71 = OpConstantNull %bool
%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
%float_n1 = OpConstant %float -1 %float_n1 = OpConstant %float -1
%87 = OpConstantComposite %v2float %float_1 %float_n1 %89 = OpConstantComposite %v2float %float_1 %float_n1
%89 = OpConstantComposite %v2float %15 %float_1 %91 = OpConstantComposite %v2float %19 %float_1
%void = OpTypeVoid %void = OpTypeVoid
%103 = OpTypeFunction %void %105 = OpTypeFunction %void
%113 = OpTypeFunction %v4float %v2float %113 = OpTypeFunction %v4float %v2float
%v2bool = OpTypeVector %bool 2 %v2bool = OpTypeVector %bool 2
%vs_main_inner = OpFunction %VertexOutputs None %29 %true = OpConstantTrue %bool
%vs_main_inner = OpFunction %VertexOutputs None %33
%VertexIndex = OpFunctionParameter %uint %VertexIndex = OpFunctionParameter %uint
%33 = OpLabel %37 = OpLabel
%texcoord = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %46 %texcoord = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %50
%output = OpVariable %_ptr_Function_VertexOutputs Function %49 %output = OpVariable %_ptr_Function_VertexOutputs Function %53
%flipY = OpVariable %_ptr_Function_bool Function %71 %flipY = OpVariable %_ptr_Function_bool Function %2
OpStore %texcoord %43 OpStore %texcoord %47
%52 = OpAccessChain %_ptr_Function_v4float %output %uint_1 %56 = OpAccessChain %_ptr_Function_v4float %output %uint_1
%54 = OpAccessChain %_ptr_Function_v2float %texcoord %VertexIndex %58 = OpAccessChain %_ptr_Function_v2float %texcoord %VertexIndex
%55 = OpLoad %v2float %54 %59 = OpLoad %v2float %58
%56 = OpVectorTimesScalar %v2float %55 %float_2 %60 = OpVectorTimesScalar %v2float %59 %float_2
%59 = OpFSub %v2float %56 %58 %63 = OpFSub %v2float %60 %62
%60 = OpCompositeExtract %float %59 0 %64 = OpCompositeExtract %float %63 0
%61 = OpCompositeExtract %float %59 1 %65 = OpCompositeExtract %float %63 1
%62 = OpCompositeConstruct %v4float %60 %61 %15 %float_1 %66 = OpCompositeConstruct %v4float %64 %65 %19 %float_1
OpStore %52 %62 OpStore %56 %66
%65 = OpAccessChain %_ptr_Uniform_float %uniforms %uint_0 %uint_0 %uint_1 %69 = OpAccessChain %_ptr_Uniform_float %uniforms %uint_0 %uint_0 %uint_1
%66 = OpLoad %float %65 %70 = OpLoad %float %69
%67 = OpFOrdLessThan %bool %66 %15 %71 = OpFOrdLessThan %bool %70 %19
OpStore %flipY %67 OpStore %flipY %71
%72 = OpLoad %bool %flipY %74 = OpLoad %bool %flipY
OpSelectionMerge %73 None OpSelectionMerge %75 None
OpBranchConditional %72 %74 %75 OpBranchConditional %74 %76 %77
%74 = OpLabel %76 = OpLabel
%76 = OpAccessChain %_ptr_Function_v2float %output %uint_0 %78 = OpAccessChain %_ptr_Function_v2float %output %uint_0
%77 = OpAccessChain %_ptr_Function_v2float %texcoord %VertexIndex %79 = OpAccessChain %_ptr_Function_v2float %texcoord %VertexIndex
%78 = OpLoad %v2float %77 %80 = OpLoad %v2float %79
%80 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_0 %82 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_0
%81 = OpLoad %v2float %80 %83 = OpLoad %v2float %82
%82 = OpFMul %v2float %78 %81 %84 = OpFMul %v2float %80 %83
%83 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_1 %85 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_1
%84 = OpLoad %v2float %83 %86 = OpLoad %v2float %85
%85 = OpFAdd %v2float %82 %84 %87 = OpFAdd %v2float %84 %86
%88 = OpFMul %v2float %85 %87 %90 = OpFMul %v2float %87 %89
%90 = OpFAdd %v2float %88 %89 %92 = OpFAdd %v2float %90 %91
OpStore %76 %90 OpStore %78 %92
OpBranch %73 OpBranch %75
%77 = OpLabel
%93 = OpAccessChain %_ptr_Function_v2float %output %uint_0
%94 = OpAccessChain %_ptr_Function_v2float %texcoord %VertexIndex
%95 = OpLoad %v2float %94
%96 = OpFMul %v2float %95 %89
%97 = OpFAdd %v2float %96 %91
%98 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_0
%99 = OpLoad %v2float %98
%100 = OpFMul %v2float %97 %99
%101 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_1
%102 = OpLoad %v2float %101
%103 = OpFAdd %v2float %100 %102
OpStore %93 %103
OpBranch %75
%75 = OpLabel %75 = OpLabel
%91 = OpAccessChain %_ptr_Function_v2float %output %uint_0 %104 = OpLoad %VertexOutputs %output
%92 = OpAccessChain %_ptr_Function_v2float %texcoord %VertexIndex OpReturnValue %104
%93 = OpLoad %v2float %92
%94 = OpFMul %v2float %93 %87
%95 = OpFAdd %v2float %94 %89
%96 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_0
%97 = OpLoad %v2float %96
%98 = OpFMul %v2float %95 %97
%99 = OpAccessChain %_ptr_Uniform_v2float %uniforms %uint_0 %uint_1
%100 = OpLoad %v2float %99
%101 = OpFAdd %v2float %98 %100
OpStore %91 %101
OpBranch %73
%73 = OpLabel
%102 = OpLoad %VertexOutputs %output
OpReturnValue %102
OpFunctionEnd OpFunctionEnd
%vs_main = OpFunction %void None %103 %vs_main = OpFunction %void None %105
%106 = OpLabel %108 = OpLabel
%108 = OpLoad %uint %VertexIndex_1 %110 = OpLoad %uint %VertexIndex_1
%107 = OpFunctionCall %VertexOutputs %vs_main_inner %108 %109 = OpFunctionCall %VertexOutputs %vs_main_inner %110
%109 = OpCompositeExtract %v2float %107 0 %111 = OpCompositeExtract %v2float %109 0
OpStore %texcoords_1 %109 OpStore %texcoords_1 %111
%110 = OpCompositeExtract %v4float %107 1 %112 = OpCompositeExtract %v4float %109 1
OpStore %position_1 %110 OpStore %position_1 %112
OpStore %vertex_point_size %float_1 OpStore %vertex_point_size %float_1
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%tint_discard_func = OpFunction %void None %103
%112 = OpLabel
OpKill
OpFunctionEnd
%fs_main_inner = OpFunction %v4float None %113 %fs_main_inner = OpFunction %v4float None %113
%texcoord_0 = OpFunctionParameter %v2float %texcoord_0 = OpFunctionParameter %v2float
%116 = OpLabel %116 = OpLabel
%clampedTexcoord = OpVariable %_ptr_Function_v2float Function %8 %clampedTexcoord = OpVariable %_ptr_Function_v2float Function %12
%srcColor = OpVariable %_ptr_Function_v4float Function %12 %srcColor = OpVariable %_ptr_Function_v4float Function %16
%117 = OpExtInst %v2float %118 NClamp %texcoord_0 %8 %58 %117 = OpExtInst %v2float %118 NClamp %texcoord_0 %12 %62
OpStore %clampedTexcoord %117 OpStore %clampedTexcoord %117
%122 = OpLoad %v2float %clampedTexcoord %122 = OpLoad %v2float %clampedTexcoord
%123 = OpFOrdEqual %v2bool %122 %texcoord_0 %123 = OpFOrdEqual %v2bool %122 %texcoord_0
@ -204,17 +203,23 @@
OpSelectionMerge %125 None OpSelectionMerge %125 None
OpBranchConditional %120 %126 %125 OpBranchConditional %120 %126 %125
%126 = OpLabel %126 = OpLabel
%127 = OpFunctionCall %void %tint_discard_func OpStore %tint_discarded %true
OpReturnValue %12 OpBranch %125
%125 = OpLabel %125 = OpLabel
OpStore %srcColor %12 OpStore %srcColor %16
%129 = OpLoad %v4float %srcColor %129 = OpLoad %v4float %srcColor
OpReturnValue %129 OpReturnValue %129
OpFunctionEnd OpFunctionEnd
%fs_main = OpFunction %void None %103 %fs_main = OpFunction %void None %105
%131 = OpLabel %131 = OpLabel
%133 = OpLoad %v2float %texcoord_1 %133 = OpLoad %v2float %texcoord_1
%132 = OpFunctionCall %v4float %fs_main_inner %133 %132 = OpFunctionCall %v4float %fs_main_inner %133
OpStore %value %132 OpStore %value %132
%134 = OpLoad %bool %tint_discarded
OpSelectionMerge %135 None
OpBranchConditional %134 %136 %135
%136 = OpLabel
OpKill
%135 = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,9 +1,8 @@
static bool tint_discard = false; static bool tint_discarded = false;
int f(int x) { int f(int x) {
if ((x == 10)) { if ((x == 10)) {
tint_discard = true; tint_discarded = true;
return 0;
} }
return x; return x;
} }
@ -19,9 +18,6 @@ int main_inner(int3 x) {
int y = x.x; int y = x.x;
while (true) { while (true) {
const int r = f(y); const int r = f(y);
if (tint_discard) {
return 0;
}
if ((r == 0)) { if ((r == 0)) {
break; break;
} }
@ -29,18 +25,12 @@ int main_inner(int3 x) {
return y; return y;
} }
void tint_discard_func() {
discard;
}
tint_symbol_2 main(tint_symbol_1 tint_symbol) { tint_symbol_2 main(tint_symbol_1 tint_symbol) {
const int inner_result = main_inner(tint_symbol.x); const int inner_result = main_inner(tint_symbol.x);
if (tint_discard) {
tint_discard_func();
const tint_symbol_2 tint_symbol_3 = (tint_symbol_2)0;
return tint_symbol_3;
}
tint_symbol_2 wrapper_result = (tint_symbol_2)0; tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.value = inner_result; wrapper_result.value = inner_result;
if (tint_discarded) {
discard;
}
return wrapper_result; return wrapper_result;
} }

View File

@ -1,9 +1,8 @@
static bool tint_discard = false; static bool tint_discarded = false;
int f(int x) { int f(int x) {
if ((x == 10)) { if ((x == 10)) {
tint_discard = true; tint_discarded = true;
return 0;
} }
return x; return x;
} }
@ -19,9 +18,6 @@ int main_inner(int3 x) {
int y = x.x; int y = x.x;
while (true) { while (true) {
const int r = f(y); const int r = f(y);
if (tint_discard) {
return 0;
}
if ((r == 0)) { if ((r == 0)) {
break; break;
} }
@ -29,18 +25,12 @@ int main_inner(int3 x) {
return y; return y;
} }
void tint_discard_func() {
discard;
}
tint_symbol_2 main(tint_symbol_1 tint_symbol) { tint_symbol_2 main(tint_symbol_1 tint_symbol) {
const int inner_result = main_inner(tint_symbol.x); const int inner_result = main_inner(tint_symbol.x);
if (tint_discard) {
tint_discard_func();
const tint_symbol_2 tint_symbol_3 = (tint_symbol_2)0;
return tint_symbol_3;
}
tint_symbol_2 wrapper_result = (tint_symbol_2)0; tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.value = inner_result; wrapper_result.value = inner_result;
if (tint_discarded) {
discard;
}
return wrapper_result; return wrapper_result;
} }

View File

@ -1,13 +1,12 @@
#version 310 es #version 310 es
precision mediump float; precision mediump float;
bool tint_discarded = false;
layout(location = 1) flat in ivec3 x_1; layout(location = 1) flat in ivec3 x_1;
layout(location = 2) out int value; layout(location = 2) out int value;
bool tint_discard = false;
int f(int x) { int f(int x) {
if ((x == 10)) { if ((x == 10)) {
tint_discard = true; tint_discarded = true;
return 0;
} }
return x; return x;
} }
@ -16,9 +15,6 @@ int tint_symbol(ivec3 x) {
int y = x.x; int y = x.x;
while (true) { while (true) {
int r = f(y); int r = f(y);
if (tint_discard) {
return 0;
}
if ((r == 0)) { if ((r == 0)) {
break; break;
} }
@ -26,16 +22,11 @@ int tint_symbol(ivec3 x) {
return y; return y;
} }
void tint_discard_func() {
discard;
}
void main() { void main() {
int inner_result = tint_symbol(x_1); int inner_result = tint_symbol(x_1);
if (tint_discard) {
tint_discard_func();
return;
}
value = inner_result; value = inner_result;
if (tint_discarded) {
discard;
}
return; return;
} }

View File

@ -1,10 +1,9 @@
#include <metal_stdlib> #include <metal_stdlib>
using namespace metal; using namespace metal;
int f(int x, thread bool* const tint_symbol_5) { int f(int x, thread bool* const tint_symbol_4) {
if ((x == 10)) { if ((x == 10)) {
*(tint_symbol_5) = true; *(tint_symbol_4) = true;
return 0;
} }
return x; return x;
} }
@ -17,13 +16,10 @@ struct tint_symbol_3 {
int value [[color(2)]]; int value [[color(2)]];
}; };
int tint_symbol_inner(int3 x, thread bool* const tint_symbol_6) { int tint_symbol_inner(int3 x, thread bool* const tint_symbol_5) {
int y = x[0]; int y = x[0];
while (true) { while (true) {
int const r = f(y, tint_symbol_6); int const r = f(y, tint_symbol_5);
if (*(tint_symbol_6)) {
return 0;
}
if ((r == 0)) { if ((r == 0)) {
break; break;
} }
@ -31,20 +27,14 @@ int tint_symbol_inner(int3 x, thread bool* const tint_symbol_6) {
return y; return y;
} }
void tint_discard_func() {
discard_fragment();
}
fragment tint_symbol_3 tint_symbol(tint_symbol_2 tint_symbol_1 [[stage_in]]) { fragment tint_symbol_3 tint_symbol(tint_symbol_2 tint_symbol_1 [[stage_in]]) {
thread bool tint_symbol_7 = false; thread bool tint_symbol_6 = false;
int const inner_result = tint_symbol_inner(tint_symbol_1.x, &(tint_symbol_7)); int const inner_result = tint_symbol_inner(tint_symbol_1.x, &(tint_symbol_6));
if (tint_symbol_7) {
tint_discard_func();
tint_symbol_3 const tint_symbol_4 = tint_symbol_3{};
return tint_symbol_4;
}
tint_symbol_3 wrapper_result = {}; tint_symbol_3 wrapper_result = {};
wrapper_result.value = inner_result; wrapper_result.value = inner_result;
if (tint_symbol_6) {
discard_fragment();
}
return wrapper_result; return wrapper_result;
} }

View File

@ -1,20 +1,17 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 58 ; Bound: 47
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %x_1 %value OpEntryPoint Fragment %main "main" %x_1 %value
OpExecutionMode %main OriginUpperLeft OpExecutionMode %main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %x_1 "x_1" OpName %x_1 "x_1"
OpName %value "value" OpName %value "value"
OpName %tint_discard "tint_discard"
OpName %f "f" OpName %f "f"
OpName %x "x" OpName %x "x"
OpName %tint_return_flag "tint_return_flag"
OpName %tint_return_value "tint_return_value"
OpName %tint_discard_func "tint_discard_func"
OpName %main_inner "main_inner" OpName %main_inner "main_inner"
OpName %x_0 "x" OpName %x_0 "x"
OpName %y "y" OpName %y "y"
@ -22,92 +19,72 @@
OpDecorate %x_1 Location 1 OpDecorate %x_1 Location 1
OpDecorate %x_1 Flat OpDecorate %x_1 Flat
OpDecorate %value Location 2 OpDecorate %value Location 2
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%int = OpTypeInt 32 1 %int = OpTypeInt 32 1
%v3int = OpTypeVector %int 3 %v3int = OpTypeVector %int 3
%_ptr_Input_v3int = OpTypePointer Input %v3int %_ptr_Input_v3int = OpTypePointer Input %v3int
%x_1 = OpVariable %_ptr_Input_v3int Input %x_1 = OpVariable %_ptr_Input_v3int Input
%_ptr_Output_int = OpTypePointer Output %int %_ptr_Output_int = OpTypePointer Output %int
%7 = OpConstantNull %int %11 = OpConstantNull %int
%value = OpVariable %_ptr_Output_int Output %7 %value = OpVariable %_ptr_Output_int Output %11
%bool = OpTypeBool
%9 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discard = OpVariable %_ptr_Private_bool Private %9
%12 = OpTypeFunction %int %int %12 = OpTypeFunction %int %int
%_ptr_Function_bool = OpTypePointer Function %bool
%_ptr_Function_int = OpTypePointer Function %int
%int_10 = OpConstant %int 10 %int_10 = OpConstant %int 10
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%21 = OpTypeFunction %int %v3int
%_ptr_Function_int = OpTypePointer Function %int
%void = OpTypeVoid %void = OpTypeVoid
%30 = OpTypeFunction %void %38 = OpTypeFunction %void
%34 = OpTypeFunction %int %v3int
%f = OpFunction %int None %12 %f = OpFunction %int None %12
%x = OpFunctionParameter %int %x = OpFunctionParameter %int
%15 = OpLabel %15 = OpLabel
%tint_return_flag = OpVariable %_ptr_Function_bool Function %9 %17 = OpIEqual %bool %x %int_10
%tint_return_value = OpVariable %_ptr_Function_int Function %7 OpSelectionMerge %18 None
%21 = OpIEqual %bool %x %int_10 OpBranchConditional %17 %19 %18
OpSelectionMerge %22 None %19 = OpLabel
OpBranchConditional %21 %23 %22 OpStore %tint_discarded %true
%23 = OpLabel OpBranch %18
OpStore %tint_discard %true %18 = OpLabel
OpStore %tint_return_flag %true OpReturnValue %x
OpStore %tint_return_value %7
OpBranch %22
%22 = OpLabel
%26 = OpLoad %bool %tint_return_flag
%25 = OpLogicalNot %bool %26
OpSelectionMerge %27 None
OpBranchConditional %25 %28 %27
%28 = OpLabel
OpStore %tint_return_flag %true
OpStore %tint_return_value %x
OpBranch %27
%27 = OpLabel
%29 = OpLoad %int %tint_return_value
OpReturnValue %29
OpFunctionEnd OpFunctionEnd
%tint_discard_func = OpFunction %void None %30 %main_inner = OpFunction %int None %21
%33 = OpLabel
OpKill
OpFunctionEnd
%main_inner = OpFunction %int None %34
%x_0 = OpFunctionParameter %v3int %x_0 = OpFunctionParameter %v3int
%37 = OpLabel %24 = OpLabel
%y = OpVariable %_ptr_Function_int Function %7 %y = OpVariable %_ptr_Function_int Function %11
%38 = OpCompositeExtract %int %x_0 0 %25 = OpCompositeExtract %int %x_0 0
OpStore %y %38 OpStore %y %25
OpBranch %40 OpBranch %28
%40 = OpLabel %28 = OpLabel
OpLoopMerge %41 %42 None OpLoopMerge %29 %30 None
OpBranch %43 OpBranch %31
%43 = OpLabel %31 = OpLabel
%45 = OpLoad %int %y %33 = OpLoad %int %y
%44 = OpFunctionCall %int %f %45 %32 = OpFunctionCall %int %f %33
%46 = OpLoad %bool %tint_discard %34 = OpIEqual %bool %32 %11
OpSelectionMerge %47 None OpSelectionMerge %35 None
OpBranchConditional %46 %48 %47 OpBranchConditional %34 %36 %35
%48 = OpLabel %36 = OpLabel
%49 = OpFunctionCall %void %tint_discard_func OpBranch %29
OpReturnValue %7 %35 = OpLabel
%47 = OpLabel OpBranch %30
%50 = OpIEqual %bool %44 %7 %30 = OpLabel
OpSelectionMerge %51 None OpBranch %28
OpBranchConditional %50 %52 %51 %29 = OpLabel
%52 = OpLabel %37 = OpLoad %int %y
OpBranch %41 OpReturnValue %37
%51 = OpLabel
OpBranch %42
%42 = OpLabel
OpBranch %40
%41 = OpLabel
%53 = OpLoad %int %y
OpReturnValue %53
OpFunctionEnd OpFunctionEnd
%main = OpFunction %void None %30 %main = OpFunction %void None %38
%55 = OpLabel %41 = OpLabel
%57 = OpLoad %v3int %x_1 %43 = OpLoad %v3int %x_1
%56 = OpFunctionCall %int %main_inner %57 %42 = OpFunctionCall %int %main_inner %43
OpStore %value %56 OpStore %value %42
%44 = OpLoad %bool %tint_discarded
OpSelectionMerge %45 None
OpBranchConditional %44 %46 %45
%46 = OpLabel
OpKill
%45 = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,3 +1,5 @@
static bool tint_discarded = false;
static float fClipDistance3 = 0.0f; static float fClipDistance3 = 0.0f;
static float fClipDistance4 = 0.0f; static float fClipDistance4 = 0.0f;
cbuffer cbuffer_x_29 : register(b0, space0) { cbuffer cbuffer_x_29 : register(b0, space0) {
@ -10,7 +12,6 @@ cbuffer cbuffer_x_137 : register(b2, space0) {
uint4 x_137[1]; uint4 x_137[1];
}; };
static float4 glFragColor = float4(0.0f, 0.0f, 0.0f, 0.0f); static float4 glFragColor = float4(0.0f, 0.0f, 0.0f, 0.0f);
static bool tint_discard = false;
void main_1() { void main_1() {
float3 viewDirectionW = float3(0.0f, 0.0f, 0.0f); float3 viewDirectionW = float3(0.0f, 0.0f, 0.0f);
@ -31,13 +32,11 @@ void main_1() {
float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f); float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
const float x_9 = fClipDistance3; const float x_9 = fClipDistance3;
if ((x_9 > 0.0f)) { if ((x_9 > 0.0f)) {
tint_discard = true; tint_discarded = true;
return;
} }
const float x_17 = fClipDistance4; const float x_17 = fClipDistance4;
if ((x_17 > 0.0f)) { if ((x_17 > 0.0f)) {
tint_discard = true; tint_discarded = true;
return;
} }
const float4 x_34 = asfloat(x_29[0]); const float4 x_34 = asfloat(x_29[0]);
const float3 x_38 = (0.0f).xxx; const float3 x_38 = (0.0f).xxx;
@ -105,26 +104,16 @@ main_out main_inner(float fClipDistance3_param, float fClipDistance4_param) {
fClipDistance3 = fClipDistance3_param; fClipDistance3 = fClipDistance3_param;
fClipDistance4 = fClipDistance4_param; fClipDistance4 = fClipDistance4_param;
main_1(); main_1();
if (tint_discard) { const main_out tint_symbol_8 = {glFragColor};
const main_out tint_symbol_8 = (main_out)0;
return tint_symbol_8; return tint_symbol_8;
}
const main_out tint_symbol_9 = {glFragColor};
return tint_symbol_9;
}
void tint_discard_func() {
discard;
} }
tint_symbol_2 main(tint_symbol_1 tint_symbol) { tint_symbol_2 main(tint_symbol_1 tint_symbol) {
const main_out inner_result = main_inner(tint_symbol.fClipDistance3_param, tint_symbol.fClipDistance4_param); const main_out inner_result = main_inner(tint_symbol.fClipDistance3_param, tint_symbol.fClipDistance4_param);
if (tint_discard) {
tint_discard_func();
const tint_symbol_2 tint_symbol_10 = (tint_symbol_2)0;
return tint_symbol_10;
}
tint_symbol_2 wrapper_result = (tint_symbol_2)0; tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.glFragColor_1 = inner_result.glFragColor_1; wrapper_result.glFragColor_1 = inner_result.glFragColor_1;
if (tint_discarded) {
discard;
}
return wrapper_result; return wrapper_result;
} }

View File

@ -1,3 +1,5 @@
static bool tint_discarded = false;
static float fClipDistance3 = 0.0f; static float fClipDistance3 = 0.0f;
static float fClipDistance4 = 0.0f; static float fClipDistance4 = 0.0f;
cbuffer cbuffer_x_29 : register(b0, space0) { cbuffer cbuffer_x_29 : register(b0, space0) {
@ -10,7 +12,6 @@ cbuffer cbuffer_x_137 : register(b2, space0) {
uint4 x_137[1]; uint4 x_137[1];
}; };
static float4 glFragColor = float4(0.0f, 0.0f, 0.0f, 0.0f); static float4 glFragColor = float4(0.0f, 0.0f, 0.0f, 0.0f);
static bool tint_discard = false;
void main_1() { void main_1() {
float3 viewDirectionW = float3(0.0f, 0.0f, 0.0f); float3 viewDirectionW = float3(0.0f, 0.0f, 0.0f);
@ -31,13 +32,11 @@ void main_1() {
float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f); float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
const float x_9 = fClipDistance3; const float x_9 = fClipDistance3;
if ((x_9 > 0.0f)) { if ((x_9 > 0.0f)) {
tint_discard = true; tint_discarded = true;
return;
} }
const float x_17 = fClipDistance4; const float x_17 = fClipDistance4;
if ((x_17 > 0.0f)) { if ((x_17 > 0.0f)) {
tint_discard = true; tint_discarded = true;
return;
} }
const float4 x_34 = asfloat(x_29[0]); const float4 x_34 = asfloat(x_29[0]);
const float3 x_38 = (0.0f).xxx; const float3 x_38 = (0.0f).xxx;
@ -105,26 +104,16 @@ main_out main_inner(float fClipDistance3_param, float fClipDistance4_param) {
fClipDistance3 = fClipDistance3_param; fClipDistance3 = fClipDistance3_param;
fClipDistance4 = fClipDistance4_param; fClipDistance4 = fClipDistance4_param;
main_1(); main_1();
if (tint_discard) { const main_out tint_symbol_8 = {glFragColor};
const main_out tint_symbol_8 = (main_out)0;
return tint_symbol_8; return tint_symbol_8;
}
const main_out tint_symbol_9 = {glFragColor};
return tint_symbol_9;
}
void tint_discard_func() {
discard;
} }
tint_symbol_2 main(tint_symbol_1 tint_symbol) { tint_symbol_2 main(tint_symbol_1 tint_symbol) {
const main_out inner_result = main_inner(tint_symbol.fClipDistance3_param, tint_symbol.fClipDistance4_param); const main_out inner_result = main_inner(tint_symbol.fClipDistance3_param, tint_symbol.fClipDistance4_param);
if (tint_discard) {
tint_discard_func();
const tint_symbol_2 tint_symbol_10 = (tint_symbol_2)0;
return tint_symbol_10;
}
tint_symbol_2 wrapper_result = (tint_symbol_2)0; tint_symbol_2 wrapper_result = (tint_symbol_2)0;
wrapper_result.glFragColor_1 = inner_result.glFragColor_1; wrapper_result.glFragColor_1 = inner_result.glFragColor_1;
if (tint_discarded) {
discard;
}
return wrapper_result; return wrapper_result;
} }

View File

@ -1,6 +1,7 @@
#version 310 es #version 310 es
precision mediump float; precision mediump float;
bool tint_discarded = false;
layout(location = 2) in float fClipDistance3_param_1; layout(location = 2) in float fClipDistance3_param_1;
layout(location = 3) in float fClipDistance4_param_1; layout(location = 3) in float fClipDistance4_param_1;
layout(location = 0) out vec4 glFragColor_1_1; layout(location = 0) out vec4 glFragColor_1_1;
@ -38,7 +39,6 @@ layout(binding = 2, std140) uniform x_137_block_ubo {
} x_137; } x_137;
vec4 glFragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f); vec4 glFragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
bool tint_discard = false;
void main_1() { void main_1() {
vec3 viewDirectionW = vec3(0.0f, 0.0f, 0.0f); vec3 viewDirectionW = vec3(0.0f, 0.0f, 0.0f);
vec4 baseColor = vec4(0.0f, 0.0f, 0.0f, 0.0f); vec4 baseColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
@ -58,13 +58,11 @@ void main_1() {
vec4 color = vec4(0.0f, 0.0f, 0.0f, 0.0f); vec4 color = vec4(0.0f, 0.0f, 0.0f, 0.0f);
float x_9 = fClipDistance3; float x_9 = fClipDistance3;
if ((x_9 > 0.0f)) { if ((x_9 > 0.0f)) {
tint_discard = true; tint_discarded = true;
return;
} }
float x_17 = fClipDistance4; float x_17 = fClipDistance4;
if ((x_17 > 0.0f)) { if ((x_17 > 0.0f)) {
tint_discard = true; tint_discarded = true;
return;
} }
vec4 x_34 = x_29.inner.vEyePosition; vec4 x_34 = x_29.inner.vEyePosition;
vec3 x_38 = vec3(0.0f); vec3 x_38 = vec3(0.0f);
@ -125,24 +123,15 @@ main_out tint_symbol(float fClipDistance3_param, float fClipDistance4_param) {
fClipDistance3 = fClipDistance3_param; fClipDistance3 = fClipDistance3_param;
fClipDistance4 = fClipDistance4_param; fClipDistance4 = fClipDistance4_param;
main_1(); main_1();
if (tint_discard) { main_out tint_symbol_1 = main_out(glFragColor);
main_out tint_symbol_1 = main_out(vec4(0.0f));
return tint_symbol_1; return tint_symbol_1;
}
main_out tint_symbol_2 = main_out(glFragColor);
return tint_symbol_2;
}
void tint_discard_func() {
discard;
} }
void main() { void main() {
main_out inner_result = tint_symbol(fClipDistance3_param_1, fClipDistance4_param_1); main_out inner_result = tint_symbol(fClipDistance3_param_1, fClipDistance4_param_1);
if (tint_discard) {
tint_discard_func();
return;
}
glFragColor_1_1 = inner_result.glFragColor_1; glFragColor_1_1 = inner_result.glFragColor_1;
if (tint_discarded) {
discard;
}
return; return;
} }

View File

@ -17,7 +17,7 @@ struct Mesh {
/* 0x0000 */ float visibility; /* 0x0000 */ float visibility;
}; };
void main_1(thread float* const tint_symbol_7, thread bool* const tint_symbol_8, thread float* const tint_symbol_9, const constant Scene* const tint_symbol_10, const constant Material* const tint_symbol_11, const constant Mesh* const tint_symbol_12, thread float4* const tint_symbol_13) { void main_1(thread float* const tint_symbol_5, thread bool* const tint_symbol_6, thread float* const tint_symbol_7, const constant Scene* const tint_symbol_8, const constant Material* const tint_symbol_9, const constant Mesh* const tint_symbol_10, thread float4* const tint_symbol_11) {
float3 viewDirectionW = 0.0f; float3 viewDirectionW = 0.0f;
float4 baseColor = 0.0f; float4 baseColor = 0.0f;
float3 diffuseColor = 0.0f; float3 diffuseColor = 0.0f;
@ -34,23 +34,21 @@ void main_1(thread float* const tint_symbol_7, thread bool* const tint_symbol_8,
float3 finalDiffuse = 0.0f; float3 finalDiffuse = 0.0f;
float3 finalSpecular = 0.0f; float3 finalSpecular = 0.0f;
float4 color = 0.0f; float4 color = 0.0f;
float const x_9 = *(tint_symbol_7); float const x_9 = *(tint_symbol_5);
if ((x_9 > 0.0f)) { if ((x_9 > 0.0f)) {
*(tint_symbol_8) = true; *(tint_symbol_6) = true;
return;
} }
float const x_17 = *(tint_symbol_9); float const x_17 = *(tint_symbol_7);
if ((x_17 > 0.0f)) { if ((x_17 > 0.0f)) {
*(tint_symbol_8) = true; *(tint_symbol_6) = true;
return;
} }
float4 const x_34 = (*(tint_symbol_10)).vEyePosition; float4 const x_34 = (*(tint_symbol_8)).vEyePosition;
float3 const x_38 = float3(0.0f); float3 const x_38 = float3(0.0f);
viewDirectionW = normalize((float3(x_34[0], x_34[1], x_34[2]) - x_38)); viewDirectionW = normalize((float3(x_34[0], x_34[1], x_34[2]) - x_38));
baseColor = float4(1.0f); baseColor = float4(1.0f);
float4 const x_52 = (*(tint_symbol_11)).vDiffuseColor; float4 const x_52 = (*(tint_symbol_9)).vDiffuseColor;
diffuseColor = float3(x_52[0], x_52[1], x_52[2]); diffuseColor = float3(x_52[0], x_52[1], x_52[2]);
float const x_60 = (*(tint_symbol_11)).vDiffuseColor[3]; float const x_60 = (*(tint_symbol_9)).vDiffuseColor[3];
alpha = x_60; alpha = x_60;
float3 const x_62 = float3(0.0f); float3 const x_62 = float3(0.0f);
float3 const x_64 = float3(0.0f); float3 const x_64 = float3(0.0f);
@ -66,12 +64,12 @@ void main_1(thread float* const tint_symbol_7, thread bool* const tint_symbol_8,
shadow = 1.0f; shadow = 1.0f;
refractionColor = float4(0.0f, 0.0f, 0.0f, 1.0f); refractionColor = float4(0.0f, 0.0f, 0.0f, 1.0f);
reflectionColor = float4(0.0f, 0.0f, 0.0f, 1.0f); reflectionColor = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 const x_94 = float3((*(tint_symbol_11)).vEmissiveColor); float3 const x_94 = float3((*(tint_symbol_9)).vEmissiveColor);
emissiveColor = x_94; emissiveColor = x_94;
float3 const x_96 = diffuseBase; float3 const x_96 = diffuseBase;
float3 const x_97 = diffuseColor; float3 const x_97 = diffuseColor;
float3 const x_99 = emissiveColor; float3 const x_99 = emissiveColor;
float3 const x_103 = float3((*(tint_symbol_11)).vAmbientColor); float3 const x_103 = float3((*(tint_symbol_9)).vAmbientColor);
float4 const x_108 = baseColor; float4 const x_108 = baseColor;
finalDiffuse = (clamp((((x_96 * x_97) + x_99) + x_103), float3(0.0f), float3(1.0f)) * float3(x_108[0], x_108[1], x_108[2])); finalDiffuse = (clamp((((x_96 * x_97) + x_99) + x_103), float3(0.0f), float3(1.0f)) * float3(x_108[0], x_108[1], x_108[2]));
finalSpecular = float3(0.0f); finalSpecular = float3(0.0f);
@ -87,11 +85,11 @@ void main_1(thread float* const tint_symbol_7, thread bool* const tint_symbol_8,
float3 const x_132 = fmax(float3(x_129[0], x_129[1], x_129[2]), float3(0.0f)); float3 const x_132 = fmax(float3(x_129[0], x_129[1], x_129[2]), float3(0.0f));
float4 const x_133 = color; float4 const x_133 = color;
color = float4(x_132[0], x_132[1], x_132[2], x_133[3]); color = float4(x_132[0], x_132[1], x_132[2], x_133[3]);
float const x_140 = (*(tint_symbol_12)).visibility; float const x_140 = (*(tint_symbol_10)).visibility;
float const x_142 = color[3]; float const x_142 = color[3];
color[3] = (x_142 * x_140); color[3] = (x_142 * x_140);
float4 const x_147 = color; float4 const x_147 = color;
*(tint_symbol_13) = x_147; *(tint_symbol_11) = x_147;
return; return;
} }
@ -108,35 +106,25 @@ struct tint_symbol_3 {
float4 glFragColor_1 [[color(0)]]; float4 glFragColor_1 [[color(0)]];
}; };
main_out tint_symbol_inner(float fClipDistance3_param, float fClipDistance4_param, thread float* const tint_symbol_14, thread float* const tint_symbol_15, thread bool* const tint_symbol_16, const constant Scene* const tint_symbol_17, const constant Material* const tint_symbol_18, const constant Mesh* const tint_symbol_19, thread float4* const tint_symbol_20) { main_out tint_symbol_inner(float fClipDistance3_param, float fClipDistance4_param, thread float* const tint_symbol_12, thread float* const tint_symbol_13, thread bool* const tint_symbol_14, const constant Scene* const tint_symbol_15, const constant Material* const tint_symbol_16, const constant Mesh* const tint_symbol_17, thread float4* const tint_symbol_18) {
*(tint_symbol_14) = fClipDistance3_param; *(tint_symbol_12) = fClipDistance3_param;
*(tint_symbol_15) = fClipDistance4_param; *(tint_symbol_13) = fClipDistance4_param;
main_1(tint_symbol_14, tint_symbol_16, tint_symbol_15, tint_symbol_17, tint_symbol_18, tint_symbol_19, tint_symbol_20); main_1(tint_symbol_12, tint_symbol_14, tint_symbol_13, tint_symbol_15, tint_symbol_16, tint_symbol_17, tint_symbol_18);
if (*(tint_symbol_16)) { main_out const tint_symbol_4 = {.glFragColor_1=*(tint_symbol_18)};
main_out const tint_symbol_4 = main_out{};
return tint_symbol_4; return tint_symbol_4;
}
main_out const tint_symbol_5 = {.glFragColor_1=*(tint_symbol_20)};
return tint_symbol_5;
} }
void tint_discard_func() { fragment tint_symbol_3 tint_symbol(const constant Scene* tint_symbol_22 [[buffer(0)]], const constant Material* tint_symbol_23 [[buffer(1)]], const constant Mesh* tint_symbol_24 [[buffer(2)]], tint_symbol_2 tint_symbol_1 [[stage_in]]) {
discard_fragment(); thread float tint_symbol_19 = 0.0f;
} thread float tint_symbol_20 = 0.0f;
thread bool tint_symbol_21 = false;
fragment tint_symbol_3 tint_symbol(const constant Scene* tint_symbol_24 [[buffer(0)]], const constant Material* tint_symbol_25 [[buffer(1)]], const constant Mesh* tint_symbol_26 [[buffer(2)]], tint_symbol_2 tint_symbol_1 [[stage_in]]) { thread float4 tint_symbol_25 = 0.0f;
thread float tint_symbol_21 = 0.0f; main_out const inner_result = tint_symbol_inner(tint_symbol_1.fClipDistance3_param, tint_symbol_1.fClipDistance4_param, &(tint_symbol_19), &(tint_symbol_20), &(tint_symbol_21), tint_symbol_22, tint_symbol_23, tint_symbol_24, &(tint_symbol_25));
thread float tint_symbol_22 = 0.0f;
thread bool tint_symbol_23 = false;
thread float4 tint_symbol_27 = 0.0f;
main_out const inner_result = tint_symbol_inner(tint_symbol_1.fClipDistance3_param, tint_symbol_1.fClipDistance4_param, &(tint_symbol_21), &(tint_symbol_22), &(tint_symbol_23), tint_symbol_24, tint_symbol_25, tint_symbol_26, &(tint_symbol_27));
if (tint_symbol_23) {
tint_discard_func();
tint_symbol_3 const tint_symbol_6 = tint_symbol_3{};
return tint_symbol_6;
}
tint_symbol_3 wrapper_result = {}; tint_symbol_3 wrapper_result = {};
wrapper_result.glFragColor_1 = inner_result.glFragColor_1; wrapper_result.glFragColor_1 = inner_result.glFragColor_1;
if (tint_symbol_21) {
discard_fragment();
}
return wrapper_result; return wrapper_result;
} }

View File

@ -1,13 +1,14 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 202 ; Bound: 188
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
%84 = OpExtInstImport "GLSL.std.450" %74 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %fClipDistance3_param_1 %fClipDistance4_param_1 %glFragColor_1_1 OpEntryPoint Fragment %main "main" %fClipDistance3_param_1 %fClipDistance4_param_1 %glFragColor_1_1
OpExecutionMode %main OriginUpperLeft OpExecutionMode %main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %fClipDistance3_param_1 "fClipDistance3_param_1" OpName %fClipDistance3_param_1 "fClipDistance3_param_1"
OpName %fClipDistance4_param_1 "fClipDistance4_param_1" OpName %fClipDistance4_param_1 "fClipDistance4_param_1"
OpName %glFragColor_1_1 "glFragColor_1_1" OpName %glFragColor_1_1 "glFragColor_1_1"
@ -33,9 +34,7 @@
OpMemberName %Mesh 0 "visibility" OpMemberName %Mesh 0 "visibility"
OpName %x_137 "x_137" OpName %x_137 "x_137"
OpName %glFragColor "glFragColor" OpName %glFragColor "glFragColor"
OpName %tint_discard "tint_discard"
OpName %main_1 "main_1" OpName %main_1 "main_1"
OpName %tint_return_flag "tint_return_flag"
OpName %viewDirectionW "viewDirectionW" OpName %viewDirectionW "viewDirectionW"
OpName %baseColor "baseColor" OpName %baseColor "baseColor"
OpName %diffuseColor "diffuseColor" OpName %diffuseColor "diffuseColor"
@ -52,7 +51,6 @@
OpName %finalDiffuse "finalDiffuse" OpName %finalDiffuse "finalDiffuse"
OpName %finalSpecular "finalSpecular" OpName %finalSpecular "finalSpecular"
OpName %color "color" OpName %color "color"
OpName %tint_discard_func "tint_discard_func"
OpName %main_out "main_out" OpName %main_out "main_out"
OpMemberName %main_out 0 "glFragColor_1" OpMemberName %main_out 0 "glFragColor_1"
OpName %main_inner "main_inner" OpName %main_inner "main_inner"
@ -85,18 +83,22 @@
OpDecorate %x_137 DescriptorSet 0 OpDecorate %x_137 DescriptorSet 0
OpDecorate %x_137 Binding 2 OpDecorate %x_137 Binding 2
OpMemberDecorate %main_out 0 Offset 0 OpMemberDecorate %main_out 0 Offset 0
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%_ptr_Input_float = OpTypePointer Input %float %_ptr_Input_float = OpTypePointer Input %float
%fClipDistance3_param_1 = OpVariable %_ptr_Input_float Input %fClipDistance3_param_1 = OpVariable %_ptr_Input_float Input
%fClipDistance4_param_1 = OpVariable %_ptr_Input_float Input %fClipDistance4_param_1 = OpVariable %_ptr_Input_float Input
%v4float = OpTypeVector %float 4 %v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float %_ptr_Output_v4float = OpTypePointer Output %v4float
%8 = OpConstantNull %v4float %12 = OpConstantNull %v4float
%glFragColor_1_1 = OpVariable %_ptr_Output_v4float Output %8 %glFragColor_1_1 = OpVariable %_ptr_Output_v4float Output %12
%_ptr_Private_float = OpTypePointer Private %float %_ptr_Private_float = OpTypePointer Private %float
%11 = OpConstantNull %float %15 = OpConstantNull %float
%fClipDistance3 = OpVariable %_ptr_Private_float Private %11 %fClipDistance3 = OpVariable %_ptr_Private_float Private %15
%fClipDistance4 = OpVariable %_ptr_Private_float Private %11 %fClipDistance4 = OpVariable %_ptr_Private_float Private %15
%Scene = OpTypeStruct %v4float %Scene = OpTypeStruct %v4float
%x_29_block = OpTypeStruct %Scene %x_29_block = OpTypeStruct %Scene
%_ptr_Uniform_x_29_block = OpTypePointer Uniform %x_29_block %_ptr_Uniform_x_29_block = OpTypePointer Uniform %x_29_block
@ -111,227 +113,198 @@
%_ptr_Uniform_x_137_block = OpTypePointer Uniform %x_137_block %_ptr_Uniform_x_137_block = OpTypePointer Uniform %x_137_block
%x_137 = OpVariable %_ptr_Uniform_x_137_block Uniform %x_137 = OpVariable %_ptr_Uniform_x_137_block Uniform
%_ptr_Private_v4float = OpTypePointer Private %v4float %_ptr_Private_v4float = OpTypePointer Private %v4float
%glFragColor = OpVariable %_ptr_Private_v4float Private %8 %glFragColor = OpVariable %_ptr_Private_v4float Private %12
%bool = OpTypeBool
%29 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discard = OpVariable %_ptr_Private_bool Private %29
%void = OpTypeVoid %void = OpTypeVoid
%32 = OpTypeFunction %void %32 = OpTypeFunction %void
%_ptr_Function_bool = OpTypePointer Function %bool
%_ptr_Function_v3float = OpTypePointer Function %v3float %_ptr_Function_v3float = OpTypePointer Function %v3float
%40 = OpConstantNull %v3float %38 = OpConstantNull %v3float
%_ptr_Function_v4float = OpTypePointer Function %v4float %_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Function_float = OpTypePointer Function %float %_ptr_Function_float = OpTypePointer Function %float
%v2float = OpTypeVector %float 2 %v2float = OpTypeVector %float 2
%_ptr_Function_v2float = OpTypePointer Function %v2float %_ptr_Function_v2float = OpTypePointer Function %v2float
%50 = OpConstantNull %v2float %48 = OpConstantNull %v2float
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%uint = OpTypeInt 32 0 %uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0 %uint_0 = OpConstant %uint 0
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float %_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%91 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1 %81 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%uint_3 = OpConstant %uint 3 %uint_3 = OpConstant %uint 3
%_ptr_Uniform_float = OpTypePointer Uniform %float %_ptr_Uniform_float = OpTypePointer Uniform %float
%118 = OpConstantComposite %v3float %float_1 %float_1 %float_1 %108 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%119 = OpConstantComposite %v4float %11 %11 %11 %float_1 %109 = OpConstantComposite %v4float %15 %15 %15 %float_1
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float %_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
%uint_1 = OpConstant %uint 1 %uint_1 = OpConstant %uint 1
%main_out = OpTypeStruct %v4float %main_out = OpTypeStruct %v4float
%182 = OpTypeFunction %main_out %float %float %170 = OpTypeFunction %main_out %float %float
%193 = OpConstantNull %main_out
%main_1 = OpFunction %void None %32 %main_1 = OpFunction %void None %32
%35 = OpLabel %35 = OpLabel
%tint_return_flag = OpVariable %_ptr_Function_bool Function %29 %viewDirectionW = OpVariable %_ptr_Function_v3float Function %38
%viewDirectionW = OpVariable %_ptr_Function_v3float Function %40 %baseColor = OpVariable %_ptr_Function_v4float Function %12
%baseColor = OpVariable %_ptr_Function_v4float Function %8 %diffuseColor = OpVariable %_ptr_Function_v3float Function %38
%diffuseColor = OpVariable %_ptr_Function_v3float Function %40 %alpha = OpVariable %_ptr_Function_float Function %15
%alpha = OpVariable %_ptr_Function_float Function %11 %normalW = OpVariable %_ptr_Function_v3float Function %38
%normalW = OpVariable %_ptr_Function_v3float Function %40 %uvOffset = OpVariable %_ptr_Function_v2float Function %48
%uvOffset = OpVariable %_ptr_Function_v2float Function %50 %baseAmbientColor = OpVariable %_ptr_Function_v3float Function %38
%baseAmbientColor = OpVariable %_ptr_Function_v3float Function %40 %glossiness = OpVariable %_ptr_Function_float Function %15
%glossiness = OpVariable %_ptr_Function_float Function %11 %diffuseBase = OpVariable %_ptr_Function_v3float Function %38
%diffuseBase = OpVariable %_ptr_Function_v3float Function %40 %shadow = OpVariable %_ptr_Function_float Function %15
%shadow = OpVariable %_ptr_Function_float Function %11 %refractionColor = OpVariable %_ptr_Function_v4float Function %12
%refractionColor = OpVariable %_ptr_Function_v4float Function %8 %reflectionColor = OpVariable %_ptr_Function_v4float Function %12
%reflectionColor = OpVariable %_ptr_Function_v4float Function %8 %emissiveColor = OpVariable %_ptr_Function_v3float Function %38
%emissiveColor = OpVariable %_ptr_Function_v3float Function %40 %finalDiffuse = OpVariable %_ptr_Function_v3float Function %38
%finalDiffuse = OpVariable %_ptr_Function_v3float Function %40 %finalSpecular = OpVariable %_ptr_Function_v3float Function %38
%finalSpecular = OpVariable %_ptr_Function_v3float Function %40 %color = OpVariable %_ptr_Function_v4float Function %12
%color = OpVariable %_ptr_Function_v4float Function %8 %59 = OpLoad %float %fClipDistance3
%61 = OpLoad %float %fClipDistance3 %60 = OpFOrdGreaterThan %bool %59 %15
%62 = OpFOrdGreaterThan %bool %61 %11 OpSelectionMerge %61 None
OpSelectionMerge %63 None OpBranchConditional %60 %62 %61
OpBranchConditional %62 %64 %63 %62 = OpLabel
%64 = OpLabel OpStore %tint_discarded %true
OpStore %tint_discard %true OpBranch %61
OpStore %tint_return_flag %true %61 = OpLabel
OpBranch %63 %64 = OpLoad %float %fClipDistance4
%63 = OpLabel %65 = OpFOrdGreaterThan %bool %64 %15
%67 = OpLoad %bool %tint_return_flag OpSelectionMerge %66 None
%66 = OpLogicalNot %bool %67 OpBranchConditional %65 %67 %66
OpSelectionMerge %68 None %67 = OpLabel
OpBranchConditional %66 %69 %68 OpStore %tint_discarded %true
%69 = OpLabel OpBranch %66
%70 = OpLoad %float %fClipDistance4 %66 = OpLabel
%71 = OpFOrdGreaterThan %bool %70 %11 %71 = OpAccessChain %_ptr_Uniform_v4float %x_29 %uint_0 %uint_0
OpSelectionMerge %72 None %72 = OpLoad %v4float %71
OpBranchConditional %71 %73 %72 %75 = OpCompositeExtract %float %72 0
%73 = OpLabel %76 = OpCompositeExtract %float %72 1
OpStore %tint_discard %true %77 = OpCompositeExtract %float %72 2
OpStore %tint_return_flag %true %78 = OpCompositeConstruct %v3float %75 %76 %77
OpBranch %72 %79 = OpFSub %v3float %78 %38
%72 = OpLabel %73 = OpExtInst %v3float %74 Normalize %79
%75 = OpLoad %bool %tint_return_flag OpStore %viewDirectionW %73
%74 = OpLogicalNot %bool %75 OpStore %baseColor %81
OpSelectionMerge %76 None %82 = OpAccessChain %_ptr_Uniform_v4float %x_49 %uint_0 %uint_0
OpBranchConditional %74 %77 %76 %83 = OpLoad %v4float %82
%77 = OpLabel %84 = OpCompositeExtract %float %83 0
%81 = OpAccessChain %_ptr_Uniform_v4float %x_29 %uint_0 %uint_0 %85 = OpCompositeExtract %float %83 1
%82 = OpLoad %v4float %81 %86 = OpCompositeExtract %float %83 2
%85 = OpCompositeExtract %float %82 0 %87 = OpCompositeConstruct %v3float %84 %85 %86
%86 = OpCompositeExtract %float %82 1 OpStore %diffuseColor %87
%87 = OpCompositeExtract %float %82 2 %90 = OpAccessChain %_ptr_Uniform_float %x_49 %uint_0 %uint_0 %uint_3
%88 = OpCompositeConstruct %v3float %85 %86 %87 %91 = OpLoad %float %90
%89 = OpFSub %v3float %88 %40 OpStore %alpha %91
%83 = OpExtInst %v3float %84 Normalize %89 OpStore %uvOffset %48
OpStore %viewDirectionW %83 %92 = OpLoad %v4float %baseColor
OpStore %baseColor %91 %93 = OpCompositeExtract %float %92 0
%92 = OpAccessChain %_ptr_Uniform_v4float %x_49 %uint_0 %uint_0 %94 = OpCompositeExtract %float %92 1
%93 = OpLoad %v4float %92 %95 = OpCompositeExtract %float %92 2
%94 = OpCompositeExtract %float %93 0 %96 = OpCompositeConstruct %v3float %93 %94 %95
%95 = OpCompositeExtract %float %93 1 %97 = OpCompositeExtract %float %12 0
%96 = OpCompositeExtract %float %93 2 %98 = OpCompositeExtract %float %12 1
%97 = OpCompositeConstruct %v3float %94 %95 %96 %99 = OpCompositeExtract %float %12 2
OpStore %diffuseColor %97 %100 = OpCompositeConstruct %v3float %97 %98 %99
%100 = OpAccessChain %_ptr_Uniform_float %x_49 %uint_0 %uint_0 %uint_3 %101 = OpFMul %v3float %96 %100
%101 = OpLoad %float %100
OpStore %alpha %101
OpStore %uvOffset %50
%102 = OpLoad %v4float %baseColor %102 = OpLoad %v4float %baseColor
%103 = OpCompositeExtract %float %102 0 %103 = OpCompositeExtract %float %101 0
%104 = OpCompositeExtract %float %102 1 %104 = OpCompositeExtract %float %101 1
%105 = OpCompositeExtract %float %102 2 %105 = OpCompositeExtract %float %101 2
%106 = OpCompositeConstruct %v3float %103 %104 %105 %106 = OpCompositeExtract %float %102 3
%107 = OpCompositeExtract %float %8 0 %107 = OpCompositeConstruct %v4float %103 %104 %105 %106
%108 = OpCompositeExtract %float %8 1 OpStore %baseColor %107
%109 = OpCompositeExtract %float %8 2 OpStore %baseAmbientColor %108
%110 = OpCompositeConstruct %v3float %107 %108 %109 OpStore %glossiness %15
%111 = OpFMul %v3float %106 %110 OpStore %diffuseBase %38
%112 = OpLoad %v4float %baseColor
%113 = OpCompositeExtract %float %111 0
%114 = OpCompositeExtract %float %111 1
%115 = OpCompositeExtract %float %111 2
%116 = OpCompositeExtract %float %112 3
%117 = OpCompositeConstruct %v4float %113 %114 %115 %116
OpStore %baseColor %117
OpStore %baseAmbientColor %118
OpStore %glossiness %11
OpStore %diffuseBase %40
OpStore %shadow %float_1 OpStore %shadow %float_1
OpStore %refractionColor %119 OpStore %refractionColor %109
OpStore %reflectionColor %119 OpStore %reflectionColor %109
%121 = OpAccessChain %_ptr_Uniform_v3float %x_49 %uint_0 %uint_3 %111 = OpAccessChain %_ptr_Uniform_v3float %x_49 %uint_0 %uint_3
%122 = OpLoad %v3float %121 %112 = OpLoad %v3float %111
OpStore %emissiveColor %122 OpStore %emissiveColor %112
%123 = OpLoad %v3float %diffuseBase %113 = OpLoad %v3float %diffuseBase
%124 = OpLoad %v3float %diffuseColor %114 = OpLoad %v3float %diffuseColor
%125 = OpLoad %v3float %emissiveColor %115 = OpLoad %v3float %emissiveColor
%127 = OpAccessChain %_ptr_Uniform_v3float %x_49 %uint_0 %uint_1 %117 = OpAccessChain %_ptr_Uniform_v3float %x_49 %uint_0 %uint_1
%128 = OpLoad %v3float %127 %118 = OpLoad %v3float %117
%129 = OpLoad %v4float %baseColor %119 = OpLoad %v4float %baseColor
%131 = OpFMul %v3float %123 %124 %121 = OpFMul %v3float %113 %114
%132 = OpFAdd %v3float %131 %125 %122 = OpFAdd %v3float %121 %115
%133 = OpFAdd %v3float %132 %128 %123 = OpFAdd %v3float %122 %118
%130 = OpExtInst %v3float %84 NClamp %133 %40 %118 %120 = OpExtInst %v3float %74 NClamp %123 %38 %108
%134 = OpCompositeExtract %float %129 0 %124 = OpCompositeExtract %float %119 0
%135 = OpCompositeExtract %float %129 1 %125 = OpCompositeExtract %float %119 1
%136 = OpCompositeExtract %float %129 2 %126 = OpCompositeExtract %float %119 2
%137 = OpCompositeConstruct %v3float %134 %135 %136 %127 = OpCompositeConstruct %v3float %124 %125 %126
%138 = OpFMul %v3float %130 %137 %128 = OpFMul %v3float %120 %127
OpStore %finalDiffuse %138 OpStore %finalDiffuse %128
OpStore %finalSpecular %40 OpStore %finalSpecular %38
%139 = OpLoad %v3float %finalDiffuse %129 = OpLoad %v3float %finalDiffuse
%140 = OpLoad %v3float %baseAmbientColor %130 = OpLoad %v3float %baseAmbientColor
%141 = OpLoad %v3float %finalSpecular %131 = OpLoad %v3float %finalSpecular
%142 = OpLoad %v4float %reflectionColor %132 = OpLoad %v4float %reflectionColor
%143 = OpLoad %v4float %refractionColor %133 = OpLoad %v4float %refractionColor
%144 = OpFMul %v3float %139 %140 %134 = OpFMul %v3float %129 %130
%145 = OpFAdd %v3float %144 %141 %135 = OpFAdd %v3float %134 %131
%146 = OpCompositeExtract %float %142 0 %136 = OpCompositeExtract %float %132 0
%147 = OpCompositeExtract %float %142 1 %137 = OpCompositeExtract %float %132 1
%148 = OpCompositeExtract %float %142 2 %138 = OpCompositeExtract %float %132 2
%149 = OpCompositeConstruct %v3float %146 %147 %148 %139 = OpCompositeConstruct %v3float %136 %137 %138
%150 = OpFAdd %v3float %145 %149 %140 = OpFAdd %v3float %135 %139
%151 = OpCompositeExtract %float %143 0 %141 = OpCompositeExtract %float %133 0
%152 = OpCompositeExtract %float %143 1 %142 = OpCompositeExtract %float %133 1
%153 = OpCompositeExtract %float %143 2 %143 = OpCompositeExtract %float %133 2
%154 = OpCompositeConstruct %v3float %151 %152 %153 %144 = OpCompositeConstruct %v3float %141 %142 %143
%155 = OpFAdd %v3float %150 %154 %145 = OpFAdd %v3float %140 %144
%156 = OpLoad %float %alpha %146 = OpLoad %float %alpha
%157 = OpCompositeExtract %float %155 0 %147 = OpCompositeExtract %float %145 0
%158 = OpCompositeExtract %float %155 1 %148 = OpCompositeExtract %float %145 1
%159 = OpCompositeExtract %float %155 2 %149 = OpCompositeExtract %float %145 2
%160 = OpCompositeConstruct %v4float %157 %158 %159 %156 %150 = OpCompositeConstruct %v4float %147 %148 %149 %146
OpStore %color %160 OpStore %color %150
%161 = OpLoad %v4float %color %151 = OpLoad %v4float %color
%163 = OpCompositeExtract %float %161 0 %153 = OpCompositeExtract %float %151 0
%164 = OpCompositeExtract %float %161 1 %154 = OpCompositeExtract %float %151 1
%165 = OpCompositeExtract %float %161 2 %155 = OpCompositeExtract %float %151 2
%166 = OpCompositeConstruct %v3float %163 %164 %165 %156 = OpCompositeConstruct %v3float %153 %154 %155
%162 = OpExtInst %v3float %84 NMax %166 %40 %152 = OpExtInst %v3float %74 NMax %156 %38
%167 = OpLoad %v4float %color %157 = OpLoad %v4float %color
%168 = OpCompositeExtract %float %162 0 %158 = OpCompositeExtract %float %152 0
%169 = OpCompositeExtract %float %162 1 %159 = OpCompositeExtract %float %152 1
%170 = OpCompositeExtract %float %162 2 %160 = OpCompositeExtract %float %152 2
%171 = OpCompositeExtract %float %167 3 %161 = OpCompositeExtract %float %157 3
%172 = OpCompositeConstruct %v4float %168 %169 %170 %171 %162 = OpCompositeConstruct %v4float %158 %159 %160 %161
OpStore %color %172 OpStore %color %162
%173 = OpAccessChain %_ptr_Uniform_float %x_137 %uint_0 %uint_0 %163 = OpAccessChain %_ptr_Uniform_float %x_137 %uint_0 %uint_0
%174 = OpLoad %float %173 %164 = OpLoad %float %163
%175 = OpAccessChain %_ptr_Function_float %color %uint_3 %165 = OpAccessChain %_ptr_Function_float %color %uint_3
%176 = OpLoad %float %175 %166 = OpLoad %float %165
%177 = OpAccessChain %_ptr_Function_float %color %uint_3 %167 = OpAccessChain %_ptr_Function_float %color %uint_3
%178 = OpFMul %float %176 %174 %168 = OpFMul %float %166 %164
OpStore %177 %178 OpStore %167 %168
%179 = OpLoad %v4float %color %169 = OpLoad %v4float %color
OpStore %glFragColor %179 OpStore %glFragColor %169
OpStore %tint_return_flag %true
OpBranch %76
%76 = OpLabel
OpBranch %68
%68 = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%tint_discard_func = OpFunction %void None %32 %main_inner = OpFunction %main_out None %170
%181 = OpLabel
OpKill
OpFunctionEnd
%main_inner = OpFunction %main_out None %182
%fClipDistance3_param = OpFunctionParameter %float %fClipDistance3_param = OpFunctionParameter %float
%fClipDistance4_param = OpFunctionParameter %float %fClipDistance4_param = OpFunctionParameter %float
%187 = OpLabel %175 = OpLabel
OpStore %fClipDistance3 %fClipDistance3_param OpStore %fClipDistance3 %fClipDistance3_param
OpStore %fClipDistance4 %fClipDistance4_param OpStore %fClipDistance4 %fClipDistance4_param
%188 = OpFunctionCall %void %main_1 %176 = OpFunctionCall %void %main_1
%189 = OpLoad %bool %tint_discard %177 = OpLoad %v4float %glFragColor
OpSelectionMerge %190 None %178 = OpCompositeConstruct %main_out %177
OpBranchConditional %189 %191 %190 OpReturnValue %178
%191 = OpLabel
%192 = OpFunctionCall %void %tint_discard_func
OpReturnValue %193
%190 = OpLabel
%194 = OpLoad %v4float %glFragColor
%195 = OpCompositeConstruct %main_out %194
OpReturnValue %195
OpFunctionEnd OpFunctionEnd
%main = OpFunction %void None %32 %main = OpFunction %void None %32
%197 = OpLabel %180 = OpLabel
%199 = OpLoad %float %fClipDistance3_param_1 %182 = OpLoad %float %fClipDistance3_param_1
%200 = OpLoad %float %fClipDistance4_param_1 %183 = OpLoad %float %fClipDistance4_param_1
%198 = OpFunctionCall %main_out %main_inner %199 %200 %181 = OpFunctionCall %main_out %main_inner %182 %183
%201 = OpCompositeExtract %v4float %198 0 %184 = OpCompositeExtract %v4float %181 0
OpStore %glFragColor_1_1 %201 OpStore %glFragColor_1_1 %184
%185 = OpLoad %bool %tint_discarded
OpSelectionMerge %186 None
OpBranchConditional %185 %187 %186
%187 = OpLabel
OpKill
%186 = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,29 +1,15 @@
bug/tint/1369.wgsl:3:3 warning: code is unreachable static bool tint_discarded = false;
return true;
^^^^^^
bug/tint/1369.wgsl:9:5 warning: code is unreachable
var also_unreachable : bool;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
static bool tint_discard = false;
bool call_discard() { bool call_discard() {
tint_discard = true; tint_discarded = true;
return false;
return true; return true;
} }
void tint_discard_func() {
discard;
}
void f() { void f() {
bool v = call_discard(); bool v = call_discard();
if (tint_discard) {
tint_discard_func();
return;
}
bool also_unreachable = false; bool also_unreachable = false;
if (tint_discarded) {
discard;
}
return; return;
} }

View File

@ -1,29 +1,15 @@
bug/tint/1369.wgsl:3:3 warning: code is unreachable static bool tint_discarded = false;
return true;
^^^^^^
bug/tint/1369.wgsl:9:5 warning: code is unreachable
var also_unreachable : bool;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
static bool tint_discard = false;
bool call_discard() { bool call_discard() {
tint_discard = true; tint_discarded = true;
return false;
return true; return true;
} }
void tint_discard_func() {
discard;
}
void f() { void f() {
bool v = call_discard(); bool v = call_discard();
if (tint_discard) {
tint_discard_func();
return;
}
bool also_unreachable = false; bool also_unreachable = false;
if (tint_discarded) {
discard;
}
return; return;
} }

View File

@ -1,38 +1,21 @@
bug/tint/1369.wgsl:3:3 warning: code is unreachable
return true;
^^^^^^
bug/tint/1369.wgsl:9:5 warning: code is unreachable
var also_unreachable : bool;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
#version 310 es #version 310 es
precision mediump float; precision mediump float;
bool tint_discard = false; bool tint_discarded = false;
bool call_discard() { bool call_discard() {
tint_discard = true; tint_discarded = true;
return false;
return true; return true;
} }
void f() { void f() {
bool v = call_discard(); bool v = call_discard();
if (tint_discard) {
return;
}
bool also_unreachable = false; bool also_unreachable = false;
} }
void tint_discard_func() {
discard;
}
void main() { void main() {
f(); f();
if (tint_discard) { if (tint_discarded) {
tint_discard_func(); discard;
return;
} }
return; return;
} }

View File

@ -1,32 +1,18 @@
bug/tint/1369.wgsl:3:3 warning: code is unreachable
return true;
^^^^^^
bug/tint/1369.wgsl:9:5 warning: code is unreachable
var also_unreachable : bool;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include <metal_stdlib> #include <metal_stdlib>
using namespace metal; using namespace metal;
bool call_discard(thread bool* const tint_symbol) { bool call_discard(thread bool* const tint_symbol) {
*(tint_symbol) = true; *(tint_symbol) = true;
return false;
return true; return true;
} }
void tint_discard_func() {
discard_fragment();
}
fragment void f() { fragment void f() {
thread bool tint_symbol_1 = false; thread bool tint_symbol_1 = false;
bool v = call_discard(&(tint_symbol_1)); bool v = call_discard(&(tint_symbol_1));
if (tint_symbol_1) {
tint_discard_func();
return;
}
bool also_unreachable = false; bool also_unreachable = false;
if (tint_symbol_1) {
discard_fragment();
}
return; return;
} }

View File

@ -1,29 +1,21 @@
bug/tint/1369.wgsl:3:3 warning: code is unreachable
return true;
^^^^^^
bug/tint/1369.wgsl:9:5 warning: code is unreachable
var also_unreachable : bool;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 22 ; Bound: 20
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %f "f" OpEntryPoint Fragment %f "f"
OpExecutionMode %f OriginUpperLeft OpExecutionMode %f OriginUpperLeft
OpName %tint_discard "tint_discard" OpName %tint_discarded "tint_discarded"
OpName %call_discard "call_discard" OpName %call_discard "call_discard"
OpName %tint_discard_func "tint_discard_func"
OpName %f "f" OpName %f "f"
OpName %v "v" OpName %v "v"
OpName %also_unreachable "also_unreachable"
%bool = OpTypeBool %bool = OpTypeBool
%2 = OpConstantNull %bool %2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool %_ptr_Private_bool = OpTypePointer Private %bool
%tint_discard = OpVariable %_ptr_Private_bool Private %2 %tint_discarded = OpVariable %_ptr_Private_bool Private %2
%5 = OpTypeFunction %bool %5 = OpTypeFunction %bool
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%void = OpTypeVoid %void = OpTypeVoid
@ -31,24 +23,20 @@ bug/tint/1369.wgsl:9:5 warning: code is unreachable
%_ptr_Function_bool = OpTypePointer Function %bool %_ptr_Function_bool = OpTypePointer Function %bool
%call_discard = OpFunction %bool None %5 %call_discard = OpFunction %bool None %5
%7 = OpLabel %7 = OpLabel
OpStore %tint_discard %true OpStore %tint_discarded %true
OpReturnValue %2 OpReturnValue %true
OpFunctionEnd
%tint_discard_func = OpFunction %void None %9
%12 = OpLabel
OpKill
OpFunctionEnd OpFunctionEnd
%f = OpFunction %void None %9 %f = OpFunction %void None %9
%14 = OpLabel %12 = OpLabel
%v = OpVariable %_ptr_Function_bool Function %2 %v = OpVariable %_ptr_Function_bool Function %2
%15 = OpFunctionCall %bool %call_discard %also_unreachable = OpVariable %_ptr_Function_bool Function %2
OpStore %v %15 %13 = OpFunctionCall %bool %call_discard
%18 = OpLoad %bool %tint_discard OpStore %v %13
OpSelectionMerge %19 None %17 = OpLoad %bool %tint_discarded
OpBranchConditional %18 %20 %19 OpSelectionMerge %18 None
%20 = OpLabel OpBranchConditional %17 %19 %18
%21 = OpFunctionCall %void %tint_discard_func
OpReturn
%19 = OpLabel %19 = OpLabel
OpKill
%18 = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,11 +1,3 @@
bug/tint/1369.wgsl:3:3 warning: code is unreachable
return true;
^^^^^^
bug/tint/1369.wgsl:9:5 warning: code is unreachable
var also_unreachable : bool;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
fn call_discard() -> bool { fn call_discard() -> bool {
discard; discard;
return true; return true;

View File

@ -0,0 +1,17 @@
@group(0) @binding(0) var t : texture_2d<f32>;
@group(0) @binding(1) var s : sampler;
@group(0) @binding(2) var<storage, read_write> a : atomic<i32>;
@fragment
fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i32 {
if (in == 0.0) {
discard;
}
var result = i32(textureSample(t, s, coord).x);
for (var i = 0; i < 10; i = atomicAdd(&a, 1)) {
result += i;
}
return result;
}

View File

@ -0,0 +1,55 @@
static bool tint_discarded = false;
Texture2D<float4> t : register(t0, space0);
SamplerState s : register(s1, space0);
RWByteAddressBuffer a : register(u2, space0);
struct tint_symbol_2 {
float tint_symbol : TEXCOORD0;
float2 coord : TEXCOORD1;
};
struct tint_symbol_3 {
int value : SV_Target0;
};
int tint_atomicAdd(RWByteAddressBuffer buffer, uint offset, int value) {
int original_value = 0;
buffer.InterlockedAdd(offset, value, original_value);
return original_value;
}
int foo_inner(float tint_symbol, float2 coord) {
if ((tint_symbol == 0.0f)) {
tint_discarded = true;
}
int result = int(t.Sample(s, coord).x);
{
int i = 0;
while (true) {
if (!((i < 10))) {
break;
}
{
result = (result + i);
}
{
int tint_symbol_4 = 0;
if (!(tint_discarded)) {
tint_symbol_4 = tint_atomicAdd(a, 0u, 1);
}
i = tint_symbol_4;
}
}
}
return result;
}
tint_symbol_3 foo(tint_symbol_2 tint_symbol_1) {
const int inner_result = foo_inner(tint_symbol_1.tint_symbol, tint_symbol_1.coord);
tint_symbol_3 wrapper_result = (tint_symbol_3)0;
wrapper_result.value = inner_result;
if (tint_discarded) {
discard;
}
return wrapper_result;
}

View File

@ -0,0 +1,55 @@
static bool tint_discarded = false;
Texture2D<float4> t : register(t0, space0);
SamplerState s : register(s1, space0);
RWByteAddressBuffer a : register(u2, space0);
struct tint_symbol_2 {
float tint_symbol : TEXCOORD0;
float2 coord : TEXCOORD1;
};
struct tint_symbol_3 {
int value : SV_Target0;
};
int tint_atomicAdd(RWByteAddressBuffer buffer, uint offset, int value) {
int original_value = 0;
buffer.InterlockedAdd(offset, value, original_value);
return original_value;
}
int foo_inner(float tint_symbol, float2 coord) {
if ((tint_symbol == 0.0f)) {
tint_discarded = true;
}
int result = int(t.Sample(s, coord).x);
{
int i = 0;
while (true) {
if (!((i < 10))) {
break;
}
{
result = (result + i);
}
{
int tint_symbol_4 = 0;
if (!(tint_discarded)) {
tint_symbol_4 = tint_atomicAdd(a, 0u, 1);
}
i = tint_symbol_4;
}
}
}
return result;
}
tint_symbol_3 foo(tint_symbol_2 tint_symbol_1) {
const int inner_result = foo_inner(tint_symbol_1.tint_symbol, tint_symbol_1.coord);
tint_symbol_3 wrapper_result = (tint_symbol_3)0;
wrapper_result.value = inner_result;
if (tint_discarded) {
discard;
}
return wrapper_result;
}

View File

@ -0,0 +1,47 @@
#version 310 es
precision mediump float;
bool tint_discarded = false;
layout(location = 0) in float tint_symbol_1;
layout(location = 1) in vec2 coord_1;
layout(location = 0) out int value;
layout(binding = 2, std430) buffer a_block_ssbo {
int inner;
} a;
uniform highp sampler2D t_s;
int foo(float tint_symbol, vec2 coord) {
if ((tint_symbol == 0.0f)) {
tint_discarded = true;
}
int result = int(texture(t_s, coord).x);
{
int i = 0;
while (true) {
if (!((i < 10))) {
break;
}
{
result = (result + i);
}
{
int tint_symbol_2 = 0;
if (!(tint_discarded)) {
tint_symbol_2 = atomicAdd(a.inner, 1);
}
i = tint_symbol_2;
}
}
}
return result;
}
void main() {
int inner_result = foo(tint_symbol_1, coord_1);
value = inner_result;
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,49 @@
#include <metal_stdlib>
using namespace metal;
struct tint_symbol_1 {
float in [[user(locn0)]];
float2 coord [[user(locn1)]];
};
struct tint_symbol_2 {
int value [[color(0)]];
};
int foo_inner(float in, float2 coord, thread bool* const tint_symbol_4, texture2d<float, access::sample> tint_symbol_5, sampler tint_symbol_6, device atomic_int* const tint_symbol_7) {
if ((in == 0.0f)) {
*(tint_symbol_4) = true;
}
int result = int(tint_symbol_5.sample(tint_symbol_6, coord)[0]);
{
int i = 0;
while (true) {
if (!((i < 10))) {
break;
}
{
result = as_type<int>((as_type<uint>(result) + as_type<uint>(i)));
}
{
int tint_symbol_3 = 0;
if (!(*(tint_symbol_4))) {
tint_symbol_3 = atomic_fetch_add_explicit(tint_symbol_7, 1, memory_order_relaxed);
}
i = tint_symbol_3;
}
}
}
return result;
}
fragment tint_symbol_2 foo(texture2d<float, access::sample> tint_symbol_9 [[texture(0)]], sampler tint_symbol_10 [[sampler(0)]], device atomic_int* tint_symbol_11 [[buffer(0)]], tint_symbol_1 tint_symbol [[stage_in]]) {
thread bool tint_symbol_8 = false;
int const inner_result = foo_inner(tint_symbol.in, tint_symbol.coord, &(tint_symbol_8), tint_symbol_9, tint_symbol_10, tint_symbol_11);
tint_symbol_2 wrapper_result = {};
wrapper_result.value = inner_result;
if (tint_symbol_8) {
discard_fragment();
}
return wrapper_result;
}

View File

@ -0,0 +1,145 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 83
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %foo "foo" %in_1 %coord_1 %value
OpExecutionMode %foo OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %in_1 "in_1"
OpName %coord_1 "coord_1"
OpName %value "value"
OpName %t "t"
OpName %s "s"
OpName %a_block "a_block"
OpMemberName %a_block 0 "inner"
OpName %a "a"
OpName %foo_inner "foo_inner"
OpName %in "in"
OpName %coord "coord"
OpName %result "result"
OpName %i "i"
OpName %tint_symbol "tint_symbol"
OpName %foo "foo"
OpDecorate %in_1 Location 0
OpDecorate %coord_1 Location 1
OpDecorate %value Location 0
OpDecorate %t DescriptorSet 0
OpDecorate %t Binding 0
OpDecorate %s DescriptorSet 0
OpDecorate %s Binding 1
OpDecorate %a_block Block
OpMemberDecorate %a_block 0 Offset 0
OpDecorate %a DescriptorSet 0
OpDecorate %a Binding 2
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%float = OpTypeFloat 32
%_ptr_Input_float = OpTypePointer Input %float
%in_1 = OpVariable %_ptr_Input_float Input
%v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%coord_1 = OpVariable %_ptr_Input_v2float Input
%int = OpTypeInt 32 1
%_ptr_Output_int = OpTypePointer Output %int
%14 = OpConstantNull %int
%value = OpVariable %_ptr_Output_int Output %14
%17 = OpTypeImage %float 2D 0 0 0 1 Unknown
%_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
%t = OpVariable %_ptr_UniformConstant_17 UniformConstant
%20 = OpTypeSampler
%_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
%s = OpVariable %_ptr_UniformConstant_20 UniformConstant
%a_block = OpTypeStruct %int
%_ptr_StorageBuffer_a_block = OpTypePointer StorageBuffer %a_block
%a = OpVariable %_ptr_StorageBuffer_a_block StorageBuffer
%24 = OpTypeFunction %int %float %v2float
%29 = OpConstantNull %float
%true = OpConstantTrue %bool
%v4float = OpTypeVector %float 4
%39 = OpTypeSampledImage %17
%_ptr_Function_int = OpTypePointer Function %int
%int_10 = OpConstant %int 10
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%int_1 = OpConstant %int 1
%void = OpTypeVoid
%73 = OpTypeFunction %void
%foo_inner = OpFunction %int None %24
%in = OpFunctionParameter %float
%coord = OpFunctionParameter %v2float
%28 = OpLabel
%result = OpVariable %_ptr_Function_int Function %14
%i = OpVariable %_ptr_Function_int Function %14
%tint_symbol = OpVariable %_ptr_Function_int Function %14
%30 = OpFOrdEqual %bool %in %29
OpSelectionMerge %31 None
OpBranchConditional %30 %32 %31
%32 = OpLabel
OpStore %tint_discarded %true
OpBranch %31
%31 = OpLabel
%37 = OpLoad %20 %s
%38 = OpLoad %17 %t
%40 = OpSampledImage %39 %38 %37
%35 = OpImageSampleImplicitLod %v4float %40 %coord
%41 = OpCompositeExtract %float %35 0
%34 = OpConvertFToS %int %41
OpStore %result %34
OpStore %i %14
OpBranch %45
%45 = OpLabel
OpLoopMerge %46 %47 None
OpBranch %48
%48 = OpLabel
%50 = OpLoad %int %i
%52 = OpSLessThan %bool %50 %int_10
%49 = OpLogicalNot %bool %52
OpSelectionMerge %53 None
OpBranchConditional %49 %54 %53
%54 = OpLabel
OpBranch %46
%53 = OpLabel
%55 = OpLoad %int %result
%56 = OpLoad %int %i
%57 = OpIAdd %int %55 %56
OpStore %result %57
OpBranch %47
%47 = OpLabel
%60 = OpLoad %bool %tint_discarded
%59 = OpLogicalNot %bool %60
OpSelectionMerge %61 None
OpBranchConditional %59 %62 %61
%62 = OpLabel
%69 = OpAccessChain %_ptr_StorageBuffer_int %a %uint_0
%63 = OpAtomicIAdd %int %69 %uint_1 %uint_0 %int_1
OpStore %tint_symbol %63
OpBranch %61
%61 = OpLabel
%71 = OpLoad %int %tint_symbol
OpStore %i %71
OpBranch %45
%46 = OpLabel
%72 = OpLoad %int %result
OpReturnValue %72
OpFunctionEnd
%foo = OpFunction %void None %73
%76 = OpLabel
%78 = OpLoad %float %in_1
%79 = OpLoad %v2float %coord_1
%77 = OpFunctionCall %int %foo_inner %78 %79
OpStore %value %77
%80 = OpLoad %bool %tint_discarded
OpSelectionMerge %81 None
OpBranchConditional %80 %82 %81
%82 = OpLabel
OpKill
%81 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,17 @@
@group(0) @binding(0) var t : texture_2d<f32>;
@group(0) @binding(1) var s : sampler;
@group(0) @binding(2) var<storage, read_write> a : atomic<i32>;
@fragment
fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i32 {
if ((in == 0.0)) {
discard;
}
var result = i32(textureSample(t, s, coord).x);
for(var i = 0; (i < 10); i = atomicAdd(&(a), 1)) {
result += i;
}
return result;
}

View File

@ -0,0 +1,19 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@group(0) @binding(1) var<storage, read_write> output : f32;
fn foo() {
if (non_uniform_global < 0) {
discard;
}
}
fn bar() {
output = dpdx(1.0);
}
@fragment
fn main() {
foo();
bar();
}

View File

@ -0,0 +1,24 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
RWByteAddressBuffer output : register(u1, space0);
void foo() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
}
void bar() {
if (!(tint_discarded)) {
output.Store(0u, asuint(ddx(1.0f)));
}
}
void main() {
foo();
bar();
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,24 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
RWByteAddressBuffer output : register(u1, space0);
void foo() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
}
void bar() {
if (!(tint_discarded)) {
output.Store(0u, asuint(ddx(1.0f)));
}
}
void main() {
foo();
bar();
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,36 @@
#version 310 es
precision mediump float;
bool tint_discarded = false;
layout(binding = 0, std430) buffer non_uniform_global_block_ssbo {
int inner;
} non_uniform_global;
layout(binding = 1, std430) buffer tint_symbol_block_ssbo {
float inner;
} tint_symbol;
void foo() {
if ((non_uniform_global.inner < 0)) {
tint_discarded = true;
}
}
void bar() {
if (!(tint_discarded)) {
tint_symbol.inner = dFdx(1.0f);
}
}
void tint_symbol_1() {
foo();
bar();
}
void main() {
tint_symbol_1();
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,25 @@
#include <metal_stdlib>
using namespace metal;
void foo(device int* const tint_symbol_1, thread bool* const tint_symbol_2) {
if ((*(tint_symbol_1) < 0)) {
*(tint_symbol_2) = true;
}
}
void bar(thread bool* const tint_symbol_3, device float* const tint_symbol_4) {
if (!(*(tint_symbol_3))) {
*(tint_symbol_4) = dfdx(1.0f);
}
}
fragment void tint_symbol(device int* tint_symbol_5 [[buffer(0)]], device float* tint_symbol_7 [[buffer(1)]]) {
thread bool tint_symbol_6 = false;
foo(tint_symbol_5, &(tint_symbol_6));
bar(&(tint_symbol_6), tint_symbol_7);
if (tint_symbol_6) {
discard_fragment();
}
return;
}

View File

@ -0,0 +1,87 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 44
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %non_uniform_global_block "non_uniform_global_block"
OpMemberName %non_uniform_global_block 0 "inner"
OpName %non_uniform_global "non_uniform_global"
OpName %output_block "output_block"
OpMemberName %output_block 0 "inner"
OpName %output "output"
OpName %foo "foo"
OpName %bar "bar"
OpName %main "main"
OpDecorate %non_uniform_global_block Block
OpMemberDecorate %non_uniform_global_block 0 Offset 0
OpDecorate %non_uniform_global DescriptorSet 0
OpDecorate %non_uniform_global Binding 0
OpDecorate %output_block Block
OpMemberDecorate %output_block 0 Offset 0
OpDecorate %output DescriptorSet 0
OpDecorate %output Binding 1
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%int = OpTypeInt 32 1
%non_uniform_global_block = OpTypeStruct %int
%_ptr_StorageBuffer_non_uniform_global_block = OpTypePointer StorageBuffer %non_uniform_global_block
%non_uniform_global = OpVariable %_ptr_StorageBuffer_non_uniform_global_block StorageBuffer
%float = OpTypeFloat 32
%output_block = OpTypeStruct %float
%_ptr_StorageBuffer_output_block = OpTypePointer StorageBuffer %output_block
%output = OpVariable %_ptr_StorageBuffer_output_block StorageBuffer
%void = OpTypeVoid
%13 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%22 = OpConstantNull %int
%true = OpConstantTrue %bool
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%float_1 = OpConstant %float 1
%foo = OpFunction %void None %13
%16 = OpLabel
%20 = OpAccessChain %_ptr_StorageBuffer_int %non_uniform_global %uint_0
%21 = OpLoad %int %20
%23 = OpSLessThan %bool %21 %22
OpSelectionMerge %24 None
OpBranchConditional %23 %25 %24
%25 = OpLabel
OpStore %tint_discarded %true
OpBranch %24
%24 = OpLabel
OpReturn
OpFunctionEnd
%bar = OpFunction %void None %13
%28 = OpLabel
%30 = OpLoad %bool %tint_discarded
%29 = OpLogicalNot %bool %30
OpSelectionMerge %31 None
OpBranchConditional %29 %32 %31
%32 = OpLabel
%34 = OpAccessChain %_ptr_StorageBuffer_float %output %uint_0
%35 = OpDPdx %float %float_1
OpStore %34 %35
OpBranch %31
%31 = OpLabel
OpReturn
OpFunctionEnd
%main = OpFunction %void None %13
%38 = OpLabel
%39 = OpFunctionCall %void %foo
%40 = OpFunctionCall %void %bar
%41 = OpLoad %bool %tint_discarded
OpSelectionMerge %42 None
OpBranchConditional %41 %43 %42
%43 = OpLabel
OpKill
%42 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,19 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@group(0) @binding(1) var<storage, read_write> output : f32;
fn foo() {
if ((non_uniform_global < 0)) {
discard;
}
}
fn bar() {
output = dpdx(1.0);
}
@fragment
fn main() {
foo();
bar();
}

View File

@ -0,0 +1,26 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@group(0) @binding(1) var<storage, read_write> output : f32;
@fragment
fn main() {
if (non_uniform_global < 0) {
discard;
}
output = dpdx(1.0);
if (output < 0) {
var i = 0;
loop {
if (output > f32(i)) {
output = f32(i);
return;
}
continuing {
i++;
break if i == 5;
}
}
return;
}
return;
}

View File

@ -0,0 +1,38 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
RWByteAddressBuffer output : register(u1, space0);
void main() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
if (!(tint_discarded)) {
output.Store(0u, asuint(ddx(1.0f)));
}
if ((asfloat(output.Load(0u)) < 0.0f)) {
int i = 0;
while (true) {
if ((asfloat(output.Load(0u)) > float(i))) {
if (!(tint_discarded)) {
output.Store(0u, asuint(float(i)));
}
if (tint_discarded) {
discard;
}
return;
}
{
i = (i + 1);
if ((i == 5)) { break; }
}
}
if (tint_discarded) {
discard;
}
return;
}
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,38 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
RWByteAddressBuffer output : register(u1, space0);
void main() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
if (!(tint_discarded)) {
output.Store(0u, asuint(ddx(1.0f)));
}
if ((asfloat(output.Load(0u)) < 0.0f)) {
int i = 0;
while (true) {
if ((asfloat(output.Load(0u)) > float(i))) {
if (!(tint_discarded)) {
output.Store(0u, asuint(float(i)));
}
if (tint_discarded) {
discard;
}
return;
}
{
i = (i + 1);
if ((i == 5)) { break; }
}
}
if (tint_discarded) {
discard;
}
return;
}
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,45 @@
#version 310 es
precision mediump float;
bool tint_discarded = false;
layout(binding = 0, std430) buffer non_uniform_global_block_ssbo {
int inner;
} non_uniform_global;
layout(binding = 1, std430) buffer tint_symbol_block_ssbo {
float inner;
} tint_symbol;
void tint_symbol_1() {
if ((non_uniform_global.inner < 0)) {
tint_discarded = true;
}
if (!(tint_discarded)) {
tint_symbol.inner = dFdx(1.0f);
}
if ((tint_symbol.inner < 0.0f)) {
int i = 0;
while (true) {
if ((tint_symbol.inner > float(i))) {
if (!(tint_discarded)) {
tint_symbol.inner = float(i);
}
return;
}
{
i = (i + 1);
if ((i == 5)) { break; }
}
}
return;
}
return;
}
void main() {
tint_symbol_1();
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,39 @@
#include <metal_stdlib>
using namespace metal;
fragment void tint_symbol(device int* tint_symbol_1 [[buffer(0)]], device float* tint_symbol_3 [[buffer(1)]]) {
thread bool tint_symbol_2 = false;
if ((*(tint_symbol_1) < 0)) {
tint_symbol_2 = true;
}
if (!(tint_symbol_2)) {
*(tint_symbol_3) = dfdx(1.0f);
}
if ((*(tint_symbol_3) < 0.0f)) {
int i = 0;
while (true) {
if ((*(tint_symbol_3) > float(i))) {
if (!(tint_symbol_2)) {
*(tint_symbol_3) = float(i);
}
if (tint_symbol_2) {
discard_fragment();
}
return;
}
{
i = as_type<int>((as_type<uint>(i) + as_type<uint>(1)));
if ((i == 5)) { break; }
}
}
if (tint_symbol_2) {
discard_fragment();
}
return;
}
if (tint_symbol_2) {
discard_fragment();
}
return;
}

View File

@ -0,0 +1,137 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 76
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %non_uniform_global_block "non_uniform_global_block"
OpMemberName %non_uniform_global_block 0 "inner"
OpName %non_uniform_global "non_uniform_global"
OpName %output_block "output_block"
OpMemberName %output_block 0 "inner"
OpName %output "output"
OpName %main "main"
OpName %i "i"
OpDecorate %non_uniform_global_block Block
OpMemberDecorate %non_uniform_global_block 0 Offset 0
OpDecorate %non_uniform_global DescriptorSet 0
OpDecorate %non_uniform_global Binding 0
OpDecorate %output_block Block
OpMemberDecorate %output_block 0 Offset 0
OpDecorate %output DescriptorSet 0
OpDecorate %output Binding 1
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%int = OpTypeInt 32 1
%non_uniform_global_block = OpTypeStruct %int
%_ptr_StorageBuffer_non_uniform_global_block = OpTypePointer StorageBuffer %non_uniform_global_block
%non_uniform_global = OpVariable %_ptr_StorageBuffer_non_uniform_global_block StorageBuffer
%float = OpTypeFloat 32
%output_block = OpTypeStruct %float
%_ptr_StorageBuffer_output_block = OpTypePointer StorageBuffer %output_block
%output = OpVariable %_ptr_StorageBuffer_output_block StorageBuffer
%void = OpTypeVoid
%13 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%22 = OpConstantNull %int
%true = OpConstantTrue %bool
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%float_1 = OpConstant %float 1
%37 = OpConstantNull %float
%_ptr_Function_int = OpTypePointer Function %int
%int_1 = OpConstant %int 1
%int_5 = OpConstant %int 5
%main = OpFunction %void None %13
%16 = OpLabel
%i = OpVariable %_ptr_Function_int Function %22
%20 = OpAccessChain %_ptr_StorageBuffer_int %non_uniform_global %uint_0
%21 = OpLoad %int %20
%23 = OpSLessThan %bool %21 %22
OpSelectionMerge %24 None
OpBranchConditional %23 %25 %24
%25 = OpLabel
OpStore %tint_discarded %true
OpBranch %24
%24 = OpLabel
%28 = OpLoad %bool %tint_discarded
%27 = OpLogicalNot %bool %28
OpSelectionMerge %29 None
OpBranchConditional %27 %30 %29
%30 = OpLabel
%32 = OpAccessChain %_ptr_StorageBuffer_float %output %uint_0
%33 = OpDPdx %float %float_1
OpStore %32 %33
OpBranch %29
%29 = OpLabel
%35 = OpAccessChain %_ptr_StorageBuffer_float %output %uint_0
%36 = OpLoad %float %35
%38 = OpFOrdLessThan %bool %36 %37
OpSelectionMerge %39 None
OpBranchConditional %38 %40 %39
%40 = OpLabel
OpStore %i %22
OpBranch %43
%43 = OpLabel
OpLoopMerge %44 %45 None
OpBranch %46
%46 = OpLabel
%47 = OpAccessChain %_ptr_StorageBuffer_float %output %uint_0
%48 = OpLoad %float %47
%50 = OpLoad %int %i
%49 = OpConvertSToF %float %50
%51 = OpFOrdGreaterThan %bool %48 %49
OpSelectionMerge %52 None
OpBranchConditional %51 %53 %52
%53 = OpLabel
%55 = OpLoad %bool %tint_discarded
%54 = OpLogicalNot %bool %55
OpSelectionMerge %56 None
OpBranchConditional %54 %57 %56
%57 = OpLabel
%58 = OpAccessChain %_ptr_StorageBuffer_float %output %uint_0
%60 = OpLoad %int %i
%59 = OpConvertSToF %float %60
OpStore %58 %59
OpBranch %56
%56 = OpLabel
%61 = OpLoad %bool %tint_discarded
OpSelectionMerge %62 None
OpBranchConditional %61 %63 %62
%63 = OpLabel
OpKill
%62 = OpLabel
OpReturn
%52 = OpLabel
OpBranch %45
%45 = OpLabel
%64 = OpLoad %int %i
%66 = OpIAdd %int %64 %int_1
OpStore %i %66
%67 = OpLoad %int %i
%69 = OpIEqual %bool %67 %int_5
OpBranchConditional %69 %44 %43
%44 = OpLabel
%70 = OpLoad %bool %tint_discarded
OpSelectionMerge %71 None
OpBranchConditional %70 %72 %71
%72 = OpLabel
OpKill
%71 = OpLabel
OpReturn
%39 = OpLabel
%73 = OpLoad %bool %tint_discarded
OpSelectionMerge %74 None
OpBranchConditional %73 %75 %74
%75 = OpLabel
OpKill
%74 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,27 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@group(0) @binding(1) var<storage, read_write> output : f32;
@fragment
fn main() {
if ((non_uniform_global < 0)) {
discard;
}
output = dpdx(1.0);
if ((output < 0)) {
var i = 0;
loop {
if ((output > f32(i))) {
output = f32(i);
return;
}
continuing {
i++;
break if (i == 5);
}
}
return;
}
return;
}

View File

@ -0,0 +1,13 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@fragment
fn main() {
if (non_uniform_global < 0) {
discard;
}
{
{
return;
}
}
}

View File

@ -0,0 +1,17 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
void main() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
{
{
if (tint_discarded) {
discard;
}
return;
}
}
return;
}

View File

@ -0,0 +1,17 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
void main() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
{
{
if (tint_discarded) {
discard;
}
return;
}
}
return;
}

View File

@ -0,0 +1,26 @@
#version 310 es
precision mediump float;
bool tint_discarded = false;
layout(binding = 0, std430) buffer non_uniform_global_block_ssbo {
int inner;
} non_uniform_global;
void tint_symbol() {
if ((non_uniform_global.inner < 0)) {
tint_discarded = true;
}
{
{
return;
}
}
}
void main() {
tint_symbol();
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,19 @@
#include <metal_stdlib>
using namespace metal;
fragment void tint_symbol(device int* tint_symbol_1 [[buffer(0)]]) {
thread bool tint_symbol_2 = false;
if ((*(tint_symbol_1) < 0)) {
tint_symbol_2 = true;
}
{
{
if (tint_symbol_2) {
discard_fragment();
}
return;
}
}
return;
}

View File

@ -0,0 +1,52 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 26
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %non_uniform_global_block "non_uniform_global_block"
OpMemberName %non_uniform_global_block 0 "inner"
OpName %non_uniform_global "non_uniform_global"
OpName %main "main"
OpDecorate %non_uniform_global_block Block
OpMemberDecorate %non_uniform_global_block 0 Offset 0
OpDecorate %non_uniform_global DescriptorSet 0
OpDecorate %non_uniform_global Binding 0
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%int = OpTypeInt 32 1
%non_uniform_global_block = OpTypeStruct %int
%_ptr_StorageBuffer_non_uniform_global_block = OpTypePointer StorageBuffer %non_uniform_global_block
%non_uniform_global = OpVariable %_ptr_StorageBuffer_non_uniform_global_block StorageBuffer
%void = OpTypeVoid
%9 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%18 = OpConstantNull %int
%true = OpConstantTrue %bool
%main = OpFunction %void None %9
%12 = OpLabel
%16 = OpAccessChain %_ptr_StorageBuffer_int %non_uniform_global %uint_0
%17 = OpLoad %int %16
%19 = OpSLessThan %bool %17 %18
OpSelectionMerge %20 None
OpBranchConditional %19 %21 %20
%21 = OpLabel
OpStore %tint_discarded %true
OpBranch %20
%20 = OpLabel
%23 = OpLoad %bool %tint_discarded
OpSelectionMerge %24 None
OpBranchConditional %23 %25 %24
%25 = OpLabel
OpKill
%24 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,13 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@fragment
fn main() {
if ((non_uniform_global < 0)) {
discard;
}
{
{
return;
}
}
}

View File

@ -0,0 +1,11 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@group(0) @binding(1) var<storage, read_write> output : f32;
@fragment
fn main() {
if (non_uniform_global < 0) {
discard;
}
output = dpdx(1.0);
}

View File

@ -0,0 +1,16 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
RWByteAddressBuffer output : register(u1, space0);
void main() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
if (!(tint_discarded)) {
output.Store(0u, asuint(ddx(1.0f)));
}
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,16 @@
static bool tint_discarded = false;
RWByteAddressBuffer non_uniform_global : register(u0, space0);
RWByteAddressBuffer output : register(u1, space0);
void main() {
if ((asint(non_uniform_global.Load(0u)) < 0)) {
tint_discarded = true;
}
if (!(tint_discarded)) {
output.Store(0u, asuint(ddx(1.0f)));
}
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,28 @@
#version 310 es
precision mediump float;
bool tint_discarded = false;
layout(binding = 0, std430) buffer non_uniform_global_block_ssbo {
int inner;
} non_uniform_global;
layout(binding = 1, std430) buffer tint_symbol_block_ssbo {
float inner;
} tint_symbol;
void tint_symbol_1() {
if ((non_uniform_global.inner < 0)) {
tint_discarded = true;
}
if (!(tint_discarded)) {
tint_symbol.inner = dFdx(1.0f);
}
}
void main() {
tint_symbol_1();
if (tint_discarded) {
discard;
}
return;
}

View File

@ -0,0 +1,17 @@
#include <metal_stdlib>
using namespace metal;
fragment void tint_symbol(device int* tint_symbol_1 [[buffer(0)]], device float* tint_symbol_3 [[buffer(1)]]) {
thread bool tint_symbol_2 = false;
if ((*(tint_symbol_1) < 0)) {
tint_symbol_2 = true;
}
if (!(tint_symbol_2)) {
*(tint_symbol_3) = dfdx(1.0f);
}
if (tint_symbol_2) {
discard_fragment();
}
return;
}

View File

@ -0,0 +1,75 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 38
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpName %tint_discarded "tint_discarded"
OpName %non_uniform_global_block "non_uniform_global_block"
OpMemberName %non_uniform_global_block 0 "inner"
OpName %non_uniform_global "non_uniform_global"
OpName %output_block "output_block"
OpMemberName %output_block 0 "inner"
OpName %output "output"
OpName %main "main"
OpDecorate %non_uniform_global_block Block
OpMemberDecorate %non_uniform_global_block 0 Offset 0
OpDecorate %non_uniform_global DescriptorSet 0
OpDecorate %non_uniform_global Binding 0
OpDecorate %output_block Block
OpMemberDecorate %output_block 0 Offset 0
OpDecorate %output DescriptorSet 0
OpDecorate %output Binding 1
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%tint_discarded = OpVariable %_ptr_Private_bool Private %2
%int = OpTypeInt 32 1
%non_uniform_global_block = OpTypeStruct %int
%_ptr_StorageBuffer_non_uniform_global_block = OpTypePointer StorageBuffer %non_uniform_global_block
%non_uniform_global = OpVariable %_ptr_StorageBuffer_non_uniform_global_block StorageBuffer
%float = OpTypeFloat 32
%output_block = OpTypeStruct %float
%_ptr_StorageBuffer_output_block = OpTypePointer StorageBuffer %output_block
%output = OpVariable %_ptr_StorageBuffer_output_block StorageBuffer
%void = OpTypeVoid
%13 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%22 = OpConstantNull %int
%true = OpConstantTrue %bool
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%float_1 = OpConstant %float 1
%main = OpFunction %void None %13
%16 = OpLabel
%20 = OpAccessChain %_ptr_StorageBuffer_int %non_uniform_global %uint_0
%21 = OpLoad %int %20
%23 = OpSLessThan %bool %21 %22
OpSelectionMerge %24 None
OpBranchConditional %23 %25 %24
%25 = OpLabel
OpStore %tint_discarded %true
OpBranch %24
%24 = OpLabel
%28 = OpLoad %bool %tint_discarded
%27 = OpLogicalNot %bool %28
OpSelectionMerge %29 None
OpBranchConditional %27 %30 %29
%30 = OpLabel
%32 = OpAccessChain %_ptr_StorageBuffer_float %output %uint_0
%33 = OpDPdx %float %float_1
OpStore %32 %33
OpBranch %29
%29 = OpLabel
%35 = OpLoad %bool %tint_discarded
OpSelectionMerge %36 None
OpBranchConditional %35 %37 %36
%37 = OpLabel
OpKill
%36 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,11 @@
@group(0) @binding(0) var<storage, read_write> non_uniform_global : i32;
@group(0) @binding(1) var<storage, read_write> output : f32;
@fragment
fn main() {
if ((non_uniform_global < 0)) {
discard;
}
output = dpdx(1.0);
}

View File

@ -1,55 +0,0 @@
; Test: SpvParserCFGTest_EmitBody_Kill_InsideLoop.spvasm
; SPIR-V
; Version: 1.0
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 1000
; Schema: 0
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %100 "main"
OpExecutionMode %100 OriginUpperLeft
OpName %var "var"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%bool = OpTypeBool
%5 = OpConstantNull %bool
%true = OpConstantTrue %bool
%false = OpConstantFalse %bool
%uint = OpTypeInt 32 0
%int = OpTypeInt 32 1
%uint_42 = OpConstant %uint 42
%int_42 = OpConstant %int 42
%13 = OpTypeFunction %uint
%uint_0 = OpConstant %uint 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_3 = OpConstant %uint 3
%uint_4 = OpConstant %uint 4
%uint_5 = OpConstant %uint 5
%uint_6 = OpConstant %uint 6
%uint_7 = OpConstant %uint 7
%uint_8 = OpConstant %uint 8
%uint_10 = OpConstant %uint 10
%uint_20 = OpConstant %uint 20
%uint_30 = OpConstant %uint 30
%uint_40 = OpConstant %uint 40
%uint_50 = OpConstant %uint 50
%uint_90 = OpConstant %uint 90
%uint_99 = OpConstant %uint 99
%_ptr_Private_uint = OpTypePointer Private %uint
%var = OpVariable %_ptr_Private_uint Private
%uint_999 = OpConstant %uint 999
%100 = OpFunction %void None %3
%10 = OpLabel
OpBranch %20
%20 = OpLabel
OpLoopMerge %99 %80 None
OpBranchConditional %5 %30 %30
%30 = OpLabel
OpKill
%80 = OpLabel
OpBranch %20
%99 = OpLabel
OpKill
OpFunctionEnd

View File

@ -1,958 +0,0 @@
struct BST {
data : i32,
leftIndex : i32,
rightIndex : i32,
}
struct buf0 {
injectionSwitch : vec2<f32>,
}
@group(0) @binding(0) var<uniform> x_8 : buf0;
var<private> gl_FragCoord : vec4<f32>;
var<private> x_GLF_color : vec4<f32>;
fn main_1() {
var tree : array<BST, 10u>;
var x_67 : bool;
var x_114 : bool;
var x_572 : i32;
var x_67_phi : bool;
var x_70_phi : i32;
var x_116_phi : bool;
var x_119_phi : i32;
var x_569_phi : i32;
var x_572_phi : i32;
var x_574_phi : i32;
tree[0] = BST(9, -1, -1);
switch(0u) {
default: {
x_67_phi = false;
x_70_phi = 0;
loop {
var x_95 : i32;
var x_87 : i32;
var x_68 : bool;
var x_71 : i32;
var x_68_phi : bool;
var x_71_phi : i32;
x_67 = x_67_phi;
let x_70 : i32 = x_70_phi;
x_116_phi = x_67;
if ((x_70 <= 1)) {
} else {
break;
}
let x_76 : i32 = tree[x_70].data;
if ((5 <= x_76)) {
var x_114_phi : bool;
let x_89_save = x_70;
let x_90 : i32 = tree[x_89_save].leftIndex;
if ((x_90 == -1)) {
let x_97 : f32 = x_8.injectionSwitch.y;
let x_99 : f32 = x_8.injectionSwitch.x;
if ((x_97 < x_99)) {
loop {
discard;
}
}
tree[x_89_save].leftIndex = 1;
tree[1] = BST(5, -1, -1);
loop {
x_114_phi = x_67;
if ((0 < i32(x_97))) {
} else {
break;
}
x_114_phi = true;
break;
}
x_114 = x_114_phi;
x_116_phi = x_114;
if (x_114) {
break;
}
} else {
x_95 = tree[x_89_save].leftIndex;
x_68_phi = x_67;
x_71_phi = x_95;
continue;
}
} else {
let x_81_save = x_70;
let x_82 : i32 = tree[x_81_save].rightIndex;
if ((x_82 == -1)) {
tree[x_81_save].rightIndex = 1;
tree[1] = BST(5, -1, -1);
x_116_phi = true;
break;
} else {
x_87 = tree[x_81_save].rightIndex;
x_68_phi = x_67;
x_71_phi = x_87;
continue;
}
}
x_68_phi = x_114;
x_71_phi = x_70;
continuing {
x_68 = x_68_phi;
x_71 = x_71_phi;
x_67_phi = x_68;
x_70_phi = x_71;
}
}
let x_116 : bool = x_116_phi;
if (x_116) {
break;
}
}
}
x_119_phi = 0;
loop {
var x_133 : bool;
var x_120 : i32;
var x_134_phi : bool;
let x_119 : i32 = x_119_phi;
let x_125 : f32 = gl_FragCoord.y;
let x_126 : bool = (x_125 < 0.0);
x_134_phi = x_126;
if (!(x_126)) {
let x_131 : f32 = x_8.injectionSwitch.y;
x_133 = (x_119 != i32(x_131));
x_134_phi = x_133;
}
let x_134 : bool = x_134_phi;
if (x_134) {
} else {
break;
}
var x_139 : bool;
var x_186 : bool;
var x_139_phi : bool;
var x_142_phi : i32;
var x_188_phi : bool;
switch(0u) {
default: {
x_139_phi = false;
x_142_phi = 0;
loop {
var x_167 : i32;
var x_159 : i32;
var x_140 : bool;
var x_143 : i32;
var x_140_phi : bool;
var x_143_phi : i32;
x_139 = x_139_phi;
let x_142 : i32 = x_142_phi;
x_188_phi = x_139;
if ((x_142 <= 2)) {
} else {
break;
}
let x_148 : i32 = tree[x_142].data;
if ((12 <= x_148)) {
var x_186_phi : bool;
let x_161_save = x_142;
let x_162 : i32 = tree[x_161_save].leftIndex;
if ((x_162 == -1)) {
let x_169 : f32 = x_8.injectionSwitch.y;
let x_171 : f32 = x_8.injectionSwitch.x;
if ((x_169 < x_171)) {
loop {
discard;
}
}
tree[x_161_save].leftIndex = 2;
tree[2] = BST(12, -1, -1);
loop {
x_186_phi = x_139;
if ((0 < i32(x_169))) {
} else {
break;
}
x_186_phi = true;
break;
}
x_186 = x_186_phi;
x_188_phi = x_186;
if (x_186) {
break;
}
} else {
x_167 = tree[x_161_save].leftIndex;
x_140_phi = x_139;
x_143_phi = x_167;
continue;
}
} else {
let x_153_save = x_142;
let x_154 : i32 = tree[x_153_save].rightIndex;
if ((x_154 == -1)) {
tree[x_153_save].rightIndex = 2;
tree[2] = BST(12, -1, -1);
x_188_phi = true;
break;
} else {
x_159 = tree[x_153_save].rightIndex;
x_140_phi = x_139;
x_143_phi = x_159;
continue;
}
}
x_140_phi = x_186;
x_143_phi = x_142;
continuing {
x_140 = x_140_phi;
x_143 = x_143_phi;
x_139_phi = x_140;
x_142_phi = x_143;
}
}
let x_188 : bool = x_188_phi;
if (x_188) {
break;
}
}
}
continuing {
x_120 = (x_119 + 1);
x_119_phi = x_120;
}
}
var x_193 : bool;
var x_240 : bool;
var x_193_phi : bool;
var x_196_phi : i32;
var x_242_phi : bool;
switch(0u) {
default: {
x_193_phi = false;
x_196_phi = 0;
loop {
var x_221 : i32;
var x_213 : i32;
var x_194 : bool;
var x_197 : i32;
var x_194_phi : bool;
var x_197_phi : i32;
x_193 = x_193_phi;
let x_196 : i32 = x_196_phi;
x_242_phi = x_193;
if ((x_196 <= 3)) {
} else {
break;
}
let x_202 : i32 = tree[x_196].data;
if ((15 <= x_202)) {
var x_240_phi : bool;
let x_215_save = x_196;
let x_216 : i32 = tree[x_215_save].leftIndex;
if ((x_216 == -1)) {
let x_223 : f32 = x_8.injectionSwitch.y;
let x_225 : f32 = x_8.injectionSwitch.x;
if ((x_223 < x_225)) {
loop {
discard;
}
}
tree[x_215_save].leftIndex = 3;
tree[3] = BST(15, -1, -1);
loop {
x_240_phi = x_193;
if ((0 < i32(x_223))) {
} else {
break;
}
x_240_phi = true;
break;
}
x_240 = x_240_phi;
x_242_phi = x_240;
if (x_240) {
break;
}
} else {
x_221 = tree[x_215_save].leftIndex;
x_194_phi = x_193;
x_197_phi = x_221;
continue;
}
} else {
let x_207_save = x_196;
let x_208 : i32 = tree[x_207_save].rightIndex;
if ((x_208 == -1)) {
tree[x_207_save].rightIndex = 3;
tree[3] = BST(15, -1, -1);
x_242_phi = true;
break;
} else {
x_213 = tree[x_207_save].rightIndex;
x_194_phi = x_193;
x_197_phi = x_213;
continue;
}
}
x_194_phi = x_240;
x_197_phi = x_196;
continuing {
x_194 = x_194_phi;
x_197 = x_197_phi;
x_193_phi = x_194;
x_196_phi = x_197;
}
}
let x_242 : bool = x_242_phi;
if (x_242) {
break;
}
}
}
var x_247 : bool;
var x_294 : bool;
var x_247_phi : bool;
var x_250_phi : i32;
var x_296_phi : bool;
switch(0u) {
default: {
x_247_phi = false;
x_250_phi = 0;
loop {
var x_275 : i32;
var x_267 : i32;
var x_248 : bool;
var x_251 : i32;
var x_248_phi : bool;
var x_251_phi : i32;
x_247 = x_247_phi;
let x_250 : i32 = x_250_phi;
x_296_phi = x_247;
if ((x_250 <= 4)) {
} else {
break;
}
let x_256 : i32 = tree[x_250].data;
if ((7 <= x_256)) {
var x_294_phi : bool;
let x_269_save = x_250;
let x_270 : i32 = tree[x_269_save].leftIndex;
if ((x_270 == -1)) {
let x_277 : f32 = x_8.injectionSwitch.y;
let x_279 : f32 = x_8.injectionSwitch.x;
if ((x_277 < x_279)) {
loop {
discard;
}
}
tree[x_269_save].leftIndex = 4;
tree[4] = BST(7, -1, -1);
loop {
x_294_phi = x_247;
if ((0 < i32(x_277))) {
} else {
break;
}
x_294_phi = true;
break;
}
x_294 = x_294_phi;
x_296_phi = x_294;
if (x_294) {
break;
}
} else {
x_275 = tree[x_269_save].leftIndex;
x_248_phi = x_247;
x_251_phi = x_275;
continue;
}
} else {
let x_261_save = x_250;
let x_262 : i32 = tree[x_261_save].rightIndex;
if ((x_262 == -1)) {
tree[x_261_save].rightIndex = 4;
tree[4] = BST(7, -1, -1);
x_296_phi = true;
break;
} else {
x_267 = tree[x_261_save].rightIndex;
x_248_phi = x_247;
x_251_phi = x_267;
continue;
}
}
x_248_phi = x_294;
x_251_phi = x_250;
continuing {
x_248 = x_248_phi;
x_251 = x_251_phi;
x_247_phi = x_248;
x_250_phi = x_251;
}
}
let x_296 : bool = x_296_phi;
if (x_296) {
break;
}
}
}
var x_301 : bool;
var x_348 : bool;
var x_301_phi : bool;
var x_304_phi : i32;
var x_350_phi : bool;
switch(0u) {
default: {
x_301_phi = false;
x_304_phi = 0;
loop {
var x_329 : i32;
var x_321 : i32;
var x_302 : bool;
var x_305 : i32;
var x_302_phi : bool;
var x_305_phi : i32;
x_301 = x_301_phi;
let x_304 : i32 = x_304_phi;
x_350_phi = x_301;
if ((x_304 <= 5)) {
} else {
break;
}
let x_310 : i32 = tree[x_304].data;
if ((8 <= x_310)) {
var x_348_phi : bool;
let x_323_save = x_304;
let x_324 : i32 = tree[x_323_save].leftIndex;
if ((x_324 == -1)) {
let x_331 : f32 = x_8.injectionSwitch.y;
let x_333 : f32 = x_8.injectionSwitch.x;
if ((x_331 < x_333)) {
loop {
discard;
}
}
tree[x_323_save].leftIndex = 5;
tree[5] = BST(8, -1, -1);
loop {
x_348_phi = x_301;
if ((0 < i32(x_331))) {
} else {
break;
}
x_348_phi = true;
break;
}
x_348 = x_348_phi;
x_350_phi = x_348;
if (x_348) {
break;
}
} else {
x_329 = tree[x_323_save].leftIndex;
x_302_phi = x_301;
x_305_phi = x_329;
continue;
}
} else {
let x_315_save = x_304;
let x_316 : i32 = tree[x_315_save].rightIndex;
if ((x_316 == -1)) {
tree[x_315_save].rightIndex = 5;
tree[5] = BST(8, -1, -1);
x_350_phi = true;
break;
} else {
x_321 = tree[x_315_save].rightIndex;
x_302_phi = x_301;
x_305_phi = x_321;
continue;
}
}
x_302_phi = x_348;
x_305_phi = x_304;
continuing {
x_302 = x_302_phi;
x_305 = x_305_phi;
x_301_phi = x_302;
x_304_phi = x_305;
}
}
let x_350 : bool = x_350_phi;
if (x_350) {
break;
}
}
}
var x_355 : bool;
var x_402 : bool;
var x_355_phi : bool;
var x_358_phi : i32;
var x_404_phi : bool;
switch(0u) {
default: {
x_355_phi = false;
x_358_phi = 0;
loop {
var x_383 : i32;
var x_375 : i32;
var x_356 : bool;
var x_359 : i32;
var x_356_phi : bool;
var x_359_phi : i32;
x_355 = x_355_phi;
let x_358 : i32 = x_358_phi;
x_404_phi = x_355;
if ((x_358 <= 6)) {
} else {
break;
}
let x_364 : i32 = tree[x_358].data;
if ((2 <= x_364)) {
var x_402_phi : bool;
let x_377_save = x_358;
let x_378 : i32 = tree[x_377_save].leftIndex;
if ((x_378 == -1)) {
let x_385 : f32 = x_8.injectionSwitch.y;
let x_387 : f32 = x_8.injectionSwitch.x;
if ((x_385 < x_387)) {
loop {
discard;
}
}
tree[x_377_save].leftIndex = 6;
tree[6] = BST(2, -1, -1);
loop {
x_402_phi = x_355;
if ((0 < i32(x_385))) {
} else {
break;
}
x_402_phi = true;
break;
}
x_402 = x_402_phi;
x_404_phi = x_402;
if (x_402) {
break;
}
} else {
x_383 = tree[x_377_save].leftIndex;
x_356_phi = x_355;
x_359_phi = x_383;
continue;
}
} else {
let x_369_save = x_358;
let x_370 : i32 = tree[x_369_save].rightIndex;
if ((x_370 == -1)) {
tree[x_369_save].rightIndex = 6;
tree[6] = BST(2, -1, -1);
x_404_phi = true;
break;
} else {
x_375 = tree[x_369_save].rightIndex;
x_356_phi = x_355;
x_359_phi = x_375;
continue;
}
}
x_356_phi = x_402;
x_359_phi = x_358;
continuing {
x_356 = x_356_phi;
x_359 = x_359_phi;
x_355_phi = x_356;
x_358_phi = x_359;
}
}
let x_404 : bool = x_404_phi;
if (x_404) {
break;
}
}
}
var x_409 : bool;
var x_456 : bool;
var x_409_phi : bool;
var x_412_phi : i32;
var x_458_phi : bool;
switch(0u) {
default: {
x_409_phi = false;
x_412_phi = 0;
loop {
var x_437 : i32;
var x_429 : i32;
var x_410 : bool;
var x_413 : i32;
var x_410_phi : bool;
var x_413_phi : i32;
x_409 = x_409_phi;
let x_412 : i32 = x_412_phi;
x_458_phi = x_409;
if ((x_412 <= 7)) {
} else {
break;
}
let x_418 : i32 = tree[x_412].data;
if ((6 <= x_418)) {
var x_456_phi : bool;
let x_431_save = x_412;
let x_432 : i32 = tree[x_431_save].leftIndex;
if ((x_432 == -1)) {
let x_439 : f32 = x_8.injectionSwitch.y;
let x_441 : f32 = x_8.injectionSwitch.x;
if ((x_439 < x_441)) {
loop {
discard;
}
}
tree[x_431_save].leftIndex = 7;
tree[7] = BST(6, -1, -1);
loop {
x_456_phi = x_409;
if ((0 < i32(x_439))) {
} else {
break;
}
x_456_phi = true;
break;
}
x_456 = x_456_phi;
x_458_phi = x_456;
if (x_456) {
break;
}
} else {
x_437 = tree[x_431_save].leftIndex;
x_410_phi = x_409;
x_413_phi = x_437;
continue;
}
} else {
let x_423_save = x_412;
let x_424 : i32 = tree[x_423_save].rightIndex;
if ((x_424 == -1)) {
tree[x_423_save].rightIndex = 7;
tree[7] = BST(6, -1, -1);
x_458_phi = true;
break;
} else {
x_429 = tree[x_423_save].rightIndex;
x_410_phi = x_409;
x_413_phi = x_429;
continue;
}
}
x_410_phi = x_456;
x_413_phi = x_412;
continuing {
x_410 = x_410_phi;
x_413 = x_413_phi;
x_409_phi = x_410;
x_412_phi = x_413;
}
}
let x_458 : bool = x_458_phi;
if (x_458) {
break;
}
}
}
var x_463 : bool;
var x_510 : bool;
var x_463_phi : bool;
var x_466_phi : i32;
var x_512_phi : bool;
switch(0u) {
default: {
x_463_phi = false;
x_466_phi = 0;
loop {
var x_491 : i32;
var x_483 : i32;
var x_464 : bool;
var x_467 : i32;
var x_464_phi : bool;
var x_467_phi : i32;
x_463 = x_463_phi;
let x_466 : i32 = x_466_phi;
x_512_phi = x_463;
if ((x_466 <= 8)) {
} else {
break;
}
let x_472 : i32 = tree[x_466].data;
if ((17 <= x_472)) {
var x_510_phi : bool;
let x_485_save = x_466;
let x_486 : i32 = tree[x_485_save].leftIndex;
if ((x_486 == -1)) {
let x_493 : f32 = x_8.injectionSwitch.y;
let x_495 : f32 = x_8.injectionSwitch.x;
if ((x_493 < x_495)) {
loop {
discard;
}
}
tree[x_485_save].leftIndex = 8;
tree[8] = BST(17, -1, -1);
loop {
x_510_phi = x_463;
if ((0 < i32(x_493))) {
} else {
break;
}
x_510_phi = true;
break;
}
x_510 = x_510_phi;
x_512_phi = x_510;
if (x_510) {
break;
}
} else {
x_491 = tree[x_485_save].leftIndex;
x_464_phi = x_463;
x_467_phi = x_491;
continue;
}
} else {
let x_477_save = x_466;
let x_478 : i32 = tree[x_477_save].rightIndex;
if ((x_478 == -1)) {
tree[x_477_save].rightIndex = 8;
tree[8] = BST(17, -1, -1);
x_512_phi = true;
break;
} else {
x_483 = tree[x_477_save].rightIndex;
x_464_phi = x_463;
x_467_phi = x_483;
continue;
}
}
x_464_phi = x_510;
x_467_phi = x_466;
continuing {
x_464 = x_464_phi;
x_467 = x_467_phi;
x_463_phi = x_464;
x_466_phi = x_467;
}
}
let x_512 : bool = x_512_phi;
if (x_512) {
break;
}
}
}
var x_517 : bool;
var x_564 : bool;
var x_517_phi : bool;
var x_520_phi : i32;
var x_566_phi : bool;
switch(0u) {
default: {
x_517_phi = false;
x_520_phi = 0;
loop {
var x_545 : i32;
var x_537 : i32;
var x_518 : bool;
var x_521 : i32;
var x_518_phi : bool;
var x_521_phi : i32;
x_517 = x_517_phi;
let x_520 : i32 = x_520_phi;
x_566_phi = x_517;
if ((x_520 <= 9)) {
} else {
break;
}
let x_526 : i32 = tree[x_520].data;
if ((13 <= x_526)) {
var x_564_phi : bool;
let x_539_save = x_520;
let x_540 : i32 = tree[x_539_save].leftIndex;
if ((x_540 == -1)) {
let x_547 : f32 = x_8.injectionSwitch.y;
let x_549 : f32 = x_8.injectionSwitch.x;
if ((x_547 < x_549)) {
loop {
discard;
}
}
tree[x_539_save].leftIndex = 9;
tree[9] = BST(13, -1, -1);
loop {
x_564_phi = x_517;
if ((0 < i32(x_547))) {
} else {
break;
}
x_564_phi = true;
break;
}
x_564 = x_564_phi;
x_566_phi = x_564;
if (x_564) {
break;
}
} else {
x_545 = tree[x_539_save].leftIndex;
x_518_phi = x_517;
x_521_phi = x_545;
continue;
}
} else {
let x_531_save = x_520;
let x_532 : i32 = tree[x_531_save].rightIndex;
if ((x_532 == -1)) {
tree[x_531_save].rightIndex = 9;
tree[9] = BST(13, -1, -1);
x_566_phi = true;
break;
} else {
x_537 = tree[x_531_save].rightIndex;
x_518_phi = x_517;
x_521_phi = x_537;
continue;
}
}
x_518_phi = x_564;
x_521_phi = x_520;
continuing {
x_518 = x_518_phi;
x_521 = x_521_phi;
x_517_phi = x_518;
x_520_phi = x_521;
}
}
let x_566 : bool = x_566_phi;
if (x_566) {
break;
}
}
}
x_569_phi = 0;
x_572_phi = 0;
x_574_phi = 0;
loop {
var x_597 : i32;
var x_607 : i32;
var x_612 : i32;
var x_575 : i32;
var x_570_phi : i32;
var x_573_phi : i32;
let x_569 : i32 = x_569_phi;
x_572 = x_572_phi;
let x_574 : i32 = x_574_phi;
if ((x_574 < 20)) {
} else {
break;
}
var x_582_phi : i32;
var x_597_phi : i32;
var x_598_phi : bool;
switch(0u) {
default: {
x_582_phi = 0;
loop {
let x_582 : i32 = x_582_phi;
x_597_phi = x_569;
x_598_phi = false;
if ((x_582 != -1)) {
} else {
break;
}
let x_589 : BST = tree[x_582];
let x_590 : i32 = x_589.data;
let x_591 : i32 = x_589.leftIndex;
let x_592 : i32 = x_589.rightIndex;
if ((x_590 == x_574)) {
x_597_phi = x_574;
x_598_phi = true;
break;
}
continuing {
x_582_phi = select(x_591, x_592, (x_574 > x_590));
}
}
x_597 = x_597_phi;
let x_598 : bool = x_598_phi;
x_570_phi = x_597;
if (x_598) {
break;
}
x_570_phi = -1;
}
}
var x_570 : i32;
var x_606 : i32;
var x_611 : i32;
var x_607_phi : i32;
var x_612_phi : i32;
x_570 = x_570_phi;
switch(x_574) {
case 2, 5, 6, 7, 8, 9, 12, 13, 15, 17: {
x_607_phi = x_572;
if ((x_570 == bitcast<i32>(x_574))) {
x_606 = bitcast<i32>((x_572 + bitcast<i32>(1)));
x_607_phi = x_606;
}
x_607 = x_607_phi;
x_573_phi = x_607;
}
default: {
x_612_phi = x_572;
if ((x_570 == bitcast<i32>(-1))) {
x_611 = bitcast<i32>((x_572 + bitcast<i32>(1)));
x_612_phi = x_611;
}
x_612 = x_612_phi;
x_573_phi = x_612;
}
}
let x_573 : i32 = x_573_phi;
continuing {
x_575 = (x_574 + 1);
x_569_phi = x_570;
x_572_phi = x_573;
x_574_phi = x_575;
}
}
if ((x_572 == bitcast<i32>(20))) {
x_GLF_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
} else {
x_GLF_color = vec4<f32>(0.0, 0.0, 1.0, 1.0);
}
return;
}
struct main_out {
@location(0)
x_GLF_color_1 : vec4<f32>,
}
@fragment
fn main(@builtin(position) gl_FragCoord_param : vec4<f32>) -> main_out {
gl_FragCoord = gl_FragCoord_param;
main_1();
return main_out(x_GLF_color);
}