diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index a051333848..a4657cb0b7 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -898,6 +898,7 @@ FILE: ../../../flutter/impeller/runtime_stage/runtime_stage.h FILE: ../../../flutter/impeller/runtime_stage/runtime_stage_playground.cc FILE: ../../../flutter/impeller/runtime_stage/runtime_stage_playground.h FILE: ../../../flutter/impeller/runtime_stage/runtime_stage_unittests.cc +FILE: ../../../flutter/impeller/runtime_stage/runtime_types.h FILE: ../../../flutter/impeller/tessellator/c/tessellator.cc FILE: ../../../flutter/impeller/tessellator/c/tessellator.h FILE: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart diff --git a/engine/src/flutter/impeller/renderer/BUILD.gn b/engine/src/flutter/impeller/renderer/BUILD.gn index 460502c838..f593a42fd1 100644 --- a/engine/src/flutter/impeller/renderer/BUILD.gn +++ b/engine/src/flutter/impeller/renderer/BUILD.gn @@ -81,6 +81,7 @@ impeller_component("renderer") { "../base", "../geometry", "../image", + "../runtime_stage", "../tessellator", ] diff --git a/engine/src/flutter/impeller/renderer/shader_types.h b/engine/src/flutter/impeller/renderer/shader_types.h index 7750032b03..fe4af812f1 100644 --- a/engine/src/flutter/impeller/renderer/shader_types.h +++ b/engine/src/flutter/impeller/renderer/shader_types.h @@ -9,7 +9,9 @@ #include #include "flutter/fml/hash_combine.h" +#include "flutter/fml/logging.h" #include "impeller/geometry/matrix.h" +#include "impeller/runtime_stage/runtime_types.h" namespace impeller { @@ -22,6 +24,22 @@ enum class ShaderStage { kCompute, }; +constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage) { + switch (stage) { + case RuntimeShaderStage::kVertex: + return ShaderStage::kVertex; + case RuntimeShaderStage::kFragment: + return ShaderStage::kFragment; + case RuntimeShaderStage::kCompute: + return ShaderStage::kCompute; + case RuntimeShaderStage::kTessellationControl: + return ShaderStage::kTessellationControl; + case RuntimeShaderStage::kTessellationEvaluation: + return ShaderStage::kTessellationEvaluation; + } + FML_UNREACHABLE(); +} + enum class ShaderType { kUnknown, kVoid, diff --git a/engine/src/flutter/impeller/runtime_stage/BUILD.gn b/engine/src/flutter/impeller/runtime_stage/BUILD.gn index e0fe250226..b36a7f9017 100644 --- a/engine/src/flutter/impeller/runtime_stage/BUILD.gn +++ b/engine/src/flutter/impeller/runtime_stage/BUILD.gn @@ -20,11 +20,11 @@ impeller_component("runtime_stage") { sources = [ "runtime_stage.cc", "runtime_stage.h", + "runtime_types.h", ] public_deps = [ ":runtime_stage_flatbuffers", "../base", - "../renderer", "//flutter/fml", ] } diff --git a/engine/src/flutter/impeller/runtime_stage/runtime_stage.cc b/engine/src/flutter/impeller/runtime_stage/runtime_stage.cc index 353287d6a0..c75f33b425 100644 --- a/engine/src/flutter/impeller/runtime_stage/runtime_stage.cc +++ b/engine/src/flutter/impeller/runtime_stage/runtime_stage.cc @@ -43,18 +43,18 @@ static RuntimeUniformType ToType(fb::UniformDataType type) { FML_UNREACHABLE(); } -static ShaderStage ToShaderStage(fb::Stage stage) { +static RuntimeShaderStage ToShaderStage(fb::Stage stage) { switch (stage) { case fb::Stage::kVertex: - return ShaderStage::kVertex; + return RuntimeShaderStage::kVertex; case fb::Stage::kFragment: - return ShaderStage::kFragment; + return RuntimeShaderStage::kFragment; case fb::Stage::kCompute: - return ShaderStage::kCompute; + return RuntimeShaderStage::kCompute; case fb::Stage::kTessellationControl: - return ShaderStage::kTessellationControl; + return RuntimeShaderStage::kTessellationControl; case fb::Stage::kTessellationEvaluation: - return ShaderStage::kTessellationEvaluation; + return RuntimeShaderStage::kTessellationEvaluation; } FML_UNREACHABLE(); } @@ -128,7 +128,7 @@ const std::string& RuntimeStage::GetEntrypoint() const { return entrypoint_; } -ShaderStage RuntimeStage::GetShaderStage() const { +RuntimeShaderStage RuntimeStage::GetShaderStage() const { return stage_; } diff --git a/engine/src/flutter/impeller/runtime_stage/runtime_stage.h b/engine/src/flutter/impeller/runtime_stage/runtime_stage.h index 2bbcf83d37..fcf5d529d9 100644 --- a/engine/src/flutter/impeller/runtime_stage/runtime_stage.h +++ b/engine/src/flutter/impeller/runtime_stage/runtime_stage.h @@ -9,52 +9,19 @@ #include "flutter/fml/macros.h" #include "flutter/fml/mapping.h" -#include "impeller/renderer/shader_function.h" -#include "impeller/renderer/shader_types.h" +#include "impeller/runtime_stage/runtime_types.h" namespace impeller { -enum RuntimeUniformType { - kBoolean, - kSignedByte, - kUnsignedByte, - kSignedShort, - kUnsignedShort, - kSignedInt, - kUnsignedInt, - kSignedInt64, - kUnsignedInt64, - kHalfFloat, - kFloat, - kDouble, - kSampledImage, -}; - -struct RuntimeUniformDimensions { - size_t rows = 0; - size_t cols = 0; -}; - -struct RuntimeUniformDescription { - std::string name; - size_t location = 0u; - RuntimeUniformType type = kFloat; - RuntimeUniformDimensions dimensions; - size_t bit_width; - size_t array_elements; -}; - -size_t SizeOfRuntimeUniformType(RuntimeUniformType type); - class RuntimeStage { public: - RuntimeStage(std::shared_ptr payload); + explicit RuntimeStage(std::shared_ptr payload); ~RuntimeStage(); bool IsValid() const; - ShaderStage GetShaderStage() const; + RuntimeShaderStage GetShaderStage() const; const std::vector& GetUniforms() const; @@ -65,7 +32,7 @@ class RuntimeStage { const std::shared_ptr& GetCodeMapping() const; private: - ShaderStage stage_ = ShaderStage::kUnknown; + RuntimeShaderStage stage_ = RuntimeShaderStage::kVertex; std::shared_ptr payload_; std::string entrypoint_; std::shared_ptr code_mapping_; diff --git a/engine/src/flutter/impeller/runtime_stage/runtime_stage_playground.cc b/engine/src/flutter/impeller/runtime_stage/runtime_stage_playground.cc index af1dc536cf..0960308433 100644 --- a/engine/src/flutter/impeller/runtime_stage/runtime_stage_playground.cc +++ b/engine/src/flutter/impeller/runtime_stage/runtime_stage_playground.cc @@ -9,6 +9,7 @@ #include "flutter/fml/make_copyable.h" #include "flutter/testing/testing.h" #include "impeller/renderer/shader_library.h" +#include "impeller/renderer/shader_types.h" namespace impeller { @@ -34,7 +35,8 @@ bool RuntimeStagePlayground::RegisterStage(const RuntimeStage& stage) { auto future = registration.get_future(); auto library = GetContext()->GetShaderLibrary(); GetContext()->GetShaderLibrary()->RegisterFunction( - stage.GetEntrypoint(), stage.GetShaderStage(), stage.GetCodeMapping(), + stage.GetEntrypoint(), ToShaderStage(stage.GetShaderStage()), + stage.GetCodeMapping(), fml::MakeCopyable([reg = std::move(registration)](bool result) mutable { reg.set_value(result); })); diff --git a/engine/src/flutter/impeller/runtime_stage/runtime_stage_unittests.cc b/engine/src/flutter/impeller/runtime_stage/runtime_stage_unittests.cc index 66e3a83da6..108d59d074 100644 --- a/engine/src/flutter/impeller/runtime_stage/runtime_stage_unittests.cc +++ b/engine/src/flutter/impeller/runtime_stage/runtime_stage_unittests.cc @@ -13,6 +13,7 @@ #include "impeller/renderer/pipeline_descriptor.h" #include "impeller/renderer/pipeline_library.h" #include "impeller/renderer/shader_library.h" +#include "impeller/renderer/shader_types.h" #include "impeller/runtime_stage/runtime_stage.h" #include "impeller/runtime_stage/runtime_stage_playground.h" @@ -29,7 +30,7 @@ TEST(RuntimeStageTest, CanReadValidBlob) { ASSERT_GT(fixture->GetSize(), 0u); RuntimeStage stage(std::move(fixture)); ASSERT_TRUE(stage.IsValid()); - ASSERT_EQ(stage.GetShaderStage(), ShaderStage::kFragment); + ASSERT_EQ(stage.GetShaderStage(), RuntimeShaderStage::kFragment); } TEST(RuntimeStageTest, CanRejectInvalidBlob) { @@ -199,9 +200,9 @@ TEST_P(RuntimeStageTest, CanRegisterStage) { auto future = registration.get_future(); auto library = GetContext()->GetShaderLibrary(); library->RegisterFunction( - stage.GetEntrypoint(), // - stage.GetShaderStage(), // - stage.GetCodeMapping(), // + stage.GetEntrypoint(), // + ToShaderStage(stage.GetShaderStage()), // + stage.GetCodeMapping(), // fml::MakeCopyable([reg = std::move(registration)](bool result) mutable { reg.set_value(result); })); diff --git a/engine/src/flutter/impeller/runtime_stage/runtime_types.h b/engine/src/flutter/impeller/runtime_stage/runtime_types.h new file mode 100644 index 0000000000..7b3f06b050 --- /dev/null +++ b/engine/src/flutter/impeller/runtime_stage/runtime_types.h @@ -0,0 +1,50 @@ +// 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. + +#pragma once + +#include +#include + +namespace impeller { + +enum RuntimeUniformType { + kBoolean, + kSignedByte, + kUnsignedByte, + kSignedShort, + kUnsignedShort, + kSignedInt, + kUnsignedInt, + kSignedInt64, + kUnsignedInt64, + kHalfFloat, + kFloat, + kDouble, + kSampledImage, +}; + +enum class RuntimeShaderStage { + kVertex, + kFragment, + kCompute, + kTessellationControl, + kTessellationEvaluation, +}; + +struct RuntimeUniformDimensions { + size_t rows = 0; + size_t cols = 0; +}; + +struct RuntimeUniformDescription { + std::string name; + size_t location = 0u; + RuntimeUniformType type = RuntimeUniformType::kFloat; + RuntimeUniformDimensions dimensions; + size_t bit_width; + size_t array_elements; +}; + +} // namespace impeller