-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement WebGL getFrameBufferAttachmentParameter API #20317
Conversation
Heads up! This PR modifies the following files:
|
@bors-servo try |
…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 -->
There was a problem hiding this 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, |
There was a problem hiding this comment.
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 | ||
{ |
There was a problem hiding this comment.
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(); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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()
💔 Test failed - linux-rel-css |
Bors fails at WebGL2 tests that we talked about on IRC. How can we disable them? The WebGL1 ones are all passing. |
Enabled |
c567d0d
to
10b9a79
Compare
Note that the line-height test is known flake. You should look at the |
Oh, okay. Errors in Lines 1 to 4 in fc90e61
|
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. |
☔ The latest upstream changes (presumably #20326) made this pull request unmergeable. Please resolve the merge conflicts. |
419f791
to
c10fef9
Compare
@emilio Should be good now! :) |
|
||
// Note: commented out stuff is for the WebGL2 standard. | ||
let target_matches = match target { | ||
//constants::READ_FRAMEBUFFER | |
There was a problem hiding this comment.
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 //
?
components/canvas/webgl_thread.rs
Outdated
target: u32, | ||
attachment: u32, | ||
pname: u32, | ||
chan: WebGLSender<WebGLResult<WebGLParameter>> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
c10fef9
to
a687d50
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
28b9346
to
a91642a
Compare
return object_binding_to_js_or_null!(cx, &self.bound_renderbuffer); | ||
} | ||
self.webgl_error(InvalidEnum); | ||
return NullValue(); |
There was a problem hiding this comment.
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
.
a91642a
to
db015a3
Compare
Looks great, thanks! @bors-servo r+ |
@bors-servo r+ |
📌 Commit da01db9 has been approved by |
…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 -->
💔 Test failed - linux-rel-wpt |
Looks like /_mozilla/webgl/conformance-1.0.3/conformance/misc/object-deletion-behaviour.html still needs expectation updates. |
5800857
to
2182d9b
Compare
2182d9b
to
ee5bdbb
Compare
@bors-servo: r+ |
📌 Commit ee5bdbb has been approved by |
…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 -->
☀️ 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 |
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 errorsThis change is