mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-16 21:39:29 -07:00
Created a pass-through post processing compute pass. The other post-processing passes will be changed over to this kind of thing.
makePassFBO has now been split into makeRenderTarget and makeComputeTarget.
This commit is contained in:
52
js/webgpu/postProcessingPass.js
Normal file
52
js/webgpu/postProcessingPass.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import { structs, byteSizeOf } from "/lib/gpu-buffer.js";
|
||||
import { makeComputeTarget, loadShader, makeUniformBuffer, makeBindGroup, makePass } from "./utils.js";
|
||||
|
||||
export default (context, getInputs) => {
|
||||
const { config, device, timeBuffer } = context;
|
||||
|
||||
const assets = [loadShader(device, "shaders/wgsl/postProcessingPass.wgsl")];
|
||||
|
||||
let configBuffer;
|
||||
let computePipeline;
|
||||
let output;
|
||||
let screenSize;
|
||||
|
||||
const getOutputs = () => ({
|
||||
primary: output,
|
||||
});
|
||||
|
||||
const ready = (async () => {
|
||||
const [postProcessingShader] = await Promise.all(assets);
|
||||
|
||||
computePipeline = device.createComputePipeline({
|
||||
compute: {
|
||||
module: postProcessingShader.module,
|
||||
entryPoint: "computeMain",
|
||||
},
|
||||
});
|
||||
|
||||
const configUniforms = structs.from(postProcessingShader.code).Config;
|
||||
configBuffer = makeUniformBuffer(device, configUniforms, {
|
||||
/* TODO */
|
||||
});
|
||||
})();
|
||||
|
||||
const setSize = (width, height) => {
|
||||
output?.destroy();
|
||||
output = makeComputeTarget(device, width, height);
|
||||
screenSize = [width, height];
|
||||
};
|
||||
|
||||
const execute = (encoder) => {
|
||||
const inputs = getInputs();
|
||||
const tex = inputs.primary;
|
||||
const computePass = encoder.beginComputePass();
|
||||
computePass.setPipeline(computePipeline);
|
||||
const computeBindGroup = makeBindGroup(device, computePipeline, 0, [configBuffer, timeBuffer, tex.createView(), output.createView()]);
|
||||
computePass.setBindGroup(0, computeBindGroup);
|
||||
computePass.dispatch(Math.ceil(screenSize[0] / 32), screenSize[1], 1);
|
||||
computePass.endPass();
|
||||
};
|
||||
|
||||
return makePass(getOutputs, ready, setSize, execute);
|
||||
};
|
||||
Reference in New Issue
Block a user