@luma.gl/webgpu 9.1.1 → 9.1.3
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.
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +3 -2
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +7 -3
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +4 -1
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +7 -0
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +2 -2
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/dist.dev.js +71 -56
- package/dist/dist.min.js +4 -4
- package/dist/index.cjs +69 -56
- package/dist/index.cjs.map +3 -3
- package/package.json +2 -2
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +3 -2
- package/src/adapter/helpers/webgpu-parameters.ts +7 -4
- package/src/adapter/resources/webgpu-render-pass.ts +8 -2
- package/src/adapter/resources/webgpu-render-pipeline.ts +8 -0
- package/src/adapter/webgpu-device.ts +2 -3
package/dist/dist.dev.js
CHANGED
|
@@ -57,10 +57,10 @@ var __exports__ = (() => {
|
|
|
57
57
|
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
58
58
|
|
|
59
59
|
// src/adapter/webgpu-adapter.ts
|
|
60
|
-
var
|
|
60
|
+
var import_core19 = __toESM(require_core(), 1);
|
|
61
61
|
|
|
62
62
|
// src/adapter/webgpu-device.ts
|
|
63
|
-
var
|
|
63
|
+
var import_core18 = __toESM(require_core(), 1);
|
|
64
64
|
|
|
65
65
|
// src/adapter/resources/webgpu-buffer.ts
|
|
66
66
|
var import_core = __toESM(require_core(), 1);
|
|
@@ -481,9 +481,10 @@ var __exports__ = (() => {
|
|
|
481
481
|
};
|
|
482
482
|
|
|
483
483
|
// src/adapter/resources/webgpu-render-pipeline.ts
|
|
484
|
-
var
|
|
484
|
+
var import_core10 = __toESM(require_core(), 1);
|
|
485
485
|
|
|
486
486
|
// src/adapter/helpers/webgpu-parameters.ts
|
|
487
|
+
var import_core7 = __toESM(require_core(), 1);
|
|
487
488
|
function addDepthStencil(descriptor) {
|
|
488
489
|
descriptor.depthStencil = descriptor.depthStencil || {
|
|
489
490
|
// required, set something
|
|
@@ -663,7 +664,8 @@ var __exports__ = (() => {
|
|
|
663
664
|
for (const [key, value] of Object.entries(parameters)) {
|
|
664
665
|
const setterFunction = PARAMETER_TABLE[key];
|
|
665
666
|
if (!setterFunction) {
|
|
666
|
-
|
|
667
|
+
import_core7.log.warn(`Illegal parameter ${key}`)();
|
|
668
|
+
continue;
|
|
667
669
|
}
|
|
668
670
|
setterFunction(key, value, pipelineDescriptor);
|
|
669
671
|
}
|
|
@@ -671,7 +673,7 @@ var __exports__ = (() => {
|
|
|
671
673
|
function addColorState(descriptor) {
|
|
672
674
|
descriptor.fragment.targets = descriptor.fragment?.targets || [];
|
|
673
675
|
if (!Array.isArray(descriptor.fragment?.targets)) {
|
|
674
|
-
|
|
676
|
+
import_core7.log.warn("parameters: no targets array")();
|
|
675
677
|
}
|
|
676
678
|
if (descriptor.fragment?.targets?.length === 0) {
|
|
677
679
|
descriptor.fragment.targets?.push({});
|
|
@@ -680,7 +682,7 @@ var __exports__ = (() => {
|
|
|
680
682
|
}
|
|
681
683
|
|
|
682
684
|
// src/adapter/helpers/get-bind-group.ts
|
|
683
|
-
var
|
|
685
|
+
var import_core8 = __toESM(require_core(), 1);
|
|
684
686
|
function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
|
|
685
687
|
const entries = getBindGroupEntries(bindings, shaderLayout);
|
|
686
688
|
return device.createBindGroup({
|
|
@@ -693,7 +695,7 @@ var __exports__ = (() => {
|
|
|
693
695
|
(binding) => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase()
|
|
694
696
|
);
|
|
695
697
|
if (!bindingLayout) {
|
|
696
|
-
|
|
698
|
+
import_core8.log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
|
|
697
699
|
}
|
|
698
700
|
return bindingLayout || null;
|
|
699
701
|
}
|
|
@@ -712,7 +714,7 @@ var __exports__ = (() => {
|
|
|
712
714
|
return entries;
|
|
713
715
|
}
|
|
714
716
|
function getBindGroupEntry(binding, index, options) {
|
|
715
|
-
if (binding instanceof
|
|
717
|
+
if (binding instanceof import_core8.Buffer) {
|
|
716
718
|
return {
|
|
717
719
|
binding: index,
|
|
718
720
|
resource: {
|
|
@@ -720,12 +722,12 @@ var __exports__ = (() => {
|
|
|
720
722
|
}
|
|
721
723
|
};
|
|
722
724
|
}
|
|
723
|
-
if (binding instanceof
|
|
725
|
+
if (binding instanceof import_core8.Sampler) {
|
|
724
726
|
return {
|
|
725
727
|
binding: index,
|
|
726
728
|
resource: binding.handle
|
|
727
729
|
};
|
|
728
|
-
} else if (binding instanceof
|
|
730
|
+
} else if (binding instanceof import_core8.Texture) {
|
|
729
731
|
if (options?.sampler) {
|
|
730
732
|
return {
|
|
731
733
|
binding: index,
|
|
@@ -741,7 +743,7 @@ var __exports__ = (() => {
|
|
|
741
743
|
}
|
|
742
744
|
|
|
743
745
|
// src/adapter/helpers/get-vertex-buffer-layout.ts
|
|
744
|
-
var
|
|
746
|
+
var import_core9 = __toESM(require_core(), 1);
|
|
745
747
|
function getWebGPUVertexFormat(format) {
|
|
746
748
|
if (format.endsWith("-webgl")) {
|
|
747
749
|
throw new Error(`WebGPU does not support vertex format ${format}`);
|
|
@@ -755,26 +757,27 @@ var __exports__ = (() => {
|
|
|
755
757
|
const vertexAttributes = [];
|
|
756
758
|
let stepMode = "vertex";
|
|
757
759
|
let byteStride = 0;
|
|
758
|
-
|
|
760
|
+
let format = mapping.format;
|
|
759
761
|
if (mapping.attributes) {
|
|
760
762
|
for (const attributeMapping of mapping.attributes) {
|
|
761
763
|
const attributeName = attributeMapping.attribute;
|
|
762
764
|
const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
|
|
763
765
|
const location = attributeLayout?.location;
|
|
766
|
+
format = attributeMapping.format || mapping.format;
|
|
764
767
|
stepMode = attributeLayout?.stepMode || (attributeLayout?.name.startsWith("instance") ? "instance" : "vertex");
|
|
765
768
|
vertexAttributes.push({
|
|
766
|
-
format: getWebGPUVertexFormat(
|
|
769
|
+
format: getWebGPUVertexFormat(format),
|
|
767
770
|
offset: attributeMapping.byteOffset,
|
|
768
771
|
shaderLocation: location
|
|
769
772
|
});
|
|
770
|
-
byteStride += (0,
|
|
773
|
+
byteStride += (0, import_core9.decodeVertexFormat)(format).byteLength;
|
|
771
774
|
}
|
|
772
775
|
} else {
|
|
773
776
|
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
|
|
774
777
|
if (!attributeLayout) {
|
|
775
778
|
continue;
|
|
776
779
|
}
|
|
777
|
-
byteStride = (0,
|
|
780
|
+
byteStride = (0, import_core9.decodeVertexFormat)(format).byteLength;
|
|
778
781
|
stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
|
|
779
782
|
vertexAttributes.push({
|
|
780
783
|
format: getWebGPUVertexFormat(format),
|
|
@@ -792,7 +795,7 @@ var __exports__ = (() => {
|
|
|
792
795
|
for (const attribute of shaderLayout.attributes) {
|
|
793
796
|
if (!usedAttributes.has(attribute.name)) {
|
|
794
797
|
vertexBufferLayouts.push({
|
|
795
|
-
arrayStride: (0,
|
|
798
|
+
arrayStride: (0, import_core9.decodeVertexFormat)("float32x3").byteLength,
|
|
796
799
|
stepMode: attribute.stepMode || (attribute.name.startsWith("instance") ? "instance" : "vertex"),
|
|
797
800
|
attributes: [
|
|
798
801
|
{
|
|
@@ -809,7 +812,7 @@ var __exports__ = (() => {
|
|
|
809
812
|
function findAttributeLayout(shaderLayout, name, attributeNames) {
|
|
810
813
|
const attribute = shaderLayout.attributes.find((attribute_) => attribute_.name === name);
|
|
811
814
|
if (!attribute) {
|
|
812
|
-
|
|
815
|
+
import_core9.log.warn(`Unknown attribute ${name}`)();
|
|
813
816
|
return null;
|
|
814
817
|
}
|
|
815
818
|
if (attributeNames.has(name)) {
|
|
@@ -820,7 +823,7 @@ var __exports__ = (() => {
|
|
|
820
823
|
}
|
|
821
824
|
|
|
822
825
|
// src/adapter/resources/webgpu-render-pipeline.ts
|
|
823
|
-
var WebGPURenderPipeline = class extends
|
|
826
|
+
var WebGPURenderPipeline = class extends import_core10.RenderPipeline {
|
|
824
827
|
device;
|
|
825
828
|
handle;
|
|
826
829
|
vs;
|
|
@@ -835,14 +838,14 @@ var __exports__ = (() => {
|
|
|
835
838
|
this.handle = this.props.handle;
|
|
836
839
|
if (!this.handle) {
|
|
837
840
|
const descriptor = this._getRenderPipelineDescriptor();
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
+
import_core10.log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
|
|
842
|
+
import_core10.log.probe(1, JSON.stringify(descriptor, null, 2))();
|
|
843
|
+
import_core10.log.groupEnd(1)();
|
|
841
844
|
this.device.handle.pushErrorScope("validation");
|
|
842
845
|
this.handle = this.device.handle.createRenderPipeline(descriptor);
|
|
843
846
|
this.device.handle.popErrorScope().then((error) => {
|
|
844
847
|
if (error) {
|
|
845
|
-
|
|
848
|
+
import_core10.log.error(`${this} creation failed:
|
|
846
849
|
"${error.message}"`, this, this.props.vs?.source)();
|
|
847
850
|
}
|
|
848
851
|
});
|
|
@@ -869,7 +872,7 @@ var __exports__ = (() => {
|
|
|
869
872
|
webgpuRenderPass.handle.setPipeline(this.handle);
|
|
870
873
|
this.device.handle.popErrorScope().then((error) => {
|
|
871
874
|
if (error) {
|
|
872
|
-
|
|
875
|
+
import_core10.log.error(`${this} setPipeline failed:
|
|
873
876
|
"${error.message}"`, this)();
|
|
874
877
|
}
|
|
875
878
|
});
|
|
@@ -933,14 +936,21 @@ var __exports__ = (() => {
|
|
|
933
936
|
},
|
|
934
937
|
layout: "auto"
|
|
935
938
|
};
|
|
939
|
+
if (this.props.parameters.depthWriteEnabled && this.props.parameters.depthCompare) {
|
|
940
|
+
descriptor.depthStencil = {
|
|
941
|
+
format: "depth24plus",
|
|
942
|
+
depthWriteEnabled: this.props.parameters.depthWriteEnabled,
|
|
943
|
+
depthCompare: this.props.parameters.depthCompare
|
|
944
|
+
};
|
|
945
|
+
}
|
|
936
946
|
applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
|
|
937
947
|
return descriptor;
|
|
938
948
|
}
|
|
939
949
|
};
|
|
940
950
|
|
|
941
951
|
// src/adapter/resources/webgpu-framebuffer.ts
|
|
942
|
-
var
|
|
943
|
-
var WebGPUFramebuffer = class extends
|
|
952
|
+
var import_core11 = __toESM(require_core(), 1);
|
|
953
|
+
var WebGPUFramebuffer = class extends import_core11.Framebuffer {
|
|
944
954
|
device;
|
|
945
955
|
colorAttachments = [];
|
|
946
956
|
depthStencilAttachment = null;
|
|
@@ -954,8 +964,8 @@ var __exports__ = (() => {
|
|
|
954
964
|
};
|
|
955
965
|
|
|
956
966
|
// src/adapter/resources/webgpu-compute-pipeline.ts
|
|
957
|
-
var
|
|
958
|
-
var WebGPUComputePipeline = class extends
|
|
967
|
+
var import_core12 = __toESM(require_core(), 1);
|
|
968
|
+
var WebGPUComputePipeline = class extends import_core12.ComputePipeline {
|
|
959
969
|
device;
|
|
960
970
|
handle;
|
|
961
971
|
/** For internal use to create BindGroups */
|
|
@@ -993,8 +1003,8 @@ var __exports__ = (() => {
|
|
|
993
1003
|
};
|
|
994
1004
|
|
|
995
1005
|
// src/adapter/resources/webgpu-render-pass.ts
|
|
996
|
-
var
|
|
997
|
-
var WebGPURenderPass = class extends
|
|
1006
|
+
var import_core13 = __toESM(require_core(), 1);
|
|
1007
|
+
var WebGPURenderPass = class extends import_core13.RenderPass {
|
|
998
1008
|
device;
|
|
999
1009
|
handle;
|
|
1000
1010
|
/** Active pipeline */
|
|
@@ -1023,14 +1033,14 @@ var __exports__ = (() => {
|
|
|
1023
1033
|
this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
1024
1034
|
this.device.handle.popErrorScope().then((error) => {
|
|
1025
1035
|
if (error) {
|
|
1026
|
-
|
|
1036
|
+
import_core13.log.error(`${this} creation failed:
|
|
1027
1037
|
"${error.message}"`, this)();
|
|
1028
1038
|
}
|
|
1029
1039
|
});
|
|
1030
1040
|
this.handle.label = this.props.id;
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1041
|
+
import_core13.log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)();
|
|
1042
|
+
import_core13.log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))();
|
|
1043
|
+
import_core13.log.groupEnd(3)();
|
|
1034
1044
|
}
|
|
1035
1045
|
destroy() {
|
|
1036
1046
|
}
|
|
@@ -1126,7 +1136,9 @@ var __exports__ = (() => {
|
|
|
1126
1136
|
(colorAttachment, index) => ({
|
|
1127
1137
|
// clear values
|
|
1128
1138
|
loadOp: this.props.clearColor !== false ? "clear" : "load",
|
|
1129
|
-
|
|
1139
|
+
clearValue: convertColor(
|
|
1140
|
+
this.props.clearColors?.[index] || this.props.clearColor || import_core13.RenderPass.defaultClearColor
|
|
1141
|
+
),
|
|
1130
1142
|
storeOp: this.props.discard ? "discard" : "store",
|
|
1131
1143
|
// ...colorAttachment,
|
|
1132
1144
|
view: colorAttachment.handle
|
|
@@ -1157,10 +1169,13 @@ var __exports__ = (() => {
|
|
|
1157
1169
|
return renderPassDescriptor;
|
|
1158
1170
|
}
|
|
1159
1171
|
};
|
|
1172
|
+
function convertColor(color) {
|
|
1173
|
+
return { r: color[0], g: color[1], b: color[2], a: color[3] };
|
|
1174
|
+
}
|
|
1160
1175
|
|
|
1161
1176
|
// src/adapter/resources/webgpu-compute-pass.ts
|
|
1162
|
-
var
|
|
1163
|
-
var WebGPUComputePass = class extends
|
|
1177
|
+
var import_core14 = __toESM(require_core(), 1);
|
|
1178
|
+
var WebGPUComputePass = class extends import_core14.ComputePass {
|
|
1164
1179
|
device;
|
|
1165
1180
|
handle;
|
|
1166
1181
|
_webgpuPipeline = null;
|
|
@@ -1235,7 +1250,7 @@ var __exports__ = (() => {
|
|
|
1235
1250
|
};
|
|
1236
1251
|
|
|
1237
1252
|
// src/adapter/resources/webgpu-vertex-array.ts
|
|
1238
|
-
var
|
|
1253
|
+
var import_core15 = __toESM(require_core(), 1);
|
|
1239
1254
|
|
|
1240
1255
|
// ../../node_modules/@probe.gl/env/dist/lib/globals.js
|
|
1241
1256
|
var document_ = globalThis.document || {};
|
|
@@ -1290,7 +1305,7 @@ var __exports__ = (() => {
|
|
|
1290
1305
|
}
|
|
1291
1306
|
|
|
1292
1307
|
// src/adapter/resources/webgpu-vertex-array.ts
|
|
1293
|
-
var WebGPUVertexArray = class extends
|
|
1308
|
+
var WebGPUVertexArray = class extends import_core15.VertexArray {
|
|
1294
1309
|
get [Symbol.toStringTag]() {
|
|
1295
1310
|
return "WebGPUVertexArray";
|
|
1296
1311
|
}
|
|
@@ -1319,7 +1334,7 @@ var __exports__ = (() => {
|
|
|
1319
1334
|
const webgpuRenderPass = renderPass;
|
|
1320
1335
|
const webgpuIndexBuffer = this.indexBuffer;
|
|
1321
1336
|
if (webgpuIndexBuffer?.handle) {
|
|
1322
|
-
|
|
1337
|
+
import_core15.log.info(
|
|
1323
1338
|
3,
|
|
1324
1339
|
"setting index buffer",
|
|
1325
1340
|
webgpuIndexBuffer?.handle,
|
|
@@ -1334,7 +1349,7 @@ var __exports__ = (() => {
|
|
|
1334
1349
|
for (let location = 0; location < this.maxVertexAttributes; location++) {
|
|
1335
1350
|
const webgpuBuffer = this.attributes[location];
|
|
1336
1351
|
if (webgpuBuffer?.handle) {
|
|
1337
|
-
|
|
1352
|
+
import_core15.log.info(3, `setting vertex buffer ${location}`, webgpuBuffer?.handle)();
|
|
1338
1353
|
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer?.handle);
|
|
1339
1354
|
}
|
|
1340
1355
|
}
|
|
@@ -1352,8 +1367,8 @@ var __exports__ = (() => {
|
|
|
1352
1367
|
};
|
|
1353
1368
|
|
|
1354
1369
|
// src/adapter/webgpu-canvas-context.ts
|
|
1355
|
-
var
|
|
1356
|
-
var WebGPUCanvasContext = class extends
|
|
1370
|
+
var import_core16 = __toESM(require_core(), 1);
|
|
1371
|
+
var WebGPUCanvasContext = class extends import_core16.CanvasContext {
|
|
1357
1372
|
device;
|
|
1358
1373
|
gpuCanvasContext;
|
|
1359
1374
|
/** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
|
|
@@ -1410,7 +1425,7 @@ var __exports__ = (() => {
|
|
|
1410
1425
|
colorSpace: this.props.colorSpace,
|
|
1411
1426
|
alphaMode: this.props.alphaMode
|
|
1412
1427
|
});
|
|
1413
|
-
|
|
1428
|
+
import_core16.log.log(1, `${this} Resized ${oldWidth}x${oldHeight} => ${newWidth}x${newHeight}px`)();
|
|
1414
1429
|
}
|
|
1415
1430
|
}
|
|
1416
1431
|
resize(options) {
|
|
@@ -1447,8 +1462,8 @@ var __exports__ = (() => {
|
|
|
1447
1462
|
};
|
|
1448
1463
|
|
|
1449
1464
|
// src/adapter/resources/webgpu-query-set.ts
|
|
1450
|
-
var
|
|
1451
|
-
var WebGPUQuerySet = class extends
|
|
1465
|
+
var import_core17 = __toESM(require_core(), 1);
|
|
1466
|
+
var WebGPUQuerySet = class extends import_core17.QuerySet {
|
|
1452
1467
|
device;
|
|
1453
1468
|
handle;
|
|
1454
1469
|
constructor(device, props) {
|
|
@@ -1467,7 +1482,7 @@ var __exports__ = (() => {
|
|
|
1467
1482
|
};
|
|
1468
1483
|
|
|
1469
1484
|
// src/adapter/webgpu-device.ts
|
|
1470
|
-
var WebGPUDevice = class extends
|
|
1485
|
+
var WebGPUDevice = class extends import_core18.Device {
|
|
1471
1486
|
/** type of this device */
|
|
1472
1487
|
type = "webgpu";
|
|
1473
1488
|
/** The underlying WebGPU device */
|
|
@@ -1505,8 +1520,8 @@ var __exports__ = (() => {
|
|
|
1505
1520
|
this._isLost = true;
|
|
1506
1521
|
resolve({ reason: "destroyed", message: lostInfo.message });
|
|
1507
1522
|
});
|
|
1508
|
-
|
|
1509
|
-
|
|
1523
|
+
const canvasContextProps = import_core18.Device._getCanvasContextProps(props);
|
|
1524
|
+
if (canvasContextProps) {
|
|
1510
1525
|
this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
|
|
1511
1526
|
}
|
|
1512
1527
|
}
|
|
@@ -1630,7 +1645,7 @@ var __exports__ = (() => {
|
|
|
1630
1645
|
for (const feature of WEBGPU_ALWAYS_FEATURES) {
|
|
1631
1646
|
features.add(feature);
|
|
1632
1647
|
}
|
|
1633
|
-
return new
|
|
1648
|
+
return new import_core18.DeviceFeatures(Array.from(features), this.props._disabledFeatures);
|
|
1634
1649
|
}
|
|
1635
1650
|
_getDeviceSpecificTextureFormatCapabilities(capabilities) {
|
|
1636
1651
|
const { format } = capabilities;
|
|
@@ -1682,7 +1697,7 @@ var __exports__ = (() => {
|
|
|
1682
1697
|
};
|
|
1683
1698
|
|
|
1684
1699
|
// src/adapter/webgpu-adapter.ts
|
|
1685
|
-
var WebGPUAdapter = class extends
|
|
1700
|
+
var WebGPUAdapter = class extends import_core19.Adapter {
|
|
1686
1701
|
/** type of device's created by this adapter */
|
|
1687
1702
|
type = "webgpu";
|
|
1688
1703
|
constructor() {
|
|
@@ -1699,7 +1714,7 @@ var __exports__ = (() => {
|
|
|
1699
1714
|
"WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu"
|
|
1700
1715
|
);
|
|
1701
1716
|
}
|
|
1702
|
-
|
|
1717
|
+
import_core19.log.groupCollapsed(1, "WebGPUDevice created")();
|
|
1703
1718
|
const adapter = await navigator.gpu.requestAdapter({
|
|
1704
1719
|
powerPreference: "high-performance"
|
|
1705
1720
|
// forceSoftware: false
|
|
@@ -1709,7 +1724,7 @@ var __exports__ = (() => {
|
|
|
1709
1724
|
}
|
|
1710
1725
|
const adapterInfo = adapter.info || // @ts-ignore Chrome has removed this function
|
|
1711
1726
|
await adapter.requestAdapterInfo?.();
|
|
1712
|
-
|
|
1727
|
+
import_core19.log.probe(2, "Adapter available", adapterInfo)();
|
|
1713
1728
|
const requiredFeatures = [];
|
|
1714
1729
|
const requiredLimits = {};
|
|
1715
1730
|
if (props._requestMaxLimits) {
|
|
@@ -1729,14 +1744,14 @@ var __exports__ = (() => {
|
|
|
1729
1744
|
requiredFeatures,
|
|
1730
1745
|
requiredLimits
|
|
1731
1746
|
});
|
|
1732
|
-
|
|
1747
|
+
import_core19.log.probe(1, "GPUDevice available")();
|
|
1733
1748
|
const device = new WebGPUDevice(props, gpuDevice, adapter, adapterInfo);
|
|
1734
|
-
|
|
1749
|
+
import_core19.log.probe(
|
|
1735
1750
|
1,
|
|
1736
1751
|
"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features"
|
|
1737
1752
|
)();
|
|
1738
|
-
|
|
1739
|
-
|
|
1753
|
+
import_core19.log.table(1, device.info)();
|
|
1754
|
+
import_core19.log.groupEnd(1)();
|
|
1740
1755
|
return device;
|
|
1741
1756
|
}
|
|
1742
1757
|
async attach(handle) {
|
package/dist/dist.min.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
6
|
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
var __exports__=(()=>{var
|
|
8
|
-
"${i.message}"`,this,this.props.source)()}),this.handle.label=this.props.id,this._checkCompilationError()}get asyncCompilationStatus(){return this.getCompilationInfo().then(()=>this.compilationStatus)}async _checkCompilationError(){let e=await this.getCompilationInfo(),t=Boolean(e.find(r=>r.type==="error"));this.compilationStatus=t?"error":"success",this.debugShader(),this.compilationStatus==="error"&&L.log.error("Shader compilation error",e)()}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}};var w=h(
|
|
7
|
+
var __exports__=(()=>{var Ce=Object.create;var F=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Ge=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Te=(n,e)=>{for(var t in e)F(n,t,{get:e[t],enumerable:!0})},R=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Pe(e))!Ae.call(n,i)&&i!==t&&F(n,i,{get:()=>e[i],enumerable:!(r=Ee(e,i))||r.enumerable});return n},O=(n,e,t)=>(R(n,e,"default"),t&&R(t,e,"default")),d=(n,e,t)=>(t=n!=null?Ce(Be(n)):{},R(e||!n||!n.__esModule?F(t,"default",{value:n,enumerable:!0}):t,n)),Le=n=>R(F({},"__esModule",{value:!0}),n);var h=Ge((Me,re)=>{re.exports=globalThis.luma});var W={};Te(W,{WebGPUBuffer:()=>b,WebGPUDevice:()=>S,WebGPUSampler:()=>c,WebGPUShader:()=>P,WebGPUTexture:()=>E,webgpuAdapter:()=>xe});O(W,d(h(),1));var f=d(h(),1);var I=d(h(),1);var U=d(h(),1);function _e(n){return n.byteLength||n.data?.byteLength||0}var b=class extends U.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=_e(t);let r=Boolean(t.data),i=Math.ceil(this.byteLength/4)*4;this.handle=this.props.handle||this.device.handle.createBuffer({size:i,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:this.props.mappedAtCreation||r,label:this.props.id}),t.data&&this._writeMapped(t.data),r&&!t.mappedAtCreation&&this.handle.unmap()}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){this.device.handle.queue.writeBuffer(this.handle,t,e.buffer,e.byteOffset,e.byteLength)}async readAsync(e=0,t=this.byteLength){let r=new b(this.device,{usage:U.Buffer.MAP_READ|U.Buffer.COPY_DST,byteLength:t}),i=this.device.handle.createCommandEncoder();i.copyBufferToBuffer(this.handle,e,r.handle,0,t),this.device.handle.queue.submit([i.finish()]),await r.handle.mapAsync(GPUMapMode.READ,e,t);let s=r.handle.getMappedRange().slice(0);return r.handle.unmap(),r.destroy(),new Uint8Array(s)}_writeMapped(e){let t=this.handle.getMappedRange();new e.constructor(t).set(e)}mapAsync(e,t=0,r){return this.handle.mapAsync(e,t,r)}getMappedRange(e=0,t){return this.handle.getMappedRange(e,t)}unmap(){this.handle.unmap()}};var v=d(h(),1);function C(n){if(n.includes("webgl"))throw new Error("webgl-only format");return n}var ne=d(h(),1),c=class extends ne.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let r={...this.props,mipmapFilter:void 0};t.type!=="comparison-sampler"&&delete r.compare,t.mipmapFilter&&t.mipmapFilter!=="none"&&(r.mipmapFilter=t.mipmapFilter),this.handle=this.handle||this.device.handle.createSampler(r),this.handle.label=this.props.id}destroy(){this.handle=null}};var ie=d(h(),1),T=class extends ie.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.handle=this.handle||this.texture.handle.createView({format:t.format||this.texture.format,dimension:t.dimension||this.texture.dimension,aspect:t.aspect,baseMipLevel:t.baseMipLevel,mipLevelCount:t.mipLevelCount,baseArrayLayer:t.baseArrayLayer,arrayLayerCount:t.arrayLayerCount}),this.handle.label=this.props.id}destroy(){this.handle=null}};var De={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},E=class extends v.Texture{device;handle;sampler;view;constructor(e,t){super(e,t),this.device=e;let r={...this.props};t.data&&(r.data=t.data),this.initialize(r)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new T(this.device,{...e,texture:this})}initialize(e){this.handle=this.props.handle||this.createHandle(),this.handle.label||=this.id,this.props.data&&(v.Texture.isExternalImage(this.props.data)?this.copyExternalImage({image:this.props.data}):this.setData({data:this.props.data})),this.width=this.handle.width,this.height=this.handle.height,this.sampler=e.sampler instanceof c?e.sampler:new c(this.device,e.sampler||{}),this.view=new T(this.device,{...this.props,texture:this})}createHandle(){let e=this.props.width||this.props.data?.width||1,t=this.props.height||this.props.data?.height||1;return this.device.handle.createTexture({label:this.id,size:{width:e,height:t,depthOrArrayLayers:this.depth},usage:this.props.usage||v.Texture.TEXTURE|v.Texture.COPY_DST,dimension:De[this.dimension],format:C(this.format),mipLevelCount:this.mipLevels,sampleCount:this.props.samples})}createGPUTextureView(){return this.handle.createView({label:this.id})}setSampler(e){return this.sampler=e instanceof c?e:new c(this.device,e),this}setTexture1DData(e){throw new Error("not implemented")}setTexture2DData(e,t,r){throw new Error("not implemented")}setTexture3DData(e,t,r){throw new Error("not implemented")}setTextureCubeData(e,t){throw new Error("not implemented")}setTextureArrayData(e){throw new Error("not implemented")}setTextureCubeArrayData(e){throw new Error("not implemented")}setData(e){if(ArrayBuffer.isView(e.data)){let t=new Uint8ClampedArray(e.data.buffer),r=new ImageData(t,this.width,this.height);return this.copyExternalImage({image:r})}throw new Error("Texture.setData: Use CommandEncoder to upload data to texture in WebGPU")}copyExternalImage(e){let t=v.Texture.getExternalImageSize(e.image),r={...v.Texture.defaultCopyExternalImageOptions,...t,...e},{image:i,sourceX:s,sourceY:a,width:o,height:p,depth:l,mipLevel:g,x:u,y:G,z:J,aspect:we,colorSpace:ye,premultipliedAlpha:ve,flipY:Se}=r;return this.device.handle.queue.copyExternalImageToTexture({source:i,origin:[s,a],flipY:Se},{texture:this.handle,origin:[u,G,J],mipLevel:g,aspect:we,colorSpace:ye,premultipliedAlpha:ve},[o,p,l]),{width:o,height:p}}};var se=d(h(),1);var M=class extends se.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof c?e:new c(this.device,e),this}};var L=d(h(),1),P=class extends L.Shader{device;handle;constructor(e,t){super(e,t),this.device=e;let r=t.source.includes("#version");if(this.props.language==="glsl"||r)throw new Error("GLSL shaders are not supported in WebGPU");this.device.handle.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createShaderModule({code:t.source}),this.device.handle.popErrorScope().then(i=>{i&&L.log.error(`${this} creation failed:
|
|
8
|
+
"${i.message}"`,this,this.props.source)()}),this.handle.label=this.props.id,this._checkCompilationError()}get asyncCompilationStatus(){return this.getCompilationInfo().then(()=>this.compilationStatus)}async _checkCompilationError(){let e=await this.getCompilationInfo(),t=Boolean(e.find(r=>r.type==="error"));this.compilationStatus=t?"error":"success",this.debugShader(),this.compilationStatus==="error"&&L.log.error("Shader compilation error",e)()}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}};var w=d(h(),1);var Z=d(h(),1);function m(n){return n.depthStencil=n.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},n.depthStencil}function k(n){return m(n).stencilFront}function V(n){return m(n).stencilBack}var Ie={cullMode:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(n,e,t)=>{let r=m(t);r.depthWriteEnabled=e},depthCompare:(n,e,t)=>{let r=m(t);r.depthCompare=e},depthFormat:(n,e,t)=>{let r=m(t);r.format=e},depthBias:(n,e,t)=>{let r=m(t);r.depthBias=e},depthBiasSlopeScale:(n,e,t)=>{let r=m(t);r.depthBiasSlopeScale=e},depthBiasClamp:(n,e,t)=>{let r=m(t);r.depthBiasClamp=e},stencilReadMask:(n,e,t)=>{let r=m(t);r.stencilReadMask=e},stencilWriteMask:(n,e,t)=>{let r=m(t);r.stencilWriteMask=e},stencilCompare:(n,e,t)=>{let r=k(t),i=V(t);r.compare=e,i.compare=e},stencilPassOperation:(n,e,t)=>{let r=k(t),i=V(t);r.passOp=e,i.passOp=e},stencilFailOperation:(n,e,t)=>{let r=k(t),i=V(t);r.failOp=e,i.failOp=e},stencilDepthFailOperation:(n,e,t)=>{let r=k(t),i=V(t);r.depthFailOp=e,i.depthFailOp=e},sampleCount:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(n,e,t)=>{let r=ae(t);r[0].writeMask=e},blendColorOperation:(n,e,t)=>{ae(t)}},We={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"};function oe(n,e={}){Object.assign(n,{...We,...n}),Re(n,e)}function Re(n,e){for(let[t,r]of Object.entries(e)){let i=Ie[t];if(!i){Z.log.warn(`Illegal parameter ${t}`)();continue}i(t,r,n)}}function ae(n){return n.fragment.targets=n.fragment?.targets||[],Array.isArray(n.fragment?.targets)||Z.log.warn("parameters: no targets array")(),n.fragment?.targets?.length===0&&n.fragment.targets?.push({}),n.fragment?.targets}var x=d(h(),1);function $(n,e,t,r){let i=Fe(r,t);return n.createBindGroup({layout:e,entries:i})}function he(n,e){let t=n.bindings.find(r=>r.name===e||`${r.name}uniforms`===e.toLocaleLowerCase());return t||x.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),t||null}function Fe(n,e){let t=[];for(let[r,i]of Object.entries(n)){let s=he(e,r);s&&t.push(de(i,s.location)),s=he(e,`${r}Sampler`),s&&t.push(de(i,s.location,{sampler:!0}))}return t}function de(n,e,t){if(n instanceof x.Buffer)return{binding:e,resource:{buffer:n.handle}};if(n instanceof x.Sampler)return{binding:e,resource:n.handle};if(n instanceof x.Texture)return t?.sampler?{binding:e,resource:n.sampler.handle}:{binding:e,resource:n.handle.createView({label:"bind-group-auto-created"})};throw new Error("invalid binding")}var B=d(h(),1);function K(n){if(n.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${n}`);return n}function pe(n,e){let t=[],r=new Set;for(let i of e){let s=[],a="vertex",o=0,p=i.format;if(i.attributes)for(let l of i.attributes){let g=l.attribute,u=le(n,g,r),G=u?.location;p=l.format||i.format,a=u?.stepMode||(u?.name.startsWith("instance")?"instance":"vertex"),s.push({format:K(p),offset:l.byteOffset,shaderLocation:G}),o+=(0,B.decodeVertexFormat)(p).byteLength}else{let l=le(n,i.name,r);if(!l)continue;o=(0,B.decodeVertexFormat)(p).byteLength,a=l.stepMode||(l.name.startsWith("instance")?"instance":"vertex"),s.push({format:K(p),offset:0,shaderLocation:l.location})}t.push({arrayStride:i.byteStride||o,stepMode:a,attributes:s})}for(let i of n.attributes)r.has(i.name)||t.push({arrayStride:(0,B.decodeVertexFormat)("float32x3").byteLength,stepMode:i.stepMode||(i.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:K("float32x3"),offset:0,shaderLocation:i.location}]});return t}function le(n,e,t){let r=n.attributes.find(i=>i.name===e);if(!r)return B.log.warn(`Unknown attribute ${e}`)(),null;if(t.has(e))throw new Error(`Duplicate attribute ${e}`);return t.add(e),r}var q=class extends w.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let r=this._getRenderPipelineDescriptor();w.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),w.log.probe(1,JSON.stringify(r,null,2))(),w.log.groupEnd(1)(),this.device.handle.pushErrorScope("validation"),this.handle=this.device.handle.createRenderPipeline(r),this.device.handle.popErrorScope().then(i=>{i&&w.log.error(`${this} creation failed:
|
|
9
9
|
"${i.message}"`,this,this.props.vs?.source)()})}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;this.device.handle.pushErrorScope("validation"),t.handle.setPipeline(this.handle),this.device.handle.popErrorScope().then(i=>{i&&w.log.error(`${this} setPipeline failed:
|
|
10
|
-
"${i.message}"`,this)()});let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup
|
|
11
|
-
"${a.message}"`,this)()}),this.handle.label=this.props.id,y.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),y.log.probe(3,JSON.stringify(i,null,2))(),y.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.handle.setPipeline(this.pipeline.handle)}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,i){this.handle.setIndexBuffer(e.handle,t,r,i)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,t.handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:i,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),i&&this.handle.setScissorRect(i[0],i[1],i[2],i[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4],s[5])}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map((r,i)=>({loadOp:this.props.clearColor!==!1?"clear":"load",colorClearValue:this.props.clearColors?.[i]||this.props.clearColor||y.RenderPass.defaultClearColor,storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),this.props.clearDepth!==!1&&(r.depthClearValue=this.props.clearDepth),!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}};var ue=h(o(),1),Q=class extends ue.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let i=t.timestampQuerySet;i&&(r={querySet:i.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder?.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}};var D=h(o(),1);var ht=globalThis.document||{},dt=globalThis.process||{},lt=globalThis.console,me=globalThis.navigator||{};function N(n){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=n||e;return Boolean(t&&t.indexOf("Electron")>=0)}function fe(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||N()}function K(n){return!n&&!fe()?"Node":N(n)?"Electron":(n||me.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var j=class extends D.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let i=e,s=this.indexBuffer;s?.handle&&(D.log.info(3,"setting index buffer",s?.handle,s?.indexType)(),i.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let l=this.attributes[a];l?.handle&&(D.log.info(3,`setting vertex buffer ${a}`,l?.handle)(),i.handle.setVertexBuffer(a,l?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return K()==="Chrome"}};var Y=h(o(),1);var _=class extends Y.CanvasContext{device;gpuCanvasContext;format=navigator.gpu.getPreferredCanvasFormat();depthStencilFormat="depth24plus";depthStencilAttachment=null;get[Symbol.toStringTag](){return"WebGPUCanvasContext"}constructor(e,t,r){super(r),this.device=e,this.width=-1,this.height=-1,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this.gpuCanvasContext=this.canvas.getContext("webgpu"),this.format="bgra8unorm"}destroy(){this.gpuCanvasContext.unconfigure()}getCurrentFramebuffer(){this.update();let e=this.getCurrentTexture();return this.width=e.width,this.height=e.height,this._createDepthStencilAttachment(),new A(this.device,{colorAttachments:[e],depthStencilAttachment:this.depthStencilAttachment})}update(){let e=this.width,t=this.height,[r,i]=this.getPixelSize();(r!==e||i!==t)&&(this.width=r,this.height=i,this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.gpuCanvasContext.configure({device:this.device.handle,format:C(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),Y.log.log(1,`${this} Resized ${e}x${t} => ${r}x${i}px`)())}resize(e){if(this.update(),!!this.device.handle&&this.canvas){let t=this.getDevicePixelRatio(e?.useDevicePixels);this.setDevicePixelRatio(t,e);return}}getCurrentTexture(){return this.device.createTexture({id:`${this.id}#color-texture`,handle:this.gpuCanvasContext.getCurrentTexture(),format:this.format})}_createDepthStencilAttachment(){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,format:this.depthStencilFormat,width:this.width,height:this.height,usage:GPUTextureUsage.RENDER_ATTACHMENT})),this.depthStencilAttachment}};var ge=h(o(),1),H=class extends ge.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}};var S=class extends X.Device{type="webgpu";handle;adapter;adapterInfo;features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder=null;renderPass=null;constructor(e,t,r,i){if(super({...e,id:e.id||"webgpu-device"}),this.handle=t,this.adapter=r,this.adapterInfo=i,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,t.addEventListener("uncapturederror",s=>{let a=s instanceof GPUUncapturedErrorEvent?s.error.message:"Unknown WebGPU error";if(this.reportError(new Error(a)),this.props.debug)debugger;s.preventDefault()}),this.lost=new Promise(async s=>{let a=await this.handle.lost;this._isLost=!0,s({reason:"destroyed",message:a.message})}),e.createCanvasContext){let s=e.createCanvasContext===!0?{}:e.createCanvasContext;this.canvasContext=new _(this,this.adapter,s)}}destroy(){this.handle.destroy()}get isLost(){return this._isLost}createBuffer(e){let t=this._normalizeBufferProps(e);return new b(this,t)}createTexture(e){return new E(this,e)}createExternalTexture(e){return new U(this,e)}createShader(e){return new P(this,e)}createSampler(e){return new p(this,e)}createRenderPipeline(e){return new $(this,e)}createFramebuffer(e){return new A(this,e)}createComputePipeline(e){return new q(this,e)}createVertexArray(e){return new j(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new z(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new Q(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new H(this,e)}createCanvasContext(e){return new _(this,this.adapter,e)}submit(){let e=this.commandEncoder?.finish();e&&(this.handle.pushErrorScope("validation"),this.handle.queue.submit([e]),this.handle.popErrorScope().then(t=>{t&&this.reportError(new Error(`WebGPU command submission failed: ${t.message}`))})),this.commandEncoder=null}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",i=e||"",s=t||"",a=r==="apple"?"apple":"unknown",l=this.adapterInfo.architecture||"unknown",c=this.adapterInfo.backend||"unknown",d=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:i,version:s,gpu:a,gpuType:d,gpuBackend:c,gpuArchitecture:l,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new X.DeviceFeatures(Array.from(e),this.props._disabledFeatures)}_getDeviceSpecificTextureFormatCapabilities(e){let{format:t}=e;return t.includes("webgl")?{format:t,create:!1,render:!1,filter:!1,blend:!1,store:!1}:e}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:i=0,texture:s,mipLevel:a=0,aspect:l="all",colorSpace:c="display-p3",premultipliedAlpha:d=!1,width:g=s.width,height:u=s.height,depth:G=1}=e,J=s;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,i]},{texture:J.handle,origin:[0,0,0],mipLevel:a,aspect:l,colorSpace:c,premultipliedAlpha:d},[g,u,G])}};var ee=class extends f.Adapter{type="webgpu";constructor(){super(),S.adapter=this}isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");f.log.groupCollapsed(1,"WebGPUDevice created")();let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=t.info||await t.requestAdapterInfo?.();f.log.probe(2,"Adapter available",r)();let i=[],s={};if(e._requestMaxLimits){i.push(...Array.from(t.features));let c=Object.keys(t.limits).filter(d=>!["minSubgroupSize","maxSubgroupSize"].includes(d));for(let d of c){let g=d,u=t.limits[g];typeof u=="number"&&(s[g]=u)}}let a=await t.requestDevice({requiredFeatures:i,requiredLimits:s});f.log.probe(1,"GPUDevice available")();let l=new S(e,a,t,r);return f.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),f.log.table(1,l.info)(),f.log.groupEnd(1)(),l}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},be=new ee;return Te(I);})();
|
|
10
|
+
"${i.message}"`,this)()});let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||$(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:pe(this.shaderLayout,this.props.bufferLayout)},t={module:this.props.fs.handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:[{format:C(this.device.getCanvasContext().format)}]},r={vertex:e,fragment:t,primitive:{topology:this.props.topology},layout:"auto"};return this.props.parameters.depthWriteEnabled&&this.props.parameters.depthCompare&&(r.depthStencil={format:"depth24plus",depthWriteEnabled:this.props.parameters.depthWriteEnabled,depthCompare:this.props.parameters.depthCompare}),oe(r,this.props.parameters),r}};var ce=d(h(),1),A=class extends ce.Framebuffer{device;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}updateAttachments(){}};var ue=d(h(),1);var z=class extends ue.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let r=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:r.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||$(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}};var y=d(h(),1),Q=class extends y.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.getCanvasContext().getCurrentFramebuffer(),i=this.getRenderPassDescriptor(r),s=t.timestampQuerySet;if(s&&(i.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let a=t.timestampQuerySet;i.timestampWrites=a?{querySet:a.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}if(!e.commandEncoder)throw new Error("commandEncoder not available");this.device.handle.pushErrorScope("validation"),this.handle=this.props.handle||e.commandEncoder.beginRenderPass(i),this.device.handle.popErrorScope().then(a=>{a&&y.log.error(`${this} creation failed:
|
|
11
|
+
"${a.message}"`,this)()}),this.handle.label=this.props.id,y.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),y.log.probe(3,JSON.stringify(i,null,2))(),y.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.handle.setPipeline(this.pipeline.handle)}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,i){this.handle.setIndexBuffer(e.handle,t,r,i)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,t.handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:i,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),i&&this.handle.setScissorRect(i[0],i[1],i[2],i[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4],s[5])}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map((r,i)=>({loadOp:this.props.clearColor!==!1?"clear":"load",clearValue:Oe(this.props.clearColors?.[i]||this.props.clearColor||y.RenderPass.defaultClearColor),storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),this.props.clearDepth!==!1&&(r.depthClearValue=this.props.clearDepth),!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}};function Oe(n){return{r:n[0],g:n[1],b:n[2],a:n[3]}}var me=d(h(),1),N=class extends me.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let i=t.timestampQuerySet;i&&(r={querySet:i.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder?.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}};var _=d(h(),1);var lt=globalThis.document||{},pt=globalThis.process||{},ct=globalThis.console,fe=globalThis.navigator||{};function j(n){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=n||e;return Boolean(t&&t.indexOf("Electron")>=0)}function ge(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||j()}function ee(n){return!n&&!ge()?"Node":j(n)?"Electron":(n||fe.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var Y=class extends _.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let i=e,s=this.indexBuffer;s?.handle&&(_.log.info(3,"setting index buffer",s?.handle,s?.indexType)(),i.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let o=this.attributes[a];o?.handle&&(_.log.info(3,`setting vertex buffer ${a}`,o?.handle)(),i.handle.setVertexBuffer(a,o?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return ee()==="Chrome"}};var H=d(h(),1);var D=class extends H.CanvasContext{device;gpuCanvasContext;format=navigator.gpu.getPreferredCanvasFormat();depthStencilFormat="depth24plus";depthStencilAttachment=null;get[Symbol.toStringTag](){return"WebGPUCanvasContext"}constructor(e,t,r){super(r),this.device=e,this.width=-1,this.height=-1,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this.gpuCanvasContext=this.canvas.getContext("webgpu"),this.format="bgra8unorm"}destroy(){this.gpuCanvasContext.unconfigure()}getCurrentFramebuffer(){this.update();let e=this.getCurrentTexture();return this.width=e.width,this.height=e.height,this._createDepthStencilAttachment(),new A(this.device,{colorAttachments:[e],depthStencilAttachment:this.depthStencilAttachment})}update(){let e=this.width,t=this.height,[r,i]=this.getPixelSize();(r!==e||i!==t)&&(this.width=r,this.height=i,this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.gpuCanvasContext.configure({device:this.device.handle,format:C(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),H.log.log(1,`${this} Resized ${e}x${t} => ${r}x${i}px`)())}resize(e){if(this.update(),!!this.device.handle&&this.canvas){let t=this.getDevicePixelRatio(e?.useDevicePixels);this.setDevicePixelRatio(t,e);return}}getCurrentTexture(){return this.device.createTexture({id:`${this.id}#color-texture`,handle:this.gpuCanvasContext.getCurrentTexture(),format:this.format})}_createDepthStencilAttachment(){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,format:this.depthStencilFormat,width:this.width,height:this.height,usage:GPUTextureUsage.RENDER_ATTACHMENT})),this.depthStencilAttachment}};var be=d(h(),1),X=class extends be.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}};var S=class extends I.Device{type="webgpu";handle;adapter;adapterInfo;features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder=null;renderPass=null;constructor(e,t,r,i){super({...e,id:e.id||"webgpu-device"}),this.handle=t,this.adapter=r,this.adapterInfo=i,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,t.addEventListener("uncapturederror",a=>{let o=a instanceof GPUUncapturedErrorEvent?a.error.message:"Unknown WebGPU error";if(this.reportError(new Error(o)),this.props.debug)debugger;a.preventDefault()}),this.lost=new Promise(async a=>{let o=await this.handle.lost;this._isLost=!0,a({reason:"destroyed",message:o.message})});let s=I.Device._getCanvasContextProps(e);s&&(this.canvasContext=new D(this,this.adapter,s))}destroy(){this.handle.destroy()}get isLost(){return this._isLost}createBuffer(e){let t=this._normalizeBufferProps(e);return new b(this,t)}createTexture(e){return new E(this,e)}createExternalTexture(e){return new M(this,e)}createShader(e){return new P(this,e)}createSampler(e){return new c(this,e)}createRenderPipeline(e){return new q(this,e)}createFramebuffer(e){return new A(this,e)}createComputePipeline(e){return new z(this,e)}createVertexArray(e){return new Y(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new Q(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new N(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new X(this,e)}createCanvasContext(e){return new D(this,this.adapter,e)}submit(){let e=this.commandEncoder?.finish();e&&(this.handle.pushErrorScope("validation"),this.handle.queue.submit([e]),this.handle.popErrorScope().then(t=>{t&&this.reportError(new Error(`WebGPU command submission failed: ${t.message}`))})),this.commandEncoder=null}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",i=e||"",s=t||"",a=r==="apple"?"apple":"unknown",o=this.adapterInfo.architecture||"unknown",p=this.adapterInfo.backend||"unknown",l=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:i,version:s,gpu:a,gpuType:l,gpuBackend:p,gpuArchitecture:o,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new I.DeviceFeatures(Array.from(e),this.props._disabledFeatures)}_getDeviceSpecificTextureFormatCapabilities(e){let{format:t}=e;return t.includes("webgl")?{format:t,create:!1,render:!1,filter:!1,blend:!1,store:!1}:e}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:i=0,texture:s,mipLevel:a=0,aspect:o="all",colorSpace:p="display-p3",premultipliedAlpha:l=!1,width:g=s.width,height:u=s.height,depth:G=1}=e,J=s;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,i]},{texture:J.handle,origin:[0,0,0],mipLevel:a,aspect:o,colorSpace:p,premultipliedAlpha:l},[g,u,G])}};var te=class extends f.Adapter{type="webgpu";constructor(){super(),S.adapter=this}isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");f.log.groupCollapsed(1,"WebGPUDevice created")();let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=t.info||await t.requestAdapterInfo?.();f.log.probe(2,"Adapter available",r)();let i=[],s={};if(e._requestMaxLimits){i.push(...Array.from(t.features));let p=Object.keys(t.limits).filter(l=>!["minSubgroupSize","maxSubgroupSize"].includes(l));for(let l of p){let g=l,u=t.limits[g];typeof u=="number"&&(s[g]=u)}}let a=await t.requestDevice({requiredFeatures:i,requiredLimits:s});f.log.probe(1,"GPUDevice available")();let o=new S(e,a,t,r);return f.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),f.log.table(1,o.info)(),f.log.groupEnd(1)(),o}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},xe=new te;return Le(W);})();
|
|
12
12
|
return __exports__;
|
|
13
13
|
});
|