@rings-webgpu/core 1.0.46 → 1.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24305,75 +24305,44 @@ class R32UintTexture extends Texture {
24305
24305
  }
24306
24306
 
24307
24307
  const _floatView$1 = new Float32Array(1);
24308
- const _int32View$1 = new Int32Array(_floatView$1.buffer);
24309
- function batchConvertToHalfFloat(src, dst, offset, length) {
24310
- for (let i = 0; i < length; i++) {
24311
- const val = src[offset + i];
24312
- _floatView$1[0] = val;
24313
- const x = _int32View$1[0];
24314
- let bits = x >> 16 & 32768;
24315
- let m = x >> 12 & 2047;
24316
- const e = x >> 23 & 255;
24317
- if (e < 103) {
24318
- dst[offset + i] = bits;
24319
- continue;
24320
- }
24321
- if (e > 142) {
24322
- bits |= 31744;
24323
- bits |= (e == 255 ? 1 : 0) && x & 8388607;
24324
- dst[offset + i] = bits;
24325
- continue;
24326
- }
24327
- if (e < 114) {
24328
- m |= 2048;
24329
- bits |= (m >> 114 - e) + (m >> 113 - e & 1);
24330
- dst[offset + i] = bits;
24331
- continue;
24332
- }
24333
- bits |= e - 112 << 10 | m >> 1;
24334
- bits += m & 1;
24335
- dst[offset + i] = bits;
24336
- }
24337
- }
24308
+ new Int32Array(_floatView$1.buffer);
24338
24309
  class Float16ArrayTexture extends Texture {
24339
24310
  uint16Array;
24340
- floatArray;
24341
24311
  _dataBuffer;
24342
24312
  /**
24343
- * 使用数字数组填充纹理,格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
24313
+ * 使用 Uint16Array 填充纹理(Float16 格式),格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
24344
24314
  * @param width 纹理宽度
24345
24315
  * @param height 纹理高度
24346
- * @param numbers 每个像素的颜色值数组
24316
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
24347
24317
  * @param useMipmap 是否生成Mipmap
24348
24318
  * @returns 返回纹理实例
24349
24319
  */
24350
- create(width, height, numbers = null, mipmap = true) {
24351
- if (numbers == null) {
24352
- numbers = [];
24353
- for (let i = 0, c = width * height * 4; i < c; i++) {
24354
- numbers[i] = 0;
24355
- }
24320
+ create(width, height, data = null, mipmap = true) {
24321
+ if (data == null) {
24322
+ const size = width * height * 4;
24323
+ data = new Uint16Array(size);
24324
+ data.fill(0);
24356
24325
  }
24357
- this.updateTexture(width, height, numbers, mipmap);
24326
+ this.updateTexture(width, height, data, mipmap);
24358
24327
  return this;
24359
24328
  }
24360
24329
  /**
24361
24330
  * 更新纹理内容
24362
24331
  * @param width 纹理宽度
24363
24332
  * @param height 纹理高度
24364
- * @param numbers 像素数据数组
24333
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
24365
24334
  * @param mipmap 是否生成Mipmap
24366
24335
  * @param startRow 起始行(部分更新)
24367
24336
  * @param rowCount 更新的行数(部分更新)
24368
24337
  */
24369
- updateTexture(width, height, numbers, mipmap = true, startRow, rowCount) {
24338
+ updateTexture(width, height, data, mipmap = true, startRow, rowCount) {
24370
24339
  if (width != this.width || height != this.height) {
24371
24340
  this._dataBuffer && this._dataBuffer.destroy();
24372
24341
  this._dataBuffer = null;
24373
24342
  this.gpuTexture && this.gpuTexture.destroy();
24374
24343
  this.gpuTexture = null;
24375
24344
  }
24376
- this.floatArray = numbers;
24345
+ this.uint16Array = data;
24377
24346
  let device = webGPUContext.device;
24378
24347
  const bytesPerRow = width * 4 * 2;
24379
24348
  this.format = GPUTextureFormat.rgba16float;
@@ -24383,14 +24352,7 @@ class Float16ArrayTexture extends Texture {
24383
24352
  const updateHeight = rowCount;
24384
24353
  const updateOffset = startRow * width * 4;
24385
24354
  const updateLength = updateHeight * width * 4;
24386
- if (!this.uint16Array || this.uint16Array.length < updateOffset + updateLength) {
24387
- if (!this.uint16Array || this.uint16Array.length < numbers.length) {
24388
- this.uint16Array = new Uint16Array(numbers.length);
24389
- }
24390
- }
24391
- const uint16Array2 = this.uint16Array;
24392
- batchConvertToHalfFloat(numbers, uint16Array2, updateOffset, updateLength);
24393
- const updateData = uint16Array2.subarray(updateOffset, updateOffset + updateLength);
24355
+ const updateData = data.subarray(updateOffset, updateOffset + updateLength);
24394
24356
  const neededSize2 = updateData.byteLength;
24395
24357
  if (!this._dataBuffer || this._dataBuffer.size < neededSize2) {
24396
24358
  this._dataBuffer && this._dataBuffer.destroy();
@@ -24425,11 +24387,7 @@ class Float16ArrayTexture extends Texture {
24425
24387
  GPUContext.endCommandEncoder(commandEncoder2);
24426
24388
  return;
24427
24389
  }
24428
- if (!this.uint16Array || this.uint16Array.length != numbers.length) {
24429
- this.uint16Array = new Uint16Array(numbers.length);
24430
- }
24431
- const uint16Array = this.uint16Array;
24432
- batchConvertToHalfFloat(numbers, uint16Array, 0, numbers.length);
24390
+ const uint16Array = data;
24433
24391
  const neededSize = uint16Array.byteLength;
24434
24392
  if (!this._dataBuffer || this._dataBuffer.size < neededSize) {
24435
24393
  this._dataBuffer && this._dataBuffer.destroy();
@@ -24818,7 +24776,8 @@ let GSplatRenderer = class extends RenderNode {
24818
24776
  const h = this.size.y | 0;
24819
24777
  const count = asset.count;
24820
24778
  const tA = new Uint32Array(w * h * 4);
24821
- const tB = new Array(w * h * 4).fill(0);
24779
+ const tB = new Uint16Array(w * h * 4);
24780
+ tB.fill(0);
24822
24781
  const fb = new ArrayBuffer(4);
24823
24782
  const f32 = new Float32Array(fb);
24824
24783
  const u32 = new Uint32Array(fb);
@@ -24892,10 +24851,10 @@ let GSplatRenderer = class extends RenderNode {
24892
24851
  const cBy = r01 * r02 + r11 * r12 + r21 * r22;
24893
24852
  const cBz = r02 * r02 + r12 * r12 + r22 * r22;
24894
24853
  const bidx = idx;
24895
- tB[bidx + 0] = cAx;
24896
- tB[bidx + 1] = cAy;
24897
- tB[bidx + 2] = cAz;
24898
- tB[bidx + 3] = cBz;
24854
+ tB[bidx + 0] = toHalfFloat(cAx) & 65535;
24855
+ tB[bidx + 1] = toHalfFloat(cAy) & 65535;
24856
+ tB[bidx + 2] = toHalfFloat(cAz) & 65535;
24857
+ tB[bidx + 3] = toHalfFloat(cBz) & 65535;
24899
24858
  const hx = toHalfFloat(cBx) & 65535;
24900
24859
  const hy = toHalfFloat(cBy) & 65535;
24901
24860
  tA[idx + 3] = hx | hy << 16;
@@ -42367,7 +42326,7 @@ class PostProcessingComponent extends ComponentBase {
42367
42326
  }
42368
42327
  }
42369
42328
 
42370
- const version = "1.0.45";
42329
+ const version = "1.0.48";
42371
42330
 
42372
42331
  class Engine3D {
42373
42332
  /**
@@ -54630,7 +54589,7 @@ let GSplatStreamRenderer = class extends RenderNode {
54630
54589
  _transformAData;
54631
54590
  // RGBA32U: count * 4
54632
54591
  _transformBData;
54633
- // RGBA16F: count * 4
54592
+ // RGBA16F: count * 4 (Float16 format)
54634
54593
  _orderData;
54635
54594
  // R32U: size.x * size.y
54636
54595
  _positions;
@@ -54688,7 +54647,8 @@ let GSplatStreamRenderer = class extends RenderNode {
54688
54647
  this._colorData.fill(0);
54689
54648
  this._transformAData = new Uint32Array(total * 4);
54690
54649
  this._transformAData.fill(0);
54691
- this._transformBData = new Array(total * 4).fill(0);
54650
+ this._transformBData = new Uint16Array(total * 4);
54651
+ this._transformBData.fill(0);
54692
54652
  this._orderData = new Uint32Array(total);
54693
54653
  for (let i = 0; i < total; i++) {
54694
54654
  this._orderData[i] = i < totalCount ? i : totalCount > 0 ? totalCount - 1 : 0;
@@ -54838,10 +54798,10 @@ let GSplatStreamRenderer = class extends RenderNode {
54838
54798
  const cBy = r01 * r02 + r11 * r12 + r21 * r22;
54839
54799
  const cBz = r02 * r02 + r12 * r12 + r22 * r22;
54840
54800
  const bidx = idx;
54841
- this._transformBData[bidx + 0] = cAx;
54842
- this._transformBData[bidx + 1] = cAy;
54843
- this._transformBData[bidx + 2] = cAz;
54844
- this._transformBData[bidx + 3] = cBz;
54801
+ this._transformBData[bidx + 0] = toHalfFloat(cAx) & 65535;
54802
+ this._transformBData[bidx + 1] = toHalfFloat(cAy) & 65535;
54803
+ this._transformBData[bidx + 2] = toHalfFloat(cAz) & 65535;
54804
+ this._transformBData[bidx + 3] = toHalfFloat(cBz) & 65535;
54845
54805
  const hx = toHalfFloat(cBx) & 65535;
54846
54806
  const hy = toHalfFloat(cBy) & 65535;
54847
54807
  this._transformAData[idx + 3] = hx | hy << 16;
@@ -62200,6 +62160,11 @@ class PlyStreamParser {
62200
62160
  _onSplatParsed = null;
62201
62161
  _batchSize = 1e3;
62202
62162
  _cancelled = false;
62163
+ // Async processing state
62164
+ _parseTimeoutId = null;
62165
+ _verticesPerChunk = 1e7;
62166
+ // Number of vertices to process per chunk
62167
+ _useIdleCallback = typeof requestIdleCallback !== "undefined";
62203
62168
  constructor(onHeaderParsed, onSplatParsed, batchSize = 1e3) {
62204
62169
  this._onHeaderParsed = onHeaderParsed;
62205
62170
  this._onSplatParsed = onSplatParsed;
@@ -62222,6 +62187,14 @@ class PlyStreamParser {
62222
62187
  */
62223
62188
  cancel() {
62224
62189
  this._cancelled = true;
62190
+ if (this._parseTimeoutId !== null) {
62191
+ if (this._useIdleCallback) {
62192
+ cancelIdleCallback(this._parseTimeoutId);
62193
+ } else {
62194
+ clearTimeout(this._parseTimeoutId);
62195
+ }
62196
+ this._parseTimeoutId = null;
62197
+ }
62225
62198
  }
62226
62199
  /**
62227
62200
  * Check if parsing is cancelled
@@ -62390,21 +62363,36 @@ class PlyStreamParser {
62390
62363
  }
62391
62364
  /**
62392
62365
  * Parse vertices from current data buffer
62366
+ * Entry point - checks if async processing is already scheduled
62393
62367
  */
62394
62368
  _parseVertices() {
62395
62369
  if (!this._header || !this._dataBuffer) return;
62370
+ if (this._parseTimeoutId !== null) {
62371
+ return;
62372
+ }
62373
+ this._parseVerticesChunk();
62374
+ }
62375
+ /**
62376
+ * Parse a chunk of vertices with time and count limits
62377
+ */
62378
+ _parseVerticesChunk() {
62379
+ if (!this._header || !this._dataBuffer || this._cancelled) {
62380
+ this._parseTimeoutId = null;
62381
+ return;
62382
+ }
62396
62383
  const payload = new DataView(this._dataBuffer.buffer, this._dataBuffer.byteOffset, this._dataBuffer.byteLength);
62397
62384
  const vertexCount = this._header.vertexCount;
62398
62385
  const has = (n) => this._properties.find((p) => p.name === n) != null;
62399
62386
  const propIndex = (n) => this._properties.findIndex((p) => p.name === n);
62387
+ const startTime = performance.now();
62388
+ const maxProcessingTime = 5;
62389
+ let processedInThisChunk = 0;
62400
62390
  while (this._processedVertices < vertexCount && !this._cancelled) {
62401
62391
  const v = this._processedVertices;
62402
62392
  const vOffset = v * this._vertexStride;
62403
62393
  if (vOffset + this._vertexStride > this._dataOffset) {
62404
- break;
62405
- }
62406
- if (this._cancelled) {
62407
- break;
62394
+ this._parseTimeoutId = null;
62395
+ return;
62408
62396
  }
62409
62397
  const ix = propIndex("x");
62410
62398
  const iy = propIndex("y");
@@ -62470,12 +62458,47 @@ class PlyStreamParser {
62470
62458
  this._onSplatParsed(splatData, v);
62471
62459
  }
62472
62460
  this._processedVertices++;
62461
+ processedInThisChunk++;
62473
62462
  if (this._processedVertices % this._batchSize === 0) {
62474
- setTimeout(() => {
62475
- this._parseVertices();
62476
- }, 0);
62463
+ this._scheduleNextChunk();
62477
62464
  return;
62478
62465
  }
62466
+ if (processedInThisChunk >= this._verticesPerChunk) {
62467
+ const elapsed = performance.now() - startTime;
62468
+ if (elapsed > maxProcessingTime) {
62469
+ this._scheduleNextChunk();
62470
+ return;
62471
+ }
62472
+ processedInThisChunk = 0;
62473
+ }
62474
+ }
62475
+ this._parseTimeoutId = null;
62476
+ }
62477
+ /**
62478
+ * Schedule next chunk of vertex processing
62479
+ */
62480
+ _scheduleNextChunk() {
62481
+ if (this._cancelled) {
62482
+ this._parseTimeoutId = null;
62483
+ return;
62484
+ }
62485
+ if (this._useIdleCallback) {
62486
+ this._parseTimeoutId = requestIdleCallback((deadline) => {
62487
+ this._parseTimeoutId = null;
62488
+ if (!this._cancelled && deadline.timeRemaining() > 0) {
62489
+ this._parseVerticesChunk();
62490
+ } else if (!this._cancelled) {
62491
+ this._parseTimeoutId = setTimeout(() => {
62492
+ this._parseTimeoutId = null;
62493
+ this._parseVerticesChunk();
62494
+ }, 0);
62495
+ }
62496
+ }, { timeout: 100 });
62497
+ } else {
62498
+ this._parseTimeoutId = setTimeout(() => {
62499
+ this._parseTimeoutId = null;
62500
+ this._parseVerticesChunk();
62501
+ }, 0);
62479
62502
  }
62480
62503
  }
62481
62504
  /**
@@ -71929,14 +71952,19 @@ class SolidColorSky extends LDRTextureCube {
71929
71952
  this.color.b,
71930
71953
  this.color.a
71931
71954
  );
71932
- this._internalTexture.create(this._minSize, this._minSize, numbers, false);
71955
+ const float16Data = new Uint16Array(numbers.length);
71956
+ for (let i = 0; i < numbers.length; i++) {
71957
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71958
+ }
71959
+ this._internalTexture.create(this._minSize, this._minSize, float16Data, false);
71933
71960
  this.createFromTexture(this._minSize, this._internalTexture);
71934
71961
  return this;
71935
71962
  }
71936
71963
  changeColor(color) {
71937
71964
  this._skyColor = color;
71965
+ const numbers = [];
71938
71966
  Engine3D.res.fillColor(
71939
- this._internalTexture.floatArray,
71967
+ numbers,
71940
71968
  this._minSize,
71941
71969
  this._minSize,
71942
71970
  this.color.r,
@@ -71944,10 +71972,14 @@ class SolidColorSky extends LDRTextureCube {
71944
71972
  this.color.b,
71945
71973
  this.color.a
71946
71974
  );
71975
+ const float16Data = new Uint16Array(numbers.length);
71976
+ for (let i = 0; i < numbers.length; i++) {
71977
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71978
+ }
71947
71979
  this._internalTexture.updateTexture(
71948
71980
  this._minSize,
71949
71981
  this._minSize,
71950
- this._internalTexture.floatArray,
71982
+ float16Data,
71951
71983
  false
71952
71984
  );
71953
71985
  this._faceData.uploadTexture(0, this._internalTexture);