@rings-webgpu/core 1.0.46 → 1.0.47

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.46";
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;
@@ -71929,14 +71889,19 @@ class SolidColorSky extends LDRTextureCube {
71929
71889
  this.color.b,
71930
71890
  this.color.a
71931
71891
  );
71932
- this._internalTexture.create(this._minSize, this._minSize, numbers, false);
71892
+ const float16Data = new Uint16Array(numbers.length);
71893
+ for (let i = 0; i < numbers.length; i++) {
71894
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71895
+ }
71896
+ this._internalTexture.create(this._minSize, this._minSize, float16Data, false);
71933
71897
  this.createFromTexture(this._minSize, this._internalTexture);
71934
71898
  return this;
71935
71899
  }
71936
71900
  changeColor(color) {
71937
71901
  this._skyColor = color;
71902
+ const numbers = [];
71938
71903
  Engine3D.res.fillColor(
71939
- this._internalTexture.floatArray,
71904
+ numbers,
71940
71905
  this._minSize,
71941
71906
  this._minSize,
71942
71907
  this.color.r,
@@ -71944,10 +71909,14 @@ class SolidColorSky extends LDRTextureCube {
71944
71909
  this.color.b,
71945
71910
  this.color.a
71946
71911
  );
71912
+ const float16Data = new Uint16Array(numbers.length);
71913
+ for (let i = 0; i < numbers.length; i++) {
71914
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71915
+ }
71947
71916
  this._internalTexture.updateTexture(
71948
71917
  this._minSize,
71949
71918
  this._minSize,
71950
- this._internalTexture.floatArray,
71919
+ float16Data,
71951
71920
  false
71952
71921
  );
71953
71922
  this._faceData.uploadTexture(0, this._internalTexture);