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

Added Uniform{2i, 2iv, 2fv, 3f, 3i, 3iv, 3fv} #10436

Merged
merged 1 commit into from Apr 14, 2016
Merged

Conversation

@autrilla
Copy link
Contributor

autrilla commented Apr 6, 2016

@emilio r?

Partial #10417.


This change is Reviewable

@highfive
Copy link

highfive commented Apr 6, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webglrenderingcontext.rs, components/script/dom/webidls/WebGLRenderingContext.webidl
  • @emilio: components/script/dom/webglrenderingcontext.rs
@highfive
Copy link

highfive commented Apr 6, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
_cx: *mut JSContext,
uniform: Option<&WebGLUniformLocation>,
data: Option<*mut JSObject>) {
let data = match data {

This comment has been minimized.

@Manishearth

Manishearth Apr 6, 2016

Member

if the passed location is null, data passed in will be silently ignored.

I assume that means that we should return early here and not throw any errors?

This comment has been minimized.

@emilio

emilio Apr 6, 2016

Member

That refers to the WebGLUniformLocation variable, which is ignored if it's null in Uniform2f()... That check should be repeated here though, since in the case null, null were registering an error when we should not.

This comment has been minimized.

@autrilla

autrilla Apr 6, 2016

Author Contributor

I suppose so, yes. The other previously implemented uniform vector functions didn't do it either, so should I fix that in this PR, or open an issue and handle it in another PR?

This comment has been minimized.

@emilio

emilio Apr 6, 2016

Member

Preferably fixing it here, but if you don't have the time or anything feel free to file an issue :)

return self.webgl_error(InvalidOperation);
}

self.Uniform2f(uniform, data[0], data[1]);

This comment has been minimized.

@Manishearth

Manishearth Apr 6, 2016

Member

I don't see how this works. This will only work for glUniform2fv(uniform, 1, data), i.e. uniform vec2 foo or uniform vec2 foo[1], but not for uniform vec2 foo[10], which is set as glUniform2fv(uniform, 10, data). In this case I'm assuming the WebGL API internally figures out the size because hey, we're not in C++-land anymore, but the behavior should be the same. We'll need a new message for it.

@emilio does this sound correct?

This comment has been minimized.

@emilio

emilio Apr 6, 2016

Member

Yep, that's true... We also do this in other parts of the code, so we should add Uniformxy messages that receive a Vec<y> and allow that.

If you want to do it for this PR, that would be just great, but if you'd prefer to land it as is and leaving it as a followup it'd be fine too.

@bors-servo
Copy link
Contributor

bors-servo commented Apr 6, 2016

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

@autrilla autrilla force-pushed the autrilla:uniform2 branch from ab18de0 to 616f759 Apr 7, 2016
@KiChjang KiChjang removed the S-needs-rebase label Apr 7, 2016
@autrilla autrilla force-pushed the autrilla:uniform2 branch from 88c2db7 to 2961747 Apr 7, 2016
@autrilla
Copy link
Contributor Author

autrilla commented Apr 7, 2016

@emilio could you review this changes to see if the general principle is fine? (Don't accept the PR or anything though)

@emilio
Copy link
Member

emilio commented Apr 7, 2016

@autrilla: Yeah those changes look in the good direction :)

@autrilla autrilla force-pushed the autrilla:uniform2 branch 2 times, most recently from aee94e6 to 1b160cd Apr 7, 2016
@autrilla
Copy link
Contributor Author

autrilla commented Apr 9, 2016

This should do it. I still want to refactor it a bit because it is too copy-pasty (maybe with a macro?). Extracting parts of the function is a bit hard because errors are expected to be returned directly from the function and not sent to the ipc_renderer... If anyone has any ideas on doing this cleanly, I'd appreciate them!

This should be covered by tests/wpt/web-platform-tests/webgl/conformance-1.0.3/conformance/more/functions/uniformi.html, although not extremely thoroughly.

@emilio
Copy link
Member

emilio commented Apr 10, 2016

Ok, so I'd try to abstract all this in a function belonging to WebGLRenderingContext and returning either true or false (true if it's valid, false if not).

