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

Metal debug render tests #1855

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6971217
Fixed metal symbol render tests.
alexcristici Nov 9, 2023
1e74712
Revert the removing of SymbolDynamicUBO.
alexcristici Nov 9, 2023
3c055bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
622b634
Implemented the missing SymbolDynamicUBO in the symbol metal shaders.
alexcristici Nov 9, 2023
942398b
Merge branch 'main' into metal-symbol-render-tests
alexcristici Nov 9, 2023
4261e3b
Fixes.
alexcristici Nov 9, 2023
1f667b8
Merge branch 'metal-symbol-render-tests' of https://github.com/alexcr…
alexcristici Nov 9, 2023
4138d9a
Merge branch 'main' into metal-symbol-render-tests
alexcristici Nov 9, 2023
27f7b9b
Fixed circle render tests.
alexcristici Nov 9, 2023
cd7bcd6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
dc0651f
Merge branch 'main' into metal-circle-render-tests
alexcristici Nov 9, 2023
95e13c0
Modified Benchmark app to be able to render style json render test in…
alexcristici Nov 9, 2023
43d36a0
Merge branch 'metal-symbol-render-tests' into metal-debug-render-tests
alexcristici Nov 9, 2023
a07b603
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
b0e8953
Merge branch 'metal-circle-render-tests' into metal-debug-render-tests
alexcristici Nov 9, 2023
d4e49c1
Merge branch 'metal-debug-render-tests' of https://github.com/alexcri…
alexcristici Nov 9, 2023
7c66183
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 9, 2023
d3dad38
Fixed metal heatmap render tests.
alexcristici Nov 14, 2023
4ac0781
Merge branch 'metal-heatmap-render-tests' into metal-debug-render-tests
alexcristici Nov 14, 2023
4bfa17b
Fixed metal background render tests and implemented missing backgroun…
alexcristici Nov 14, 2023
fb0adb1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2023
6457b32
Merge branch 'metal-background-render-tests' into metal-debug-render-…
alexcristici Nov 14, 2023
2c5f270
Merge branch 'metal-background-render-tests' into metal-debug-render-…
alexcristici Nov 14, 2023
8e43350
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2023
9b66f75
Merge branch 'metal-debug-render-tests' of https://github.com/alexcri…
alexcristici Nov 14, 2023
c2af7de
Fixed color per vertex.
alexcristici Nov 14, 2023
81affc5
Merge branch 'metal-fill-color-fix' into metal-debug-render-tests
alexcristici Nov 14, 2023
8be24f0
Fixed metal vertex attribute update render tests.
alexcristici Nov 15, 2023
1351dbb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2023
a0befef
Merge branch 'metal-vertex-attribute-render-tests' into metal-debug-r…
alexcristici Nov 15, 2023
86bfaba
Merged collision drawables shared buffers.
alexcristici Nov 15, 2023
e580a75
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2023
afdb441
Revert comment.
alexcristici Nov 15, 2023
ad22a42
Merged triangulated fill outlines.
alexcristici Nov 15, 2023
6253cc9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2023
304f2f5
Fixed metal line render tests.
alexcristici Nov 15, 2023
098b6c7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2023
e7a6c54
Merge branch 'metal-line-render-tests' into metal-debug-render-tests
alexcristici Nov 15, 2023
4e5dcf7
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 15, 2023
85fdb1c
Implemented metal debug shader.
alexcristici Nov 15, 2023
d005f51
Merge branch 'metal-debug-shader' into metal-debug-render-tests
alexcristici Nov 15, 2023
fb1b339
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 15, 2023
40f4c25
Updated expected image for render-tests/text-pitch-alignment/viewport…
alexcristici Nov 16, 2023
5507b13
Merge branch 'render-test-depthtest-wrong-expected' into metal-debug-…
alexcristici Nov 16, 2023
2ffeff2
Added debug.
alexcristici Nov 16, 2023
337c5f8
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 16, 2023
1cb3686
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 17, 2023
7bcd75e
Revert changes.
alexcristici Nov 17, 2023
28d19fa
More reverts.
alexcristici Nov 17, 2023
b2fe0ed
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 18, 2023
c614c22
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 20, 2023
a606c25
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 21, 2023
1db0fa5
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 22, 2023
9df20a1
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 24, 2023
c2f776d
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 27, 2023
e9f2a09
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 27, 2023
6a535c7
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 27, 2023
1a2970f
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 28, 2023
edb2f08
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 28, 2023
c9d02bf
Merge branch 'main' into metal-debug-render-tests
alexcristici Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions platform/ios/benchmark/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ filegroup(
"MBXBenchAppDelegate.mm",
"MBXBenchViewController.mm",
"locations.cpp",
"file_source.cpp",
],
visibility = ["//platform:__pkg__"],
)
Expand All @@ -17,6 +18,7 @@ filegroup(
"MBXBenchAppDelegate.h",
"MBXBenchViewController.h",
"locations.hpp",
"file_source.hpp",
],
visibility = ["//platform:__pkg__"],
)
Expand Down
70 changes: 55 additions & 15 deletions platform/ios/benchmark/MBXBenchViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
#import "MLNOfflineStorage_Private.h"
#import "MLNSettings_Private.h"

