Flutter Engine
The Flutter Engine
specialization_constants_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/testing/testing.h" // IWYU pragma: keep
6#include "fml/mapping.h"
7#include "gtest/gtest.h"
10
11namespace impeller {
12namespace testing {
13
14TEST(SpecConstant, CanCreateShaderWithSpecializationConstant) {
15 auto mock_gles = MockGLES::Init();
16 auto& proc_table = mock_gles->GetProcTable();
17 auto shader_source =
18 "#version 100\n"
19 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
20 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
21 "#endif\n"
22 "void main() { return vec4(0.0); }";
23 auto test_shader = std::make_shared<fml::DataMapping>(shader_source);
24
25 auto result = proc_table.ComputeShaderWithDefines(*test_shader, {0});
26
27 auto expected_shader_source =
28 "#version 100\n"
29 "#define SPIRV_CROSS_CONSTANT_ID_0 0.000000\n"
30 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
31 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
32 "#endif\n"
33 "void main() { return vec4(0.0); }";
34
35 if (!result.has_value()) {
36 GTEST_FAIL() << "Expected shader source";
37 }
38 ASSERT_EQ(result.value(), expected_shader_source);
39}
40
41TEST(SpecConstant, CanCreateShaderWithSpecializationConstantMultipleValues) {
42 auto mock_gles = MockGLES::Init();
43 auto& proc_table = mock_gles->GetProcTable();
44 auto shader_source =
45 "#version 100\n"
46 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
47 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
48 "#endif\n"
49 "void main() { return vec4(0.0); }";
50 auto test_shader = std::make_shared<fml::DataMapping>(shader_source);
51
52 auto result =
53 proc_table.ComputeShaderWithDefines(*test_shader, {0, 1, 2, 3, 4, 5});
54
55 auto expected_shader_source =
56 "#version 100\n"
57 "#define SPIRV_CROSS_CONSTANT_ID_0 0.000000\n"
58 "#define SPIRV_CROSS_CONSTANT_ID_1 1.000000\n"
59 "#define SPIRV_CROSS_CONSTANT_ID_2 2.000000\n"
60 "#define SPIRV_CROSS_CONSTANT_ID_3 3.000000\n"
61 "#define SPIRV_CROSS_CONSTANT_ID_4 4.000000\n"
62 "#define SPIRV_CROSS_CONSTANT_ID_5 5.000000\n"
63 "#ifndef SPIRV_CROSS_CONSTANT_ID_0\n"
64 "#define SPIRV_CROSS_CONSTANT_ID_0 1\n"
65 "#endif\n"
66 "void main() { return vec4(0.0); }";
67
68 if (!result.has_value()) {
69 GTEST_FAIL() << "Expected shader source";
70 }
71 ASSERT_EQ(result.value(), expected_shader_source);
72}
73
74} // namespace testing
75} // namespace impeller
static std::shared_ptr< MockGLES > Init(const std::optional< std::vector< const unsigned char * > > &extensions=std::nullopt, const char *version_string="OpenGL ES 3.0", ProcTableGLES::Resolver resolver=kMockResolverGLES)
Returns an initialized |MockGLES| instance.
Definition: mock_gles.cc:166
GAsyncResult * result
TEST(AiksCanvasTest, EmptyCullRect)