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

Commit a933ef8

Browse files
jonahwilliamsharryterkelsen
authored andcommitted
[Impeller] Refactor CapabilitiesGLES into a Capabilties. (#46621)
From #46585 For Framebuffer fetch and other changes we should refactor the CapabilitiesGLES into a regular capabilities.
1 parent d5cf300 commit a933ef8

File tree

8 files changed

+169
-30
lines changed

8 files changed

+169
-30
lines changed

impeller/renderer/backend/gles/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ config("gles_config") {
1414
impeller_component("gles_unittests") {
1515
testonly = true
1616
sources = [
17+
"test/capabilities_unittests.cc",
1718
"test/mock_gles.cc",
1819
"test/mock_gles.h",
1920
"test/mock_gles_unittests.cc",

impeller/renderer/backend/gles/capabilities_gles.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,60 @@ size_t CapabilitiesGLES::GetMaxTextureUnits(ShaderStage stage) const {
103103
FML_UNREACHABLE();
104104
}
105105

106+
bool CapabilitiesGLES::SupportsOffscreenMSAA() const {
107+
return false;
108+
}
109+
110+
bool CapabilitiesGLES::SupportsSSBO() const {
111+
return false;
112+
}
113+
114+
bool CapabilitiesGLES::SupportsBufferToTextureBlits() const {
115+
return false;
116+
}
117+
118+
bool CapabilitiesGLES::SupportsTextureToTextureBlits() const {
119+
return false;
120+
}
121+
122+
bool CapabilitiesGLES::SupportsFramebufferFetch() const {
123+
return false;
124+
}
125+
126+
bool CapabilitiesGLES::SupportsCompute() const {
127+
return false;
128+
}
129+
130+
bool CapabilitiesGLES::SupportsComputeSubgroups() const {
131+
return false;
132+
}
133+
134+
bool CapabilitiesGLES::SupportsReadFromOnscreenTexture() const {
135+
return false;
136+
}
137+
138+
bool CapabilitiesGLES::SupportsReadFromResolve() const {
139+
return false;
140+
}
141+
142+
bool CapabilitiesGLES::SupportsDecalSamplerAddressMode() const {
143+
return false;
144+
}
145+
146+
bool CapabilitiesGLES::SupportsDeviceTransientTextures() const {
147+
return false;
148+
}
149+
150+
PixelFormat CapabilitiesGLES::GetDefaultColorFormat() const {
151+
return PixelFormat::kR8G8B8A8UNormInt;
152+
}
153+
154+
PixelFormat CapabilitiesGLES::GetDefaultStencilFormat() const {
155+
return PixelFormat::kS8UInt;
156+
}
157+
158+
PixelFormat CapabilitiesGLES::GetDefaultDepthStencilFormat() const {
159+
return PixelFormat::kD24UnormS8Uint;
160+
}
161+
106162
} // namespace impeller

impeller/renderer/backend/gles/capabilities_gles.h

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66

77
#include <cstddef>
88

9-
#include "flutter/fml/macros.h"
9+
#include "impeller/base/backend_cast.h"
1010
#include "impeller/core/shader_types.h"
1111
#include "impeller/geometry/size.h"
12+
#include "impeller/renderer/capabilities.h"
1213

1314
namespace impeller {
1415

1516
class ProcTableGLES;
1617

17-
struct CapabilitiesGLES {
18-
CapabilitiesGLES(const ProcTableGLES& gl);
18+
//------------------------------------------------------------------------------
19+
/// @brief The Vulkan layers and extensions wrangler.
20+
///
21+
class CapabilitiesGLES final
22+
: public Capabilities,
23+
public BackendCast<CapabilitiesGLES, Capabilities> {
24+
public:
25+
explicit CapabilitiesGLES(const ProcTableGLES& gl);
26+
27+
CapabilitiesGLES(const CapabilitiesGLES&) = delete;
28+
29+
CapabilitiesGLES(CapabilitiesGLES&&) = delete;
30+
31+
CapabilitiesGLES& operator=(const CapabilitiesGLES&) = delete;
32+
33+
CapabilitiesGLES& operator=(CapabilitiesGLES&&) = delete;
1934

2035
// Must be at least 8.
2136
size_t max_combined_texture_image_units = 8;
@@ -57,6 +72,48 @@ struct CapabilitiesGLES {
5772
size_t num_shader_binary_formats = 0;
5873

5974
size_t GetMaxTextureUnits(ShaderStage stage) const;
75+
76+
// |Capabilities|
77+
bool SupportsOffscreenMSAA() const override;
78+
79+
// |Capabilities|
80+
bool SupportsSSBO() const override;
81+
82+
// |Capabilities|
83+
bool SupportsBufferToTextureBlits() const override;
84+
85+
// |Capabilities|
86+
bool SupportsTextureToTextureBlits() const override;
87+
88+
// |Capabilities|
89+
bool SupportsFramebufferFetch() const override;
90+
91+
// |Capabilities|
92+
bool SupportsCompute() const override;
93+
94+
// |Capabilities|
95+
bool SupportsComputeSubgroups() const override;
96+
97+
// |Capabilities|
98+
bool SupportsReadFromOnscreenTexture() const override;
99+
100+
// |Capabilities|
101+
bool SupportsReadFromResolve() const override;
102+
103+
// |Capabilities|
104+
bool SupportsDecalSamplerAddressMode() const override;
105+
106+
// |Capabilities|
107+
bool SupportsDeviceTransientTextures() const override;
108+
109+
// |Capabilities|
110+
PixelFormat GetDefaultColorFormat() const override;
111+
112+
// |Capabilities|
113+
PixelFormat GetDefaultStencilFormat() const override;
114+
115+
// |Capabilities|
116+
PixelFormat GetDefaultDepthStencilFormat() const override;
60117
};
61118

62119
} // namespace impeller

impeller/renderer/backend/gles/context_gles.cc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "impeller/base/config.h"
88
#include "impeller/base/validation.h"
9+
#include "impeller/renderer/backend/gles/command_buffer_gles.h"
910

1011
namespace impeller {
1112

@@ -58,27 +59,7 @@ ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
5859
std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES());
5960
}
6061

61-
// Create the device capabilities.
62-
{
63-
device_capabilities_ =
64-
CapabilitiesBuilder()
65-
.SetSupportsOffscreenMSAA(false)
66-
.SetSupportsSSBO(false)
67-
.SetSupportsBufferToTextureBlits(false)
68-
.SetSupportsTextureToTextureBlits(false)
69-
.SetSupportsFramebufferFetch(false)
70-
.SetDefaultColorFormat(PixelFormat::kR8G8B8A8UNormInt)
71-
.SetDefaultStencilFormat(PixelFormat::kS8UInt)
72-
.SetDefaultDepthStencilFormat(PixelFormat::kD24UnormS8Uint)
73-
.SetSupportsCompute(false)
74-
.SetSupportsComputeSubgroups(false)
75-
.SetSupportsReadFromResolve(false)
76-
.SetSupportsReadFromOnscreenTexture(false)
77-
.SetSupportsDecalSamplerAddressMode(false)
78-
.SetSupportsDeviceTransientTextures(false)
79-
.Build();
80-
}
81-
62+
device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
8263
is_valid_ = true;
8364
}
8465

impeller/renderer/backend/gles/context_gles.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "flutter/fml/macros.h"
88
#include "impeller/base/backend_cast.h"
99
#include "impeller/renderer/backend/gles/allocator_gles.h"
10-
#include "impeller/renderer/backend/gles/command_buffer_gles.h"
10+
#include "impeller/renderer/backend/gles/capabilities_gles.h"
1111
#include "impeller/renderer/backend/gles/pipeline_library_gles.h"
1212
#include "impeller/renderer/backend/gles/reactor_gles.h"
1313
#include "impeller/renderer/backend/gles/sampler_library_gles.h"
@@ -44,6 +44,9 @@ class ContextGLES final : public Context,
4444
std::shared_ptr<PipelineLibraryGLES> pipeline_library_;
4545
std::shared_ptr<SamplerLibraryGLES> sampler_library_;
4646
std::shared_ptr<AllocatorGLES> resource_allocator_;
47+
// Note: This is stored separately from the ProcTableGLES CapabilitiesGLES
48+
// in order to satisfy the Context::GetCapabilities signature which returns
49+
// a reference.
4750
std::shared_ptr<const Capabilities> device_capabilities_;
4851
bool is_valid_ = false;
4952

impeller/renderer/backend/gles/proc_table_gles.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "impeller/base/allocation.h"
1010
#include "impeller/base/comparable.h"
1111
#include "impeller/base/validation.h"
12+
#include "impeller/renderer/backend/gles/capabilities_gles.h"
13+
#include "impeller/renderer/capabilities.h"
1214

1315
namespace impeller {
1416

@@ -125,7 +127,7 @@ ProcTableGLES::ProcTableGLES(Resolver resolver) {
125127
DiscardFramebufferEXT.Reset();
126128
}
127129

128-
capabilities_ = std::make_unique<CapabilitiesGLES>(*this);
130+
capabilities_ = std::make_shared<CapabilitiesGLES>(*this);
129131

130132
is_valid_ = true;
131133
}
@@ -148,8 +150,9 @@ const DescriptionGLES* ProcTableGLES::GetDescription() const {
148150
return description_.get();
149151
}
150152

151-
const CapabilitiesGLES* ProcTableGLES::GetCapabilities() const {
152-
return capabilities_.get();
153+
const std::shared_ptr<const CapabilitiesGLES>& ProcTableGLES::GetCapabilities()
154+
const {
155+
return capabilities_;
153156
}
154157

155158
static const char* FramebufferStatusToString(GLenum status) {

impeller/renderer/backend/gles/proc_table_gles.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class ProcTableGLES {
229229

230230
const DescriptionGLES* GetDescription() const;
231231

232-
const CapabilitiesGLES* GetCapabilities() const;
232+
const std::shared_ptr<const CapabilitiesGLES>& GetCapabilities() const;
233233

234234
std::string DescribeCurrentFramebuffer() const;
235235

@@ -248,7 +248,7 @@ class ProcTableGLES {
248248
private:
249249
bool is_valid_ = false;
250250
std::unique_ptr<DescriptionGLES> description_;
251-
std::unique_ptr<CapabilitiesGLES> capabilities_;
251+
std::shared_ptr<const CapabilitiesGLES> capabilities_;
252252
GLint debug_label_max_length_ = 0;
253253

254254
FML_DISALLOW_COPY_AND_ASSIGN(ProcTableGLES);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/testing/testing.h" // IWYU pragma: keep
6+
#include "gtest/gtest.h"
7+
#include "impeller/renderer/backend/gles/proc_table_gles.h"
8+
#include "impeller/renderer/backend/gles/test/mock_gles.h"
9+
10+
namespace impeller {
11+
namespace testing {
12+
13+
TEST(CapabilitiesGLES, CanInitializeWithDefaults) {
14+
auto mock_gles = MockGLES::Init();
15+
16+
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
17+
18+
EXPECT_FALSE(capabilities->SupportsOffscreenMSAA());
19+
EXPECT_FALSE(capabilities->SupportsSSBO());
20+
EXPECT_FALSE(capabilities->SupportsBufferToTextureBlits());
21+
EXPECT_FALSE(capabilities->SupportsTextureToTextureBlits());
22+
EXPECT_FALSE(capabilities->SupportsFramebufferFetch());
23+
EXPECT_FALSE(capabilities->SupportsCompute());
24+
EXPECT_FALSE(capabilities->SupportsComputeSubgroups());
25+
EXPECT_FALSE(capabilities->SupportsReadFromOnscreenTexture());
26+
EXPECT_FALSE(capabilities->SupportsReadFromResolve());
27+
EXPECT_FALSE(capabilities->SupportsDecalSamplerAddressMode());
28+
EXPECT_FALSE(capabilities->SupportsDeviceTransientTextures());
29+
30+
EXPECT_EQ(capabilities->GetDefaultColorFormat(),
31+
PixelFormat::kR8G8B8A8UNormInt);
32+
EXPECT_EQ(capabilities->GetDefaultStencilFormat(), PixelFormat::kS8UInt);
33+
EXPECT_EQ(capabilities->GetDefaultDepthStencilFormat(),
34+
PixelFormat::kD24UnormS8Uint);
35+
}
36+
37+
} // namespace testing
38+
} // namespace impeller

0 commit comments

Comments
 (0)