-
Notifications
You must be signed in to change notification settings - Fork 313
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
Update samples to work with TypeScript strict mode (part 2) #285
base: main
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
@@ -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 | ||
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In response to the GitHub Actions check warning)
It would be nice to make the build warning-free. In this case it can probably be
view: undefined!,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kainino0x
I wanted to use
view: undefined!
too, but it was inferred as the never type and didn't work out. How about usingview: undefined as unknown as GPUTextureView
? Using as twice isn't intuitive, but since we can't directly cast undefined to GPUTextureView, it seems unavoidable. If there's a better suggestion, I'd love to hear it.