The key point here, is that the return self.webgl_error(..) is actually a cool idiom, but it doesn't return nothing, so it's strictly equivalent to:

self.webgl_error(..);
return;

So... It isn't hard to imagine a function like:

fn validate_uniform_parameters<T>(&self, uniform: Option<&WebGLUniformLocation>, expected_size: u32, data: Option<&[T]>) -> bool {
    let uniform = match uniform {
        Some(uniform) => uniform,
        None => return, // No error, as spec'd
    };

    let data = match data {
        Some(data) => data,
        None => {
            self.webgl_error(InvalidOperation);
            return false;
        },
    };

    if data.len() % expected_size != 0 {
        // ...
    }

    // ...
    true
}

That way it can be reused both in the vector and not vector function, with just an extra check on data if we use optional object in the WebIDL:

fn Uniform2i(&self, uniform: Option<&WebGLUniformLocation>, x: i32, y: i32) {
    if !self.validate_uniform_parameters(uniform, 2, Some(&[x, y])) {
        return; // Error handled above
    }
    self.ipc_renderer...
}

fn Uniform2iv(&self, uniform: Option<&WebGLUniformLocation>, data: Option<*mut JSObject>) {
    let data_slice = data.and_then(|data| unsafe {
        array_buffer_view_data_checked::<i32>(data)
    });

    if !self.validate_uniform_parameters(uniform, 2, data_slice) {
        return; // Error handled above
    }
    self.ipc_renderer...
}

Would something like that make sense?


Review status: 0 of 5 files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@autrilla
Copy link
Contributor Author

autrilla commented Apr 10, 2016

@emilio yes, that makes sense. Not needing to return self.webgl error definitely makes things easier. I'll update the code and push it again

@emilio
Copy link
Member

emilio commented Apr 13, 2016

Review status: 0 of 6 files reviewed at latest revision, 4 unresolved discussions.


components/script/dom/webglrenderingcontext.rs, line 195 [r7] (raw file):
It's probably better to pass directly &WebGLUniformLocation and the current program to the caller instead of unwrapping.


components/script/dom/webglrenderingcontext.rs, line 216 [r7] (raw file):
So, I'm not too confident this is the right way to check this, nor the most performant way.

We know what the expected type should be, eg (Uniform1i should have a type of constants::INT). We should pass that type to this function instead of using TypeId here.

Also, why do you check for data.len() >= 1 here and data.len() == 1 in constants::INT? It seems we should check that the length is a multiple of the expected one, that is: data.len() % n == 0.

Even more, why splitting this and validate_uniform_vector_parameters? The only check that could potentially fail is the size check, and this is only called from Uniformxy, where we actually know that size is right (because we're just faking the slice).

We should unify both functions, even when there are a few boilerplate arguments in the non-vector functions.


components/script/dom/webglrenderingcontext.rs, line 240 [r7] (raw file):
Same here about the unwrap()s


Comments from Reviewable

@autrilla
Copy link
Contributor Author

autrilla commented Apr 13, 2016

components/script/dom/webglrenderingcontext.rs, line 216 [r7] (raw file):
The == 1 for constants::INT was a mistake. The length does not have to be a multiple of the expected length here, it has to be at least that size. This is not used for filling up arrays, it's used for filling up single webgl vectors. If we have an INT_VEC4, it makes as much sense to pass 5 parameters as it makes to pass 8. Really, anything beyond 4 makes no sense, but the spec does not say anything about supplying more values than actually fit in the uniform. In the end OpenGL is C, which does not really know about the actual size of the "array" (it's just a pointer) being passed, so you just get the first 4 values and keep going.

I think you're right on the rest.


Comments from Reviewable

@autrilla
Copy link
Contributor Author

autrilla commented Apr 13, 2016

components/script/dom/webglrenderingcontext.rs, line 263 [r7] (raw file):
This is broken too. Say we're writing to an INT_VEC3 array of two elements, and we pass [1, 2, 3, 4, 5, 6]. This would be totally valid, but I'm checking the length of the data, when I should be checking the length of the data divided by the size of each 'element'.