#include "file_source.hpp"
#include "locations.hpp"

#include <chrono>

#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gfx/headless_frontend.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/storage/file_source_manager.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/run_loop.hpp>

@protocol BenchMapDelegate <NSObject>
- (void)mapDidFinishRenderingFrameFullyRendered:(BOOL)fullyRendered
Expand Down Expand Up @@ -44,6 +47,7 @@ @interface MBXBenchViewController () <BenchMapDelegate> {
std::unique_ptr<BenchMapObserver> observer;
std::unique_ptr<mbgl::HeadlessFrontend> frontend;
std::unique_ptr<mbgl::Map> map;
mbgl::util::RunLoop runLoop;
}

@property (nonatomic) UIImageView *imageView;
Expand Down Expand Up @@ -93,8 +97,9 @@ - (void)viewDidAppear:(BOOL)animated
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.imageView];

mbgl::Size viewSize = { static_cast<uint32_t>(self.view.bounds.size.width),
static_cast<uint32_t>(self.view.bounds.size.height) };
//mbgl::Size viewSize = { static_cast<uint32_t>(self.view.bounds.size.width),
// static_cast<uint32_t>(self.view.bounds.size.height) };
mbgl::Size viewSize = { 512, 512 };
auto pixelRatio = [[UIScreen mainScreen] scale];

observer = std::make_unique<BenchMapObserver>(self);
Expand All @@ -104,24 +109,41 @@ - (void)viewDidAppear:(BOOL)animated
mbgl::gfx::HeadlessBackend::SwapBehaviour::Flush,
mbgl::gfx::ContextMode::Unique,
/* localFontFamily */ std::nullopt,
/* invalidateOnUpdate */ false
/* invalidateOnUpdate */ true
);

mbgl::MapOptions mapOptions;
mapOptions.withMapMode(mbgl::MapMode::Continuous)
mapOptions.withMapMode(mbgl::MapMode::Static)
.withSize(viewSize)
.withPixelRatio(pixelRatio)
.withConstrainMode(mbgl::ConstrainMode::None)
.withViewportMode(mbgl::ViewportMode::Default)
.withCrossSourceCollisions(true);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* cachePath = [documentsDirectory stringByAppendingPathComponent:@"cache-style.db"];

mbgl::TileServerOptions* tileServerOptions = [[MLNSettings sharedSettings] tileServerOptionsInternal];
mbgl::ResourceOptions resourceOptions;
resourceOptions.withCachePath(MLNOfflineStorage.sharedOfflineStorage.databasePath.UTF8String)
resourceOptions.withCachePath(cachePath.UTF8String)
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String)
.withTileServerOptions(*tileServerOptions);
mbgl::ClientOptions clientOptions;

auto* fileSourceManager = mbgl::FileSourceManager::get();

auto resourceLoaderFactory = fileSourceManager->unRegisterFileSourceFactory(
mbgl::FileSourceType::ResourceLoader);
auto factory = [defaultFactory = std::move(resourceLoaderFactory)](const mbgl::ResourceOptions& resourceOptions,
const mbgl::ClientOptions& clientOptions) {
assert(defaultFactory);
std::shared_ptr<mbgl::FileSource> fileSource = defaultFactory(resourceOptions, clientOptions);
return std::make_unique<mbgl::ProxyFileSource>(std::move(fileSource), resourceOptions, clientOptions);
};

fileSourceManager->registerFileSourceFactory(mbgl::FileSourceType::ResourceLoader, std::move(factory));

