-
Couldn't load subscription status.
- Fork 344
Update samples to work with TypeScript strict mode (part 2) #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
217e5fd
593c7d4
ab3f4e4
7cb5518
229ee58
e4fd662
12e1d0d
fad1617
06c3cc8
c1b5a89
c85c030
41d5064
bd44d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,20 +11,22 @@ import Radiosity from './radiosity'; | |
| import Rasterizer from './rasterizer'; | ||
| import Tonemapper from './tonemapper'; | ||
| import Raytracer from './raytracer'; | ||
| import { assert } from '../../components/SampleLayout'; | ||
|
|
||
| const init: SampleInit = async ({ canvas, pageState, gui }) => { | ||
| const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); | ||
| const requiredFeatures: GPUFeatureName[] = | ||
| presentationFormat === 'bgra8unorm' ? ['bgra8unorm-storage'] : []; | ||
| const adapter = await navigator.gpu.requestAdapter(); | ||
| for (const feature of requiredFeatures) { | ||
| if (!adapter.features.has(feature)) { | ||
| if (!adapter?.features.has(feature)) { | ||
| throw new Error( | ||
| `sample requires ${feature}, but is not supported by the adapter` | ||
| ); | ||
| } | ||
| } | ||
| const device = await adapter.requestDevice({ requiredFeatures }); | ||
| const device = await adapter?.requestDevice({ requiredFeatures }); | ||
| assert(device, 'device is null'); | ||
nash1111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!pageState.active) return; | ||
|
|
||
|
|
@@ -36,8 +38,8 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => { | |
| rotateCamera: true, | ||
| }; | ||
|
|
||
| gui.add(params, 'renderer', ['rasterizer', 'raytracer']); | ||
| gui.add(params, 'rotateCamera', true); | ||
| gui?.add(params, 'renderer', ['rasterizer', 'raytracer']); | ||
| gui?.add(params, 'rotateCamera', true); | ||
|
||
|
|
||
| const devicePixelRatio = window.devicePixelRatio || 1; | ||
| canvas.width = canvas.clientWidth * devicePixelRatio; | ||
|
|
@@ -80,7 +82,9 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => { | |
| } | ||
|
|
||
| const canvasTexture = context.getCurrentTexture(); | ||
| const commandEncoder = device.createCommandEncoder(); | ||
| const commandEncoder = device?.createCommandEncoder(); | ||
| assert(commandEncoder, 'commandEncoder is null'); | ||
| assert(device, 'device is null'); | ||
nash1111 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| common.update({ | ||
| rotateCamera: params.rotateCamera, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { mat4, vec3 } from 'wgpu-matrix'; | ||
| import { makeSample, SampleInit } from '../../components/SampleLayout'; | ||
| import { assert, makeSample, SampleInit } from '../../components/SampleLayout'; | ||
|
|
||
| import { | ||
| cubeVertexArray, | ||
|
|
@@ -14,7 +14,8 @@ import sampleCubemapWGSL from './sampleCubemap.frag.wgsl'; | |
|
|
||
| const init: SampleInit = async ({ canvas, pageState }) => { | ||
| const adapter = await navigator.gpu.requestAdapter(); | ||
| const device = await adapter.requestDevice(); | ||
| const device = await adapter?.requestDevice(); | ||
| assert(device, 'device is null'); | ||
|
|
||
| if (!pageState.active) return; | ||
| const context = canvas.getContext('webgpu') as GPUCanvasContext; | ||
|
|
@@ -198,7 +199,7 @@ const init: SampleInit = async ({ canvas, pageState }) => { | |
| const renderPassDescriptor: GPURenderPassDescriptor = { | ||
| colorAttachments: [ | ||
| { | ||
| view: undefined, // Assigned later | ||
| view: undefined as any, // Assigned later | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (In response to the GitHub Actions check warning) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kainino0x |
||
| loadOp: 'clear', | ||
| storeOp: 'store', | ||
| }, | ||
|
|
@@ -245,6 +246,7 @@ const init: SampleInit = async ({ canvas, pageState }) => { | |
| function frame() { | ||
| // Sample is no longer the active page. | ||
| if (!pageState.active) return; | ||
| assert(device, 'device is null'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly shouldn't be necessary, though I'm less certain about this since it's inside a function. OK to keep if needed. |
||
|
|
||
| updateTransformationMatrix(); | ||
| device.queue.writeBuffer( | ||
|
|
@@ -255,9 +257,16 @@ const init: SampleInit = async ({ canvas, pageState }) => { | |
| modelViewProjectionMatrix.byteLength | ||
| ); | ||
|
|
||
| renderPassDescriptor.colorAttachments[0].view = context | ||
| .getCurrentTexture() | ||
| .createView(); | ||
| type GPURenderPassColorAttachmentArray = | ||
| (GPURenderPassColorAttachment | null)[]; | ||
|
|
||
| const attachment = ( | ||
| renderPassDescriptor.colorAttachments as GPURenderPassColorAttachmentArray | ||
| )[0]; | ||
|
|
||
| assert(attachment, 'attachment is null'); | ||
|
|
||
| attachment.view = context.getCurrentTexture().createView(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a complicated way to get const colorAttachment0: GPURenderPassColorAttachment = {
view: undefined as any, // Assigned later
};
const renderPassDescriptor: GPURenderPassDescriptor = {
colorAttachments: [colorAttachment0],colorAttachment0.view = context.getCurrentTexture().createView(); |
||
|
|
||
| const commandEncoder = device.createCommandEncoder(); | ||
| const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.