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

Add support for WebGL2 ReadPixels functions #24783

Merged
merged 1 commit into from Nov 26, 2019

Conversation

@mmatyas
Copy link
Contributor

mmatyas commented Nov 19, 2019

Adds support for the new ReadPixels functions introduced with WebGL2 and the relevant PixelStorei parameters..

Reference: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.10


This is a work in progress patch, but I think it might be ready for comments. There are a few issues left:

  • When the target is the pixel pack buffer, the GL function expects a byte offset as a pointer. In Sparkle the read_pixels functions return/work on top of arrays, so for now I've made a workaround patch. I wonder if that's okay or should we do it somehow differently?
  • When writing to the pixel pack buffer, padding bytes on the destination are properly ignored. When writing to client buffers, Sparkle read_pixels returns a buffer with 1 byte alignment, which I think is fine (less stuff to move between threads), but requires positioning the rows manually (see the bottom of read_pixels_into vs. ReadPixels_).
  • There are some duplicated code between the array buffer and pixel pack buffer variants, eg. the detection of intersection with the framebuffer. This could be refactored, but that results in a function with Result<Option<Rect<u32>>, WebGLError>, which I'm not sure is readable enough to help.
  • There is a duplication with the WebGL1 code. WebGL2 introduces row length, skip pixels and skip rows as pixel pack parameters which affect the ReadPixels operation. The helper functions could be moved to be usable in WebGL1, but then these new modifiers would also need to be passed as a function parameter, which is somewhat ugly (but would work). What's your opinion about this?

cc @jdm @zakorgy


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes
@highfive
Copy link

highfive commented Nov 19, 2019

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/webglrenderingcontext.rs, components/script/dom/webidls/WebGL2RenderingContext.webidl, components/script/dom/webgl2renderingcontext.rs
  • @jgraham: tests/wpt/webgl/meta/conformance2/reading/read-pixels-into-pixel-pack-buffer.html.ini, tests/wpt/webgl/meta/conformance2/reading/read-pixels-pack-parameters.html.ini
  • @KiChjang: components/script/dom/webglrenderingcontext.rs, components/script/dom/webidls/WebGL2RenderingContext.webidl, components/script/dom/webgl2renderingcontext.rs
@highfive
Copy link

highfive commented Nov 19, 2019

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@mmatyas mmatyas force-pushed the mmatyas:webgl_fns_readpixels branch from d84e29b to b6dbeae Nov 19, 2019
Copy link
Member

nox left a comment

Started a review but have yet to finish it.

components/canvas/Cargo.toml Outdated Show resolved Hide resolved
Cargo.lock Outdated Show resolved Hide resolved
components/script/dom/webgl2renderingcontext.rs Outdated Show resolved Hide resolved
components/script/dom/webgl2renderingcontext.rs Outdated Show resolved Hide resolved
components/script/dom/webgl2renderingcontext.rs Outdated Show resolved Hide resolved
components/script/dom/webgl2renderingcontext.rs Outdated Show resolved Hide resolved
@bors-servo
Copy link
Contributor

bors-servo commented Nov 25, 2019

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

@mmatyas mmatyas force-pushed the mmatyas:webgl_fns_readpixels branch 2 times, most recently from e85c8dc to 0ef11db Nov 25, 2019
@mmatyas
Copy link
Contributor Author

mmatyas commented Nov 25, 2019

Updated to master, and also opened a pull request to Sparkle.

@jdm
Copy link
Member

jdm commented Nov 26, 2019

@nox Re-review ping.

@nox
nox approved these changes Nov 26, 2019
Copy link
Member

nox left a comment

I have some concerns about the sparkle changes, but the code here looks good.

We need to publish sparkle and make the corresponding manifest changes here and then it's ready to be landed.

@jdm
Copy link
Member

jdm commented Nov 26, 2019

Sparkle has been published.

Adds support for the new ReadPixels functions introduced with WebGL2
and the relevant PixelStorei parameters.

Reference: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.10
@mmatyas mmatyas force-pushed the mmatyas:webgl_fns_readpixels branch from 0ef11db to 8fefa23 Nov 26, 2019
@mmatyas
Copy link
Contributor Author

mmatyas commented Nov 26, 2019

Ok, updated with the Sparkle related changes.

@jdm
Copy link
Member

jdm commented Nov 26, 2019

@bors-servo r=nox

@bors-servo
Copy link
Contributor

bors-servo commented Nov 26, 2019

📌 Commit 8fefa23 has been approved by nox

@bors-servo
Copy link
Contributor

bors-servo commented Nov 26, 2019

Testing commit 8fefa23 with merge 8e0aa68...

bors-servo added a commit that referenced this pull request Nov 26, 2019
Add support for WebGL2 ReadPixels functions

Adds support for the new ReadPixels functions introduced with WebGL2 and the relevant PixelStorei parameters..

Reference: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.10

<!-- Please describe your changes on the following line: -->

---

This is a work in progress patch, but I think it might be ready for comments. There are a few issues left:

- When the target is the pixel pack buffer, the GL function expects a byte offset as a pointer. In Sparkle the `read_pixels` functions return/work on top of arrays, so for now I've made a [workaround patch](mmatyas/sparkle@45d8bb2). I wonder if that's okay or should we do it somehow differently?
- When writing to the pixel pack buffer, padding bytes on the destination are properly ignored. When writing to client buffers, Sparkle `read_pixels` returns a buffer with 1 byte alignment, which I think is fine (less stuff to move between threads), but requires positioning the rows manually (see the bottom of `read_pixels_into` vs. `ReadPixels_`).
- There are some duplicated code between the array buffer and pixel pack buffer variants, eg. the detection of intersection with the framebuffer. This could be refactored, but that results in a function with `Result<Option<Rect<u32>>, WebGLError>`, which I'm not sure is readable enough to help.
- There is a duplication with the WebGL1 code. WebGL2 introduces row length, skip pixels and skip rows as pixel pack parameters which affect the ReadPixels operation. The helper functions could be moved to be usable in WebGL1, but then these new modifiers would also need to be passed as a function parameter, which is somewhat ugly (but would work). What's your opinion about this?

cc @jdm @zakorgy

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 26, 2019

☀️ Test successful - status-taskcluster
Approved by: nox
Pushing 8e0aa68 to master...

@bors-servo bors-servo merged commit 8fefa23 into servo:master Nov 26, 2019
1 of 2 checks passed
1 of 2 checks passed
Community-TC (pull_request) TaskGroup: failure
Details
homu Test successful
Details
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

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