rm-webgpu-compute-tasks 0.0.2 → 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 +107 -48
- package/src/index.js +1272 -270
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;
|
|
@@ -294,13 +317,6 @@ declare interface IOption {
|
|
|
294
317
|
opacity?: number;
|
|
295
318
|
}
|
|
296
319
|
|
|
297
|
-
declare interface IOption_2 {
|
|
298
|
-
side?: GPUCullMode;
|
|
299
|
-
topology?: GPUPrimitiveTopology;
|
|
300
|
-
cubeTexture: Texture;
|
|
301
|
-
results?: Uint32Array;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
320
|
declare type IStruct = IStructBaseType[];
|
|
305
321
|
|
|
306
322
|
declare interface IStructArray {
|
|
@@ -340,6 +356,7 @@ export declare function loadData(base: string, linesJson_?: any): Promise<IData
|
|
|
340
356
|
}>;
|
|
341
357
|
|
|
342
358
|
export declare class Object3D extends THREE.Object3D {
|
|
359
|
+
static get GROU_INDEX(): number;
|
|
343
360
|
static get bindGroupLayout(): GPUBindGroupLayout;
|
|
344
361
|
private buffer;
|
|
345
362
|
bindGroup: GPUBindGroup;
|
|
@@ -376,11 +393,13 @@ declare function obstacleDetection_(opt: ICreateObstacleDetection): Promise<{
|
|
|
376
393
|
result: number[];
|
|
377
394
|
}>;
|
|
378
395
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
396
|
+
declare interface Option_2 {
|
|
397
|
+
base: string;
|
|
398
|
+
urls: string[];
|
|
399
|
+
erodeMaskSize?: number;
|
|
400
|
+
kernelSize?: number;
|
|
401
|
+
gridSize?: number;
|
|
402
|
+
gridAmount?: number;
|
|
384
403
|
}
|
|
385
404
|
|
|
386
405
|
export declare class PerspectiveCamera extends THREE.PerspectiveCamera {
|
|
@@ -451,35 +470,52 @@ export declare class Renderer {
|
|
|
451
470
|
format: GPUTextureFormat;
|
|
452
471
|
renderTarget: GPUTextureView | null;
|
|
453
472
|
depthTarget: GPUTextureView | null;
|
|
473
|
+
/**
|
|
474
|
+
* @param width
|
|
475
|
+
* @param height
|
|
476
|
+
* @param format
|
|
477
|
+
*/
|
|
454
478
|
constructor(width?: number, height?: number, format?: GPUTextureFormat);
|
|
479
|
+
/** 渲染
|
|
480
|
+
* @param meshList
|
|
481
|
+
* @param camera
|
|
482
|
+
* @param depthClearValue
|
|
483
|
+
* @returns
|
|
484
|
+
*/
|
|
455
485
|
render(meshList: Object3D[], camera: PerspectiveCamera, depthClearValue?: number): void;
|
|
486
|
+
compute(materials: ComputeMaterial[] | ComputeMaterial): void;
|
|
456
487
|
}
|
|
457
488
|
|
|
489
|
+
export declare const segmentObjectPointClouds: typeof sopc_ & {
|
|
490
|
+
getResult(opt: Option_2): Promise<number[][][]>;
|
|
491
|
+
};
|
|
492
|
+
|
|
458
493
|
export declare const shaderLocationMap: Map<string, number>;
|
|
459
494
|
|
|
460
|
-
export declare class ShaderMaterial {
|
|
495
|
+
export declare class ShaderMaterial<T = GPURenderPipeline> {
|
|
496
|
+
static get GROU_INDEX(): number;
|
|
461
497
|
vertex: string;
|
|
462
498
|
fragment: string;
|
|
463
|
-
pipeline?:
|
|
499
|
+
pipeline?: T;
|
|
464
500
|
bindGroup: GPUBindGroup;
|
|
465
501
|
buffer: GPUBuffer;
|
|
466
502
|
uniforms: Record<string, {
|
|
467
503
|
value: UniformValue;
|
|
468
504
|
}>;
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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;
|
|
480
516
|
get needsUniformUpdate(): boolean;
|
|
481
517
|
set needsUniformUpdate(v: boolean);
|
|
482
|
-
|
|
518
|
+
protected _needsBindGroupUpdate: boolean;
|
|
483
519
|
get needsBindGroupUpdate(): boolean;
|
|
484
520
|
set needsBindGroupUpdate(v: boolean);
|
|
485
521
|
constructor(options: ShaderMaterialOptions);
|
|
@@ -487,47 +523,52 @@ export declare class ShaderMaterial {
|
|
|
487
523
|
* 初始化uniform
|
|
488
524
|
* @param uniforms
|
|
489
525
|
*/
|
|
490
|
-
|
|
526
|
+
protected _initUniform(uniforms: any): void;
|
|
491
527
|
/**
|
|
492
528
|
* 获取绑定组布局
|
|
493
529
|
* @returns
|
|
494
530
|
*/
|
|
495
|
-
|
|
531
|
+
protected _getBindGroupLayout(): GPUBindGroupLayout;
|
|
496
532
|
/**
|
|
497
533
|
* 创建绑定组
|
|
498
534
|
*/
|
|
499
|
-
|
|
535
|
+
protected _createBindGroup(): void;
|
|
500
536
|
/** 生成uniform 代码
|
|
501
|
-
* @param
|
|
537
|
+
* @param mtype
|
|
502
538
|
* @returns
|
|
503
539
|
*/
|
|
504
|
-
|
|
540
|
+
protected _generateUniformWGSL(mtype: "vertex" | "fragment" | "compute"): string;
|
|
505
541
|
/** 生成 顶点着色器入参类型代码
|
|
506
542
|
* @param attrMap
|
|
507
543
|
* @returns
|
|
508
544
|
*/
|
|
509
|
-
|
|
545
|
+
protected _generateVertexInputWGSL(attrMap: Map<string, GPUAttribute>): string;
|
|
510
546
|
/**
|
|
511
547
|
* 生成 Storage 类型代码
|
|
512
548
|
*/
|
|
513
|
-
|
|
549
|
+
protected _generateStorageWGSL(type: "vertex" | "fragment" | "compute"): string;
|
|
514
550
|
/** 创建渲染管线
|
|
515
551
|
* @param attrMap
|
|
516
552
|
* @param colorFormat
|
|
517
553
|
* @param depthFormat
|
|
518
554
|
* @returns
|
|
519
555
|
*/
|
|
520
|
-
createPipeline(attrMap: Map<string, GPUAttribute>, colorFormat?: GPUTextureFormat, depthFormat?: GPUTextureFormat): GPURenderPipeline;
|
|
556
|
+
createPipeline(attrMap: Map<string, GPUAttribute>, colorFormat?: GPUTextureFormat, depthFormat?: GPUTextureFormat): GPURenderPipeline | T | undefined;
|
|
521
557
|
/**
|
|
522
558
|
* 更新uniform 数据
|
|
523
559
|
*/
|
|
524
|
-
|
|
560
|
+
protected _updateUniform(): void;
|
|
525
561
|
update(): void;
|
|
526
562
|
/** 获取buffer
|
|
527
563
|
* @param name
|
|
528
564
|
* @returns
|
|
529
565
|
*/
|
|
530
566
|
getStorageBuffer(name: string): GPUBuffer | undefined;
|
|
567
|
+
/** 主动设置GPUBuffer, 可共享其他材质已经创建的 GPUBuffer
|
|
568
|
+
* @param name
|
|
569
|
+
* @param buff
|
|
570
|
+
*/
|
|
571
|
+
setStorageBuffer(name: string, buff: GPUBuffer): void;
|
|
531
572
|
}
|
|
532
573
|
|
|
533
574
|
export declare interface ShaderMaterialOptions {
|
|
@@ -543,9 +584,16 @@ export declare interface ShaderMaterialOptions {
|
|
|
543
584
|
blend?: GPUBlendState;
|
|
544
585
|
writeMask?: number | undefined;
|
|
545
586
|
depthStencil?: Omit<GPUDepthStencilState, "format">;
|
|
546
|
-
|
|
587
|
+
define?: Record<string, boolean>;
|
|
547
588
|
}
|
|
548
589
|
|
|
590
|
+
declare function sopc_(opt: Option_2): Promise<{
|
|
591
|
+
renderer: Renderer;
|
|
592
|
+
camera: PerspectiveCamera;
|
|
593
|
+
results: number[][][];
|
|
594
|
+
pointsArray: Float32Array<ArrayBufferLike>;
|
|
595
|
+
}>;
|
|
596
|
+
|
|
549
597
|
export declare class Texture {
|
|
550
598
|
depthTexture: GPUTexture;
|
|
551
599
|
depthView: GPUTextureView;
|
|
@@ -568,7 +616,18 @@ export declare class Texture {
|
|
|
568
616
|
|
|
569
617
|
export declare const transparentOption: Omit<GPUColorTargetState, "format">;
|
|
570
618
|
|
|
571
|
-
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];
|
|
572
631
|
|
|
573
632
|
declare type WGSl_TYPE = "f32" | "u32" | "vec2" | "vec3" | "vec4" | "mat3x3" | "mat4x4";
|
|
574
633
|
|