Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free threaded resources on Android #2761

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,8 @@ if(MLN_WITH_OPENGL)
SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/gl/attribute.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/attribute.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/buffer_resource.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/buffer_resource.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/command_encoder.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/command_encoder.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/context.cpp
Expand Down Expand Up @@ -1111,6 +1113,8 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/src/mbgl/gl/renderer_backend.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/resource_pool.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/resource_pool.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/resource_upload_thread_pool.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/resource_upload_thread_pool.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/state.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/texture.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/texture.hpp
Expand Down
4 changes: 4 additions & 0 deletions bazel/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ MLN_CORE_HEADERS = [
MLN_OPENGL_SOURCE = [
"src/mbgl/gl/attribute.cpp",
"src/mbgl/gl/attribute.hpp",
"src/mbgl/gl/buffer_resource.cpp",
"src/mbgl/gl/buffer_resource.hpp",
"src/mbgl/gl/command_encoder.cpp",
"src/mbgl/gl/command_encoder.hpp",
"src/mbgl/gl/context.cpp",
Expand Down Expand Up @@ -898,6 +900,8 @@ MLN_OPENGL_SOURCE = [
"src/mbgl/gl/renderer_backend.cpp",
"src/mbgl/gl/resource_pool.cpp",
"src/mbgl/gl/resource_pool.hpp",
"src/mbgl/gl/resource_upload_thread_pool.cpp",
"src/mbgl/gl/resource_upload_thread_pool.hpp",
"src/mbgl/gl/state.hpp",
"src/mbgl/gl/texture.cpp",
"src/mbgl/gl/texture.hpp",
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/gl/drawable_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DrawableGL : public gfx::Drawable {

void setVertexAttrId(const size_t id);

void upload(gfx::UploadPass&);
void issueUpload(gfx::UploadPass&);

void updateVertexAttributes(gfx::VertexAttributeArrayPtr,
std::size_t vertexCount,
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/gl/layer_group_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TileLayerGroupGL : public TileLayerGroup {
TileLayerGroupGL(int32_t layerIndex, std::size_t initialCapacity, std::string name);
~TileLayerGroupGL() override {}

void upload(gfx::UploadPass&) override;
void issueUpload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;

const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
Expand All @@ -39,7 +39,7 @@ class LayerGroupGL : public LayerGroup {
LayerGroupGL(int32_t layerIndex, std::size_t initialCapacity, std::string name);
~LayerGroupGL() override {}

void upload(gfx::UploadPass&) override;
void issueUpload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;

const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
Expand Down
20 changes: 20 additions & 0 deletions include/mbgl/gl/renderer_backend.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/gl/resource_upload_thread_pool.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/size.hpp>
#include <mbgl/util/util.hpp>
Expand All @@ -14,6 +15,16 @@ namespace gl {
using ProcAddress = void (*)();
using FramebufferID = uint32_t;

class UploadThreadContext {
public:
UploadThreadContext() = default;
virtual ~UploadThreadContext() = default;
virtual void createContext() = 0;
virtual void destroyContext() = 0;
virtual void bindContext() = 0;
virtual void unbindContext() = 0;
};

class RendererBackend : public gfx::RendererBackend {
public:
RendererBackend(gfx::ContextMode);
Expand All @@ -28,6 +39,10 @@ class RendererBackend : public gfx::RendererBackend {
void initShaders(gfx::ShaderRegistry&, const ProgramParameters& programParameters) override;
#endif

virtual bool supportFreeThreadedUpload() { return false; }
virtual std::shared_ptr<UploadThreadContext> createUploadThreadContext() { return nullptr; }
gl::ResourceUploadThreadPool& getResourceUploadThreadPool();

protected:
std::unique_ptr<gfx::Context> createContext() override;

Expand All @@ -52,12 +67,17 @@ class RendererBackend : public gfx::RendererBackend {
/// Returns true when assumed framebuffer binding hasn't changed from the implicit binding.
bool implicitFramebufferBound();

void destroyResourceUploadThreadPool() { resourceUploadThreadPool = nullptr; }

public:
/// Triggers an OpenGL state update if the internal assumed state doesn't
/// match the supplied values.
void setFramebufferBinding(FramebufferID fbo);
void setViewport(int32_t x, int32_t y, const Size&);
void setScissorTest(bool);

private:
std::unique_ptr<gl::ResourceUploadThreadPool> resourceUploadThreadPool;
};

} // namespace gl
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/mtl/layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LayerGroup : public mbgl::LayerGroup {
LayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name);
~LayerGroup() override {}

void upload(gfx::UploadPass&) override;
void issueUpload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;

const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/mtl/tile_layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TileLayerGroup : public mbgl::TileLayerGroup {
TileLayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name);
~TileLayerGroup() override {}

void upload(gfx::UploadPass&) override;
void issueUpload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;

const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/renderer/layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LayerGroupBase : public util::SimpleIdentifiable {
/// Called before starting each frame
virtual void preRender(RenderOrchestrator&, PaintParameters&) {}
/// Called during the upload pass
virtual void upload(gfx::UploadPass&) {}
virtual void issueUpload(gfx::UploadPass&) {}
/// Called during each render pass
virtual void render(RenderOrchestrator&, PaintParameters&) {}
/// Called at the end of each frame
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/renderer/render_target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RenderTarget {
}

/// Upload the layer groups
void upload(gfx::UploadPass& uploadPass);
void issueUpload(gfx::UploadPass& uploadPass);

/// Render the layer groups
void render(RenderOrchestrator&, const RenderTree&, PaintParameters&);
Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/util/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ inline float stof(const std::string &str) {
return std::stof(str);
}

// returns true if str contains substr
inline bool contains(const std::string &str, const std::string &substr) {
return str.find(substr) != std::string::npos;
}

} // namespace util
} // namespace mbgl

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/vulkan/layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LayerGroup : public mbgl::LayerGroup {
LayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name);
~LayerGroup() override {}

void upload(gfx::UploadPass&) override;
void issueUpload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;

const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/vulkan/tile_layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TileLayerGroup : public mbgl::TileLayerGroup {
TileLayerGroup(int32_t layerIndex, std::size_t initialCapacity, std::string name);
~TileLayerGroup() override {}

void upload(gfx::UploadPass&) override;
void issueUpload(gfx::UploadPass&) override;
void render(RenderOrchestrator&, PaintParameters&) override;

const gfx::UniformBufferArray& getUniformBuffers() const override { return uniformBuffers; };
Expand Down
Loading
Loading