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

Use an intermediate renderbuffer when blitting between texture arrays… #3327

Closed
wants to merge 1 commit into from

Conversation

@jamienicol
Copy link
Contributor

jamienicol commented Nov 19, 2018

… on adreno devices

When the texture cache is grown we allocate a larger texture array
then copy each layer of the old array in to the new one. To perform
this copy we use use glBlitFramebuffer, with the read and draw
framebuffers bound to the correct layer in the old and new textures.

Unfortunately on Adreno devices this does not work. glBlitFramebuffer
always writes to the 0th layer of the texture bound to the draw
framebuffer. glCopyTexSubImage3D also does not work correctly - it
always reads from the 0th layer of the texture bound to the read
framebuffer.

As a workaround, we use glBlitFramebuffer to blit from the old texture
in to a temporary renderbuffer, then use glCopyTexSubImage3D to copy
from that renderbuffer to the new texture.


This change is Reviewable

@leeoniya
Copy link

leeoniya commented Nov 19, 2018

@gw3583
Copy link
Collaborator

gw3583 commented Nov 20, 2018

@leeoniya Yep, definitely.

@gw3583
Copy link
Collaborator

gw3583 commented Nov 20, 2018

Compile errors on CI (I didn't check the platforms / features causing it):

error[E0609]: no field `width` on type `&device::gl::Texture`
    --> webrender\src\device\gl.rs:1641:46
     |
1641 |                                          src.width as _, src.height as _);
     |                                              ^^^^^
error[E0609]: no field `height` on type `&device::gl::Texture`
    --> webrender\src\device\gl.rs:1641:62
     |
1641 |                                          src.width as _, src.height as _);
     |                                                              ^^^^^^
error[E0609]: no field `width` on type `&device::gl::Texture`
    --> webrender\src\device\gl.rs:1668:57
     |
1668 |                                               0, 0, src.width as _, src.height as _);
     |                                                         ^^^^^
error[E0609]: no field `height` on type `&device::gl::Texture`
    --> webrender\src\device\gl.rs:1668:73
     |
1668 |                                               0, 0, src.width as _, src.height as _);
     |                                                                         ^^^^^^
error[E0609]: no field `0` on type `&_`
    --> webrender\src\device\gl.rs:1673:48
     |
1673 |             self.gl.delete_renderbuffers(&[rbo.0]);
     |                                                ^
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0609`.
error: Could not compile `webrender`.
Caused by:

@jamienicol
Copy link
Contributor Author

jamienicol commented Nov 20, 2018

Texture.width/height got changed to Texture.size recently, but that hadn't made it to gecko yet.

… on adreno devices

When the texture cache is grown we allocate a larger texture array
then copy each layer of the old array in to the new one. To perform
this copy we use use glBlitFramebuffer, with the read and draw
framebuffers bound to the correct layer in the old and new textures.

Unfortunately on Adreno devices this does not work. glBlitFramebuffer
always writes to the 0th layer of the texture bound to the draw
framebuffer. glCopyTexSubImage3D also does not work correctly - it
always reads from the 0th layer of the texture bound to the read
framebuffer.

As a workaround, we use glBlitFramebuffer to blit from the old texture
in to a temporary renderbuffer, then use glCopyTexSubImage3D to copy
from that renderbuffer to the new texture.
@jamienicol jamienicol force-pushed the jamienicol:blitframebuffers-adreno branch from 5be55f7 to 5b8be07 Nov 20, 2018
@jamienicol
Copy link
Contributor Author

jamienicol commented Nov 20, 2018

I have updated the wiki page to include this bug

let rbo = RBOId(self.gl.gen_renderbuffers(1)[0]);
let fbo = FBOId(self.gl.gen_framebuffers(1)[0]);
self.gl.bind_renderbuffer(gl::RENDERBUFFER, rbo.0);
self.gl.renderbuffer_storage(gl::RENDERBUFFER, gl::RGBA8,

This comment has been minimized.

@kvark

kvark Nov 20, 2018

Member

how are we sure gl::RGBA8 is compatible with whatever texture we are blitting?

self.bind_read_target_impl(*read_fbo);
self.bind_draw_target_impl(*draw_fbo);
self.bind_draw_target_impl(match &temp_buffer {

This comment has been minimized.

@kvark

kvark Nov 20, 2018

Member

nit: remove &

self.blit_render_target(rect, rect);

// Copy from the intermediate buffer to the dst texture if necessary
if let Some((_, fbo)) = &temp_buffer {

This comment has been minimized.

@kvark

kvark Nov 20, 2018

Member

here and below: when matching we don't need the reference, instead we can avoid the fields moved out by marking them as Some((_, ref fbo)). IIRC, recent Rust inserts some of those ref automatically, but I'm not a big fan of that

if let Some((_, fbo)) = &temp_buffer {
self.bind_read_target_impl(*fbo);
self.bind_texture(DEFAULT_TEXTURE, dst);
self.gl.copy_tex_sub_image_3d(dst.target, 0, 0, 0, i as _,

This comment has been minimized.

@kvark

kvark Nov 20, 2018

Member

note that we have 2 bugs here covered by the same flag: inability to blit to layer != 0 and inability to copy from layer != 0. The flag name itself only reflects the first bug, which is a bit unclear.

@staktrace
Copy link
Contributor

staktrace commented Nov 20, 2018

For posterity: this patch fixes the issues on my Xperia XZ1 Compact (which has an Adreno 540) but doesn't fix the problems on my Xperia Z3 Compact (which has an Adreno 330).

@kvark
Copy link
Member

kvark commented Nov 20, 2018

@staktrace do we know what other issues Adreno 330 has in addition to these?

@staktrace
Copy link
Contributor

staktrace commented Nov 20, 2018

It's a little hard to tell which of the visible artifacts are caused by this issue and which are caused by other issues. Certainly fixing this issue on Adreno 540 results in much better behaviour, so either all the visible artifacts on the 330 are caused by this problem, or there's multiple problems that only affect the 330. I don't have a good sense for how likely that is.

@Manishearth
Copy link
Member

Manishearth commented Nov 21, 2018

servo/servo#22232 is also fixed by this

@Manishearth
Copy link
Member

Manishearth commented Nov 26, 2018

@kvark any progress on this being merged? it fixes a rather annoying Servo bug too.

@jdm
Copy link
Member

jdm commented Nov 26, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Nov 27, 2018

The latest upstream changes (presumably #3338) made this pull request unmergeable. Please resolve the merge conflicts.

@kvark
Copy link
Member

kvark commented Nov 27, 2018

If I understand correctly, this can be closed in favor of #3338. Please feel free to reopen otherwise!

@kvark kvark closed this Nov 27, 2018
bors-servo added a commit to servo/servo that referenced this pull request Nov 27, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Nov 27, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Nov 27, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Nov 27, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Nov 28, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Nov 28, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Nov 28, 2018
Update webrender

Fixes #22232 , once servo/webrender#3327 lands and I update this PR to include it

All the integer casts are due to servo/webrender#3291

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22237)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.