Implement ANativeWindow backed EGLSurface

RESOLVED WONTFIX

Status

()

defect
P2
normal
RESOLVED WONTFIX
7 years ago
5 years ago

People

(Reporter: joe, Assigned: sotaro)

Tracking

Trunk
ARM
Gonk (Firefox OS)
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(blocking-kilimanjaro:+, blocking-basecamp:-)

Details

(Whiteboard: [soft])

Attachments

(1 attachment, 17 obsolete attachments)

56.24 KB, patch
Details | Diff | Splinter Review
Once we support sharing textures between the compositor and WebGL, it should be relatively simple to extend that sharing to support gralloc for b2g (he said, waving his hands).
WebGL stuff is already on the GPU side of things. How does gralloc help us?
We can't do fast cross-process webgl without gralloc.  (Until we do GL proxying, anyway.)
(In reply to Chris Jones [:cjones] [:warhammer] from comment #2)
> We can't do fast cross-process webgl without gralloc.  (Until we do GL
> proxying, anyway.)

Why not?
How do you propose sharing the WebGL render target across processes?
Right, sorry. The extension I was thinking of doesn't exist yet.
I'm doing a refactoring of these backends. Are there any documents on how to create a PBuffer, GL texture, or GL renderbuffer backed by gralloc?
Depends on: 716859
OS: Mac OS X → Gonk
Hardware: x86 → ARM
The android source code! ;)

