Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 35cdd66

Browse files
committed
[Impeller] Add a way to query the gfx backend type.
1 parent 2d8cff4 commit 35cdd66

File tree

8 files changed

+45
-0
lines changed

8 files changed

+45
-0
lines changed

impeller/aiks/testing/context_mock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string>
88
#include <vector>
99

10+
#include "gmock/gmock-function-mocker.h"
1011
#include "gmock/gmock.h"
1112
#include "impeller/renderer/command_buffer.h"
1213
#include "impeller/renderer/context.h"
@@ -64,6 +65,8 @@ class ContextMock : public Context {
6465
public:
6566
MOCK_CONST_METHOD0(DescribeGpuModel, std::string());
6667

68+
MOCK_CONST_METHOD0(GetBackendType, Context::BackendType());
69+
6770
MOCK_CONST_METHOD0(IsValid, bool());
6871

6972
MOCK_CONST_METHOD0(GetCapabilities,

impeller/renderer/backend/gles/context_gles.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
8686

8787
ContextGLES::~ContextGLES() = default;
8888

89+
Context::BackendType ContextGLES::GetBackendType() const {
90+
return Context::BackendType::kOpenGLES;
91+
}
92+
8993
const ReactorGLES::Ref& ContextGLES::GetReactor() const {
9094
return reactor_;
9195
}

impeller/renderer/backend/gles/context_gles.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class ContextGLES final : public Context,
2828
// |Context|
2929
~ContextGLES() override;
3030

31+
// |Context|
32+
BackendType GetBackendType() const override;
33+
3134
const ReactorGLES::Ref& GetReactor() const;
3235

3336
std::optional<ReactorGLES::WorkerID> AddReactorWorker(

impeller/renderer/backend/metal/context_mtl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class ContextMTL final : public Context,
5252
// |Context|
5353
~ContextMTL() override;
5454

55+
// |Context|
56+
BackendType GetBackendType() const override;
57+
5558
id<MTLDevice> GetMTLDevice() const;
5659

5760
// |Context|

impeller/renderer/backend/metal/context_mtl.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ new ContextMTL(device, command_queue,
286286

287287
ContextMTL::~ContextMTL() = default;
288288

289+
Context::BackendType ContextMTL::GetBackendType() const {
290+
return Context::BackendType::kMetal;
291+
}
292+
289293
// |Context|
290294
std::string ContextMTL::DescribeGpuModel() const {
291295
return std::string([[device_ name] UTF8String]);

impeller/renderer/backend/vulkan/context_vk.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ ContextVK::~ContextVK() {
120120
CommandPoolVK::ClearAllPools(this);
121121
}
122122

123+
Context::BackendType ContextVK::GetBackendType() const {
124+
return Context::BackendType::kVulkan;
125+
}
126+
123127
void ContextVK::Setup(Settings settings) {
124128
TRACE_EVENT0("impeller", "ContextVK::Setup");
125129

impeller/renderer/backend/vulkan/context_vk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class ContextVK final : public Context,
5555
// |Context|
5656
~ContextVK() override;
5757

58+
// |Context|
59+
BackendType GetBackendType() const override;
60+
5861
// |Context|
5962
std::string DescribeGpuModel() const override;
6063

impeller/renderer/context.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,32 @@ class Allocator;
4343
/// `//impeller/renderer/backend`.
4444
class Context {
4545
public:
46+
enum class BackendType {
47+
kMetal,
48+
kOpenGLES,
49+
kVulkan,
50+
};
51+
4652
//----------------------------------------------------------------------------
4753
/// @brief Destroys an Impeller context.
4854
///
4955
virtual ~Context();
5056

57+
//----------------------------------------------------------------------------
58+
/// @brief Get the graphics backend of an Impeller context.
59+
///
60+
/// This is useful for cases where a renderer needs to track and
61+
/// lookup backend-specific resources, like shaders or uniform
62+
/// layout information.
63+
///
64+
/// It's not recommended to use this as a substitute for
65+
/// per-backend capability checking. Instead, check for specific
66+
/// capabilities via `GetCapabilities()`.
67+
///
68+
/// @return The graphics backend of the `Context`.
69+
///
70+
virtual BackendType GetBackendType() const = 0;
71+
5172
// TODO(129920): Refactor and move to capabilities.
5273
virtual std::string DescribeGpuModel() const = 0;
5374

0 commit comments

Comments
 (0)