@antv/l7-renderer 2.20.14 → 2.20.15

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.
@@ -1,12 +1,14 @@
1
- import type { Bindings, BindingsDescriptor, Device, InputLayout, InputLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor } from '@antv/g-device-api';
1
+ import type { Bindings, BindingsDescriptor, Device, InputLayout, InputLayoutDescriptor, Program, ProgramDescriptor, RenderPipeline, RenderPipelineDescriptor } from '@antv/g-device-api';
2
2
  export declare class RenderCache {
3
3
  private device;
4
4
  constructor(device: Device);
5
5
  private bindingsCache;
6
6
  private renderPipelinesCache;
7
7
  private inputLayoutsCache;
8
+ private programCache;
8
9
  createBindings(descriptor: BindingsDescriptor): Bindings;
9
10
  createRenderPipeline(descriptor: RenderPipelineDescriptor): RenderPipeline;
10
11
  createInputLayout(descriptor: InputLayoutDescriptor): InputLayout;
12
+ createProgram(descriptor: ProgramDescriptor): Program;
11
13
  destroy(): void;
12
14
  }
@@ -92,12 +92,28 @@ function bindingsDescriptorHash(a) {
92
92
  }
93
93
  return hashCodeNumberFinish(hash);
94
94
  }
95
+ function programDescriptorEquals(a, b) {
96
+ var _a$vertex, _b$vertex, _a$fragment, _b$fragment;
97
+ return ((_a$vertex = a.vertex) === null || _a$vertex === void 0 ? void 0 : _a$vertex.glsl) === ((_b$vertex = b.vertex) === null || _b$vertex === void 0 ? void 0 : _b$vertex.glsl) && ((_a$fragment = a.fragment) === null || _a$fragment === void 0 ? void 0 : _a$fragment.glsl) === ((_b$fragment = b.fragment) === null || _b$fragment === void 0 ? void 0 : _b$fragment.glsl);
98
+ }
99
+ function programDescriptorCopy(a) {
100
+ var _a$vertex2, _a$fragment2;
101
+ return {
102
+ vertex: {
103
+ glsl: (_a$vertex2 = a.vertex) === null || _a$vertex2 === void 0 ? void 0 : _a$vertex2.glsl
104
+ },
105
+ fragment: {
106
+ glsl: (_a$fragment2 = a.fragment) === null || _a$fragment2 === void 0 ? void 0 : _a$fragment2.glsl
107
+ }
108
+ };
109
+ }
95
110
  export var RenderCache = /*#__PURE__*/function () {
96
111
  function RenderCache(device) {
97
112
  _classCallCheck(this, RenderCache);
98
113
  _defineProperty(this, "bindingsCache", new HashMap(bindingsDescriptorEquals, bindingsDescriptorHash));
99
114
  _defineProperty(this, "renderPipelinesCache", new HashMap(renderPipelineDescriptorEquals, renderPipelineDescriptorHash));
100
115
  _defineProperty(this, "inputLayoutsCache", new HashMap(inputLayoutDescriptorEquals, nullHashFunc));
116
+ _defineProperty(this, "programCache", new HashMap(programDescriptorEquals, nullHashFunc));
101
117
  this.device = device;
102
118
  }
103
119
  _createClass(RenderCache, [{
@@ -145,6 +161,17 @@ export var RenderCache = /*#__PURE__*/function () {
145
161
  }
146
162
  return inputLayout;
147
163
  }
164
+ }, {
165
+ key: "createProgram",
166
+ value: function createProgram(descriptor) {
167
+ var program = this.programCache.get(descriptor);
168
+ if (program === null) {
169
+ var descriptorCopy = programDescriptorCopy(descriptor);
170
+ program = this.device.createProgram(descriptor);
171
+ this.programCache.add(descriptorCopy, program);
172
+ }
173
+ return program;
174
+ }
148
175
  }, {
149
176
  key: "destroy",
150
177
  value: function destroy() {
@@ -179,17 +206,28 @@ export var RenderCache = /*#__PURE__*/function () {
179
206
  var inputLayout = _step3.value;
180
207
  inputLayout.destroy();
181
208
  }
182
- // for (const program of this.programCache.values()) program.destroy();
183
- // for (const sampler of this.samplerCache.values()) sampler.destroy();
184
209
  } catch (err) {
185
210
  _iterator3.e(err);
186
211
  } finally {
187
212
  _iterator3.f();
188
213
  }
214
+ var _iterator4 = _createForOfIteratorHelper(this.programCache.values()),
215
+ _step4;
216
+ try {
217
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
218
+ var program = _step4.value;
219
+ program.destroy();
220
+ }
221
+ // for (const sampler of this.samplerCache.values()) sampler.destroy();
222
+ } catch (err) {
223
+ _iterator4.e(err);
224
+ } finally {
225
+ _iterator4.f();
226
+ }
189
227
  this.bindingsCache.clear();
190
228
  this.renderPipelinesCache.clear();
191
229
  this.inputLayoutsCache.clear();
192
- // this.programCache.clear();
230
+ this.programCache.clear();
193
231
  // this.samplerCache.clear();
194
232
  }
195
233
  }]);
