-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Difference between Float32Array::new().subarray and Float32Array::view() #1615
Comments
Pointed out in rustwasm#1615!
Ah that was just an old example which predated the existence of
I think so! I believe that's a method on |
This comment was marked as abuse.
This comment was marked as abuse.
Oh no you're right about the perf optimization, I think it's just that webgl doesn't have support for that but webgl2 does. |
Closing with the example update in #1618 |
@dakom (Little late, but...) The reason for When you call When the So the point of In other words, with WebGL1 the Rust code looks like this (including the code for unsafe fn view(slice: &[f32]) -> Float32Array {
let buf = wasm_bindgen::memory();
let mem = buf.unchecked_ref::<WebAssembly::Memory>();
// Allocates a new Float32Array object in JS
Float32Array::new_with_byte_offset_and_length(
&mem.buffer(),
slice.as_ptr() as u32,
slice.len() as u32,
)
}
gl.buffer_sub_data_with_i32_and_array_buffer_view(
target,
offset,
&unsafe { view(&slice) },
); But with WebGL2 it would look like this: let buf = wasm_bindgen::memory();
let mem = buf.unchecked_ref::<WebAssembly::Memory>();
gl.buffer_sub_data_with_i32_and_array_buffer_view(
target,
offset,
&mem.buffer(),
slice.as_ptr() as u32,
slice.len() as u32,
); Note the lack of needing to create a new |
Summary
The docs show Float32Array::view() as
unsafe
while the webgl example does not use this function - rather it uses a combo of Float32Array::new() and Float32Array::subarrayIs there a performance tradeoff happening with this approach, that would be gained by switching to
view()
?Additional Details
If we are always able to get a view into Float32Array, without really allocating, I wonder if we actually gain from
bufferSubData()
? (e.g. https://docs.rs/web-sys/0.3.7/web_sys/struct.WebGl2RenderingContext.html#method.buffer_sub_data_with_i32_and_array_buffer)The text was updated successfully, but these errors were encountered: