Auto merge of #25930 - mmatyas:webgl_fns_indexed_unibuf, r=jdm

Add support for WebGL2 GetIndexedParameter

Adds support for the `GetIndexedParameter` WebGL2 call.

See: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.2

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

Depends on #25915.

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. -->
This commit is contained in:
bors-servo 2020-03-10 10:37:53 -04:00 committed by GitHub
commit 30fafdca19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 187 additions and 135 deletions

View file

@ -56,6 +56,24 @@ use std::cell::Cell;
use std::cmp;
use std::ptr::{self, NonNull};
#[unrooted_must_root_lint::must_root]
#[derive(JSTraceable, MallocSizeOf)]
struct IndexedBinding {
buffer: MutNullableDom<WebGLBuffer>,
start: Cell<i64>,
size: Cell<i64>,
}
impl IndexedBinding {
fn new() -> IndexedBinding {
IndexedBinding {
buffer: MutNullableDom::new(None),
start: Cell::new(0),
size: Cell::new(0),
}
}
}
#[dom_struct]
pub struct WebGL2RenderingContext {
reflector_: Reflector,
@ -69,6 +87,8 @@ pub struct WebGL2RenderingContext {
bound_pixel_unpack_buffer: MutNullableDom<WebGLBuffer>,
bound_transform_feedback_buffer: MutNullableDom<WebGLBuffer>,
bound_uniform_buffer: MutNullableDom<WebGLBuffer>,
indexed_uniform_buffer_bindings: Box<[IndexedBinding]>,
indexed_transform_feedback_buffer_bindings: Box<[IndexedBinding]>,
current_transform_feedback: MutNullableDom<WebGLTransformFeedback>,
texture_pack_row_length: Cell<usize>,
texture_pack_skip_pixels: Cell<usize>,
@ -111,6 +131,15 @@ impl WebGL2RenderingContext {
.map(|_| Default::default())
.collect::<Vec<_>>()
.into();
let indexed_uniform_buffer_bindings = (0..base.limits().max_uniform_buffer_bindings)
.map(|_| IndexedBinding::new())
.collect::<Vec<_>>()
.into();
let indexed_transform_feedback_buffer_bindings =
(0..base.limits().max_transform_feedback_separate_attribs)
.map(|_| IndexedBinding::new())
.collect::<Vec<_>>()
.into();
Some(WebGL2RenderingContext {
reflector_: Reflector::new(),
@ -124,6 +153,8 @@ impl WebGL2RenderingContext {
bound_pixel_unpack_buffer: MutNullableDom::new(None),
bound_transform_feedback_buffer: MutNullableDom::new(None),
bound_uniform_buffer: MutNullableDom::new(None),
indexed_uniform_buffer_bindings,
indexed_transform_feedback_buffer_bindings,
current_transform_feedback: MutNullableDom::new(None),
texture_pack_row_length: Cell::new(0),
texture_pack_skip_pixels: Cell::new(0),
@ -1396,6 +1427,14 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
self.unbind_from(&self.bound_pixel_unpack_buffer, &buffer);
self.unbind_from(&self.bound_transform_feedback_buffer, &buffer);
self.unbind_from(&self.bound_uniform_buffer, &buffer);
for binding in self.indexed_uniform_buffer_bindings.iter() {
self.unbind_from(&binding.buffer, &buffer);
}
for binding in self.indexed_transform_feedback_buffer_bindings.iter() {
self.unbind_from(&binding.buffer, &buffer);
}
buffer.mark_for_deletion(false);
}
@ -1520,6 +1559,46 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
.GetShaderPrecisionFormat(shader_type, precision_type)
}
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.2
#[allow(unsafe_code)]
fn GetIndexedParameter(&self, cx: JSContext, target: u32, index: u32) -> JSVal {
let bindings = match target {
constants::TRANSFORM_FEEDBACK_BUFFER_BINDING |
constants::TRANSFORM_FEEDBACK_BUFFER_SIZE |
constants::TRANSFORM_FEEDBACK_BUFFER_START => {
&self.indexed_transform_feedback_buffer_bindings
},
constants::UNIFORM_BUFFER_BINDING |
constants::UNIFORM_BUFFER_SIZE |
constants::UNIFORM_BUFFER_START => &self.indexed_uniform_buffer_bindings,
_ => {
self.base.webgl_error(InvalidEnum);
return NullValue();
},
};
let binding = match bindings.get(index as usize) {
Some(binding) => binding,
None => {
self.base.webgl_error(InvalidValue);
return NullValue();
},
};
match target {
constants::TRANSFORM_FEEDBACK_BUFFER_BINDING | constants::UNIFORM_BUFFER_BINDING => unsafe {
optional_root_object_to_js_or_null!(*cx, binding.buffer.get())
},
constants::TRANSFORM_FEEDBACK_BUFFER_START | constants::UNIFORM_BUFFER_START => {
Int32Value(binding.start.get() as _)
},
constants::TRANSFORM_FEEDBACK_BUFFER_SIZE | constants::UNIFORM_BUFFER_SIZE => {
Int32Value(binding.size.get() as _)
},
_ => unreachable!(),
}
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetUniformLocation(
&self,
@ -3212,20 +3291,21 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.16
fn BindBufferBase(&self, target: u32, index: u32, buffer: Option<&WebGLBuffer>) {
let (bind_limit, slot) = match target {
let (generic_slot, indexed_bindings) = match target {
constants::TRANSFORM_FEEDBACK_BUFFER => (
self.base.limits().max_transform_feedback_separate_attribs,
&self.bound_transform_feedback_buffer,
&self.indexed_transform_feedback_buffer_bindings,
),
constants::UNIFORM_BUFFER => (
self.base.limits().max_uniform_buffer_bindings,
&self.bound_uniform_buffer,
&self.indexed_uniform_buffer_bindings,
),
_ => return self.base.webgl_error(InvalidEnum),
};
if index >= bind_limit {
return self.base.webgl_error(InvalidValue);
}
let indexed_binding = match indexed_bindings.get(index as usize) {
Some(slot) => slot,
None => return self.base.webgl_error(InvalidValue),
};
if let Some(buffer) = buffer {
handle_potential_webgl_error!(self.base, self.base.validate_ownership(buffer), return);
@ -3234,6 +3314,9 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
return self.base.webgl_error(InvalidOperation);
}
handle_potential_webgl_error!(self.base, buffer.set_target_maybe(target), return);
// for both the generic and the indexed bindings
buffer.increment_attached_counter();
buffer.increment_attached_counter();
}
@ -3242,12 +3325,16 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
index,
buffer.map(|b| b.id()),
));
for slot in &[&generic_slot, &indexed_binding.buffer] {
if let Some(old) = slot.get() {
old.decrement_attached_counter();
}
slot.set(buffer);
}
indexed_binding.start.set(0);
indexed_binding.size.set(0);
}
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.16
fn BindBufferRange(
@ -3258,20 +3345,21 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
offset: i64,
size: i64,
) {
let (bind_limit, slot) = match target {
let (generic_slot, indexed_bindings) = match target {
constants::TRANSFORM_FEEDBACK_BUFFER => (
self.base.limits().max_transform_feedback_separate_attribs,
&self.bound_transform_feedback_buffer,
&self.indexed_transform_feedback_buffer_bindings,
),
constants::UNIFORM_BUFFER => (
self.base.limits().max_uniform_buffer_bindings,
&self.bound_uniform_buffer,
&self.indexed_uniform_buffer_bindings,
),
_ => return self.base.webgl_error(InvalidEnum),
};
if index >= bind_limit {
return self.base.webgl_error(InvalidValue);
}
let indexed_binding = match indexed_bindings.get(index as usize) {
Some(slot) => slot,
None => return self.base.webgl_error(InvalidValue),
};
if offset < 0 || size < 0 {
return self.base.webgl_error(InvalidValue);
@ -3302,6 +3390,9 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
return self.base.webgl_error(InvalidOperation);
}
handle_potential_webgl_error!(self.base, buffer.set_target_maybe(target), return);
// for both the generic and the indexed bindings
buffer.increment_attached_counter();
buffer.increment_attached_counter();
}
@ -3312,12 +3403,16 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
offset,
size,
));
for slot in &[&generic_slot, &indexed_binding.buffer] {
if let Some(old) = slot.get() {
old.decrement_attached_counter();
}
slot.set(buffer);
}
indexed_binding.start.set(offset);
indexed_binding.size.set(size);
}
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.16
fn GetUniformIndices(&self, program: &WebGLProgram, names: Vec<DOMString>) -> Option<Vec<u32>> {

View file

@ -531,7 +531,7 @@ interface mixin WebGL2RenderingContextBase
/* Uniform Buffer Objects and Transform Feedback Buffers */
void bindBufferBase(GLenum target, GLuint index, WebGLBuffer? buffer);
void bindBufferRange(GLenum target, GLuint index, WebGLBuffer? buffer, GLintptr offset, GLsizeiptr size);
// any getIndexedParameter(GLenum target, GLuint index);
any getIndexedParameter(GLenum target, GLuint index);
sequence<GLuint>? getUniformIndices(WebGLProgram program, sequence<DOMString> uniformNames);
any getActiveUniforms(WebGLProgram program, sequence<GLuint> uniformIndices, GLenum pname);
GLuint getUniformBlockIndex(WebGLProgram program, DOMString uniformBlockName);

View file

@ -1,91 +0,0 @@
[bound-buffer-size-change-test.html]
[WebGL test #38: gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #23: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #4: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #28: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0) should be 4. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #22: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0) should be 4. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #33: gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1) should be 12. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #16: gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #7: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #35: gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #37: gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1) should be 16. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #39: gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1) should be 12. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #21: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0) should be 8. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #40: gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1) should be 16. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #15: gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #25: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0) should be 4. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #32: gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #14: gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #11: gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #36: gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1) should be 12. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #3: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #5: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #6: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #24: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0) should be 8. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #34: gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1) should be 16. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #26: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #2: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #20: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be [object WebGLBuffer\]. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #27: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0) should be 8. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #12: gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL
[WebGL test #13: gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1) should be 0. Threw exception TypeError: gl.getIndexedParameter is not a function]
expected: FAIL

View file

@ -1,5 +0,0 @@
[buffer-overflow-test.html]
expected: ERROR
[WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
expected: FAIL

View file

@ -1,7 +1,4 @@
[methods-2.html]
[WebGL test #19: Property either does not exist or is not a function: getIndexedParameter]
expected: FAIL
[WebGL test #11: Property either does not exist or is not a function: compressedTexSubImage3D]
expected: FAIL
@ -14,33 +11,39 @@
[WebGL test #18: Property either does not exist or is not a function: drawBuffers]
expected: FAIL
[WebGL test #22: Property either does not exist or is not a function: bindVertexArray]
expected: FAIL
[WebGL test #12: Property either does not exist or is not a function: vertexAttribI4i]
expected: FAIL
[WebGL test #19: Property either does not exist or is not a function: createVertexArray]
expected: FAIL
[WebGL test #6: Property either does not exist or is not a function: texStorage2D]
expected: FAIL
[WebGL test #1: Property either does not exist or is not a function: blitFramebuffer]
expected: FAIL
[WebGL test #21: Property either does not exist or is not a function: isVertexArray]
expected: FAIL
[WebGL test #20: Property either does not exist or is not a function: deleteVertexArray]
expected: FAIL
[WebGL test #5: Property either does not exist or is not a function: texImage3D]
expected: FAIL
[WebGL test #17: Property either does not exist or is not a function: drawRangeElements]
expected: FAIL
[WebGL test #21: Property either does not exist or is not a function: deleteVertexArray]
expected: FAIL
[WebGL test #10: Property either does not exist or is not a function: compressedTexImage3D]
expected: FAIL
[WebGL test #7: Property either does not exist or is not a function: texStorage3D]
expected: FAIL
[WebGL test #22: Property either does not exist or is not a function: isVertexArray]
expected: FAIL
[WebGL test #4: Property either does not exist or is not a function: renderbufferStorageMultisample]
expected: FAIL
@ -50,12 +53,6 @@
[WebGL test #0: Property either does not exist or is not a function: isContextLost]
expected: FAIL
[WebGL test #20: Property either does not exist or is not a function: createVertexArray]
expected: FAIL
[WebGL test #23: Property either does not exist or is not a function: bindVertexArray]
expected: FAIL
[WebGL test #16: Property either does not exist or is not a function: vertexAttribIPointer]
expected: FAIL

View file

@ -1,11 +1,67 @@
[switching-objects.html]
expected: ERROR
[WebGL test #6: buffer should match expected values]
expected: FAIL
[WebGL test #23: getError expected: NO_ERROR. Was INVALID_OPERATION : begin on tf1]
expected: FAIL
[WebGL test #41: getError expected: NO_ERROR. Was INVALID_OPERATION : end while paused]
expected: FAIL
[WebGL test #26: getError expected: NO_ERROR. Was INVALID_OPERATION : end on tf1]
expected: FAIL
[WebGL test #33: getError expected: INVALID_OPERATION. Was NO_ERROR : wrong primitive mode]
expected: FAIL
[WebGL test #14: getError expected: NO_ERROR. Was INVALID_OPERATION : begin]
expected: FAIL
[WebGL test #27: buffer should match expected values]
expected: FAIL
[WebGL test #22: getError expected: NO_ERROR. Was INVALID_OPERATION : bind while paused]
expected: FAIL
[WebGL test #34: getError expected: INVALID_OPERATION. Was NO_ERROR : switch program while active]
expected: FAIL
[WebGL test #3: getError expected: NO_ERROR. Was INVALID_OPERATION : begin TF]
expected: FAIL
[WebGL test #17: TRANSFORM_FEEDBACK_BINDING was [object WebGLTransformFeedback\], but expected [object WebGLTransformFeedback\]]
expected: FAIL
[WebGL test #39: getError expected: NO_ERROR. Was INVALID_OPERATION : pause]
expected: FAIL
[WebGL test #16: getError expected: INVALID_OPERATION. Was NO_ERROR : bind while unpaused]
expected: FAIL
[WebGL test #28: getError expected: NO_ERROR. Was INVALID_OPERATION : end on tf2]
expected: FAIL
[WebGL test #36: getError expected: INVALID_OPERATION. Was NO_ERROR : bindTransformFeedback when active]
expected: FAIL
[WebGL test #9: TRANSFORM_FEEDBACK_BUFFER_BINDING[0\] was [object WebGLBuffer\], but expected [object WebGLBuffer\]]
expected: FAIL
[WebGL test #20: getError expected: NO_ERROR. Was INVALID_OPERATION : begin on tf2]
expected: FAIL
[WebGL test #19: buffer should match expected values]
expected: FAIL
[WebGL test #32: getError expected: NO_ERROR. Was INVALID_OPERATION : transform feedback should begin successfully]
expected: FAIL
[WebGL test #18: getError expected: NO_ERROR. Was INVALID_OPERATION : transform feedback should complete successfully]
expected: FAIL
[WebGL test #5: getError expected: NO_ERROR. Was INVALID_OPERATION : end TF]
expected: FAIL
[WebGL test #38: getError expected: INVALID_OPERATION. Was NO_ERROR : bindBufferBase(TRANSFORM_FEEDBACK_BUFFER) when active]
expected: FAIL

View file

@ -2,10 +2,10 @@
[WebGL test #31: buffer should match expected values]
expected: FAIL
[WebGL test #25: buffer should match expected values]
[WebGL test #11: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be null. Was [object WebGLBuffer\].]
expected: FAIL
[WebGL test #11: gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0) should be null. Threw exception TypeError: gl.getIndexedParameter is not a function]
[WebGL test #25: buffer should match expected values]
expected: FAIL
[WebGL test #32: buffer should match expected values]