You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// https://deno.com/blog/v1.40#webgpu-windowing--bring-your-own-windowimport{EventType,WindowBuilder,getKeyName}from"jsr:@divy/[email protected]";constwidth=800;constheight=600;constwin=newWindowBuilder("Hello, World!",width,height).build();constadapter=awaitnavigator.gpu.requestAdapter();if(!adapter){console.error("WebGPU not supported!");Deno.exit(1);}constdevice=awaitadapter.requestDevice();/* Returns a Deno.UnsafeWindowSurface */letsurface=win.windowSurface();/* Returns a WebGPU GPUCanvasContext */constcontext=surface.getContext("webgpu");context.configure({
device,format: navigator.gpu.getPreferredCanvasFormat(),
width,
height,});constSDL_WINDOWEVENT_RESIZED=5;forawait(consteventofwin.events()){// console.log("get event ", event);if(event.type===EventType.Quit)break;elseif(event.type===EventType.KeyDown){// console.log(`key down `, getKeyName(event.keysym.sym))if(getKeyName(event.keysym.sym)==="Escape"){break;}continue;}elseif(event.type===EventType.WindowEvent){switch(event.event){caseSDL_WINDOWEVENT_RESIZED:
console.info("resized!")surface=win.windowSurface();continue;}}elseif(event.type!==EventType.Draw)continue;// Sine waveconstr=Math.sin(Date.now()/1000)/2+0.5;constg=Math.sin(Date.now()/1000+2)/2+0.5;constb=Math.sin(Date.now()/1000+4)/2+0.5;constencode=(textureView: GPUTextureView)=>{constcommandEncoder=device.createCommandEncoder();constpassEncoder=commandEncoder.beginRenderPass({colorAttachments: [{view: textureView,clearValue: { r, g, b,a: 1.0},loadOp: "clear",storeOp: "store",},],});passEncoder.end();returncommandEncoder.finish();};// this would cause to freeze when calling `surface.present()`{device.queue.submit([encode(context.getCurrentTexture().createView())]);device.queue.submit([encode(context.getCurrentTexture().createView())]);}// this would also cause to freeze// {// const cmbBuffers = [];// cmbBuffers.push(encode(context.getCurrentTexture().createView()));// cmbBuffers.push(encode(context.getCurrentTexture().createView()));// device.queue.submit(cmbBuffers);// }// this would not cause to freeze// {// const cmbBuffers = [];// cmbBuffers.push(encode(context.getCurrentTexture().createView()));// encode(context.getCurrentTexture().createView());// device.queue.submit(cmbBuffers);// }surface.present();}
The text was updated successfully, but these errors were encountered:
deno --version
:Platform: ArchLinux, KDE Plasma 6, wayland
Example code:
The text was updated successfully, but these errors were encountered: