@antv/g-webgpu 0.6.0 → 1.1.1
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/LICENSE +21 -0
- package/README.md +0 -35
- package/dist/index.umd.min.js +16 -0
- package/es/ContextRegisterPlugin.d.ts +7 -0
- package/es/ContextRegisterPlugin.js +28 -0
- package/es/WebGLContextService.d.ts +18 -0
- package/es/WebGLContextService.js +99 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +34 -6
- package/lib/ContextRegisterPlugin.d.ts +7 -0
- package/lib/ContextRegisterPlugin.js +37 -0
- package/lib/WebGLContextService.d.ts +18 -0
- package/lib/WebGLContextService.js +107 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +49 -29
- package/package.json +36 -33
- package/CHANGELOG.md +0 -75
- package/es/Kernel.js +0 -331
- package/es/Kernel.js.map +0 -1
- package/es/Renderer.js +0 -310
- package/es/Renderer.js.map +0 -1
- package/es/Scene.js +0 -39
- package/es/Scene.js.map +0 -1
- package/es/View.js +0 -86
- package/es/View.js.map +0 -1
- package/es/World.js +0 -239
- package/es/World.js.map +0 -1
- package/es/camera/Camera.js +0 -801
- package/es/camera/Camera.js.map +0 -1
- package/es/camera/Landmark.js +0 -86
- package/es/camera/Landmark.js.map +0 -1
- package/es/index.js.map +0 -1
- package/es/renderable/Renderable.js +0 -132
- package/es/renderable/Renderable.js.map +0 -1
- package/es/renderable/line/Line.js +0 -164
- package/es/renderable/line/Line.js.map +0 -1
- package/es/renderable/point/Point.js +0 -203
- package/es/renderable/point/Point.js.map +0 -1
- package/es/utils/canvas.js +0 -8
- package/es/utils/canvas.js.map +0 -1
- package/es/utils/math.js +0 -23
- package/es/utils/math.js.map +0 -1
- package/es/utils/picking.js +0 -4
- package/es/utils/picking.js.map +0 -1
- package/es/utils/polyline-normals.js +0 -127
- package/es/utils/polyline-normals.js.map +0 -1
- package/lib/Kernel.js +0 -352
- package/lib/Kernel.js.map +0 -1
- package/lib/Renderer.js +0 -325
- package/lib/Renderer.js.map +0 -1
- package/lib/Scene.js +0 -49
- package/lib/Scene.js.map +0 -1
- package/lib/View.js +0 -99
- package/lib/View.js.map +0 -1
- package/lib/World.js +0 -265
- package/lib/World.js.map +0 -1
- package/lib/camera/Camera.js +0 -870
- package/lib/camera/Camera.js.map +0 -1
- package/lib/camera/Landmark.js +0 -95
- package/lib/camera/Landmark.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/renderable/Renderable.js +0 -141
- package/lib/renderable/Renderable.js.map +0 -1
- package/lib/renderable/line/Line.js +0 -182
- package/lib/renderable/line/Line.js.map +0 -1
- package/lib/renderable/point/Point.js +0 -221
- package/lib/renderable/point/Point.js.map +0 -1
- package/lib/utils/canvas.js +0 -15
- package/lib/utils/canvas.js.map +0 -1
- package/lib/utils/math.js +0 -36
- package/lib/utils/math.js.map +0 -1
- package/lib/utils/picking.js +0 -11
- package/lib/utils/picking.js.map +0 -1
- package/lib/utils/polyline-normals.js +0 -135
- package/lib/utils/polyline-normals.js.map +0 -1
package/es/Kernel.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import _initializerDefineProperty from "@babel/runtime/helpers/initializerDefineProperty";
|
|
5
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
6
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
7
|
-
import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
|
|
8
|
-
import _initializerWarningHelper from "@babel/runtime/helpers/initializerWarningHelper";
|
|
9
|
-
import _isTypedArray from "lodash/isTypedArray";
|
|
10
|
-
import _isNumber from "lodash/isNumber";
|
|
11
|
-
import _isArray from "lodash/isArray";
|
|
12
|
-
|
|
13
|
-
var _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _temp;
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
|
-
import { AST_TOKEN_TYPES, DefineValuePlaceholder, IDENTIFIER, STORAGE_CLASS, Target, createEntity } from '@antv/g-webgpu-core'; // tslint:disable-next-line:no-submodule-imports
|
|
20
|
-
|
|
21
|
-
import * as WebGPUConstants from '@webgpu/types/dist/constants';
|
|
22
|
-
import { inject, injectable } from 'inversify';
|
|
23
|
-
import { createCanvas } from './utils/canvas';
|
|
24
|
-
export var Kernel = (_dec = injectable(), _dec2 = inject(IDENTIFIER.RenderEngine), _dec3 = inject(IDENTIFIER.ConfigService), _dec(_class = (_class2 = (_temp = /*#__PURE__*/function () {
|
|
25
|
-
function Kernel() {
|
|
26
|
-
_classCallCheck(this, Kernel);
|
|
27
|
-
|
|
28
|
-
_initializerDefineProperty(this, "engine", _descriptor, this);
|
|
29
|
-
|
|
30
|
-
_initializerDefineProperty(this, "configService", _descriptor2, this);
|
|
31
|
-
|
|
32
|
-
this.entity = createEntity();
|
|
33
|
-
this.model = void 0;
|
|
34
|
-
this.dirty = true;
|
|
35
|
-
this.compiledBundle = void 0;
|
|
36
|
-
this.initPromise = void 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_createClass(Kernel, [{
|
|
40
|
-
key: "init",
|
|
41
|
-
value: function init() {
|
|
42
|
-
var _this$configService$g = this.configService.get(),
|
|
43
|
-
canvas = _this$configService$g.canvas,
|
|
44
|
-
engineOptions = _this$configService$g.engineOptions;
|
|
45
|
-
|
|
46
|
-
this.initPromise = this.engine.init(_objectSpread({
|
|
47
|
-
canvas: canvas || createCanvas(),
|
|
48
|
-
swapChainFormat: WebGPUConstants.TextureFormat.BGRA8Unorm,
|
|
49
|
-
antialiasing: false
|
|
50
|
-
}, engineOptions));
|
|
51
|
-
}
|
|
52
|
-
}, {
|
|
53
|
-
key: "setBundle",
|
|
54
|
-
value: function setBundle(bundle) {
|
|
55
|
-
// deep clone
|
|
56
|
-
this.compiledBundle = JSON.parse(JSON.stringify(bundle));
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "setDispatch",
|
|
60
|
-
value: function setDispatch(dispatch) {
|
|
61
|
-
if (this.compiledBundle.context) {
|
|
62
|
-
this.compiledBundle.context.dispatch = dispatch;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "setMaxIteration",
|
|
69
|
-
value: function setMaxIteration(maxIteration) {
|
|
70
|
-
if (this.compiledBundle.context) {
|
|
71
|
-
this.compiledBundle.context.maxIteration = maxIteration;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "setBinding",
|
|
78
|
-
value: function setBinding(name, data) {
|
|
79
|
-
var _this = this;
|
|
80
|
-
|
|
81
|
-
if (typeof name === 'string') {
|
|
82
|
-
var isNumberLikeData = _isNumber(data) || _isTypedArray(data) || _isArray(data);
|
|
83
|
-
|
|
84
|
-
if (this.compiledBundle && this.compiledBundle.context) {
|
|
85
|
-
// set define, eg. setBinding('MAX_LENGTH', 10)
|
|
86
|
-
var existedDefine = this.compiledBundle.context.defines.find(function (b) {
|
|
87
|
-
return b.name === name;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
if (existedDefine) {
|
|
91
|
-
existedDefine.value = data;
|
|
92
|
-
return this;
|
|
93
|
-
} // set uniform
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var existedBinding = this.compiledBundle.context.uniforms.find(function (b) {
|
|
97
|
-
return b.name === name;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (existedBinding) {
|
|
101
|
-
// update uniform or buffer
|
|
102
|
-
if (isNumberLikeData) {
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
existedBinding.data = data;
|
|
105
|
-
existedBinding.isReferer = false;
|
|
106
|
-
|
|
107
|
-
if (existedBinding.storageClass === STORAGE_CLASS.Uniform) {
|
|
108
|
-
if (this.model) {
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
this.model.updateUniform(name, data);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
if (this.model) {
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
this.model.updateBuffer(name, data);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
// update with another kernel
|
|
120
|
-
existedBinding.isReferer = true; // @ts-ignore
|
|
121
|
-
|
|
122
|
-
existedBinding.data = data;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
Object.keys(name).forEach(function (key) {
|
|
128
|
-
_this.setBinding(key, name[key]);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
}, {
|
|
135
|
-
key: "execute",
|
|
136
|
-
value: function () {
|
|
137
|
-
var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
138
|
-
var _this2 = this;
|
|
139
|
-
|
|
140
|
-
var iteration,
|
|
141
|
-
i,
|
|
142
|
-
_args = arguments;
|
|
143
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
144
|
-
while (1) {
|
|
145
|
-
switch (_context.prev = _context.next) {
|
|
146
|
-
case 0:
|
|
147
|
-
iteration = _args.length > 0 && _args[0] !== undefined ? _args[0] : 1;
|
|
148
|
-
|
|
149
|
-
if (!this.dirty) {
|
|
150
|
-
_context.next = 6;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (this.compiledBundle.context) {
|
|
155
|
-
if (iteration > 1) {
|
|
156
|
-
this.compiledBundle.context.maxIteration = iteration;
|
|
157
|
-
} else {
|
|
158
|
-
this.compiledBundle.context.maxIteration++;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
_context.next = 5;
|
|
163
|
-
return this.compile();
|
|
164
|
-
|
|
165
|
-
case 5:
|
|
166
|
-
this.dirty = false;
|
|
167
|
-
|
|
168
|
-
case 6:
|
|
169
|
-
this.engine.beginFrame(); // 首先开启当前 frame 的 compute pass
|
|
170
|
-
|
|
171
|
-
this.engine.clear({});
|
|
172
|
-
|
|
173
|
-
if (this.compiledBundle.context) {
|
|
174
|
-
this.compiledBundle.context.uniforms.filter(function (_ref) {
|
|
175
|
-
var isReferer = _ref.isReferer;
|
|
176
|
-
return isReferer;
|
|
177
|
-
}).forEach(function (_ref2) {
|
|
178
|
-
var data = _ref2.data,
|
|
179
|
-
name = _ref2.name;
|
|
180
|
-
|
|
181
|
-
// @ts-ignore
|
|
182
|
-
_this2.model.confirmInput(data.model, name);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
for (i = 0; i < iteration; i++) {
|
|
187
|
-
this.model.run();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
this.engine.endFrame();
|
|
191
|
-
return _context.abrupt("return", this);
|
|
192
|
-
|
|
193
|
-
case 12:
|
|
194
|
-
case "end":
|
|
195
|
-
return _context.stop();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}, _callee, this);
|
|
199
|
-
}));
|
|
200
|
-
|
|
201
|
-
function execute() {
|
|
202
|
-
return _execute.apply(this, arguments);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return execute;
|
|
206
|
-
}()
|
|
207
|
-
/**
|
|
208
|
-
* read output from GPUBuffer
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
}, {
|
|
212
|
-
key: "getOutput",
|
|
213
|
-
value: function () {
|
|
214
|
-
var _getOutput = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
215
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
216
|
-
while (1) {
|
|
217
|
-
switch (_context2.prev = _context2.next) {
|
|
218
|
-
case 0:
|
|
219
|
-
return _context2.abrupt("return", this.model.readData());
|
|
220
|
-
|
|
221
|
-
case 1:
|
|
222
|
-
case "end":
|
|
223
|
-
return _context2.stop();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}, _callee2, this);
|
|
227
|
-
}));
|
|
228
|
-
|
|
229
|
-
function getOutput() {
|
|
230
|
-
return _getOutput.apply(this, arguments);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return getOutput;
|
|
234
|
-
}()
|
|
235
|
-
}, {
|
|
236
|
-
key: "compile",
|
|
237
|
-
value: function () {
|
|
238
|
-
var _compile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
239
|
-
var context, target, shader;
|
|
240
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
241
|
-
while (1) {
|
|
242
|
-
switch (_context3.prev = _context3.next) {
|
|
243
|
-
case 0:
|
|
244
|
-
_context3.next = 2;
|
|
245
|
-
return this.initPromise;
|
|
246
|
-
|
|
247
|
-
case 2:
|
|
248
|
-
context = _objectSpread({}, this.compiledBundle.context);
|
|
249
|
-
target = this.engine.supportWebGPU ? this.engine.useWGSL ? Target.WGSL : Target.GLSL450 : Target.GLSL100;
|
|
250
|
-
shader = this.compiledBundle.shaders[target]; // this.bindings?.forEach(({ name, data }) => {
|
|
251
|
-
// if (name === name.toUpperCase()) {
|
|
252
|
-
// const define = context.defines.find((d) => d.name === name);
|
|
253
|
-
// if (define) {
|
|
254
|
-
// // @ts-ignore
|
|
255
|
-
// define.value = data;
|
|
256
|
-
// }
|
|
257
|
-
// }
|
|
258
|
-
// });
|
|
259
|
-
// 生成运行时 define
|
|
260
|
-
|
|
261
|
-
context.defines.filter(function (define) {
|
|
262
|
-
return define.runtime;
|
|
263
|
-
}).forEach(function (define) {
|
|
264
|
-
var valuePlaceHolder = "".concat(DefineValuePlaceholder).concat(define.name);
|
|
265
|
-
shader = shader.replace(valuePlaceHolder, "".concat(define.value));
|
|
266
|
-
});
|
|
267
|
-
context.shader = shader; // 添加 uniform 绑定的数据
|
|
268
|
-
|
|
269
|
-
context.uniforms.forEach(function (uniform) {
|
|
270
|
-
// const binding = this.bindings.find((b) => b.name === uniform.name);
|
|
271
|
-
// if (binding) {
|
|
272
|
-
// // @ts-ignore
|
|
273
|
-
// uniform.data = binding.referer || binding.data;
|
|
274
|
-
// // @ts-ignore
|
|
275
|
-
// uniform.isReferer = !!binding.referer;
|
|
276
|
-
// }
|
|
277
|
-
// 未指定数据,尝试根据 uniform 类型初始化
|
|
278
|
-
if (!uniform.data) {
|
|
279
|
-
if (uniform.storageClass === STORAGE_CLASS.StorageBuffer) {
|
|
280
|
-
var sizePerElement = 1;
|
|
281
|
-
|
|
282
|
-
if (uniform.type === AST_TOKEN_TYPES.FloatArray) {
|
|
283
|
-
sizePerElement = 1;
|
|
284
|
-
} else if (uniform.type === AST_TOKEN_TYPES.Vector4FloatArray) {
|
|
285
|
-
sizePerElement = 4;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
uniform.data = new Float32Array(context.output.length * sizePerElement).fill(0);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}); // } else if (uniform.type === 'image2D') {
|
|
292
|
-
// // @ts-ignore
|
|
293
|
-
// buffer.data = new Uint8ClampedArray(context.output.length!).fill(0);
|
|
294
|
-
// }
|
|
295
|
-
|
|
296
|
-
this.compiledBundle.context = context;
|
|
297
|
-
_context3.next = 11;
|
|
298
|
-
return this.engine.createComputeModel(this.compiledBundle.context);
|
|
299
|
-
|
|
300
|
-
case 11:
|
|
301
|
-
this.model = _context3.sent;
|
|
302
|
-
|
|
303
|
-
case 12:
|
|
304
|
-
case "end":
|
|
305
|
-
return _context3.stop();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}, _callee3, this);
|
|
309
|
-
}));
|
|
310
|
-
|
|
311
|
-
function compile() {
|
|
312
|
-
return _compile.apply(this, arguments);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return compile;
|
|
316
|
-
}()
|
|
317
|
-
}]);
|
|
318
|
-
|
|
319
|
-
return Kernel;
|
|
320
|
-
}(), _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "engine", [_dec2], {
|
|
321
|
-
configurable: true,
|
|
322
|
-
enumerable: true,
|
|
323
|
-
writable: true,
|
|
324
|
-
initializer: null
|
|
325
|
-
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "configService", [_dec3], {
|
|
326
|
-
configurable: true,
|
|
327
|
-
enumerable: true,
|
|
328
|
-
writable: true,
|
|
329
|
-
initializer: null
|
|
330
|
-
})), _class2)) || _class);
|
|
331
|
-
//# sourceMappingURL=Kernel.js.map
|
package/es/Kernel.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Kernel.ts"],"names":["AST_TOKEN_TYPES","DefineValuePlaceholder","IDENTIFIER","STORAGE_CLASS","Target","createEntity","WebGPUConstants","inject","injectable","createCanvas","Kernel","RenderEngine","ConfigService","entity","model","dirty","compiledBundle","initPromise","configService","get","canvas","engineOptions","engine","init","swapChainFormat","TextureFormat","BGRA8Unorm","antialiasing","bundle","JSON","parse","stringify","dispatch","context","maxIteration","name","data","isNumberLikeData","existedDefine","defines","find","b","value","existedBinding","uniforms","isReferer","storageClass","Uniform","updateUniform","updateBuffer","Object","keys","forEach","key","setBinding","iteration","compile","beginFrame","clear","filter","confirmInput","i","run","endFrame","readData","target","supportWebGPU","useWGSL","WGSL","GLSL450","GLSL100","shader","shaders","define","runtime","valuePlaceHolder","replace","uniform","StorageBuffer","sizePerElement","type","FloatArray","Vector4FloatArray","Float32Array","output","length","fill","createComputeModel"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SACEA,eADF,EAEEC,sBAFF,EAMEC,UANF,EAWEC,aAXF,EAYEC,MAZF,EAaEC,YAbF,QAcO,qBAdP,C,CAeA;;AACA,OAAO,KAAKC,eAAZ,MAAiC,8BAAjC;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,SAASC,YAAT,QAA6B,gBAA7B;AAGA,WAAaC,MAAb,WADCF,UAAU,EACX,UACGD,MAAM,CAACL,UAAU,CAACS,YAAZ,CADT,UAIGJ,MAAM,CAACL,UAAU,CAACU,aAAZ,CAJT;AAAA;AAAA;;AAAA;;AAAA;;AAAA,SAOUC,MAPV,GAOmBR,YAAY,EAP/B;AAAA,SASUS,KATV;AAAA,SAWUC,KAXV,GAW2B,IAX3B;AAAA,SAaUC,cAbV;AAAA,SAeUC,WAfV;AAAA;;AAAA;AAAA;AAAA,2BAiBgB;AAAA,kCACsB,KAAKC,aAAL,CAAmBC,GAAnB,EADtB;AAAA,UACJC,MADI,yBACJA,MADI;AAAA,UACIC,aADJ,yBACIA,aADJ;;AAGZ,WAAKJ,WAAL,GAAmB,KAAKK,MAAL,CAAYC,IAAZ;AACjBH,QAAAA,MAAM,EAAEA,MAAM,IAAIX,YAAY,EADb;AAEjBe,QAAAA,eAAe,EAAElB,eAAe,CAACmB,aAAhB,CAA8BC,UAF9B;AAGjBC,QAAAA,YAAY,EAAE;AAHG,SAIdN,aAJc,EAAnB;AAMD;AA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AAe,CAACkF,iBAArC,EAAwD;AAC7DH,wBAAAA,cAAc,GAAG,CAAjB;AACD;;AACDF,sBAAAA,OAAO,CAACzC,IAAR,GAAe,IAAI+C,YAAJ,CACblD,OAAO,CAACmD,MAAR,CAAeC,MAAf,GAAyBN,cADZ,EAEbO,IAFa,CAER,CAFQ,CAAf;AAGD;AACF;AACF,iBAvBD,EAzMJ,CAiOI;AACA;AACA;AACA;;AAEA,qBAAKtE,cAAL,CAAoBiB,OAApB,GAA8BA,OAA9B;AAtOJ;AAAA,uBAuOuB,KAAKX,MAAL,CAAYiE,kBAAZ,CACjB,KAAKvE,cAAL,CAAoBiB,OADH,CAvOvB;;AAAA;AAuOI,qBAAKnB,KAvOT;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import {\n AST_TOKEN_TYPES,\n DefineValuePlaceholder,\n GLSLContext,\n IComputeModel,\n IConfigService,\n IDENTIFIER,\n IRendererService,\n IShaderModuleService,\n ISystem,\n KernelBundle,\n STORAGE_CLASS,\n Target,\n createEntity,\n} from '@antv/g-webgpu-core';\n// tslint:disable-next-line:no-submodule-imports\nimport * as WebGPUConstants from '@webgpu/types/dist/constants';\nimport { inject, injectable } from 'inversify';\nimport { isArray, isNil, isNumber, isTypedArray } from 'lodash';\nimport { createCanvas } from './utils/canvas';\n\n@injectable()\nexport class Kernel {\n @inject(IDENTIFIER.RenderEngine)\n private readonly engine: IRendererService;\n\n @inject(IDENTIFIER.ConfigService)\n private readonly configService: IConfigService;\n\n private entity = createEntity();\n\n private model: IComputeModel;\n\n private dirty: boolean = true;\n\n private compiledBundle: KernelBundle;\n\n private initPromise: Promise<void>;\n\n public init() {\n const { canvas, engineOptions } = this.configService.get();\n\n this.initPromise = this.engine.init({\n canvas: canvas || createCanvas(),\n swapChainFormat: WebGPUConstants.TextureFormat.BGRA8Unorm,\n antialiasing: false,\n ...engineOptions,\n });\n }\n\n public setBundle(bundle: KernelBundle) {\n // deep clone\n this.compiledBundle = JSON.parse(JSON.stringify(bundle));\n }\n\n public setDispatch(dispatch: [number, number, number]) {\n if (this.compiledBundle.context) {\n this.compiledBundle.context.dispatch = dispatch;\n }\n return this;\n }\n\n public setMaxIteration(maxIteration: number) {\n if (this.compiledBundle.context) {\n this.compiledBundle.context.maxIteration = maxIteration;\n }\n return this;\n }\n\n public setBinding(\n name:\n | string\n | Record<\n string,\n | number\n | number[]\n | Float32Array\n | Uint8Array\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n >,\n data?:\n | number\n | number[]\n | Float32Array\n | Uint8Array\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n | Kernel,\n ) {\n if (typeof name === 'string') {\n const isNumberLikeData =\n isNumber(data) || isTypedArray(data) || isArray(data);\n if (this.compiledBundle && this.compiledBundle.context) {\n // set define, eg. setBinding('MAX_LENGTH', 10)\n const existedDefine = this.compiledBundle.context.defines.find(\n (b) => b.name === name,\n );\n if (existedDefine) {\n existedDefine.value = data as number;\n return this;\n }\n\n // set uniform\n const existedBinding = this.compiledBundle.context.uniforms.find(\n (b) => b.name === name,\n );\n if (existedBinding) {\n // update uniform or buffer\n if (isNumberLikeData) {\n // @ts-ignore\n existedBinding.data = data;\n existedBinding.isReferer = false;\n\n if (existedBinding.storageClass === STORAGE_CLASS.Uniform) {\n if (this.model) {\n // @ts-ignore\n this.model.updateUniform(name, data);\n }\n } else {\n if (this.model) {\n // @ts-ignore\n this.model.updateBuffer(name, data);\n }\n }\n } else {\n // update with another kernel\n existedBinding.isReferer = true;\n // @ts-ignore\n existedBinding.data = data as Kernel;\n }\n }\n }\n } else {\n Object.keys(name).forEach((key) => {\n this.setBinding(key, name[key]);\n });\n }\n return this;\n }\n\n public async execute(iteration: number = 1) {\n if (this.dirty) {\n if (this.compiledBundle.context) {\n if (iteration > 1) {\n this.compiledBundle.context.maxIteration = iteration;\n } else {\n this.compiledBundle.context.maxIteration++;\n }\n }\n await this.compile();\n this.dirty = false;\n }\n\n this.engine.beginFrame();\n\n // 首先开启当前 frame 的 compute pass\n this.engine.clear({});\n\n if (this.compiledBundle.context) {\n this.compiledBundle.context.uniforms\n .filter(({ isReferer }) => isReferer)\n .forEach(({ data, name }) => {\n // @ts-ignore\n this.model.confirmInput((data as Kernel).model, name);\n });\n }\n for (let i = 0; i < iteration; i++) {\n this.model.run();\n }\n\n this.engine.endFrame();\n return this;\n }\n\n /**\n * read output from GPUBuffer\n */\n public async getOutput() {\n return this.model.readData();\n }\n\n private async compile() {\n await this.initPromise;\n\n const context = {\n ...this.compiledBundle.context!,\n };\n\n const target = this.engine.supportWebGPU\n ? this.engine.useWGSL\n ? Target.WGSL\n : Target.GLSL450\n : Target.GLSL100;\n let shader = this.compiledBundle.shaders[target];\n\n // this.bindings?.forEach(({ name, data }) => {\n // if (name === name.toUpperCase()) {\n // const define = context.defines.find((d) => d.name === name);\n // if (define) {\n // // @ts-ignore\n // define.value = data;\n // }\n // }\n // });\n\n // 生成运行时 define\n context.defines\n .filter((define) => define.runtime)\n .forEach((define) => {\n const valuePlaceHolder = `${DefineValuePlaceholder}${define.name}`;\n shader = shader.replace(valuePlaceHolder, `${define.value}`);\n });\n\n context.shader = shader;\n\n // 添加 uniform 绑定的数据\n context.uniforms.forEach((uniform) => {\n // const binding = this.bindings.find((b) => b.name === uniform.name);\n // if (binding) {\n // // @ts-ignore\n // uniform.data = binding.referer || binding.data;\n // // @ts-ignore\n // uniform.isReferer = !!binding.referer;\n // }\n\n // 未指定数据,尝试根据 uniform 类型初始化\n if (!uniform.data) {\n if (uniform.storageClass === STORAGE_CLASS.StorageBuffer) {\n let sizePerElement = 1;\n if (uniform.type === AST_TOKEN_TYPES.FloatArray) {\n sizePerElement = 1;\n } else if (uniform.type === AST_TOKEN_TYPES.Vector4FloatArray) {\n sizePerElement = 4;\n }\n uniform.data = new Float32Array(\n context.output.length! * sizePerElement,\n ).fill(0);\n }\n }\n });\n // } else if (uniform.type === 'image2D') {\n // // @ts-ignore\n // buffer.data = new Uint8ClampedArray(context.output.length!).fill(0);\n // }\n\n this.compiledBundle.context = context;\n this.model = await this.engine.createComputeModel(\n this.compiledBundle.context,\n );\n }\n}\n"],"file":"Kernel.js"}
|
package/es/Renderer.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _initializerDefineProperty from "@babel/runtime/helpers/initializerDefineProperty";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
-
import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
|
|
7
|
-
import _initializerWarningHelper from "@babel/runtime/helpers/initializerWarningHelper";
|
|
8
|
-
|
|
9
|
-
var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3, _temp;
|
|
10
|
-
|
|
11
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
|
-
|
|
13
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
-
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
16
|
-
|
|
17
|
-
import { IDENTIFIER } from '@antv/g-webgpu-core'; // tslint:disable-next-line:no-submodule-imports
|
|
18
|
-
|
|
19
|
-
import * as WebGPUConstants from '@webgpu/types/dist/constants';
|
|
20
|
-
import { inject, injectable } from 'inversify';
|
|
21
|
-
export var Renderer = (_dec = injectable(), _dec2 = inject(IDENTIFIER.RenderEngine), _dec3 = inject(IDENTIFIER.ShaderModuleService), _dec4 = inject(IDENTIFIER.ConfigService), _dec(_class = (_class2 = (_temp = /*#__PURE__*/function () {
|
|
22
|
-
function Renderer() {
|
|
23
|
-
_classCallCheck(this, Renderer);
|
|
24
|
-
|
|
25
|
-
_initializerDefineProperty(this, "engine", _descriptor, this);
|
|
26
|
-
|
|
27
|
-
_initializerDefineProperty(this, "shaderModule", _descriptor2, this);
|
|
28
|
-
|
|
29
|
-
_initializerDefineProperty(this, "configService", _descriptor3, this);
|
|
30
|
-
|
|
31
|
-
this.inited = false;
|
|
32
|
-
this.rendering = false;
|
|
33
|
-
this.pendings = [];
|
|
34
|
-
this.views = [];
|
|
35
|
-
this.size = void 0;
|
|
36
|
-
this.container = void 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_createClass(Renderer, [{
|
|
40
|
-
key: "init",
|
|
41
|
-
value: function () {
|
|
42
|
-
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
43
|
-
var systems, config, _iterator, _step, system;
|
|
44
|
-
|
|
45
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
46
|
-
while (1) {
|
|
47
|
-
switch (_context.prev = _context.next) {
|
|
48
|
-
case 0:
|
|
49
|
-
// 模块化处理
|
|
50
|
-
this.shaderModule.registerBuiltinModules();
|
|
51
|
-
systems = this.container.getAll(IDENTIFIER.Systems);
|
|
52
|
-
config = this.configService.get();
|
|
53
|
-
|
|
54
|
-
if (!config.canvas) {
|
|
55
|
-
_context.next = 25;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_context.next = 6;
|
|
60
|
-
return this.engine.init({
|
|
61
|
-
canvas: config.canvas,
|
|
62
|
-
swapChainFormat: WebGPUConstants.TextureFormat.BGRA8Unorm,
|
|
63
|
-
antialiasing: false
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
case 6:
|
|
67
|
-
_iterator = _createForOfIteratorHelper(systems);
|
|
68
|
-
_context.prev = 7;
|
|
69
|
-
|
|
70
|
-
_iterator.s();
|
|
71
|
-
|
|
72
|
-
case 9:
|
|
73
|
-
if ((_step = _iterator.n()).done) {
|
|
74
|
-
_context.next = 16;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
system = _step.value;
|
|
79
|
-
|
|
80
|
-
if (!system.initialize) {
|
|
81
|
-
_context.next = 14;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
_context.next = 14;
|
|
86
|
-
return system.initialize();
|
|
87
|
-
|
|
88
|
-
case 14:
|
|
89
|
-
_context.next = 9;
|
|
90
|
-
break;
|
|
91
|
-
|
|
92
|
-
case 16:
|
|
93
|
-
_context.next = 21;
|
|
94
|
-
break;
|
|
95
|
-
|
|
96
|
-
case 18:
|
|
97
|
-
_context.prev = 18;
|
|
98
|
-
_context.t0 = _context["catch"](7);
|
|
99
|
-
|
|
100
|
-
_iterator.e(_context.t0);
|
|
101
|
-
|
|
102
|
-
case 21:
|
|
103
|
-
_context.prev = 21;
|
|
104
|
-
|
|
105
|
-
_iterator.f();
|
|
106
|
-
|
|
107
|
-
return _context.finish(21);
|
|
108
|
-
|
|
109
|
-
case 24:
|
|
110
|
-
this.inited = true;
|
|
111
|
-
|
|
112
|
-
case 25:
|
|
113
|
-
case "end":
|
|
114
|
-
return _context.stop();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, _callee, this, [[7, 18, 21, 24]]);
|
|
118
|
-
}));
|
|
119
|
-
|
|
120
|
-
function init() {
|
|
121
|
-
return _init.apply(this, arguments);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return init;
|
|
125
|
-
}()
|
|
126
|
-
}, {
|
|
127
|
-
key: "render",
|
|
128
|
-
value: function () {
|
|
129
|
-
var _render = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
130
|
-
var systems,
|
|
131
|
-
_len,
|
|
132
|
-
views,
|
|
133
|
-
_key,
|
|
134
|
-
_iterator2,
|
|
135
|
-
_step2,
|
|
136
|
-
system,
|
|
137
|
-
_args2 = arguments;
|
|
138
|
-
|
|
139
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
140
|
-
while (1) {
|
|
141
|
-
switch (_context2.prev = _context2.next) {
|
|
142
|
-
case 0:
|
|
143
|
-
if (!(!this.inited || this.rendering)) {
|
|
144
|
-
_context2.next = 2;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return _context2.abrupt("return");
|
|
149
|
-
|
|
150
|
-
case 2:
|
|
151
|
-
if (this.pendings.length) {
|
|
152
|
-
this.pendings.forEach(function (pending) {
|
|
153
|
-
pending();
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.rendering = true;
|
|
158
|
-
this.engine.beginFrame();
|
|
159
|
-
systems = this.container.getAll(IDENTIFIER.Systems);
|
|
160
|
-
|
|
161
|
-
for (_len = _args2.length, views = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
162
|
-
views[_key] = _args2[_key];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_iterator2 = _createForOfIteratorHelper(systems);
|
|
166
|
-
_context2.prev = 8;
|
|
167
|
-
|
|
168
|
-
_iterator2.s();
|
|
169
|
-
|
|
170
|
-
case 10:
|
|
171
|
-
if ((_step2 = _iterator2.n()).done) {
|
|
172
|
-
_context2.next = 17;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
system = _step2.value;
|
|
177
|
-
|
|
178
|
-
if (!system.execute) {
|
|
179
|
-
_context2.next = 15;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
_context2.next = 15;
|
|
184
|
-
return system.execute(views);
|
|
185
|
-
|
|
186
|
-
case 15:
|
|
187
|
-
_context2.next = 10;
|
|
188
|
-
break;
|
|
189
|
-
|
|
190
|
-
case 17:
|
|
191
|
-
_context2.next = 22;
|
|
192
|
-
break;
|
|
193
|
-
|
|
194
|
-
case 19:
|
|
195
|
-
_context2.prev = 19;
|
|
196
|
-
_context2.t0 = _context2["catch"](8);
|
|
197
|
-
|
|
198
|
-
_iterator2.e(_context2.t0);
|
|
199
|
-
|
|
200
|
-
case 22:
|
|
201
|
-
_context2.prev = 22;
|
|
202
|
-
|
|
203
|
-
_iterator2.f();
|
|
204
|
-
|
|
205
|
-
return _context2.finish(22);
|
|
206
|
-
|
|
207
|
-
case 25:
|
|
208
|
-
// 录制一遍绘制命令,后续直接播放
|
|
209
|
-
// if (this.useRenderBundle) {
|
|
210
|
-
// if (!this.renderBundleRecorded) {
|
|
211
|
-
// this.engine.startRecordBundle();
|
|
212
|
-
// if (this.onUpdate) {
|
|
213
|
-
// await this.onUpdate(this.engine);
|
|
214
|
-
// }
|
|
215
|
-
// this.renderBundle = this.engine.stopRecordBundle();
|
|
216
|
-
// this.renderBundleRecorded = true;
|
|
217
|
-
// }
|
|
218
|
-
// this.engine.executeBundles([this.renderBundle]);
|
|
219
|
-
// } else {
|
|
220
|
-
// if (this.onUpdate) {
|
|
221
|
-
// await this.onUpdate(this.engine);
|
|
222
|
-
// }
|
|
223
|
-
// }
|
|
224
|
-
this.engine.endFrame();
|
|
225
|
-
this.rendering = false;
|
|
226
|
-
|
|
227
|
-
case 27:
|
|
228
|
-
case "end":
|
|
229
|
-
return _context2.stop();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}, _callee2, this, [[8, 19, 22, 25]]);
|
|
233
|
-
}));
|
|
234
|
-
|
|
235
|
-
function render() {
|
|
236
|
-
return _render.apply(this, arguments);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return render;
|
|
240
|
-
}()
|
|
241
|
-
}, {
|
|
242
|
-
key: "clear",
|
|
243
|
-
value: function clear(options) {
|
|
244
|
-
var _this = this;
|
|
245
|
-
|
|
246
|
-
if (this.inited) {
|
|
247
|
-
this.engine.clear(options);
|
|
248
|
-
} else {
|
|
249
|
-
this.pendings.unshift(function () {
|
|
250
|
-
_this.engine.clear(options);
|
|
251
|
-
|
|
252
|
-
_this.pendings.shift();
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return this;
|
|
257
|
-
} // public setScissor(
|
|
258
|
-
// scissor: Partial<{
|
|
259
|
-
// enable: boolean;
|
|
260
|
-
// box: {
|
|
261
|
-
// x: number;
|
|
262
|
-
// y: number;
|
|
263
|
-
// width: number;
|
|
264
|
-
// height: number;
|
|
265
|
-
// };
|
|
266
|
-
// }>,
|
|
267
|
-
// ) {
|
|
268
|
-
// this.engine.setScissor(scissor);
|
|
269
|
-
// return this;
|
|
270
|
-
// }
|
|
271
|
-
|
|
272
|
-
}, {
|
|
273
|
-
key: "setSize",
|
|
274
|
-
value: function setSize(_ref) {
|
|
275
|
-
var width = _ref.width,
|
|
276
|
-
height = _ref.height;
|
|
277
|
-
var canvas = this.engine.getCanvas();
|
|
278
|
-
this.size = {
|
|
279
|
-
width: width,
|
|
280
|
-
height: height
|
|
281
|
-
};
|
|
282
|
-
canvas.width = width;
|
|
283
|
-
canvas.height = height;
|
|
284
|
-
return this;
|
|
285
|
-
}
|
|
286
|
-
}, {
|
|
287
|
-
key: "getSize",
|
|
288
|
-
value: function getSize() {
|
|
289
|
-
return this.size;
|
|
290
|
-
}
|
|
291
|
-
}]);
|
|
292
|
-
|
|
293
|
-
return Renderer;
|
|
294
|
-
}(), _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "engine", [_dec2], {
|
|
295
|
-
configurable: true,
|
|
296
|
-
enumerable: true,
|
|
297
|
-
writable: true,
|
|
298
|
-
initializer: null
|
|
299
|
-
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "shaderModule", [_dec3], {
|
|
300
|
-
configurable: true,
|
|
301
|
-
enumerable: true,
|
|
302
|
-
writable: true,
|
|
303
|
-
initializer: null
|
|
304
|
-
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "configService", [_dec4], {
|
|
305
|
-
configurable: true,
|
|
306
|
-
enumerable: true,
|
|
307
|
-
writable: true,
|
|
308
|
-
initializer: null
|
|
309
|
-
})), _class2)) || _class);
|
|
310
|
-
//# sourceMappingURL=Renderer.js.map
|