auto apiKey = [[MLNSettings sharedSettings] apiKey];
if (apiKey) {
resourceOptions.withApiKey([apiKey UTF8String]);
Expand All @@ -130,9 +152,21 @@ - (void)viewDidAppear:(BOOL)animated
map = std::make_unique<mbgl::Map>(*frontend, *observer, mapOptions, resourceOptions, clientOptions);
map->setSize(viewSize);
map->setDebug(mbgl::MapDebugOptions::NoDebug);
map->getStyle().loadURL([url.absoluteString UTF8String]);
//map->getStyle().loadURL([url.absoluteString UTF8String]);

NSString* jsonPath = [documentsDirectory stringByAppendingPathComponent:@"style.json"];
NSData* jsonData = [NSData dataWithContentsOfFile:jsonPath];
NSString* jsonString = [[NSString alloc] initWithBytes:[jsonData bytes]
length:[jsonData length]
encoding:NSUTF8StringEncoding];

[self startBenchmarkIteration];
map->getStyle().loadJSON(jsonString.UTF8String);
//map->setDebug(mbgl::MapDebugOptions::Collision | mbgl::MapDebugOptions::TileBorders);

//map->getStyle().loadURL("https://api.maptiler.com/maps/2f4c4899-e695-4c8b-a4ef-92fa9d2740ff/style.json?key=G4MQXsYbLiUxOu3SV4lh");

//[self startBenchmarkIteration];
[self renderFrame];
}

// For setting the filename
Expand Down Expand Up @@ -194,17 +228,19 @@ - (void)renderFrame
{
mbgl::gfx::BackendScope guard{*(frontend->getBackend())};

frontend->renderFrame();
//frontend->renderFrame();

//auto image = frontend->readStillImage();

auto image = frontend->readStillImage();
auto result = frontend->render(*map);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(
image.data.get(),
image.size.width,
image.size.height,
result.image.data.get(),
result.image.size.width,
result.image.size.height,
8,
4 * image.size.width,
4 * result.image.size.width,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault
);
Expand Down Expand Up @@ -288,7 +324,11 @@ - (void)mapDidFinishRenderingFrameFullyRendered:(__unused BOOL)fullyRendered
frameEncodingTime:(double)frameEncodingTime
frameRenderingTime:(double)frameRenderingTime
{
if (state == State::Benchmarking)
dispatch_async(dispatch_get_main_queue(), ^{
[self renderFrame];
});

/*if (state == State::Benchmarking)
{
frames++;
totalFrameEncodingTime += frameEncodingTime;
Expand Down Expand Up @@ -344,7 +384,7 @@ - (void)mapDidFinishRenderingFrameFullyRendered:(__unused BOOL)fullyRendered
[self renderFrame];
});
return;
}
}*/
}

- (NSUInteger)supportedInterfaceOrientations
Expand Down
126 changes: 126 additions & 0 deletions platform/ios/benchmark/file_source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <mbgl/storage/file_source_manager.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/util/async_request.hpp>
#include <mbgl/util/client_options.hpp>
#include <mbgl/util/logging.hpp>

#include <atomic>

#include "file_source.hpp"

namespace mbgl {

std::atomic_size_t requestCount{0};
std::atomic_size_t transferredSize{0};
std::atomic_bool active{false};
std::atomic_bool offline{true};

ProxyFileSource::ProxyFileSource(std::shared_ptr<FileSource> defaultResourceLoader_,
const ResourceOptions& resourceOptions_,
const ClientOptions& clientOptions_)
: defaultResourceLoader(std::move(defaultResourceLoader_)),
resourceOptions(resourceOptions_.clone()),
clientOptions(clientOptions_.clone()) {
assert(defaultResourceLoader);
if (offline) {
std::shared_ptr<FileSource> dbfs = FileSourceManager::get()->getFileSource(
FileSourceType::Database, resourceOptions_, clientOptions_);
dbfs->setProperty(READ_ONLY_MODE_KEY, true);
}
}

ProxyFileSource::~ProxyFileSource() = default;

std::unique_ptr<AsyncRequest> ProxyFileSource::request(const Resource& resource, Callback callback) {
auto transformed = resource;

// If offline, force always loading the resource from the cache
// so we don't make any network request.
if (offline) {
transformed.loadingMethod = Resource::LoadingMethod::CacheOnly;
}

// This is needed for compatibility with the style tests that
// are using local:// instead of http:// which is the schema
// we support for cached files.
if (transformed.url.compare(0, 8, "local://") == 0) {
transformed.url.replace(0, 8, "http://");

if (transformed.kind == Resource::Kind::Tile && transformed.tileData) {
transformed.tileData->urlTemplate.replace(0, 8, "http://");
}
}

if (transformed.url.compare(0, 22, "http://localhost:2900/") == 0) {
transformed.url.replace(0, 22, "http://");

if (transformed.kind == Resource::Kind::Tile && transformed.tileData) {
transformed.tileData->urlTemplate.replace(0, 22, "http://");
}
}

return defaultResourceLoader->request(transformed, [=](Response response) {
if (transformed.loadingMethod == Resource::LoadingMethod::CacheOnly && response.noContent) {
if (transformed.kind == Resource::Kind::Tile && transformed.tileData) {
mbgl::Log::Info(
mbgl::Event::Database,
"Resource not found in cache: " + transformed.url + "(" + transformed.tileData->urlTemplate + ")");
} else {
mbgl::Log::Info(mbgl::Event::Database, "Resource not found in cache: " + transformed.url);
}
}

std::size_t size = response.data != nullptr ? response.data->size() : 0;
if (active) {
requestCount++;
transferredSize += size;
}
callback(response);
});
}

void ProxyFileSource::setResourceOptions(ResourceOptions options) {
resourceOptions = options;
}

ResourceOptions ProxyFileSource::getResourceOptions() {
return resourceOptions.clone();
}

void ProxyFileSource::setClientOptions(ClientOptions options) {
clientOptions = options;
}

ClientOptions ProxyFileSource::getClientOptions() {
return clientOptions.clone();
}

// static
void ProxyFileSource::setOffline(bool status) {
offline = status;
}

// static
void ProxyFileSource::setTrackingActive(bool active_) {
active = active_;
requestCount = 0;
transferredSize = 0;
}

// static
bool ProxyFileSource::isTrackingActive() {
return active;
}

// static
size_t ProxyFileSource::getRequestCount() {
return requestCount;
}

// static
size_t ProxyFileSource::getTransferredSize() {
return transferredSize;
}

} // namespace mbgl
59 changes: 59 additions & 0 deletions platform/ios/benchmark/file_source.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <mbgl/storage/file_source.hpp>

namespace mbgl {

class ClientOptions;
class ResourceOptions;

class ProxyFileSource : public FileSource {
public:
ProxyFileSource(std::shared_ptr<FileSource>, const ResourceOptions&, const ClientOptions&);
~ProxyFileSource();

std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
bool canRequest(const Resource&) const override { return true; }

/**
* @brief Flag to change the networking mode of the file source.
*/
static void setOffline(bool);

/**
* @brief Starts/stops metrics tracking.
*/
static void setTrackingActive(bool);

/**
* @brief Returns metrics tracking status.
*/
static bool isTrackingActive();

/**
* @brief Returns the total amount of requests.
*
* @return size_t
*/
static size_t getRequestCount();

/**
* @brief Returns the size of transferred data (in bytes).
*
* @return size_t
*/
static size_t getTransferredSize();

void setResourceOptions(ResourceOptions) override;
ResourceOptions getResourceOptions() override;

void setClientOptions(ClientOptions) override;
ClientOptions getClientOptions() override;

private:
std::shared_ptr<FileSource> defaultResourceLoader;
ResourceOptions resourceOptions;
ClientOptions clientOptions;
};

} // namespace mbgl
4 changes: 4 additions & 0 deletions render-test/manifest_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
continue;
}

