Skip to content
Merged
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
44 changes: 30 additions & 14 deletions sample/helloTriangleMSAA/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,42 @@ const pipeline = device.createRenderPipeline({
},
});

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 getMSAATempTextureView = (() => {
let texture: GPUTexture | undefined;
let view: GPUTextureView | undefined;
return () => {
let usage = GPUTextureUsage.RENDER_ATTACHMENT;
if (settings.transientAttachment) {
usage |= GPUTextureUsage.TRANSIENT_ATTACHMENT;
}

if (texture?.usage !== usage) {
console.log(`Reallocating with usage ${usage}`);

if (texture) {
texture.destroy();
}

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

return view!;
};
})();

function frame() {
const commandEncoder = device.createCommandEncoder();

const renderPassDescriptor: GPURenderPassDescriptor = {
colorAttachments: [
{
view,
view: getMSAATempTextureView(),
resolveTarget: context.getCurrentTexture().createView(),
clearValue: [0, 0, 0, 0], // Clear to transparent
loadOp: 'clear',
Expand Down
Loading