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

Implement WebGL getFrameBufferAttachmentParameter API #20317

Merged

Conversation

gootorov
Copy link
Contributor

@gootorov gootorov commented Mar 16, 2018

Implementation of getFramebufferAttachmentParameter as in WebGL1 specification.

Part of #10209.

r? emilio or jdm.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/webglrenderingcontext.rs, components/script/dom/webidls/WebGLRenderingContext.webidl, components/script/dom/webgl2renderingcontext.rs
  • @fitzgen: components/script/dom/webglrenderingcontext.rs, components/script/dom/webidls/WebGLRenderingContext.webidl, components/script/dom/webgl2renderingcontext.rs
  • @KiChjang: components/script/dom/webglrenderingcontext.rs, components/script/dom/webidls/WebGLRenderingContext.webidl, components/script/dom/webgl2renderingcontext.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 16, 2018
@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@jdm
Copy link
Member

jdm commented Mar 16, 2018

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit c99d3c2 with merge 610d0b5...

bors-servo pushed a commit that referenced this pull request Mar 16, 2018
…er, r=<try>

Implement WebGL getFrameBufferAttachmentParameter API

<!-- Please describe your changes on the following line: -->
Implementation of `getFramebufferAttachmentParameter` as in WebGL1 specification.

Part of #10209.

r? emilio or jdm.

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [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. -->

<!-- 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/20317)
<!-- Reviewable:end -->
Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending going through the GLES specs and such, looks good! I only have a couple minor suggestions.

Let's see what bors thinks, thanks for working on this!

@@ -142,6 +142,14 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
self.base.GetExtension(cx, name)
}

