()
| 460 | } |
| 461 | |
| 462 | async _initContext() { |
| 463 | this.adapter = await navigator.gpu?.requestAdapter(this._webgpuAttributes); |
| 464 | this.device = await this.adapter?.requestDevice({ |
| 465 | // Todo: check support |
| 466 | requiredFeatures: ['depth32float-stencil8'] |
| 467 | }); |
| 468 | if (!this.device) { |
| 469 | throw new Error('Your browser does not support WebGPU.'); |
| 470 | } |
| 471 | this.queue = this.device.queue; |
| 472 | this.drawingContext = this.canvas.getContext('webgpu'); |
| 473 | this.presentationFormat = navigator.gpu.getPreferredCanvasFormat(); |
| 474 | this.drawingContext.configure({ |
| 475 | device: this.device, |
| 476 | format: this.presentationFormat, |
| 477 | usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, |
| 478 | alphaMode: 'premultiplied', |
| 479 | }); |
| 480 | |
| 481 | // TODO disablable stencil |
| 482 | this.mainFramebuffer = this.createFramebuffer({ _useCanvasFormat: true }); |
| 483 | this._updateSize(); |
| 484 | this._update(); |
| 485 | this.flushDraw(); |
| 486 | } |
| 487 | |
| 488 | async _setAttributes(key, value) { |
| 489 | if (typeof this._pInst._webgpuAttributes === "undefined") { |
no test coverage detected