rm-webgpu-compute-tasks 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +110 -50
- package/src/index.js +1279 -276
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ import { Vector4 } from 'three';
|
|
|
9
9
|
export declare class AtomicUint32Array extends Uint32Array {
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export declare function autoWorkgroup(maxSize?: [number, number?, number?]): {
|
|
13
|
+
workgroupSize: Vec3;
|
|
14
|
+
workgroupCount: Vec3;
|
|
15
|
+
};
|
|
16
|
+
|
|
12
17
|
export declare class BaseMaterial extends ShaderMaterial {
|
|
13
18
|
constructor(opt?: IOption);
|
|
14
19
|
}
|
|
@@ -34,6 +39,30 @@ declare type BufferGroup = {
|
|
|
34
39
|
group: GPUBindGroup;
|
|
35
40
|
};
|
|
36
41
|
|
|
42
|
+
export declare class ComputeMaterial extends ShaderMaterial<GPUComputePipeline> {
|
|
43
|
+
workgroupCount: [number, number?, number?];
|
|
44
|
+
workgroupSize: [number, number, number];
|
|
45
|
+
constructor(opt: ComputeMaterialOptions);
|
|
46
|
+
setWorkgroupCount(workgroupCount: [number, number?, number?]): void;
|
|
47
|
+
needsPipelineUpdate: boolean;
|
|
48
|
+
createPipeline(): GPUComputePipeline | undefined;
|
|
49
|
+
update(): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export declare interface ComputeMaterialOptions {
|
|
53
|
+
beforeCcde?: string;
|
|
54
|
+
mainCode: string;
|
|
55
|
+
uniforms?: Record<string, {
|
|
56
|
+
value: UniformValue;
|
|
57
|
+
write?: boolean;
|
|
58
|
+
atomic?: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
define?: Record<string, boolean>;
|
|
61
|
+
workgroupCount?: [number, number?, number?];
|
|
62
|
+
workgroupSize?: [number, number, number];
|
|
63
|
+
maxSize?: [number, number?, number?];
|
|
64
|
+
}
|
|
65
|
+
|
|
37
66
|
/** 创建buffer
|
|
38
67
|
* @param device
|
|
39
68
|
* @param options
|
|
@@ -107,16 +136,17 @@ export declare class CubeTexture extends Texture {
|
|
|
107
136
|
private buildFaceViews;
|
|
108
137
|
}
|
|
109
138
|
|
|
110
|
-
export declare class DepthMaterial extends ShaderMaterial {
|
|
111
|
-
constructor(opt?: IBaseMaterialOption);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
139
|
export declare function destroyWebgpu(): Promise<void>;
|
|
115
140
|
|
|
116
141
|
export declare const getAdapter: () => GPUAdapter;
|
|
117
142
|
|
|
118
143
|
export declare const getDevice: () => GPUDevice;
|
|
119
144
|
|
|
145
|
+
export declare function getNullBG(): {
|
|
146
|
+
bindGroup: GPUBindGroup;
|
|
147
|
+
bindGroupLayout: GPUBindGroupLayout | null;
|
|
148
|
+
};
|
|
149
|
+
|
|
120
150
|
export declare function getSampler(desc: GPUSamplerDescriptor): GPUSampler;
|
|
121
151
|
|
|
122
152
|
export declare type GPUAttribute = {
|
|
@@ -224,13 +254,6 @@ declare type GpuComputedOption = {
|
|
|
224
254
|
code?: string;
|
|
225
255
|
};
|
|
226
256
|
|
|
227
|
-
declare interface IBaseMaterialOption {
|
|
228
|
-
color?: number;
|
|
229
|
-
side?: GPUCullMode;
|
|
230
|
-
topology?: GPUPrimitiveTopology;
|
|
231
|
-
map?: Texture;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
257
|
export declare interface ICreateObstacleDetection {
|
|
235
258
|
base: string;
|
|
236
259
|
size?: number;
|
|
@@ -239,6 +262,7 @@ export declare interface ICreateObstacleDetection {
|
|
|
239
262
|
canvasWidth?: number;
|
|
240
263
|
canvasHeight?: number;
|
|
241
264
|
fov?: number;
|
|
265
|
+
linesJson?: any;
|
|
242
266
|
}
|
|
243
267
|
|
|
244
268
|
export declare interface ICubeTextureOption {
|
|
@@ -293,13 +317,6 @@ declare interface IOption {
|
|
|
293
317
|
opacity?: number;
|
|
294
318
|
}
|
|
295
319
|
|
|
296
|
-
declare interface IOption_2 {
|
|
297
|
-
side?: GPUCullMode;
|
|
298
|
-
topology?: GPUPrimitiveTopology;
|
|
299
|
-
cubeTexture: Texture;
|
|
300
|
-
results?: Uint32Array;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
320
|
declare type IStruct = IStructBaseType[];
|
|
304
321
|
|
|
305
322
|
declare interface IStructArray {
|
|
@@ -333,12 +350,13 @@ export declare interface IVertexInputDes {
|
|
|
333
350
|
/**
|
|
334
351
|
* @param base
|
|
335
352
|
*/
|
|
336
|
-
export declare function loadData(base: string): Promise<IData & {
|
|
353
|
+
export declare function loadData(base: string, linesJson_?: any): Promise<IData & {
|
|
337
354
|
map: Map<number, [number, number, number, number]>;
|
|
338
355
|
linesJson: any[];
|
|
339
356
|
}>;
|
|
340
357
|
|
|
341
358
|
export declare class Object3D extends THREE.Object3D {
|
|
359
|
+
static get GROU_INDEX(): number;
|
|
342
360
|
static get bindGroupLayout(): GPUBindGroupLayout;
|
|
343
361
|
private buffer;
|
|
344
362
|
bindGroup: GPUBindGroup;
|
|
@@ -355,7 +373,7 @@ export declare class Object3D extends THREE.Object3D {
|
|
|
355
373
|
}
|
|
356
374
|
|
|
357
375
|
export declare const obstacleDetection: typeof obstacleDetection_ & {
|
|
358
|
-
getResult(base: string): Promise<number[]>;
|
|
376
|
+
getResult(base: string, linesJson?: any): Promise<number[]>;
|
|
359
377
|
};
|
|
360
378
|
|
|
361
379
|
declare function obstacleDetection_(opt: ICreateObstacleDetection): Promise<{
|
|
@@ -375,11 +393,13 @@ declare function obstacleDetection_(opt: ICreateObstacleDetection): Promise<{
|
|
|
375
393
|
result: number[];
|
|
376
394
|
}>;
|
|
377
395
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
396
|
+
declare interface Option_2 {
|
|
397
|
+
base: string;
|
|
398
|
+
urls: string[];
|
|
399
|
+
erodeMaskSize?: number;
|
|
400
|
+
kernelSize?: number;
|
|
401
|
+
gridSize?: number;
|
|
402
|
+
gridAmount?: number;
|
|
383
403
|
}
|
|
384
404
|
|
|
385
405
|
export declare class PerspectiveCamera extends THREE.PerspectiveCamera {
|
|
@@ -450,35 +470,52 @@ export declare class Renderer {
|
|
|
450
470
|
format: GPUTextureFormat;
|
|
451
471
|
renderTarget: GPUTextureView | null;
|
|
452
472
|
depthTarget: GPUTextureView | null;
|
|
473
|
+
/**
|
|
474
|
+
* @param width
|
|
475
|
+
* @param height
|
|
476
|
+
* @param format
|
|
477
|
+
*/
|
|
453
478
|
constructor(width?: number, height?: number, format?: GPUTextureFormat);
|
|
479
|
+
/** 渲染
|
|
480
|
+
* @param meshList
|
|
481
|
+
* @param camera
|
|
482
|
+
* @param depthClearValue
|
|
483
|
+
* @returns
|
|
484
|
+
*/
|
|
454
485
|
render(meshList: Object3D[], camera: PerspectiveCamera, depthClearValue?: number): void;
|
|
486
|
+
compute(materials: ComputeMaterial[] | ComputeMaterial): void;
|
|
455
487
|
}
|
|
456
488
|
|
|
489
|
+
export declare const segmentObjectPointClouds: typeof sopc_ & {
|
|
490
|
+
getResult(opt: Option_2): Promise<number[][][]>;
|
|
491
|
+
};
|
|
492
|
+
|
|
457
493
|
export declare const shaderLocationMap: Map<string, number>;
|
|
458
494
|
|
|
459
|
-
export declare class ShaderMaterial {
|
|
495
|
+
export declare class ShaderMaterial<T = GPURenderPipeline> {
|
|
496
|
+
static get GROU_INDEX(): number;
|
|
460
497
|
vertex: string;
|
|
461
498
|
fragment: string;
|
|
462
|
-
pipeline?:
|
|
499
|
+
pipeline?: T;
|
|
463
500
|
bindGroup: GPUBindGroup;
|
|
464
501
|
buffer: GPUBuffer;
|
|
465
502
|
uniforms: Record<string, {
|
|
466
503
|
value: UniformValue;
|
|
467
504
|
}>;
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
505
|
+
protected uniformArray: Float32Array<ArrayBuffer>;
|
|
506
|
+
protected _bufferUniforms: Record<string, UniformMeta>;
|
|
507
|
+
protected _textureUniforms: Record<string, UniformMeta>;
|
|
508
|
+
protected _storageUniforms: Record<string, UniformMeta>;
|
|
509
|
+
protected topology?: GPUPrimitiveTopology;
|
|
510
|
+
protected side?: GPUCullMode;
|
|
511
|
+
protected blend?: GPUBlendState;
|
|
512
|
+
protected writeMask?: number | undefined;
|
|
513
|
+
protected depthStencil?: Omit<GPUDepthStencilState, "format">;
|
|
514
|
+
protected define?: Record<string, boolean>;
|
|
515
|
+
protected _needsUniformUpdate: boolean;
|
|
479
516
|
get needsUniformUpdate(): boolean;
|
|
480
517
|
set needsUniformUpdate(v: boolean);
|
|
481
|
-
|
|
518
|
+
protected _needsBindGroupUpdate: boolean;
|
|
482
519
|
get needsBindGroupUpdate(): boolean;
|
|
483
520
|
set needsBindGroupUpdate(v: boolean);
|
|
484
521
|
constructor(options: ShaderMaterialOptions);
|
|
@@ -486,47 +523,52 @@ export declare class ShaderMaterial {
|
|
|
486
523
|
* 初始化uniform
|
|
487
524
|
* @param uniforms
|
|
488
525
|
*/
|
|
489
|
-
|
|
526
|
+
protected _initUniform(uniforms: any): void;
|
|
490
527
|
/**
|
|
491
528
|
* 获取绑定组布局
|
|
492
529
|
* @returns
|
|
493
530
|
*/
|
|
494
|
-
|
|
531
|
+
protected _getBindGroupLayout(): GPUBindGroupLayout;
|
|
495
532
|
/**
|
|
496
533
|
* 创建绑定组
|
|
497
534
|
*/
|
|
498
|
-
|
|
535
|
+
protected _createBindGroup(): void;
|
|
499
536
|
/** 生成uniform 代码
|
|
500
|
-
* @param
|
|
537
|
+
* @param mtype
|
|
501
538
|
* @returns
|
|
502
539
|
*/
|
|
503
|
-
|
|
540
|
+
protected _generateUniformWGSL(mtype: "vertex" | "fragment" | "compute"): string;
|
|
504
541
|
/** 生成 顶点着色器入参类型代码
|
|
505
542
|
* @param attrMap
|
|
506
543
|
* @returns
|
|
507
544
|
*/
|
|
508
|
-
|
|
545
|
+
protected _generateVertexInputWGSL(attrMap: Map<string, GPUAttribute>): string;
|
|
509
546
|
/**
|
|
510
547
|
* 生成 Storage 类型代码
|
|
511
548
|
*/
|
|
512
|
-
|
|
549
|
+
protected _generateStorageWGSL(type: "vertex" | "fragment" | "compute"): string;
|
|
513
550
|
/** 创建渲染管线
|
|
514
551
|
* @param attrMap
|
|
515
552
|
* @param colorFormat
|
|
516
553
|
* @param depthFormat
|
|
517
554
|
* @returns
|
|
518
555
|
*/
|
|
519
|
-
createPipeline(attrMap: Map<string, GPUAttribute>, colorFormat?: GPUTextureFormat, depthFormat?: GPUTextureFormat): GPURenderPipeline;
|
|
556
|
+
createPipeline(attrMap: Map<string, GPUAttribute>, colorFormat?: GPUTextureFormat, depthFormat?: GPUTextureFormat): GPURenderPipeline | T | undefined;
|
|
520
557
|
/**
|
|
521
558
|
* 更新uniform 数据
|
|
522
559
|
*/
|
|
523
|
-
|
|
560
|
+
protected _updateUniform(): void;
|
|
524
561
|
update(): void;
|
|
525
562
|
/** 获取buffer
|
|
526
563
|
* @param name
|
|
527
564
|
* @returns
|
|
528
565
|
*/
|
|
529
566
|
getStorageBuffer(name: string): GPUBuffer | undefined;
|
|
567
|
+
/** 主动设置GPUBuffer, 可共享其他材质已经创建的 GPUBuffer
|
|
568
|
+
* @param name
|
|
569
|
+
* @param buff
|
|
570
|
+
*/
|
|
571
|
+
setStorageBuffer(name: string, buff: GPUBuffer): void;
|
|
530
572
|
}
|
|
531
573
|
|
|
532
574
|
export declare interface ShaderMaterialOptions {
|
|
@@ -542,9 +584,16 @@ export declare interface ShaderMaterialOptions {
|
|
|
542
584
|
blend?: GPUBlendState;
|
|
543
585
|
writeMask?: number | undefined;
|
|
544
586
|
depthStencil?: Omit<GPUDepthStencilState, "format">;
|
|
545
|
-
|
|
587
|
+
define?: Record<string, boolean>;
|
|
546
588
|
}
|
|
547
589
|
|
|
590
|
+
declare function sopc_(opt: Option_2): Promise<{
|
|
591
|
+
renderer: Renderer;
|
|
592
|
+
camera: PerspectiveCamera;
|
|
593
|
+
results: number[][][];
|
|
594
|
+
pointsArray: Float32Array<ArrayBufferLike>;
|
|
595
|
+
}>;
|
|
596
|
+
|
|
548
597
|
export declare class Texture {
|
|
549
598
|
depthTexture: GPUTexture;
|
|
550
599
|
depthView: GPUTextureView;
|
|
@@ -567,7 +616,18 @@ export declare class Texture {
|
|
|
567
616
|
|
|
568
617
|
export declare const transparentOption: Omit<GPUColorTargetState, "format">;
|
|
569
618
|
|
|
570
|
-
declare
|
|
619
|
+
export declare interface UniformMeta {
|
|
620
|
+
type: string;
|
|
621
|
+
value: UniformValue;
|
|
622
|
+
binding?: number;
|
|
623
|
+
buffer?: GPUBuffer;
|
|
624
|
+
write?: boolean;
|
|
625
|
+
atomic?: boolean;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export declare type UniformValue = Color | Matrix4 | Matrix3 | Texture | CubeTexture | number | Vector2 | Vector3 | Vector4 | number[] | Float32Array | Uint32Array | Uint8Array;
|
|
629
|
+
|
|
630
|
+
declare type Vec3 = [number, number, number];
|
|
571
631
|
|
|
572
632
|
declare type WGSl_TYPE = "f32" | "u32" | "vec2" | "vec3" | "vec4" | "mat3x3" | "mat4x4";
|
|
573
633
|
|