mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
[ir] Restore losts tests.
When the `BuilderImpl` tests were split apart in 131581 these two files accidentally got created in the wrong spot. This removed them from being tested. Add them back and update format to match current disassembly. Bug: tint:1718 Change-Id: I9b248121a9f45862060d44f50a290344e1222874 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134440 Kokoro: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
a2b489b900
commit
686d2e2d4d
@@ -2264,7 +2264,9 @@ if (tint_build_unittests) {
|
||||
"ir/constant_test.cc",
|
||||
"ir/discard_test.cc",
|
||||
"ir/from_program_binary_test.cc",
|
||||
"ir/from_program_builtin_test.cc",
|
||||
"ir/from_program_call_test.cc",
|
||||
"ir/from_program_function_test.cc",
|
||||
"ir/from_program_literal_test.cc",
|
||||
"ir/from_program_materialize_test.cc",
|
||||
"ir/from_program_store_test.cc",
|
||||
|
||||
@@ -1468,7 +1468,9 @@ if(TINT_BUILD_TESTS)
|
||||
ir/constant_test.cc
|
||||
ir/discard_test.cc
|
||||
ir/from_program_binary_test.cc
|
||||
ir/from_program_builtin_test.cc
|
||||
ir/from_program_call_test.cc
|
||||
ir/from_program_function_test.cc
|
||||
ir/from_program_literal_test.cc
|
||||
ir/from_program_materialize_test.cc
|
||||
ir/from_program_store_test.cc
|
||||
|
||||
57
src/tint/ir/from_program_builtin_test.cc
Normal file
57
src/tint/ir/from_program_builtin_test.cc
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2023 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/ir/test_helper.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "src/tint/ast/case_selector.h"
|
||||
#include "src/tint/ast/int_literal_expression.h"
|
||||
#include "src/tint/constant/scalar.h"
|
||||
|
||||
namespace tint::ir {
|
||||
namespace {
|
||||
|
||||
using namespace tint::number_suffixes; // NOLINT
|
||||
|
||||
using IR_BuilderImplTest = TestHelper;
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitExpression_Builtin) {
|
||||
auto i = GlobalVar("i", builtin::AddressSpace::kPrivate, Expr(1_f));
|
||||
auto* expr = Call("asin", i);
|
||||
WrapInFunction(expr);
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(# Root block
|
||||
%fn1 = block {
|
||||
%i:ptr<private, f32, read_write> = var, 1.0f
|
||||
br %fn2 # root_end
|
||||
}
|
||||
|
||||
%fn2 = root_terminator
|
||||
|
||||
%test_function = func():void [@compute @workgroup_size(1, 1, 1)] -> %fn3 {
|
||||
%fn3 = block {
|
||||
%3:f32 = load %i
|
||||
%tint_symbol:f32 = asin %3
|
||||
br %fn4 # return
|
||||
}
|
||||
%fn4 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ir
|
||||
182
src/tint/ir/from_program_function_test.cc
Normal file
182
src/tint/ir/from_program_function_test.cc
Normal file
@@ -0,0 +1,182 @@
|
||||
// Copyright 2023 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/ir/test_helper.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "src/tint/ast/case_selector.h"
|
||||
#include "src/tint/ast/int_literal_expression.h"
|
||||
#include "src/tint/constant/scalar.h"
|
||||
|
||||
namespace tint::ir {
|
||||
namespace {
|
||||
|
||||
using namespace tint::number_suffixes; // NOLINT
|
||||
|
||||
using IR_BuilderImplTest = TestHelper;
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_Vertex) {
|
||||
Func("test", utils::Empty, ty.vec4<f32>(), utils::Vector{Return(vec4<f32>(0_f, 0_f, 0_f, 0_f))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(%test = func():vec4<f32> [@vertex ra: @position] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 vec4<f32> 0.0f # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_Fragment) {
|
||||
Func("test", utils::Empty, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(%test = func():void [@fragment] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_Compute) {
|
||||
Func("test", utils::Empty, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute), WorkgroupSize(8_i, 4_i, 2_i)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()),
|
||||
R"(%test = func():void [@compute @workgroup_size(8, 4, 2)] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_Return) {
|
||||
Func("test", utils::Empty, ty.vec3<f32>(), utils::Vector{Return(vec3<f32>(0_f, 0_f, 0_f))},
|
||||
utils::Empty);
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(%test = func():vec3<f32> -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 vec3<f32> 0.0f # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_ReturnPosition) {
|
||||
Func("test", utils::Empty, ty.vec4<f32>(), utils::Vector{Return(vec4<f32>(1_f, 2_f, 3_f, 4_f))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(%test = func():vec4<f32> [@vertex ra: @position] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 vec4<f32> 1.0f, 2.0f, 3.0f, 4.0f # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_ReturnPositionInvariant) {
|
||||
Func("test", utils::Empty, ty.vec4<f32>(), utils::Vector{Return(vec4<f32>(1_f, 2_f, 3_f, 4_f))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition), Invariant()});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()),
|
||||
R"(%test = func():vec4<f32> [@vertex ra: @position @invariant] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 vec4<f32> 1.0f, 2.0f, 3.0f, 4.0f # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_ReturnLocation) {
|
||||
Func("test", utils::Empty, ty.vec4<f32>(), utils::Vector{Return(vec4<f32>(1_f, 2_f, 3_f, 4_f))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kFragment)}, utils::Vector{Location(1_i)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()),
|
||||
R"(%test = func():vec4<f32> [@fragment ra: @location(1)] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 vec4<f32> 1.0f, 2.0f, 3.0f, 4.0f # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_ReturnFragDepth) {
|
||||
Func("test", utils::Empty, ty.f32(), utils::Vector{Return(1_f)},
|
||||
utils::Vector{Stage(ast::PipelineStage::kFragment)},
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(%test = func():f32 [@fragment ra: @frag_depth] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 1.0f # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(IR_BuilderImplTest, EmitFunction_ReturnSampleMask) {
|
||||
Func("test", utils::Empty, ty.u32(), utils::Vector{Return(1_u)},
|
||||
utils::Vector{Stage(ast::PipelineStage::kFragment)},
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)});
|
||||
|
||||
auto m = Build();
|
||||
ASSERT_TRUE(m) << (!m ? m.Failure() : "");
|
||||
|
||||
EXPECT_EQ(Disassemble(m.Get()), R"(%test = func():u32 [@fragment ra: @sample_mask] -> %fn1 {
|
||||
%fn1 = block {
|
||||
br %fn2 1u # return
|
||||
}
|
||||
%fn2 = func_terminator
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ir
|
||||
Reference in New Issue
Block a user