@@ -29,7 +29,7 @@ var DeviceModel = /*#__PURE__*/function () {
29
29
  diagnosticDerivativeUniformityEnabled = options.diagnosticDerivativeUniformityEnabled;
30
30
  this.options = options;
31
31
  var diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? '' : this.service['viewportOrigin'] === ViewportOrigin.UPPER_LEFT ? 'diagnostic(off,derivative_uniformity);' : '';
32
- var program = device.createProgram({
32
+ this.program = service.renderCache.createProgram({
33
33
  vertex: {
34
34
  glsl: vs
35
35
  },
@@ -40,7 +40,6 @@ var DeviceModel = /*#__PURE__*/function () {
40
40
  }
41
41
  }
42
42
  });
43
- this.program = program;
44
43
  if (uniforms) {
45
44
  this.uniforms = this.extractUniforms(uniforms);
46
45
  }
@@ -83,12 +82,10 @@ var DeviceModel = /*#__PURE__*/function () {
83
82
  if (elements) {
84
83
  this.indexBuffer = elements.get();
85
84
  }
86
-
87
- // const inputLayout = device.createInputLayout({
88
85
  var inputLayout = service.renderCache.createInputLayout({
89
86
  vertexBufferDescriptors: vertexBufferDescriptors,
90
87
  indexBufferFormat: elements ? Format.U32_R : null,
91
- program: program
88
+ program: this.program
92
89
  });
93
90
  this.inputLayout = inputLayout;
94
91
  this.pipeline = this.createPipeline(options);
@@ -119,9 +116,8 @@ var DeviceModel = /*#__PURE__*/function () {
119
116
  stencil: stencil
120
117
  });
121
118
  var stencilEnabled = !!(stencilParams && stencilParams.enable);
122
-
123
- // return this.device.createRenderPipeline({
124
- return this.service.renderCache.createRenderPipeline({
119
+ return this.device.createRenderPipeline({
120
+ // return this.service.renderCache.createRenderPipeline({
125
121
  inputLayout: this.inputLayout,
126
122
  program: this.program,
127
123
  topology: primitiveMap[primitive],
@@ -351,12 +347,12 @@ var DeviceModel = /*#__PURE__*/function () {
351
347
  var _ref5 = stencil || {},
352
348
  enable = _ref5.enable,
353
349
  _ref5$mask = _ref5.mask,
354
- mask = _ref5$mask === void 0 ? -1 : _ref5$mask,
350
+ mask = _ref5$mask === void 0 ? 0xffffffff : _ref5$mask,
355
351
  _ref5$func = _ref5.func,
356
352
  func = _ref5$func === void 0 ? {
357
353
  cmp: gl.ALWAYS,
358
354
  ref: 0,
359
- mask: -1
355
+ mask: 0xffffffff
360
356
  } : _ref5$func,
361
357
  _ref5$opFront = _ref5.opFront,
362
358
  opFront = _ref5$opFront === void 0 ? {
@@ -4,6 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import { TextureUsage as DeviceTextureUsage, FilterMode, Format, MipmapFilterMode } from '@antv/g-device-api';
5
5
  import { TextureUsage, gl } from '@antv/l7-core';
6
6
  import { wrapModeMap } from "./constants";
7
+ import { extend3ChannelsTo4 } from "./utils/typedarray";
7
8
  export function isTexture2D(t) {
8
9
  return !!(t && t['texture']);
9
10
  }
@@ -39,8 +40,7 @@ var DeviceTexture2D = /*#__PURE__*/function () {
39
40
  _createClass(DeviceTexture2D, [{
40
41
  key: "createTexture",
41
42
  value: function createTexture(options) {
42
- var data = options.data,
43
- _options$type = options.type,
43
+ var _options$type = options.type,
44
44
  type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
45
45
  width = options.width,
46
46
  height = options.height,
@@ -56,6 +56,7 @@ var DeviceTexture2D = /*#__PURE__*/function () {
56
56
  _options$unorm = options.unorm,
57
57
  unorm = _options$unorm === void 0 ? false : _options$unorm,
58
58
  label = options.label;
59
+ var data = options.data;
59
60
  this.width = width;
60
61
  this.height = height;
61
62
  var pixelFormat = Format.U8_RGBA_RT;
@@ -64,7 +65,16 @@ var DeviceTexture2D = /*#__PURE__*/function () {
64
65
  } else if (type === gl.UNSIGNED_BYTE && format === gl.LUMINANCE) {
65
66
  pixelFormat = Format.U8_LUMINANCE;
66
67
  } else if (type === gl.FLOAT && format === gl.RGB) {
67
- pixelFormat = Format.F32_RGB;
68
+ // @see https://github.com/antvis/L7/pull/2262
69
+ if (this.device.queryVendorInfo().platformString === 'WebGPU') {
70
+ if (data) {
71
+ // @ts-ignore
72
+ data = extend3ChannelsTo4(data, 0);
73
+ }
74
+ pixelFormat = Format.F32_RGBA;
75
+ } else {
76
+ pixelFormat = Format.F32_RGB;
77
+ }
68
78
  } else if (type === gl.FLOAT && format === gl.RGBA) {
69
79
  pixelFormat = Format.F32_RGBA;
70
80
  } else if (type === gl.FLOAT && format === gl.RED) {
@@ -302,6 +302,7 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
302
302
  }, {
303
303
  key: "beginFrame",
304
304
  value: function beginFrame() {
305
+ this.device.beginFrame();
305
306
  var currentFramebuffer = this.currentFramebuffer,
306
307
  swapChain = this.swapChain,
307
308
  mainColorRT = this.mainColorRT,
@@ -337,6 +338,7 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
337
338
  key: "endFrame",
338
339
  value: function endFrame() {
339
340
  this.device.submitPass(this.renderPass);
341
+ this.device.endFrame();
340
342
  }
341
343
  }, {
342
344
  key: "getPointSizeRange",
@@ -1,2 +1,7 @@
1
1
  export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
2
2
  export declare function isTypedArray(x: any): x is TypedArray;
3
+ /**
4
+ * WebGPU does not support RGB texture, so we need to convert RGB to RGBA
5
+ * @see https://github.com/antvis/L7/pull/2262
6
+ */
7
+ export declare function extend3ChannelsTo4(array: Float32Array, valueToInsert: number): Float32Array;
@@ -13,4 +13,22 @@ var dtypes = {
13
13
  // eslint-disable-next-line
14
14
  export function isTypedArray(x) {
15
15
  return Object.prototype.toString.call(x) in dtypes;
16
+ }
17
+
18
+ /**
19
+ * WebGPU does not support RGB texture, so we need to convert RGB to RGBA
20
+ * @see https://github.com/antvis/L7/pull/2262
21
+ */
22
+ export function extend3ChannelsTo4(array, valueToInsert) {
23
+ var originalLength = array.length;
24
+ var insertCount = Math.ceil(originalLength / 3);
25
+ var newLength = originalLength + insertCount;
26
+ var newArray = new Float32Array(newLength);
27
+ for (var i = 0; i < newLength; i += 4) {
28
+ newArray[i] = array[i / 4 * 3];
29
+ newArray[i + 1] = array[i / 4 * 3 + 1];
30
+ newArray[i + 2] = array[i / 4 * 3 + 2];
31
+ newArray[i + 3] = valueToInsert;
32
+ }
33
+ return newArray;
16
34
  }
@@ -117,6 +117,21 @@ function bindingsDescriptorHash(a) {
117
117
  }
118
118
  return (0, import_HashMap.hashCodeNumberFinish)(hash);
119
119
  }
120
+ function programDescriptorEquals(a, b) {
121
+ var _a, _b, _c, _d;
122
+ return ((_a = a.vertex) == null ? void 0 : _a.glsl) === ((_b = b.vertex) == null ? void 0 : _b.glsl) && ((_c = a.fragment) == null ? void 0 : _c.glsl) === ((_d = b.fragment) == null ? void 0 : _d.glsl);
123
+ }
124
+ function programDescriptorCopy(a) {
125
+ var _a, _b;
126
+ return {
127
+ vertex: {
128
+ glsl: (_a = a.vertex) == null ? void 0 : _a.glsl
129
+ },
130
+ fragment: {
131
+ glsl: (_b = a.fragment) == null ? void 0 : _b.glsl
132
+ }
133
+ };
134
+ }
120
135
  var RenderCache = class {
121
136
  constructor(device) {
122
137
  this.device = device;
@@ -129,6 +144,10 @@ var RenderCache = class {
129
144
  import_g_device_api.inputLayoutDescriptorEquals,
130
145
  import_HashMap.nullHashFunc
131
146
  );
147
+ this.programCache = new import_HashMap.HashMap(
148
+ programDescriptorEquals,
149
+ import_HashMap.nullHashFunc
150
+ );
132
151
  }
133
152
  createBindings(descriptor) {
134
153
  var _a;
@@ -163,6 +182,15 @@ var RenderCache = class {
163
182
  }
164
183
  return inputLayout;
165
184
  }
185
+ createProgram(descriptor) {
186
+ let program = this.programCache.get(descriptor);
187
+ if (program === null) {
188
+ const descriptorCopy = programDescriptorCopy(descriptor);
189
+ program = this.device.createProgram(descriptor);
190
+ this.programCache.add(descriptorCopy, program);
191
+ }
192
+ return program;
193
+ }
166
194
  destroy() {
167
195
  for (const bindings of this.bindingsCache.values())
168
196
  bindings.destroy();
@@ -170,9 +198,12 @@ var RenderCache = class {
170
198
  renderPipeline.destroy();
171
199
  for (const inputLayout of this.inputLayoutsCache.values())
172
200
  inputLayout.destroy();
201
+ for (const program of this.programCache.values())
202
+ program.destroy();
173
203
  this.bindingsCache.clear();
174
204
  this.renderPipelinesCache.clear();
175
205
  this.inputLayoutsCache.clear();
206
+ this.programCache.clear();
176
207
  }
177
208
  };
178
209
  // Annotate the CommonJS export names for ESM import in node:
@@ -58,7 +58,7 @@ var DeviceModel = class {
58
58
  } = options;
59
59
  this.options = options;
60
60
  const diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? "" : this.service["viewportOrigin"] === import_g_device_api.ViewportOrigin.UPPER_LEFT ? "diagnostic(off,derivative_uniformity);" : "";
61
- const program = device.createProgram({
61
+ this.program = service.renderCache.createProgram({
62
62
  vertex: {
63
63
  glsl: vs
64
64
  },
@@ -67,7 +67,6 @@ var DeviceModel = class {
67
67
  postprocess: (fs2) => diagnosticDerivativeUniformityHeader + fs2
68
68
  }
69
69
  });
70
- this.program = program;
71
70
  if (uniforms) {
72
71
  this.uniforms = this.extractUniforms(uniforms);
73
72
  }
@@ -109,7 +108,7 @@ var DeviceModel = class {
109
108
  const inputLayout = service.renderCache.createInputLayout({
110
109
  vertexBufferDescriptors,
111
110
  indexBufferFormat: elements ? import_g_device_api.Format.U32_R : null,
112
- program
111
+ program: this.program
113
112
  });
114
113
  this.inputLayout = inputLayout;
115
114
  this.pipeline = this.createPipeline(options);
@@ -124,7 +123,8 @@ var DeviceModel = class {
124
123
  const blendEnabled = !!(blendParams && blendParams.enable);
125
124
  const stencilParams = this.getStencilDrawParams({ stencil });
126
125
  const stencilEnabled = !!(stencilParams && stencilParams.enable);
127
- return this.service.renderCache.createRenderPipeline({
126
+ return this.device.createRenderPipeline({
127
+ // return this.service.renderCache.createRenderPipeline({
128
128
  inputLayout: this.inputLayout,
129
129
  program: this.program,
130
130
  topology: import_constants.primitiveMap[primitive],
@@ -331,11 +331,11 @@ var DeviceModel = class {
331
331
  }) {
332
332
  const {
333
333
  enable,
334
- mask = -1,
334
+ mask = 4294967295,
335
335
  func = {
336
336
  cmp: import_l7_core.gl.ALWAYS,
337
337
  ref: 0,
338
- mask: -1
338
+ mask: 4294967295
339
339
  },
340
340
  opFront = {
341
341
  fail: import_l7_core.gl.KEEP,
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(DeviceTexture2D_exports);
26
26
  var import_g_device_api = require("@antv/g-device-api");
27
27
  var import_l7_core = require("@antv/l7-core");
28
28
  var import_constants = require("./constants");
29
+ var import_typedarray = require("./utils/typedarray");
29
30
  function isTexture2D(t) {
30
31
  return !!(t && t["texture"]);
31
32
  }
@@ -57,7 +58,6 @@ var DeviceTexture2D = class {
57
58
  }
58
59
  createTexture(options) {
59
60
  const {
60
- data,
61
61
  type = import_l7_core.gl.UNSIGNED_BYTE,
62
62
  width,
63
63
  height,
@@ -74,6 +74,7 @@ var DeviceTexture2D = class {
74
74
  // copy = false,
75
75
  label
76
76
  } = options;
77
+ let { data } = options;
77
78
  this.width = width;
78
79
  this.height = height;
79
80
  let pixelFormat = import_g_device_api.Format.U8_RGBA_RT;
@@ -82,7 +83,14 @@ var DeviceTexture2D = class {
82
83
  } else if (type === import_l7_core.gl.UNSIGNED_BYTE && format === import_l7_core.gl.LUMINANCE) {
83
84
  pixelFormat = import_g_device_api.Format.U8_LUMINANCE;
84
85
  } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RGB) {
85
- pixelFormat = import_g_device_api.Format.F32_RGB;
86
+ if (this.device.queryVendorInfo().platformString === "WebGPU") {
87
+ if (data) {
88
+ data = (0, import_typedarray.extend3ChannelsTo4)(data, 0);
89
+ }
90
+ pixelFormat = import_g_device_api.Format.F32_RGBA;
91
+ } else {
92
+ pixelFormat = import_g_device_api.Format.F32_RGB;
93
+ }
86
94
  } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RGBA) {
87
95
  pixelFormat = import_g_device_api.Format.F32_RGBA;
88
96
  } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RED) {
@@ -246,6 +246,7 @@ var DeviceRendererService = class {
246
246
  );
247
247
  }
248
248
  beginFrame() {
249
+ this.device.beginFrame();
249
250
  const { currentFramebuffer, swapChain, mainColorRT, mainDepthRT } = this;
250
251
  const colorAttachment = currentFramebuffer ? currentFramebuffer["colorRenderTarget"] : mainColorRT;
251
252
  const colorResolveTo = currentFramebuffer ? null : swapChain.getOnscreenTexture();
@@ -276,6 +277,7 @@ var DeviceRendererService = class {
276
277
  }
277
278
  endFrame() {
278
279
  this.device.submitPass(this.renderPass);
280
+ this.device.endFrame();
279
281
  }
280
282
  getPointSizeRange() {
281
283
  const gl = this.device["gl"];
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/device/utils/typedarray.ts
20
20
  var typedarray_exports = {};
21
21
  __export(typedarray_exports, {
22
+ extend3ChannelsTo4: () => extend3ChannelsTo4,
22
23
  isTypedArray: () => isTypedArray
23
24
  });
24
25
  module.exports = __toCommonJS(typedarray_exports);
@@ -37,7 +38,21 @@ var dtypes = {
37
38
  function isTypedArray(x) {
38
39
  return Object.prototype.toString.call(x) in dtypes;
39
40
  }
41
+ function extend3ChannelsTo4(array, valueToInsert) {
42
+ const originalLength = array.length;
43
+ const insertCount = Math.ceil(originalLength / 3);
44
+ const newLength = originalLength + insertCount;
45
+ const newArray = new Float32Array(newLength);
46
+ for (let i = 0; i < newLength; i += 4) {
47
+ newArray[i] = array[i / 4 * 3];
48
+ newArray[i + 1] = array[i / 4 * 3 + 1];
49
+ newArray[i + 2] = array[i / 4 * 3 + 2];
50
+ newArray[i + 3] = valueToInsert;
51
+ }
52
+ return newArray;
53
+ }
40
54
  // Annotate the CommonJS export names for ESM import in node:
41
55
  0 && (module.exports = {
56
+ extend3ChannelsTo4,
42
57
  isTypedArray
43
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-renderer",
3
- "version": "2.20.14",
3
+ "version": "2.20.15",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "xiaoiver",
@@ -24,20 +24,20 @@
24
24
  "tsc": "tsc --project tsconfig.build.json"
25
25
  },
26
26
  "dependencies": {
27
- "@antv/g-device-api": "^1.5.0",
28
- "@antv/l7-core": "2.20.14",
29
- "@antv/l7-utils": "2.20.14",
27
+ "@antv/g-device-api": "^1.6.4",
28
+ "@antv/l7-core": "2.20.15",
29
+ "@antv/l7-utils": "2.20.15",
30
30
  "@babel/runtime": "^7.7.7",
31
31
  "inversify": "^5.0.1",
32
32
  "reflect-metadata": "^0.2.1",
33
33
  "regl": "1.6.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@antv/l7-test-utils": "2.20.14",
36
+ "@antv/l7-test-utils": "2.20.15",
37
37
  "gl": "^6.0.2"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "ad997ac14616fa503fec4022f1a1a48747524f87"
42
+ "gitHead": "283c12854a06cd2181552d6a9cf00d3e34bbd58e"
43
43
  }