vello_hybrid: Read pixel pack buffer data into JS array first - #1814
vello_hybrid: Read pixel pack buffer data into JS array first#1814LaurenzV wants to merge 1 commit into
Conversation
| // Safari 15 crashes the tab when attempting to read from a pixel pack buffer directly | ||
| // into WASM-allocated memory. Therefore, we first read it into a JS-allocated buffer and | ||
| // only then transfer it into the buffer backing the pixmap in WASM memory. | ||
| let readback = | ||
| js_sys::Uint8Array::new_with_length(u32::from(self.width) * u32::from(self.height) * 4); |
There was a problem hiding this comment.
This workaround makes sense. I found several related WebKit issues involving getBufferSubData on iOS 15, incorrect buffer offsets, and WebGL operations on WASM-backed views causing crashes. The performance impact should be negligible here, but this makes Safari 15’s limitation the common path for every browser. If a consumer already has a reliable browser-detection approach, would it be better to use this workaround only for affected Safari versions and retain the direct readback elsewhere?
There was a problem hiding this comment.
But how would you implement that? Letting the user pass the browser they are using? What if a user for example masks their browser? I agree it’s unfortunate :( but not sure if its worth special-casing.
There was a problem hiding this comment.
But how would you implement that? Letting the user pass the browser they are using? What if a user for example masks their browser? I agree it’s unfortunate :( but not sure if its worth special-casing.
I don't think passing the browser is a good idea. It would be better to simply enable/disable the feature and let consumers decide for themselves. That said, I don't think the current changes would have much negative impact either.
There was a problem hiding this comment.
So should I add a boolean flag? Or just leave it this way for now?
Safari 15 seems to have problems with the combination of PBO + WASM memory. Putting data into WASM memory directly works fine, copying memory from PBO to JS-allocated buffers also works fine, but copying from PBO to WASM-allocated memory results in a tab crash. This PR fixes this by first copying it into a JS-allocated array and then into the actual pixmap buffer.
out.mp4
While it's a bit unfortunate to have two allocations now and another step of indirection, I haven't figured out a better approach to circumvent this. Just to be sure I also spot-checked some other devices to make sure nothing breaks, and they still seem to pass the probe normally. I also confirmed it fixes the probe in
vello_bench2while it crashes before this fix.