Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
4 changes: 0 additions & 4 deletions impeller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ config("impeller_public_config") {

defines = []

if (impeller_debug) {
defines += [ "IMPELLER_DEBUG=1" ]
}

if (impeller_supports_rendering) {
defines += [ "IMPELLER_SUPPORTS_RENDERING=1" ]
}
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/gles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impeller_component("gles") {
"reactor_gles.h",
"render_pass_gles.cc",
"render_pass_gles.h",
"render_pass_gles3.cc",
"render_pass_gles3.h",
"render_pass_utils.cc",
"render_pass_utils.h",
"sampler_gles.cc",
"sampler_gles.h",
"sampler_library_gles.cc",
Expand Down
9 changes: 5 additions & 4 deletions impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ bool BufferBindingsGLES::ReadUniformsBindingsV3(const ProcTableGLES& gl,
gl.GetActiveUniformBlockName(program, i, name_length, &length, name.data());

GLuint block_index = gl.GetUniformBlockIndex(program, name.data());
gl.UniformBlockBinding(program_handle_, block_index, i);

ubo_locations_[std::string{name.data(), static_cast<size_t>(length)}] =
std::make_pair(block_index, i);
}
Expand Down Expand Up @@ -219,8 +221,8 @@ bool BufferBindingsGLES::BindVertexAttributes(const ProcTableGLES& gl,

bool BufferBindingsGLES::BindUniformData(
const ProcTableGLES& gl,
const std::vector<TextureAndSampler>& bound_textures,
const std::vector<BufferResource>& bound_buffers,
const TextureAndSampler bound_textures[],
const BufferResource bound_buffers[],
Range texture_range,
Range buffer_range) {
for (auto i = 0u; i < buffer_range.length; i++) {
Expand Down Expand Up @@ -336,7 +338,6 @@ bool BufferBindingsGLES::BindUniformBufferV3(
return BindUniformBufferV2(gl, buffer, metadata, device_buffer_gles);
}
const auto& [block_index, binding_point] = it->second;
gl.UniformBlockBinding(program_handle_, block_index, binding_point);

if (!device_buffer_gles.BindAndUploadDataIfNecessary(
DeviceBufferGLES::BindingType::kUniformBuffer)) {
Expand Down Expand Up @@ -444,7 +445,7 @@ bool BufferBindingsGLES::BindUniformBufferV2(

std::optional<size_t> BufferBindingsGLES::BindTextures(
const ProcTableGLES& gl,
const std::vector<TextureAndSampler>& bound_textures,
const TextureAndSampler bound_textures[],
Range texture_range,
ShaderStage stage,
size_t unit_start_index) {
Expand Down
15 changes: 7 additions & 8 deletions impeller/renderer/backend/gles/buffer_bindings_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class BufferBindingsGLES {
size_t vertex_offset);

bool BindUniformData(const ProcTableGLES& gl,
const std::vector<TextureAndSampler>& bound_textures,
const std::vector<BufferResource>& bound_buffers,
const TextureAndSampler bound_textures[],
const BufferResource bound_buffers[],
Range texture_range,
Range buffer_range);

Expand Down Expand Up @@ -95,12 +95,11 @@ class BufferBindingsGLES {
const ShaderMetadata* metadata,
const DeviceBufferGLES& device_buffer_gles);

std::optional<size_t> BindTextures(
const ProcTableGLES& gl,
const std::vector<TextureAndSampler>& bound_textures,
Range texture_range,
ShaderStage stage,
size_t unit_start_index = 0);
std::optional<size_t> BindTextures(const ProcTableGLES& gl,
const TextureAndSampler bound_textures[],
Range texture_range,
ShaderStage stage,
size_t unit_start_index = 0);

BufferBindingsGLES(const BufferBindingsGLES&) = delete;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ TEST(BufferBindingsGLESTest, BindUniformData) {
BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));

EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
bound_buffers, Range{0, 0},
Range{0, 1}));
EXPECT_TRUE(
bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures.data(),
bound_buffers.data(), Range{0, 0}, Range{0, 1}));
}

} // namespace testing
Expand Down
11 changes: 11 additions & 0 deletions impeller/renderer/backend/gles/command_buffer_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "impeller/base/config.h"
#include "impeller/renderer/backend/gles/blit_pass_gles.h"
#include "impeller/renderer/backend/gles/render_pass_gles.h"
#include "impeller/renderer/backend/gles/render_pass_gles3.h"

namespace impeller {

Expand Down Expand Up @@ -58,6 +59,16 @@ std::shared_ptr<RenderPass> CommandBufferGLES::OnCreateRenderPass(
if (!context) {
return nullptr;
}
if (reactor_->GetProcTable().GetDescription()->GetGlVersion().IsAtLeast(
Version{3, 0, 0}) &&
reactor_->CanReactOnCurrentThread()) {
auto pass = std::shared_ptr<RenderPassGLES3>(
new RenderPassGLES3(context, target, reactor_));
if (!pass->IsValid()) {
return nullptr;
}
return pass;
}
auto pass = std::shared_ptr<RenderPassGLES>(
new RenderPassGLES(context, target, reactor_));
if (!pass->IsValid()) {
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/gles/context_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ContextGLES::ContextGLES(
gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
enable_gpu_tracing);
command_queue_ = std::make_shared<CommandQueue>();
global_state_ = std::make_shared<GlobalStateGLES>();
is_valid_ = true;
}

Expand Down
10 changes: 10 additions & 0 deletions impeller/renderer/backend/gles/context_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_

#include "impeller/base/backend_cast.h"
#include "impeller/core/formats.h"
#include "impeller/core/runtime_types.h"
#include "impeller/renderer/backend/gles/allocator_gles.h"
#include "impeller/renderer/backend/gles/capabilities_gles.h"
Expand All @@ -20,6 +21,12 @@

namespace impeller {

struct GlobalStateGLES {
GLuint fbo_id = GL_NONE;
std::optional<Viewport> viewport = std::nullopt;
std::optional<ISize> target_size = std::nullopt;
};

class ContextGLES final : public Context,
public BackendCast<ContextGLES, Context>,
public std::enable_shared_from_this<ContextGLES> {
Expand All @@ -44,13 +51,16 @@ class ContextGLES final : public Context,

std::shared_ptr<GPUTracerGLES> GetGPUTracer() const { return gpu_tracer_; }

GlobalStateGLES* GetGlobalState() const { return global_state_.get(); }

private:
std::shared_ptr<ReactorGLES> reactor_;
std::shared_ptr<ShaderLibraryGLES> shader_library_;
std::shared_ptr<PipelineLibraryGLES> pipeline_library_;
std::shared_ptr<SamplerLibraryGLES> sampler_library_;
std::shared_ptr<AllocatorGLES> resource_allocator_;
std::shared_ptr<CommandQueue> command_queue_;
std::shared_ptr<GlobalStateGLES> global_state_;
std::shared_ptr<GPUTracerGLES> gpu_tracer_;

// Note: This is stored separately from the ProcTableGLES CapabilitiesGLES
Expand Down
34 changes: 26 additions & 8 deletions impeller/renderer/backend/gles/device_buffer_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ uint8_t* DeviceBufferGLES::OnGetContents() const {
if (!reactor_) {
return nullptr;
}
if (initialized_) {
return reinterpret_cast<uint8_t*>(data_);
}
return backing_store_->GetBuffer();
}

Expand All @@ -47,8 +50,8 @@ bool DeviceBufferGLES::OnCopyHostBuffer(const uint8_t* source,
return false;
}

std::memmove(backing_store_->GetBuffer() + offset,
source + source_range.offset, source_range.length);
std::memmove(OnGetContents() + offset, source + source_range.offset,
source_range.length);
Flush(Range{offset, source_range.length});

return true;
Expand All @@ -63,6 +66,9 @@ std::optional<GLuint> DeviceBufferGLES::GetHandle() const {
}

void DeviceBufferGLES::Flush(std::optional<Range> range) const {
if (initialized_) {
return;
}
if (!range.has_value()) {
dirty_range_ = Range{
0, static_cast<size_t>(backing_store_->GetLength().GetByteSize())};
Expand Down Expand Up @@ -111,15 +117,24 @@ bool DeviceBufferGLES::BindAndUploadDataIfNecessary(BindingType type) const {

gl.BindBuffer(target_type, buffer.value());
if (!initialized_) {
gl.BufferData(target_type, backing_store_->GetLength().GetByteSize(),
nullptr, GL_DYNAMIC_DRAW);
gl.BufferStorageEXT(
target_type, backing_store_->GetLength().GetByteSize(), nullptr,
GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT_EXT | GL_MAP_COHERENT_BIT_EXT);
data_ = gl.MapBufferRange(target_type, 0,
backing_store_->GetLength().GetByteSize(),
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
initialized_ = true;
}

if (dirty_range_.has_value()) {
auto range = dirty_range_.value();
gl.BufferSubData(target_type, range.offset, range.length,
backing_store_->GetBuffer() + range.offset);
Range range = dirty_range_.value();
if (gl.MapBufferRange.IsAvailable()) {
::memcpy(reinterpret_cast<uint8_t*>(data_) + range.offset,
backing_store_->GetBuffer() + range.offset, range.length);
} else {
gl.BufferSubData(target_type, range.offset, range.length,
backing_store_->GetBuffer() + range.offset);
}
dirty_range_ = std::nullopt;
}

Expand All @@ -145,14 +160,17 @@ bool DeviceBufferGLES::SetLabel(std::string_view label, Range range) {
}

const uint8_t* DeviceBufferGLES::GetBufferData() const {
if (initialized_) {
return reinterpret_cast<uint8_t*>(data_);
}
return backing_store_->GetBuffer();
}

void DeviceBufferGLES::UpdateBufferData(
const std::function<void(uint8_t* data, size_t length)>&
update_buffer_data) {
if (update_buffer_data) {
update_buffer_data(backing_store_->GetBuffer(),
update_buffer_data(OnGetContents(),
backing_store_->GetLength().GetByteSize());
Flush(Range{
0, static_cast<size_t>(backing_store_->GetLength().GetByteSize())});
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/gles/device_buffer_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DeviceBufferGLES final
mutable std::shared_ptr<Allocation> backing_store_;
mutable std::optional<Range> dirty_range_ = std::nullopt;
mutable bool initialized_ = false;
mutable void* data_ = nullptr;

// |DeviceBuffer|
uint8_t* OnGetContents() const override;
Expand Down
3 changes: 3 additions & 0 deletions impeller/renderer/backend/gles/proc_table_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ void(glDepthRange)(GLdouble n, GLdouble f);
#define FOR_EACH_IMPELLER_GLES3_PROC(PROC) \
PROC(FenceSync); \
PROC(DeleteSync); \
PROC(MapBufferRange); \
PROC(UnmapBuffer); \
PROC(GetActiveUniformBlockiv); \
PROC(GetActiveUniformBlockName); \
PROC(GetUniformBlockIndex); \
Expand All @@ -257,6 +259,7 @@ void(glDepthRange)(GLdouble n, GLdouble f);
PROC(PopDebugGroupKHR); \
PROC(ObjectLabelKHR); \
PROC(RenderbufferStorageMultisampleEXT); \
PROC(BufferStorageEXT); \
PROC(GenQueriesEXT); \
PROC(DeleteQueriesEXT); \
PROC(GetQueryObjectui64vEXT); \
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/gles/reactor_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class ReactorGLES {
///
const ProcTableGLES& GetProcTable() const;

bool CanReactOnCurrentThread() const;

//----------------------------------------------------------------------------
/// @brief Returns the OpenGL handle for a reactor handle if one is
/// available. This is typically only safe to call within a
Expand Down Expand Up @@ -306,8 +308,6 @@ class ReactorGLES {

bool HasPendingOperations() const;

bool CanReactOnCurrentThread() const;

bool ConsolidateHandles();

bool FlushOps();
Expand Down
Loading
Loading