#[allow(unsafe_code)]
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
unsafe fn GetFramebufferAttachmentParameter(&self, cx: *mut JSContext,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Indentation looks off, let's use:

unsafe fn GetFramebufferAttachmentParameter(
    &self,
    cx: *mut JSContext,
    // ...
) -> JSVal {

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6
unsafe fn GetFramebufferAttachmentParameter(&self, _cx: *mut JSContext,
target: u32, attachment: u32, pname: u32) -> JSVal
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Ditto about indentation.

if let None = self.bound_framebuffer.get() {
self.webgl_error(InvalidOperation);
return NullValue();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably easier and faster if we do the validation here, to keep it all in the same place.

The WebGL thread should assert that glGetError returns GL_NO_ERROR in debug builds, in case we've messed up.

Does that sound fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though now I see it we're very inconsistent about it, I think it's nicer. wdyt? (also, @jdm wdyt?)

Copy link
Contributor Author

@gootorov gootorov Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a bit inconsistent in the code base. I noticed that usually on the receiver channel side we validate input that we pass to GLES and on the sender side (here) we check what GLES returned. If it returns something we don't expect, we panic. At least that's how I understood it.

Validating everything here wouldn't be any harder, we could do that if that's faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it again today, I think it will look nicer, I agree. If that's faster too, then it's a win-win. We could move all validation for other APIs here too as a follow-up.

@jdm What do you think? Sounds good?

target: u32, attachment: u32, pname: u32) -> JSVal
{
// Check if currently bound framebuffer is non-zero as per spec.
if let None = self.bound_framebuffer.get() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: self.bound_framebuffer.get().is_none()

@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-css

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Mar 16, 2018
@gootorov
Copy link
Contributor Author

gootorov commented Mar 16, 2018

Bors fails at WebGL2 tests that we talked about on IRC. How can we disable them? The WebGL1 ones are all passing.
There are some other tests as well that are expected to timeout but are OK now. Shall we enable them now?

@gootorov
Copy link
Contributor Author

gootorov commented Mar 16, 2018

Nevermind, the WebGL2 tests has actually always been disabled.
WebGL2 tests are disabled, but bors still runs them, why is that?

Enabled rapid-resizing that is unexpectedly passing now and looking into wpt/CSS2/visudet/line-height-204 that started to fail.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Mar 16, 2018
@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch from c567d0d to 10b9a79 Compare March 17, 2018 00:02
@emilio
Copy link
Member

emilio commented Mar 17, 2018

Note that the line-height test is known flake. You should look at the filtered-wpt-errorsummary.log file instead: http://build.servo.org/builders/linux-rel-css/builds/8248/steps/shell__4/logs/filtered-wpt-errorsummary.log

@gootorov
Copy link
Contributor Author

gootorov commented Mar 17, 2018

Oh, okay. Errors in filtered-wpt-errorsummary.log are expected. Those are failures from WebGL2 tests that we discussed, but I don't know why bors complains about them.

[framebuffer-test.html]
expected: ERROR
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

@emilio
Copy link
Member

emilio commented Mar 17, 2018

Why wouldn't it run them? The annotation in that file just means that the test failed because it threw before the end. That may be possible, since you just added an interface that could've made the test throw, so expectations need to be updated.

@bors-servo
Copy link
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Mar 18, 2018
@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch from 419f791 to c10fef9 Compare March 18, 2018 14:21
@gootorov
Copy link
Contributor Author

@emilio Should be good now! :)


// Note: commented out stuff is for the WebGL2 standard.
let target_matches = match target {
//constants::READ_FRAMEBUFFER |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a space after //?

target: u32,
attachment: u32,
pname: u32,
chan: WebGLSender<WebGLResult<WebGLParameter>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there's no reason this chan returns a WebGLResult now, right? I'd make it just return an integer, and remove the dead code from the handle_potential_webgl_error stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The channels require a type parameter and we can't pass WebGLSender to get_framebuffer_attachment_parameter(). We can simplify that to WebGLSender<WebGLParameter> and the code below would become

match receiver.recv().unwrap() {
    WebGLParameter::Int(value) => Int32Value(value),
    _ => panic!("Framebuffer attachment parameter must be an integer"),
}

Sounds good?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, we could do WebGLSender<i32>, and then Int32Value(receiver.recv().unwrap()) would be possible. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if it will always return an integer then WebGLSender<i32> makes sense.

WebGLParameter::Float(_) => panic!("Framebuffer attachment parameter should not be float"),
WebGLParameter::FloatArray(_) => panic!("Framebuffer attachment parameter should not be float array"),
WebGLParameter::String(_) => panic!("Framebuffer attachment parameter should not be string"),
WebGLParameter::Invalid => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change suggested above, a;; this block becomes:

Int32Value(receiver.recv().unwrap())

//constants::FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE |
//constants::FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER |
constants::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME |
constants::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, according to the spec, when OBJECT_TYPE is passed, we need to return a WebGLTexture or WebGLRenderbuffer, right? Not an integer which happens to be the name of that texture / rb on the GPU.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebGL and GLES specs say slightly different things, for some reason.
According to GLES spec, it returns one of NONE, TEXTURE, or RENDERBUFFER, which are typedef'ed unsigned integers as can be seen in this table:
https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14

@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch from c10fef9 to a687d50 Compare March 18, 2018 18:48
Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really close! :)

constants::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME => {
if self.bound_renderbuffer.get().is_some() {
return object_binding_to_js_or_null!(cx, &self.bound_renderbuffer);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: else after return is unnecessary.

@@ -2343,6 +2343,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return NullValue();
}

// special case that returns `WebGLRenderbuffer` or `WebGLTexture` dom object
match pname {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just if pname == constants::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME?

return object_binding_to_js_or_null!(cx, &self.bound_renderbuffer);
} else {
let texture = self.bound_texture(constants::TEXTURE_2D);
return optional_root_object_to_js_or_null!(cx, texture);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the spec says:

If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then querying any other pname will generate INVALID_ENUM.

Which means that if there's no texture and no renderbuffer, we should return and signal an invalid enum error for all the parameter names too.

@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch from 28b9346 to a91642a Compare March 20, 2018 16:50
return object_binding_to_js_or_null!(cx, &self.bound_renderbuffer);
}
self.webgl_error(InvalidEnum);
return NullValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be instead:

// From the GLES2 spec:
//
//     If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE,
//     then querying any other pname will generate INVALID_ENUM.
//
if pname != constants::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE &&
    self.bound_texture(..).is_none() &&
    self.bound_renderbuffer.get().is_none()
{
    self.webgl_error(InvalidEnum);
    return NullValue();
}

That is, my reading of that quote is that InvalidEnum should be returned for all other constants, not only for OBJECT_NAME.

@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch from a91642a to db015a3 Compare March 21, 2018 01:11
@emilio
Copy link
Member

emilio commented Mar 21, 2018

Looks great, thanks!

@bors-servo r+

@jdm
Copy link
Member

jdm commented Mar 21, 2018

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit da01db9 has been approved by jdm

@highfive highfive assigned jdm and unassigned emilio Mar 21, 2018
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 21, 2018
bors-servo pushed a commit that referenced this pull request Mar 21, 2018
…er, r=jdm

Implement WebGL getFrameBufferAttachmentParameter API

<!-- Please describe your changes on the following line: -->
Implementation of `getFramebufferAttachmentParameter` as in WebGL1 specification.

Part of #10209.

r? emilio or jdm.

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [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. -->

<!-- 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/20317)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

⌛ Testing commit da01db9 with merge 6bfcff7...

@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Mar 21, 2018
@jdm
Copy link
Member

jdm commented Mar 21, 2018

Looks like /_mozilla/webgl/conformance-1.0.3/conformance/misc/object-deletion-behaviour.html still needs expectation updates.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Mar 22, 2018
@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch 2 times, most recently from 5800857 to 2182d9b Compare March 22, 2018 16:19
@gootorov gootorov force-pushed the webgl-getFramebufferAttachmentParameter branch from 2182d9b to ee5bdbb Compare March 22, 2018 16:26
@jdm
Copy link
Member

jdm commented Mar 22, 2018

@bors-servo: r+
Thanks!

@bors-servo
Copy link
Contributor

📌 Commit ee5bdbb has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 22, 2018
@bors-servo
Copy link
Contributor

⌛ Testing commit ee5bdbb with merge 4aaac61...

bors-servo pushed a commit that referenced this pull request Mar 22, 2018
…er, r=jdm

Implement WebGL getFrameBufferAttachmentParameter API

<!-- Please describe your changes on the following line: -->
Implementation of `getFramebufferAttachmentParameter` as in WebGL1 specification.

Part of #10209.

r? emilio or jdm.

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [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. -->

<!-- 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/20317)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing 4aaac61 to master...

@bors-servo bors-servo merged commit ee5bdbb into servo:master Mar 22, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 22, 2018
@gootorov gootorov deleted the webgl-getFramebufferAttachmentParameter branch March 22, 2018 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants