rm-webgpu-compute-tasks 0.0.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.
Files changed (3) hide show
  1. package/package.json +29 -0
  2. package/src/index.d.ts +574 -0
  3. package/src/index.js +2323 -0
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "rm-webgpu-compute-tasks",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./src/index.d.ts",
14
+ "default": "./src/index.js",
15
+ "style": "./src/index.css"
16
+ },
17
+ "require": {
18
+ "types": "./src/index.d.ts",
19
+ "default": "./src/index.js"
20
+ }
21
+ }
22
+ },
23
+ "dependencies": {
24
+ "three": ">=0.181.0",
25
+ "webgpu": "^0.4.0"
26
+ },
27
+ "author": "夏过初秋",
28
+ "license": "UNLICENSED"
29
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,574 @@
1
+ import { Color } from 'three';
2
+ import { Matrix3 } from 'three';
3
+ import { Matrix4 } from 'three';
4
+ import * as THREE from 'three';
5
+ import { Vector2 } from 'three';
6
+ import { Vector3 } from 'three';
7
+ import { Vector4 } from 'three';
8
+
9
+ export declare class AtomicUint32Array extends Uint32Array {
10
+ }
11
+
12
+ export declare class BaseMaterial extends ShaderMaterial {
13
+ constructor(opt?: IOption);
14
+ }
15
+
16
+ declare type BufferDataType = Record<string, (number[]) | ArrayBufferView | IStruct | IStructArray>;
17
+
18
+ export declare class BufferGeometry extends THREE.BufferGeometry {
19
+ gpuAttributes: Map<string, GPUAttribute>;
20
+ indexBuffer?: GPUBuffer;
21
+ indexFormat?: GPUIndexFormat;
22
+ needsUpdate: boolean;
23
+ count: number;
24
+ update(): void;
25
+ setAttribute<K extends string>(name: K, attribute: THREE.BufferAttribute | THREE.InterleavedBufferAttribute): this;
26
+ private getVertexFormat;
27
+ }
28
+
29
+ declare type BufferGroup = {
30
+ buffers: {
31
+ name: string;
32
+ buffer: GPUBuffer;
33
+ }[];
34
+ group: GPUBindGroup;
35
+ };
36
+
37
+ /** 创建buffer
38
+ * @param device
39
+ * @param options
40
+ * @returns
41
+ */
42
+ export declare function createBuffer(device: GPUDevice, options: {
43
+ data?: ArrayBuffer | ArrayBufferView;
44
+ size?: number;
45
+ usage: GPUBufferUsageFlags;
46
+ mappedAtCreation?: boolean;
47
+ label?: string;
48
+ }): GPUBuffer;
49
+
50
+ /** 创建计算管线
51
+ * @param device
52
+ * @param options
53
+ * @returns
54
+ */
55
+ export declare function createComputePipeline(device: GPUDevice, options: {
56
+ layout?: GPUPipelineLayout;
57
+ compute: GPUProgrammableStage;
58
+ label?: string;
59
+ }): GPUComputePipeline;
60
+
61
+ /** 创建渲染管线
62
+ * @param device
63
+ * @param options
64
+ * @returns
65
+ */
66
+ export declare function createRenderPipeline(device: GPUDevice, options: {
67
+ layout?: GPUPipelineLayout;
68
+ vertex: GPUVertexState;
69
+ primitive?: GPUPrimitiveState;
70
+ depthStencil?: GPUDepthStencilState;
71
+ multisample?: GPUMultisampleState;
72
+ fragment?: GPUFragmentState;
73
+ label?: string;
74
+ }): GPURenderPipeline;
75
+
76
+ /** 创建纹理
77
+ * @param device
78
+ * @param options
79
+ * @returns
80
+ */
81
+ export declare function createTexture(device: GPUDevice, options: {
82
+ size: GPUExtent3D;
83
+ format: GPUTextureFormat;
84
+ usage: GPUTextureUsageFlags;
85
+ dimension?: GPUTextureDimension;
86
+ mipLevelCount?: number;
87
+ sampleCount?: number;
88
+ data?: ArrayBufferView;
89
+ bytesPerRow?: number;
90
+ label?: string;
91
+ }): GPUTexture;
92
+
93
+ export declare class CubeCamera {
94
+ cameras: PerspectiveCamera[];
95
+ depthClearValue: number;
96
+ constructor(near?: number, far?: number, depthClearValue?: number);
97
+ setPosition(x: number, y: number, z: number): void;
98
+ updateDirections(): void;
99
+ render(meshList: Object3D[], renderer: Renderer, cubeTexture: CubeTexture): void;
100
+ }
101
+
102
+ export declare class CubeTexture extends Texture {
103
+ get cubeView(): GPUTextureView;
104
+ faceViews: GPUTextureView[];
105
+ constructor(width: number, height?: number, des?: ICubeTextureOption);
106
+ getFaceView(face: number): GPUTextureView;
107
+ private buildFaceViews;
108
+ }
109
+
110
+ export declare class DepthMaterial extends ShaderMaterial {
111
+ constructor(opt?: IBaseMaterialOption);
112
+ }
113
+
114
+ export declare function destroyWebgpu(): Promise<void>;
115
+
116
+ export declare const getAdapter: () => GPUAdapter;
117
+
118
+ export declare const getDevice: () => GPUDevice;
119
+
120
+ export declare function getSampler(desc: GPUSamplerDescriptor): GPUSampler;
121
+
122
+ export declare type GPUAttribute = {
123
+ buffer: GPUBuffer;
124
+ stride: number;
125
+ format: GPUVertexFormat;
126
+ shaderLocation: number;
127
+ };
128
+
129
+ export declare class GpuComputed {
130
+ template?: BufferDataType;
131
+ option?: GpuComputedOption;
132
+ pipeline?: GPUComputePipeline;
133
+ device?: GPUDevice;
134
+ groupLayout?: any;
135
+ code?: string;
136
+ constructor(template: BufferDataType, option?: GpuComputedOption);
137
+ /** 完善模版数据
138
+ * @param template
139
+ */
140
+ private improveTemplateOption;
141
+ /** 获取Gpu设备
142
+ * @returns
143
+ */
144
+ getDevice(): Promise<{
145
+ adapter: GPUAdapter;
146
+ device: GPUDevice;
147
+ }>;
148
+ /**
149
+ * 初始化计算管线
150
+ */
151
+ initPipeline(): Promise<void>;
152
+ /**
153
+ * 根据数据创建buffer组
154
+ * @param data 数据
155
+ * @param bindGroup 已创建的bindGroup, 会在没有传入对应数据时使用,用于Buffer重复利用,不需要重新构建,按名字判断,所以请确保名称和类型一致性
156
+ * @returns
157
+ */
158
+ createBindGroup(data: Record<string, any>, bindGroup?: {
159
+ group: GPUBindGroup;
160
+ buffers: {
161
+ name: string;
162
+ buffer: GPUBuffer;
163
+ }[];
164
+ }): {
165
+ group: GPUBindGroup;
166
+ buffers: {
167
+ name: string;
168
+ buffer: GPUBuffer;
169
+ }[];
170
+ };
171
+ /** 数据映射回模版数据
172
+ * @param array
173
+ * @param key
174
+ */
175
+ dataMap(array: Float32Array | Uint32Array | Int32Array, key: string): Float32Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Record<string, number | number[]> | Record<string, number | number[]>[];
176
+ /** 开始计算
177
+ * @param group 数据组
178
+ * @param workgroupCount 工作组大小
179
+ * @param synchronize 需要同步的数据字段
180
+ * @returns
181
+ */
182
+ computed(group: BufferGroup, workgroupCount: [number, number?, number?], synchronize?: string[]): Promise<(Float32Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>)[]>;
183
+ /** 初始化gpu设备
184
+ * @returns
185
+ */
186
+ static init(opt?: InitOption): Promise<void>;
187
+ static set(adapter_: GPUAdapter, device_: GPUDevice): void;
188
+ /** 注销gpu设备
189
+ */
190
+ static destroy(): void;
191
+ /**
192
+ * @param data
193
+ */
194
+ static buildBufferTypeByData(data: Record<string, any>): Record<string, IStructArray | IStruct | ArrayBufferView<ArrayBufferLike>>;
195
+ /** 通过数据创建
196
+ * @param opt
197
+ * @returns
198
+ */
199
+ static fromByData(opt: {
200
+ data: Record<string, any>;
201
+ } & GpuComputedOption): Promise<GpuComputed>;
202
+ /** 快捷计算方法
203
+ * @param opt
204
+ * @returns
205
+ */
206
+ static computed(opt: {
207
+ data: Record<string, any>;
208
+ workgroupCount: [number, number?, number?];
209
+ synchronize?: string[];
210
+ map?: boolean;
211
+ onSuccess?: (opt: {
212
+ gpuComputed: GpuComputed;
213
+ group: BufferGroup;
214
+ results: (Float32Array | Uint32Array | Int32Array)[];
215
+ }) => void;
216
+ } & GpuComputedOption): Promise<(Float32Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Record<string, number | number[]> | Record<string, number | number[]>[])[]>;
217
+ }
218
+
219
+ declare type GpuComputedOption = {
220
+ workgroupSize?: [number, number, number];
221
+ globalInvocationIdName?: string;
222
+ workgroupIndexName?: string;
223
+ beforeCodes?: string[];
224
+ code?: string;
225
+ };
226
+
227
+ declare interface IBaseMaterialOption {
228
+ color?: number;
229
+ side?: GPUCullMode;
230
+ topology?: GPUPrimitiveTopology;
231
+ map?: Texture;
232
+ }
233
+
234
+ export declare interface ICreateObstacleDetection {
235
+ base: string;
236
+ size?: number;
237
+ near?: number;
238
+ far?: number;
239
+ canvasWidth?: number;
240
+ canvasHeight?: number;
241
+ fov?: number;
242
+ }
243
+
244
+ export declare interface ICubeTextureOption {
245
+ sampler?: GPUSamplerDescriptor;
246
+ format?: GPUTextureFormat;
247
+ needDepthTexture?: boolean;
248
+ }
249
+
250
+ declare interface IData {
251
+ indexArray: number[];
252
+ pointClouds: Float32Array[];
253
+ pointCloudArray: number[];
254
+ rectArray: number[];
255
+ trajectoryList: {
256
+ x: number;
257
+ y: number;
258
+ z: number;
259
+ }[];
260
+ }
261
+
262
+ declare type InitOption = {
263
+ featureLevel?: string;
264
+ powerPreference?: GPUPowerPreference;
265
+ forceFallbackAdapter?: boolean;
266
+ xrCompatible?: boolean;
267
+ requiredFeatures?: Iterable<GPUFeatureName>;
268
+ requiredLimits?: Record<string, GPUSize64 | undefined>;
269
+ defaultQueue?: GPUQueueDescriptor;
270
+ };
271
+
272
+ declare type InitOption_2 = {
273
+ featureLevel?: string;
274
+ powerPreference?: GPUPowerPreference;
275
+ forceFallbackAdapter?: boolean;
276
+ xrCompatible?: boolean;
277
+ requiredFeatures?: Iterable<GPUFeatureName>;
278
+ requiredLimits?: Record<string, GPUSize64 | undefined>;
279
+ defaultQueue?: GPUQueueDescriptor;
280
+ };
281
+
282
+ export declare function initWebgpu(opt?: InitOption_2): Promise<{
283
+ device: GPUDevice;
284
+ adapter: GPUAdapter;
285
+ } | undefined>;
286
+
287
+ declare interface IOption {
288
+ color?: number;
289
+ side?: GPUCullMode;
290
+ topology?: GPUPrimitiveTopology;
291
+ map?: Texture;
292
+ transparent?: boolean;
293
+ opacity?: number;
294
+ }
295
+
296
+ declare interface IOption_2 {
297
+ side?: GPUCullMode;
298
+ topology?: GPUPrimitiveTopology;
299
+ cubeTexture: Texture;
300
+ results?: Uint32Array;
301
+ }
302
+
303
+ declare type IStruct = IStructBaseType[];
304
+
305
+ declare interface IStructArray {
306
+ buffer?: number[];
307
+ stride?: number;
308
+ layout: IStruct;
309
+ }
310
+
311
+ declare interface IStructBaseType {
312
+ name: string;
313
+ type: WGSl_TYPE;
314
+ offset?: number;
315
+ size?: number;
316
+ }
317
+
318
+ export declare interface ITextureOption {
319
+ sampler?: GPUSamplerDescriptor;
320
+ format?: GPUTextureFormat;
321
+ depthOrArrayLayers?: number;
322
+ dimension?: GPUTextureDimension;
323
+ viewDimension?: GPUTextureViewDimension;
324
+ init?: boolean;
325
+ needDepthTexture?: boolean;
326
+ }
327
+
328
+ export declare interface IVertexInputDes {
329
+ name: string;
330
+ type: string;
331
+ }
332
+
333
+ /**
334
+ * @param base
335
+ */
336
+ export declare function loadData(base: string): Promise<IData & {
337
+ map: Map<number, [number, number, number, number]>;
338
+ linesJson: any[];
339
+ }>;
340
+
341
+ export declare class Object3D extends THREE.Object3D {
342
+ static get bindGroupLayout(): GPUBindGroupLayout;
343
+ private buffer;
344
+ bindGroup: GPUBindGroup;
345
+ needsUpdate: boolean;
346
+ material: ShaderMaterial;
347
+ geometry: BufferGeometry;
348
+ private uniformArray;
349
+ constructor(geometry: BufferGeometry, material: ShaderMaterial);
350
+ updateMatrixWorld(force?: boolean): void;
351
+ private _updateBuffer;
352
+ pipeline: GPURenderPipeline | null;
353
+ private createPipeline;
354
+ update(format: GPUTextureFormat): void;
355
+ }
356
+
357
+ export declare const obstacleDetection: typeof obstacleDetection_ & {
358
+ getResult(base: string): Promise<number[]>;
359
+ };
360
+
361
+ declare function obstacleDetection_(opt: ICreateObstacleDetection): Promise<{
362
+ renderer: Renderer;
363
+ camera: PerspectiveCamera;
364
+ data: IData & {
365
+ map: Map<number, [number, number, number, number]>;
366
+ linesJson: any[];
367
+ };
368
+ depthCubeTexture: CubeTexture;
369
+ resultCubeTexture: CubeTexture;
370
+ cubeCamera: CubeCamera;
371
+ quadObject3D: Object3D;
372
+ pointsObject3D: Object3D;
373
+ indexCount: number;
374
+ resultTextureBuff: Uint32Array<ArrayBuffer>;
375
+ result: number[];
376
+ }>;
377
+
378
+ export declare class OcclusionMaterial extends ShaderMaterial {
379
+ constructor(opt: IOption_2);
380
+ static packUint(v: number): Vector4;
381
+ static unpackUint(r: number, g: number, b: number, a: number): number;
382
+ static unpackUintByUint8(buff: Uint8Array, i: number): number | null;
383
+ }
384
+
385
+ export declare class PerspectiveCamera extends THREE.PerspectiveCamera {
386
+ static get bindGroupLayout(): GPUBindGroupLayout;
387
+ private buffer;
388
+ bindGroup: GPUBindGroup;
389
+ private _needsUpdate;
390
+ get needsUpdate(): boolean;
391
+ set needsUpdate(v: boolean);
392
+ private uniformArray;
393
+ constructor(fov: number, aspect: number, near: number, far: number);
394
+ private _updateBuffer;
395
+ updateMatrix(): void;
396
+ updateMatrixWorld(): void;
397
+ updateProjectionMatrix(): void;
398
+ update(): void;
399
+ }
400
+
401
+ /** 自动推导读取 cubemap face */
402
+ export declare function readCubeTexture(texture: GPUTexture, face?: number, mipLevel?: number, device?: GPUDevice): Promise<{
403
+ data: Uint8Array<ArrayBuffer>;
404
+ width: number;
405
+ height: number;
406
+ format: "depth32float-stencil8" | "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16unorm" | "r16snorm" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16unorm" | "rg16snorm" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16unorm" | "rgba16snorm" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb";
407
+ bytesPerPixel: number;
408
+ }>;
409
+
410
+ /** 读取buffer
411
+ * @param buffer
412
+ * @param size 字节数
413
+ * @param Type
414
+ * @returns
415
+ */
416
+ export declare function readGPUBuffer<T extends ArrayBufferView = Uint8Array>(buffer: GPUBuffer, size: number, Type?: {
417
+ new (buffer: ArrayBuffer): T;
418
+ }, device?: GPUDevice): Promise<T>;
419
+
420
+ /**
421
+ * @param texture
422
+ * @param options
423
+ * @param device
424
+ * @returns
425
+ */
426
+ export declare function readTextureBuffer(texture: GPUTexture & {
427
+ width?: number;
428
+ height?: number;
429
+ format?: GPUTextureFormat;
430
+ depthOrArrayLayers?: number;
431
+ }, options?: ReadTextureOptions, device?: GPUDevice): Promise<{
432
+ data: Uint8Array<ArrayBuffer>;
433
+ width: number;
434
+ height: number;
435
+ bytesPerPixel: number;
436
+ format: "depth32float-stencil8" | "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16unorm" | "r16snorm" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16unorm" | "rg16snorm" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16unorm" | "rgba16snorm" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb";
437
+ }>;
438
+
439
+ declare interface ReadTextureOptions {
440
+ face?: number;
441
+ layer?: number;
442
+ mipLevel?: number;
443
+ }
444
+
445
+ export declare class Renderer {
446
+ canvas?: HTMLCanvasElement;
447
+ context?: GPUCanvasContext;
448
+ depthTexture: GPUTexture;
449
+ depthTextureView: GPUTextureView;
450
+ format: GPUTextureFormat;
451
+ renderTarget: GPUTextureView | null;
452
+ depthTarget: GPUTextureView | null;
453
+ constructor(width?: number, height?: number, format?: GPUTextureFormat);
454
+ render(meshList: Object3D[], camera: PerspectiveCamera, depthClearValue?: number): void;
455
+ }
456
+
457
+ export declare const shaderLocationMap: Map<string, number>;
458
+
459
+ export declare class ShaderMaterial {
460
+ vertex: string;
461
+ fragment: string;
462
+ pipeline?: GPURenderPipeline;
463
+ bindGroup: GPUBindGroup;
464
+ buffer: GPUBuffer;
465
+ uniforms: Record<string, {
466
+ value: UniformValue;
467
+ }>;
468
+ private uniformArray;
469
+ private _bufferUniforms;
470
+ private _textureUniforms;
471
+ private _storageUniforms;
472
+ private topology?;
473
+ private side?;
474
+ private blend?;
475
+ private writeMask?;
476
+ private depthStencil?;
477
+ private env?;
478
+ private _needsUniformUpdate;
479
+ get needsUniformUpdate(): boolean;
480
+ set needsUniformUpdate(v: boolean);
481
+ private _needsBindGroupUpdate;
482
+ get needsBindGroupUpdate(): boolean;
483
+ set needsBindGroupUpdate(v: boolean);
484
+ constructor(options: ShaderMaterialOptions);
485
+ /**
486
+ * 初始化uniform
487
+ * @param uniforms
488
+ */
489
+ private _initUniform;
490
+ /**
491
+ * 获取绑定组布局
492
+ * @returns
493
+ */
494
+ private _getBindGroupLayout;
495
+ /**
496
+ * 创建绑定组
497
+ */
498
+ private _createBindGroup;
499
+ /** 生成uniform 代码
500
+ * @param type
501
+ * @returns
502
+ */
503
+ private _generateUniformWGSL;
504
+ /** 生成 顶点着色器入参类型代码
505
+ * @param attrMap
506
+ * @returns
507
+ */
508
+ private _generateVertexInputWGSL;
509
+ /**
510
+ * 生成 Storage 类型代码
511
+ */
512
+ private _generateStorageWGSL;
513
+ /** 创建渲染管线
514
+ * @param attrMap
515
+ * @param colorFormat
516
+ * @param depthFormat
517
+ * @returns
518
+ */
519
+ createPipeline(attrMap: Map<string, GPUAttribute>, colorFormat?: GPUTextureFormat, depthFormat?: GPUTextureFormat): GPURenderPipeline;
520
+ /**
521
+ * 更新uniform 数据
522
+ */
523
+ private _updateUniform;
524
+ update(): void;
525
+ /** 获取buffer
526
+ * @param name
527
+ * @returns
528
+ */
529
+ getStorageBuffer(name: string): GPUBuffer | undefined;
530
+ }
531
+
532
+ export declare interface ShaderMaterialOptions {
533
+ vertex: string;
534
+ fragment: string;
535
+ uniforms?: Record<string, {
536
+ value: UniformValue;
537
+ write?: boolean;
538
+ atomic?: boolean;
539
+ }>;
540
+ topology?: GPUPrimitiveTopology;
541
+ side?: GPUCullMode;
542
+ blend?: GPUBlendState;
543
+ writeMask?: number | undefined;
544
+ depthStencil?: Omit<GPUDepthStencilState, "format">;
545
+ env?: Record<string, boolean>;
546
+ }
547
+
548
+ export declare class Texture {
549
+ depthTexture: GPUTexture;
550
+ depthView: GPUTextureView;
551
+ texture: GPUTexture;
552
+ view: GPUTextureView;
553
+ width: number;
554
+ height: number;
555
+ format: GPUTextureFormat;
556
+ sampler: GPUSampler;
557
+ private needDepthTexture;
558
+ private depthOrArrayLayers;
559
+ private dimension;
560
+ private viewDimension;
561
+ constructor(width: number, height?: number, des?: ITextureOption);
562
+ protected init(width: number, height?: number): void;
563
+ destroy(): void;
564
+ static fromByImage(bitmap: ImageBitmap): Promise<Texture>;
565
+ static fromURL(url: string): Promise<Texture>;
566
+ }
567
+
568
+ export declare const transparentOption: Omit<GPUColorTargetState, "format">;
569
+
570
+ declare type UniformValue = Color | Matrix4 | Matrix3 | Texture | CubeTexture | number | Vector2 | Vector3 | Vector4 | number[] | Float32Array | Uint32Array | Uint8Array;
571
+
572
+ declare type WGSl_TYPE = "f32" | "u32" | "vec2" | "vec3" | "vec4" | "mat3x3" | "mat4x4";
573
+
574
+ export { }