writer/wgsl: Ensure that test programs are valid
Make all test programs valid. Change-Id: Id7eb790519e3dec30a5b826f06585d277995b9b5 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50720 Auto-Submit: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
4ace822c4b
commit
42f8999af5
|
@ -31,6 +31,17 @@ using WgslBinaryTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(WgslBinaryTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto op_ty = [&]() -> ast::Type* {
|
||||
if (params.op == ast::BinaryOp::kLogicalAnd ||
|
||||
params.op == ast::BinaryOp::kLogicalOr) {
|
||||
return ty.bool_();
|
||||
} else {
|
||||
return ty.u32();
|
||||
}
|
||||
};
|
||||
|
||||
Global("left", op_ty(), ast::StorageClass::kPrivate);
|
||||
Global("right", op_ty(), ast::StorageClass::kPrivate);
|
||||
auto* left = Expr("left");
|
||||
auto* right = Expr("right");
|
||||
|
||||
|
|
|
@ -101,27 +101,30 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) {
|
||||
Global("s", ty.sampler(ast::SamplerKind::kSampler), ast::StorageClass::kNone);
|
||||
Global("s", ty.sampler(ast::SamplerKind::kSampler), ast::StorageClass::kNone,
|
||||
nullptr,
|
||||
{create<ast::GroupDecoration>(0), create<ast::BindingDecoration>(0)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.Generate(nullptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " var s : sampler;\n");
|
||||
EXPECT_EQ(gen.result(), " [[group(0), binding(0)]] var s : sampler;\n");
|
||||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Global_Texture) {
|
||||
auto st = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32());
|
||||
Global("t", ty.access(ast::AccessControl::kReadOnly, st),
|
||||
ast::StorageClass::kNone);
|
||||
ast::StorageClass::kNone, nullptr,
|
||||
{create<ast::GroupDecoration>(0), create<ast::BindingDecoration>(0)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.Generate(nullptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " var t : [[access(read)]] texture_1d<f32>;\n");
|
||||
EXPECT_EQ(gen.result(), " [[group(0), binding(0)]] var t : [[access(read)]] texture_1d<f32>;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace {
|
|||
using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitIdentifierExpression_Single) {
|
||||
Global("glsl", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* i = Expr("glsl");
|
||||
WrapInFunction(i);
|
||||
|
||||
|
|
|
@ -59,10 +59,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
|||
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
|
||||
ast::DecorationList{
|
||||
Builtin(ast::Builtin::kPosition),
|
||||
create<ast::BindingDecoration>(0),
|
||||
create<ast::GroupDecoration>(1),
|
||||
Location(2),
|
||||
create<ast::OverrideDecoration>(42),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -70,7 +67,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
|||
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
|
||||
EXPECT_EQ(
|
||||
gen.result(),
|
||||
R"([[builtin(position), binding(0), group(1), location(2), override(42)]] var<private> a : f32;
|
||||
R"([[builtin(position), location(2)]] var<private> a : f32;
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,11 @@ class TestHelperBase : public BASE, public ProgramBuilder {
|
|||
return *gen_;
|
||||
}
|
||||
program = std::make_unique<Program>(std::move(*this));
|
||||
diag::Formatter formatter;
|
||||
[&]() {
|
||||
ASSERT_TRUE(program->IsValid())
|
||||
<< formatter.format(program->Diagnostics());
|
||||
}();
|
||||
gen_ = std::make_unique<GeneratorImpl>(program.get());
|
||||
return *gen_;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue