@@ -38,6 +38,14 @@ const reorderFS = /* glsl */`
38
38
}
39
39
` ;
40
40
41
+ const readImageDataAsync = ( texture ) => {
42
+ return texture . read ( 0 , 0 , texture . width , texture . height , {
43
+ mipLevel : 0 ,
44
+ face : 0 ,
45
+ immediate : true
46
+ } ) ;
47
+ } ;
48
+
41
49
const resolve = ( scope , values ) => {
42
50
for ( const key in values ) {
43
51
scope . resolve ( key ) . setValue ( values [ key ] ) ;
@@ -129,8 +137,6 @@ class GSplatSogsData {
129
137
130
138
numSplats ;
131
139
132
- shBands ;
133
-
134
140
means_l ;
135
141
136
142
means_u ;
@@ -192,7 +198,17 @@ class GSplatSogsData {
192
198
return true ;
193
199
}
194
200
195
- decompress ( ) {
201
+ get shBands ( ) {
202
+ // sh palette has 64 sh entries per row. use width to calculate number of bands
203
+ const widths = {
204
+ 192 : 1 , // 64 * 3
205
+ 512 : 2 , // 64 * 8
206
+ 960 : 3 // 64 * 15
207
+ } ;
208
+ return widths [ this . sh_centroids ?. resource ?. width ] ?? 0 ;
209
+ }
210
+
211
+ async decompress ( ) {
196
212
const members = [
197
213
'x' , 'y' , 'z' ,
198
214
'f_dc_0' , 'f_dc_1' , 'f_dc_2' , 'opacity' ,
@@ -202,6 +218,16 @@ class GSplatSogsData {
202
218
203
219
const { shBands } = this ;
204
220
221
+ // copy back gpu texture data so cpu iterator has access to it
222
+ const { means_l, means_u, quats, scales, sh0, sh_labels, sh_centroids } = this ;
223
+ means_l . _levels [ 0 ] = await readImageDataAsync ( means_l ) ;
224
+ means_u . _levels [ 0 ] = await readImageDataAsync ( means_u ) ;
225
+ quats . _levels [ 0 ] = await readImageDataAsync ( quats ) ;
226
+ scales . _levels [ 0 ] = await readImageDataAsync ( scales ) ;
227
+ sh0 . _levels [ 0 ] = await readImageDataAsync ( sh0 ) ;
228
+ sh_labels . _levels [ 0 ] = await readImageDataAsync ( sh_labels ) ;
229
+ sh_centroids . _levels [ 0 ] = await readImageDataAsync ( sh_centroids ) ;
230
+
205
231
// allocate spherical harmonics data
206
232
if ( shBands > 0 ) {
207
233
const shMembers = [ ] ;
@@ -362,23 +388,25 @@ class GSplatSogsData {
362
388
return order ;
363
389
}
364
390
365
- reorderData ( ) {
366
- if ( ! this . orderTexture ) {
367
- const { device, height, width } = this . means_l ;
368
-
369
- this . orderTexture = new Texture ( device , {
370
- name : 'orderTexture' ,
371
- width,
372
- height,
373
- format : PIXELFORMAT_R32U ,
374
- mipmaps : false ,
375
- levels : [ this . calcMortonOrder ( ) ]
376
- } ) ;
391
+ async reorderData ( ) {
392
+ const { device, height, width } = this . means_l ;
377
393
378
- device . on ( 'devicerestored' , ( ) => {
379
- this . reorderGpuMemory ( ) ;
380
- } ) ;
381
- }
394
+ // copy back means_l and means_u data from gpu so cpu reorder has access to it
395
+ this . means_l . _levels [ 0 ] = await readImageDataAsync ( this . means_l ) ;
396
+ this . means_u . _levels [ 0 ] = await readImageDataAsync ( this . means_u ) ;
397
+
398
+ this . orderTexture = new Texture ( device , {
399
+ name : 'orderTexture' ,
400
+ width,
401
+ height,
402
+ format : PIXELFORMAT_R32U ,
403
+ mipmaps : false ,
404
+ levels : [ this . calcMortonOrder ( ) ]
405
+ } ) ;
406
+
407
+ device . on ( 'devicerestored' , ( ) => {
408
+ this . reorderGpuMemory ( ) ;
409
+ } ) ;
382
410
383
411
this . reorderGpuMemory ( ) ;
384
412
}
0 commit comments