-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Framebuffer refactor #5793
Framebuffer refactor #5793
Conversation
17d1dc0
to
a541fae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good direction here. Aside from a few places the type annotations could be improved, the main thing I'm wondering about is whether we can make the ownership conventions clearer. Can the the Framebuffer
itself own the attachments and be responsible for releasing them in a Framebuffer#destroy
method comparable to Texture#destroy
and VertexArrayObject#destroy
? Or does the need for shared attachments prevent that?
src/gl/value.js
Outdated
|
||
constructor(context: Context) { | ||
constructor(context: Context, parent: ?any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding an any
-typed parameter and member in the base class, override the constructor in ColorAttachment
and DepthAttachment
.
src/source/tile.js
Outdated
@@ -87,6 +87,7 @@ class Tile { | |||
needsHillshadePrepare: ?boolean | |||
request: any; | |||
texture: any; | |||
fbo: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fbo: Framebuffer
Note that the test updated in 3577b7c changed because it had been incorrectly overdrawing before: |
@lbud the heatmap drawing changes look great to me! |
3577b7c
to
880b481
Compare
Yes, good idea — addressed this in 470e764. Per the WebGL spec, "If the renderbuffer has already been deleted the call has no effect," so shared renderbuffer attachments won't cause a problem (confirmed on a debug map). |
src/style/style_layer.js
Outdated
return false; | ||
} | ||
|
||
resize(gl: WebGLRenderingContext) { // eslint-disable-line | ||
resize() { // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint-disable-line
was probably for the unused parameter and can be removed too.
src/render/draw_fill_extrusion.js
Outdated
@@ -20,9 +21,11 @@ function draw(painter: Painter, source: SourceCache, layer: FillExtrusionStyleLa | |||
return; | |||
} | |||
|
|||
if (painter.renderPass === '3d') { | |||
if (painter.renderPass === 'offscreen') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One rule of thumb that I try to follow is that if you have a series of conditionals, it's good for comprehensibility if you can make the bodies of each branch parallel in form (same principle as parallelism in grammar). Here, for instance, I would rename setupFramebuffer
to drawExtrusionFramebuffer
and move the code just above and below the call into the function, so that the two branch bodes are both a single drawExtrusion*(...)
expression.
src/style/style_layer.js
Outdated
@@ -42,7 +42,7 @@ class StyleLayer extends Evented { | |||
_transitioningPaint: Transitioning<any>; | |||
+paint: mixed; | |||
|
|||
viewportFrame: ?RenderTexture; | |||
viewportFrame: ?Framebuffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this declaration be pushed down hierarchy, into FillExtrusionStyleLayer
?
src/source/raster_dem_tile_source.js
Outdated
@@ -116,6 +116,10 @@ class RasterDEMTileSource extends RasterTileSource implements Source { | |||
|
|||
unloadTile(tile: Tile) { | |||
if (tile.demTexture) this.map.painter.saveTileTexture(tile.demTexture); | |||
if (tile.fbo) { | |||
this.map.painter.saveTileFramebuffer(tile.fbo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much of a performance difference does caching framebuffers make? If it's not too big a difference, I think it would be good to keep things simple and create a fresh framebuffer for each new DEM tile.
…have framebuffers destroy their own attachments
6a2216c
to
3a5a0aa
Compare
@lbud are you planning to do a similar refactor (consolidating offscreen rendering into an "offscreen" pass) on the gl-native side? |
@mourner we should use the same process (an offscreen pass to render to all offscreen framebuffers) on native. I haven't yet started something like this there, although at the moment fill-extrusion layers are the only offscreen layer type on master, so if I were to do so right now it would just be a minor refactor (moving extrusion depth buffer setup into render_fill_extrusion.cpp and renaming "3d" to "offscreen"). I know you and @mollymerp have heatmap/hillshade branches in progress — not sure how far along you are; if it's convenient for you to render those in the 3d pass feel free to make those changes, but if not it shouldn't be a big deal to refactor afterward as we did in gl-js. |
Primary changes:
fill-extrusion
,heatmap
,hillshade
) into oneoffscreen
pass (fixes Render to heatmap framebuffer in separate pass #5803)Context
responsible for all framebuffer + renderbuffer creationFramebuffer
class, responsible for managing its color and/or depth attachment states, retaining size info, and cleaning up its attachments withgl.delete*
calls when destroyedRenderTexture
classMinor changes:
Caches tile-sized framebuffers on the painter when unloaded (fromhillshade
layers) for reuse in new loaded hillshade tilesheatmap-radius/antimeridian
render test (Framebuffer refactor #5793 (comment))Benchmark results: https://bl.ocks.org/anonymous/raw/3d9a8aa509b5dc8d0c1d97c6e5f6110f/
Refs #145.