MCPcopy Index your code
hub / github.com/apache/tvm / draw

Method draw

web/src/webgpu.ts:344–392  ·  view source on GitHub ↗
(buffer: GPUBuffer, height: number, width: number)

Source from the content-addressed store, hash-verified

342 }
343
344 draw(buffer: GPUBuffer, height: number, width: number) {
345 // resize the staging texture
346 if (height != this.stagingTexture.height || width != this.stagingTexture.width) {
347 this.stagingTexture.destroy();
348 this.stagingTexture = this.device.createTexture({
349 size: [height, width, 1],
350 format: "rgba8unorm",
351 usage:
352 GPUTextureUsage.TEXTURE_BINDING |
353 GPUTextureUsage.COPY_DST |
354 GPUTextureUsage.RENDER_ATTACHMENT,
355 });
356 }
357
358 const commandEncoder = this.device.createCommandEncoder();
359 commandEncoder.copyBufferToTexture({
360 buffer: buffer,
361 offset: 0,
362 bytesPerRow: this.stagingTexture.width * 4
363 }, {
364 texture: this.stagingTexture
365 }, {
366 width: this.stagingTexture.width,
367 height: this.stagingTexture.height
368 });
369
370 const passEncoder = commandEncoder.beginRenderPass({
371 colorAttachments: [
372 {
373 view: this.canvasContext.getCurrentTexture().createView(),
374 clearValue: { r: 0.0, g: 0.0, b: 0.0, a: 1.0 },
375 loadOp: "clear",
376 storeOp: "store",
377 },
378 ],
379 });
380 passEncoder.setPipeline(this.renderPipeline);
381 const renderBindingGroup = this.device.createBindGroup({
382 layout: this.renderPipeline.getBindGroupLayout(0),
383 entries: [
384 { binding: 0, resource: this.renderSampler },
385 { binding: 1, resource: this.stagingTexture.createView() },
386 ],
387 });
388 passEncoder.setBindGroup(0, renderBindingGroup);
389 passEncoder.draw(6, 1, 0, 0);
390 passEncoder.end();
391 this.device.queue.submit([commandEncoder.finish()]);
392 }
393
394 dispose(): void {
395 this.stagingTexture.destroy();

Callers 2

clearMethod · 0.80
drawImageFromBufferMethod · 0.80

Calls 3

endMethod · 0.80
submitMethod · 0.80
finishMethod · 0.80

Tested by

no test coverage detected