Closed
Bug 1325911
Opened 8 years ago
Closed 8 years ago
Support dynamic GL Context type selection with webrender.
Categories
(Core :: Graphics: WebRender, defect)
Core
Graphics: WebRender
Tracking
()
RESOLVED
FIXED
mozilla55
Tracking | Status | |
---|---|---|
firefox55 | --- | fixed |
People
(Reporter: sotaro, Assigned: sotaro)
References
Details
Attachments
(2 files, 20 obsolete files)
291.80 KB,
patch
|
Details | Diff | Splinter Review | |
8.34 KB,
patch
|
sotaro
:
review+
|
Details | Diff | Splinter Review |
Current gleam and webrender does not support dynamic GL Context type selection.
Assignee | ||
Updated•8 years ago
|
Assignee | ||
Updated•8 years ago
|
See Also: → https://github.com/servo/gleam/issues/99
Assignee | ||
Updated•8 years ago
|
Assignee: nobody → sotaro.ikeda.g
Assignee | ||
Comment 1•8 years ago
|
||
webrender depends on offscreen_gl_context. offscreen_gl_context also uses gleam. gecko does not use offscreen_gl_context, therefore we do not have a necessity to add "dynamic GL Context type selection" to offscreen_gl_context. Instread, it seems better if webrender has a capability to remove offscreen_gl_context.
Assignee | ||
Comment 2•8 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #1)
> webrender depends on offscreen_gl_context. offscreen_gl_context also uses
> gleam. gecko does not use offscreen_gl_context, therefore we do not have a
> necessity to add "dynamic GL Context type selection" to
> offscreen_gl_context. Instread, it seems better if webrender has a
> capability to remove offscreen_gl_context.
Hmm, it seems simpler to keep offscreen_gl_context.
Assignee | ||
Comment 3•8 years ago
|
||
It seems like it would be worth it to modify the generator to auto-generate the Rust wrappers too, with some simple rules for changing names etc. (The functions where we actually modify the signature etc. should still be hand-written.)
Comment 5•8 years ago
|
||
We tried to hack it here with Glenn and got it running with RenderDoc capturing successfully. For some reason, the coordinate space is flipped at Y, even though Angle should take care of that.
We didn't switch from the global gl generator to the struct one. I agree that the struct may be more idiomatic and even beneficial in the long term, but I'm not sure if it's worth converting everything for Angle (in the scope of this bug), since this is certainly not required.
Our approach would just need the Android path of both Gleam and WebRender to be converted to a compile-time feature, plus a few platform-independent shader bugs that we'll do regardless.
Assignee | ||
Comment 6•8 years ago
|
||
:kvark your approach seems enough for this bug. But the patch showed garbled characters, can you update the patch again?
Flags: needinfo?(kvark)
Comment 7•8 years ago
|
||
Comment on attachment 8828116 [details]
Angle patches WIP (ZIP archive)
Oh, sorry about that! I'm still figuring out the proper way to work with BugZilla. The patch is a ZIP having separate patches for glutin-0.7.2, gleam-0.2.30, and WR).
Attachment #8828116 -
Attachment description: Angle patches WIP → Angle patches WIP (ZIP archive)
Attachment #8828116 -
Attachment is patch: false
Flags: needinfo?(kvark)
Comment 8•8 years ago
|
||
Relevant (newly created) Github issues:
https://github.com/servo/gleam/issues/103
https://github.com/servo/webrender/issues/747
Assignee | ||
Comment 9•8 years ago
|
||
Thanks! attachment 8828116 [details] changes GL type by feature. It decides the GL type during build time. I thought that for quantum, it is nice if we could change gl type dynamically. Then created this bug. StructGenerator is used since it seems to fit to the situation of dynamic Gl type selection.
Assignee | ||
Comment 10•8 years ago
|
||
With the patch, gecko graphic branch could choose Choose ANGLE GLES or normal GL based on pref.
Attachment #8827348 -
Attachment is obsolete: true
Assignee | ||
Comment 11•8 years ago
|
||
I prefer runtime gl type selection. Other guys might prefer static gl type selection for simplicity.
Comment 12•8 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #10)
> Created attachment 8828250 [details] [diff] [review]
> wip patch - Choose ANGLE GLES or normal GL based on pref
>
> With the patch, gecko graphic branch could choose Choose ANGLE GLES or
> normal GL based on pref.
Is disabling the GPU process necessary? I don't want to regress that because it will mean all windows (even non-webrender windows) get forced into the UI process in QR builds.
Assignee | ||
Comment 13•8 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #12)
>
> Is disabling the GPU process necessary? I don't want to regress that because
> it will mean all windows (even non-webrender windows) get forced into the UI
> process in QR builds.
It is not intrinsic to the bug. But without it caused the crash during starting firefox. I suspect that I is a problem around GLContextProviderEGL. I did not look into it yet. Similar problem for native windows GL context was addressed recently by other bug.
Comment 14•8 years ago
|
||
Ah, I see. Randall has patches in bug 1329362 for GLContextProviderEGL, but I'm not sure if they only get it working for Android, or if it works for Windows as well. Might be worth taking a look.
Comment 15•8 years ago
|
||
Sotaro,
I agree that run-time selection is better for the end game. Please provide the corresponding PRs into WR/gleam.
Assignee | ||
Comment 16•8 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #14)
> Ah, I see. Randall has patches in bug 1329362 for GLContextProviderEGL, but
> I'm not sure if they only get it working for Android, or if it works for
> Windows as well. Might be worth taking a look.
We needs bug 1329362 also for windows ANGLE. GLContextProviderEGL::CreateForCompositorWidget() requests RealWidget(), it returns nulptr when GPU process is enabled.
https://dxr.mozilla.org/mozilla-central/source/gfx/gl/GLContextProviderEGL.cpp#713
Assignee | ||
Comment 17•8 years ago
|
||
(In reply to Dzmitry Malyshau [:kvark] from comment #15)
> Sotaro,
> I agree that run-time selection is better for the end game. Please provide
> the corresponding PRs into WR/gleam.
Thanks. I am going to create PRs.
Assignee | ||
Comment 18•8 years ago
|
||
Assignee | ||
Comment 19•8 years ago
|
||
attachment 8828744 [details] [diff] [review], by using gl::gl_type(), target cgfs were reduced.
Assignee | ||
Comment 20•8 years ago
|
||
Created issue of adding gl type detection function.
https://github.com/servo/gleam/issues/104
Assignee | ||
Updated•8 years ago
|
Attachment #8828744 -
Attachment is obsolete: true
Assignee | ||
Comment 21•8 years ago
|
||
Created a pull request just for discussion.
https://github.com/servo/gleam/pull/106
Assignee | ||
Comment 22•8 years ago
|
||
Attachment #8828250 -
Attachment is obsolete: true
Assignee | ||
Comment 23•8 years ago
|
||
Attachment #8835233 -
Attachment is obsolete: true
Assignee | ||
Comment 24•8 years ago
|
||
Assignee | ||
Comment 25•8 years ago
|
||
With attachment 8836227 [details] [diff] [review] and https://github.com/servo/gleam/pull/106/files, offscreen_gl_context build was failed with the following error log. Compiler's help message did not work: -(
0:01.81 error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
0:01.81 --> /home/sotaro/quantum_gfx_src_8/graphics/third_party/rust/offscreen_gl_context/src/gl_context.rs:200:70
0:01.81 |
0:01.81 200 | self.draw_buffer = Some(try!(DrawBuffer::new(&self, self.gl_.as_ref(), size, color_attachment_type)));
0:01.81 | ^^^^^^
0:01.81 |
0:01.81 help: consider using an explicit lifetime parameter as shown: fn create_draw_buffer(&'a mut self, size: Size2D<i32>,
0:01.81 color_attachment_type: ColorAttachmentType)
0:01.81 -> Result<(), &'static str>
0:01.81 --> /home/sotaro/quantum_gfx_src_8/graphics/third_party/rust/offscreen_gl_context/src/gl_context.rs:199:5
0:01.81 |
0:01.81 199 | fn create_draw_buffer(&mut self, size: Size2D<i32>, color_attachment_type: ColorAttachmentType) -> Result<(), &'static str> {
0:01.81 | _____^ starting here...
0:01.81 200 | | self.draw_buffer = Some(try!(DrawBuffer::new(&self, self.gl_.as_ref(), size, color_attachment_type)));
0:01.81 201 | | Ok(())
0:01.81 202 | | }
0:01.81 | |_____^ ...ending here
0:01.81
0:01.83 error: aborting due to previous error
Assignee | ||
Comment 26•8 years ago
|
||
:emilio, can you give me an advice about how to address the build failure in Comment 25? Thanks!
Flags: needinfo?(emilio+bugs)
Assignee | ||
Comment 27•8 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #26)
> :emilio, can you give me an advice about how to address the build failure in
> Comment 25? Thanks!
attachment 8836017 [details] [diff] [review] uses Rc to share ref to Gl. But if Rc is not used, I am not sure how to address the compile failure.
Comment 28•8 years ago
|
||
So the thing why it doesn't work is because even though our usage is fine (because GLContext::gl_ is effectively immutable), you can't have a reference to it while the owner has a Box, because theoretically, the owner (GLContext in this case) may mutate it while the buffer is reading.
The way to do it is either refcount it, or use a bit of unsafety. Given the context completely own both the struct and the buffer, I think it's justified to use a bit of unsafety here, I'll prepare a patch.
Flags: needinfo?(emilio+bugs)
Comment 29•8 years ago
|
||
Assignee | ||
Comment 30•8 years ago
|
||
:emilio, thanks so much! Which do you prefer to use in webrender? refcount it, or use a bit of unsafety?
I tend to prefer refcount way because of safety. If gleam usage is only for offscreen_gl_context, a bit of unsafety seems ok. But gleam is used also for webrender.
Flags: needinfo?(emilio+bugs)
Comment 31•8 years ago
|
||
For unsafety, I meant just the raw pointer bits I added with a bunch of comments in https://github.com/emilio/rust-offscreen-rendering-context/pull/81. Gleam shouldn't change anything.
In that case it's fine because the vtable is immutable, and the buffer never outlives the context.
I don't think that's related to WR at all though, does WR suffer from similar lifetime issues as offscreen_gl_context?
Seems like in WR the context can live in the Device fairly easily as a Box?
Flags: needinfo?(emilio+bugs) → needinfo?(sotaro.ikeda.g)
Assignee | ||
Comment 32•8 years ago
|
||
(In reply to Emilio Cobos Álvarez [:emilio] from comment #31)
> For unsafety, I meant just the raw pointer bits I added with a bunch of
> comments in
> https://github.com/emilio/rust-offscreen-rendering-context/pull/81. Gleam
> shouldn't change anything.
>
> In that case it's fine because the vtable is immutable, and the buffer never
> outlives the context.
>
> I don't think that's related to WR at all though, does WR suffer from
> similar lifetime issues as offscreen_gl_context?
Yes, I think so. There a lot of patterns that object needs to hold ref to Gl like DrawBuffer.
>
>
> Seems like in WR the context can live in the Device fairly easily as a Box?
When I tried, I faced a lot of build errors :-(
Flags: needinfo?(sotaro.ikeda.g)
Assignee | ||
Comment 33•8 years ago
|
||
Assignee | ||
Comment 34•8 years ago
|
||
With attachment 8836696 [details] [diff] [review], I faced the following lifetime related errors, it is caused by same reason as offscreen_gl_context case.
-----------------------------------------------------------------
0:02.26 error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
0:02.26 --> /home/sotaro/quantum_gfx_src_8/graphics/gfx/webrender/src/device.rs:688:17
0:02.26 |
0:02.26 688 | GpuMarker {
0:02.26 | ^^^^^^^^^
0:02.26
0:02.26 error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
0:02.26 --> /home/sotaro/quantum_gfx_src_8/graphics/gfx/webrender/src/device.rs:693:17
0:02.26 |
0:02.26 693 | GpuMarker {
0:02.26 | ^^^^^^^^^
0:02.26
0:02.28 error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
0:02.28 --> /home/sotaro/quantum_gfx_src_8/graphics/gfx/webrender/src/device.rs:1066:31
0:02.28 |
0:02.28 1066 | gl_: self.gl_.as_ref(),
0:02.28 | ^^^^^^
0:02.28
0:02.30 error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
0:02.30 --> /home/sotaro/quantum_gfx_src_8/graphics/gfx/webrender/src/device.rs:1398:27
0:02.30 |
0:02.30 1398 | gl_: self.gl_.as_ref(),
0:02.30 | ^^^^^^
0:02.30
0:02.32 error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
0:02.32 --> /home/sotaro/quantum_gfx_src_8/graphics/gfx/webrender/src/device.rs:1737:27
0:02.32 |
0:02.32 1737 | gl_: self.gl_.as_ref(),
0:02.32 | ^^^^^^
0:02.32
0:02.49 libmedia_libogg.a.desc
0:03.29 error: aborting due to 5 previous errors
0:03.29
0:03.30 error: Could not compile `webrender`.
Assignee | ||
Comment 35•8 years ago
|
||
By Comment 34, I tend to prefer using Rc.
Comment 36•8 years ago
|
||
Wait a second, since I think Rc is going to be quite a pain to use in offscreen_gl_context. Let me try to find a better solution.
Comment 37•8 years ago
|
||
(Not to use _in_ offscreen_gl_context itself, but to use by the consumers. Not totally sure yet.
Comment 38•8 years ago
|
||
I can't apply that patch to current webrender trunk (with the paths adjusted), but from comment 34 I believe most of the errors if not all are due to GpuMarker, right?
If so, I think you could make something like:
GpuMarker::with("foo", self, |device| {
})
work, which would be something like (simplified):
pub fn with<R, F>(name: &str, device: &mut Device, f: F) -> R
where F: FnOnce(&mut Device) -> R,
{
device.gl().push_marker();
let ret = f(device);
device.gl().pop_marker();
ret
}
Though I don't know what would kvark or gw.
Even if your patch worked (which can be made to work taking the reference to the functions directly), I believe you'd have borrow checker errors due to having a reference to the functions in the marker (which would prevent you from mutating the rest of the device).
Given the GpuMarkers are objects on the stack, I believe it's not such a big deal for them to contain a raw pointer, but if you think that it is and want to refcount the functions that's fine, I'll manage to get the other stuff working on my side with Rc :)
Assignee | ||
Comment 39•8 years ago
|
||
(In reply to Emilio Cobos Álvarez [:emilio] from comment #38)
> I can't apply that patch to current webrender trunk (with the paths
> adjusted),
Sorry, I am working on graphics branch.
> but from comment 34 I believe most of the errors if not all are
> due to GpuMarker, right?
The pasted log shows erros around GpuMarker, but GpuProfiler, GpuFrameProfile, GpuProfiler, GpuMarker, Texture, Program and VAO has lifetime problem because of referring Box.
Assignee | ||
Comment 40•8 years ago
|
||
The following seems to related to comment #28, since Box holds raw pointer.
https://doc.rust-lang.org/nomicon/references.html#aliasing
------------------------------------
In addition to references, Rust has raw pointers: *const T and *mut T. Raw pointers have no inherent ownership or aliasing semantics. As a result, Rust makes absolutely no effort to track that they are used correctly, and they are wildly unsafe.
Assignee | ||
Comment 41•8 years ago
|
||
:kvark, can you comment to https://github.com/servo/gleam/pull/106? And can you give me a code snip about how to use GlTyped? I am still not sure how to use GlTyped extension trait from Gl trait, since client only own Gl trait object.
> No. My proposal to have GlTyped extension trait assumed that any clients that work with the trait object would only use Gl, while the clients working with it generically will have the convenience of GlTyped.
Flags: needinfo?(kvark)
Assignee | ||
Comment 42•8 years ago
|
||
(In reply to Sotaro Ikeda [:sotaro] from comment #41)
> :kvark, can you comment to https://github.com/servo/gleam/pull/106? And can
> you give me a code snip about how to use GlTyped? I am still not sure how to
> use GlTyped extension trait from Gl trait, since client only own Gl trait
> object.
At first, I thought to use ufcs.
> https://doc.rust-lang.org/book/ufcs.html
But the following code caused error"the trait `gleam::gl::GlTyped` is not implemented for `gleam::gl".
> gl::GlTyped::buffer_data(ctx.get_gl().as_ref(), buffer_type, &data, usage)
Comment 43•8 years ago
|
||
Sotaro, you can't downcast `Gl` to `GlTyped`. So when I suggested `GlTyped` extension I thought that the clients would use it generically when they can, and just use `Gl` when they have to have a trait object. It very much depends on how you are using it, so you probably see better what works and what does not.
I commented on the gleam PR, please let me know if there is anything else pending!
Flags: needinfo?(kvark)
Assignee | ||
Comment 44•8 years ago
|
||
:kvark, I updated a patch of https://github.com/servo/gleam/pull/106. Can you review it again?
Flags: needinfo?(kvark)
Assignee | ||
Updated•8 years ago
|
Flags: needinfo?(kvark)
Assignee | ||
Comment 45•8 years ago
|
||
Assignee | ||
Comment 46•8 years ago
|
||
Assignee | ||
Comment 47•8 years ago
|
||
Attachment #8836696 -
Attachment is obsolete: true
Assignee | ||
Updated•8 years ago
|
Attachment #8836227 -
Attachment is obsolete: true
Assignee | ||
Comment 48•8 years ago
|
||
Attachment #8841859 -
Attachment is obsolete: true
Assignee | ||
Comment 49•8 years ago
|
||
Attachment #8842247 -
Attachment is obsolete: true
Assignee | ||
Updated•8 years ago
|
Attachment #8842304 -
Attachment description: tmp patch - webrender → wip patch - webrender
Assignee | ||
Updated•8 years ago
|
See Also: → https://github.com/servo/webrender/issues/771
Assignee | ||
Comment 50•8 years ago
|
||
Attachment #8842304 -
Attachment is obsolete: true
Assignee | ||
Comment 51•8 years ago
|
||
Attachment #8844296 -
Attachment is obsolete: true
Assignee | ||
Updated•8 years ago
|
Attachment #8836017 -
Attachment is obsolete: true
Assignee | ||
Updated•8 years ago
|
See Also: → https://github.com/servo/webrender/pull/965
Assignee | ||
Comment 52•8 years ago
|
||
Assignee | ||
Updated•8 years ago
|
Attachment #8828116 -
Attachment is obsolete: true
Assignee | ||
Comment 53•8 years ago
|
||
Attachment #8844306 -
Attachment is obsolete: true
Assignee | ||
Comment 54•8 years ago
|
||
The patch expects https://github.com/servo/webrender/pull/965 and ./mach vendor rust.
Assignee | ||
Updated•8 years ago
|
Attachment #8844814 -
Flags: review?(bugmail)
Assignee | ||
Comment 55•8 years ago
|
||
Update nits.
Attachment #8844814 -
Attachment is obsolete: true
Attachment #8844814 -
Flags: review?(bugmail)
Assignee | ||
Updated•8 years ago
|
Attachment #8844816 -
Flags: review?(bugmail)
Comment 56•8 years ago
|
||
Comment on attachment 8844816 [details] [diff] [review]
patch for gecko
Review of attachment 8844816 [details] [diff] [review]:
-----------------------------------------------------------------
LGTM. When we pull the next WR update with your PR I'll make sure to include this patch.
Attachment #8844816 -
Flags: review?(bugmail) → review+
Assignee | ||
Comment 57•8 years ago
|
||
Rebased.
Attachment #8844816 -
Attachment is obsolete: true
Attachment #8846461 -
Flags: review+
Assignee | ||
Updated•8 years ago
|
Attachment #8844813 -
Attachment is obsolete: true
Assignee | ||
Comment 58•8 years ago
|
||
Attachment #8844812 -
Attachment is obsolete: true
Assignee | ||
Comment 59•8 years ago
|
||
Rebased.
Attachment #8846461 -
Attachment is obsolete: true
Attachment #8846990 -
Flags: review+
Assignee | ||
Comment 60•8 years ago
|
||
Attachment #8846990 -
Attachment is obsolete: true
Attachment #8847448 -
Flags: review+
Assignee | ||
Comment 61•8 years ago
|
||
Attachment #8847448 -
Attachment is obsolete: true
Assignee | ||
Updated•8 years ago
|
Attachment #8847449 -
Flags: review+
Comment 62•8 years ago
|
||
Is it ok if I land the gecko patch to bump the gleam version, along with a WR update? Or do you want me to wait until you have the whole angle change ready?
Assignee | ||
Comment 63•8 years ago
|
||
It is OK to land the gecko patch:)
Comment 64•8 years ago
|
||
Pushed by kgupta@mozilla.com:
https://hg.mozilla.org/projects/graphics/rev/5974b444127a
Update Gleam to v0.4. r=kats
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Comment 65•8 years ago
|
||
status-firefox55:
--- → fixed
Target Milestone: --- → mozilla55
You need to log in
before you can comment on or make changes to this bug.
Description
•