Not my area of expertise though.  You can get an EGLImage out of gralloc buffers, if that helps.
(In reply to Jeff Gilbert [:jgilbert] from comment #5)
> Right, sorry. The extension I was thinking of doesn't exist yet.
> I'm doing a refactoring of these backends. Are there any documents on how to
> create a PBuffer, GL texture, or GL renderbuffer backed by gralloc?

There's no documentation, but you can create an EGLImage from gralloc buffers, render into those, and then bind them as a texture on the other side.  That *should* work across processes.
blocking-basecamp: ? → +
Whiteboard: [soft]
the patch add support of gralloc-backed WebGL rendering. I confirm the rendering on my hardware(MSM8960). it has some problems need to address, but it could be a start.
This seems much more complicated than is needed for gralloc-based OMTC/inter-process pass-through.

It would seem to me that all we need is the (Content) CanvasLayer, when supplied with a gralloc buffer from the Compositor, is to build an EGLImage backed by the gralloc buffer, and copy from the GLContext backing surface to the gralloc EGLImage. (Similar to bug 728524)
I have often read in many places about "performance is very important in b2g". Then, I created attachment 643291 [details] [diff] [review]. In bug 728524, fCopyTexSubImage2D() is used to copy data, it could affect to the performance.

If we want to do cross-process webgl, multiple gralloc-ed buffers are necessary. From my understanding about android, there is no simple way to do multiple gralloc-buffered OpenGL rendering. Therefore data copy to gralloc-ed buffers becomes necessary.

But in android(gonk), ANativeWindow and eglWindowSurface provide this capability. They could provide multiple gralloc-buffered GL context. By using them, we do not need to call data-copy to gralloc-ed buffers.

IMHO, if we want to get best performance in cross-process webgl in b2g, we need to use ANativeWindow and eglWindowSurface. But their implementation provide complexities...
Performance is certainly important, but when performance impact is relatively negligable, it's preferable to go with the simpler solution. 

In the simple general cross-thread/process approach, double-buffering is sufficient. (for now) The way we do this for cross-threads is by copying from our GLContext's backing surface into the EGLImage, which writes to the compositor's surface directly. Currently, we use CopyTexSubImage, since we are concerned about the massive state save-restore required for drawing the texture to an EGLImage-backed framebuffer. (Even though drawing a textured quad appears to be faster than CopyTexSubImage, in general)

My understanding is that it should be simple to gralloc a buffer and attach it to an EGLImage-backed texture, and likewise content-side, attach an EGLImage to that same gralloc buffer, and just copy into it. This would seem relatively simple, and would get use the vast majority of the performance we need.

An 'easy' to use abstraction which does proper triple-buffering (when needed) is coming soon, but should only be a marginal win over our method here. (for any non-trivial webgl apps)
I agree, when performance impact is relatively negligable, we should use simpler solution.
How are we doing here?
Priority: -- → P2
The prereq work in bug 716859 is about ready to go up for review. This will be a 200 line patch on top of that.
Renom if you think we can't ship a v1 without this.
blocking-basecamp: + → ---
blocking-kilimanjaro: --- → +
Per IRC conversations with a few other folks, I think the best course of action if there is disagreement on whether this blocks or not is to do the following:

- Move the blocking-basecamp flag to ? for re-evaluation
- Indicate a rationale for why you disagree
blocking-basecamp: --- → ?
blocking-basecamp: ? → -
Summary: support gralloc-backed WebGL → Support ANativeWindow backed EGLSurface
From Bug 917444 and Bug 894847, I am going to rethink about this again.
This is a wip patch. Confirmed that the patch works on master hamachi.
Attachment #643291 - Attachment is obsolete: true
By applying the patch, crystalskull draws about 33 fps both HWComposer composition and OpenGL composition on master hamachi.
(In reply to Sotaro Ikeda [:sotaro] from comment #18)
> Created attachment 819267 [details] [diff] [review]
> WIP patch - Support ANativeWindow backed EGLSurface

attachment 819267 [details] [diff] [review] does not handle correctly the following case, a dead lock happen in GonkNativeWindowClient.
 - app go to background and go to foreground again.
attachment 819267 [details] [diff] [review] is [3]'s wip patch. Updated the patch for current master.
The following is a fps of crystalskull on master hamachi. Compare the fps of HwComposer composition and OpenGL composition. [3] got good fps on the both cases.
[1]
  - HwComposer : 32-33fps
  - OpenGL: 0fps(< 1 fps), a lot of frame drops?
[2]
  - HwComposer : 30-33fps
  - OpenGL:25-26fps
[3]
  - HwComposer : 32-33fps
  - OpenGL : 32-33fps
Sorry, [1], [2], [3] is the following.
[1] Do nothing about frame complete(current behavior)
[2] Ensure frame complete by reading one pixcel
[3] ANativeWindow backed EGLSurface
(In reply to Sotaro Ikeda [:sotaro] from comment #21)
> attachment 819267 [details] [diff] [review] is [3]'s wip patch. Updated the
> patch for current master.

It does not work on SkiaGL backed 2D canvas.
We just recently did cleanup in bug 814159... which remove backing surface and X-backed GL Context.

Can we expose some interface which would allow to build EGLSurface backed with X window, NativeSurface, or something else, instead ifdef-ing half of GLContext implementation?
attachment 819267 [details] [diff] [review] is just a prototype to show ANativwWindow backed EGLSurface working on b2g. I created a patch for next week's graphics work week in Paris. If I could get good feed back about it there, I am going to implement it more clean way. Comment 25 is also a good input.
(In reply to Oleg Romashin (:romaxa) from comment #25)
> Can we expose some interface which would allow to build EGLSurface backed
> with X window, NativeSurface, or something else, instead ifdef-ing half of
> GLContext implementation?

Sounds reasonable!
By the discussion in graphics work week in Paris, feed backs to the idea of using ANativeWindow backed EGLSurface were positive.
blocking-b2g: --- → 1.3?
Why not make GLSreenBuffer to inherit EGLNativeBase directly? use SurfaceTexture and SurfaceTextureClient introduce BinderIPC when deQ/Q. And why not update CreateConfig to enable EGL_SWAP_BEHAVIOUR_PRESERVED_BIT if needed, which is the default for 2D canvas.
And why not update fBindFramebuffer implementation? The FBO under GLScreenBuffer should be removed now, and fbo 0 means EGLSurface now.
Instead native_window_set_buffers_geometry, why not mWindowClient->perform?
(In reply to Chiajung Hung [:chiajung] from comment #29)
> Why not make GLSreenBuffer to inherit EGLNativeBase directly? use
> SurfaceTexture and SurfaceTextureClient introduce BinderIPC when deQ/Q. 

It does not use Binder IPC. enqueue/dequeue happens between GonkNativeWindowClient and GonkNativeWindow. It is just simple callback.
Intent of it's implementation is to run OpenGL as same as android one.
Assignee: nobody → sotaro.ikeda.g
My inital attemp to implement this is to make GLScreenBuffer inherit EGLNativeBase and hook dequeue to SwapConsumer, queue to SwapProducer. which runs same as Android as well but code path simpler and avoid to depend on android::SurfaceTexture at all.
blocking-b2g: 1.3? → koi?
Change to 1.3? again. Right now, there is not urgent necessity to uplift to 1.2.
blocking-b2g: koi? → 1.3?
Blocks: 925444
Bug 925444 requires proper handling of fence syncs which were introduced in Jellybean. In AOSP fence syncs are handled as a feature of SurfaceTexture [1] and GLConsumer [2].

Sotaro believes this can be addressed in this bug. If that is the case then this bug need to be blocking 1.3.

[1] https://www.codeaurora.org/cgit/quic/la/platform/frameworks/base/tree/core/jni/android/graphics/SurfaceTexture.cpp?h=jb_3.2#n79
[2] https://www.codeaurora.org/cgit/quic/la/platform/frameworks/native/tree/include/gui/GLConsumer.h?h=b2g_jb_3.2#n68
Blocks: 930299
Sotaro, is this still on target to get resolved for 1.3 FC, if so what is the eta of resolution here ? Given the activity not sue what the next steps are, can you please help outline them with progress ?
Flags: needinfo?(sotaro.ikeda.g)
I don't think this is blocking or needs to be tracked for 1.3.
(In reply to bhavana bajaj [:bajaj] (on vacation until 12/02/2013) from comment #37)
> Sotaro, is this still on target to get resolved for 1.3 FC, if so what is
> the eta of resolution here ? Given the activity not sue what the next steps
> are, can you please help outline them with progress ?

From Comment 37, this bug is not resolved for 1.3 FC. Next step is to update a patch for not to use a lot of ifdef. To to it, need some re-structure around SurfaceStream.
Flags: needinfo?(sotaro.ikeda.g)
No longer blocks: 925444
(In reply to Sotaro Ikeda [:sotaro] from comment #39)
> (In reply to bhavana bajaj [:bajaj] (on vacation until 12/02/2013) from
> comment #37)
> > Sotaro, is this still on target to get resolved for 1.3 FC, if so what is
> > the eta of resolution here ? Given the activity not sue what the next steps
> > are, can you please help outline them with progress ?
> 
> From Comment 37, this bug is not resolved for 1.3 FC. Next step is to update
> a patch for not to use a lot of ifdef. To to it, need some re-structure
> around SurfaceStream.

mvines - Can we remove this from the FxOS v1.3 FC blocking list?
Flags: needinfo?(mvines)
Ah, it was there only because it blocked bug 925444 but that is no longer the case
No longer blocks: 930299
blocking-b2g: 1.3? → ---
Flags: needinfo?(mvines)
Depends on: 988956
blocking-b2g: --- → 1.5?
Depends on: 988954
Depends on: 984434
No longer depends on: 988954
Status: NEW → ASSIGNED
By Bug 917444, WebGL performance was degraded on b2g. This bug could could solve the performance problem.
blocking-b2g: 2.0? → 2.0+
I change my mind. Bug 1001417 seems better way to enhance WebGL on b2g.
milan, how do you think about Comment 43? I changed the "blocking-b2g:" flag to "2.0?".
blocking-b2g: 2.0+ → 2.0?
Flags: needinfo?(milan)
Status: ASSIGNED → NEW
I definitely like the approach in bug 1001417.
blocking-b2g: 2.0? → ---
Flags: needinfo?(milan)
bug 1001417 is a way to go. Set this bus to INCOMPLETE.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INCOMPLETE
No longer depends on: 988956
Reopen this bug. I am going to compere performance to Bug 1001417.
Status: RESOLVED → REOPENED
Resolution: INCOMPLETE → ---
Depends on: 1001417
Summary: Support ANativeWindow backed EGLSurface → Evaluate ANativeWindow backed EGLSurface performance
Depends on: 1006957
Patch for gonk JB.
Attachment #819267 - Attachment is obsolete: true
Attachment #8428444 - Attachment is obsolete: true
This bug's way is faster than bug 1001417. But attachment 8428449 [details] [diff] [review] seems to have some problems. Some rendering objects are not rendered(missing).
I recognized that I forgot to add release fence handling correctly.
Add ICS support.
Attachment #8428449 - Attachment is obsolete: true
Add release fence handling. Still some specific items are not drawn. I am going to think that GLContextEGLGonkNativeWindow is missing some correct function overwrites.
Attachment #8428930 - Attachment is obsolete: true
At first fps is very high. But after that some how fps becomes lower.
(In reply to Sotaro Ikeda [:sotaro] from comment #54)
> At first fps is very high. But after that some how fps becomes lower.

This performance drop is not always happen. This problem might not be related to graphics.
(In reply to Sotaro Ikeda [:sotaro] from comment #53)
> Created attachment 8428948 [details] [diff] [review]
> WIP patch - Support ANativeWindow backed EGLSurface
> 
> Add release fence handling. Still some specific items are not drawn. I am
> going to think that GLContextEGLGonkNativeWindow is missing some correct
> function overwrites.

It became clear that the problem happened because z-buffer was missing.
Fix rendering problem. Still the patch break video playback.
Attachment #8428948 - Attachment is obsolete: true
(In reply to Sotaro Ikeda [:sotaro] from comment #57)
> Created attachment 8429549 [details] [diff] [review]
> WIP patch - Support ANativeWindow backed EGLSurface
> 
> Fix rendering problem. Still the patch break video playback.

The patch is based on Bug 1001417.
Summary: Evaluate ANativeWindow backed EGLSurface performance → Implement ANativeWindow backed EGLSurface
Fix crash problem in Youtue site.
Attachment #8429549 - Attachment is obsolete: true
Blocks: 1014011
Add KK support.
Attachment #8429708 - Attachment is obsolete: true
Add missing files.
Attachment #8430065 - Attachment is obsolete: true
No longer blocks: 1014011
Update EGLSurface configuration.
Attachment #8430084 - Attachment is obsolete: true
Add acquire fence handling to GonkNativeWindow.
Attachment #8430391 - Attachment is obsolete: true
Add "webgl.eglsurface.gonk-native-window" preference.
Attachment #8432737 - Attachment is obsolete: true
Update EGL config creation.
Attachment #8432759 - Attachment is obsolete: true
At first, I thought that it seems necessary to handle SurfaceStream's frame copy. But it seem to be used only 2DCanvas not on WebGL.


CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
{
// snip
  if (aLayer->mStream) {
    stream = aLayer->mStream;

    // Copy our current surface to the current producer surface in our stream, then
    // call SwapProducer to make a new buffer ready.
    stream->CopySurfaceToProducer(aLayer->mTextureSurface, aLayer->mFactory);
    stream->SwapProducer(aLayer->mFactory, gfx::IntSize(aSize.width, aSize.height));
  }

http://mxr.mozilla.org/mozilla-central/source/gfx/layers/client/CanvasClient.cpp
Fix build failures on other platforms.
Attachment #8432836 - Attachment is obsolete: true
Change ISurfaceAllocator's MessageLoop.
Attachment #8433416 - Attachment is obsolete: true
https://tbpl.mozilla.org/?tree=Try&rev=0db4d4a34dc5

On tryserver, some tests are failed.
Attachment #8433792 - Attachment is obsolete: true
Un-bitrot.
Attachment #8444010 - Attachment is obsolete: true
SurfaceStream's performance becomes almost same to this bug's patch. In this case, just use SurfaceStream is a good idea.
Status: REOPENED → RESOLVED
Closed: 5 years ago5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.