WebGL texImage2D is slower with Image or Canvas than with Uint8Array
Reported by
w...@haxx.es,
Apr 5 2017
|
|||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 Steps to reproduce the problem: 1. get a big image (load a HTMLImage or create a Canvas) 2. create an array representing raw data for this image 2. create a webgl texture 3. disable texture fliping and alpha premultiplication 4. upload the image to the texture using texImage2D and compare What is the expected behavior? It should as fast using either of the three image sources : Image, Canvas, Uint8Array What went wrong? texImage2D takes a few hundred milliseconds with Image or Canvas, ten times less with Uint8Array. It seems like using either Image or Canvas as texImage2D input forces some CPU conversion before uploading the image. Did this work before? N/A Chrome version: 57.0.2987.133 Channel: stable OS Version: OS X 10.12.3 Flash Version: Test case here https://jsperf.com/webgl-teximage2d/1
,
Apr 5 2017
,
Apr 6 2017
Calling toDataURL on a large canvas forces a GPU-to-CPU readback of the contents, defeating all of the optimizations the browser performs behind the scenes. This is why WebGL's texImage2D and texSubImage2D (and now the 3D variants) accept HTMLCanvasElements, HTMLImageElements, ImageBitmaps, etc. These utilize GPU-to-GPU copies behind the scenes. This is expected behavior. Please switch your code to pass the canvases, images, etc. in directly. ImageBitmap rather than HTMLImageElement is now the recommended way to asynchronously prepare large images for upload to WebGL textures.
,
Apr 7 2017
toDataURL is indeed slow, but it wasn't the problem here since it was not part of the actual performance test (only initialization, to create an image from the canvas rather than download an image from the web). After more investigation following your informations I can add that : - ImageBitmap a nice to use with fetch, but passing an ImageBitmap to texImage2D is not much faster than passing directly a Uint8Array. - Passing a HTMLCanvasElement was slowing down texImage2D if drawn a HTMLImageElement in said canvas - If the canvas is drawn an ImageBitmap and then the canvas is passed to texImage2D, it gets faster than passing the ImageBitmap directly. It's kind of unexpected that ImageBitmap=>texImage2D is slow while ImageBitmap=>Canvas=>texImage2D is fast, but adding a canvas is not much so I'll consider WontFix acceptable. Thanks !
,
Apr 13 2017
wiz@ - sorry if I misinterpreted your test. It's unexpected that uploading an ImageBitmap via texImage2D is slower than taking the same ImageBitmap, drawing it to a canvas, and uploading it via texImage2D. If you have some test case demonstrating this, please file a new bug. Please be careful to avoid issues like accidentally caching the results of previous runs, or re-using the same ImageBitmap over and over again, thereby causing it to be cached in a texture internally and making the ImageBitmap -> Canvas -> Texture path accidentally faster. |
|||
►
Sign in to add a comment |
|||
Comment 1 by w...@haxx.es
, Apr 5 2017