Skip to content

Commit

Permalink
Add Free-Threaded resource upload to Android OpenGL Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alasram committed Sep 13, 2024
1 parent cb38119 commit 0d64d6c
Show file tree
Hide file tree
Showing 47 changed files with 1,216 additions and 156 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,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 @@ -1107,6 +1109,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 @@ -864,6 +864,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 @@ -892,6 +894,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&);

protected:
class Impl;
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
21 changes: 21 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,11 @@ class RendererBackend : public gfx::RendererBackend {
void initShaders(gfx::ShaderRegistry&, const ProgramParameters& programParameters) override;
#endif

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

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

Expand All @@ -52,12 +68,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

0 comments on commit 0d64d6c

Please sign in to comment.