@luma.gl/webgpu 9.0.0-alpha.47 → 9.0.0-alpha.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.
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +2 -2
- package/dist/adapter/resources/webgpu-texture.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +2 -5
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/dist.dev.js +46 -652
- package/dist/index.cjs +130 -135
- package/dist.min.js +12 -10
- package/package.json +3 -3
- package/src/adapter/resources/webgpu-texture.ts +2 -2
- package/src/adapter/webgpu-device.ts +2 -5
package/dist/dist.dev.js
CHANGED
|
@@ -824,8 +824,6 @@ var __exports__ = (() => {
|
|
|
824
824
|
VERSION: VERSION3,
|
|
825
825
|
version: VERSION3,
|
|
826
826
|
log,
|
|
827
|
-
// A global stats object that various components can add information to
|
|
828
|
-
// E.g. see webgl/resource.js
|
|
829
827
|
stats: lumaStats
|
|
830
828
|
};
|
|
831
829
|
}
|
|
@@ -851,17 +849,10 @@ var __exports__ = (() => {
|
|
|
851
849
|
|
|
852
850
|
// ../core/src/adapter/resources/resource.ts
|
|
853
851
|
var Resource = class {
|
|
854
|
-
/** props.id, for debugging. */
|
|
855
852
|
userData = {};
|
|
856
|
-
/** Whether this resource has been destroyed */
|
|
857
853
|
destroyed = false;
|
|
858
|
-
/** For resources that allocate GPU memory */
|
|
859
854
|
allocatedBytes = 0;
|
|
860
|
-
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
|
|
861
855
|
_attachedResources = /* @__PURE__ */ new Set();
|
|
862
|
-
/**
|
|
863
|
-
* Create a new Resource. Called from Subclass
|
|
864
|
-
*/
|
|
865
856
|
constructor(device, props, defaultProps) {
|
|
866
857
|
if (!device) {
|
|
867
858
|
throw new Error("no device");
|
|
@@ -874,13 +865,9 @@ var __exports__ = (() => {
|
|
|
874
865
|
this.userData = this.props.userData || {};
|
|
875
866
|
this.addStats();
|
|
876
867
|
}
|
|
877
|
-
/**
|
|
878
|
-
* destroy can be called on any resource to release it before it is garbage collected.
|
|
879
|
-
*/
|
|
880
868
|
destroy() {
|
|
881
869
|
this.destroyResource();
|
|
882
870
|
}
|
|
883
|
-
/** @deprecated Use destroy() */
|
|
884
871
|
delete() {
|
|
885
872
|
this.destroy();
|
|
886
873
|
return this;
|
|
@@ -888,70 +875,48 @@ var __exports__ = (() => {
|
|
|
888
875
|
toString() {
|
|
889
876
|
return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
|
|
890
877
|
}
|
|
891
|
-
/**
|
|
892
|
-
* Combines a map of user props and default props, only including props from defaultProps
|
|
893
|
-
* @returns returns a map of overridden default props
|
|
894
|
-
*/
|
|
895
878
|
getProps() {
|
|
896
879
|
return this.props;
|
|
897
880
|
}
|
|
898
|
-
// ATTACHED RESOURCES
|
|
899
|
-
/**
|
|
900
|
-
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
|
|
901
|
-
* Called automatically when sub resources are auto created but can be called by application
|
|
902
|
-
*/
|
|
903
881
|
attachResource(resource) {
|
|
904
882
|
this._attachedResources.add(resource);
|
|
905
883
|
}
|
|
906
|
-
/**
|
|
907
|
-
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
|
|
908
|
-
*/
|
|
909
884
|
detachResource(resource) {
|
|
910
885
|
this._attachedResources.delete(resource);
|
|
911
886
|
}
|
|
912
|
-
/**
|
|
913
|
-
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
|
|
914
|
-
*/
|
|
915
887
|
destroyAttachedResource(resource) {
|
|
916
888
|
if (this._attachedResources.delete(resource)) {
|
|
917
889
|
resource.destroy();
|
|
918
890
|
}
|
|
919
891
|
}
|
|
920
|
-
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
|
|
921
892
|
destroyAttachedResources() {
|
|
922
893
|
for (const resource of Object.values(this._attachedResources)) {
|
|
923
894
|
resource.destroy();
|
|
924
895
|
}
|
|
925
896
|
this._attachedResources = /* @__PURE__ */ new Set();
|
|
926
897
|
}
|
|
927
|
-
// PROTECTED METHODS
|
|
928
|
-
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
|
|
929
898
|
destroyResource() {
|
|
930
899
|
this.destroyAttachedResources();
|
|
931
900
|
this.removeStats();
|
|
932
901
|
this.destroyed = true;
|
|
933
902
|
}
|
|
934
|
-
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
|
|
935
903
|
removeStats() {
|
|
936
904
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
937
905
|
const name2 = this[Symbol.toStringTag];
|
|
938
906
|
stats.get(`${name2}s Active`).decrementCount();
|
|
939
907
|
}
|
|
940
|
-
/** Called by subclass to track memory allocations */
|
|
941
908
|
trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
|
|
942
909
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
943
910
|
stats.get("GPU Memory").addCount(bytes);
|
|
944
911
|
stats.get(`${name2} Memory`).addCount(bytes);
|
|
945
912
|
this.allocatedBytes = bytes;
|
|
946
913
|
}
|
|
947
|
-
/** Called by subclass to track memory deallocations */
|
|
948
914
|
trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
|
|
949
915
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
950
916
|
stats.get("GPU Memory").subtractCount(this.allocatedBytes);
|
|
951
917
|
stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
|
|
952
918
|
this.allocatedBytes = 0;
|
|
953
919
|
}
|
|
954
|
-
/** Called by resource constructor to track object creation */
|
|
955
920
|
addStats() {
|
|
956
921
|
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
957
922
|
const name2 = this[Symbol.toStringTag];
|
|
@@ -960,7 +925,6 @@ var __exports__ = (() => {
|
|
|
960
925
|
stats.get(`${name2}s Active`).incrementCount();
|
|
961
926
|
}
|
|
962
927
|
};
|
|
963
|
-
/** Default properties for resource */
|
|
964
928
|
__publicField(Resource, "defaultProps", {
|
|
965
929
|
id: "undefined",
|
|
966
930
|
handle: void 0,
|
|
@@ -983,9 +947,6 @@ var __exports__ = (() => {
|
|
|
983
947
|
get [Symbol.toStringTag]() {
|
|
984
948
|
return "Buffer";
|
|
985
949
|
}
|
|
986
|
-
/** The usage with which this buffer was created */
|
|
987
|
-
/** For index buffers, whether indices are 16 or 32 bit */
|
|
988
|
-
/** Length of buffer in bytes */
|
|
989
950
|
constructor(device, props) {
|
|
990
951
|
const deducedProps = {
|
|
991
952
|
...props
|
|
@@ -1007,159 +968,55 @@ var __exports__ = (() => {
|
|
|
1007
968
|
readAsync(byteOffset, byteLength) {
|
|
1008
969
|
throw new Error("not implemented");
|
|
1009
970
|
}
|
|
1010
|
-
// TODO - can sync read be supported in WebGPU?
|
|
1011
971
|
getData() {
|
|
1012
972
|
throw new Error("not implemented");
|
|
1013
973
|
}
|
|
1014
|
-
// Convenience API
|
|
1015
|
-
/** Read data from the buffer *
|
|
1016
|
-
async readAsync(options: {
|
|
1017
|
-
byteOffset?: number,
|
|
1018
|
-
byteLength?: number,
|
|
1019
|
-
map?: boolean,
|
|
1020
|
-
unmap?: boolean
|
|
1021
|
-
}): Promise<ArrayBuffer> {
|
|
1022
|
-
if (options.map ?? true) {
|
|
1023
|
-
await this.mapAsync(Buffer.MAP_READ, options.byteOffset, options.byteLength);
|
|
1024
|
-
}
|
|
1025
|
-
const arrayBuffer = this.getMappedRange(options.byteOffset, options.byteLength);
|
|
1026
|
-
if (options.unmap ?? true) {
|
|
1027
|
-
this.unmap();
|
|
1028
|
-
}
|
|
1029
|
-
return arrayBuffer;
|
|
1030
|
-
}
|
|
1031
|
-
/** Write data to the buffer *
|
|
1032
|
-
async writeAsync(options: {
|
|
1033
|
-
data: ArrayBuffer,
|
|
1034
|
-
byteOffset?: number,
|
|
1035
|
-
byteLength?: number,
|
|
1036
|
-
map?: boolean,
|
|
1037
|
-
unmap?: boolean
|
|
1038
|
-
}): Promise<void> {
|
|
1039
|
-
if (options.map ?? true) {
|
|
1040
|
-
await this.mapAsync(Buffer.MAP_WRITE, options.byteOffset, options.byteLength);
|
|
1041
|
-
}
|
|
1042
|
-
const arrayBuffer = this.getMappedRange(options.byteOffset, options.byteLength);
|
|
1043
|
-
const destArray = new Uint8Array(arrayBuffer);
|
|
1044
|
-
const srcArray = new Uint8Array(options.data);
|
|
1045
|
-
destArray.set(srcArray);
|
|
1046
|
-
if (options.unmap ?? true) {
|
|
1047
|
-
this.unmap();
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
*/
|
|
1051
|
-
// Mapped API (WebGPU)
|
|
1052
|
-
/** Maps the memory so that it can be read */
|
|
1053
|
-
// abstract mapAsync(mode, byteOffset, byteLength): Promise<void>
|
|
1054
|
-
/** Get the mapped range of data for reading or writing */
|
|
1055
|
-
// abstract getMappedRange(byteOffset, byteLength): ArrayBuffer;
|
|
1056
|
-
/** unmap makes the contents of the buffer available to the GPU again */
|
|
1057
|
-
// abstract unmap(): void;
|
|
1058
974
|
};
|
|
1059
975
|
var Buffer2 = _Buffer;
|
|
1060
976
|
__publicField(Buffer2, "defaultProps", {
|
|
1061
977
|
...Resource.defaultProps,
|
|
1062
978
|
usage: 0,
|
|
1063
|
-
// Buffer.COPY_DST | Buffer.COPY_SRC
|
|
1064
979
|
byteLength: 0,
|
|
1065
980
|
byteOffset: 0,
|
|
1066
981
|
data: null,
|
|
1067
982
|
indexType: "uint16",
|
|
1068
983
|
mappedAtCreation: false
|
|
1069
984
|
});
|
|
1070
|
-
// Usage Flags
|
|
1071
985
|
__publicField(Buffer2, "MAP_READ", 1);
|
|
1072
986
|
__publicField(Buffer2, "MAP_WRITE", 2);
|
|
1073
987
|
__publicField(Buffer2, "COPY_SRC", 4);
|
|
1074
988
|
__publicField(Buffer2, "COPY_DST", 8);
|
|
1075
|
-
/** Index buffer */
|
|
1076
989
|
__publicField(Buffer2, "INDEX", 16);
|
|
1077
|
-
/** Vertex buffer */
|
|
1078
990
|
__publicField(Buffer2, "VERTEX", 32);
|
|
1079
|
-
/** Uniform buffer */
|
|
1080
991
|
__publicField(Buffer2, "UNIFORM", 64);
|
|
1081
|
-
/** Storage buffer */
|
|
1082
992
|
__publicField(Buffer2, "STORAGE", 128);
|
|
1083
993
|
__publicField(Buffer2, "INDIRECT", 256);
|
|
1084
994
|
__publicField(Buffer2, "QUERY_RESOLVE", 512);
|
|
1085
995
|
|
|
1086
996
|
// ../core/src/adapter/device.ts
|
|
1087
|
-
var
|
|
1088
|
-
id: null,
|
|
1089
|
-
type: "best-available",
|
|
1090
|
-
canvas: null,
|
|
1091
|
-
container: null,
|
|
1092
|
-
webgl2: true,
|
|
1093
|
-
// Attempt to create a WebGL2 context
|
|
1094
|
-
webgl1: true,
|
|
1095
|
-
// Attempt to create a WebGL1 context (false to fail if webgl2 not available)
|
|
1096
|
-
manageState: true,
|
|
1097
|
-
width: 800,
|
|
1098
|
-
// width are height are only used by headless gl
|
|
1099
|
-
height: 600,
|
|
1100
|
-
debug: Boolean(log.get("debug")),
|
|
1101
|
-
// Instrument context (at the expense of performance)
|
|
1102
|
-
break: [],
|
|
1103
|
-
// alpha: undefined,
|
|
1104
|
-
// depth: undefined,
|
|
1105
|
-
// stencil: undefined,
|
|
1106
|
-
// antialias: undefined,
|
|
1107
|
-
// premultipliedAlpha: undefined,
|
|
1108
|
-
// preserveDrawingBuffer: undefined,
|
|
1109
|
-
// failIfMajorPerformanceCaveat: undefined
|
|
1110
|
-
gl: null
|
|
1111
|
-
};
|
|
1112
|
-
var Device = class {
|
|
997
|
+
var _Device = class {
|
|
1113
998
|
get [Symbol.toStringTag]() {
|
|
1114
999
|
return "Device";
|
|
1115
1000
|
}
|
|
1116
1001
|
constructor(props) {
|
|
1117
1002
|
this.props = {
|
|
1118
|
-
...
|
|
1003
|
+
..._Device.defaultProps,
|
|
1119
1004
|
...props
|
|
1120
1005
|
};
|
|
1121
1006
|
this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
|
|
1122
1007
|
}
|
|
1123
|
-
/** id of this device, primarily for debugging */
|
|
1124
|
-
/** stats */
|
|
1125
1008
|
statsManager = lumaStats;
|
|
1126
|
-
/** A copy of the device props */
|
|
1127
|
-
/** Available for the application to store data on the device */
|
|
1128
1009
|
userData = {};
|
|
1129
|
-
/** Used by other luma.gl modules to store data on the device */
|
|
1130
1010
|
_lumaData = {};
|
|
1131
|
-
// Capabilities
|
|
1132
|
-
/** Information about the device (vendor, versions etc) */
|
|
1133
|
-
/** Optional capability discovery */
|
|
1134
|
-
/** WebGPU style device limits */
|
|
1135
|
-
/** Check if device supports a specific texture format (creation and `nearest` sampling) */
|
|
1136
|
-
/** Check if linear filtering (sampler interpolation) is supported for a specific texture format */
|
|
1137
|
-
/** Check if device supports rendering to a specific texture format */
|
|
1138
|
-
// Device loss
|
|
1139
|
-
/** `true` if device is already lost */
|
|
1140
|
-
/** Promise that resolves when device is lost */
|
|
1141
|
-
/**
|
|
1142
|
-
* Trigger device loss.
|
|
1143
|
-
* @returns `true` if context loss could actually be triggered.
|
|
1144
|
-
* @note primarily intended for testing how application reacts to device loss
|
|
1145
|
-
*/
|
|
1146
1011
|
loseDevice() {
|
|
1147
1012
|
return false;
|
|
1148
1013
|
}
|
|
1149
|
-
// Canvas context
|
|
1150
|
-
/** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
|
|
1151
|
-
/** Returns the default / primary canvas context. Throws an error if no canvas context is available (a WebGPU compute device) */
|
|
1152
1014
|
getCanvasContext() {
|
|
1153
1015
|
if (!this.canvasContext) {
|
|
1154
1016
|
throw new Error("Device has no CanvasContext");
|
|
1155
1017
|
}
|
|
1156
1018
|
return this.canvasContext;
|
|
1157
1019
|
}
|
|
1158
|
-
/** Creates a new CanvasContext (WebGPU only) */
|
|
1159
|
-
/** Call after rendering a frame (necessary e.g. on WebGL OffscreenCanvas) */
|
|
1160
|
-
// Resource creation
|
|
1161
|
-
/** Create a buffer */
|
|
1162
|
-
/** Create a texture */
|
|
1163
1020
|
createTexture(props) {
|
|
1164
1021
|
if (props instanceof Promise || typeof props === "string") {
|
|
1165
1022
|
props = {
|
|
@@ -1168,21 +1025,9 @@ var __exports__ = (() => {
|
|
|
1168
1025
|
}
|
|
1169
1026
|
return this._createTexture(props);
|
|
1170
1027
|
}
|
|
1171
|
-
/** Create a temporary texture view of a video source */
|
|
1172
|
-
/** Create a sampler */
|
|
1173
|
-
/** Create a Framebuffer. Must have at least one attachment. */
|
|
1174
|
-
/** Create a shader */
|
|
1175
|
-
/** Create a render pipeline (aka program) */
|
|
1176
|
-
/** Create a compute pipeline (aka program). WebGPU only. */
|
|
1177
1028
|
createCommandEncoder(props = {}) {
|
|
1178
1029
|
throw new Error("not implemented");
|
|
1179
1030
|
}
|
|
1180
|
-
/** Create a vertex array */
|
|
1181
|
-
/** Create a RenderPass */
|
|
1182
|
-
/** Create a ComputePass */
|
|
1183
|
-
/** Get a renderpass that is set up to render to the primary CanvasContext */
|
|
1184
|
-
/** Create a transform feedback (immutable set of output buffer bindings). WebGL 2 only. */
|
|
1185
|
-
// Implementation
|
|
1186
1031
|
_getBufferProps(props) {
|
|
1187
1032
|
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
|
|
1188
1033
|
props = {
|
|
@@ -1204,6 +1049,21 @@ var __exports__ = (() => {
|
|
|
1204
1049
|
return newProps;
|
|
1205
1050
|
}
|
|
1206
1051
|
};
|
|
1052
|
+
var Device = _Device;
|
|
1053
|
+
__publicField(Device, "defaultProps", {
|
|
1054
|
+
id: null,
|
|
1055
|
+
type: "best-available",
|
|
1056
|
+
canvas: null,
|
|
1057
|
+
container: null,
|
|
1058
|
+
webgl2: true,
|
|
1059
|
+
webgl1: true,
|
|
1060
|
+
manageState: true,
|
|
1061
|
+
width: 800,
|
|
1062
|
+
height: 600,
|
|
1063
|
+
debug: Boolean(log.get("debug")),
|
|
1064
|
+
break: [],
|
|
1065
|
+
gl: null
|
|
1066
|
+
});
|
|
1207
1067
|
__publicField(Device, "VERSION", VERSION2);
|
|
1208
1068
|
|
|
1209
1069
|
// ../core/src/adapter/canvas-context.ts
|
|
@@ -1212,7 +1072,6 @@ var __exports__ = (() => {
|
|
|
1212
1072
|
var DEFAULT_CANVAS_CONTEXT_PROPS = {
|
|
1213
1073
|
canvas: null,
|
|
1214
1074
|
width: 800,
|
|
1215
|
-
// width are height are only used by headless gl
|
|
1216
1075
|
height: 600,
|
|
1217
1076
|
useDevicePixels: true,
|
|
1218
1077
|
autoResize: true,
|
|
@@ -1224,13 +1083,11 @@ var __exports__ = (() => {
|
|
|
1224
1083
|
var CanvasContext = class {
|
|
1225
1084
|
width = 1;
|
|
1226
1085
|
height = 1;
|
|
1227
|
-
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
1228
1086
|
_canvasSizeInfo = {
|
|
1229
1087
|
clientWidth: 0,
|
|
1230
1088
|
clientHeight: 0,
|
|
1231
1089
|
devicePixelRatio: 1
|
|
1232
1090
|
};
|
|
1233
|
-
/** Check if the DOM is loaded */
|
|
1234
1091
|
static get isPageLoaded() {
|
|
1235
1092
|
return isPageLoaded();
|
|
1236
1093
|
}
|
|
@@ -1281,11 +1138,6 @@ var __exports__ = (() => {
|
|
|
1281
1138
|
this.resizeObserver.observe(this.canvas);
|
|
1282
1139
|
}
|
|
1283
1140
|
}
|
|
1284
|
-
/** Returns a framebuffer with properly resized current 'swap chain' textures */
|
|
1285
|
-
/**
|
|
1286
|
-
* Returns the current DPR, if props.useDevicePixels is true
|
|
1287
|
-
* Device refers to physical
|
|
1288
|
-
*/
|
|
1289
1141
|
getDevicePixelRatio(useDevicePixels) {
|
|
1290
1142
|
if (typeof OffscreenCanvas !== "undefined" && this.canvas instanceof OffscreenCanvas) {
|
|
1291
1143
|
return 1;
|
|
@@ -1300,12 +1152,6 @@ var __exports__ = (() => {
|
|
|
1300
1152
|
}
|
|
1301
1153
|
return useDevicePixels;
|
|
1302
1154
|
}
|
|
1303
|
-
/**
|
|
1304
|
-
* Returns the size of drawing buffer in device pixels.
|
|
1305
|
-
* @note This can be different from the 'CSS' size of a canvas, and also from the
|
|
1306
|
-
* canvas' internal drawing buffer size (.width, .height).
|
|
1307
|
-
* This is the size required to cover the canvas, adjusted for DPR
|
|
1308
|
-
*/
|
|
1309
1155
|
getPixelSize() {
|
|
1310
1156
|
switch (this.type) {
|
|
1311
1157
|
case "node":
|
|
@@ -1324,9 +1170,6 @@ var __exports__ = (() => {
|
|
|
1324
1170
|
const [width, height] = this.getPixelSize();
|
|
1325
1171
|
return width / height;
|
|
1326
1172
|
}
|
|
1327
|
-
/**
|
|
1328
|
-
* Returns multiplier need to convert CSS size to Device size
|
|
1329
|
-
*/
|
|
1330
1173
|
cssToDeviceRatio() {
|
|
1331
1174
|
try {
|
|
1332
1175
|
const [drawingBufferWidth] = this.getDrawingBufferSize();
|
|
@@ -1338,18 +1181,11 @@ var __exports__ = (() => {
|
|
|
1338
1181
|
return 1;
|
|
1339
1182
|
}
|
|
1340
1183
|
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Maps CSS pixel position to device pixel position
|
|
1343
|
-
*/
|
|
1344
1184
|
cssToDevicePixels(cssPixel, yInvert = true) {
|
|
1345
1185
|
const ratio = this.cssToDeviceRatio();
|
|
1346
1186
|
const [width, height] = this.getDrawingBufferSize();
|
|
1347
1187
|
return scalePixels(cssPixel, ratio, width, height, yInvert);
|
|
1348
1188
|
}
|
|
1349
|
-
/**
|
|
1350
|
-
* Use devicePixelRatio to set canvas width and height
|
|
1351
|
-
* @note this is a raw port of luma.gl v8 code. Might be worth a review
|
|
1352
|
-
*/
|
|
1353
1189
|
setDevicePixelRatio(devicePixelRatio, options = {}) {
|
|
1354
1190
|
if (!this.htmlCanvas) {
|
|
1355
1191
|
return;
|
|
@@ -1381,8 +1217,6 @@ var __exports__ = (() => {
|
|
|
1381
1217
|
this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
|
|
1382
1218
|
}
|
|
1383
1219
|
}
|
|
1384
|
-
// PRIVATE
|
|
1385
|
-
/** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */
|
|
1386
1220
|
getDrawingBufferSize() {
|
|
1387
1221
|
const gl = this.device.gl;
|
|
1388
1222
|
if (!gl) {
|
|
@@ -1390,23 +1224,12 @@ var __exports__ = (() => {
|
|
|
1390
1224
|
}
|
|
1391
1225
|
return [gl.drawingBufferWidth, gl.drawingBufferHeight];
|
|
1392
1226
|
}
|
|
1393
|
-
/** Perform platform specific updates (WebGPU vs WebGL) */
|
|
1394
|
-
/**
|
|
1395
|
-
* Allows subclass constructor to override the canvas id for auto created canvases.
|
|
1396
|
-
* This can really help when debugging DOM in apps that create multiple devices
|
|
1397
|
-
*/
|
|
1398
1227
|
_setAutoCreatedCanvasId(id) {
|
|
1399
1228
|
if (this.htmlCanvas?.id === "lumagl-auto-created-canvas") {
|
|
1400
1229
|
this.htmlCanvas.id = id;
|
|
1401
1230
|
}
|
|
1402
1231
|
}
|
|
1403
1232
|
};
|
|
1404
|
-
/**
|
|
1405
|
-
* Get a 'lazy' promise that resolves when the DOM is loaded.
|
|
1406
|
-
* @note Since there may be limitations on number of `load` event listeners,
|
|
1407
|
-
* it is recommended avoid calling this function until actually needed.
|
|
1408
|
-
* I.e. don't call it until you know that you will be looking up a string in the DOM.
|
|
1409
|
-
*/
|
|
1410
1233
|
__publicField(CanvasContext, "pageLoaded", getPageLoadPromise());
|
|
1411
1234
|
function getPageLoadPromise() {
|
|
1412
1235
|
if (isPageLoaded() || typeof window === "undefined") {
|
|
@@ -1472,7 +1295,6 @@ var __exports__ = (() => {
|
|
|
1472
1295
|
return {
|
|
1473
1296
|
x,
|
|
1474
1297
|
y,
|
|
1475
|
-
// when ratio < 1, current css pixel and next css pixel may point to same device pixel, set width/height to 1 in those cases.
|
|
1476
1298
|
width: Math.max(xHigh - x + 1, 1),
|
|
1477
1299
|
height: Math.max(yHigh - y + 1, 1)
|
|
1478
1300
|
};
|
|
@@ -1490,12 +1312,6 @@ var __exports__ = (() => {
|
|
|
1490
1312
|
get [Symbol.toStringTag]() {
|
|
1491
1313
|
return "Texture";
|
|
1492
1314
|
}
|
|
1493
|
-
/** dimension of this texture */
|
|
1494
|
-
/** format of this texture */
|
|
1495
|
-
/** width in pixels of this texture */
|
|
1496
|
-
/** height in pixels of this texture */
|
|
1497
|
-
/** depth of this texture */
|
|
1498
|
-
/** Default sampler for this texture */
|
|
1499
1315
|
constructor(device, props, defaultProps = _Texture.defaultProps) {
|
|
1500
1316
|
super(device, props, defaultProps);
|
|
1501
1317
|
this.dimension = this.props.dimension;
|
|
@@ -1516,11 +1332,8 @@ var __exports__ = (() => {
|
|
|
1516
1332
|
depth: 1,
|
|
1517
1333
|
mipmaps: true,
|
|
1518
1334
|
sampler: {},
|
|
1519
|
-
// type: undefined,
|
|
1520
1335
|
compressed: false,
|
|
1521
|
-
// mipLevels: 1,
|
|
1522
1336
|
usage: 0,
|
|
1523
|
-
// usage: GPUTextureUsage.COPY_DST
|
|
1524
1337
|
mipLevels: void 0,
|
|
1525
1338
|
samples: void 0,
|
|
1526
1339
|
type: void 0
|
|
@@ -1589,7 +1402,6 @@ var __exports__ = (() => {
|
|
|
1589
1402
|
mipmapFilter: "nearest",
|
|
1590
1403
|
lodMinClamp: 0,
|
|
1591
1404
|
lodMaxClamp: 32,
|
|
1592
|
-
// Per WebGPU spec
|
|
1593
1405
|
compare: "less-equal",
|
|
1594
1406
|
maxAnisotropy: 1
|
|
1595
1407
|
});
|
|
@@ -1599,21 +1411,13 @@ var __exports__ = (() => {
|
|
|
1599
1411
|
get [Symbol.toStringTag]() {
|
|
1600
1412
|
return "Framebuffer";
|
|
1601
1413
|
}
|
|
1602
|
-
/** Width of all attachments in this framebuffer */
|
|
1603
|
-
/** Height of all attachments in this framebuffer */
|
|
1604
|
-
/** Color attachments */
|
|
1605
1414
|
colorAttachments = [];
|
|
1606
|
-
/** Depth-stencil attachment, if provided */
|
|
1607
1415
|
depthStencilAttachment = null;
|
|
1608
1416
|
constructor(device, props = {}) {
|
|
1609
1417
|
super(device, props, _Framebuffer.defaultProps);
|
|
1610
1418
|
this.width = this.props.width;
|
|
1611
1419
|
this.height = this.props.height;
|
|
1612
1420
|
}
|
|
1613
|
-
/**
|
|
1614
|
-
* Resizes all attachments
|
|
1615
|
-
* @note resize() destroys existing textures (if size has changed).
|
|
1616
|
-
*/
|
|
1617
1421
|
resize(size) {
|
|
1618
1422
|
let updateSize = !size;
|
|
1619
1423
|
if (size) {
|
|
@@ -1627,51 +1431,6 @@ var __exports__ = (() => {
|
|
|
1627
1431
|
this.resizeAttachments(this.width, this.height);
|
|
1628
1432
|
}
|
|
1629
1433
|
}
|
|
1630
|
-
// /** Returns fully populated attachment object. */
|
|
1631
|
-
// protected normalizeColorAttachment(
|
|
1632
|
-
// attachment: Texture | ColorTextureFormat
|
|
1633
|
-
// ): Required<ColorAttachment> {
|
|
1634
|
-
// const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
|
|
1635
|
-
// texture: undefined!,
|
|
1636
|
-
// format: undefined!,
|
|
1637
|
-
// clearValue: [0.0, 0.0, 0.0, 0.0],
|
|
1638
|
-
// loadOp: 'clear',
|
|
1639
|
-
// storeOp: 'store'
|
|
1640
|
-
// };
|
|
1641
|
-
// if (attachment instanceof Texture) {
|
|
1642
|
-
// return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
|
|
1643
|
-
// }
|
|
1644
|
-
// if (typeof attachment === 'string') {
|
|
1645
|
-
// return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
|
|
1646
|
-
// }
|
|
1647
|
-
// return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
|
|
1648
|
-
// }
|
|
1649
|
-
// /** Wraps texture inside fully populated attachment object. */
|
|
1650
|
-
// protected normalizeDepthStencilAttachment(
|
|
1651
|
-
// attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
|
|
1652
|
-
// ): Required<DepthStencilAttachment> {
|
|
1653
|
-
// const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
|
|
1654
|
-
// texture: undefined!,
|
|
1655
|
-
// format: undefined!,
|
|
1656
|
-
// depthClearValue: 1.0,
|
|
1657
|
-
// depthLoadOp: 'clear',
|
|
1658
|
-
// depthStoreOp: 'store',
|
|
1659
|
-
// depthReadOnly: false,
|
|
1660
|
-
// stencilClearValue: 0,
|
|
1661
|
-
// stencilLoadOp: 'clear',
|
|
1662
|
-
// stencilStoreOp: 'store',
|
|
1663
|
-
// stencilReadOnly: false
|
|
1664
|
-
// };
|
|
1665
|
-
// if (typeof attachment === 'string') {
|
|
1666
|
-
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
|
|
1667
|
-
// }
|
|
1668
|
-
// // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
|
|
1669
|
-
// if (attachment.handle || attachment instanceof Texture) {
|
|
1670
|
-
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
|
|
1671
|
-
// }
|
|
1672
|
-
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
|
|
1673
|
-
// }
|
|
1674
|
-
/** Auto creates any textures */
|
|
1675
1434
|
autoCreateAttachmentTextures() {
|
|
1676
1435
|
this.colorAttachments = this.props.colorAttachments.map((attachment) => {
|
|
1677
1436
|
if (typeof attachment === "string") {
|
|
@@ -1691,7 +1450,6 @@ var __exports__ = (() => {
|
|
|
1691
1450
|
}
|
|
1692
1451
|
}
|
|
1693
1452
|
}
|
|
1694
|
-
/** Create a color texture */
|
|
1695
1453
|
createColorTexture(format) {
|
|
1696
1454
|
return this.device.createTexture({
|
|
1697
1455
|
id: "color-attachment",
|
|
@@ -1701,7 +1459,6 @@ var __exports__ = (() => {
|
|
|
1701
1459
|
height: this.height
|
|
1702
1460
|
});
|
|
1703
1461
|
}
|
|
1704
|
-
/** Create depth stencil texture */
|
|
1705
1462
|
createDepthStencilTexture(format) {
|
|
1706
1463
|
return this.device.createTexture({
|
|
1707
1464
|
id: "depth-stencil-attachment",
|
|
@@ -1711,11 +1468,6 @@ var __exports__ = (() => {
|
|
|
1711
1468
|
height: this.height
|
|
1712
1469
|
});
|
|
1713
1470
|
}
|
|
1714
|
-
/**
|
|
1715
|
-
* Default implementation of resize
|
|
1716
|
-
* Creates new textures with correct size for all attachments.
|
|
1717
|
-
* and destroys existing textures if owned
|
|
1718
|
-
*/
|
|
1719
1471
|
resizeAttachments(width, height) {
|
|
1720
1472
|
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
1721
1473
|
if (this.colorAttachments[i]) {
|
|
@@ -1740,37 +1492,6 @@ var __exports__ = (() => {
|
|
|
1740
1492
|
this.attachResource(resizedTexture);
|
|
1741
1493
|
}
|
|
1742
1494
|
}
|
|
1743
|
-
/** Create a color attachment for WebGL *
|
|
1744
|
-
protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
|
|
1745
|
-
return this.device._createTexture({
|
|
1746
|
-
id: `${this.id}-color`,
|
|
1747
|
-
data: null, // reserves texture memory, but texels are undefined
|
|
1748
|
-
format,
|
|
1749
|
-
// type: GL.UNSIGNED_BYTE,
|
|
1750
|
-
width: this.width,
|
|
1751
|
-
height: this.height,
|
|
1752
|
-
// Note: Mipmapping can be disabled by texture resource when we resize the texture
|
|
1753
|
-
// to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
|
|
1754
|
-
// behavior we always disable mipmaps.
|
|
1755
|
-
mipmaps: false,
|
|
1756
|
-
// Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
|
|
1757
|
-
// Use LINEAR so subpixel algos like fxaa work.
|
|
1758
|
-
// Set WRAP modes that support NPOT textures too.
|
|
1759
|
-
sampler: {
|
|
1760
|
-
minFilter: 'linear',
|
|
1761
|
-
magFilter: 'linear',
|
|
1762
|
-
addressModeU: 'clamp-to-edge',
|
|
1763
|
-
addressModeV: 'clamp-to-edge'
|
|
1764
|
-
}
|
|
1765
|
-
// parameters: {
|
|
1766
|
-
// [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
|
|
1767
|
-
// [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
|
|
1768
|
-
// [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
1769
|
-
// [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
|
|
1770
|
-
// }
|
|
1771
|
-
});
|
|
1772
|
-
}
|
|
1773
|
-
*/
|
|
1774
1495
|
};
|
|
1775
1496
|
var Framebuffer = _Framebuffer;
|
|
1776
1497
|
__publicField(Framebuffer, "defaultProps", {
|
|
@@ -1778,9 +1499,7 @@ var __exports__ = (() => {
|
|
|
1778
1499
|
width: 1,
|
|
1779
1500
|
height: 1,
|
|
1780
1501
|
colorAttachments: [],
|
|
1781
|
-
// ['rgba8unorm-unsized'],
|
|
1782
1502
|
depthStencilAttachment: null
|
|
1783
|
-
// 'depth24plus-stencil8'
|
|
1784
1503
|
});
|
|
1785
1504
|
|
|
1786
1505
|
// ../core/src/adapter/resources/render-pipeline.ts
|
|
@@ -1789,31 +1508,20 @@ var __exports__ = (() => {
|
|
|
1789
1508
|
return "RenderPipeline";
|
|
1790
1509
|
}
|
|
1791
1510
|
hash = "";
|
|
1792
|
-
/** The merged layout */
|
|
1793
|
-
/** Buffer map describing buffer interleaving etc */
|
|
1794
1511
|
constructor(device, props) {
|
|
1795
1512
|
super(device, props, _RenderPipeline.defaultProps);
|
|
1796
1513
|
this.shaderLayout = this.props.shaderLayout;
|
|
1797
1514
|
this.bufferLayout = this.props.bufferLayout || [];
|
|
1798
1515
|
}
|
|
1799
|
-
/** Set bindings (stored on pipeline and set before each call) */
|
|
1800
|
-
/** Uniforms
|
|
1801
|
-
* @deprecated Only supported on WebGL devices.
|
|
1802
|
-
* @note textures, samplers and uniform buffers should be set via `setBindings()`, these are not considered uniforms.
|
|
1803
|
-
* @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.
|
|
1804
|
-
*/
|
|
1805
|
-
/** Draw call */
|
|
1806
1516
|
};
|
|
1807
1517
|
var RenderPipeline = _RenderPipeline;
|
|
1808
1518
|
__publicField(RenderPipeline, "defaultProps", {
|
|
1809
1519
|
...Resource.defaultProps,
|
|
1810
1520
|
vs: null,
|
|
1811
1521
|
vsEntryPoint: "",
|
|
1812
|
-
// main
|
|
1813
1522
|
vsConstants: {},
|
|
1814
1523
|
fs: null,
|
|
1815
1524
|
fsEntryPoint: "",
|
|
1816
|
-
// main
|
|
1817
1525
|
fsConstants: {},
|
|
1818
1526
|
shaderLayout: null,
|
|
1819
1527
|
bufferLayout: [],
|
|
@@ -1852,43 +1560,8 @@ var __exports__ = (() => {
|
|
|
1852
1560
|
constructor(device, props) {
|
|
1853
1561
|
super(device, props, _RenderPass.defaultProps);
|
|
1854
1562
|
}
|
|
1855
|
-
/** Call when rendering is done in this pass. */
|
|
1856
|
-
/**
|
|
1857
|
-
* A small set of parameters can be changed between every draw call
|
|
1858
|
-
* (viewport, scissorRect, blendColor, stencilReference)
|
|
1859
|
-
*/
|
|
1860
|
-
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1861
|
-
// beginOcclusionQuery(queryIndex: number): void;
|
|
1862
|
-
// endOcclusionQuery(): void;
|
|
1863
|
-
// executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
1864
|
-
// In WebGPU the following methods are on the renderpass.
|
|
1865
|
-
// luma.gl keeps them on the pipeline for now
|
|
1866
|
-
/*
|
|
1867
|
-
setPipeline(pipeline: RenderPipeline): void {}
|
|
1868
|
-
setIndexBuffer(
|
|
1869
|
-
buffer: Buffer,
|
|
1870
|
-
indexFormat: 'uint16' | 'uint32',
|
|
1871
|
-
offset?: number,
|
|
1872
|
-
size?: number
|
|
1873
|
-
): void {}
|
|
1874
|
-
abstract setVertexBuffer(slot: number, buffer: Buffer, offset: number): void;
|
|
1875
|
-
abstract setBindings(bindings: Record<string, Binding>): void;
|
|
1876
|
-
abstract setParameters(parameters: RenderPassParameters);
|
|
1877
|
-
draw(options: {
|
|
1878
|
-
vertexCount?: number; // Either vertexCount or indexCount must be provided
|
|
1879
|
-
indexCount?: number; // Activates indexed drawing (call setIndexBuffer())
|
|
1880
|
-
instanceCount?: number; //
|
|
1881
|
-
firstVertex?: number;
|
|
1882
|
-
firstIndex?: number; // requires device.features.has('indirect-first-instance')?
|
|
1883
|
-
firstInstance?: number;
|
|
1884
|
-
baseVertex?: number;
|
|
1885
|
-
}): void {}
|
|
1886
|
-
drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
|
|
1887
|
-
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
|
|
1888
|
-
*/
|
|
1889
1563
|
};
|
|
1890
1564
|
var RenderPass = _RenderPass;
|
|
1891
|
-
/** Default properties for RenderPass */
|
|
1892
1565
|
__publicField(RenderPass, "defaultProps", {
|
|
1893
1566
|
...Resource.defaultProps,
|
|
1894
1567
|
framebuffer: null,
|
|
@@ -1909,22 +1582,6 @@ var __exports__ = (() => {
|
|
|
1909
1582
|
constructor(device, props) {
|
|
1910
1583
|
super(device, props, Resource.defaultProps);
|
|
1911
1584
|
}
|
|
1912
|
-
/** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
|
|
1913
|
-
// abstract setBindings(bindings: Binding[]): void;
|
|
1914
|
-
/**
|
|
1915
|
-
* Dispatch work to be performed with the current ComputePipeline.
|
|
1916
|
-
* @param x X dimension of the grid of workgroups to dispatch.
|
|
1917
|
-
* @param y Y dimension of the grid of workgroups to dispatch.
|
|
1918
|
-
* @param z Z dimension of the grid of workgroups to dispatch.
|
|
1919
|
-
*/
|
|
1920
|
-
/**
|
|
1921
|
-
* Dispatch work to be performed with the current ComputePipeline.
|
|
1922
|
-
* @param indirectBuffer buffer must be a tightly packed block of three 32-bit unsigned integer values (12 bytes total), given in the same order as the arguments for dispatch()
|
|
1923
|
-
* @param indirectOffset
|
|
1924
|
-
*/
|
|
1925
|
-
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1926
|
-
// beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1927
|
-
// endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1928
1585
|
};
|
|
1929
1586
|
__publicField(ComputePass, "defaultProps", {
|
|
1930
1587
|
...Resource.defaultProps
|
|
@@ -1989,7 +1646,6 @@ var __exports__ = (() => {
|
|
|
1989
1646
|
f16: 2,
|
|
1990
1647
|
i32: 4,
|
|
1991
1648
|
u32: 4
|
|
1992
|
-
// 'bool-webgl': 4,
|
|
1993
1649
|
};
|
|
1994
1650
|
|
|
1995
1651
|
// ../core/src/adapter/type-utils/decode-data-type.ts
|
|
@@ -2096,9 +1752,7 @@ var __exports__ = (() => {
|
|
|
2096
1752
|
vertexFormat,
|
|
2097
1753
|
bufferDataType: vertexFormatInfo.type,
|
|
2098
1754
|
bufferComponents: vertexFormatInfo.components,
|
|
2099
|
-
// normalized is a property of the buffer's vertex format
|
|
2100
1755
|
normalized: vertexFormatInfo.normalized,
|
|
2101
|
-
// integer is a property of the shader declaration
|
|
2102
1756
|
integer: attributeTypeInfo.integer,
|
|
2103
1757
|
stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
|
|
2104
1758
|
byteOffset: bufferMapping?.byteOffset || 0,
|
|
@@ -2140,7 +1794,6 @@ var __exports__ = (() => {
|
|
|
2140
1794
|
bufferName: name2,
|
|
2141
1795
|
stepMode: bufferLayout.stepMode,
|
|
2142
1796
|
vertexFormat: bufferLayout.format,
|
|
2143
|
-
// If offset is needed, use `attributes` field.
|
|
2144
1797
|
byteOffset: 0,
|
|
2145
1798
|
byteStride: bufferLayout.byteStride || 0
|
|
2146
1799
|
};
|
|
@@ -2177,8 +1830,6 @@ var __exports__ = (() => {
|
|
|
2177
1830
|
get [Symbol.toStringTag]() {
|
|
2178
1831
|
return "VertexArray";
|
|
2179
1832
|
}
|
|
2180
|
-
/** Max number of vertex attributes */
|
|
2181
|
-
/** Attribute infos indexed by location - TODO only needed by webgl module? */
|
|
2182
1833
|
indexBuffer = null;
|
|
2183
1834
|
constructor(device, props) {
|
|
2184
1835
|
super(device, props, _VertexArray.defaultProps);
|
|
@@ -2186,9 +1837,6 @@ var __exports__ = (() => {
|
|
|
2186
1837
|
this.attributes = new Array(this.maxVertexAttributes).fill(null);
|
|
2187
1838
|
this.attributeInfos = getAttributeInfosByLocation(props.renderPipeline.shaderLayout, props.renderPipeline.bufferLayout, this.maxVertexAttributes);
|
|
2188
1839
|
}
|
|
2189
|
-
/** Set attributes (stored on pipeline and set before each call) */
|
|
2190
|
-
/** Set attributes (stored on pipeline and set before each call) */
|
|
2191
|
-
/** Set constant attributes (WebGL only) */
|
|
2192
1840
|
};
|
|
2193
1841
|
var VertexArray = _VertexArray;
|
|
2194
1842
|
__publicField(VertexArray, "defaultProps", {
|
|
@@ -2214,7 +1862,6 @@ var __exports__ = (() => {
|
|
|
2214
1862
|
const size = Math.ceil(this.byteLength / 4) * 4;
|
|
2215
1863
|
this.handle = this.props.handle || this.device.handle.createBuffer({
|
|
2216
1864
|
size,
|
|
2217
|
-
// usage defaults to vertex
|
|
2218
1865
|
usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
2219
1866
|
mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
|
|
2220
1867
|
label: this.props.id
|
|
@@ -2229,7 +1876,6 @@ var __exports__ = (() => {
|
|
|
2229
1876
|
destroy() {
|
|
2230
1877
|
this.handle.destroy();
|
|
2231
1878
|
}
|
|
2232
|
-
// WebGPU provides multiple ways to write a buffer...
|
|
2233
1879
|
write(data, byteOffset = 0) {
|
|
2234
1880
|
this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
|
|
2235
1881
|
}
|
|
@@ -2251,7 +1897,6 @@ var __exports__ = (() => {
|
|
|
2251
1897
|
const arrayBuffer = this.handle.getMappedRange();
|
|
2252
1898
|
new typedArray.constructor(arrayBuffer).set(typedArray);
|
|
2253
1899
|
}
|
|
2254
|
-
// WEBGPU API
|
|
2255
1900
|
mapAsync(mode, offset = 0, size) {
|
|
2256
1901
|
return this.handle.mapAsync(mode, offset, size);
|
|
2257
1902
|
}
|
|
@@ -2299,12 +1944,8 @@ var __exports__ = (() => {
|
|
|
2299
1944
|
"3d": "3d"
|
|
2300
1945
|
};
|
|
2301
1946
|
var WebGPUTexture = class extends Texture {
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
// img.src = src;
|
|
2305
|
-
// await img.decode();
|
|
2306
|
-
// return WebGPUTexture(img, usage);
|
|
2307
|
-
// }
|
|
1947
|
+
height = 1;
|
|
1948
|
+
width = 1;
|
|
2308
1949
|
constructor(device, props) {
|
|
2309
1950
|
super(device, props);
|
|
2310
1951
|
if (typeof this.props.format === "number") {
|
|
@@ -2320,15 +1961,7 @@ var __exports__ = (() => {
|
|
|
2320
1961
|
this.width = this.handle.width;
|
|
2321
1962
|
this.height = this.handle.height;
|
|
2322
1963
|
this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
|
|
2323
|
-
this.view = this.handle.createView({
|
|
2324
|
-
// format: this.props.format,
|
|
2325
|
-
// dimension: this.props.dimension,
|
|
2326
|
-
// aspect = "all";
|
|
2327
|
-
// baseMipLevel: 0;
|
|
2328
|
-
// mipLevelCount;
|
|
2329
|
-
// baseArrayLayer = 0;
|
|
2330
|
-
// arrayLayerCount;
|
|
2331
|
-
});
|
|
1964
|
+
this.view = this.handle.createView({});
|
|
2332
1965
|
}
|
|
2333
1966
|
createHandle() {
|
|
2334
1967
|
if (typeof this.props.format === "number") {
|
|
@@ -2352,10 +1985,6 @@ var __exports__ = (() => {
|
|
|
2352
1985
|
destroy() {
|
|
2353
1986
|
this.handle.destroy();
|
|
2354
1987
|
}
|
|
2355
|
-
/**
|
|
2356
|
-
* Set default sampler
|
|
2357
|
-
* Accept a sampler instance or set of props;
|
|
2358
|
-
*/
|
|
2359
1988
|
setSampler(sampler) {
|
|
2360
1989
|
this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
2361
1990
|
return this;
|
|
@@ -2365,7 +1994,6 @@ var __exports__ = (() => {
|
|
|
2365
1994
|
source: options.data
|
|
2366
1995
|
});
|
|
2367
1996
|
}
|
|
2368
|
-
/** Set image */
|
|
2369
1997
|
setImage(options) {
|
|
2370
1998
|
const {
|
|
2371
1999
|
source,
|
|
@@ -2382,101 +2010,22 @@ var __exports__ = (() => {
|
|
|
2382
2010
|
colorSpace = "srgb",
|
|
2383
2011
|
premultipliedAlpha = false
|
|
2384
2012
|
} = options;
|
|
2385
|
-
this.device.handle.queue.copyExternalImageToTexture(
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
aspect,
|
|
2397
|
-
colorSpace,
|
|
2398
|
-
premultipliedAlpha
|
|
2399
|
-
},
|
|
2400
|
-
// copySize: GPUExtent3D
|
|
2401
|
-
[width, height, depth]
|
|
2402
|
-
);
|
|
2013
|
+
this.device.handle.queue.copyExternalImageToTexture({
|
|
2014
|
+
source,
|
|
2015
|
+
origin: [sourceX, sourceY]
|
|
2016
|
+
}, {
|
|
2017
|
+
texture: this.handle,
|
|
2018
|
+
origin: [x, y, z],
|
|
2019
|
+
mipLevel,
|
|
2020
|
+
aspect,
|
|
2021
|
+
colorSpace,
|
|
2022
|
+
premultipliedAlpha
|
|
2023
|
+
}, [width, height, depth]);
|
|
2403
2024
|
return {
|
|
2404
2025
|
width,
|
|
2405
2026
|
height
|
|
2406
2027
|
};
|
|
2407
2028
|
}
|
|
2408
|
-
/*
|
|
2409
|
-
async readPixels() {
|
|
2410
|
-
const readbackBuffer = device.createBuffer({
|
|
2411
|
-
usage: Buffer.COPY_DST | Buffer.MAP_READ,
|
|
2412
|
-
size: 4 * textureWidth * textureHeight,
|
|
2413
|
-
});
|
|
2414
|
-
// Copy data from the texture to the buffer.
|
|
2415
|
-
const encoder = device.createCommandEncoder();
|
|
2416
|
-
encoder.copyTextureToBuffer(
|
|
2417
|
-
{ texture },
|
|
2418
|
-
{ buffer, rowPitch: textureWidth * 4 },
|
|
2419
|
-
[textureWidth, textureHeight],
|
|
2420
|
-
);
|
|
2421
|
-
device.submit([encoder.finish()]);
|
|
2422
|
-
// Get the data on the CPU.
|
|
2423
|
-
await buffer.mapAsync(GPUMapMode.READ);
|
|
2424
|
-
saveScreenshot(buffer.getMappedRange());
|
|
2425
|
-
buffer.unmap();
|
|
2426
|
-
}
|
|
2427
|
-
setImageData(imageData, usage): this {
|
|
2428
|
-
let data = null;
|
|
2429
|
-
const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;
|
|
2430
|
-
if (bytesPerRow == img.width * 4) {
|
|
2431
|
-
data = imageData.data;
|
|
2432
|
-
} else {
|
|
2433
|
-
data = new Uint8Array(bytesPerRow * img.height);
|
|
2434
|
-
let imagePixelIndex = 0;
|
|
2435
|
-
for (let y = 0; y < img.height; ++y) {
|
|
2436
|
-
for (let x = 0; x < img.width; ++x) {
|
|
2437
|
-
const i = x * 4 + y * bytesPerRow;
|
|
2438
|
-
data[i] = imageData.data[imagePixelIndex];
|
|
2439
|
-
data[i + 1] = imageData.data[imagePixelIndex + 1];
|
|
2440
|
-
data[i + 2] = imageData.data[imagePixelIndex + 2];
|
|
2441
|
-
data[i + 3] = imageData.data[imagePixelIndex + 3];
|
|
2442
|
-
imagePixelIndex += 4;
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
return this;
|
|
2447
|
-
}
|
|
2448
|
-
setData(data): this {
|
|
2449
|
-
const textureDataBuffer = this.device.handle.createBuffer({
|
|
2450
|
-
size: data.byteLength,
|
|
2451
|
-
usage: Buffer.COPY_DST | Buffer.COPY_SRC,
|
|
2452
|
-
mappedAtCreation: true
|
|
2453
|
-
});
|
|
2454
|
-
new Uint8Array(textureDataBuffer.getMappedRange()).set(data);
|
|
2455
|
-
textureDataBuffer.unmap();
|
|
2456
|
-
this.setBuffer(textureDataBuffer);
|
|
2457
|
-
textureDataBuffer.destroy();
|
|
2458
|
-
return this;
|
|
2459
|
-
}
|
|
2460
|
-
setBuffer(textureDataBuffer, {bytesPerRow}): this {
|
|
2461
|
-
const commandEncoder = this.device.handle.createCommandEncoder();
|
|
2462
|
-
commandEncoder.copyBufferToTexture(
|
|
2463
|
-
{
|
|
2464
|
-
buffer: textureDataBuffer,
|
|
2465
|
-
bytesPerRow
|
|
2466
|
-
},
|
|
2467
|
-
{
|
|
2468
|
-
texture: this.handle
|
|
2469
|
-
},
|
|
2470
|
-
{
|
|
2471
|
-
width,
|
|
2472
|
-
height,
|
|
2473
|
-
depth
|
|
2474
|
-
}
|
|
2475
|
-
);
|
|
2476
|
-
this.device.handle.defaultQueue.submit([commandEncoder.finish()]);
|
|
2477
|
-
return this;
|
|
2478
|
-
}
|
|
2479
|
-
*/
|
|
2480
2029
|
};
|
|
2481
2030
|
|
|
2482
2031
|
// src/adapter/resources/webgpu-external-texture.ts
|
|
@@ -2492,7 +2041,6 @@ var __exports__ = (() => {
|
|
|
2492
2041
|
}
|
|
2493
2042
|
destroy() {
|
|
2494
2043
|
}
|
|
2495
|
-
/** Set default sampler */
|
|
2496
2044
|
setSampler(sampler) {
|
|
2497
2045
|
this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
2498
2046
|
return this;
|
|
@@ -2536,14 +2084,12 @@ var __exports__ = (() => {
|
|
|
2536
2084
|
case "glsl":
|
|
2537
2085
|
return this.device.handle.createShaderModule({
|
|
2538
2086
|
code: source,
|
|
2539
|
-
// @ts-expect-error
|
|
2540
2087
|
transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)
|
|
2541
2088
|
});
|
|
2542
2089
|
default:
|
|
2543
2090
|
throw new Error(language);
|
|
2544
2091
|
}
|
|
2545
2092
|
}
|
|
2546
|
-
/** Returns compilation info for this shader */
|
|
2547
2093
|
async compilationInfo() {
|
|
2548
2094
|
const compilationInfo = await this.handle.getCompilationInfo();
|
|
2549
2095
|
return compilationInfo.messages;
|
|
@@ -2553,18 +2099,15 @@ var __exports__ = (() => {
|
|
|
2553
2099
|
// src/adapter/helpers/webgpu-parameters.ts
|
|
2554
2100
|
function addDepthStencil(descriptor) {
|
|
2555
2101
|
descriptor.depthStencil = descriptor.depthStencil || {
|
|
2556
|
-
// required, set something
|
|
2557
2102
|
format: "depth24plus",
|
|
2558
2103
|
stencilFront: {},
|
|
2559
2104
|
stencilBack: {},
|
|
2560
|
-
// TODO can this cause trouble? Should we set to WebGPU defaults? Are there defaults?
|
|
2561
2105
|
depthWriteEnabled: false,
|
|
2562
2106
|
depthCompare: "less-equal"
|
|
2563
2107
|
};
|
|
2564
2108
|
return descriptor.depthStencil;
|
|
2565
2109
|
}
|
|
2566
2110
|
var PARAMETER_TABLE = {
|
|
2567
|
-
// RASTERIZATION PARAMETERS
|
|
2568
2111
|
cullMode: (parameter, value, descriptor) => {
|
|
2569
2112
|
descriptor.primitive = descriptor.primitive || {};
|
|
2570
2113
|
descriptor.primitive.cullMode = value;
|
|
@@ -2573,7 +2116,6 @@ var __exports__ = (() => {
|
|
|
2573
2116
|
descriptor.primitive = descriptor.primitive || {};
|
|
2574
2117
|
descriptor.primitive.frontFace = value;
|
|
2575
2118
|
},
|
|
2576
|
-
// DEPTH
|
|
2577
2119
|
depthWriteEnabled: (parameter, value, descriptor) => {
|
|
2578
2120
|
const depthStencil = addDepthStencil(descriptor);
|
|
2579
2121
|
depthStencil.depthWriteEnabled = value;
|
|
@@ -2598,7 +2140,6 @@ var __exports__ = (() => {
|
|
|
2598
2140
|
const depthStencil = addDepthStencil(descriptor);
|
|
2599
2141
|
depthStencil.depthBiasClamp = value;
|
|
2600
2142
|
},
|
|
2601
|
-
// STENCIL
|
|
2602
2143
|
stencilReadMask: (parameter, value, descriptor) => {
|
|
2603
2144
|
const depthStencil = addDepthStencil(descriptor);
|
|
2604
2145
|
depthStencil.stencilReadMask = value;
|
|
@@ -2627,7 +2168,6 @@ var __exports__ = (() => {
|
|
|
2627
2168
|
depthStencil.stencilFront.depthFailOp = value;
|
|
2628
2169
|
depthStencil.stencilBack.depthFailOp = value;
|
|
2629
2170
|
},
|
|
2630
|
-
// MULTISAMPLE
|
|
2631
2171
|
sampleCount: (parameter, value, descriptor) => {
|
|
2632
2172
|
descriptor.multisample = descriptor.multisample || {};
|
|
2633
2173
|
descriptor.multisample.count = value;
|
|
@@ -2640,7 +2180,6 @@ var __exports__ = (() => {
|
|
|
2640
2180
|
descriptor.multisample = descriptor.multisample || {};
|
|
2641
2181
|
descriptor.multisample.alphaToCoverageEnabled = value;
|
|
2642
2182
|
},
|
|
2643
|
-
// COLOR
|
|
2644
2183
|
colorMask: (parameter, value, descriptor) => {
|
|
2645
2184
|
const targets = addColorState(descriptor);
|
|
2646
2185
|
targets[0].writeMask = value;
|
|
@@ -2648,47 +2187,8 @@ var __exports__ = (() => {
|
|
|
2648
2187
|
blendColorOperation: (parameter, value, descriptor) => {
|
|
2649
2188
|
addColorState(descriptor);
|
|
2650
2189
|
}
|
|
2651
|
-
/*
|
|
2652
|
-
blendColorSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
2653
|
-
addColorState(descriptor);
|
|
2654
|
-
targets[0].blend = targets[0].blend || {};
|
|
2655
|
-
targets[0].blend.color = targets[0].blend.color || {};
|
|
2656
|
-
targets[0].blend.color.srcTarget = value;
|
|
2657
|
-
},
|
|
2658
|
-
blendColorDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
2659
|
-
addColorState(descriptor);
|
|
2660
|
-
targets[0].blend = targets[0].blend || {};
|
|
2661
|
-
targets[0].blend.color = targets[0].blend.color || {};
|
|
2662
|
-
targets[0].blend.color.dstTarget = value;
|
|
2663
|
-
},
|
|
2664
|
-
blendAlphaOperation: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
2665
|
-
addColorState(descriptor);
|
|
2666
|
-
targets[0].blend = targets[0].blend || {};
|
|
2667
|
-
targets[0].blend.alpha = targets[0].blend.alpha || {};
|
|
2668
|
-
targets[0].blend.alpha.operation = value;
|
|
2669
|
-
},
|
|
2670
|
-
blendAlphaSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
2671
|
-
addColorState(descriptor);
|
|
2672
|
-
targets[0].blend = targets[0].blend || {};
|
|
2673
|
-
targets[0].blend.alpha = targets[0].blend.alpha || {};
|
|
2674
|
-
targets[0].blend.alpha.srcTarget = value;
|
|
2675
|
-
},
|
|
2676
|
-
blendAlphaDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
|
|
2677
|
-
addColorState(descriptor);
|
|
2678
|
-
targets[0].blend = targets[0].blend || {};
|
|
2679
|
-
targets[0].blend.alpha = targets[0].blend.alpha || {};
|
|
2680
|
-
targets[0].blend.alpha.dstTarget = value;
|
|
2681
|
-
},
|
|
2682
|
-
*/
|
|
2683
2190
|
};
|
|
2684
2191
|
var DEFAULT_PIPELINE_DESCRIPTOR = {
|
|
2685
|
-
// depthStencil: {
|
|
2686
|
-
// stencilFront: {},
|
|
2687
|
-
// stencilBack: {},
|
|
2688
|
-
// // depthWriteEnabled: true,
|
|
2689
|
-
// // depthCompare: 'less',
|
|
2690
|
-
// // format: 'depth24plus-stencil8',
|
|
2691
|
-
// },
|
|
2692
2192
|
primitive: {
|
|
2693
2193
|
cullMode: "back",
|
|
2694
2194
|
topology: "triangle-list"
|
|
@@ -2700,9 +2200,7 @@ var __exports__ = (() => {
|
|
|
2700
2200
|
fragment: {
|
|
2701
2201
|
module: void 0,
|
|
2702
2202
|
entryPoint: "main",
|
|
2703
|
-
targets: [
|
|
2704
|
-
// { format: props.color0Format || 'bgra8unorm' }
|
|
2705
|
-
]
|
|
2203
|
+
targets: []
|
|
2706
2204
|
},
|
|
2707
2205
|
layout: "auto"
|
|
2708
2206
|
};
|
|
@@ -2814,7 +2312,6 @@ var __exports__ = (() => {
|
|
|
2814
2312
|
stepMode = attributeLayout.stepMode || "vertex";
|
|
2815
2313
|
vertexAttributes.push({
|
|
2816
2314
|
format: getWebGPUVertexFormat(mapping.format),
|
|
2817
|
-
// We only support 0 offset for non-interleaved buffer layouts
|
|
2818
2315
|
offset: 0,
|
|
2819
2316
|
shaderLocation: attributeLayout.location
|
|
2820
2317
|
});
|
|
@@ -2877,9 +2374,6 @@ var __exports__ = (() => {
|
|
|
2877
2374
|
var WebGPURenderPipeline = class extends RenderPipeline {
|
|
2878
2375
|
fs = null;
|
|
2879
2376
|
_indexBuffer = null;
|
|
2880
|
-
// private _firstIndex: number;
|
|
2881
|
-
// private _lastIndex: number;
|
|
2882
|
-
/** For internal use to create BindGroups */
|
|
2883
2377
|
_bindGroupLayout = null;
|
|
2884
2378
|
_bindGroup = null;
|
|
2885
2379
|
constructor(device, props) {
|
|
@@ -2932,13 +2426,9 @@ var __exports__ = (() => {
|
|
|
2932
2426
|
_getBuffers() {
|
|
2933
2427
|
return this._buffers;
|
|
2934
2428
|
}
|
|
2935
|
-
/** Return a bind group created by setBindings */
|
|
2936
2429
|
_getBindGroup() {
|
|
2937
2430
|
return this._bindGroup;
|
|
2938
2431
|
}
|
|
2939
|
-
/**
|
|
2940
|
-
* Populate the complex WebGPU GPURenderPipelineDescriptor
|
|
2941
|
-
*/
|
|
2942
2432
|
_getRenderPipelineDescriptor() {
|
|
2943
2433
|
const vertex = {
|
|
2944
2434
|
module: cast(this.props.vs).handle,
|
|
@@ -2951,7 +2441,6 @@ var __exports__ = (() => {
|
|
|
2951
2441
|
module: cast(this.props.fs).handle,
|
|
2952
2442
|
entryPoint: this.props.fsEntryPoint || "main",
|
|
2953
2443
|
targets: [{
|
|
2954
|
-
// TODO exclamation mark hack!
|
|
2955
2444
|
format: getWebGPUTextureFormat(this.device?.canvasContext?.format)
|
|
2956
2445
|
}]
|
|
2957
2446
|
};
|
|
@@ -2984,12 +2473,7 @@ var __exports__ = (() => {
|
|
|
2984
2473
|
if (options.indexCount) {
|
|
2985
2474
|
webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
|
|
2986
2475
|
} else {
|
|
2987
|
-
webgpuRenderPass.handle.draw(
|
|
2988
|
-
options.vertexCount || 0,
|
|
2989
|
-
options.instanceCount || 1,
|
|
2990
|
-
// If 0, nothing will be drawn
|
|
2991
|
-
options.firstInstance
|
|
2992
|
-
);
|
|
2476
|
+
webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstInstance);
|
|
2993
2477
|
}
|
|
2994
2478
|
}
|
|
2995
2479
|
_setAttributeBuffers(webgpuRenderPass) {
|
|
@@ -3019,12 +2503,10 @@ var __exports__ = (() => {
|
|
|
3019
2503
|
compute: {
|
|
3020
2504
|
module,
|
|
3021
2505
|
entryPoint: this.props.csEntryPoint
|
|
3022
|
-
// constants: this.props.csConstants
|
|
3023
2506
|
},
|
|
3024
2507
|
layout: "auto"
|
|
3025
2508
|
});
|
|
3026
2509
|
}
|
|
3027
|
-
/** For internal use in render passes */
|
|
3028
2510
|
_getBindGroupLayout() {
|
|
3029
2511
|
return this.handle.getBindGroupLayout(0);
|
|
3030
2512
|
}
|
|
@@ -3032,7 +2514,6 @@ var __exports__ = (() => {
|
|
|
3032
2514
|
|
|
3033
2515
|
// src/adapter/resources/webgpu-render-pass.ts
|
|
3034
2516
|
var WebGPURenderPass = class extends RenderPass {
|
|
3035
|
-
/** Active pipeline */
|
|
3036
2517
|
pipeline = null;
|
|
3037
2518
|
constructor(device, props = {}) {
|
|
3038
2519
|
super(device, props);
|
|
@@ -3054,7 +2535,6 @@ var __exports__ = (() => {
|
|
|
3054
2535
|
this.pipeline = cast(pipeline);
|
|
3055
2536
|
this.handle.setPipeline(this.pipeline.handle);
|
|
3056
2537
|
}
|
|
3057
|
-
/** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
|
|
3058
2538
|
setBindings(bindings) {
|
|
3059
2539
|
this.pipeline?.setBindings(bindings);
|
|
3060
2540
|
const bindGroup = this.pipeline?._getBindGroup();
|
|
@@ -3106,27 +2586,14 @@ var __exports__ = (() => {
|
|
|
3106
2586
|
insertDebugMarker(markerLabel) {
|
|
3107
2587
|
this.handle.insertDebugMarker(markerLabel);
|
|
3108
2588
|
}
|
|
3109
|
-
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
3110
|
-
// beginOcclusionQuery(queryIndex: number): void;
|
|
3111
|
-
// endOcclusionQuery(): void;
|
|
3112
|
-
// beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
3113
|
-
// endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
3114
|
-
// executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
3115
|
-
// INTERNAL
|
|
3116
|
-
/**
|
|
3117
|
-
* Partial render pass descriptor. Used by WebGPURenderPass.
|
|
3118
|
-
* @returns attachments fields of a renderpass descriptor.
|
|
3119
|
-
*/
|
|
3120
2589
|
getRenderPassDescriptor(framebuffer) {
|
|
3121
2590
|
const renderPassDescriptor = {
|
|
3122
2591
|
colorAttachments: []
|
|
3123
2592
|
};
|
|
3124
2593
|
renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment) => ({
|
|
3125
|
-
// clear values
|
|
3126
2594
|
loadOp: this.props.clearColor !== false ? "clear" : "load",
|
|
3127
2595
|
colorClearValue: this.props.clearColor || [0, 0, 0, 0],
|
|
3128
2596
|
storeOp: this.props.discard ? "discard" : "store",
|
|
3129
|
-
// ...colorAttachment,
|
|
3130
2597
|
view: colorAttachment.handle.createView()
|
|
3131
2598
|
}));
|
|
3132
2599
|
if (framebuffer.depthStencilAttachment) {
|
|
@@ -3163,10 +2630,8 @@ var __exports__ = (() => {
|
|
|
3163
2630
|
this.device = device;
|
|
3164
2631
|
this.handle = this.props.handle || device.commandEncoder?.beginComputePass({
|
|
3165
2632
|
label: this.props.id
|
|
3166
|
-
// timestampWrites?: GPUComputePassTimestampWrites;
|
|
3167
2633
|
});
|
|
3168
2634
|
}
|
|
3169
|
-
/** @note no WebGPU destroy method, just gc */
|
|
3170
2635
|
destroy() {
|
|
3171
2636
|
}
|
|
3172
2637
|
end() {
|
|
@@ -3177,24 +2642,12 @@ var __exports__ = (() => {
|
|
|
3177
2642
|
this.handle.setPipeline(wgpuPipeline.handle);
|
|
3178
2643
|
this._bindGroupLayout = wgpuPipeline._getBindGroupLayout();
|
|
3179
2644
|
}
|
|
3180
|
-
/** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
|
|
3181
2645
|
setBindings(bindings) {
|
|
3182
2646
|
throw new Error("fix me");
|
|
3183
2647
|
}
|
|
3184
|
-
/**
|
|
3185
|
-
* Dispatch work to be performed with the current ComputePipeline.
|
|
3186
|
-
* @param x X dimension of the grid of workgroups to dispatch.
|
|
3187
|
-
* @param y Y dimension of the grid of workgroups to dispatch.
|
|
3188
|
-
* @param z Z dimension of the grid of workgroups to dispatch.
|
|
3189
|
-
*/
|
|
3190
2648
|
dispatch(x, y, z) {
|
|
3191
2649
|
this.handle.dispatchWorkgroups(x, y, z);
|
|
3192
2650
|
}
|
|
3193
|
-
/**
|
|
3194
|
-
* Dispatch work to be performed with the current ComputePipeline.
|
|
3195
|
-
* @param indirectBuffer buffer must be a tightly packed block of three 32-bit unsigned integer values (12 bytes total), given in the same order as the arguments for dispatch()
|
|
3196
|
-
* @param indirectOffset
|
|
3197
|
-
*/
|
|
3198
2651
|
dispatchIndirect(indirectBuffer, indirectOffset = 0) {
|
|
3199
2652
|
this.handle.dispatchWorkgroupsIndirect(cast(indirectBuffer).handle, indirectOffset);
|
|
3200
2653
|
}
|
|
@@ -3207,9 +2660,6 @@ var __exports__ = (() => {
|
|
|
3207
2660
|
insertDebugMarker(markerLabel) {
|
|
3208
2661
|
this.handle.insertDebugMarker(markerLabel);
|
|
3209
2662
|
}
|
|
3210
|
-
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
3211
|
-
// beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
3212
|
-
// endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
3213
2663
|
};
|
|
3214
2664
|
|
|
3215
2665
|
// src/adapter/resources/webgpu-vertex-array.ts
|
|
@@ -3217,30 +2667,21 @@ var __exports__ = (() => {
|
|
|
3217
2667
|
get [Symbol.toStringTag]() {
|
|
3218
2668
|
return "WebGPUVertexArray";
|
|
3219
2669
|
}
|
|
3220
|
-
/** Vertex Array is a helper class under WebGPU */
|
|
3221
|
-
/** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
|
|
3222
2670
|
static isConstantAttributeZeroSupported(device) {
|
|
3223
2671
|
return device.info.type === "webgl2" || getBrowser() === "Chrome";
|
|
3224
2672
|
}
|
|
3225
|
-
// Create a VertexArray
|
|
3226
2673
|
constructor(device, props) {
|
|
3227
2674
|
super(device, props);
|
|
3228
2675
|
this.device = device;
|
|
3229
2676
|
}
|
|
3230
2677
|
destroy() {
|
|
3231
2678
|
}
|
|
3232
|
-
/**
|
|
3233
|
-
* Set an elements buffer, for indexed rendering.
|
|
3234
|
-
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
3235
|
-
*/
|
|
3236
2679
|
setIndexBuffer(buffer) {
|
|
3237
2680
|
this.indexBuffer = buffer;
|
|
3238
2681
|
}
|
|
3239
|
-
/** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
|
|
3240
2682
|
setBuffer(location, buffer) {
|
|
3241
2683
|
this.attributes[location] = buffer;
|
|
3242
2684
|
}
|
|
3243
|
-
/** Set a location in vertex attributes array to a constant value, disables the location */
|
|
3244
2685
|
setConstant(location, value) {
|
|
3245
2686
|
log.warn(`${this.id} constant attributes not supported on WebGPU`);
|
|
3246
2687
|
}
|
|
@@ -3268,9 +2709,7 @@ var __exports__ = (() => {
|
|
|
3268
2709
|
|
|
3269
2710
|
// src/adapter/webgpu-canvas-context.ts
|
|
3270
2711
|
var WebGPUCanvasContext = class extends CanvasContext {
|
|
3271
|
-
/** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
|
|
3272
2712
|
format = navigator.gpu.getPreferredCanvasFormat();
|
|
3273
|
-
/** Default stencil format for depth textures */
|
|
3274
2713
|
depthStencilFormat = "depth24plus";
|
|
3275
2714
|
depthStencilAttachment = null;
|
|
3276
2715
|
constructor(device, adapter, props) {
|
|
@@ -3282,7 +2721,6 @@ var __exports__ = (() => {
|
|
|
3282
2721
|
this.gpuCanvasContext = this.canvas.getContext("webgpu");
|
|
3283
2722
|
this.format = "bgra8unorm";
|
|
3284
2723
|
}
|
|
3285
|
-
/** Destroy any textures produced while configured and remove the context configuration. */
|
|
3286
2724
|
destroy() {
|
|
3287
2725
|
this.gpuCanvasContext.unconfigure();
|
|
3288
2726
|
}
|
|
@@ -3292,7 +2730,6 @@ var __exports__ = (() => {
|
|
|
3292
2730
|
handle: this.gpuCanvasContext.getCurrentTexture()
|
|
3293
2731
|
});
|
|
3294
2732
|
}
|
|
3295
|
-
/** Update framebuffer with properly resized "swap chain" texture views */
|
|
3296
2733
|
getCurrentFramebuffer() {
|
|
3297
2734
|
this.update();
|
|
3298
2735
|
const currentColorAttachment = this.getCurrentTexture();
|
|
@@ -3304,7 +2741,6 @@ var __exports__ = (() => {
|
|
|
3304
2741
|
depthStencilAttachment: this.depthStencilAttachment
|
|
3305
2742
|
});
|
|
3306
2743
|
}
|
|
3307
|
-
/** Resizes and updates render targets if necessary */
|
|
3308
2744
|
update() {
|
|
3309
2745
|
const [width, height] = this.getPixelSize();
|
|
3310
2746
|
const sizeChanged = width !== this.width || height !== this.height;
|
|
@@ -3318,8 +2754,6 @@ var __exports__ = (() => {
|
|
|
3318
2754
|
this.gpuCanvasContext.configure({
|
|
3319
2755
|
device: this.device.handle,
|
|
3320
2756
|
format: getWebGPUTextureFormat(this.format),
|
|
3321
|
-
// Can be used to define e.g. -srgb views
|
|
3322
|
-
// viewFormats: [...]
|
|
3323
2757
|
colorSpace: this.props.colorSpace,
|
|
3324
2758
|
alphaMode: this.props.alphaMode
|
|
3325
2759
|
});
|
|
@@ -3329,7 +2763,6 @@ var __exports__ = (() => {
|
|
|
3329
2763
|
resize(options) {
|
|
3330
2764
|
this.update();
|
|
3331
2765
|
}
|
|
3332
|
-
/** We build render targets on demand (i.e. not when size changes but when about to render) */
|
|
3333
2766
|
_createDepthStencilAttachment() {
|
|
3334
2767
|
if (!this.depthStencilAttachment) {
|
|
3335
2768
|
this.depthStencilAttachment = this.device.createTexture({
|
|
@@ -3350,7 +2783,6 @@ var __exports__ = (() => {
|
|
|
3350
2783
|
commandEncoder = null;
|
|
3351
2784
|
renderPass = null;
|
|
3352
2785
|
_isLost = false;
|
|
3353
|
-
/** Check if WebGPU is available */
|
|
3354
2786
|
static isSupported() {
|
|
3355
2787
|
return Boolean(typeof navigator !== "undefined" && navigator.gpu);
|
|
3356
2788
|
}
|
|
@@ -3361,7 +2793,6 @@ var __exports__ = (() => {
|
|
|
3361
2793
|
log.groupCollapsed(1, "WebGPUDevice created")();
|
|
3362
2794
|
const adapter = await navigator.gpu.requestAdapter({
|
|
3363
2795
|
powerPreference: "high-performance"
|
|
3364
|
-
// forceSoftware: false
|
|
3365
2796
|
});
|
|
3366
2797
|
if (!adapter) {
|
|
3367
2798
|
throw new Error("Failed to request WebGPU adapter");
|
|
@@ -3370,8 +2801,6 @@ var __exports__ = (() => {
|
|
|
3370
2801
|
log.probe(1, "Adapter available", adapterInfo)();
|
|
3371
2802
|
const gpuDevice = await adapter.requestDevice({
|
|
3372
2803
|
requiredFeatures: adapter.features
|
|
3373
|
-
// TODO ensure we obtain best limits
|
|
3374
|
-
// requiredLimits: adapter.limits
|
|
3375
2804
|
});
|
|
3376
2805
|
log.probe(1, "GPUDevice available")();
|
|
3377
2806
|
if (typeof props.canvas === "string") {
|
|
@@ -3397,12 +2826,8 @@ var __exports__ = (() => {
|
|
|
3397
2826
|
renderer: "",
|
|
3398
2827
|
version: "",
|
|
3399
2828
|
gpu: "unknown",
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
shadingLanguageVersions: {
|
|
3403
|
-
glsl: "450",
|
|
3404
|
-
wgsl: "100"
|
|
3405
|
-
},
|
|
2829
|
+
shadingLanguage: "wgsl",
|
|
2830
|
+
shadingLanguageVersion: 100,
|
|
3406
2831
|
vendorMasked: "",
|
|
3407
2832
|
rendererMasked: ""
|
|
3408
2833
|
};
|
|
@@ -3422,10 +2847,6 @@ var __exports__ = (() => {
|
|
|
3422
2847
|
});
|
|
3423
2848
|
this.features = this._getFeatures();
|
|
3424
2849
|
}
|
|
3425
|
-
// TODO
|
|
3426
|
-
// Load the glslang module now so that it is available synchronously when compiling shaders
|
|
3427
|
-
// const {glsl = true} = props;
|
|
3428
|
-
// this.glslang = glsl && await loadGlslangModule();
|
|
3429
2850
|
destroy() {
|
|
3430
2851
|
this.handle.destroy();
|
|
3431
2852
|
}
|
|
@@ -3438,11 +2859,9 @@ var __exports__ = (() => {
|
|
|
3438
2859
|
isTextureFormatSupported(format) {
|
|
3439
2860
|
return !format.includes("webgl");
|
|
3440
2861
|
}
|
|
3441
|
-
/** @todo implement proper check? */
|
|
3442
2862
|
isTextureFormatFilterable(format) {
|
|
3443
2863
|
return this.isTextureFormatSupported(format);
|
|
3444
2864
|
}
|
|
3445
|
-
/** @todo implement proper check? */
|
|
3446
2865
|
isTextureFormatRenderable(format) {
|
|
3447
2866
|
return this.isTextureFormatSupported(format);
|
|
3448
2867
|
}
|
|
@@ -3477,11 +2896,6 @@ var __exports__ = (() => {
|
|
|
3477
2896
|
createVertexArray(props) {
|
|
3478
2897
|
return new WebGPUVertexArray(this, props);
|
|
3479
2898
|
}
|
|
3480
|
-
// WebGPU specifics
|
|
3481
|
-
/**
|
|
3482
|
-
* Allows a render pass to begin against a canvas context
|
|
3483
|
-
* @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
|
|
3484
|
-
*/
|
|
3485
2899
|
beginRenderPass(props) {
|
|
3486
2900
|
this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
|
|
3487
2901
|
return new WebGPURenderPass(this, props);
|
|
@@ -3490,21 +2904,12 @@ var __exports__ = (() => {
|
|
|
3490
2904
|
this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
|
|
3491
2905
|
return new WebGPUComputePass(this, props);
|
|
3492
2906
|
}
|
|
3493
|
-
// createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
|
|
3494
|
-
// return new WebGPUCommandEncoder(this, props);
|
|
3495
|
-
// }
|
|
3496
2907
|
createTransformFeedback(props) {
|
|
3497
2908
|
throw new Error("Transform feedback not supported in WebGPU");
|
|
3498
2909
|
}
|
|
3499
2910
|
createCanvasContext(props) {
|
|
3500
2911
|
return new WebGPUCanvasContext(this, this.adapter, props);
|
|
3501
2912
|
}
|
|
3502
|
-
/**
|
|
3503
|
-
* Gets default renderpass encoder.
|
|
3504
|
-
* Creates a new encoder against default canvasContext if not already created
|
|
3505
|
-
* @note Called internally by Model.
|
|
3506
|
-
* @deprecated Create explicit pass with device.beginRenderPass
|
|
3507
|
-
*/
|
|
3508
2913
|
getDefaultRenderPass() {
|
|
3509
2914
|
throw new Error("a");
|
|
3510
2915
|
}
|
|
@@ -3558,33 +2963,22 @@ var __exports__ = (() => {
|
|
|
3558
2963
|
aspect = "all",
|
|
3559
2964
|
colorSpace = "display-p3",
|
|
3560
2965
|
premultipliedAlpha = false,
|
|
3561
|
-
// destinationX,
|
|
3562
|
-
// destinationY,
|
|
3563
|
-
// desitnationZ,
|
|
3564
2966
|
width = texture.width,
|
|
3565
2967
|
height = texture.height,
|
|
3566
2968
|
depth = 1
|
|
3567
2969
|
} = options;
|
|
3568
2970
|
const webGpuTexture = texture;
|
|
3569
|
-
this.handle?.queue.copyExternalImageToTexture(
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
mipLevel,
|
|
3581
|
-
aspect,
|
|
3582
|
-
colorSpace,
|
|
3583
|
-
premultipliedAlpha
|
|
3584
|
-
},
|
|
3585
|
-
// copySize: GPUExtent3D
|
|
3586
|
-
[width, height, depth]
|
|
3587
|
-
);
|
|
2971
|
+
this.handle?.queue.copyExternalImageToTexture({
|
|
2972
|
+
source,
|
|
2973
|
+
origin: [sourceX, sourceY]
|
|
2974
|
+
}, {
|
|
2975
|
+
texture: webGpuTexture.handle,
|
|
2976
|
+
origin: [0, 0, 0],
|
|
2977
|
+
mipLevel,
|
|
2978
|
+
aspect,
|
|
2979
|
+
colorSpace,
|
|
2980
|
+
premultipliedAlpha
|
|
2981
|
+
}, [width, height, depth]);
|
|
3588
2982
|
}
|
|
3589
2983
|
};
|
|
3590
2984
|
var WebGPUDevice = _WebGPUDevice;
|