diff --git a/impeller/golden_tests/metal_screenshoter.mm b/impeller/golden_tests/metal_screenshoter.mm index cd1a8bbd536ea..5d051e12e6ca7 100644 --- a/impeller/golden_tests/metal_screenshoter.mm +++ b/impeller/golden_tests/metal_screenshoter.mm @@ -15,7 +15,8 @@ MetalScreenshoter::MetalScreenshoter() { FML_CHECK(::glfwInit() == GLFW_TRUE); - playground_ = PlaygroundImpl::Create(PlaygroundBackend::kMetal); + playground_ = + PlaygroundImpl::Create(PlaygroundBackend::kMetal, PlaygroundSwitches{}); aiks_context_.reset(new AiksContext(playground_->GetContext())); } diff --git a/impeller/playground/backend/gles/playground_impl_gles.cc b/impeller/playground/backend/gles/playground_impl_gles.cc index a1441a7bf6e2f..6e5c3f11ab198 100644 --- a/impeller/playground/backend/gles/playground_impl_gles.cc +++ b/impeller/playground/backend/gles/playground_impl_gles.cc @@ -51,8 +51,9 @@ void PlaygroundImplGLES::DestroyWindowHandle(WindowHandle handle) { ::glfwDestroyWindow(reinterpret_cast(handle)); } -PlaygroundImplGLES::PlaygroundImplGLES() - : handle_(nullptr, &DestroyWindowHandle), +PlaygroundImplGLES::PlaygroundImplGLES(PlaygroundSwitches switches) + : PlaygroundImpl(switches), + handle_(nullptr, &DestroyWindowHandle), worker_(std::shared_ptr(new ReactorWorker())) { ::glfwDefaultWindowHints(); diff --git a/impeller/playground/backend/gles/playground_impl_gles.h b/impeller/playground/backend/gles/playground_impl_gles.h index 9540d1460e6a9..1aecd2138e6db 100644 --- a/impeller/playground/backend/gles/playground_impl_gles.h +++ b/impeller/playground/backend/gles/playground_impl_gles.h @@ -11,7 +11,7 @@ namespace impeller { class PlaygroundImplGLES final : public PlaygroundImpl { public: - PlaygroundImplGLES(); + explicit PlaygroundImplGLES(PlaygroundSwitches switches); ~PlaygroundImplGLES(); diff --git a/impeller/playground/backend/metal/playground_impl_mtl.h b/impeller/playground/backend/metal/playground_impl_mtl.h index 345574ebe16ac..d1b1aebd80edb 100644 --- a/impeller/playground/backend/metal/playground_impl_mtl.h +++ b/impeller/playground/backend/metal/playground_impl_mtl.h @@ -13,7 +13,7 @@ namespace impeller { class PlaygroundImplMTL final : public PlaygroundImpl { public: - PlaygroundImplMTL(); + explicit PlaygroundImplMTL(PlaygroundSwitches switches); ~PlaygroundImplMTL(); diff --git a/impeller/playground/backend/metal/playground_impl_mtl.mm b/impeller/playground/backend/metal/playground_impl_mtl.mm index cf26700b41706..8ac6758469548 100644 --- a/impeller/playground/backend/metal/playground_impl_mtl.mm +++ b/impeller/playground/backend/metal/playground_impl_mtl.mm @@ -62,8 +62,10 @@ ::glfwDestroyWindow(reinterpret_cast(handle)); } -PlaygroundImplMTL::PlaygroundImplMTL() - : handle_(nullptr, &DestroyWindowHandle), data_(std::make_unique()) { +PlaygroundImplMTL::PlaygroundImplMTL(PlaygroundSwitches switches) + : PlaygroundImpl(switches), + handle_(nullptr, &DestroyWindowHandle), + data_(std::make_unique()) { ::glfwDefaultWindowHints(); ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); diff --git a/impeller/playground/backend/vulkan/playground_impl_vk.cc b/impeller/playground/backend/vulkan/playground_impl_vk.cc index 5460fa44d7ee4..a5840872cbed8 100644 --- a/impeller/playground/backend/vulkan/playground_impl_vk.cc +++ b/impeller/playground/backend/vulkan/playground_impl_vk.cc @@ -48,8 +48,9 @@ void PlaygroundImplVK::DestroyWindowHandle(WindowHandle handle) { ::glfwDestroyWindow(reinterpret_cast(handle)); } -PlaygroundImplVK::PlaygroundImplVK() - : concurrent_loop_(fml::ConcurrentMessageLoop::Create()), +PlaygroundImplVK::PlaygroundImplVK(PlaygroundSwitches switches) + : PlaygroundImpl(switches), + concurrent_loop_(fml::ConcurrentMessageLoop::Create()), handle_(nullptr, &DestroyWindowHandle) { if (!::glfwVulkanSupported()) { VALIDATION_LOG << "Attempted to initialize a Vulkan playground on a system " @@ -76,6 +77,7 @@ PlaygroundImplVK::PlaygroundImplVK() context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground(); context_settings.cache_directory = fml::paths::GetCachesDirectory(); context_settings.worker_task_runner = concurrent_loop_->GetTaskRunner(); + context_settings.enable_validation = switches_.enable_vulkan_validation; auto context = ContextVK::Create(std::move(context_settings)); diff --git a/impeller/playground/backend/vulkan/playground_impl_vk.h b/impeller/playground/backend/vulkan/playground_impl_vk.h index a1aa4afa6e352..bb0a7842a18c7 100644 --- a/impeller/playground/backend/vulkan/playground_impl_vk.h +++ b/impeller/playground/backend/vulkan/playground_impl_vk.h @@ -13,7 +13,7 @@ namespace impeller { class PlaygroundImplVK final : public PlaygroundImpl { public: - PlaygroundImplVK(); + explicit PlaygroundImplVK(PlaygroundSwitches switches); ~PlaygroundImplVK(); diff --git a/impeller/playground/compute_playground_test.cc b/impeller/playground/compute_playground_test.cc index eda0b2ca6c619..71721e7577ec8 100644 --- a/impeller/playground/compute_playground_test.cc +++ b/impeller/playground/compute_playground_test.cc @@ -4,11 +4,13 @@ #include "flutter/fml/time/time_point.h" +#include "flutter/testing/test_args.h" #include "impeller/playground/compute_playground_test.h" namespace impeller { -ComputePlaygroundTest::ComputePlaygroundTest() = default; +ComputePlaygroundTest::ComputePlaygroundTest() + : Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {} ComputePlaygroundTest::~ComputePlaygroundTest() = default; diff --git a/impeller/playground/playground.cc b/impeller/playground/playground.cc index cbc2caf921fc4..1f1c5930ff864 100644 --- a/impeller/playground/playground.cc +++ b/impeller/playground/playground.cc @@ -73,8 +73,9 @@ struct Playground::GLFWInitializer { } }; -Playground::Playground() - : glfw_initializer_(std::make_unique()) {} +Playground::Playground(PlaygroundSwitches switches) + : switches_(switches), + glfw_initializer_(std::make_unique()) {} Playground::~Playground() = default; @@ -109,7 +110,7 @@ bool Playground::SupportsBackend(PlaygroundBackend backend) { void Playground::SetupContext(PlaygroundBackend backend) { FML_CHECK(SupportsBackend(backend)); - impl_ = PlaygroundImpl::Create(backend); + impl_ = PlaygroundImpl::Create(backend, switches_); if (!impl_) { return; } diff --git a/impeller/playground/playground.h b/impeller/playground/playground.h index f44e36c20b100..58be5f263838b 100644 --- a/impeller/playground/playground.h +++ b/impeller/playground/playground.h @@ -13,6 +13,7 @@ #include "impeller/geometry/point.h" #include "impeller/image/compressed_image.h" #include "impeller/image/decompressed_image.h" +#include "impeller/playground/switches.h" #include "impeller/renderer/renderer.h" #include "impeller/renderer/texture.h" #include "impeller/runtime_stage/runtime_stage.h" @@ -33,7 +34,7 @@ class Playground { public: using SinglePassCallback = std::function; - explicit Playground(); + explicit Playground(PlaygroundSwitches switches); virtual ~Playground(); @@ -92,6 +93,8 @@ class Playground { virtual std::string GetWindowTitle() const = 0; protected: + const PlaygroundSwitches switches_; + virtual bool ShouldKeepRendering() const; private: diff --git a/impeller/playground/playground_impl.cc b/impeller/playground/playground_impl.cc index 613de6e411a0c..75846e64b1991 100644 --- a/impeller/playground/playground_impl.cc +++ b/impeller/playground/playground_impl.cc @@ -22,19 +22,20 @@ namespace impeller { std::unique_ptr PlaygroundImpl::Create( - PlaygroundBackend backend) { + PlaygroundBackend backend, + PlaygroundSwitches switches) { switch (backend) { #if IMPELLER_ENABLE_METAL case PlaygroundBackend::kMetal: - return std::make_unique(); + return std::make_unique(switches); #endif // IMPELLER_ENABLE_METAL #if IMPELLER_ENABLE_OPENGLES case PlaygroundBackend::kOpenGLES: - return std::make_unique(); + return std::make_unique(switches); #endif // IMPELLER_ENABLE_OPENGLES #if IMPELLER_ENABLE_VULKAN case PlaygroundBackend::kVulkan: - return std::make_unique(); + return std::make_unique(switches); #endif // IMPELLER_ENABLE_VULKAN default: FML_CHECK(false) << "Attempted to create playground with backend that " @@ -44,7 +45,8 @@ std::unique_ptr PlaygroundImpl::Create( FML_UNREACHABLE(); } -PlaygroundImpl::PlaygroundImpl() = default; +PlaygroundImpl::PlaygroundImpl(PlaygroundSwitches switches) + : switches_(switches) {} PlaygroundImpl::~PlaygroundImpl() = default; diff --git a/impeller/playground/playground_impl.h b/impeller/playground/playground_impl.h index cd47439778d7e..e89946c977667 100644 --- a/impeller/playground/playground_impl.h +++ b/impeller/playground/playground_impl.h @@ -8,6 +8,7 @@ #include "flutter/fml/macros.h" #include "impeller/playground/playground.h" +#include "impeller/playground/switches.h" #include "impeller/renderer/context.h" #include "impeller/renderer/surface.h" @@ -15,7 +16,8 @@ namespace impeller { class PlaygroundImpl { public: - static std::unique_ptr Create(PlaygroundBackend backend); + static std::unique_ptr Create(PlaygroundBackend backend, + PlaygroundSwitches switches); virtual ~PlaygroundImpl(); @@ -31,7 +33,9 @@ class PlaygroundImpl { Vector2 GetContentScale() const; protected: - PlaygroundImpl(); + const PlaygroundSwitches switches_; + + explicit PlaygroundImpl(PlaygroundSwitches switches); private: FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundImpl); diff --git a/impeller/playground/playground_test.cc b/impeller/playground/playground_test.cc index 1b5a7bd13816f..95297cf3f92bc 100644 --- a/impeller/playground/playground_test.cc +++ b/impeller/playground/playground_test.cc @@ -10,7 +10,7 @@ namespace impeller { PlaygroundTest::PlaygroundTest() - : switches_(flutter::testing::GetArgsForProcess()) {} + : Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {} PlaygroundTest::~PlaygroundTest() = default; diff --git a/impeller/playground/playground_test.h b/impeller/playground/playground_test.h index f9ff98275abd3..f1c732f0a08db 100644 --- a/impeller/playground/playground_test.h +++ b/impeller/playground/playground_test.h @@ -39,8 +39,6 @@ class PlaygroundTest : public Playground, std::string GetWindowTitle() const override; private: - const PlaygroundSwitches switches_; - // |Playground| bool ShouldKeepRendering() const; diff --git a/impeller/playground/switches.cc b/impeller/playground/switches.cc index 3991e5f9831d5..6bce0438a0839 100644 --- a/impeller/playground/switches.cc +++ b/impeller/playground/switches.cc @@ -8,11 +8,14 @@ namespace impeller { +PlaygroundSwitches::PlaygroundSwitches() = default; + PlaygroundSwitches::PlaygroundSwitches(const fml::CommandLine& args) { std::string timeout_str; if (args.GetOptionValue("playground_timeout_ms", &timeout_str)) { timeout = std::chrono::milliseconds(atoi(timeout_str.c_str())); } + enable_vulkan_validation = args.HasOption("enable_vulkan_validation"); } } // namespace impeller diff --git a/impeller/playground/switches.h b/impeller/playground/switches.h index 905123b3cc986..b8a64b1582fdf 100644 --- a/impeller/playground/switches.h +++ b/impeller/playground/switches.h @@ -17,6 +17,9 @@ struct PlaygroundSwitches { // specified in the timeout. If the timeout is zero, exactly one frame will be // rendered in the playground. std::optional timeout; + bool enable_vulkan_validation = false; + + PlaygroundSwitches(); explicit PlaygroundSwitches(const fml::CommandLine& args); }; diff --git a/impeller/renderer/backend/vulkan/capabilities_vk.cc b/impeller/renderer/backend/vulkan/capabilities_vk.cc index 0e39a0977f3a7..45e6a4cb246c9 100644 --- a/impeller/renderer/backend/vulkan/capabilities_vk.cc +++ b/impeller/renderer/backend/vulkan/capabilities_vk.cc @@ -15,6 +15,9 @@ static constexpr const char* kInstanceLayer = "ImpellerInstance"; CapabilitiesVK::CapabilitiesVK(bool enable_validations) : enable_validations_(enable_validations) { + if (enable_validations_) { + FML_LOG(INFO) << "Vulkan validations are enabled."; + } auto extensions = vk::enumerateInstanceExtensionProperties(); auto layers = vk::enumerateInstanceLayerProperties(); diff --git a/impeller/renderer/backend/vulkan/capabilities_vk.h b/impeller/renderer/backend/vulkan/capabilities_vk.h index 313c28109d110..a2b46e5c77c1e 100644 --- a/impeller/renderer/backend/vulkan/capabilities_vk.h +++ b/impeller/renderer/backend/vulkan/capabilities_vk.h @@ -24,7 +24,7 @@ class ContextVK; class CapabilitiesVK final : public Capabilities, public BackendCast { public: - explicit CapabilitiesVK(bool enable_validations = false); + explicit CapabilitiesVK(bool enable_validations); ~CapabilitiesVK(); diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index 3ab610373de63..f2463d5ab1aa2 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -114,7 +114,8 @@ void ContextVK::Setup(Settings settings) { auto& dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER; dispatcher.init(settings.proc_address_callback); - auto caps = std::shared_ptr(new CapabilitiesVK()); + auto caps = std::shared_ptr( + new CapabilitiesVK(settings.enable_validation)); if (!caps->IsValid()) { VALIDATION_LOG << "Could not determine device capabilities."; diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index 19207433d0764..2a4ab9502c248 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -36,6 +36,7 @@ class ContextVK final : public Context, public BackendCast { std::vector> shader_libraries_data; fml::UniqueFD cache_directory; std::shared_ptr worker_task_runner; + bool enable_validation = false; Settings() = default;