Metal Optimizations (#1748)

This commit is contained in:
Tim Sylvester
2023-10-10 18:34:44 -07:00
committed by GitHub
parent d63f94f5a8
commit ce0096aab0
9 changed files with 131 additions and 71 deletions

View File

@@ -14,6 +14,7 @@
#include <mbgl/mtl/mtl_fwd.hpp>
#include <memory>
#include <optional>
#include <unordered_map>
namespace mbgl {
@@ -108,10 +109,19 @@ public:
virtual bool emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr&, const void* data, std::size_t size);
/// Get a reusable buffer containing the standard fixed tile vertices (+/- `util::EXTENT`)
const BufferResource& getTileVertexBuffer();
/// Get a reusable buffer containing the standard fixed tile indexes
const BufferResource& getTileIndexBuffer();
private:
RendererBackend& backend;
bool cleanupOnDestruction = true;
std::optional<BufferResource> tileVertexBuffer;
std::optional<BufferResource> tileIndexBuffer;
gfx::RenderingStats stats;
};

View File

@@ -30,11 +30,11 @@ public:
constexpr auto& fragMain = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Metal>::fragmentMainFunction;
const std::string shaderName = std::string(name);
const auto shaderSource = std::string(shaders::prelude) + source;
auto shader = get<mtl::ShaderProgram>(shaderName);
if (!shader) {
auto& context = static_cast<Context&>(gfxContext);
const auto shaderSource = std::string(shaders::prelude) + source;
shader = context.createProgram(shaderName, shaderSource, vertMain, fragMain, programParameters, {});
assert(shader);
if (!shader || !registerShader(shader, shaderName)) {