/*if (testPath.path().string().find("text-max-width/zoom-and-property-function") == std::string::npos) {
continue;
}*/

if (testPath.path().filename() == "style.json") {
const auto defaultExpectationPath{std::move(mbgl::filesystem::path(testPath).remove_filename())};
const auto rootLength = manifest.testRootPath.length();
Expand Down
2 changes: 1 addition & 1 deletion render-test/metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct TestMetadata {
// error message: "Failed to find expectations for..., to prevent
// unit test error by missing metric.json, can turn on 'ignoreProbing'
// to prevent the unit test fail, and just verify the render result.
bool ignoreProbing = false;
bool ignoreProbing = true;

mbgl::Size size{512u, 512u};
float pixelRatio = 1.0f;
Expand Down
9 changes: 3 additions & 6 deletions src/mbgl/map/map_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,10 @@ void Map::Impl::onDidFinishRenderingFrame(RenderMode renderMode,
double frameRenderingTime) {
rendererFullyLoaded = renderMode == RenderMode::Full;

if (mode == MapMode::Continuous) {
observer.onDidFinishRenderingFrame({MapObserver::RenderMode(renderMode),
needsRepaint,
placemenChanged,
frameEncodingTime,
frameRenderingTime});
observer.onDidFinishRenderingFrame(
{MapObserver::RenderMode(renderMode), needsRepaint, placemenChanged, frameEncodingTime, frameRenderingTime});

if (mode == MapMode::Continuous) {
if (needsRepaint || transform.inTransition()) {
onUpdate();
} else if (rendererFullyLoaded) {
Expand Down