Skip to content

Commit 7c5683e

Browse files
authored
[windows] Add OpenGL golden test against ANGLE at D3D11 feature level 10_0 (flutter#194321)
Adds a test that runs the existing engine_integration_golden_test, but with a D3D11 10_0 feature level cap. This is the follow up PR mentioned in flutter#194114. Together these two PRs gives us basic smoke testing coverage on 10_0 of the rendering pipeline from Flutter app code, through Impeller rendering, to presenting on the swapchain. The feature level cap is read directly from the environment variables by `windows/flutter_project_bundle.cc`. I don't know if this is the best way to do this, because it's doing it different than other "engine switches". Reading the environment variable directly is similar to how `FLUTTER_LINUX_RENDERER` is read in the [linux embedder](https://github.com/flutter/flutter/blob/debf408b622cb24c5992cff3d9c9142be79eab40/engine/src/flutter/shell/platform/linux/fl_engine.cc#L696). An alternative would be to expose it as a flag in flutter tool and piping it all the way through to here. That would be a lot more changes and plumbing, and it makes the flag a little more public, but if you prefer that way, let me know and I'll change this. I ran this locally on a Windows VM, with a `host_debug_unopt` engine build. It caught flutter#194317, so it's already acting as a useful 10_0 smoke test. I confirmed that with the fix (flutter#194319), it runs and passes as expected (but without doing a real skia-gold validation check). Part of flutter#192899 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 5c7e45a commit 7c5683e

12 files changed

Lines changed: 197 additions & 3 deletions

File tree

‎.ci.yaml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7460,6 +7460,21 @@ targets:
74607460
]
74617461
task_name: windows_engine_integration_golden_test
74627462

7463+
- name: Windows windows_engine_integration_golden_test_feature_level_10_0
7464+
recipe: devicelab/devicelab_drone
7465+
bringup: true
7466+
presubmit: true
7467+
timeout: 60
7468+
properties:
7469+
tags: >
7470+
["devicelab", "hostonly", "windows"]
7471+
dependencies: >-
7472+
[
7473+
{"dependency": "vs_build", "version": "version:vs2019"},
7474+
{"dependency": "goldctl", "version": "git_revision:c845c41b9b81bfcb11f2f0ab17b5b2386d634c31"}
7475+
]
7476+
task_name: windows_engine_integration_golden_test_feature_level_10_0
7477+
74637478
- name: Windows texture_impeller_windows
74647479
recipe: devicelab/devicelab_drone
74657480
presubmit: false

‎TESTOWNERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
/dev/devicelab/bin/tasks/windowing_test_windows.dart @mattkae @flutter/desktop
335335
/dev/devicelab/bin/tasks/windows_desktop_impeller.dart @jonahwilliams @flutter/engine
336336
/dev/devicelab/bin/tasks/windows_engine_integration_golden_test.dart @b-luk @flutter/engine
337+
/dev/devicelab/bin/tasks/windows_engine_integration_golden_test_feature_level_10_0.dart @b-luk @flutter/engine
337338
/dev/devicelab/bin/tasks/windows_gradient_consistent_perf__e2e_summary.dart @b-luk @flutter/engine
338339
/dev/devicelab/bin/tasks/windows_gradient_dynamic_perf__e2e_summary.dart @b-luk @flutter/engine
339340
/dev/devicelab/bin/tasks/windows_gradient_static_perf__e2e_summary.dart @b-luk @flutter/engine
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 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+
import 'package:flutter_devicelab/framework/devices.dart';
6+
import 'package:flutter_devicelab/framework/framework.dart';
7+
import 'package:flutter_devicelab/tasks/integration_tests.dart';
8+
9+
Future<void> main() async {
10+
deviceOperatingSystem = DeviceOperatingSystem.windows;
11+
await task(createEngineIntegrationGoldenTest(maxD3DFeatureLevel: '10_0'));
12+
}

‎dev/devicelab/lib/tasks/integration_tests.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,14 @@ TaskFunction createWindowsStartupDriverTest({String? deviceIdOverride}) {
239239
).call;
240240
}
241241

