Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
3 changes: 0 additions & 3 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,6 @@ FILE: ../../../flutter/impeller/renderer/backend/gles/gl_description.h
FILE: ../../../flutter/impeller/renderer/backend/gles/gles.h
FILE: ../../../flutter/impeller/renderer/backend/gles/gles_handle.cc
FILE: ../../../flutter/impeller/renderer/backend/gles/gles_handle.h
FILE: ../../../flutter/impeller/renderer/backend/gles/gles_test.cc
FILE: ../../../flutter/impeller/renderer/backend/gles/gles_test.h
FILE: ../../../flutter/impeller/renderer/backend/gles/gles_unittests.cc
FILE: ../../../flutter/impeller/renderer/backend/gles/pipeline_gles.cc
FILE: ../../../flutter/impeller/renderer/backend/gles/pipeline_gles.h
FILE: ../../../flutter/impeller/renderer/backend/gles/pipeline_library_gles.cc
Expand Down
1 change: 0 additions & 1 deletion impeller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ executable("impeller_unittests") {
"image:image_unittests",
"playground",
"renderer:renderer_unittests",
"renderer/backend:backend_unittests",
"typographer:typographer_unittests",
]
}
Expand Down
8 changes: 8 additions & 0 deletions impeller/base/allocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ std::shared_ptr<fml::Mapping> CreateMappingWithCopy(const uint8_t* contents,

std::memmove(allocation->GetBuffer(), contents, length);

return CreateMappingFromAllocation(std::move(allocation));
}

