@@ -156,14 +156,8 @@ export default class WebGLBackend extends PaddlejsBackend {
156156
157157 const pbo = this . createPBO ( ) ;
158158 await this . createAndWaitForFence ( ) ;
159- const result = this . downloadFloat32TensorFromBuffer ( pbo ) ;
160-
161159 const shape = fetchInfo ? fetchInfo . shape : [ ] ;
162- if ( env . get ( 'webgl_pack_output' ) ) {
163- return result . slice ( 0 , getSizeFromShape ( shape ) ) ;
164- }
165-
166- return result ;
160+ return this . downloadFloat32TensorFromBuffer ( pbo , shape ) ;
167161 }
168162
169163 createPBO ( ) {
@@ -234,25 +228,23 @@ export default class WebGLBackend extends PaddlejsBackend {
234228 fn ( ) ;
235229 }
236230
237- downloadFloat32TensorFromBuffer ( buffer ) {
231+ downloadFloat32TensorFromBuffer ( buffer , shape ) {
238232 const size : number = 4 * this . width_texture_out * this . height_texture_out ;
239233 if ( this . glVersion === 2 ) {
240234 const gl2 = this . gl as WebGL2RenderingContext ;
241235 const pixels = new Float32Array ( size ) ;
242236 gl2 . bindBuffer ( gl2 . PIXEL_PACK_BUFFER , buffer ) ;
243237 gl2 . getBufferSubData ( gl2 . PIXEL_PACK_BUFFER , 0 , pixels ) ;
244238 gl2 . bindBuffer ( gl2 . PIXEL_PACK_BUFFER , null ) ;
245-
246239 const result : number [ ] = [ ] ;
247240 if ( env . get ( 'webgl_pack_output' ) ) {
248- return Array . from ( pixels ) ;
241+ return Array . from ( pixels ) . slice ( 0 , getSizeFromShape ( shape ) ) ;
249242 }
250243 for ( let i = 0 ; i < this . width_texture_out * this . height_texture_out ; i ++ ) {
251244 result . push ( pixels [ 4 * i ] ) ;
252245 }
253246 return result ;
254247 }
255-
256248 const pixels = buffer ;
257249 const result = [ ] as number [ ] ;
258250 for ( let i = 0 ; i < this . width_texture_out * this . height_texture_out ; i ++ ) {
0 commit comments