mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Configure contexts to reduce shader variations. (flutter/engine#27016)
Context creation options for each backend were spread across multiple translation units. This makes setting options common across all backends hard to configure. I have moved the creation of such common options into a separate translation unit. Fixes https://github.com/flutter/flutter/issues/84213
This commit is contained in:
parent
7645b70658
commit
7cfb375a5e
@ -671,6 +671,8 @@ FILE: ../../../flutter/shell/common/animator_unittests.cc
|
||||
FILE: ../../../flutter/shell/common/canvas_spy.cc
|
||||
FILE: ../../../flutter/shell/common/canvas_spy.h
|
||||
FILE: ../../../flutter/shell/common/canvas_spy_unittests.cc
|
||||
FILE: ../../../flutter/shell/common/context_options.cc
|
||||
FILE: ../../../flutter/shell/common/context_options.h
|
||||
FILE: ../../../flutter/shell/common/display.h
|
||||
FILE: ../../../flutter/shell/common/display_manager.cc
|
||||
FILE: ../../../flutter/shell/common/display_manager.h
|
||||
|
||||
@ -64,6 +64,8 @@ source_set("common") {
|
||||
"animator.h",
|
||||
"canvas_spy.cc",
|
||||
"canvas_spy.h",
|
||||
"context_options.cc",
|
||||
"context_options.h",
|
||||
"display.h",
|
||||
"display_manager.cc",
|
||||
"display_manager.h",
|
||||
|
||||
39
engine/src/flutter/shell/common/context_options.cc
Normal file
39
engine/src/flutter/shell/common/context_options.cc
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/common/context_options.h"
|
||||
|
||||
#include "flutter/common/graphics/persistent_cache.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
GrContextOptions MakeDefaultContextOptions(ContextType type,
|
||||
std::optional<GrBackendApi> api) {
|
||||
GrContextOptions options;
|
||||
|
||||
if (PersistentCache::cache_sksl()) {
|
||||
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
|
||||
}
|
||||
PersistentCache::MarkStrategySet();
|
||||
options.fPersistentCache = PersistentCache::GetCacheForProcess();
|
||||
|
||||
if (api.has_value() && api.value() == GrBackendApi::kOpenGL) {
|
||||
options.fAvoidStencilBuffers = true;
|
||||
|
||||
// To get video playback on the widest range of devices, we limit Skia to
|
||||
// ES2 shading language when the ES3 external image extension is missing.
|
||||
options.fPreferExternalImagesOverES3 = true;
|
||||
}
|
||||
|
||||
// TODO(goderbauer): remove option when skbug.com/7523 is fixed.
|
||||
options.fDisableGpuYUVConversion = true;
|
||||
|
||||
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
|
||||
|
||||
options.fReducedShaderVariations = true;
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
43
engine/src/flutter/shell/common/context_options.h
Normal file
43
engine/src/flutter/shell/common/context_options.h
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_
|
||||
#define FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "third_party/skia/include/gpu/GrContextOptions.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
enum class ContextType {
|
||||
/// The context is used to render to a texture or renderbuffer.
|
||||
kRender,
|
||||
/// The context will only be used to transfer resources to and from device
|
||||
/// memory. No rendering will be performed using this context.
|
||||
kResource,
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Initializes GrContextOptions with values suitable for Flutter.
|
||||
/// The options can be further tweaked before a GrContext is created
|
||||
/// from these options.
|
||||
///
|
||||
/// @param[in] type The type of context that will be created using these
|
||||
/// options.
|
||||
/// @param[in] type The client rendering API that will be wrapped using a
|
||||
/// context with these options. This argument is only required
|
||||
/// if the context is going to be used with a particular
|
||||
/// client rendering API.
|
||||
///
|
||||
/// @return The default graphics context options.
|
||||
///
|
||||
GrContextOptions MakeDefaultContextOptions(
|
||||
ContextType type,
|
||||
std::optional<GrBackendApi> api = std::nullopt);
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_
|
||||
@ -11,7 +11,6 @@
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/vsync_waiter_fallback.h"
|
||||
#include "third_party/skia/include/gpu/GrContextOptions.h"
|
||||
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "flutter/common/graphics/persistent_cache.h"
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/message_loop.h"
|
||||
#include "flutter/shell/common/context_options.h"
|
||||
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
|
||||
|
||||
namespace flutter {
|
||||
@ -18,30 +19,7 @@ sk_sp<GrDirectContext> ShellIOManager::CreateCompatibleResourceLoadingContext(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrContextOptions options = {};
|
||||
|
||||
if (PersistentCache::cache_sksl()) {
|
||||
FML_LOG(INFO) << "Cache SkSL";
|
||||
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
|
||||
}
|
||||
PersistentCache::MarkStrategySet();
|
||||
|
||||
options.fPersistentCache = PersistentCache::GetCacheForProcess();
|
||||
|
||||
// There is currently a bug with doing GPU YUV to RGB conversions on the IO
|
||||
// thread. The necessary work isn't being flushed or synchronized with the
|
||||
// other threads correctly, so the textures end up blank. For now, suppress
|
||||
// that feature, which will cause texture uploads to do CPU YUV conversion.
|
||||
// A similar work-around is also used in shell/gpu/gpu_surface_gl.cc.
|
||||
options.fDisableGpuYUVConversion = true;
|
||||
|
||||
// To get video playback on the widest range of devices, we limit Skia to
|
||||
// ES2 shading language when the ES3 external image extension is missing.
|
||||
options.fPreferExternalImagesOverES3 = true;
|
||||
|
||||
// Enabling this flag can increase VRAM consumption. Turn it off until
|
||||
// further notice.
|
||||
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
|
||||
const auto options = MakeDefaultContextOptions(ContextType::kResource);
|
||||
|
||||
#if !OS_FUCHSIA
|
||||
if (auto context = GrDirectContext::MakeGL(gl_interface, options)) {
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
|
||||
|
||||
#include "flutter/common/graphics/persistent_cache.h"
|
||||
#include "flutter/shell/common/context_options.h"
|
||||
#include "flutter/vulkan/vulkan_utilities.h"
|
||||
|
||||
namespace flutter {
|
||||
@ -113,13 +114,8 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
GrContextOptions options;
|
||||
if (PersistentCache::cache_sksl()) {
|
||||
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
|
||||
}
|
||||
PersistentCache::MarkStrategySet();
|
||||
options.fPersistentCache = PersistentCache::GetCacheForProcess();
|
||||
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
|
||||
const auto options =
|
||||
MakeDefaultContextOptions(ContextType::kRender, GrBackendApi::kVulkan);
|
||||
|
||||
sk_sp<GrDirectContext> context =
|
||||
GrDirectContext::MakeVulkan(backend_context, options);
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "flutter/shell/common/context_options.h"
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
#include "third_party/skia/include/gpu/GrBackendSurface.h"
|
||||
@ -43,26 +44,8 @@ sk_sp<GrDirectContext> GPUSurfaceGL::MakeGLContext(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrContextOptions options;
|
||||
|
||||
if (PersistentCache::cache_sksl()) {
|
||||
FML_LOG(INFO) << "Cache SkSL";
|
||||
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
|
||||
}
|
||||
PersistentCache::MarkStrategySet();
|
||||
options.fPersistentCache = PersistentCache::GetCacheForProcess();
|
||||
|
||||
options.fAvoidStencilBuffers = true;
|
||||
|
||||
// To get video playback on the widest range of devices, we limit Skia to
|
||||
// ES2 shading language when the ES3 external image extension is missing.
|
||||
options.fPreferExternalImagesOverES3 = true;
|
||||
|
||||
// TODO(goderbauer): remove option when skbug.com/7523 is fixed.
|
||||
// A similar work-around is also used in shell/common/io_manager.cc.
|
||||
options.fDisableGpuYUVConversion = true;
|
||||
|
||||
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
|
||||
const auto options =
|
||||
MakeDefaultContextOptions(ContextType::kRender, GrBackendApi::kOpenGL);
|
||||
|
||||
auto context = GrDirectContext::MakeGL(delegate->GetGLInterface(), options);
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ source_set("graphics") {
|
||||
deps = [
|
||||
"//flutter/common/graphics",
|
||||
"//flutter/fml",
|
||||
"//flutter/shell/common",
|
||||
"//flutter/shell/platform/darwin/common:framework_shared",
|
||||
]
|
||||
|
||||
|
||||
@ -7,21 +7,10 @@
|
||||
#include "flutter/common/graphics/persistent_cache.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
|
||||
#include "third_party/skia/include/gpu/GrContextOptions.h"
|
||||
#include "shell/common/context_options.h"
|
||||
|
||||
FLUTTER_ASSERT_ARC
|
||||
|
||||
static GrContextOptions CreateMetalGrContextOptions() {
|
||||
GrContextOptions options = {};
|
||||
if (flutter::PersistentCache::cache_sksl()) {
|
||||
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
|
||||
}
|
||||
flutter::PersistentCache::MarkStrategySet();
|
||||
options.fPersistentCache = flutter::PersistentCache::GetCacheForProcess();
|
||||
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
|
||||
return options;
|
||||
}
|
||||
|
||||
@implementation FlutterDarwinContextMetal
|
||||
|
||||
- (instancetype)initWithDefaultMTLDevice {
|
||||
@ -77,7 +66,8 @@ static GrContextOptions CreateMetalGrContextOptions() {
|
||||
}
|
||||
|
||||
- (sk_sp<GrDirectContext>)createGrContext {
|
||||
auto contextOptions = CreateMetalGrContextOptions();
|
||||
const auto contextOptions =
|
||||
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender, GrBackendApi::kMetal);
|
||||
id<MTLDevice> device = _device;
|
||||
id<MTLCommandQueue> commandQueue = _commandQueue;
|
||||
return [FlutterDarwinContextMetal createGrContext:device commandQueue:commandQueue];
|
||||
@ -85,7 +75,8 @@ static GrContextOptions CreateMetalGrContextOptions() {
|
||||
|
||||
+ (sk_sp<GrDirectContext>)createGrContext:(id<MTLDevice>)device
|
||||
commandQueue:(id<MTLCommandQueue>)commandQueue {
|
||||
auto contextOptions = CreateMetalGrContextOptions();
|
||||
const auto contextOptions =
|
||||
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender, GrBackendApi::kMetal);
|
||||
// Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
|
||||
// when the GrDirectContext is collected.
|
||||
return GrDirectContext::MakeMetal((__bridge_retained void*)device,
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
@ -20,6 +20,7 @@
|
||||
#include "flutter/flow/embedded_views.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
#include "flutter/lib/ui/window/viewport_metrics.h"
|
||||
#include "flutter/shell/common/context_options.h"
|
||||
#include "flutter/shell/platform/fuchsia/flutter/platform_view.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
@ -347,8 +348,9 @@ TEST_F(PlatformViewTests, CreateSurfaceTest) {
|
||||
);
|
||||
|
||||
// Test create surface callback function.
|
||||
sk_sp<GrDirectContext> gr_context =
|
||||
GrDirectContext::MakeMock(nullptr, GrContextOptions());
|
||||
sk_sp<GrDirectContext> gr_context = GrDirectContext::MakeMock(
|
||||
nullptr,
|
||||
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender));
|
||||
std::shared_ptr<MockExternalViewEmbedder> view_embedder =
|
||||
std::make_shared<MockExternalViewEmbedder>();
|
||||
auto CreateSurfaceCallback = [&view_embedder, gr_context]() {
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "flutter/shell/common/context_options.h"
|
||||
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
|
||||
#include "third_party/skia/include/gpu/GrBackendSurface.h"
|
||||
#include "third_party/skia/include/gpu/GrDirectContext.h"
|
||||
@ -137,9 +138,8 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) {
|
||||
backend_context.fPhysicalDevice, 0, nullptr,
|
||||
countof(device_extensions), device_extensions);
|
||||
backend_context.fVkExtensions = &vk_extensions;
|
||||
GrContextOptions options;
|
||||
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
|
||||
|
||||
const auto options = flutter::MakeDefaultContextOptions(
|
||||
flutter::ContextType::kRender, GrBackendApi::kVulkan);
|
||||
context_ = GrDirectContext::MakeVulkan(backend_context, options);
|
||||
|
||||
if (context_ == nullptr) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user