std::shared_ptr<fml::Mapping> CreateMappingFromAllocation(
std::shared_ptr<Allocation> allocation) {
if (!allocation) {
return nullptr;
}
return std::make_shared<fml::NonOwnedMapping>(
reinterpret_cast<const uint8_t*>(allocation->GetBuffer()), //
allocation->GetLength(), //
Expand Down
3 changes: 3 additions & 0 deletions impeller/base/allocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ class Allocation {
std::shared_ptr<fml::Mapping> CreateMappingWithCopy(const uint8_t* contents,
size_t length);

std::shared_ptr<fml::Mapping> CreateMappingFromAllocation(
std::shared_ptr<Allocation> allocation);

} // namespace impeller
5 changes: 4 additions & 1 deletion impeller/compiler/code_gen_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ ShaderMetadata Shader::kMetadata{{camel_case(buffer.name)}} = {
{% endfor %}

{% for sampled_image in sampled_images %}
ShaderMetadata Shader::kMetadata{{camel_case(sampled_image.name)}};
ShaderMetadata Shader::kMetadata{{camel_case(sampled_image.name)}} = {
"{{sampled_image.name}}", // name
std::vector<ShaderStructMemberMetadata> {}, // 0 members
};
{% endfor %}

} // namespace impeller
Expand Down
23 changes: 13 additions & 10 deletions impeller/compiler/compiler_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "impeller/compiler/compiler_backend.h"

#include "impeller/base/comparable.h"

namespace impeller {
namespace compiler {

Expand All @@ -27,18 +29,19 @@ const spirv_cross::Compiler* CompilerBackend::operator->() const {
uint32_t CompilerBackend::GetExtendedMSLResourceBinding(
ExtendedResourceIndex index,
spirv_cross::ID id) const {
const auto kOOBIndex = static_cast<uint32_t>(-1);
auto compiler = GetMSLCompiler();
if (!compiler) {
return kOOBIndex;
if (auto compiler = GetMSLCompiler()) {
switch (index) {
case ExtendedResourceIndex::kPrimary:
return compiler->get_automatic_msl_resource_binding(id);
case ExtendedResourceIndex::kSecondary:
return compiler->get_automatic_msl_resource_binding_secondary(id);
break;
}
}
switch (index) {
case ExtendedResourceIndex::kPrimary:
return compiler->get_automatic_msl_resource_binding(id);
case ExtendedResourceIndex::kSecondary:
return compiler->get_automatic_msl_resource_binding_secondary(id);
break;
if (auto compiler = GetGLSLCompiler()) {
return compiler->get_decoration(id, spv::Decoration::DecorationLocation);
}
const auto kOOBIndex = static_cast<uint32_t>(-1);
return kOOBIndex;
}

Expand Down
4 changes: 3 additions & 1 deletion impeller/image/backends/skia/compressed_image_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ DecompressedImage CompressedImageSkia::Decode() const {
return {};
}

auto info = SkImageInfo::MakeN32Premul(generator->getInfo().dimensions());
const auto dims = generator->getInfo().dimensions();
auto info = SkImageInfo::Make(dims.width(), dims.height(),
kRGBA_8888_SkColorType, kPremul_SkAlphaType);

auto bitmap = std::make_shared<SkBitmap>();
if (!bitmap->tryAllocPixels(info)) {
Expand Down
9 changes: 0 additions & 9 deletions impeller/renderer/backend/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,3 @@ group("backend") {
public_deps += [ "gles" ]
}
}

group("backend_unittests") {
testonly = true

deps = []
if (impeller_enable_opengles) {
deps += [ "gles:gles_unittests" ]
}
}
16 changes: 0 additions & 16 deletions impeller/renderer/backend/gles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,3 @@ impeller_component("gles") {
"//flutter/fml",
]
}

impeller_component("gles_unittests") {
testonly = true

sources = [
"gles_test.cc",
"gles_test.h",
"gles_unittests.cc",
]

deps = [
":gles",
"//flutter/testing",
"//third_party/swiftshader_flutter:swiftshader_gl",
]
}
75 changes: 75 additions & 0 deletions impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/device_buffer_gles.h"
#include "impeller/renderer/backend/gles/formats_gles.h"
#include "impeller/renderer/backend/gles/sampler_gles.h"
#include "impeller/renderer/backend/gles/texture_gles.h"

namespace impeller {

Expand Down Expand Up @@ -66,6 +68,11 @@ static std::string CreateUnifiormMemberKey(const std::string& struct_name,
return NormalizeUniformKey(stream.str());
}

static std::string CreateUnifiormMemberKey(
const std::string& non_struct_member) {
return NormalizeUniformKey(non_struct_member);
}

bool BufferBindingsGLES::ReadUniformsBindings(const ProcTableGLES& gl,
GLuint program) {
if (!gl.IsProgram(program)) {
Expand Down Expand Up @@ -141,6 +148,15 @@ bool BufferBindingsGLES::BindUniformData(
return false;
}
}

if (!BindTextures(gl, vertex_bindings)) {
return false;
}

if (!BindTextures(gl, fragment_bindings)) {
return false;
}

return true;
}

Expand Down Expand Up @@ -251,4 +267,63 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
return true;
}

bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
const Bindings& bindings) const {
size_t active_index = 0;
for (const auto& texture : bindings.textures) {
const auto& texture_gles = TextureGLES::Cast(*texture.second.resource);
if (texture.second.isa == nullptr) {
VALIDATION_LOG << "No metadata found for texture binding.";
return false;
}

const auto uniform_key = CreateUnifiormMemberKey(texture.second.isa->name);
auto uniform = uniform_locations_.find(uniform_key);
if (uniform == uniform_locations_.end()) {
VALIDATION_LOG << "Could not find uniform for key: " << uniform_key;
return false;
}

//--------------------------------------------------------------------------
/// Set the active texture unit.
///
const auto texture_index = GL_TEXTURE0 + active_index;
if (texture_index >= GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS) {
VALIDATION_LOG << "Active texture index was out of bounds.";
return false;
}
gl.ActiveTexture(texture_index);

//--------------------------------------------------------------------------
/// Bind the texture.
///
if (!texture_gles.Bind()) {
return false;
}

//--------------------------------------------------------------------------
/// If there is a sampler for the texture at the same index, configure the
/// bound texture using that sampler.
///
auto sampler = bindings.samplers.find(texture.first);
if (sampler != bindings.samplers.end()) {
const auto& sampler_gles = SamplerGLES::Cast(*sampler->second.resource);
if (!sampler_gles.ConfigureBoundTexture(gl)) {
return false;
}
}

//--------------------------------------------------------------------------
/// Set the texture uniform location.
///
gl.Uniform1i(uniform->second, active_index);

//--------------------------------------------------------------------------
/// Bump up the active index at binding.
///
active_index++;
}
return true;
}

} // namespace impeller
2 changes: 2 additions & 0 deletions impeller/renderer/backend/gles/buffer_bindings_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BufferBindingsGLES {
Allocator& transients_allocator,
const BufferResource& buffer) const;

bool BindTextures(const ProcTableGLES& gl, const Bindings& bindings) const;

FML_DISALLOW_COPY_AND_ASSIGN(BufferBindingsGLES);
};

Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/command_buffer_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool CommandBufferGLES::SubmitCommands(CompletionCallback callback) {
}

// |CommandBuffer|
std::shared_ptr<RenderPass> CommandBufferGLES::CreateRenderPass(
std::shared_ptr<RenderPass> CommandBufferGLES::OnCreateRenderPass(
RenderTarget target) const {
if (!IsValid()) {
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/command_buffer_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CommandBufferGLES final : public CommandBuffer {
bool SubmitCommands(CompletionCallback callback) override;

// |CommandBuffer|
std::shared_ptr<RenderPass> CreateRenderPass(
std::shared_ptr<RenderPass> OnCreateRenderPass(
RenderTarget target) const override;

FML_DISALLOW_COPY_AND_ASSIGN(CommandBufferGLES);
Expand Down
9 changes: 6 additions & 3 deletions impeller/renderer/backend/gles/device_buffer_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ bool DeviceBufferGLES::BindAndUploadDataIfNecessary(BindingType type) const {

// |DeviceBuffer|
bool DeviceBufferGLES::SetLabel(const std::string& label) {
// Cannot support.
if (!handle_.IsDead()) {
reactor_->SetDebugLabel(handle_, std::move(label));
}
return true;
}

// |DeviceBuffer|
bool DeviceBufferGLES::SetLabel(const std::string& label, Range range) {
// Cannot support.
return true;
// Cannot support debug label on the range. Set the label for the entire
// range.
return SetLabel(label);
}

std::shared_ptr<fml::Mapping> DeviceBufferGLES::GetBufferData() const {
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/gles/gl_description.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,12 @@ std::string GLDescription::GetString() const {
return stream.str();
}

bool GLDescription::HasExtension(const std::string& ext) const {
return extensions_.find(ext) != extensions_.end();
}

bool GLDescription::HasDebugExtension() const {
return HasExtension("GL_KHR_debug");
}

} // namespace impeller
4 changes: 4 additions & 0 deletions impeller/renderer/backend/gles/gl_description.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class GLDescription {

std::string GetString() const;

bool HasExtension(const std::string& ext) const;

bool HasDebugExtension() const;

private:
std::string vendor_;
std::string renderer_;
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/backend/gles/gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
#pragma once

#include "GLES2/gl2.h"
#define GL_GLEXT_PROTOTYPES
#include "GLES2/gl2ext.h"
22 changes: 0 additions & 22 deletions impeller/renderer/backend/gles/gles_test.cc

This file was deleted.

25 changes: 0 additions & 25 deletions impeller/renderer/backend/gles/gles_test.h

This file was deleted.

18 changes: 0 additions & 18 deletions impeller/renderer/backend/gles/gles_unittests.cc

This file was deleted.

6 changes: 5 additions & 1 deletion impeller/renderer/backend/gles/pipeline_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ PipelineGLES::PipelineGLES(ReactorGLES::Ref reactor,
reactor_(std::move(reactor)),
handle_(reactor_ ? reactor_->CreateHandle(HandleType::kProgram)
: GLESHandle::DeadHandle()),
is_valid_(!handle_.IsDead()) {}
is_valid_(!handle_.IsDead()) {
if (is_valid_) {
reactor_->SetDebugLabel(handle_, GetDescriptor().GetLabel());
}
}

// |Pipeline|
PipelineGLES::~PipelineGLES() {
Expand Down
Loading