forked from firka/flutter
[impeller] OpenGL ES 2.0: Implement texturing and debug object labeling. (flutter/engine#33156)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -77,7 +77,6 @@ executable("impeller_unittests") {
|
||||
"image:image_unittests",
|
||||
"playground",
|
||||
"renderer:renderer_unittests",
|
||||
"renderer/backend:backend_unittests",
|
||||
"typographer:typographer_unittests",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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(), //
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "impeller/compiler/compiler_backend.h"
|
||||
|
||||
#include "impeller/base/comparable.h"
|
||||
|
||||
namespace impeller {
|
||||
namespace compiler {
|
||||
|
||||
@@ -27,18 +29,19 @@ const spirv_cross::Compiler* CompilerBackend::operator->() const {
|
||||
uint32_t CompilerBackend::GetExtendedMSLResourceBinding(
|
||||
ExtendedResourceIndex index,
|
||||
spirv_cross::ID id) const {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (auto compiler = GetGLSLCompiler()) {
|
||||
return compiler->get_decoration(id, spv::Decoration::DecorationLocation);
|
||||
}
|
||||
const auto kOOBIndex = static_cast<uint32_t>(-1);
|
||||
auto compiler = GetMSLCompiler();
|
||||
if (!compiler) {
|
||||
return kOOBIndex;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return kOOBIndex;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -15,12 +15,3 @@ group("backend") {
|
||||
public_deps += [ "gles" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("backend_unittests") {
|
||||
testonly = true
|
||||
|
||||
deps = []
|
||||
if (impeller_enable_opengles) {
|
||||
deps += [ "gles:gles_unittests" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)) {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -5,3 +5,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "GLES2/gl2.h"
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include "GLES2/gl2ext.h"
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// 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 "impeller/renderer/backend/gles/gles_test.h"
|
||||
|
||||
#include "EGL/egl.h"
|
||||
#include "impeller/renderer/backend/gles/gles.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
GLESTest::GLESTest() = default;
|
||||
|
||||
GLESTest::~GLESTest() = default;
|
||||
|
||||
ProcTableGLES::Resolver GLESTest::GetResolver() const {
|
||||
return [](const char* name) {
|
||||
return reinterpret_cast<void*>(::eglGetProcAddress(name));
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
@@ -1,25 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "impeller/renderer/backend/gles/proc_table_gles.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class GLESTest : public ::testing::Test {
|
||||
public:
|
||||
GLESTest();
|
||||
|
||||
~GLESTest();
|
||||
|
||||
ProcTableGLES::Resolver GetResolver() const;
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(GLESTest);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@@ -1,18 +0,0 @@
|
||||
// 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"
|
||||
#include "impeller/renderer/backend/gles/gles_test.h"
|
||||
#include "impeller/renderer/backend/gles/proc_table_gles.h"
|
||||
|
||||
namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
TEST_F(GLESTest, CanCreateProcTable) {
|
||||
ProcTableGLES gl(GetResolver());
|
||||
ASSERT_TRUE(gl.IsValid());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
@@ -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() {
|
||||
|
||||
@@ -83,6 +83,12 @@ static bool LinkProgram(
|
||||
return false;
|
||||
}
|
||||
|
||||
gl.SetDebugLabel(DebugResourceType::kShader, vert_shader,
|
||||
SPrintF("%s Vertex Shader", descriptor.GetLabel().c_str()));
|
||||
gl.SetDebugLabel(
|
||||
DebugResourceType::kShader, frag_shader,
|
||||
SPrintF("%s Fragment Shader", descriptor.GetLabel().c_str()));
|
||||
|
||||
fml::ScopedCleanupClosure delete_vert_shader(
|
||||
[&gl, vert_shader]() { gl.DeleteShader(vert_shader); });
|
||||
fml::ScopedCleanupClosure delete_frag_shader(
|
||||
|
||||
@@ -30,11 +30,30 @@ const char* GLErrorToString(GLenum value) {
|
||||
return "Unknown.";
|
||||
}
|
||||
|
||||
ProcTableGLES::Resolver WrappedResolver(ProcTableGLES::Resolver resolver) {
|
||||
return [resolver](const char* function_name) -> void* {
|
||||
auto resolved = resolver(function_name);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
// If there are certain known suffixes (usually for extensions), strip them
|
||||
// out and try to resolve the same proc addresses again.
|
||||
auto function = std::string{function_name};
|
||||
if (function.find("KHR", function.size() - 3) != std::string::npos) {
|
||||
auto truncated = function.substr(0u, function.size() - 3);
|
||||
return resolver(truncated.c_str());
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
ProcTableGLES::ProcTableGLES(Resolver resolver) {
|
||||
if (!resolver) {
|
||||
return;
|
||||
}
|
||||
|
||||
resolver = WrappedResolver(resolver);
|
||||
|
||||
auto error_fn = reinterpret_cast<PFNGLGETERRORPROC>(resolver("glGetError"));
|
||||
if (!error_fn) {
|
||||
VALIDATION_LOG << "Could not resolve "
|
||||
@@ -56,9 +75,29 @@ ProcTableGLES::ProcTableGLES(Resolver resolver) {
|
||||
|
||||
#undef IMPELLER_PROC
|
||||
|
||||
is_valid_ = true;
|
||||
#define IMPELLER_PROC(proc_ivar) \
|
||||
if (auto fn_ptr = resolver(proc_ivar.name)) { \
|
||||
proc_ivar.function = \
|
||||
reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
|
||||
proc_ivar.error_fn = error_fn; \
|
||||
}
|
||||
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
|
||||
|
||||
#undef IMPELLER_PROC
|
||||
|
||||
description_ = std::make_unique<GLDescription>(*this);
|
||||
|
||||
if (!description_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!description_->HasDebugExtension()) {
|
||||
PushDebugGroupKHR.Reset();
|
||||
PopDebugGroupKHR.Reset();
|
||||
ObjectLabelKHR.Reset();
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
ProcTableGLES::~ProcTableGLES() = default;
|
||||
@@ -181,4 +220,38 @@ bool ProcTableGLES::IsCurrentFramebufferComplete() const {
|
||||
return status == GL_FRAMEBUFFER_COMPLETE;
|
||||
}
|
||||
|
||||
static std::optional<GLenum> ToDebugIdentifier(DebugResourceType type) {
|
||||
switch (type) {
|
||||
case DebugResourceType::kTexture:
|
||||
// No entry in GL_KHR_debug headers.
|
||||
return std::nullopt;
|
||||
case DebugResourceType::kBuffer:
|
||||
return GL_BUFFER_KHR;
|
||||
case DebugResourceType::kProgram:
|
||||
return GL_PROGRAM_KHR;
|
||||
case DebugResourceType::kShader:
|
||||
return GL_SHADER_KHR;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
void ProcTableGLES::SetDebugLabel(DebugResourceType type,
|
||||
GLint name,
|
||||
const std::string& label) const {
|
||||
if (!ObjectLabelKHR.IsAvailable()) {
|
||||
return;
|
||||
}
|
||||
const auto identifier = ToDebugIdentifier(type);
|
||||
const auto label_length =
|
||||
std::min<GLsizei>(GL_MAX_LABEL_LENGTH_KHR - 1, label.size());
|
||||
if (!identifier.has_value()) {
|
||||
return;
|
||||
}
|
||||
ObjectLabelKHR(identifier.value(), // identifier
|
||||
name, // name
|
||||
label_length, // length
|
||||
label.data() // label
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -62,21 +62,29 @@ struct GLProc {
|
||||
///
|
||||
template <class... Args>
|
||||
auto operator()(Args&&... args) const {
|
||||
FML_DCHECK(function) << "Function named "
|
||||
<< (name != nullptr ? name : "<null>")
|
||||
<< " unavailable.";
|
||||
AutoErrorCheck error(error_fn, name);
|
||||
return function(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
constexpr bool IsAvailable() const { return function != nullptr; }
|
||||
|
||||
void Reset() {
|
||||
name = nullptr;
|
||||
function = nullptr;
|
||||
error_fn = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
#define FOR_EACH_IMPELLER_PROC(PROC) \
|
||||
PROC(ActiveTexture); \
|
||||
PROC(AttachShader); \
|
||||
PROC(BindAttribLocation); \
|
||||
PROC(BindBuffer); \
|
||||
PROC(BindTexture); \
|
||||
PROC(BlendEquationSeparate); \
|
||||
PROC(BlendFuncSeparate); \
|
||||
PROC(BufferData); \
|
||||
PROC(CheckFramebufferStatus); \
|
||||
PROC(Clear); \
|
||||
PROC(ClearColor); \
|
||||
PROC(ClearDepthf); \
|
||||
@@ -121,16 +129,29 @@ struct GLProc {
|
||||
PROC(StencilFuncSeparate); \
|
||||
PROC(StencilMaskSeparate); \
|
||||
PROC(StencilOpSeparate); \
|
||||
PROC(TexImage2D); \
|
||||
PROC(TexParameteri); \
|
||||
PROC(Uniform1fv); \
|
||||
PROC(Uniform1i); \
|
||||
PROC(Uniform2fv); \
|
||||
PROC(Uniform4fv); \
|
||||
PROC(UniformMatrix4fv); \
|
||||
PROC(UseProgram); \
|
||||
PROC(CheckFramebufferStatus); \
|
||||
PROC(VertexAttribPointer); \
|
||||
PROC(Viewport);
|
||||
|
||||
#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
|
||||
PROC(PushDebugGroupKHR); \
|
||||
PROC(PopDebugGroupKHR); \
|
||||
PROC(ObjectLabelKHR);
|
||||
|
||||
enum class DebugResourceType {
|
||||
kTexture,
|
||||
kBuffer,
|
||||
kProgram,
|
||||
kShader,
|
||||
};
|
||||
|
||||
class ProcTableGLES {
|
||||
public:
|
||||
using Resolver = std::function<void*(const char* function_name)>;
|
||||
@@ -142,6 +163,7 @@ class ProcTableGLES {
|
||||
GLProc<decltype(gl##name)> name = {"gl" #name, nullptr};
|
||||
|
||||
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC);
|
||||
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC);
|
||||
|
||||
#undef IMPELLER_PROC
|
||||
|
||||
@@ -155,6 +177,10 @@ class ProcTableGLES {
|
||||
|
||||
bool IsCurrentFramebufferComplete() const;
|
||||
|
||||
void SetDebugLabel(DebugResourceType type,
|
||||
GLint name,
|
||||
const std::string& label) const;
|
||||
|
||||
private:
|
||||
bool is_valid_ = false;
|
||||
std::unique_ptr<GLDescription> description_;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "impeller/renderer/backend/gles/reactor_gles.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "impeller/base/validation.h"
|
||||
|
||||
@@ -15,7 +17,7 @@ ReactorGLES::ReactorGLES(std::unique_ptr<ProcTableGLES> gl)
|
||||
VALIDATION_LOG << "Proc table was invalid.";
|
||||
return;
|
||||
}
|
||||
|
||||
can_set_debug_labels_ = proc_table_->GetDescription()->HasDebugExtension();
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
@@ -123,16 +125,32 @@ bool ReactorGLES::React() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static DebugResourceType ToDebugResourceType(HandleType type) {
|
||||
switch (type) {
|
||||
case HandleType::kUnknown:
|
||||
FML_UNREACHABLE();
|
||||
case HandleType::kTexture:
|
||||
return DebugResourceType::kTexture;
|
||||
case HandleType::kBuffer:
|
||||
return DebugResourceType::kBuffer;
|
||||
case HandleType::kProgram:
|
||||
return DebugResourceType::kProgram;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
bool ReactorGLES::ReactOnce() {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& gl = GetProcTable();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Collect all the handles for whom there is a GL handle sibling.
|
||||
///
|
||||
for (const auto& handle_to_collect : gl_handles_to_collect_) {
|
||||
if (!CollectGLHandle(GetProcTable(), // proc table
|
||||
if (!CollectGLHandle(gl, // proc table
|
||||
handle_to_collect.first.type, // handle type
|
||||
handle_to_collect.second // GL handle name
|
||||
)) {
|
||||
@@ -150,7 +168,7 @@ bool ReactorGLES::ReactOnce() {
|
||||
// Already a realized GL handle.
|
||||
continue;
|
||||
}
|
||||
auto gl_handle = CreateGLHandle(GetProcTable(), live_handle.first.type);
|
||||
auto gl_handle = CreateGLHandle(gl, live_handle.first.type);
|
||||
if (!gl_handle.has_value()) {
|
||||
VALIDATION_LOG << "Could not create GL handle.";
|
||||
return false;
|
||||
@@ -158,6 +176,21 @@ bool ReactorGLES::ReactOnce() {
|
||||
live_handle.second = gl_handle;
|
||||
}
|
||||
|
||||
if (can_set_debug_labels_) {
|
||||
for (const auto& label : pending_debug_labels_) {
|
||||
auto live_handle = live_gl_handles_.find(label.first);
|
||||
if (live_handle == live_gl_handles_.end() ||
|
||||
!live_handle->second.has_value()) {
|
||||
continue;
|
||||
}
|
||||
gl.SetDebugLabel(ToDebugResourceType(label.first.type), // type
|
||||
live_handle->second.value(), // name
|
||||
label.second // label
|
||||
);
|
||||
}
|
||||
}
|
||||
pending_debug_labels_.clear();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Flush all pending operations in order.
|
||||
///
|
||||
@@ -170,4 +203,17 @@ bool ReactorGLES::ReactOnce() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReactorGLES::SetDebugLabel(const GLESHandle& handle, std::string label) {
|
||||
if (!can_set_debug_labels_) {
|
||||
return;
|
||||
}
|
||||
if (label.empty()) {
|
||||
return;
|
||||
}
|
||||
if (handle.IsDead()) {
|
||||
return;
|
||||
}
|
||||
pending_debug_labels_[handle] = std::move(label);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -35,6 +35,8 @@ class ReactorGLES {
|
||||
|
||||
void CollectHandle(GLESHandle handle);
|
||||
|
||||
void SetDebugLabel(const GLESHandle& handle, std::string label);
|
||||
|
||||
using Operation = std::function<void(const ReactorGLES& reactor)>;
|
||||
[[nodiscard]] bool AddOperation(Operation operation);
|
||||
|
||||
@@ -45,7 +47,9 @@ class ReactorGLES {
|
||||
std::vector<Operation> pending_operations_;
|
||||
GLESHandleMap<std::optional<GLuint>> live_gl_handles_;
|
||||
GLESHandleMap<GLuint> gl_handles_to_collect_;
|
||||
GLESHandleMap<std::string> pending_debug_labels_;
|
||||
bool in_reaction_ = false;
|
||||
bool can_set_debug_labels_ = false;
|
||||
|
||||
bool is_valid_ = false;
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ bool RenderPassGLES::IsValid() const {
|
||||
}
|
||||
|
||||
// |RenderPass|
|
||||
void RenderPassGLES::SetLabel(std::string label) {
|
||||
// Cannot support.
|
||||
void RenderPassGLES::OnSetLabel(std::string label) {
|
||||
label_ = std::move(label);
|
||||
}
|
||||
|
||||
void ConfigureBlending(const ProcTableGLES& gl,
|
||||
|
||||
@@ -19,6 +19,7 @@ class RenderPassGLES final : public RenderPass {
|
||||
friend class CommandBufferGLES;
|
||||
|
||||
ReactorGLES::Ref reactor_;
|
||||
std::string label_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
RenderPassGLES(RenderTarget target, ReactorGLES::Ref reactor);
|
||||
@@ -27,7 +28,7 @@ class RenderPassGLES final : public RenderPass {
|
||||
bool IsValid() const override;
|
||||
|
||||
// |RenderPass|
|
||||
void SetLabel(std::string label) override;
|
||||
void OnSetLabel(std::string label) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool EncodeCommands(
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
#include "impeller/renderer/backend/gles/sampler_gles.h"
|
||||
|
||||
#include "impeller/renderer/backend/gles/proc_table_gles.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
SamplerGLES::SamplerGLES() = default;
|
||||
SamplerGLES::SamplerGLES(SamplerDescriptor desc) : Sampler(std::move(desc)) {}
|
||||
|
||||
SamplerGLES::~SamplerGLES() = default;
|
||||
|
||||
@@ -14,4 +16,43 @@ bool SamplerGLES::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
static GLint ToParam(MinMagFilter filter) {
|
||||
switch (filter) {
|
||||
case MinMagFilter::kNearest:
|
||||
return GL_NEAREST;
|
||||
case MinMagFilter::kLinear:
|
||||
return GL_LINEAR;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
static GLint ToAddressMode(SamplerAddressMode mode) {
|
||||
switch (mode) {
|
||||
case SamplerAddressMode::kClampToEdge:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
case SamplerAddressMode::kRepeat:
|
||||
return GL_REPEAT;
|
||||
case SamplerAddressMode::kMirror:
|
||||
return GL_MIRRORED_REPEAT;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
bool SamplerGLES::ConfigureBoundTexture(const ProcTableGLES& gl) const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& desc = GetDescriptor();
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
ToParam(desc.min_filter));
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
ToParam(desc.mag_filter));
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||
ToAddressMode(desc.width_address_mode));
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
|
||||
ToAddressMode(desc.height_address_mode));
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -5,20 +5,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/renderer/sampler.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class SamplerLibraryGLES;
|
||||
class ProcTableGLES;
|
||||
|
||||
class SamplerGLES final : public Sampler {
|
||||
class SamplerGLES final : public Sampler,
|
||||
public BackendCast<SamplerGLES, Sampler> {
|
||||
public:
|
||||
~SamplerGLES();
|
||||
|
||||
bool ConfigureBoundTexture(const ProcTableGLES& gl) const;
|
||||
|
||||
private:
|
||||
friend class SamplerLibraryGLES;
|
||||
|
||||
SamplerGLES();
|
||||
SamplerGLES(SamplerDescriptor desc);
|
||||
|
||||
// |Sampler|
|
||||
bool IsValid() const override;
|
||||
|
||||
@@ -22,7 +22,7 @@ std::shared_ptr<const Sampler> SamplerLibraryGLES::GetSampler(
|
||||
return found->second;
|
||||
}
|
||||
return samplers_[std::move(descriptor)] =
|
||||
std::shared_ptr<SamplerGLES>(new SamplerGLES());
|
||||
std::shared_ptr<SamplerGLES>(new SamplerGLES(descriptor));
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "impeller/base/allocation.h"
|
||||
#include "impeller/base/config.h"
|
||||
#include "impeller/base/validation.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -34,18 +35,127 @@ bool TextureGLES::IsValid() const {
|
||||
|
||||
// |Texture|
|
||||
void TextureGLES::SetLabel(const std::string_view& label) {
|
||||
// Unsupported.
|
||||
if (!IsValid() || handle_.IsDead()) {
|
||||
return;
|
||||
}
|
||||
reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
|
||||
}
|
||||
|
||||
struct TexImage2DData {
|
||||
GLint internal_format = 0;
|
||||
GLenum format = GL_NONE;
|
||||
GLenum type = GL_NONE;
|
||||
std::shared_ptr<fml::Mapping> data;
|
||||
|
||||
TexImage2DData(PixelFormat pixel_format,
|
||||
const uint8_t* contents,
|
||||
size_t length) {
|
||||
switch (pixel_format) {
|
||||
case PixelFormat::kUnknown:
|
||||
return;
|
||||
case PixelFormat::kR8UNormInt:
|
||||
internal_format = GL_RGBA;
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
{
|
||||
auto allocation = std::make_shared<Allocation>();
|
||||
if (!allocation->Truncate(length * 2u, false)) {
|
||||
VALIDATION_LOG << "Could not allocate buffer for texture data.";
|
||||
return;
|
||||
}
|
||||
auto buffer = reinterpret_cast<uint16_t*>(allocation->GetBuffer());
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
uint8_t value = contents[i];
|
||||
buffer[i] = (value | value << 4 | value << 8 | value << 12);
|
||||
}
|
||||
data = CreateMappingFromAllocation(std::move(allocation));
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PixelFormat::kR8G8B8A8UNormInt:
|
||||
internal_format = GL_RGBA;
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
data = CreateMappingWithCopy(contents, length);
|
||||
if (!data) {
|
||||
VALIDATION_LOG << "Could not copy texture data.";
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case PixelFormat::kR8G8B8A8UNormIntSRGB:
|
||||
return;
|
||||
case PixelFormat::kB8G8R8A8UNormInt:
|
||||
return;
|
||||
case PixelFormat::kB8G8R8A8UNormIntSRGB:
|
||||
return;
|
||||
case PixelFormat::kS8UInt:
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
bool IsValid() const { return is_valid_; }
|
||||
|
||||
private:
|
||||
bool is_valid_ = false;
|
||||
};
|
||||
|
||||
// |Texture|
|
||||
bool TextureGLES::SetContents(const uint8_t* contents, size_t length) {
|
||||
if (length == 0u) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto mapping = CreateMappingWithCopy(contents, length);
|
||||
const auto& tex_descriptor = GetTextureDescriptor();
|
||||
|
||||
return reactor_->AddOperation([mapping](const auto& reactor) {});
|
||||
if (tex_descriptor.size.IsEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!tex_descriptor.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (length < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
|
||||
VALIDATION_LOG << "Insufficient data provided for texture.";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto data =
|
||||
std::make_shared<TexImage2DData>(tex_descriptor.format, contents, length);
|
||||
if (!data || !data->IsValid()) {
|
||||
VALIDATION_LOG << "Invalid texture format.";
|
||||
return false;
|
||||
}
|
||||
|
||||
ReactorGLES::Operation texture_upload = [handle = handle_, //
|
||||
data, //
|
||||
size = tex_descriptor.size //
|
||||
](const auto& reactor) {
|
||||
auto gl_handle = reactor.GetGLHandle(handle);
|
||||
if (!gl_handle.has_value()) {
|
||||
VALIDATION_LOG
|
||||
<< "Texture was collected before it could be uploaded to the GPU.";
|
||||
return;
|
||||
}
|
||||
const auto& gl = reactor.GetProcTable();
|
||||
gl.BindTexture(GL_TEXTURE_2D, gl_handle.value());
|
||||
gl.TexImage2D(
|
||||
GL_TEXTURE_2D, // target
|
||||
0u, // LOD level (base mip level size checked)
|
||||
data->internal_format, // internal format
|
||||
size.width, // width
|
||||
size.height, // height
|
||||
0u, // border
|
||||
data->format, // format
|
||||
data->type, // type
|
||||
reinterpret_cast<const GLvoid*>(data->data->GetMapping()) // data
|
||||
);
|
||||
};
|
||||
|
||||
return reactor_->AddOperation(texture_upload);
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
@@ -53,4 +163,17 @@ ISize TextureGLES::GetSize() const {
|
||||
return GetTextureDescriptor().size;
|
||||
}
|
||||
|
||||
bool TextureGLES::Bind() const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
auto handle = reactor_->GetGLHandle(handle_);
|
||||
if (!handle.has_value()) {
|
||||
return false;
|
||||
}
|
||||
const auto& gl = reactor_->GetProcTable();
|
||||
gl.BindTexture(GL_TEXTURE_2D, handle.value());
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -5,19 +5,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/renderer/backend/gles/gles_handle.h"
|
||||
#include "impeller/renderer/backend/gles/reactor_gles.h"
|
||||
#include "impeller/renderer/texture.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class TextureGLES final : public Texture {
|
||||
class TextureGLES final : public Texture,
|
||||
public BackendCast<TextureGLES, Texture> {
|
||||
public:
|
||||
TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc);
|
||||
|
||||
// |Texture|
|
||||
~TextureGLES() override;
|
||||
|
||||
bool Bind() const;
|
||||
|
||||
private:
|
||||
friend class AllocatorMTL;
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class CommandBufferMTL 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(CommandBufferMTL);
|
||||
|
||||
@@ -195,7 +195,7 @@ bool CommandBufferMTL::SubmitCommands(CompletionCallback callback) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderPass> CommandBufferMTL::CreateRenderPass(
|
||||
std::shared_ptr<RenderPass> CommandBufferMTL::OnCreateRenderPass(
|
||||
RenderTarget target) const {
|
||||
if (!buffer_) {
|
||||
return nullptr;
|
||||
|
||||
@@ -76,8 +76,11 @@ bool DeviceBufferMTL::SetLabel(const std::string& label, Range range) {
|
||||
if (@available(macOS 10.12, iOS 10.0, *)) {
|
||||
[buffer_ addDebugMarker:@(label.c_str())
|
||||
range:NSMakeRange(range.offset, range.length)];
|
||||
return true;
|
||||
} else {
|
||||
return SetLabel(label);
|
||||
}
|
||||
return true;
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -31,7 +31,7 @@ class RenderPassMTL final : public RenderPass {
|
||||
bool IsValid() const override;
|
||||
|
||||
// |RenderPass|
|
||||
void SetLabel(std::string label) override;
|
||||
void OnSetLabel(std::string label) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool EncodeCommands(
|
||||
|
||||
@@ -135,7 +135,6 @@ RenderPassMTL::RenderPassMTL(id<MTLCommandBuffer> buffer, RenderTarget target)
|
||||
if (!buffer_ || !desc_ || !render_target_.IsValid()) {
|
||||
return;
|
||||
}
|
||||
SetLabel("RenderPass");
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
@@ -145,12 +144,11 @@ bool RenderPassMTL::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
void RenderPassMTL::SetLabel(std::string label) {
|
||||
void RenderPassMTL::OnSetLabel(std::string label) {
|
||||
if (label.empty()) {
|
||||
return;
|
||||
}
|
||||
label_ = std::move(label);
|
||||
transients_buffer_->SetLabel(SPrintF("%s Transients", label_.c_str()));
|
||||
}
|
||||
|
||||
bool RenderPassMTL::EncodeCommands(
|
||||
|
||||
@@ -26,8 +26,8 @@ std::shared_ptr<const Sampler> SamplerLibraryMTL::GetSampler(
|
||||
desc.minFilter = ToMTLSamplerMinMagFilter(descriptor.min_filter);
|
||||
desc.magFilter = ToMTLSamplerMinMagFilter(descriptor.mag_filter);
|
||||
desc.sAddressMode = MTLSamplerAddressMode(descriptor.width_address_mode);
|
||||
desc.rAddressMode = MTLSamplerAddressMode(descriptor.depth_address_mode);
|
||||
desc.tAddressMode = MTLSamplerAddressMode(descriptor.height_address_mode);
|
||||
desc.rAddressMode = MTLSamplerAddressMode(descriptor.depth_address_mode);
|
||||
|
||||
if (!descriptor.label.empty()) {
|
||||
desc.label = @(descriptor.label.c_str());
|
||||
@@ -37,7 +37,8 @@ std::shared_ptr<const Sampler> SamplerLibraryMTL::GetSampler(
|
||||
if (!mtl_sampler) {
|
||||
return nullptr;
|
||||
}
|
||||
auto sampler = std::shared_ptr<SamplerMTL>(new SamplerMTL(mtl_sampler));
|
||||
auto sampler =
|
||||
std::shared_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
|
||||
if (!sampler->IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class SamplerMTL final : public Sampler,
|
||||
|
||||
id<MTLSamplerState> state_ = nullptr;
|
||||
|
||||
SamplerMTL(id<MTLSamplerState> state);
|
||||
SamplerMTL(SamplerDescriptor desc, id<MTLSamplerState> state);
|
||||
|
||||
// |Sampler|
|
||||
bool IsValid() const override;
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
SamplerMTL::SamplerMTL(id<MTLSamplerState> state) : state_(state) {}
|
||||
SamplerMTL::SamplerMTL(SamplerDescriptor desc, id<MTLSamplerState> state)
|
||||
: Sampler(std::move(desc)), state_(state) {}
|
||||
|
||||
SamplerMTL::~SamplerMTL() = default;
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
CommandBuffer::CommandBuffer() = default;
|
||||
@@ -14,4 +17,14 @@ bool CommandBuffer::SubmitCommands() {
|
||||
return SubmitCommands(nullptr);
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderPass> CommandBuffer::CreateRenderPass(
|
||||
RenderTarget render_target) const {
|
||||
auto pass = OnCreateRenderPass(std::move(render_target));
|
||||
if (pass && pass->IsValid()) {
|
||||
pass->SetLabel("RenderPass");
|
||||
return pass;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -70,12 +70,15 @@ class CommandBuffer {
|
||||
///
|
||||
/// @return A valid render pass or null.
|
||||
///
|
||||
virtual std::shared_ptr<RenderPass> CreateRenderPass(
|
||||
RenderTarget render_target) const = 0;
|
||||
std::shared_ptr<RenderPass> CreateRenderPass(
|
||||
RenderTarget render_target) const;
|
||||
|
||||
protected:
|
||||
CommandBuffer();
|
||||
|
||||
virtual std::shared_ptr<RenderPass> OnCreateRenderPass(
|
||||
RenderTarget render_target) const = 0;
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(CommandBuffer);
|
||||
};
|
||||
|
||||
@@ -24,6 +24,14 @@ HostBuffer& RenderPass::GetTransientsBuffer() {
|
||||
return *transients_buffer_;
|
||||
}
|
||||
|
||||
void RenderPass::SetLabel(std::string label) {
|
||||
if (label.empty()) {
|
||||
return;
|
||||
}
|
||||
transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
|
||||
OnSetLabel(std::move(label));
|
||||
}
|
||||
|
||||
bool RenderPass::AddCommand(Command command) {
|
||||
if (!command) {
|
||||
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
|
||||
|
||||
@@ -33,7 +33,7 @@ class RenderPass {
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
virtual void SetLabel(std::string label) = 0;
|
||||
void SetLabel(std::string label);
|
||||
|
||||
HostBuffer& GetTransientsBuffer();
|
||||
|
||||
@@ -66,6 +66,8 @@ class RenderPass {
|
||||
|
||||
RenderPass(RenderTarget target);
|
||||
|
||||
virtual void OnSetLabel(std::string label) = 0;
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(RenderPass);
|
||||
};
|
||||
|
||||
@@ -6,8 +6,12 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
Sampler::Sampler() = default;
|
||||
Sampler::Sampler(SamplerDescriptor desc) : desc_(std::move(desc)) {}
|
||||
|
||||
Sampler::~Sampler() = default;
|
||||
|
||||
const SamplerDescriptor& Sampler::GetDescriptor() const {
|
||||
return desc_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/renderer/sampler_descriptor.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -14,8 +15,12 @@ class Sampler {
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
const SamplerDescriptor& GetDescriptor() const;
|
||||
|
||||
protected:
|
||||
Sampler();
|
||||
SamplerDescriptor desc_;
|
||||
|
||||
Sampler(SamplerDescriptor desc);
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Sampler);
|
||||
|
||||
Reference in New Issue
Block a user