242-
TaskFunction createEngineIntegrationGoldenTest() {
242+
TaskFunction createEngineIntegrationGoldenTest({String? maxD3DFeatureLevel}) {
243243
return IntegrationTest(
244244
'${flutterDirectory.path}/dev/integration_tests/engine_integration_golden_test',
245245
'integration_test/engine_integration_golden_test.dart',
246246
createPlatforms: <String>['windows'],
247+
environment: <String, String>{
248+
if (maxD3DFeatureLevel != null) 'FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL': maxD3DFeatureLevel,
249+
},
247250
).call;
248251
}
249252

‎dev/integration_tests/engine_integration_golden_test/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ flutter test integration_test/engine_integration_golden_test.dart -d <device_id>
1313
cd dev/devicelab
1414
dart bin/run.dart -t windows_engine_integration_golden_test
1515
```
16+
17+
`windows_engine_integration_golden_test_feature_level_10_0` runs the same tests
18+
with the engine's D3D11 feature level capped to 10_0 (via
19+
`FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL`) and compares against a separate set of
20+
goldens.

‎dev/integration_tests/engine_integration_golden_test/integration_test/flutter_test_config.dart‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
library;
77

88
import 'dart:async';
9+
import 'dart:io';
910

1011
import 'package:flutter_goldens/flutter_goldens.dart' as flutter_goldens;
1112

1213
/// Configures [goldenFileComparator] for the test suite using `package:flutter_goldens`.
1314
///
1415
/// On CI/LUCI, if `GOLDCTL` environment variable is present, screenshots taken with
1516
/// `matchesGoldenFile` will be uploaded to Skia Gold.
17+
///
18+
/// On Windows, runs with the engine's D3D11 feature level capped (via the
19+
/// `FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL` environment variable) render
20+
/// differently, so they use a separate set of goldens.
1621
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
17-
return flutter_goldens.testExecutable(testMain, namePrefix: 'engine_integration_golden');
22+
final String? maxFeatureLevel = Platform.environment['FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL'];
23+
final namePrefix = maxFeatureLevel == null
24+
? 'engine_integration_golden'
25+
: 'engine_integration_golden_feature_level_$maxFeatureLevel';
26+
return flutter_goldens.testExecutable(testMain, namePrefix: namePrefix);
1827
}

‎engine/src/flutter/shell/platform/windows/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ source_set("flutter_windows_source") {
195195
"//flutter/third_party/angle:libEGL_static",
196196
"//flutter/third_party/angle:libGLESv2_static",
197197
"//flutter/third_party/rapidjson",
198+
"//third_party/abseil-cpp/absl/status:statusor",
198199
]
199200
}
200201

‎engine/src/flutter/shell/platform/windows/flutter_project_bundle.cc‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,72 @@
44

55
#include "flutter/shell/platform/windows/flutter_project_bundle.h"
66

7+
#include <charconv>
8+
#include <cstdlib>
79
#include <filesystem>
10+
#include <string_view>
811

912
#include "flutter/fml/build_config.h"
1013
#include "flutter/fml/logging.h"
1114
#include "flutter/fml/string_conversion.h"
1215
#include "flutter/shell/platform/common/engine_switches.h" // nogncheck
1316
#include "flutter/shell/platform/common/path_utils.h"
17+
#include "third_party/abseil-cpp/absl/status/statusor.h"
1418

1519
namespace flutter {
1620

21+
namespace {
22+
23+
// Parses a feature level written as "<major>_<minor>", such as "10_0".
24+
absl::StatusOr<egl::D3DFeatureLevel> ParseD3DFeatureLevel(
25+
std::string_view value) {
26+
const absl::Status invalid_status =
27+
absl::InvalidArgumentError("expected a feature level such as 10_0");
28+
const size_t separator = value.find('_');
29+
if (separator == std::string_view::npos) {
30+
return invalid_status;
31+
}
32+
const char* major_begin = value.data();
33+
const char* major_end = major_begin + separator;
34+
const char* minor_begin = major_end + 1;
35+
const char* minor_end = value.data() + value.size();
36+
37+
int major = 0;
38+
int minor = 0;
39+
auto major_result = std::from_chars(major_begin, major_end, major);
40+
auto minor_result = std::from_chars(minor_begin, minor_end, minor);
41+
if (major_result.ec != std::errc() || major_result.ptr != major_end ||
42+
minor_result.ec != std::errc() || minor_result.ptr != minor_end) {
43+
return invalid_status;
44+
}
45+
return egl::D3DFeatureLevel{major, minor};
46+
}
47+
48+
// Returns the D3D11 feature level cap from the environment, if set. The cap
49+
// lets tests emulate older GPUs, where ANGLE may only create OpenGL ES 2.0
50+
// contexts.
51+
std::optional<egl::D3DFeatureLevel> GetMaxD3DFeatureLevelFromEnvironment() {
52+
// Like engine switches, only read the environment in debug and profile.
53+
#ifndef FLUTTER_RELEASE
54+
constexpr char kKey[] = "FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL";
55+
const char* value = std::getenv(kKey);
56+
if (value == nullptr || value[0] == '\0') {
57+
return std::nullopt;
58+
}
59+
absl::StatusOr<egl::D3DFeatureLevel> level = ParseD3DFeatureLevel(value);
60+
if (!level.ok()) {
61+
FML_LOG(WARNING) << "Ignoring " << kKey << "=" << value << ": "
62+
<< level.status().message();
63+
return std::nullopt;
64+
}
65+
return level.value();
66+
#else
67+
return std::nullopt;
68+
#endif // !FLUTTER_RELEASE
69+
}
70+
71+
} // namespace
72+
1773
FlutterProjectBundle::FlutterProjectBundle(
1874
const FlutterDesktopEngineProperties& properties)
1975
: assets_path_(properties.assets_path),
@@ -45,6 +101,8 @@ FlutterProjectBundle::FlutterProjectBundle(
45101

46102
enable_flutter_gpu_ = properties.enable_flutter_gpu;
47103

104+
max_d3d_feature_level_ = GetMaxD3DFeatureLevelFromEnvironment();
105+
48106
// Resolve any relative paths.
49107
if (assets_path_.is_relative() || icu_path_.is_relative() ||
50108
(!aot_library_path_.empty() && aot_library_path_.is_relative())) {

‎engine/src/flutter/shell/platform/windows/flutter_project_bundle.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_PROJECT_BUNDLE_H_
77

88
#include <filesystem>
9+
#include <optional>
910
#include <string>
1011
#include <vector>
1112

1213
#include "flutter/shell/platform/embedder/embedder.h"
14+
#include "flutter/shell/platform/windows/egl/manager.h"
1315
#include "flutter/shell/platform/windows/public/flutter_windows.h"
1416

1517
namespace flutter {
@@ -100,6 +102,11 @@ class FlutterProjectBundle {
100102
// Returns whether the Flutter GPU API is enabled.
101103
bool enable_flutter_gpu() const { return enable_flutter_gpu_; }
102104

105+
// Returns the cap on the D3D11 feature level that ANGLE may use, if set.
106+
std::optional<egl::D3DFeatureLevel> max_d3d_feature_level() const {
107+
return max_d3d_feature_level_;
108+
}
109+
103110
private:
104111
std::filesystem::path assets_path_;
105112
std::filesystem::path icu_path_;
@@ -130,6 +137,11 @@ class FlutterProjectBundle {
130137

131138
// Whether the Flutter GPU API is enabled.
132139
bool enable_flutter_gpu_ = false;
140+
141+
// Cap on the D3D11 feature level that ANGLE may use. Set from the
142+
// FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL environment variable in debug and
143+
// profile builds.
144+
std::optional<egl::D3DFeatureLevel> max_d3d_feature_level_;
133145
};
134146

135147
} // namespace flutter

‎engine/src/flutter/shell/platform/windows/flutter_project_bundle_unittests.cc‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,54 @@ TEST(FlutterProjectBundle, Switches) {
9595
EXPECT_EQ(switches[0], "--abc");
9696
EXPECT_EQ(switches[1], "--foo=\"bar, baz\"");
9797
}
98+
99+
TEST(FlutterProjectBundle, MaxD3DFeatureLevelUnset) {
100+
FlutterDesktopEngineProperties properties = {};
101+
properties.assets_path = L"foo\\flutter_assets";
102+
properties.icu_data_path = L"foo\\icudtl.dat";
103+
104+
_putenv_s("FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL", "");
105+
106+
FlutterProjectBundle project(properties);
107+
108+
EXPECT_EQ(project.max_d3d_feature_level(), std::nullopt);
109+
}
110+
111+
TEST(FlutterProjectBundle, MaxD3DFeatureLevel) {
112+
FlutterDesktopEngineProperties properties = {};
113+
properties.assets_path = L"foo\\flutter_assets";
114+
properties.icu_data_path = L"foo\\icudtl.dat";
115+
116+
_putenv_s("FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL", "10_0");
117+
FlutterProjectBundle project_10_0(properties);
118+
119+
_putenv_s("FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL", "11_1");
120+
FlutterProjectBundle project_11_1(properties);
121+
122+
_putenv_s("FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL", "");
123+
124+
ASSERT_TRUE(project_10_0.max_d3d_feature_level().has_value());
125+
EXPECT_EQ(project_10_0.max_d3d_feature_level()->major, 10);
126+
EXPECT_EQ(project_10_0.max_d3d_feature_level()->minor, 0);
127+
128+
ASSERT_TRUE(project_11_1.max_d3d_feature_level().has_value());
129+
EXPECT_EQ(project_11_1.max_d3d_feature_level()->major, 11);
130+
EXPECT_EQ(project_11_1.max_d3d_feature_level()->minor, 1);
131+
}
132+
133+
TEST(FlutterProjectBundle, MaxD3DFeatureLevelMalformed) {
134+
FlutterDesktopEngineProperties properties = {};
135+
properties.assets_path = L"foo\\flutter_assets";
136+
properties.icu_data_path = L"foo\\icudtl.dat";
137+
138+
for (const char* value : {"10", "10.0", "10_", "_0", "10_0 ", "ten_zero"}) {
139+
_putenv_s("FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL", value);
140+
FlutterProjectBundle project(properties);
141+
_putenv_s("FLUTTER_WINDOWS_MAX_D3D_FEATURE_LEVEL", "");
142+
143+
EXPECT_EQ(project.max_d3d_feature_level(), std::nullopt) << value;
144+
}
145+
}
98146
#endif // !FLUTTER_RELEASE
99147

100148
} // namespace testing

0 commit comments

Comments
 (0)