1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "gmock/gmock.h"
16 #include "src/ast/override_decoration.h"
17 #include "src/ast/stage_decoration.h"
18 #include "src/writer/glsl/test_helper.h"
19
20 namespace tint {
21 namespace writer {
22 namespace glsl {
23 namespace {
24 using ::testing::HasSubstr;
25
26 using GlslGeneratorImplTest_WorkgroupVar = TestHelper;
27
TEST_F(GlslGeneratorImplTest_WorkgroupVar,Basic)28 TEST_F(GlslGeneratorImplTest_WorkgroupVar, Basic) {
29 Global("wg", ty.f32(), ast::StorageClass::kWorkgroup);
30
31 Func("main", {}, ty.void_(), {Assign("wg", 1.2f)},
32 {
33 Stage(ast::PipelineStage::kCompute),
34 WorkgroupSize(1),
35 });
36 GeneratorImpl& gen = Build();
37
38 ASSERT_TRUE(gen.Generate()) << gen.error();
39 EXPECT_THAT(gen.result(), HasSubstr("shared float wg;\n"));
40 }
41
TEST_F(GlslGeneratorImplTest_WorkgroupVar,Aliased)42 TEST_F(GlslGeneratorImplTest_WorkgroupVar, Aliased) {
43 auto* alias = Alias("F32", ty.f32());
44
45 Global("wg", ty.Of(alias), ast::StorageClass::kWorkgroup);
46
47 Func("main", {}, ty.void_(), {Assign("wg", 1.2f)},
48 {
49 Stage(ast::PipelineStage::kCompute),
50 WorkgroupSize(1),
51 });
52 GeneratorImpl& gen = Build();
53
54 ASSERT_TRUE(gen.Generate()) << gen.error();
55 EXPECT_THAT(gen.result(), HasSubstr("shared float wg;\n"));
56 }
57
58 } // namespace
59 } // namespace glsl
60 } // namespace writer
61 } // namespace tint
62