[Impeller] Add a way to query the gfx backend type. (flutter/engine#43837)
I've been trying to avoid this, but since the context type may vary through runtime decisions, we just need something like this to select which shader data to pull from the Dart GPU bundle at runtime. One alternative would be to add a special omni shader concept to the HAL, but that seems worse than just letting renderers key with a backend enum sometimes. Cautioned against using it for cap checks in the doc string.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock-function-mocker.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
@@ -64,6 +65,8 @@ class ContextMock : public Context {
|
||||
public:
|
||||
MOCK_CONST_METHOD0(DescribeGpuModel, std::string());
|
||||
|
||||
MOCK_CONST_METHOD0(GetBackendType, Context::BackendType());
|
||||
|
||||
MOCK_CONST_METHOD0(IsValid, bool());
|
||||
|
||||
MOCK_CONST_METHOD0(GetCapabilities,
|
||||
|
||||
@@ -86,6 +86,10 @@ ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
|
||||
|
||||
ContextGLES::~ContextGLES() = default;
|
||||
|
||||
Context::BackendType ContextGLES::GetBackendType() const {
|
||||
return Context::BackendType::kOpenGLES;
|
||||
}
|
||||
|
||||
const ReactorGLES::Ref& ContextGLES::GetReactor() const {
|
||||
return reactor_;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ class ContextGLES final : public Context,
|
||||
// |Context|
|
||||
~ContextGLES() override;
|
||||
|
||||
// |Context|
|
||||
BackendType GetBackendType() const override;
|
||||
|
||||
const ReactorGLES::Ref& GetReactor() const;
|
||||
|
||||
std::optional<ReactorGLES::WorkerID> AddReactorWorker(
|
||||
|
||||
@@ -52,6 +52,9 @@ class ContextMTL final : public Context,
|
||||
// |Context|
|
||||
~ContextMTL() override;
|
||||
|
||||
// |Context|
|
||||
BackendType GetBackendType() const override;
|
||||
|
||||
id<MTLDevice> GetMTLDevice() const;
|
||||
|
||||
// |Context|
|
||||
|
||||
@@ -286,6 +286,10 @@ std::shared_ptr<ContextMTL> ContextMTL::Create(
|
||||
|
||||
ContextMTL::~ContextMTL() = default;
|
||||
|
||||
Context::BackendType ContextMTL::GetBackendType() const {
|
||||
return Context::BackendType::kMetal;
|
||||
}
|
||||
|
||||
// |Context|
|
||||
std::string ContextMTL::DescribeGpuModel() const {
|
||||
return std::string([[device_ name] UTF8String]);
|
||||
|
||||
@@ -120,6 +120,10 @@ ContextVK::~ContextVK() {
|
||||
CommandPoolVK::ClearAllPools(this);
|
||||
}
|
||||
|
||||
Context::BackendType ContextVK::GetBackendType() const {
|
||||
return Context::BackendType::kVulkan;
|
||||
}
|
||||
|
||||
void ContextVK::Setup(Settings settings) {
|
||||
TRACE_EVENT0("impeller", "ContextVK::Setup");
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ class ContextVK final : public Context,
|
||||
// |Context|
|
||||
~ContextVK() override;
|
||||
|
||||
// |Context|
|
||||
BackendType GetBackendType() const override;
|
||||
|
||||
// |Context|
|
||||
std::string DescribeGpuModel() const override;
|
||||
|
||||
|
||||
@@ -43,11 +43,32 @@ class Allocator;
|
||||
/// `//impeller/renderer/backend`.
|
||||
class Context {
|
||||
public:
|
||||
enum class BackendType {
|
||||
kMetal,
|
||||
kOpenGLES,
|
||||
kVulkan,
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Destroys an Impeller context.
|
||||
///
|
||||
virtual ~Context();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Get the graphics backend of an Impeller context.
|
||||
///
|
||||
/// This is useful for cases where a renderer needs to track and
|
||||
/// lookup backend-specific resources, like shaders or uniform
|
||||
/// layout information.
|
||||
///
|
||||
/// It's not recommended to use this as a substitute for
|
||||
/// per-backend capability checking. Instead, check for specific
|
||||
/// capabilities via `GetCapabilities()`.
|
||||
///
|
||||
/// @return The graphics backend of the `Context`.
|
||||
///
|
||||
virtual BackendType GetBackendType() const = 0;
|
||||
|
||||
// TODO(129920): Refactor and move to capabilities.
|
||||
virtual std::string DescribeGpuModel() const = 0;
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ class MockCommandBuffer : public CommandBuffer {
|
||||
|
||||
class MockImpellerContext : public Context {
|
||||
public:
|
||||
MOCK_CONST_METHOD0(GetBackendType, Context::BackendType());
|
||||
|
||||
MOCK_CONST_METHOD0(DescribeGpuModel, std::string());
|
||||
|
||||
MOCK_CONST_METHOD0(IsValid, bool());
|
||||
|
||||
@@ -113,6 +113,8 @@ class TestImpellerContext : public impeller::Context {
|
||||
public:
|
||||
TestImpellerContext() = default;
|
||||
|
||||
BackendType GetBackendType() const override { return BackendType::kMetal; }
|
||||
|
||||
std::string DescribeGpuModel() const override { return "TestGpu"; }
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
|
||||
Reference in New Issue
Block a user