@vgpu/render 0.0.5 → 0.0.7
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/README.md +94 -5
- package/dist/frame.d.ts +19 -0
- package/dist/frame.d.ts.map +1 -0
- package/dist/frame.js +50 -0
- package/dist/frame.js.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/perf/frame-time-measure.d.ts +22 -0
- package/dist/perf/frame-time-measure.d.ts.map +1 -0
- package/dist/perf/frame-time-measure.js +91 -0
- package/dist/perf/frame-time-measure.js.map +1 -0
- package/dist/perf/gpu-frame-time.d.ts +49 -0
- package/dist/perf/gpu-frame-time.d.ts.map +1 -0
- package/dist/perf/gpu-frame-time.js +50 -0
- package/dist/perf/gpu-frame-time.js.map +1 -0
- package/dist/perf/index.d.ts +5 -0
- package/dist/perf/index.d.ts.map +1 -0
- package/dist/perf/index.js +3 -0
- package/dist/perf/index.js.map +1 -0
- package/dist/perf/pixel-diff.d.ts +27 -0
- package/dist/perf/pixel-diff.d.ts.map +1 -0
- package/dist/perf/pixel-diff.js +40 -0
- package/dist/perf/pixel-diff.js.map +1 -0
- package/dist/pipeline-descriptor.d.ts +35 -0
- package/dist/pipeline-descriptor.d.ts.map +1 -0
- package/dist/pipeline-descriptor.js +44 -0
- package/dist/pipeline-descriptor.js.map +1 -0
- package/dist/pipeline.d.ts +24 -14
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +58 -7
- package/dist/pipeline.js.map +1 -1
- package/dist/render-bundle.d.ts +24 -0
- package/dist/render-bundle.d.ts.map +1 -0
- package/dist/render-bundle.js +39 -0
- package/dist/render-bundle.js.map +1 -0
- package/dist/render-pass.d.ts +16 -1
- package/dist/render-pass.d.ts.map +1 -1
- package/dist/render-pass.js +44 -7
- package/dist/render-pass.js.map +1 -1
- package/dist/storage-buffer.d.ts +81 -0
- package/dist/storage-buffer.d.ts.map +1 -0
- package/dist/storage-buffer.js +91 -0
- package/dist/storage-buffer.js.map +1 -0
- package/dist/uniform.d.ts +55 -0
- package/dist/uniform.d.ts.map +1 -0
- package/dist/uniform.js +64 -0
- package/dist/uniform.js.map +1 -0
- package/package.json +8 -3
- package/src/Frame.docs.md +79 -0
- package/src/RenderPass.docs.md +6 -3
- package/src/createRenderPipeline.docs.md +113 -19
- package/src/perf/perf.docs.md +45 -0
- package/src/rapid-renderer.docs.md +15 -1
- package/src/render-bundle.docs.md +46 -0
- package/src/render-target/render-target-canvas.docs.md +15 -0
- package/src/storage-buffer.docs.md +102 -0
- package/src/uniform.docs.md +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-descriptor.d.ts","sourceRoot":"","sources":["../src/pipeline-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,yBAAyB,GAAG,MAAM,GAAG,eAAe,CAAC;AAEjE,MAAM,WAAW,0BAA0B;IACzC,mGAAmG;IACnG,QAAQ,CAAC,MAAM,CAAC,EAAE,yBAAyB,CAAC;IAC5C,wCAAwC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,yBAAyB,CAAC;IAC5C,2FAA2F;IAC3F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,wCAAwC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,2BAA4B,SAAQ,0BAA0B;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,qBAAqB,GAAG,IAAI,CAAC,EAAE,CAAC;CAC9D;AAED,MAAM,WAAW,6BAA8B,SAAQ,0BAA0B;IAC/E,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,mBAAmB,GAAG,IAAI,CAAC,EAAE,CAAC;CAC3D;AAED,MAAM,WAAW,qBAAqB;IACpC,yGAAyG;IACzG,QAAQ,CAAC,MAAM,CAAC,EAAE,yBAAyB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,6BAA6B,CAAC;IAClD,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IAC7C,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAC3C,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,sHAAsH;IACtH,QAAQ,CAAC,QAAQ,CAAC,EAAE,2BAA2B,CAAC;CACjD;AAED,MAAM,MAAM,2BAA2B,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,qBAAqB,GAAG,2BAA2B,CAyBnG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Shader, VGPUError } from "@vgpu/core";
|
|
2
|
+
export function toRenderPipelineDescriptor(opts) {
|
|
3
|
+
const descriptor = {
|
|
4
|
+
label: opts.label,
|
|
5
|
+
layout: opts.layout ?? "auto",
|
|
6
|
+
vertex: {
|
|
7
|
+
module: stageModule(opts.vertex, opts.shader, "vertex"),
|
|
8
|
+
entryPoint: stageEntryPoint(opts.vertex),
|
|
9
|
+
constants: opts.vertex.constants,
|
|
10
|
+
buffers: opts.vertex.buffers ? [...opts.vertex.buffers] : undefined,
|
|
11
|
+
},
|
|
12
|
+
primitive: opts.primitive,
|
|
13
|
+
depthStencil: opts.depthStencil,
|
|
14
|
+
multisample: opts.multisample,
|
|
15
|
+
};
|
|
16
|
+
if (opts.fragment) {
|
|
17
|
+
descriptor.fragment = {
|
|
18
|
+
module: stageModule(opts.fragment, opts.shader, "fragment"),
|
|
19
|
+
entryPoint: stageEntryPoint(opts.fragment),
|
|
20
|
+
constants: opts.fragment.constants,
|
|
21
|
+
targets: [...opts.fragment.targets],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return descriptor;
|
|
25
|
+
}
|
|
26
|
+
function stageModule(stage, fallback, stageName) {
|
|
27
|
+
const module = stage.module ?? stage.shader ?? fallback;
|
|
28
|
+
if (!module) {
|
|
29
|
+
throw new VGPUError({
|
|
30
|
+
code: "VGPU-RENDER-PIPELINE-MISSING-SHADER",
|
|
31
|
+
message: `Missing shader module for ${stageName} stage.`,
|
|
32
|
+
fix: "Pass options.shader for a shared module or pass vertex/fragment module or shader.",
|
|
33
|
+
where: `createRenderPipeline.${stageName}`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return isShader(module) ? module.gpu : module;
|
|
37
|
+
}
|
|
38
|
+
function stageEntryPoint(stage) {
|
|
39
|
+
return stage.entryPoint ?? stage.entry;
|
|
40
|
+
}
|
|
41
|
+
function isShader(input) {
|
|
42
|
+
return input instanceof Shader;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=pipeline-descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-descriptor.js","sourceRoot":"","sources":["../src/pipeline-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAwC/C,MAAM,UAAU,0BAA0B,CAAC,IAA2B;IACpE,MAAM,UAAU,GAAgC;QAC9C,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,MAAM;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC;YACvD,UA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;AAChD,CAAC;AAED,SAAS,eAAe,CAAC,KAAiC;IACxD,OAAO,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,KAAK,CAAC;AACzC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAgC;IAChD,OAAO,KAAK,YAAY,MAAM,CAAC;AACjC,CAAC"}
|
package/dist/pipeline.d.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly vertex: {
|
|
5
|
-
readonly entry: string;
|
|
6
|
-
};
|
|
7
|
-
readonly fragment: {
|
|
8
|
-
readonly entry: string;
|
|
9
|
-
readonly targets: readonly GPUColorTargetState[];
|
|
10
|
-
};
|
|
11
|
-
readonly primitive?: GPUPrimitiveState;
|
|
12
|
-
readonly layout?: GPUPipelineLayout | "auto";
|
|
13
|
-
readonly label?: string;
|
|
14
|
-
}
|
|
1
|
+
import { type Device } from "@vgpu/core";
|
|
2
|
+
import type { RenderPipelineAsyncFallback, RenderPipelineOptions } from "./pipeline-descriptor.ts";
|
|
3
|
+
export type { RenderPipelineAsyncFallback, RenderPipelineFragmentOptions, RenderPipelineOptions, RenderPipelineShaderInput, RenderPipelineStageOptions, RenderPipelineVertexOptions, } from "./pipeline-descriptor.ts";
|
|
15
4
|
export declare function createRenderPipeline(device: Device, opts: RenderPipelineOptions): GPURenderPipeline;
|
|
5
|
+
export declare function createRenderPipelineAsync(device: Device, opts: RenderPipelineOptions): Promise<GPURenderPipeline>;
|
|
6
|
+
/**
|
|
7
|
+
* Create a render pipeline from a raw, hand-built `GPURenderPipelineDescriptor`.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Use this when you already own a native descriptor and only want VGPU's
|
|
11
|
+
* `Device` wrapper to forward it — no `RenderPipelineOptions` reshape. The
|
|
12
|
+
* descriptor is passed through unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createRenderPipelineFromDescriptor(device: Device, descriptor: GPURenderPipelineDescriptor): GPURenderPipeline;
|
|
15
|
+
/**
|
|
16
|
+
* Async variant of {@link createRenderPipelineFromDescriptor} with the same
|
|
17
|
+
* async→sync compatibility fallback as {@link createRenderPipelineAsync}.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* The descriptor is forwarded unchanged. When `GPUDevice.createRenderPipelineAsync`
|
|
21
|
+
* is unavailable, the default `fallback: "sync"` emits a once-only diagnostic and
|
|
22
|
+
* calls the synchronous path; pass `fallback: "throw"` for a structured `VGPUError`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createRenderPipelineFromDescriptorAsync(device: Device, descriptor: GPURenderPipelineDescriptor, fallback?: RenderPipelineAsyncFallback): Promise<GPURenderPipeline>;
|
|
25
|
+
export declare function __resetCreateRenderPipelineAsyncFallbackWarningForTests(): void;
|
|
16
26
|
//# sourceMappingURL=pipeline.d.ts.map
|
package/dist/pipeline.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEnG,YAAY,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AASlC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAqB,GAAG,iBAAiB,CAEnG;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAO5B;AAED;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,2BAA2B,GACtC,iBAAiB,CAEnB;AAED;;;;;;;;GAQG;AACH,wBAAsB,uCAAuC,CAC3D,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,2BAA2B,EACvC,QAAQ,CAAC,EAAE,2BAA2B,GACrC,OAAO,CAAC,iBAAiB,CAAC,CAE5B;AA0BD,wBAAgB,uDAAuD,IAAI,IAAI,CAE9E"}
|
package/dist/pipeline.js
CHANGED
|
@@ -1,10 +1,61 @@
|
|
|
1
|
+
import { VGPUError } from "@vgpu/core";
|
|
2
|
+
import { toRenderPipelineDescriptor } from "./pipeline-descriptor.js";
|
|
3
|
+
// Warn once per JS process. This keeps compatibility fallback visible without spamming
|
|
4
|
+
// apps that intentionally warm up multiple pipelines on implementations without
|
|
5
|
+
// GPUDevice.createRenderPipelineAsync().
|
|
6
|
+
let didWarnAboutAsyncFallback = false;
|
|
1
7
|
export function createRenderPipeline(device, opts) {
|
|
2
|
-
return device.gpu.createRenderPipeline(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
return device.gpu.createRenderPipeline(toRenderPipelineDescriptor(opts));
|
|
9
|
+
}
|
|
10
|
+
export async function createRenderPipelineAsync(device, opts) {
|
|
11
|
+
return createPipelineAsync(device, toRenderPipelineDescriptor(opts), opts.fallback, "createRenderPipelineAsync");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a render pipeline from a raw, hand-built `GPURenderPipelineDescriptor`.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Use this when you already own a native descriptor and only want VGPU's
|
|
18
|
+
* `Device` wrapper to forward it — no `RenderPipelineOptions` reshape. The
|
|
19
|
+
* descriptor is passed through unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export function createRenderPipelineFromDescriptor(device, descriptor) {
|
|
22
|
+
return device.gpu.createRenderPipeline(descriptor);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Async variant of {@link createRenderPipelineFromDescriptor} with the same
|
|
26
|
+
* async→sync compatibility fallback as {@link createRenderPipelineAsync}.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* The descriptor is forwarded unchanged. When `GPUDevice.createRenderPipelineAsync`
|
|
30
|
+
* is unavailable, the default `fallback: "sync"` emits a once-only diagnostic and
|
|
31
|
+
* calls the synchronous path; pass `fallback: "throw"` for a structured `VGPUError`.
|
|
32
|
+
*/
|
|
33
|
+
export async function createRenderPipelineFromDescriptorAsync(device, descriptor, fallback) {
|
|
34
|
+
return createPipelineAsync(device, descriptor, fallback, "createRenderPipelineFromDescriptorAsync");
|
|
35
|
+
}
|
|
36
|
+
async function createPipelineAsync(device, descriptor, fallback, where) {
|
|
37
|
+
const createAsync = device.gpu.createRenderPipelineAsync;
|
|
38
|
+
if (typeof createAsync === "function") {
|
|
39
|
+
return createAsync.call(device.gpu, descriptor);
|
|
40
|
+
}
|
|
41
|
+
if ((fallback ?? "sync") === "throw") {
|
|
42
|
+
throw new VGPUError({
|
|
43
|
+
code: "VGPU-RENDER-PIPELINE-ASYNC-UNAVAILABLE",
|
|
44
|
+
message: "GPUDevice.createRenderPipelineAsync is unavailable on this WebGPU implementation.",
|
|
45
|
+
fix: "Use fallback: 'sync' for compatibility or call createRenderPipeline() explicitly during setup/warmup.",
|
|
46
|
+
where,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
warnAsyncFallbackOnce();
|
|
50
|
+
return device.gpu.createRenderPipeline(descriptor);
|
|
51
|
+
}
|
|
52
|
+
export function __resetCreateRenderPipelineAsyncFallbackWarningForTests() {
|
|
53
|
+
didWarnAboutAsyncFallback = false;
|
|
54
|
+
}
|
|
55
|
+
function warnAsyncFallbackOnce() {
|
|
56
|
+
if (didWarnAboutAsyncFallback)
|
|
57
|
+
return;
|
|
58
|
+
didWarnAboutAsyncFallback = true;
|
|
59
|
+
globalThis.console?.warn?.("[vgpu/render] createRenderPipelineAsync is unavailable; falling back to synchronous createRenderPipeline(). Pass fallback: 'throw' to make this a structured VGPUError.");
|
|
9
60
|
}
|
|
10
61
|
//# sourceMappingURL=pipeline.js.map
|
package/dist/pipeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAYtE,uFAAuF;AACvF,gFAAgF;AAChF,yCAAyC;AACzC,IAAI,yBAAyB,GAAG,KAAK,CAAC;AAItC,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,IAA2B;IAC9E,OAAO,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,MAAc,EACd,IAA2B;IAE3B,OAAO,mBAAmB,CACxB,MAAM,EACN,0BAA0B,CAAC,IAAI,CAAC,EAChC,IAAI,CAAC,QAAQ,EACb,2BAA2B,CAC5B,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kCAAkC,CAChD,MAAc,EACd,UAAuC;IAEvC,OAAO,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uCAAuC,CAC3D,MAAc,EACd,UAAuC,EACvC,QAAsC;IAEtC,OAAO,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,yCAAyC,CAAC,CAAC;AACtG,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,MAAc,EACd,UAAuC,EACvC,QAAiD,EACjD,KAAyB;IAEzB,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC;IACzD,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;QACtC,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,KAAK,OAAO,EAAE,CAAC;QACrC,MAAM,IAAI,SAAS,CAAC;YAClB,IAAI,EAAE,wCAAwC;YAC9C,OAAO,EAAE,mFAAmF;YAC5F,GAAG,EAAE,uGAAuG;YAC5G,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,qBAAqB,EAAE,CAAC;IACxB,OAAO,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,uDAAuD;IACrE,yBAAyB,GAAG,KAAK,CAAC;AACpC,CAAC;AAED,SAAS,qBAAqB;IAC5B,IAAI,yBAAyB;QAAE,OAAO;IACtC,yBAAyB,GAAG,IAAI,CAAC;IACjC,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,CACxB,yKAAyK,CAC1K,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Buffer } from "@vgpu/core";
|
|
2
|
+
import type { RenderPassDrawOptions, RenderPassDynamicOffsets } from "./render-pass.ts";
|
|
3
|
+
export interface RenderBundleOptions {
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
readonly colorFormats: readonly (GPUTextureFormat | null)[];
|
|
6
|
+
readonly depthStencilFormat?: GPUTextureFormat;
|
|
7
|
+
readonly sampleCount?: number;
|
|
8
|
+
readonly depthReadOnly?: boolean;
|
|
9
|
+
readonly stencilReadOnly?: boolean;
|
|
10
|
+
readonly record: (bundle: RenderBundleRecorder) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare class RenderBundleRecorder {
|
|
13
|
+
readonly gpu: GPURenderBundleEncoder;
|
|
14
|
+
constructor(gpu: GPURenderBundleEncoder);
|
|
15
|
+
setPipeline(pipeline: GPURenderPipeline): void;
|
|
16
|
+
setBindGroup(index: number, group: GPUBindGroup | null, dynamicOffsets?: RenderPassDynamicOffsets): void;
|
|
17
|
+
setVertexBuffer(slot: number, buffer: Buffer | GPUBuffer | null, offset?: number, size?: GPUSize64): void;
|
|
18
|
+
draw(options: RenderPassDrawOptions): void;
|
|
19
|
+
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createRenderBundle(device: {
|
|
22
|
+
readonly gpu: GPUDevice;
|
|
23
|
+
}, opts: RenderBundleOptions): GPURenderBundle;
|
|
24
|
+
//# sourceMappingURL=render-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-bundle.d.ts","sourceRoot":"","sources":["../src/render-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAExF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC;IAC5D,QAAQ,CAAC,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IAC/C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACzD;AAED,qBAAa,oBAAoB;IACnB,QAAQ,CAAC,GAAG,EAAE,sBAAsB;gBAA3B,GAAG,EAAE,sBAAsB;IAEhD,WAAW,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAI9C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,EAAE,cAAc,CAAC,EAAE,wBAAwB,GAAG,IAAI;IAIxG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAAE,MAAM,SAAI,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI;IAIpG,IAAI,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAC1C,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;CAatG;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,IAAI,EAAE,mBAAmB,GAAG,eAAe,CAWlH"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Buffer } from "@vgpu/core";
|
|
2
|
+
export class RenderBundleRecorder {
|
|
3
|
+
gpu;
|
|
4
|
+
constructor(gpu) {
|
|
5
|
+
this.gpu = gpu;
|
|
6
|
+
}
|
|
7
|
+
setPipeline(pipeline) {
|
|
8
|
+
this.gpu.setPipeline(pipeline);
|
|
9
|
+
}
|
|
10
|
+
setBindGroup(index, group, dynamicOffsets) {
|
|
11
|
+
this.gpu.setBindGroup(index, group, dynamicOffsets);
|
|
12
|
+
}
|
|
13
|
+
setVertexBuffer(slot, buffer, offset = 0, size) {
|
|
14
|
+
this.gpu.setVertexBuffer(slot, gpuBuffer(buffer), offset, size);
|
|
15
|
+
}
|
|
16
|
+
draw(optionsOrVertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) {
|
|
17
|
+
if (typeof optionsOrVertexCount === "number") {
|
|
18
|
+
this.gpu.draw(optionsOrVertexCount, instanceCount, firstVertex, firstInstance);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.gpu.draw(optionsOrVertexCount.vertexCount, optionsOrVertexCount.instanceCount ?? 1, optionsOrVertexCount.firstVertex ?? 0, optionsOrVertexCount.firstInstance ?? 0);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function createRenderBundle(device, opts) {
|
|
25
|
+
const encoder = device.gpu.createRenderBundleEncoder({
|
|
26
|
+
label: opts.label,
|
|
27
|
+
colorFormats: opts.colorFormats,
|
|
28
|
+
depthStencilFormat: opts.depthStencilFormat,
|
|
29
|
+
sampleCount: opts.sampleCount,
|
|
30
|
+
depthReadOnly: opts.depthReadOnly,
|
|
31
|
+
stencilReadOnly: opts.stencilReadOnly,
|
|
32
|
+
});
|
|
33
|
+
opts.record(new RenderBundleRecorder(encoder));
|
|
34
|
+
return encoder.finish({ label: opts.label });
|
|
35
|
+
}
|
|
36
|
+
function gpuBuffer(buffer) {
|
|
37
|
+
return buffer instanceof Buffer ? buffer.gpu : buffer;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=render-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-bundle.js","sourceRoot":"","sources":["../src/render-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAapC,MAAM,OAAO,oBAAoB;IACV;IAArB,YAAqB,GAA2B;QAA3B,QAAG,GAAH,GAAG,CAAwB;IAAG,CAAC;IAEpD,WAAW,CAAC,QAA2B;QACrC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,KA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C,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,SAAS,CAAC,MAAiC;IAClD,OAAO,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;AACxD,CAAC"}
|
package/dist/render-pass.d.ts
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { Buffer, type Device, type Texture } from "@vgpu/core";
|
|
2
2
|
export interface RenderPassOptions {
|
|
3
3
|
readonly colorAttachments: readonly ColorAttachment[];
|
|
4
|
+
readonly depthStencilAttachment?: DepthStencilAttachment;
|
|
4
5
|
readonly label?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface ColorAttachment {
|
|
7
8
|
readonly view: Texture | GPUTextureView;
|
|
8
9
|
readonly loadOp: GPULoadOp;
|
|
9
10
|
readonly storeOp: GPUStoreOp;
|
|
10
|
-
readonly clearValue?:
|
|
11
|
+
readonly clearValue?: GPUColor;
|
|
12
|
+
}
|
|
13
|
+
export interface DepthStencilAttachment {
|
|
14
|
+
readonly view: Texture | GPUTextureView;
|
|
15
|
+
readonly depthClearValue?: number;
|
|
16
|
+
readonly depthLoadOp?: GPULoadOp;
|
|
17
|
+
readonly depthStoreOp?: GPUStoreOp;
|
|
18
|
+
readonly depthReadOnly?: boolean;
|
|
19
|
+
readonly stencilClearValue?: GPUStencilValue;
|
|
20
|
+
readonly stencilLoadOp?: GPULoadOp;
|
|
21
|
+
readonly stencilStoreOp?: GPUStoreOp;
|
|
22
|
+
readonly stencilReadOnly?: boolean;
|
|
11
23
|
}
|
|
12
24
|
export interface RenderPassDrawOptions {
|
|
13
25
|
readonly vertexCount: number;
|
|
@@ -19,15 +31,18 @@ export type RenderPassDynamicOffsets = readonly GPUBufferDynamicOffset[] | Uint3
|
|
|
19
31
|
export declare class RenderPass {
|
|
20
32
|
private readonly device;
|
|
21
33
|
private readonly encoder;
|
|
34
|
+
private readonly submitOnEnd;
|
|
22
35
|
private passEncoder;
|
|
23
36
|
constructor(device: Device, opts: RenderPassOptions);
|
|
24
37
|
get gpu(): GPURenderPassEncoder;
|
|
25
38
|
setPipeline(pipeline: GPURenderPipeline): void;
|
|
26
39
|
setBindGroup(index: number, group: GPUBindGroup | null, dynamicOffsets?: RenderPassDynamicOffsets): void;
|
|
27
40
|
setVertexBuffer(slot: number, buffer: Buffer | GPUBuffer | null, offset?: number, size?: GPUSize64): void;
|
|
41
|
+
executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
28
42
|
draw(options: RenderPassDrawOptions): void;
|
|
29
43
|
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
30
44
|
end(): void;
|
|
31
45
|
dispose(): void;
|
|
32
46
|
}
|
|
47
|
+
export declare function createRenderPassOnEncoder(device: Device, opts: RenderPassOptions, encoder: GPUCommandEncoder): RenderPass;
|
|
33
48
|
//# sourceMappingURL=render-pass.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-pass.d.ts","sourceRoot":"","sources":["../src/render-pass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAI1E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,eAAe,EAAE,CAAC;IACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"render-pass.d.ts","sourceRoot":"","sources":["../src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|
3
|
+
const renderPassEncoderSources = new WeakMap();
|
|
3
4
|
export class RenderPass {
|
|
4
5
|
device;
|
|
5
6
|
encoder;
|
|
7
|
+
submitOnEnd;
|
|
6
8
|
passEncoder;
|
|
7
9
|
constructor(device, opts) {
|
|
8
10
|
this.device = device;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const source = renderPassEncoderSources.get(opts);
|
|
12
|
+
renderPassEncoderSources.delete(opts);
|
|
13
|
+
this.encoder = source?.encoder ?? device.gpu.createCommandEncoder({ label: opts.label });
|
|
14
|
+
this.submitOnEnd = source?.submitOnEnd ?? true;
|
|
15
|
+
this.passEncoder = this.encoder.beginRenderPass(renderPassDescriptor(opts));
|
|
14
16
|
}
|
|
15
17
|
get gpu() {
|
|
16
18
|
if (!this.passEncoder) {
|
|
@@ -26,11 +28,18 @@ export class RenderPass {
|
|
|
26
28
|
this.gpu.setPipeline(pipeline);
|
|
27
29
|
}
|
|
28
30
|
setBindGroup(index, group, dynamicOffsets) {
|
|
31
|
+
if (dynamicOffsets === undefined) {
|
|
32
|
+
this.gpu.setBindGroup(index, group);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
29
35
|
this.gpu.setBindGroup(index, group, dynamicOffsets);
|
|
30
36
|
}
|
|
31
37
|
setVertexBuffer(slot, buffer, offset = 0, size) {
|
|
32
38
|
this.gpu.setVertexBuffer(slot, gpuBuffer(buffer), offset, size);
|
|
33
39
|
}
|
|
40
|
+
executeBundles(bundles) {
|
|
41
|
+
this.gpu.executeBundles(bundles);
|
|
42
|
+
}
|
|
34
43
|
draw(optionsOrVertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) {
|
|
35
44
|
if (typeof optionsOrVertexCount === "number") {
|
|
36
45
|
this.gpu.draw(optionsOrVertexCount, instanceCount, firstVertex, firstInstance);
|
|
@@ -44,20 +53,48 @@ export class RenderPass {
|
|
|
44
53
|
const pass = this.passEncoder;
|
|
45
54
|
this.passEncoder = null;
|
|
46
55
|
pass.end();
|
|
47
|
-
|
|
56
|
+
if (this.submitOnEnd)
|
|
57
|
+
this.device.queue.gpu.submit([this.encoder.finish()]);
|
|
48
58
|
}
|
|
49
59
|
dispose() {
|
|
50
60
|
this.end();
|
|
51
61
|
}
|
|
52
62
|
}
|
|
63
|
+
export function createRenderPassOnEncoder(device, opts, encoder) {
|
|
64
|
+
renderPassEncoderSources.set(opts, { encoder, submitOnEnd: false });
|
|
65
|
+
return new RenderPass(device, opts);
|
|
66
|
+
}
|
|
67
|
+
function renderPassDescriptor(opts) {
|
|
68
|
+
return {
|
|
69
|
+
label: opts.label,
|
|
70
|
+
colorAttachments: opts.colorAttachments.map(colorAttachment),
|
|
71
|
+
depthStencilAttachment: opts.depthStencilAttachment ? depthStencilAttachment(opts.depthStencilAttachment) : undefined,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
53
74
|
function colorAttachment(attachment) {
|
|
54
75
|
return {
|
|
55
|
-
view:
|
|
76
|
+
view: textureView(attachment.view),
|
|
56
77
|
loadOp: attachment.loadOp,
|
|
57
78
|
storeOp: attachment.storeOp,
|
|
58
79
|
clearValue: attachment.clearValue,
|
|
59
80
|
};
|
|
60
81
|
}
|
|
82
|
+
function depthStencilAttachment(attachment) {
|
|
83
|
+
return {
|
|
84
|
+
view: textureView(attachment.view),
|
|
85
|
+
depthClearValue: attachment.depthClearValue,
|
|
86
|
+
depthLoadOp: attachment.depthLoadOp,
|
|
87
|
+
depthStoreOp: attachment.depthStoreOp,
|
|
88
|
+
depthReadOnly: attachment.depthReadOnly,
|
|
89
|
+
stencilClearValue: attachment.stencilClearValue,
|
|
90
|
+
stencilLoadOp: attachment.stencilLoadOp,
|
|
91
|
+
stencilStoreOp: attachment.stencilStoreOp,
|
|
92
|
+
stencilReadOnly: attachment.stencilReadOnly,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function textureView(view) {
|
|
96
|
+
return isVGPUTexture(view) ? view.createView() : view;
|
|
97
|
+
}
|
|
61
98
|
function gpuBuffer(buffer) {
|
|
62
99
|
return buffer instanceof Buffer ? buffer.gpu : buffer;
|
|
63
100
|
}
|
package/dist/render-pass.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-pass.js","sourceRoot":"","sources":["../src/render-pass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAA6B,MAAM,YAAY,CAAC;AAE1E,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"render-pass.js","sourceRoot":"","sources":["../src/render-pass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAA6B,MAAM,YAAY,CAAC;AAE1E,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAyChD,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAA8C,CAAC;AAE3F,MAAM,OAAO,UAAU;IAKQ;IAJZ,OAAO,CAAoB;IAC3B,WAAW,CAAU;IAC9B,WAAW,CAA8B;IAEjD,YAA6B,MAAc,EAAE,IAAuB;QAAvC,WAAM,GAAN,MAAM,CAAQ;QACzC,MAAM,MAAM,GAAG,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClD,wBAAwB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QACzF,IAAI,CAAC,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,IAAI,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,GA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,CAAC,MAAM;QACzB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,UAAU,EAAE,UAAU,CAAC,UAAU;KAClC,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,UAAkC;IAChE,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC;QAClC,eAAe,EAAE,UAAU,CAAC,eAAe;QAC3C,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,YAAY,EAAE,UAAU,CAAC,YAAY;QACrC,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,iBAAiB,EAAE,UAAU,CAAC,iBAAiB;QAC/C,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,eAAe,EAAE,UAAU,CAAC,eAAe;KAC5C,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,IAA8B;IACjD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AAED,SAAS,SAAS,CAAC,MAAiC;IAClD,OAAO,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;AACxD,CAAC;AAED,SAAS,aAAa,CAAC,IAA8B;IACnD,OAAO,OAAO,CAAE,IAA2C,CAAC,YAAY,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Buffer, type Device } from "@vgpu/core";
|
|
2
|
+
export interface StorageBufferOptions {
|
|
3
|
+
/** Byte size of the storage buffer. Must be a positive number. Storage buffers may be far larger than uniforms (up to the adapter's `maxStorageBufferBindingSize`, typically 128 MiB). */
|
|
4
|
+
readonly size: number;
|
|
5
|
+
/** Optional debug label forwarded to the buffer, bind group layout, and bind group. */
|
|
6
|
+
readonly label?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the shader only reads the buffer (`"read"`, the default → `var<storage, read>`)
|
|
9
|
+
* or also writes it (`"read-write"` → `var<storage, read_write>`). This selects the
|
|
10
|
+
* bind group layout entry type (`"read-only-storage"` vs `"storage"`) and changes the
|
|
11
|
+
* default {@link StorageBufferOptions.visibility}.
|
|
12
|
+
*/
|
|
13
|
+
readonly access?: "read" | "read-write";
|
|
14
|
+
/**
|
|
15
|
+
* Shader stages that access binding 0. Defaults to `FRAGMENT | COMPUTE` for both access modes —
|
|
16
|
+
* no `VERTEX`. Read-write storage is forbidden in the vertex stage; read-only storage is allowed
|
|
17
|
+
* there but `maxStorageBuffersInVertexStage` is 0 on many adapters (software/CI Vulkan, some
|
|
18
|
+
* mobile GPUs), so vertex-stage storage is opt-in: pass `visibility` explicitly and raise that
|
|
19
|
+
* limit via `requiredLimits`. Ignored when {@link StorageBufferOptions.bindGroupLayout} is provided.
|
|
20
|
+
*/
|
|
21
|
+
readonly visibility?: GPUShaderStageFlags;
|
|
22
|
+
/**
|
|
23
|
+
* Reuse a pipeline-owned bind group layout instead of creating one.
|
|
24
|
+
* The layout's binding 0 must be a storage buffer compatible with `size` and `access`.
|
|
25
|
+
*/
|
|
26
|
+
readonly bindGroupLayout?: GPUBindGroupLayout;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A single stable storage buffer for one render (or compute) pass, rewritten as needed.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* `StorageBuffer` is the storage-buffer counterpart to {@link Uniform}. Reach for it when
|
|
33
|
+
* the data is too large or too dynamic for a uniform: arrays, runtime-sized data, particle
|
|
34
|
+
* state, lookup tables. Storage buffers can be much bigger than uniforms (up to the adapter's
|
|
35
|
+
* `maxStorageBufferBindingSize`, typically 128 MiB, versus a uniform's 64 KiB) and can be
|
|
36
|
+
* written by the shader when `access: "read-write"`.
|
|
37
|
+
*
|
|
38
|
+
* Like `Uniform`, it owns exactly one buffer at binding 0 with a fixed (non-dynamic) offset,
|
|
39
|
+
* and the caller decides when to {@link StorageBuffer.write}. Unlike {@link UniformPool} — a
|
|
40
|
+
* dynamic-offset ring allocator for many small per-draw uniforms — there is no dynamic offset
|
|
41
|
+
* and the bind group never moves.
|
|
42
|
+
*
|
|
43
|
+
* `access` controls the layout entry type; both modes default to `FRAGMENT | COMPUTE` visibility:
|
|
44
|
+
* - `"read"` (default) → `var<storage, read>`, layout type `"read-only-storage"`.
|
|
45
|
+
* - `"read-write"` → `var<storage, read_write>`, layout type `"storage"`.
|
|
46
|
+
* Neither default includes `VERTEX`: read-write storage is forbidden in the vertex stage, and
|
|
47
|
+
* read-only storage — though legal there — needs `maxStorageBuffersInVertexStage > 0`, which is 0
|
|
48
|
+
* on many adapters (software/CI Vulkan, some mobile GPUs). For vertex-stage read-only storage, pass
|
|
49
|
+
* `visibility: VERTEX | …` explicitly and raise the limit via `requiredLimits`; do not rely on the default.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // A read-only array the fragment shader samples (var<storage, read> values: array<f32>):
|
|
54
|
+
* const storage = new StorageBuffer(device, { size: 4 * count, label: "values" });
|
|
55
|
+
* storage.write(new Float32Array(values));
|
|
56
|
+
* pass.setBindGroup(0, storage.bindGroup);
|
|
57
|
+
*
|
|
58
|
+
* // A compute-written scratch buffer (var<storage, read_write> out: array<u32>):
|
|
59
|
+
* const scratch = new StorageBuffer(device, { size: 4 * count, access: "read-write" });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class StorageBuffer {
|
|
63
|
+
readonly device: Device;
|
|
64
|
+
readonly size: number;
|
|
65
|
+
readonly access: "read" | "read-write";
|
|
66
|
+
readonly buffer: Buffer;
|
|
67
|
+
readonly bindGroupLayout: GPUBindGroupLayout;
|
|
68
|
+
readonly bindGroup: GPUBindGroup;
|
|
69
|
+
private destroyed;
|
|
70
|
+
constructor(device: Device, opts: StorageBufferOptions);
|
|
71
|
+
/** The underlying storage `GPUBuffer`. */
|
|
72
|
+
get gpu(): GPUBuffer;
|
|
73
|
+
/**
|
|
74
|
+
* Upload `data` to the buffer via `queue.writeBuffer`. No dynamic offset; the
|
|
75
|
+
* bind group is unchanged. Call only when the contents actually change.
|
|
76
|
+
*/
|
|
77
|
+
write(data: BufferSource, offset?: number): void;
|
|
78
|
+
destroy(): void;
|
|
79
|
+
dispose(): void;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=storage-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-buffer.d.ts","sourceRoot":"","sources":["../src/storage-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAA0C,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAE/F,MAAM,WAAW,oBAAoB;IACnC,0LAA0L;IAC1L,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACxC;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,CAAC;IAC1C;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,kBAAkB,CAAC;CAC/C;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,aAAa;IAQZ,QAAQ,CAAC,MAAM,EAAE,MAAM;IAPnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC;IAC7C,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,OAAO,CAAC,SAAS,CAAS;gBAEL,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB;IAmB/D,0CAA0C;IAC1C,IAAI,GAAG,IAAI,SAAS,CAEnB;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,SAAI,GAAG,IAAI;IAI3C,OAAO,IAAI,IAAI;IAMf,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { bind, createBindGroup, createBindGroupLayout } from "@vgpu/core";
|
|
2
|
+
// Both access modes default to FRAGMENT | COMPUTE (no VERTEX):
|
|
3
|
+
// - read-write storage is ILLEGAL in the vertex stage (WebGPU forbids it).
|
|
4
|
+
// - read-only storage IS legal in vertex, but maxStorageBuffersInVertexStage is 0 on many adapters
|
|
5
|
+
// (software/CI Vulkan, some mobile GPUs), so a VERTEX-visible default would silently invalidate
|
|
6
|
+
// the layout there (the draw no-ops). Vertex-stage read-only storage is opt-in: pass `visibility`
|
|
7
|
+
// explicitly AND raise the limit via requiredLimits when requesting the device.
|
|
8
|
+
const defaultVisibility = ((globalThis.GPUShaderStage?.FRAGMENT ?? 2) | (globalThis.GPUShaderStage?.COMPUTE ?? 4));
|
|
9
|
+
/**
|
|
10
|
+
* A single stable storage buffer for one render (or compute) pass, rewritten as needed.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* `StorageBuffer` is the storage-buffer counterpart to {@link Uniform}. Reach for it when
|
|
14
|
+
* the data is too large or too dynamic for a uniform: arrays, runtime-sized data, particle
|
|
15
|
+
* state, lookup tables. Storage buffers can be much bigger than uniforms (up to the adapter's
|
|
16
|
+
* `maxStorageBufferBindingSize`, typically 128 MiB, versus a uniform's 64 KiB) and can be
|
|
17
|
+
* written by the shader when `access: "read-write"`.
|
|
18
|
+
*
|
|
19
|
+
* Like `Uniform`, it owns exactly one buffer at binding 0 with a fixed (non-dynamic) offset,
|
|
20
|
+
* and the caller decides when to {@link StorageBuffer.write}. Unlike {@link UniformPool} — a
|
|
21
|
+
* dynamic-offset ring allocator for many small per-draw uniforms — there is no dynamic offset
|
|
22
|
+
* and the bind group never moves.
|
|
23
|
+
*
|
|
24
|
+
* `access` controls the layout entry type; both modes default to `FRAGMENT | COMPUTE` visibility:
|
|
25
|
+
* - `"read"` (default) → `var<storage, read>`, layout type `"read-only-storage"`.
|
|
26
|
+
* - `"read-write"` → `var<storage, read_write>`, layout type `"storage"`.
|
|
27
|
+
* Neither default includes `VERTEX`: read-write storage is forbidden in the vertex stage, and
|
|
28
|
+
* read-only storage — though legal there — needs `maxStorageBuffersInVertexStage > 0`, which is 0
|
|
29
|
+
* on many adapters (software/CI Vulkan, some mobile GPUs). For vertex-stage read-only storage, pass
|
|
30
|
+
* `visibility: VERTEX | …` explicitly and raise the limit via `requiredLimits`; do not rely on the default.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // A read-only array the fragment shader samples (var<storage, read> values: array<f32>):
|
|
35
|
+
* const storage = new StorageBuffer(device, { size: 4 * count, label: "values" });
|
|
36
|
+
* storage.write(new Float32Array(values));
|
|
37
|
+
* pass.setBindGroup(0, storage.bindGroup);
|
|
38
|
+
*
|
|
39
|
+
* // A compute-written scratch buffer (var<storage, read_write> out: array<u32>):
|
|
40
|
+
* const scratch = new StorageBuffer(device, { size: 4 * count, access: "read-write" });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export class StorageBuffer {
|
|
44
|
+
device;
|
|
45
|
+
size;
|
|
46
|
+
access;
|
|
47
|
+
buffer;
|
|
48
|
+
bindGroupLayout;
|
|
49
|
+
bindGroup;
|
|
50
|
+
destroyed = false;
|
|
51
|
+
constructor(device, opts) {
|
|
52
|
+
this.device = device;
|
|
53
|
+
this.size = opts.size;
|
|
54
|
+
this.access = opts.access ?? "read";
|
|
55
|
+
this.buffer = device.createBuffer({ size: opts.size, usage: ["storage", "copy_dst"], label: opts.label });
|
|
56
|
+
const visibility = opts.visibility ?? defaultVisibility;
|
|
57
|
+
const entry = this.access === "read-write"
|
|
58
|
+
? bind.storage(0, visibility, { minBindingSize: opts.size })
|
|
59
|
+
: bind.readonlyStorage(0, visibility, { minBindingSize: opts.size });
|
|
60
|
+
this.bindGroupLayout = opts.bindGroupLayout ?? createBindGroupLayout(device, {
|
|
61
|
+
label: opts.label ? `${opts.label}.bgl` : undefined,
|
|
62
|
+
entries: [entry],
|
|
63
|
+
});
|
|
64
|
+
this.bindGroup = createBindGroup(device, {
|
|
65
|
+
label: opts.label ? `${opts.label}.bg` : undefined,
|
|
66
|
+
layout: this.bindGroupLayout,
|
|
67
|
+
entries: [bind.resource(0, this.buffer)],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** The underlying storage `GPUBuffer`. */
|
|
71
|
+
get gpu() {
|
|
72
|
+
return this.buffer.gpu;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Upload `data` to the buffer via `queue.writeBuffer`. No dynamic offset; the
|
|
76
|
+
* bind group is unchanged. Call only when the contents actually change.
|
|
77
|
+
*/
|
|
78
|
+
write(data, offset = 0) {
|
|
79
|
+
this.buffer.write(data, offset);
|
|
80
|
+
}
|
|
81
|
+
destroy() {
|
|
82
|
+
if (this.destroyed)
|
|
83
|
+
return;
|
|
84
|
+
this.destroyed = true;
|
|
85
|
+
this.buffer.destroy();
|
|
86
|
+
}
|
|
87
|
+
dispose() {
|
|
88
|
+
this.destroy();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=storage-buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-buffer.js","sourceRoot":"","sources":["../src/storage-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,eAAe,EAAE,qBAAqB,EAAe,MAAM,YAAY,CAAC;AA6B/F,+DAA+D;AAC/D,2EAA2E;AAC3E,mGAAmG;AACnG,kGAAkG;AAClG,oGAAoG;AACpG,kFAAkF;AA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