Comments from Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Apr 13, 2016

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

@autrilla autrilla force-pushed the autrilla:uniform2 branch from c200c7f to 3fc6a96 Apr 13, 2016
@autrilla
Copy link
Contributor Author

autrilla commented Apr 13, 2016

@emilio review this whenever you get a chance, please

@jdm jdm removed the S-needs-rebase label Apr 13, 2016
@emilio
Copy link
Member

emilio commented Apr 13, 2016

So much cleaner! Great job! :)

Left a few comments, mostly nits. This is ready to merge once they're adressed and the commits are squashed :P


Reviewed 5 of 6 files at r8.
Review status: all files reviewed at latest revision, 9 unresolved discussions.


components/script/dom/webglrenderingcontext.rs, line 82 [r8] (raw file):
nit: Maybe element_count is more descriptive?


components/script/dom/webglrenderingcontext.rs, line 95 [r8] (raw file):
nit: maybe as_gl_enum or as_gl_constant is more descriptive?


components/script/dom/webglrenderingcontext.rs, line 222 [r8] (raw file):
Could you add a link to https://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml (and potentially https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10)?

Ideally each block that could return false should be annotated with the relevant part of the spec, but if you drop the link here I won't complain :P


components/script/dom/webglrenderingcontext.rs, line 226 [r8] (raw file):
To clarify the above comment, for example, a comment like:

// If the passed location is null, the data passed in will be silently ignored
// and no uniform variables will be changed.

above this line would sufice :)


components/script/dom/webglrenderingcontext.rs, line 232 [r8] (raw file):
nit: maybe merge those two lines? I don't find match self.current_program.get() specially difficult to read.


components/script/dom/webglrenderingcontext.rs, line 248 [r8] (raw file):
Please add a TODO comment here with something like "dont't request this every time, cache it"


components/script/dom/webglrenderingcontext.rs, line 1133 [r8] (raw file):
nit: This is not very important. array_buffer_view_data_checked avoids copying the whole array in the case it's invalid, and wouldn't require the .as_ref().map(Vec::as_slice) below.

Not too important, since we should copy it in the common case where the slice is valid, so I won't complain if you leave this as-is :)

If you prefer to leave this as-is, please change the name to either data_vec or just data.


components/script/dom/webglrenderingcontext.rs, line 1147 [r8] (raw file):
This looks way cleaner, doesn't it? :)


Comments from Reviewable

@emilio emilio assigned emilio and unassigned Manishearth Apr 13, 2016
@autrilla autrilla force-pushed the autrilla:uniform2 branch from 3fc6a96 to d5f8745 Apr 13, 2016
@emilio
Copy link
Member

emilio commented Apr 13, 2016

r=me with that typo corrected :P


Review status: 4 of 5 files reviewed at latest revision, 10 unresolved discussions.


components/script/dom/webglrenderingcontext.rs, line 237 [r9] (raw file):
I meant to quote the spec literally, but it's fine, with the link it's not difficult to follow.


components/script/dom/webglrenderingcontext.rs, line 1148 [r9] (raw file):
nit: This should be array_buffer_view_to_vec::<i32>()


Comments from Reviewable

@autrilla autrilla force-pushed the autrilla:uniform2 branch from d5f8745 to ae908b5 Apr 13, 2016
@autrilla autrilla force-pushed the autrilla:uniform2 branch from ae908b5 to 89c432b Apr 14, 2016
@autrilla
Copy link
Contributor Author

autrilla commented Apr 14, 2016

r+? @emilio

@KiChjang
Copy link
Member

KiChjang commented Apr 14, 2016

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Apr 14, 2016

📌 Commit 89c432b has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Apr 14, 2016

Testing commit 89c432b with merge 7845d67...

bors-servo added a commit that referenced this pull request Apr 14, 2016
Added Uniform{2i, 2iv, 2fv, 3f, 3i, 3iv, 3fv}

@emilio r?

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10436)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 14, 2016

@bors-servo bors-servo merged commit 89c432b into servo:master Apr 14, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
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

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