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

[Impeller] Refactor CapabilitiesGLES into a Capabilties. #46621

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions impeller/renderer/backend/gles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ config("gles_config") {
impeller_component("gles_unittests") {
testonly = true
sources = [
"test/capabilities_unittests.cc",
"test/mock_gles.cc",
"test/mock_gles.h",
"test/mock_gles_unittests.cc",
Expand Down
56 changes: 56 additions & 0 deletions impeller/renderer/backend/gles/capabilities_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,60 @@ size_t CapabilitiesGLES::GetMaxTextureUnits(ShaderStage stage) const {
FML_UNREACHABLE();
}

bool CapabilitiesGLES::SupportsOffscreenMSAA() const {
return false;
}

bool CapabilitiesGLES::SupportsSSBO() const {
return false;
}

bool CapabilitiesGLES::SupportsBufferToTextureBlits() const {
return false;
}

bool CapabilitiesGLES::SupportsTextureToTextureBlits() const {
return false;
}

bool CapabilitiesGLES::SupportsFramebufferFetch() const {
return false;
}

bool CapabilitiesGLES::SupportsCompute() const {
return false;
}

bool CapabilitiesGLES::SupportsComputeSubgroups() const {
return false;
}

bool CapabilitiesGLES::SupportsReadFromOnscreenTexture() const {
return false;
}

bool CapabilitiesGLES::SupportsReadFromResolve() const {
return false;
}

bool CapabilitiesGLES::SupportsDecalSamplerAddressMode() const {
return false;
}

bool CapabilitiesGLES::SupportsDeviceTransientTextures() const {
return false;
}

PixelFormat CapabilitiesGLES::GetDefaultColorFormat() const {
return PixelFormat::kR8G8B8A8UNormInt;
}

PixelFormat CapabilitiesGLES::GetDefaultStencilFormat() const {
return PixelFormat::kS8UInt;
}

PixelFormat CapabilitiesGLES::GetDefaultDepthStencilFormat() const {
return PixelFormat::kD24UnormS8Uint;
}

} // namespace impeller
63 changes: 60 additions & 3 deletions impeller/renderer/backend/gles/capabilities_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@

#include <cstddef>

#include "flutter/fml/macros.h"
#include "impeller/base/backend_cast.h"
#include "impeller/core/shader_types.h"
#include "impeller/geometry/size.h"
#include "impeller/renderer/capabilities.h"

namespace impeller {

class ProcTableGLES;

struct CapabilitiesGLES {
CapabilitiesGLES(const ProcTableGLES& gl);
//------------------------------------------------------------------------------
/// @brief The Vulkan layers and extensions wrangler.
///
class CapabilitiesGLES final
: public Capabilities,
public BackendCast<CapabilitiesGLES, Capabilities> {
public:
explicit CapabilitiesGLES(const ProcTableGLES& gl);

CapabilitiesGLES(const CapabilitiesGLES&) = delete;

CapabilitiesGLES(CapabilitiesGLES&&) = delete;

CapabilitiesGLES& operator=(const CapabilitiesGLES&) = delete;

CapabilitiesGLES& operator=(CapabilitiesGLES&&) = delete;

// Must be at least 8.
size_t max_combined_texture_image_units = 8;
Expand Down Expand Up @@ -57,6 +72,48 @@ struct CapabilitiesGLES {
size_t num_shader_binary_formats = 0;

size_t GetMaxTextureUnits(ShaderStage stage) const;

// |Capabilities|
bool SupportsOffscreenMSAA() const override;

// |Capabilities|
bool SupportsSSBO() const override;

// |Capabilities|
bool SupportsBufferToTextureBlits() const override;

// |Capabilities|
bool SupportsTextureToTextureBlits() const override;

// |Capabilities|
bool SupportsFramebufferFetch() const override;

// |Capabilities|
bool SupportsCompute() const override;

// |Capabilities|
bool SupportsComputeSubgroups() const override;

// |Capabilities|
bool SupportsReadFromOnscreenTexture() const override;

// |Capabilities|
bool SupportsReadFromResolve() const override;

// |Capabilities|
bool SupportsDecalSamplerAddressMode() const override;

// |Capabilities|
bool SupportsDeviceTransientTextures() const override;

// |Capabilities|
PixelFormat GetDefaultColorFormat() const override;

// |Capabilities|
PixelFormat GetDefaultStencilFormat() const override;

// |Capabilities|
PixelFormat GetDefaultDepthStencilFormat() const override;
};

} // namespace impeller
23 changes: 2 additions & 21 deletions impeller/renderer/backend/gles/context_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "impeller/base/config.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/command_buffer_gles.h"

namespace impeller {

Expand Down Expand Up @@ -58,27 +59,7 @@ ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
std::shared_ptr<SamplerLibraryGLES>(new SamplerLibraryGLES());
}

// Create the device capabilities.
{
device_capabilities_ =
CapabilitiesBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of CapabilitiesBuilder entirely? All backends should follow the pattern of having a custom capabilities subclass.

.SetSupportsOffscreenMSAA(false)
.SetSupportsSSBO(false)
.SetSupportsBufferToTextureBlits(false)
.SetSupportsTextureToTextureBlits(false)
.SetSupportsFramebufferFetch(false)
.SetDefaultColorFormat(PixelFormat::kR8G8B8A8UNormInt)
.SetDefaultStencilFormat(PixelFormat::kS8UInt)
.SetDefaultDepthStencilFormat(PixelFormat::kD24UnormS8Uint)
.SetSupportsCompute(false)
.SetSupportsComputeSubgroups(false)
.SetSupportsReadFromResolve(false)
.SetSupportsReadFromOnscreenTexture(false)
.SetSupportsDecalSamplerAddressMode(false)
.SetSupportsDeviceTransientTextures(false)
.Build();
}

device_capabilities_ = reactor_->GetProcTable().GetCapabilities();
is_valid_ = true;
}

Expand Down
5 changes: 4 additions & 1 deletion impeller/renderer/backend/gles/context_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "flutter/fml/macros.h"
#include "impeller/base/backend_cast.h"
#include "impeller/renderer/backend/gles/allocator_gles.h"
#include "impeller/renderer/backend/gles/command_buffer_gles.h"
#include "impeller/renderer/backend/gles/capabilities_gles.h"
#include "impeller/renderer/backend/gles/pipeline_library_gles.h"
#include "impeller/renderer/backend/gles/reactor_gles.h"
#include "impeller/renderer/backend/gles/sampler_library_gles.h"
Expand Down Expand Up @@ -44,6 +44,9 @@ class ContextGLES final : public Context,
std::shared_ptr<PipelineLibraryGLES> pipeline_library_;
std::shared_ptr<SamplerLibraryGLES> sampler_library_;
std::shared_ptr<AllocatorGLES> resource_allocator_;
// Note: This is stored separately from the ProcTableGLES CapabilitiesGLES
// in order to satisfy the Context::GetCapabilities signature which returns
// a reference.
std::shared_ptr<const Capabilities> device_capabilities_;
bool is_valid_ = false;

Expand Down
9 changes: 6 additions & 3 deletions impeller/renderer/backend/gles/proc_table_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "impeller/base/allocation.h"
#include "impeller/base/comparable.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/capabilities_gles.h"
#include "impeller/renderer/capabilities.h"

namespace impeller {

Expand Down Expand Up @@ -125,7 +127,7 @@ ProcTableGLES::ProcTableGLES(Resolver resolver) {
DiscardFramebufferEXT.Reset();
}

capabilities_ = std::make_unique<CapabilitiesGLES>(*this);
capabilities_ = std::make_shared<CapabilitiesGLES>(*this);

is_valid_ = true;
}
Expand All @@ -148,8 +150,9 @@ const DescriptionGLES* ProcTableGLES::GetDescription() const {
return description_.get();
}

const CapabilitiesGLES* ProcTableGLES::GetCapabilities() const {
return capabilities_.get();
const std::shared_ptr<const CapabilitiesGLES>& ProcTableGLES::GetCapabilities()
const {
return capabilities_;
}

static const char* FramebufferStatusToString(GLenum status) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/gles/proc_table_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class ProcTableGLES {

const DescriptionGLES* GetDescription() const;

const CapabilitiesGLES* GetCapabilities() const;
const std::shared_ptr<const CapabilitiesGLES>& GetCapabilities() const;

std::string DescribeCurrentFramebuffer() const;

Expand All @@ -248,7 +248,7 @@ class ProcTableGLES {
private:
bool is_valid_ = false;
std::unique_ptr<DescriptionGLES> description_;
std::unique_ptr<CapabilitiesGLES> capabilities_;
std::shared_ptr<const CapabilitiesGLES> capabilities_;
GLint debug_label_max_length_ = 0;

FML_DISALLOW_COPY_AND_ASSIGN(ProcTableGLES);
Expand Down
38 changes: 38 additions & 0 deletions impeller/renderer/backend/gles/test/capabilities_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

#include "flutter/testing/testing.h" // IWYU pragma: keep
#include "gtest/gtest.h"
#include "impeller/renderer/backend/gles/proc_table_gles.h"
#include "impeller/renderer/backend/gles/test/mock_gles.h"

namespace impeller {
namespace testing {

TEST(CapabilitiesGLES, CanInitializeWithDefaults) {
auto mock_gles = MockGLES::Init();

auto capabilities = mock_gles->GetProcTable().GetCapabilities();

EXPECT_FALSE(capabilities->SupportsOffscreenMSAA());
EXPECT_FALSE(capabilities->SupportsSSBO());
EXPECT_FALSE(capabilities->SupportsBufferToTextureBlits());
EXPECT_FALSE(capabilities->SupportsTextureToTextureBlits());
EXPECT_FALSE(capabilities->SupportsFramebufferFetch());
EXPECT_FALSE(capabilities->SupportsCompute());
EXPECT_FALSE(capabilities->SupportsComputeSubgroups());
EXPECT_FALSE(capabilities->SupportsReadFromOnscreenTexture());
EXPECT_FALSE(capabilities->SupportsReadFromResolve());
EXPECT_FALSE(capabilities->SupportsDecalSamplerAddressMode());
EXPECT_FALSE(capabilities->SupportsDeviceTransientTextures());

EXPECT_EQ(capabilities->GetDefaultColorFormat(),
PixelFormat::kR8G8B8A8UNormInt);
EXPECT_EQ(capabilities->GetDefaultStencilFormat(), PixelFormat::kS8UInt);
EXPECT_EQ(capabilities->GetDefaultDepthStencilFormat(),
PixelFormat::kD24UnormS8Uint);
}

} // namespace testing
} // namespace impeller