Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

HARP-15210: Wait for texture GPU upload on TileGeometryCreator. #2225

Merged
merged 2 commits into from
Jun 23, 2021

Conversation

atomicsulfate
Copy link
Collaborator

@atomicsulfate atomicsulfate commented Jun 22, 2021

Signed-off-by: Andres Mandado andres.mandado-almajano@here.com

TileGeometryCreator.createAllGeometries() returns now a promise that
is resolved when all textures in the tile are uploaded in GPU. This ensures that all textures are rendered on frame complete event.

@atomicsulfate atomicsulfate force-pushed the HARP-15210 branch 3 times, most recently from bfaf327 to 6fc8b84 Compare June 22, 2021 10:57
TileGeometryCreator.createAllGeometries() returns now a promise that
is resolved when all textures in the tile are uploaded in GPU.

Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

Merging #2225 (94b96d3) into master (81f8e59) will increase coverage by 0.13%.
The diff coverage is 98.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2225      +/-   ##
==========================================
+ Coverage   67.16%   67.29%   +0.13%     
==========================================
  Files         312      312              
  Lines       27680    27696      +16     
  Branches     6183     6184       +1     
==========================================
+ Hits        18590    18638      +48     
+ Misses       9090     9058      -32     
Impacted Files Coverage Δ
...e/harp-mapview/lib/geometry/TileGeometryCreator.ts 72.68% <93.75%> (+0.93%) ⬆️
@here/harp-mapview/lib/DecodedTileHelpers.ts 71.34% <100.00%> (+5.05%) ⬆️
...re/harp-mapview/lib/geometry/TileGeometryLoader.ts 85.92% <100.00%> (ø)
@here/harp-mapview/lib/MapMaterialAdapter.ts 92.85% <0.00%> (+0.71%) ⬆️
@here/harp-mapview/lib/text/TextElementBuilder.ts 100.00% <0.00%> (+1.05%) ⬆️
@here/harp-mapview/lib/ThemeHelpers.ts 18.39% <0.00%> (+11.49%) ⬆️
@here/harp-utils/lib/Logger/ConsoleChannel.ts 69.23% <0.00%> (+15.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81f8e59...94b96d3. Read the comment docs.

}
this.finish();
tile.dataSource.requestUpdate();
geometryCreator.createAllGeometries(tile, decodedTile).then(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is nicer to mark the function createGeometry as async (from a documentation point of view). The added benefit is that you can await here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*/
createAllGeometries(tile: Tile, decodedTile: DecodedTile) {
createAllGeometries(tile: Tile, decodedTile: DecodedTile): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can (but don't strictly have to), mark this async, I think from a documentation POV, it is nice.

Copy link
Collaborator Author

@atomicsulfate atomicsulfate Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean.

  1. If you mean I should just add "async" in front of the method without any further changes, that would actually be misleading from the documentation POV. The method is fully synchronous, ESLint would complain about the missing "async" otherwise.
  2. If you mean rewrite it to make it asynchronous, we could do it by changing at the very end return texturesReady; to await texturesReady;. But I don't see any benefit in that. Since this is a public method, better leave the decision to the calling code. Async callers may await on the promise, sync callers can work with the promise.

Awaiting on every single texture promise is not an option either, cause the promises are generated sequentially, that would make the texture loading sequential.

Copy link
Member

@nzjony nzjony Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atomicsulfate , I mean option 1.

Technically the function is synchronous, yes, but it returns a Promise, so the result isn't fully known when the function returns. You can argue that the function returns without any need to wait, but users of this are going to likely anyway await/.then() on the result of this function, so they won't know if it was synchronous or not, they will just use the result.

The docs on Mozilla.org also mention:

Async functions can contain zero or more await expressions.

Another benefit to using async is that any error thrown will cause the promise to reject, so users of the API can use .catch and react accordingly. Otherwise they need to wrap this function in a try/catch block, see: https://stackoverflow.com/questions/45594596/async-function-without-await-in-javascript#comment87236078_45594870

// Check that texture promised is not yet resolved.
let textureLoaded = false;
const texturePromise = callbackSpy.firstCall.args[0];
texturePromise.then(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this works because of the await wait below, but to be safe, you should await here too...? Or put the rest of the test in the .then() ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait... not here, that would break the test, but before await wait ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, fixed similar cases in other tests as well.

Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
@atomicsulfate atomicsulfate merged commit 8d70961 into master Jun 23, 2021
@atomicsulfate atomicsulfate deleted the HARP-15210 branch June 23, 2021 15:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants