@luma.gl/webgpu 9.0.0-alpha.10
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 +32 -0
- package/README.md +1 -0
- package/dist/adapter/helpers/accessor-to-format.d.ts +1 -0
- package/dist/adapter/helpers/accessor-to-format.d.ts.map +1 -0
- package/dist/adapter/helpers/accessor-to-format.js +2 -0
- package/dist/adapter/helpers/accessor-to-format.js.map +1 -0
- package/dist/adapter/helpers/convert-texture-format.d.ts +5 -0
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -0
- package/dist/adapter/helpers/convert-texture-format.js +8 -0
- package/dist/adapter/helpers/convert-texture-format.js.map +1 -0
- package/dist/adapter/helpers/generate-mipmaps.d.ts +10 -0
- package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -0
- package/dist/adapter/helpers/generate-mipmaps.js +95 -0
- package/dist/adapter/helpers/generate-mipmaps.js.map +1 -0
- package/dist/adapter/helpers/get-bind-group.d.ts +13 -0
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -0
- package/dist/adapter/helpers/get-bind-group.js +60 -0
- package/dist/adapter/helpers/get-bind-group.js.map +1 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +12 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +98 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
- package/dist/adapter/helpers/webgpu-parameters.d.ts +9 -0
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -0
- package/dist/adapter/helpers/webgpu-parameters.js +143 -0
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -0
- package/dist/adapter/resources/webgpu-buffer.d.ts +17 -0
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-buffer.js +80 -0
- package/dist/adapter/resources/webgpu-buffer.js.map +1 -0
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +44 -0
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-command-encoder.js +66 -0
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -0
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +32 -0
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-compute-pass.js +58 -0
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -0
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +12 -0
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-compute-pipeline.js +27 -0
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
- package/dist/adapter/resources/webgpu-external-texture.d.ts +18 -0
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-external-texture.js +30 -0
- package/dist/adapter/resources/webgpu-external-texture.js.map +1 -0
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +29 -0
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-framebuffer.js +111 -0
- package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -0
- package/dist/adapter/resources/webgpu-query.d.ts +1 -0
- package/dist/adapter/resources/webgpu-query.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-query.js +2 -0
- package/dist/adapter/resources/webgpu-query.js.map +1 -0
- package/dist/adapter/resources/webgpu-render-pass.d.ts +34 -0
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-render-pass.js +98 -0
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -0
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +44 -0
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-render-pipeline.js +164 -0
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -0
- package/dist/adapter/resources/webgpu-sampler.d.ts +16 -0
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-sampler.js +25 -0
- package/dist/adapter/resources/webgpu-sampler.js.map +1 -0
- package/dist/adapter/resources/webgpu-shader.d.ts +21 -0
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-shader.js +64 -0
- package/dist/adapter/resources/webgpu-shader.js.map +1 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +39 -0
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-texture.js +111 -0
- package/dist/adapter/resources/webgpu-texture.js.map +1 -0
- package/dist/adapter/webgpu-canvas-context.d.ts +32 -0
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -0
- package/dist/adapter/webgpu-canvas-context.js +95 -0
- package/dist/adapter/webgpu-canvas-context.js.map +1 -0
- package/dist/adapter/webgpu-device.d.ts +67 -0
- package/dist/adapter/webgpu-device.d.ts.map +1 -0
- package/dist/adapter/webgpu-device.js +242 -0
- package/dist/adapter/webgpu-device.js.map +1 -0
- package/dist/adapter/webgpu-types.d.ts +1 -0
- package/dist/adapter/webgpu-types.d.ts.map +1 -0
- package/dist/adapter/webgpu-types.js +2 -0
- package/dist/adapter/webgpu-types.js.map +1 -0
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +5 -0
- package/dist/bundle.js.map +1 -0
- package/dist/glsl/glsllang.d.ts +3 -0
- package/dist/glsl/glsllang.d.ts.map +1 -0
- package/dist/glsl/glsllang.js +10 -0
- package/dist/glsl/glsllang.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +4 -0
- package/dist/init.js.map +1 -0
- package/package.json +36 -0
- package/src/adapter/helpers/accessor-to-format.ts +101 -0
- package/src/adapter/helpers/convert-texture-format.ts +10 -0
- package/src/adapter/helpers/generate-mipmaps.ts +107 -0
- package/src/adapter/helpers/get-bind-group.ts +82 -0
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +123 -0
- package/src/adapter/helpers/webgpu-parameters.ts +229 -0
- package/src/adapter/resources/webgpu-buffer.ts +92 -0
- package/src/adapter/resources/webgpu-command-encoder.ts +112 -0
- package/src/adapter/resources/webgpu-compute-pass.ts +74 -0
- package/src/adapter/resources/webgpu-compute-pipeline.ts +34 -0
- package/src/adapter/resources/webgpu-external-texture.ts +37 -0
- package/src/adapter/resources/webgpu-framebuffer.ts +120 -0
- package/src/adapter/resources/webgpu-query.ts +43 -0
- package/src/adapter/resources/webgpu-render-pass.ts +131 -0
- package/src/adapter/resources/webgpu-render-pipeline.ts +246 -0
- package/src/adapter/resources/webgpu-sampler.ts +32 -0
- package/src/adapter/resources/webgpu-shader.ts +72 -0
- package/src/adapter/resources/webgpu-texture.ts +244 -0
- package/src/adapter/webgpu-canvas-context.ts +102 -0
- package/src/adapter/webgpu-device.ts +294 -0
- package/src/adapter/webgpu-types.ts +0 -0
- package/src/bundle.ts +4 -0
- package/src/glsl/glsllang.ts +14 -0
- package/src/index.ts +13 -0
- package/src/init.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Copyright (c) 2020 Urban Computing Foundation
|
|
2
|
+
|
|
3
|
+
This software includes parts initially developed by Uber and open sourced under MIT license.
|
|
4
|
+
Copyright (c) 2015 Uber Technologies, Inc.
|
|
5
|
+
|
|
6
|
+
This software includes parts of PhiloGL (https://github.com/philogb/philogl)
|
|
7
|
+
under MIT license. PhiloGL parts Copyright © 2013 Sencha Labs.
|
|
8
|
+
|
|
9
|
+
This software includes adaptations of some postprocessing code from
|
|
10
|
+
THREE.js (https://github.com/mrdoob/three.js/) under MIT license.
|
|
11
|
+
THREE.js parts Copyright © 2010-2018 three.js authors.
|
|
12
|
+
|
|
13
|
+
Additional attribution given in specific source files.
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in
|
|
23
|
+
all copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
31
|
+
THE SOFTWARE.
|
|
32
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# luma.gl/webgpu
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=accessor-to-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessor-to-format.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/accessor-to-format.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"accessor-to-format.js"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { TextureFormat } from '@luma.gl/api';
|
|
3
|
+
/** Ensure a texture format is WebGPU compatible */
|
|
4
|
+
export declare function getWebGPUTextureFormat(format: TextureFormat): GPUTextureFormat;
|
|
5
|
+
//# sourceMappingURL=convert-texture-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-texture-format.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/convert-texture-format.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAE3C,mDAAmD;AACnD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAK9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/helpers/convert-texture-format.ts"],"names":["getWebGPUTextureFormat","format","includes","Error"],"mappings":"AAIA,OAAO,SAASA,sBAAT,CAAgCC,MAAhC,EAAyE;AAC9E,MAAIA,MAAM,CAACC,QAAP,CAAgB,OAAhB,CAAJ,EAA8B;AAC5B,UAAM,IAAIC,KAAJ,CAAU,mBAAV,CAAN;AACD;;AACD,SAAOF,MAAP;AACD","sourcesContent":["// luma.gl, MIT license\nimport {TextureFormat} from '@luma.gl/api';\n\n/** Ensure a texture format is WebGPU compatible */\nexport function getWebGPUTextureFormat(format: TextureFormat): GPUTextureFormat {\n if (format.includes('webgl')) {\n throw new Error('webgl-only format');\n }\n return format as GPUTextureFormat;\n}\n"],"file":"convert-texture-format.js"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
/** WebGPU does not have built-in mipmap creation */
|
|
3
|
+
export declare class WebGPUMipmapGenerator {
|
|
4
|
+
device: GPUDevice;
|
|
5
|
+
mipmapSampler: GPUSampler;
|
|
6
|
+
mipmapPipeline: GPURenderPipeline;
|
|
7
|
+
constructor(device: GPUDevice, glslang: any);
|
|
8
|
+
generateMipmappedTexture(imageBitmap: ImageBitmap): GPUTexture;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=generate-mipmaps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-mipmaps.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/generate-mipmaps.ts"],"names":[],"mappings":";AAuBA,oDAAoD;AACpD,qBAAa,qBAAqB;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,aAAa,EAAE,UAAU,CAAC;IAC1B,cAAc,EAAE,iBAAiB,CAAC;gBAEtB,MAAM,EAAE,SAAS,EAAE,OAAO,KAAA;IAyBtC,wBAAwB,CAAC,WAAW,EAAE,WAAW;CAoDlD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
const VS_GEN_MIPMAP = "#version 450\nconst vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));\nlayout(location = 0) out vec2 vTex;\nvoid main() {\n gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n vTex = gl_Position / 2.0f + vec2(0.5f);\n}";
|
|
3
|
+
const FS_GEN_MIPMAP = "#version 450\nlayout(set = 0, binding = 0) uniform sampler imgSampler;\nlayout(set = 0, binding = 1) uniform texture2D img;\nlayout(location = 0) in vec2 vTex;\nlayout(location = 0) out vec4 outColor;\nvoid main() {\n outColor = texture(sampler2D(img, imgSampler), vTex);\n}";
|
|
4
|
+
export class WebGPUMipmapGenerator {
|
|
5
|
+
constructor(device, glslang) {
|
|
6
|
+
_defineProperty(this, "device", void 0);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "mipmapSampler", void 0);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "mipmapPipeline", void 0);
|
|
11
|
+
|
|
12
|
+
this.device = device;
|
|
13
|
+
this.mipmapSampler = device.createSampler({
|
|
14
|
+
minFilter: 'linear'
|
|
15
|
+
});
|
|
16
|
+
this.mipmapPipeline = device.createRenderPipeline({
|
|
17
|
+
vertexStage: {
|
|
18
|
+
module: device.createShaderModule({
|
|
19
|
+
code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')
|
|
20
|
+
}),
|
|
21
|
+
entryPoint: 'main'
|
|
22
|
+
},
|
|
23
|
+
fragmentStage: {
|
|
24
|
+
module: device.createShaderModule({
|
|
25
|
+
code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')
|
|
26
|
+
}),
|
|
27
|
+
entryPoint: 'main'
|
|
28
|
+
},
|
|
29
|
+
primitiveTopology: 'triangle-strip',
|
|
30
|
+
colorStates: [{
|
|
31
|
+
format: 'rgba8unorm'
|
|
32
|
+
}]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
generateMipmappedTexture(imageBitmap) {
|
|
37
|
+
let textureSize = {
|
|
38
|
+
width: imageBitmap.width,
|
|
39
|
+
height: imageBitmap.height,
|
|
40
|
+
depth: 1
|
|
41
|
+
};
|
|
42
|
+
const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
|
|
43
|
+
const texture = this.device.createTexture({
|
|
44
|
+
size: textureSize,
|
|
45
|
+
format: 'rgba8unorm',
|
|
46
|
+
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
|
|
47
|
+
mipLevelCount
|
|
48
|
+
});
|
|
49
|
+
this.device.queue.copyImageBitmapToTexture({
|
|
50
|
+
imageBitmap
|
|
51
|
+
}, {
|
|
52
|
+
texture: srcTexture
|
|
53
|
+
}, textureSize);
|
|
54
|
+
const commandEncoder = this.device.createCommandEncoder({});
|
|
55
|
+
|
|
56
|
+
for (let i = 1; i < mipLevelCount; ++i) {
|
|
57
|
+
const passEncoder = commandEncoder.beginRenderPass({
|
|
58
|
+
colorAttachments: [{
|
|
59
|
+
attachment: texture.createView({
|
|
60
|
+
baseMipLevel: i,
|
|
61
|
+
mipLevelCount: 1
|
|
62
|
+
}),
|
|
63
|
+
loadValue: {
|
|
64
|
+
r: 1.0,
|
|
65
|
+
g: 0.0,
|
|
66
|
+
b: 0.0,
|
|
67
|
+
a: 0.0
|
|
68
|
+
}
|
|
69
|
+
}]
|
|
70
|
+
});
|
|
71
|
+
const bindGroup = this.device.createBindGroup({
|
|
72
|
+
layout: this.mipmapPipeline.getBindGroupLayout(0),
|
|
73
|
+
bindings: [{
|
|
74
|
+
binding: 0,
|
|
75
|
+
resource: this.mipmapSampler
|
|
76
|
+
}, {
|
|
77
|
+
binding: 1,
|
|
78
|
+
resource: texture.createView({
|
|
79
|
+
baseMipLevel: i - 1,
|
|
80
|
+
mipLevelCount: 1
|
|
81
|
+
})
|
|
82
|
+
}]
|
|
83
|
+
});
|
|
84
|
+
passEncoder.setPipeline(this.mipmapPipeline);
|
|
85
|
+
passEncoder.setBindGroup(0, bindGroup);
|
|
86
|
+
passEncoder.draw(4);
|
|
87
|
+
passEncoder.endPass();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.device.queue.submit([commandEncoder.finish()]);
|
|
91
|
+
return texture;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=generate-mipmaps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/helpers/generate-mipmaps.ts"],"names":["VS_GEN_MIPMAP","FS_GEN_MIPMAP","WebGPUMipmapGenerator","constructor","device","glslang","mipmapSampler","createSampler","minFilter","mipmapPipeline","createRenderPipeline","vertexStage","module","createShaderModule","code","compileGLSL","entryPoint","fragmentStage","primitiveTopology","colorStates","format","generateMipmappedTexture","imageBitmap","textureSize","width","height","depth","mipLevelCount","Math","floor","log2","max","texture","createTexture","size","usage","GPUTextureUsage","COPY_DST","SAMPLED","OUTPUT_ATTACHMENT","queue","copyImageBitmapToTexture","srcTexture","commandEncoder","createCommandEncoder","i","passEncoder","beginRenderPass","colorAttachments","attachment","createView","baseMipLevel","loadValue","r","g","b","a","bindGroup","createBindGroup","layout","getBindGroupLayout","bindings","binding","resource","setPipeline","setBindGroup","draw","endPass","submit","finish"],"mappings":";AAMA,MAAMA,aAAa,mRAAnB;AAQA,MAAMC,aAAa,wRAAnB;AAUA,OAAO,MAAMC,qBAAN,CAA4B;AAKjCC,EAAAA,WAAW,CAACC,MAAD,EAAoBC,OAApB,EAA6B;AAAA;;AAAA;;AAAA;;AACtC,SAAKD,MAAL,GAAcA,MAAd;AAEA,SAAKE,aAAL,GAAqBF,MAAM,CAACG,aAAP,CAAqB;AAAEC,MAAAA,SAAS,EAAE;AAAb,KAArB,CAArB;AAEA,SAAKC,cAAL,GAAsBL,MAAM,CAACM,oBAAP,CAA4B;AAChDC,MAAAA,WAAW,EAAE;AACXC,QAAAA,MAAM,EAAER,MAAM,CAACS,kBAAP,CAA0B;AAChCC,UAAAA,IAAI,EAAET,OAAO,CAACU,WAAR,CAAoBf,aAApB,EAAmC,QAAnC;AAD0B,SAA1B,CADG;AAIXgB,QAAAA,UAAU,EAAE;AAJD,OADmC;AAOhDC,MAAAA,aAAa,EAAE;AACbL,QAAAA,MAAM,EAAER,MAAM,CAACS,kBAAP,CAA0B;AAChCC,UAAAA,IAAI,EAAET,OAAO,CAACU,WAAR,CAAoBd,aAApB,EAAmC,UAAnC;AAD0B,SAA1B,CADK;AAIbe,QAAAA,UAAU,EAAE;AAJC,OAPiC;AAahDE,MAAAA,iBAAiB,EAAE,gBAb6B;AAchDC,MAAAA,WAAW,EAAE,CAAC;AACZC,QAAAA,MAAM,EAAE;AADI,OAAD;AAdmC,KAA5B,CAAtB;AAkBD;;AAEDC,EAAAA,wBAAwB,CAACC,WAAD,EAA2B;AACjD,QAAIC,WAAW,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kBC,YAAAA,CAAC,EAAE,GAArB;AAA0BC,YAAAA,CAAC,EAAE;AAA7B;AALM,SAAD;AAD+B,OAA/B,CAApB;AAUA,YAAMC,SAAS,GAAG,KAAKrD,MAAL,CAAYsD,eAAZ,CAA4B;AAC5CC,QAAAA,MAAM,EAAE,KAAKlD,cAAL,CAAoBmD,kBAApB,CAAuC,CAAvC,CADoC;AAE5CC,QAAAA,QAAQ,EAAE,CAAC;AACTC,UAAAA,OAAO,EAAE,CADA;AAETC,UAAAA,QAAQ,EAAE,KAAKzD;AAFN,SAAD,EAGP;AACDwD,UAAAA,OAAO,EAAE,CADR;AAEDC,UAAAA,QAAQ,EAAE/B,OAAO,CAACkB,UAAR,CAAmB;AAC3BC,YAAAA,YAAY,EAAEN,CAAC,GAAG,CADS;AAE3BlB,YAAAA,aAAa,EAAE;AAFY,WAAnB;AAFT,SAHO;AAFkC,OAA5B,CAAlB;AAcAmB,MAAAA,WAAW,CAACkB,WAAZ,CAAwB,KAAKvD,cAA7B;AACAqC,MAAAA,WAAW,CAACmB,YAAZ,CAAyB,CAAzB,EAA4BR,SAA5B;AACAX,MAAAA,WAAW,CAACoB,IAAZ,CAAiB,CAAjB;AACApB,MAAAA,WAAW,CAACqB,OAAZ;AACD;;AAED,SAAK/D,MAAL,CAAYoC,KAAZ,CAAkB4B,MAAlB,CAAyB,CAACzB,cAAc,CAAC0B,MAAf,EAAD,CAAzB;AACA,WAAOrC,OAAP;AACD;;AAjFgC","sourcesContent":["// luma.gl, MIT license\n// Forked from Kangz/mipmapper.js under MIT license Copyright 2020 Brandon Jones\n// https://gist.github.com/Kangz/782d5f1ae502daf53910a13f55db2f83\n\n// @ts-nocheck this is written against outdated WebGPU API, needs an update pass\n\nconst VS_GEN_MIPMAP = `\\#version 450\nconst vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));\nlayout(location = 0) out vec2 vTex;\nvoid main() {\n gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n vTex = gl_Position / 2.0f + vec2(0.5f);\n}`;\n\nconst FS_GEN_MIPMAP = `#version 450\nlayout(set = 0, binding = 0) uniform sampler imgSampler;\nlayout(set = 0, binding = 1) uniform texture2D img;\nlayout(location = 0) in vec2 vTex;\nlayout(location = 0) out vec4 outColor;\nvoid main() {\n outColor = texture(sampler2D(img, imgSampler), vTex);\n}`;\n\n/** WebGPU does not have built-in mipmap creation */\nexport class WebGPUMipmapGenerator {\n device: GPUDevice;\n mipmapSampler: GPUSampler;\n mipmapPipeline: GPURenderPipeline;\n\n constructor(device: GPUDevice, glslang) {\n this.device = device;\n\n this.mipmapSampler = device.createSampler({ minFilter: 'linear' });\n\n this.mipmapPipeline = device.createRenderPipeline({\n vertexStage: {\n module: device.createShaderModule({\n code: glslang.compileGLSL(VS_GEN_MIPMAP, 'vertex')\n }),\n entryPoint: 'main'\n },\n fragmentStage: {\n module: device.createShaderModule({\n code: glslang.compileGLSL(FS_GEN_MIPMAP, 'fragment')\n }),\n entryPoint: 'main'\n },\n primitiveTopology: 'triangle-strip',\n colorStates: [{\n format: 'rgba8unorm',\n }]\n });\n }\n\n generateMipmappedTexture(imageBitmap: ImageBitmap) {\n let textureSize = {\n width: imageBitmap.width,\n height: imageBitmap.height,\n depth: 1,\n }\n const mipLevelCount = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;\n\n // Populate the top level of the srcTexture with the imageBitmap.\n const texture = this.device.createTexture({\n size: textureSize,\n format: 'rgba8unorm',\n usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,\n mipLevelCount\n });\n this.device.queue.copyImageBitmapToTexture({ imageBitmap }, { texture: srcTexture }, textureSize);\n\n const commandEncoder = this.device.createCommandEncoder({});\n for (let i = 1; i < mipLevelCount; ++i) {\n const passEncoder = commandEncoder.beginRenderPass({\n colorAttachments: [{\n attachment: texture.createView({\n baseMipLevel: i,\n mipLevelCount: 1\n }),\n loadValue: { r: 1.0, g: 0.0, b: 0.0, a: 0.0 },\n }],\n });\n\n const bindGroup = this.device.createBindGroup({\n layout: this.mipmapPipeline.getBindGroupLayout(0),\n bindings: [{\n binding: 0,\n resource: this.mipmapSampler,\n }, {\n binding: 1,\n resource: texture.createView({\n baseMipLevel: i - 1,\n mipLevelCount: 1\n }),\n }],\n });\n\n passEncoder.setPipeline(this.mipmapPipeline);\n passEncoder.setBindGroup(0, bindGroup);\n passEncoder.draw(4);\n passEncoder.endPass();\n }\n\n this.device.queue.submit([commandEncoder.finish()]);\n return texture;\n }\n}\n"],"file":"generate-mipmaps.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import type { ShaderLayout, BindingLayout, Binding } from '@luma.gl/api';
|
|
3
|
+
/**
|
|
4
|
+
* Create a WebGPU "bind group layout" from an array of luma.gl bindings
|
|
5
|
+
* @note bind groups can be automatically generated by WebGPU.
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeBindGroupLayout(device: GPUDevice, layout: GPUBindGroupLayout, bindings: Binding[]): GPUBindGroupLayout;
|
|
8
|
+
/**
|
|
9
|
+
* Create a WebGPU "bind group" from an array of luma.gl bindings
|
|
10
|
+
*/
|
|
11
|
+
export declare function getBindGroup(device: GPUDevice, bindGroupLayout: GPUBindGroupLayout, layout: ShaderLayout, bindings: Record<string, Binding>): GPUBindGroup;
|
|
12
|
+
export declare function getShaderLayoutBinding(layout: ShaderLayout, bindingName: string): BindingLayout;
|
|
13
|
+
//# sourceMappingURL=get-bind-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-bind-group.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAMvE;;;GAGG;AACF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAM3H;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,eAAe,EAAE,kBAAkB,EACnC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAMd;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa,CAM/F"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/api';
|
|
2
|
+
export function makeBindGroupLayout(device, layout, bindings) {
|
|
3
|
+
throw new Error('not implemented');
|
|
4
|
+
}
|
|
5
|
+
export function getBindGroup(device, bindGroupLayout, layout, bindings) {
|
|
6
|
+
const entries = getBindGroupEntries(bindings, layout);
|
|
7
|
+
return device.createBindGroup({
|
|
8
|
+
layout: bindGroupLayout,
|
|
9
|
+
entries
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function getShaderLayoutBinding(layout, bindingName) {
|
|
13
|
+
const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);
|
|
14
|
+
|
|
15
|
+
if (!bindingLayout) {
|
|
16
|
+
log.warn("Binding ".concat(bindingName, " not set: Not found in shader layout."))();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return bindingLayout;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getBindGroupEntries(bindings, layout) {
|
|
23
|
+
const entries = [];
|
|
24
|
+
|
|
25
|
+
for (const [bindingName, value] of Object.entries(bindings)) {
|
|
26
|
+
const bindingLayout = getShaderLayoutBinding(layout, bindingName);
|
|
27
|
+
|
|
28
|
+
if (bindingLayout) {
|
|
29
|
+
entries.push(getBindGroupEntry(value, bindingLayout.location));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return entries;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getBindGroupEntry(binding, index) {
|
|
37
|
+
if (binding instanceof Buffer) {
|
|
38
|
+
return {
|
|
39
|
+
binding: index,
|
|
40
|
+
resource: {
|
|
41
|
+
buffer: cast(binding).handle
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (binding instanceof Sampler) {
|
|
47
|
+
return {
|
|
48
|
+
binding: index,
|
|
49
|
+
resource: cast(binding).handle
|
|
50
|
+
};
|
|
51
|
+
} else if (binding instanceof Texture) {
|
|
52
|
+
return {
|
|
53
|
+
binding: index,
|
|
54
|
+
resource: cast(binding).handle.createView()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new Error('invalid binding');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=get-bind-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/helpers/get-bind-group.ts"],"names":["Buffer","Sampler","Texture","log","cast","makeBindGroupLayout","device","layout","bindings","Error","getBindGroup","bindGroupLayout","entries","getBindGroupEntries","createBindGroup","getShaderLayoutBinding","bindingName","bindingLayout","find","binding","name","warn","value","Object","push","getBindGroupEntry","location","index","resource","buffer","handle","createView"],"mappings":"AAEA,SAAQA,MAAR,EAAgBC,OAAhB,EAAyBC,OAAzB,EAAkCC,GAAlC,EAAuCC,IAAvC,QAAkD,cAAlD;AASC,OAAO,SAASC,mBAAT,CAA6BC,MAA7B,EAAgDC,MAAhD,EAA4EC,QAA5E,EAAqH;AAC3H,QAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;AAKD;AAKD,OAAO,SAASC,YAAT,CACLJ,MADK,EAELK,eAFK,EAGLJ,MAHK,EAILC,QAJK,EAKS;AACd,QAAMI,OAAO,GAAGC,mBAAmB,CA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AQ,EAAExB,IAAI,CAAgBe,OAAhB,CAAJ,CAA6BW;AAFlC,KAAP;AAID,GALD,MAKO,IAAIX,OAAO,YAAYjB,OAAvB,EAAgC;AACrC,WAAO;AACLiB,MAAAA,OAAO,EAAEQ,KADJ;AAELC,MAAAA,QAAQ,EAAExB,IAAI,CAAgBe,OAAhB,CAAJ,CAA6BW,MAA7B,CAAoCC,UAApC;AAFL,KAAP;AAID;;AACD,QAAM,IAAItB,KAAJ,CAAU,iBAAV,CAAN;AACD","sourcesContent":["// luma.gl, MIT license\nimport type {ShaderLayout, BindingLayout, Binding} from '@luma.gl/api';\nimport {Buffer, Sampler, Texture, log, cast} from '@luma.gl/api';\nimport type WebGPUBuffer from '../resources/webgpu-buffer';\nimport type WebGPUSampler from '../resources/webgpu-sampler';\nimport type WebGPUTexture from '../resources/webgpu-texture';\n\n/**\n * Create a WebGPU \"bind group layout\" from an array of luma.gl bindings\n * @note bind groups can be automatically generated by WebGPU.\n */\n export function makeBindGroupLayout(device: GPUDevice, layout: GPUBindGroupLayout, bindings: Binding[]): GPUBindGroupLayout {\n throw new Error('not implemented');\n // return device.createBindGroupLayout({\n // layout,\n // entries: getBindGroupEntries(bindings)\n // })\n}\n\n/**\n * Create a WebGPU \"bind group\" from an array of luma.gl bindings\n */\nexport function getBindGroup(\n device: GPUDevice,\n bindGroupLayout: GPUBindGroupLayout,\n layout: ShaderLayout,\n bindings: Record<string, Binding>\n): GPUBindGroup {\n const entries = getBindGroupEntries(bindings, layout);\n return device.createBindGroup({\n layout: bindGroupLayout,\n entries\n });\n}\n\nexport function getShaderLayoutBinding(layout: ShaderLayout, bindingName: string): BindingLayout {\n const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);\n if (!bindingLayout) {\n log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();\n }\n return bindingLayout;\n}\n\n/**\n * @param bindings\n * @returns\n */\nfunction getBindGroupEntries(bindings: Record<string, Binding>, layout: ShaderLayout): GPUBindGroupEntry[] {\n const entries: GPUBindGroupEntry[] = [];\n\n for (const [bindingName, value] of Object.entries(bindings)) {\n const bindingLayout = getShaderLayoutBinding(layout, bindingName);\n if (bindingLayout) {\n entries.push(getBindGroupEntry(value, bindingLayout.location));\n }\n }\n\n return entries;\n}\n\nfunction getBindGroupEntry(binding: Binding, index: number): GPUBindGroupEntry {\n if (binding instanceof Buffer) {\n return {\n binding: index,\n resource: {\n buffer: cast<WebGPUBuffer>(binding).handle\n }\n };\n }\n if (binding instanceof Sampler) {\n return {\n binding: index,\n resource: cast<WebGPUSampler>(binding).handle\n };\n } else if (binding instanceof Texture) {\n return {\n binding: index,\n resource: cast<WebGPUTexture>(binding).handle.createView()\n };\n }\n throw new Error('invalid binding');\n}\n"],"file":"get-bind-group.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import type { ShaderLayout, BufferMapping } from '@luma.gl/api';
|
|
3
|
+
/**
|
|
4
|
+
* Build a WebGPU vertex buffer layout intended for use in a GPURenderPassDescriptor.
|
|
5
|
+
* Converts luma.gl attribute definitions to a WebGPU GPUVertexBufferLayout[] array
|
|
6
|
+
* @param layout
|
|
7
|
+
* @param bufferMap The buffer map is optional
|
|
8
|
+
* @returns WebGPU layout intended for a GPURenderPassDescriptor.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getVertexBufferLayout(layout: ShaderLayout, bufferMap: BufferMapping[]): GPUVertexBufferLayout[];
|
|
11
|
+
export declare function getBufferSlots(layout: ShaderLayout, bufferMap: BufferMapping[]): Record<string, number>;
|
|
12
|
+
//# sourceMappingURL=get-vertex-buffer-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-vertex-buffer-layout.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-vertex-buffer-layout.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAkB,MAAM,cAAc,CAAC;AAG/E;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,qBAAqB,EAAE,CAkE/G;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BvG"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { decodeVertexFormat } from '@luma.gl/api';
|
|
2
|
+
export function getVertexBufferLayout(layout, bufferMap) {
|
|
3
|
+
const vertexBufferLayouts = [];
|
|
4
|
+
const usedAttributes = new Set();
|
|
5
|
+
|
|
6
|
+
for (const mapping of bufferMap) {
|
|
7
|
+
const vertexAttributes = [];
|
|
8
|
+
let stepMode = 'vertex';
|
|
9
|
+
let byteStride = 0;
|
|
10
|
+
let byteOffset = mapping.byteOffset || 0;
|
|
11
|
+
|
|
12
|
+
if ('attributes' in mapping) {
|
|
13
|
+
const arrayStride = mapping.byteStride;
|
|
14
|
+
|
|
15
|
+
for (const interleaved of mapping.attributes) {
|
|
16
|
+
const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
|
|
17
|
+
stepMode = attributeLayout.stepMode || 'vertex';
|
|
18
|
+
vertexAttributes.push({
|
|
19
|
+
format: attributeLayout.format,
|
|
20
|
+
offset: byteOffset + byteStride,
|
|
21
|
+
shaderLocation: attributeLayout.location
|
|
22
|
+
});
|
|
23
|
+
byteStride += decodeVertexFormat(attributeLayout.format).byteLength;
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);
|
|
27
|
+
byteStride = decodeVertexFormat(attributeLayout.format).byteLength, stepMode = attributeLayout.stepMode || 'vertex';
|
|
28
|
+
vertexAttributes.push({
|
|
29
|
+
format: attributeLayout.format,
|
|
30
|
+
offset: byteOffset,
|
|
31
|
+
shaderLocation: attributeLayout.location
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
vertexBufferLayouts.push({
|
|
36
|
+
arrayStride: mapping.byteStride || byteStride,
|
|
37
|
+
stepMode: stepMode || 'vertex',
|
|
38
|
+
attributes: vertexAttributes
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const attribute of layout.attributes) {
|
|
43
|
+
if (!usedAttributes.has(attribute.name)) {
|
|
44
|
+
vertexBufferLayouts.push({
|
|
45
|
+
arrayStride: decodeVertexFormat(attribute.format).byteLength,
|
|
46
|
+
stepMode: attribute.stepMode || 'vertex',
|
|
47
|
+
attributes: [{
|
|
48
|
+
format: attribute.format,
|
|
49
|
+
offset: 0,
|
|
50
|
+
shaderLocation: attribute.location
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return vertexBufferLayouts;
|
|
57
|
+
}
|
|
58
|
+
export function getBufferSlots(layout, bufferMap) {
|
|
59
|
+
const usedAttributes = new Set();
|
|
60
|
+
let bufferSlot = 0;
|
|
61
|
+
const bufferSlots = {};
|
|
62
|
+
|
|
63
|
+
for (const mapping of bufferMap) {
|
|
64
|
+
if ('attributes' in mapping) {
|
|
65
|
+
for (const interleaved of mapping.attributes) {
|
|
66
|
+
usedAttributes.add(interleaved.name);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
usedAttributes.add(mapping.name);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
bufferSlots[mapping.name] = bufferSlot++;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const attribute of layout.attributes) {
|
|
76
|
+
if (!usedAttributes.has(attribute.name)) {
|
|
77
|
+
bufferSlots[attribute.name] = bufferSlot++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return bufferSlots;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function findAttributeLayout(layout, name, attributeNames) {
|
|
85
|
+
const attribute = layout.attributes.find(attribute => attribute.name === name);
|
|
86
|
+
|
|
87
|
+
if (!attribute) {
|
|
88
|
+
throw new Error("Unknown attribute ".concat(name));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (attributeNames.has(name)) {
|
|
92
|
+
throw new Error("Duplicate attribute ".concat(name));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
attributeNames.add(name);
|
|
96
|
+
return attribute;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=get-vertex-buffer-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/helpers/get-vertex-buffer-layout.ts"],"names":["decodeVertexFormat","getVertexBufferLayout","layout","bufferMap","vertexBufferLayouts","usedAttributes","Set","mapping","vertexAttributes","stepMode","byteStride","byteOffset","arrayStride","interleaved","attributes","attributeLayout","findAttributeLayout","name","push","format","offset","shaderLocation","location","byteLength","attribute","has","getBufferSlots","bufferSlot","bufferSlots","add","attributeNames","find","Error"],"mappings":"AACA,SAAQA,kBAAR,QAAiC,cAAjC;AASA,OAAO,SAASC,qBAAT,CAA+BC,MAA/B,EAAqDC,SAArD,EAA0G;AAC/G,QAAMC,mBAA4C,GAAG,EAArD;AACA,QAAMC,cAAc,GAAG,IAAIC,GAAJ,EAAvB;;AAGA,OAAK,MAAMC,OAAX,IAAsBJ,SAAtB,EAAiC;AAE/B,UAAMK,gBAAsC,GAAG,EAA/C;AAGA,QAAIC,QAA+B,GAAG,QAAtC;AACA,QAAIC,UAAU,GAAG,CAAjB;AACA,QAAIC,UAAU,GAAGJ,OAAO,CAACI,UAAR,IAAsB,CAAvC;;AAGA,QAAI,gBAAgBJ,OAApB,EAA6B;AAC3B,YAAMK,WAAW,GAAGL,OAAO,CAACG,UAA5B;;AACA,WAAK,MAAMG,WAAX,IAA0BN,OAAO,CAACO,UAAlC,EAA8C;AAC5C,cAAMC,eAAe,GAAGC,mBAAmB,CAACd,MAAD,EAASW,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S,GAAGtB,MAAM,CAACY,UAAP,CAAkBiB,IAAlB,CAAuBP,SAAS,IAAIA,SAAS,CAACP,IAAV,KAAmBA,IAAvD,CAAlB;;AACA,MAAI,CAACO,SAAL,EAAgB;AACd,UAAM,IAAIQ,KAAJ,6BAA+Bf,IAA/B,EAAN;AACD;;AACD,MAAIa,cAAc,CAACL,GAAf,CAAmBR,IAAnB,CAAJ,EAA8B;AAC5B,UAAM,IAAIe,KAAJ,+BAAiCf,IAAjC,EAAN;AACD;;AACDa,EAAAA,cAAc,CAACD,GAAf,CAAmBZ,IAAnB;AACA,SAAOO,SAAP;AACD","sourcesContent":["import type {ShaderLayout, BufferMapping, AttributeLayout} from '@luma.gl/api';\nimport {decodeVertexFormat} from '@luma.gl/api';\n\n/**\n * Build a WebGPU vertex buffer layout intended for use in a GPURenderPassDescriptor.\n * Converts luma.gl attribute definitions to a WebGPU GPUVertexBufferLayout[] array\n * @param layout\n * @param bufferMap The buffer map is optional\n * @returns WebGPU layout intended for a GPURenderPassDescriptor.\n */\nexport function getVertexBufferLayout(layout: ShaderLayout, bufferMap: BufferMapping[]): GPUVertexBufferLayout[] {\n const vertexBufferLayouts: GPUVertexBufferLayout[] = [];\n const usedAttributes = new Set<string>();\n\n // First handle any buffers mentioned in `bufferMapping`\n for (const mapping of bufferMap) {\n // Build vertex attributes for one buffer\n const vertexAttributes: GPUVertexAttribute[] = [];\n\n // TODO verify that all stepModes for one buffer are the same\n let stepMode: 'vertex' | 'instance' = 'vertex';\n let byteStride = 0;\n let byteOffset = mapping.byteOffset || 0;\n\n // interleaved mapping {..., attributes: [{...}, ...]}\n if ('attributes' in mapping) {\n const arrayStride = mapping.byteStride;\n for (const interleaved of mapping.attributes) {\n const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);\n\n stepMode = attributeLayout.stepMode || 'vertex';\n vertexAttributes.push({\n format: attributeLayout.format,\n offset: byteOffset + byteStride,\n shaderLocation: attributeLayout.location\n });\n\n byteStride += decodeVertexFormat(attributeLayout.format).byteLength;\n }\n // non-interleaved mapping (just set offset and stride)\n } else {\n const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);\n byteStride = decodeVertexFormat(attributeLayout.format).byteLength,\n\n stepMode = attributeLayout.stepMode || 'vertex';\n vertexAttributes.push({\n format: attributeLayout.format,\n offset: byteOffset,\n shaderLocation: attributeLayout.location\n });\n }\n\n // Store all the attribute bindings for one buffer\n vertexBufferLayouts.push({\n arrayStride: mapping.byteStride || byteStride,\n stepMode: stepMode || 'vertex',\n attributes: vertexAttributes\n });\n }\n\n // Add any non-mapped attributes\n for (const attribute of layout.attributes) {\n if (!usedAttributes.has(attribute.name)) {\n vertexBufferLayouts.push({\n arrayStride: decodeVertexFormat(attribute.format).byteLength,\n stepMode: attribute.stepMode || 'vertex',\n attributes: [{\n format: attribute.format,\n offset: 0,\n shaderLocation: attribute.location\n }]\n });\n }\n }\n\n return vertexBufferLayouts;\n}\n\nexport function getBufferSlots(layout: ShaderLayout, bufferMap: BufferMapping[]): Record<string, number> {\n const usedAttributes = new Set<string>();\n let bufferSlot = 0;\n const bufferSlots: Record<string, number> = {};\n\n // First handle any buffers mentioned in `bufferMapping`\n for (const mapping of bufferMap) {\n // interleaved mapping {..., attributes: [{...}, ...]}\n if ('attributes' in mapping) {\n for (const interleaved of mapping.attributes) {\n usedAttributes.add(interleaved.name);\n }\n // non-interleaved mapping (just set offset and stride)\n } else {\n usedAttributes.add(mapping.name);\n }\n bufferSlots[mapping.name] = bufferSlot++;\n }\n\n // Add any non-mapped attributes\n for (const attribute of layout.attributes) {\n if (!usedAttributes.has(attribute.name)) {\n bufferSlots[attribute.name] = bufferSlot++;\n }\n }\n\n return bufferSlots;\n}\n\n/**\n * Looks up an attribute in the ShaderLayout.\n * @throws if name is not in ShaderLayout\n * @throws if name has already been referenced\n */\nfunction findAttributeLayout(layout: ShaderLayout, name: string, attributeNames: Set<string>): AttributeLayout {\n const attribute = layout.attributes.find(attribute => attribute.name === name);\n if (!attribute) {\n throw new Error(`Unknown attribute ${name}`);\n }\n if (attributeNames.has(name)) {\n throw new Error(`Duplicate attribute ${name}`);\n }\n attributeNames.add(name);\n return attribute;\n}\n"],"file":"get-vertex-buffer-layout.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { Parameters } from '@luma.gl/api';
|
|
3
|
+
/**
|
|
4
|
+
* Supports for luma.gl's flat parameter space
|
|
5
|
+
* Populates the corresponding sub-objects in a GPURenderPipelineDescriptor
|
|
6
|
+
*/
|
|
7
|
+
export declare const PARAMETER_TABLE: Record<keyof Parameters, Function>;
|
|
8
|
+
export declare function applyParametersToRenderPipelineDescriptor(pipelineDescriptor: GPURenderPipelineDescriptor, parameters?: Parameters): void;
|
|
9
|
+
//# sourceMappingURL=webgpu-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgpu-parameters.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/webgpu-parameters.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAYxC;;;GAGG;AAEH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,UAAU,EAAE,QAAQ,CAqJ9D,CAAC;AA8BF,wBAAgB,yCAAyC,CACvD,kBAAkB,EAAE,2BAA2B,EAC/C,UAAU,GAAE,UAAe,GAC1B,IAAI,CAIN"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
function addDepthStencil(descriptor) {
|
|
2
|
+
descriptor.depthStencil = descriptor.depthStencil || {
|
|
3
|
+
format: 'depth24plus',
|
|
4
|
+
stencilFront: {},
|
|
5
|
+
stencilBack: {}
|
|
6
|
+
};
|
|
7
|
+
return descriptor.depthStencil;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const PARAMETER_TABLE = {
|
|
11
|
+
cullMode: (parameter, value, descriptor) => {
|
|
12
|
+
descriptor.primitive = descriptor.primitive || {};
|
|
13
|
+
descriptor.primitive.cullMode = value;
|
|
14
|
+
},
|
|
15
|
+
frontFace: (parameter, value, descriptor) => {
|
|
16
|
+
descriptor.primitive = descriptor.primitive || {};
|
|
17
|
+
descriptor.primitive.frontFace = value;
|
|
18
|
+
},
|
|
19
|
+
depthWriteEnabled: (parameter, value, descriptor) => {
|
|
20
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
21
|
+
depthStencil.depthWriteEnabled = value;
|
|
22
|
+
},
|
|
23
|
+
depthCompare: (parameter, value, descriptor) => {
|
|
24
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
25
|
+
depthStencil.depthCompare = value;
|
|
26
|
+
},
|
|
27
|
+
depthFormat: (parameter, value, descriptor) => {
|
|
28
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
29
|
+
depthStencil.format = value;
|
|
30
|
+
},
|
|
31
|
+
depthBias: (parameter, value, descriptor) => {
|
|
32
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
33
|
+
depthStencil.depthBias = value;
|
|
34
|
+
},
|
|
35
|
+
depthBiasSlopeScale: (parameter, value, descriptor) => {
|
|
36
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
37
|
+
depthStencil.depthBiasSlopeScale = value;
|
|
38
|
+
},
|
|
39
|
+
depthBiasClamp: (parameter, value, descriptor) => {
|
|
40
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
41
|
+
depthStencil.depthBiasClamp = value;
|
|
42
|
+
},
|
|
43
|
+
stencilReadMask: (parameter, value, descriptor) => {
|
|
44
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
45
|
+
depthStencil.stencilReadMask = value;
|
|
46
|
+
},
|
|
47
|
+
stencilWriteMask: (parameter, value, descriptor) => {
|
|
48
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
49
|
+
depthStencil.stencilWriteMask = value;
|
|
50
|
+
},
|
|
51
|
+
stencilCompare: (parameter, value, descriptor) => {
|
|
52
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
53
|
+
depthStencil.stencilFront.compare = value;
|
|
54
|
+
depthStencil.stencilBack.compare = value;
|
|
55
|
+
},
|
|
56
|
+
stencilPassOperation: (parameter, value, descriptor) => {
|
|
57
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
58
|
+
depthStencil.stencilFront.passOp = value;
|
|
59
|
+
depthStencil.stencilBack.passOp = value;
|
|
60
|
+
},
|
|
61
|
+
stencilFailOperation: (parameter, value, descriptor) => {
|
|
62
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
63
|
+
depthStencil.stencilFront.failOp = value;
|
|
64
|
+
depthStencil.stencilBack.failOp = value;
|
|
65
|
+
},
|
|
66
|
+
stencilDepthFailOperation: (parameter, value, descriptor) => {
|
|
67
|
+
const depthStencil = addDepthStencil(descriptor);
|
|
68
|
+
depthStencil.stencilFront.depthFailOp = value;
|
|
69
|
+
depthStencil.stencilBack.depthFailOp = value;
|
|
70
|
+
},
|
|
71
|
+
sampleCount: (parameter, value, descriptor) => {
|
|
72
|
+
descriptor.multisample = descriptor.multisample || {};
|
|
73
|
+
descriptor.multisample.count = value;
|
|
74
|
+
},
|
|
75
|
+
sampleMask: (parameter, value, descriptor) => {
|
|
76
|
+
descriptor.multisample = descriptor.multisample || {};
|
|
77
|
+
descriptor.multisample.mask = value;
|
|
78
|
+
},
|
|
79
|
+
sampleAlphaToCoverageEnabled: (parameter, value, descriptor) => {
|
|
80
|
+
descriptor.multisample = descriptor.multisample || {};
|
|
81
|
+
descriptor.multisample.alphaToCoverageEnabled = value;
|
|
82
|
+
},
|
|
83
|
+
colorMask: (parameter, value, descriptor) => {
|
|
84
|
+
const targets = addColorState(descriptor);
|
|
85
|
+
targets[0].writeMask = value;
|
|
86
|
+
},
|
|
87
|
+
blendColorOperation: (parameter, value, descriptor) => {
|
|
88
|
+
const targets = addColorState(descriptor);
|
|
89
|
+
const target = targets[0];
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const DEFAULT_PIPELINE_DESCRIPTOR = {
|
|
93
|
+
primitive: {
|
|
94
|
+
cullMode: 'back',
|
|
95
|
+
topology: 'triangle-list'
|
|
96
|
+
},
|
|
97
|
+
vertex: {
|
|
98
|
+
module: undefined,
|
|
99
|
+
entryPoint: 'main'
|
|
100
|
+
},
|
|
101
|
+
fragment: {
|
|
102
|
+
module: undefined,
|
|
103
|
+
entryPoint: 'main',
|
|
104
|
+
targets: []
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
export function applyParametersToRenderPipelineDescriptor(pipelineDescriptor, parameters = {}) {
|
|
108
|
+
Object.assign(pipelineDescriptor, { ...DEFAULT_PIPELINE_DESCRIPTOR,
|
|
109
|
+
...pipelineDescriptor
|
|
110
|
+
});
|
|
111
|
+
setParameters(pipelineDescriptor, parameters);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function setParameters(pipelineDescriptor, parameters) {
|
|
115
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
116
|
+
const setterFunction = PARAMETER_TABLE[key];
|
|
117
|
+
|
|
118
|
+
if (!setterFunction) {
|
|
119
|
+
throw new Error("Illegal parameter ".concat(key));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setterFunction(key, value, pipelineDescriptor);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function addColorState(descriptor) {
|
|
127
|
+
var _descriptor$fragment, _descriptor$fragment2, _descriptor$fragment3, _descriptor$fragment4, _descriptor$fragment5;
|
|
128
|
+
|
|
129
|
+
descriptor.fragment.targets = ((_descriptor$fragment = descriptor.fragment) === null || _descriptor$fragment === void 0 ? void 0 : _descriptor$fragment.targets) || [];
|
|
130
|
+
|
|
131
|
+
if (!Array.isArray((_descriptor$fragment2 = descriptor.fragment) === null || _descriptor$fragment2 === void 0 ? void 0 : _descriptor$fragment2.targets)) {
|
|
132
|
+
throw new Error('colorstate');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (((_descriptor$fragment3 = descriptor.fragment) === null || _descriptor$fragment3 === void 0 ? void 0 : (_descriptor$fragment4 = _descriptor$fragment3.targets) === null || _descriptor$fragment4 === void 0 ? void 0 : _descriptor$fragment4.length) === 0) {
|
|
136
|
+
var _descriptor$fragment$;
|
|
137
|
+
|
|
138
|
+
(_descriptor$fragment$ = descriptor.fragment.targets) === null || _descriptor$fragment$ === void 0 ? void 0 : _descriptor$fragment$.push({});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (_descriptor$fragment5 = descriptor.fragment) === null || _descriptor$fragment5 === void 0 ? void 0 : _descriptor$fragment5.targets;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=webgpu-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/helpers/webgpu-parameters.ts"],"names":["addDepthStencil","descriptor","depthStencil","format","stencilFront","stencilBack","PARAMETER_TABLE","cullMode","parameter","value","primitive","frontFace","depthWriteEnabled","depthCompare","depthFormat","depthBias","depthBiasSlopeScale","depthBiasClamp","stencilReadMask","stencilWriteMask","stencilCompare","compare","stencilPassOperation","passOp","stencilFailOperation","failOp","stencilDepthFailOperation","depthFailOp","sampleCount","multisample","count","sampleMask","mask","sampleAlphaToCoverageEnabled","alphaToCoverageEnabled","colorMask","targets","addColorState","writeMask","blendColorOperation","target","DEFAULT_PIPELINE_DESCRIPTOR","topology","vertex","module","undefined","entryPoint","fragment","applyParametersToRenderPipelineDescriptor","pipelineDescriptor","parameters","Object","assign","setParameters","key","entries","setterFunction","Error","Array","isArray","length","push"],"mappings":"AAEA,SAASA,eAAT,CAAyBC,UAAzB,EAAwF;AACtFA,EAAAA,UAAU,CAACC,YAAX,GAA0BD,UAAU,CAACC,YAAX,IAA2B;AAEnDC,IAAAA,MAAM,EAAE,aAF2C;AAGnDC,IAAAA,YAAY,EAAE,EAHqC;AAInDC,IAAAA,WAAW,EAAE;AAJsC,GAArD;AAMA,SAAOJ,UAAU,CAACC,YAAlB;AAC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EAGQ;AACN,OAAK,MAAM,CAACI,GAAD,EAAM7C,KAAN,CAAX,IAA2B0C,MAAM,CAACI,OAAP,CAAeL,UAAf,CAA3B,EAAuD;AACrD,UAAMM,cAAc,GAAGlD,eAAe,CAACgD,GAAD,CAAtC;;AACA,QAAI,CAACE,cAAL,EAAqB;AACnB,YAAM,IAAIC,KAAJ,6BAA+BH,GAA/B,EAAN;AACD;;AACDE,IAAAA,cAAc,CAACF,GAAD,EAAM7C,KAAN,EAAawC,kBAAb,CAAd;AACD;AACF;;AAED,SAASZ,aAAT,CAAuBpC,UAAvB,EAAuF;AAAA;;AACrFA,EAAAA,UAAU,CAAC8C,QAAX,CAAqBX,OAArB,GAA+B,yBAAAnC,UAAU,CAAC8C,QAAX,8EAAqBX,OAArB,KAAgC,EAA/D;;AACA,MAAI,CAACsB,KAAK,CAACC,OAAN,0BAAc1D,UAAU,CAAC8C,QAAzB,0DAAc,sBAAqBX,OAAnC,CAAL,EAAkD;AAChD,UAAM,IAAIqB,KAAJ,CAAU,YAAV,CAAN;AACD;;AACD,MAAI,0BAAAxD,UAAU,CAAC8C,QAAX,yGAAqBX,OAArB,gFAA8BwB,MAA9B,MAAyC,CAA7C,EAAgD;AAAA;;AAC9C,6BAAA3D,UAAU,CAAC8C,QAAX,CAAoBX,OAApB,gFAA6ByB,IAA7B,CAAkC,EAAlC;AACD;;AACD,kCAAO5D,UAAU,CAAC8C,QAAlB,0DAAO,sBAAqBX,OAA5B;AACD","sourcesContent":["import {Parameters} from '@luma.gl/api';\n\nfunction addDepthStencil(descriptor: GPURenderPipelineDescriptor): GPUDepthStencilState {\n descriptor.depthStencil = descriptor.depthStencil || {\n // required, set something\n format: 'depth24plus',\n stencilFront: {},\n stencilBack: {}\n };\n return descriptor.depthStencil;\n}\n\n/**\n * Supports for luma.gl's flat parameter space\n * Populates the corresponding sub-objects in a GPURenderPipelineDescriptor\n */\n// @ts-expect-error\nexport const PARAMETER_TABLE: Record<keyof Parameters, Function> = {\n // RASTERIZATION PARAMETERS\n\n cullMode: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n descriptor.primitive = descriptor.primitive || {};\n descriptor.primitive.cullMode = value;\n },\n\n frontFace: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n descriptor.primitive = descriptor.primitive || {};\n descriptor.primitive.frontFace = value;\n },\n\n // DEPTH\n\n depthWriteEnabled: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.depthWriteEnabled = value;\n },\n\n depthCompare: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.depthCompare = value;\n },\n\n depthFormat: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.format = value;\n },\n\n depthBias: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.depthBias = value;\n },\n\n depthBiasSlopeScale: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.depthBiasSlopeScale = value;\n },\n\n depthBiasClamp: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.depthBiasClamp = value;\n },\n\n // STENCIL\n\n stencilReadMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.stencilReadMask = value;\n },\n\n stencilWriteMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.stencilWriteMask = value;\n },\n\n stencilCompare: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.stencilFront!.compare = value;\n depthStencil.stencilBack!.compare = value;\n },\n\n stencilPassOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.stencilFront!.passOp = value;\n depthStencil.stencilBack!.passOp = value;\n },\n\n stencilFailOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.stencilFront!.failOp = value;\n depthStencil.stencilBack!.failOp = value;\n },\n\n stencilDepthFailOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const depthStencil = addDepthStencil(descriptor);\n depthStencil.stencilFront!.depthFailOp = value;\n depthStencil.stencilBack!.depthFailOp = value;\n },\n\n // MULTISAMPLE\n\n sampleCount: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n descriptor.multisample = descriptor.multisample || {};\n descriptor.multisample.count = value;\n },\n\n sampleMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n descriptor.multisample = descriptor.multisample || {};\n descriptor.multisample.mask = value;\n },\n\n sampleAlphaToCoverageEnabled: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n descriptor.multisample = descriptor.multisample || {};\n descriptor.multisample.alphaToCoverageEnabled = value;\n },\n\n // COLOR\n\n colorMask: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const targets = addColorState(descriptor);\n targets[0].writeMask = value;\n },\n\n blendColorOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {\n const targets = addColorState(descriptor);\n const target = targets[0];\n // const blend: GPUBlendState = target.blend || {color: {alpha: 0}};\n // blend.color = blend.color || {};\n // target.blend.color.operation = value;\n }\n\n /*\n blendColorSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {\n addColorState(descriptor);\n targets[0].blend = targets[0].blend || {};\n targets[0].blend.color = targets[0].blend.color || {};\n targets[0].blend.color.srcTarget = value;\n },\n\n blendColorDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {\n addColorState(descriptor);\n targets[0].blend = targets[0].blend || {};\n targets[0].blend.color = targets[0].blend.color || {};\n targets[0].blend.color.dstTarget = value;\n },\n\n blendAlphaOperation: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {\n addColorState(descriptor);\n targets[0].blend = targets[0].blend || {};\n targets[0].blend.alpha = targets[0].blend.alpha || {};\n targets[0].blend.alpha.operation = value;\n },\n\n blendAlphaSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {\n addColorState(descriptor);\n targets[0].blend = targets[0].blend || {};\n targets[0].blend.alpha = targets[0].blend.alpha || {};\n targets[0].blend.alpha.srcTarget = value;\n },\n\n blendAlphaDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {\n addColorState(descriptor);\n targets[0].blend = targets[0].blend || {};\n targets[0].blend.alpha = targets[0].blend.alpha || {};\n targets[0].blend.alpha.dstTarget = value;\n },\n */\n};\n\nconst DEFAULT_PIPELINE_DESCRIPTOR: GPURenderPipelineDescriptor = {\n // depthStencil: {\n // stencilFront: {},\n // stencilBack: {},\n // // depthWriteEnabled: true,\n // // depthCompare: 'less',\n // // format: 'depth24plus-stencil8',\n // },\n\n primitive: {\n cullMode: 'back',\n topology: 'triangle-list'\n },\n\n vertex: {\n module: undefined!,\n entryPoint: 'main'\n },\n\n fragment: {\n module: undefined!,\n entryPoint: 'main',\n targets: [\n // { format: props.color0Format || 'bgra8unorm' }\n ]\n }\n};\n\nexport function applyParametersToRenderPipelineDescriptor(\n pipelineDescriptor: GPURenderPipelineDescriptor,\n parameters: Parameters = {}\n): void {\n // Apply defaults\n Object.assign(pipelineDescriptor, {...DEFAULT_PIPELINE_DESCRIPTOR, ...pipelineDescriptor});\n setParameters(pipelineDescriptor, parameters);\n}\n\n// Apply any supplied parameters\nfunction setParameters(\n pipelineDescriptor: GPURenderPipelineDescriptor,\n parameters: Parameters\n): void {\n for (const [key, value] of Object.entries(parameters)) {\n const setterFunction = PARAMETER_TABLE[key as keyof Parameters];\n if (!setterFunction) {\n throw new Error(`Illegal parameter ${key}`);\n }\n setterFunction(key, value, pipelineDescriptor);\n }\n}\n\nfunction addColorState(descriptor: GPURenderPipelineDescriptor): GPUColorTargetState[] {\n descriptor.fragment!.targets = descriptor.fragment?.targets || [];\n if (!Array.isArray(descriptor.fragment?.targets)) {\n throw new Error('colorstate');\n }\n if (descriptor.fragment?.targets?.length === 0) {\n descriptor.fragment.targets?.push({});\n }\n return descriptor.fragment?.targets as GPUColorTargetState[];\n}\n"],"file":"webgpu-parameters.js"}
|