Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions sample/helloTriangleMSAA/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GUI } from 'dat.gui';
import triangleVertWGSL from '../../shaders/triangle.vert.wgsl';
import redFragWGSL from '../../shaders/red.frag.wgsl';
import { quitIfWebGPUNotAvailable } from '../util';
Expand All @@ -9,6 +10,12 @@ const adapter = await navigator.gpu?.requestAdapter({
const device = await adapter?.requestDevice();
quitIfWebGPUNotAvailable(adapter, device);

const settings = { transientAttachment: false };
if ('TRANSIENT_ATTACHMENT' in GPUTextureUsage) {
const gui = new GUI();
gui.add(settings, 'transientAttachment');
}

const context = canvas.getContext('webgpu');

const devicePixelRatio = window.devicePixelRatio;
Expand Down Expand Up @@ -48,15 +55,20 @@ const pipeline = device.createRenderPipeline({
},
});

const texture = device.createTexture({
size: [canvas.width, canvas.height],
sampleCount,
format: presentationFormat,
usage: GPUTextureUsage.RENDER_ATTACHMENT,
});
const view = texture.createView();

function frame() {
let usage = GPUTextureUsage.RENDER_ATTACHMENT;
if (settings.transientAttachment) {
usage |= GPUTextureUsage.TRANSIENT_ATTACHMENT;
}

const texture = device.createTexture({
size: [canvas.width, canvas.height],
sampleCount,
format: presentationFormat,
usage,
});
const view = texture.createView();

const commandEncoder = device.createCommandEncoder();

const renderPassDescriptor: GPURenderPassDescriptor = {
Expand Down