@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
78 lines (77 loc) • 2.27 kB
JavaScript
import { assertFloatRenderableFormat, assertFloatSampledFormat } from "../core/format-capabilities.js";
import { builtInRenderPassBrand } from "../core/pass-brand.js";
import { BlitPass } from "./BlitPass.js";
//#region src/lib/passes/CopyPass.ts
/**
* Texture copy pass with fullscreen-blit fallback.
*/
var CopyPass = class {
[builtInRenderPassBrand] = Object.freeze({
passName: "CopyPass",
input: "float-sampled",
output: "float-renderable"
});
enabled;
needsSwap;
input;
output;
clear;
clearColor;
preserve;
fallbackBlit;
constructor(options = {}) {
this.enabled = options.enabled ?? true;
this.needsSwap = options.needsSwap ?? true;
this.input = options.input ?? "source";
this.output = options.output ?? (this.needsSwap ? "target" : "source");
this.clear = options.clear ?? false;
this.clearColor = options.clearColor ?? [
0,
0,
0,
1
];
this.preserve = options.preserve ?? true;
this.fallbackBlit = new BlitPass({
enabled: true,
needsSwap: false,
input: this.input,
output: this.output,
...options.filter !== void 0 ? { filter: options.filter } : {}
});
}
setSize(width, height) {
this.fallbackBlit.setSize(width, height);
}
render(context) {
assertFloatSampledFormat({
format: context.input.format,
target: String(this.input),
pass: "CopyPass",
deviceFeatures: context.device.features
});
assertFloatRenderableFormat({
format: context.output.format,
target: String(this.output),
pass: "CopyPass",
deviceFeatures: context.device.features
});
const source = context.input;
const target = context.output;
if (context.clear === false && context.preserve === true && source.texture !== target.texture && source.texture !== context.canvas.texture && target.texture !== context.canvas.texture && source.width === target.width && source.height === target.height && source.format === target.format) {
context.commandEncoder.copyTextureToTexture({ texture: source.texture }, { texture: target.texture }, {
width: source.width,
height: source.height,
depthOrArrayLayers: 1
});
return;
}
this.fallbackBlit.render(context);
}
dispose() {
this.fallbackBlit.dispose();
}
};
//#endregion
export { CopyPass };
//# sourceMappingURL=CopyPass.js.map