-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add webgpu
IDL spec and generated code
#38
Conversation
Looks like this needs to be rebased? |
This reverts commit f6f0fed.
This allows removing manual `OffscreenRenderingContext` and `RenderingContext` declarations.
I've rebased it, but there are still a few commits that don't matter in the end diff, and they will be squashed. Yes, the diff on |
@@ -1,5 +1,5 @@ | |||
/// https://github.com/w3c/webidl2.js#iterable-async-iterable-maplike-and-setlike-declarations | |||
public protocol IDLDeclaration: IDLNode, IDLInterfaceMember { | |||
public protocol IDLDeclaration: IDLInterfaceMember { |
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.
This conformance to IDLNode
triggered a redundancy warning, as apparently IDLInterfaceMember
already conforms to IDLNode
.
@@ -117,7 +117,7 @@ func runWebGLDemo() { | |||
// Get A WebGL context | |||
let canvas = HTMLCanvasElement(from: document.createElement(localName: "canvas"))! | |||
_ = document.body?.appendChild(node: canvas) | |||
let context = canvas.getContext(contextId: "webgl2")!.webGL2RenderingContext! | |||
let context = WebGL2RenderingContext.construct(from: canvas.getContext(contextId: "webgl2")!.jsValue)! |
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.
let context = WebGL2RenderingContext.construct(from: canvas.getContext(contextId: "webgl2")!.jsValue)! | |
let context = canvas.getContext(contextId: "webgl2")!.webGL2RenderingContext! |
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.
This doesn't work unfortunately, as these enum properties aren't public in the generated code. IDK if that's on purpose. Either way, I decided to make it work with the existing generation approach, and those properties could be made public, if needed, in a separate PR.
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.
Oh they should definitely be public — there’s no internal use for them.
Force unwrapping in `class var constructor` may crash for classes that are unavailable in the current environment. For example, after swiftwasm/WebAPIKit#38 was merged, it led to crashes in `getCanvas` calls due to these optional casts relying on `class var constructor` always succeeding: ```swift public static func construct(from value: JSValue) -> Self? { if let canvasRenderingContext2D: CanvasRenderingContext2D = value.fromJSValue() { return .canvasRenderingContext2D(canvasRenderingContext2D) } if let gpuCanvasContext: GPUCanvasContext = value.fromJSValue() { return .gpuCanvasContext(gpuCanvasContext) } if let imageBitmapRenderingContext: ImageBitmapRenderingContext = value.fromJSValue() { return .imageBitmapRenderingContext(imageBitmapRenderingContext) } if let webGL2RenderingContext: WebGL2RenderingContext = value.fromJSValue() { return .webGL2RenderingContext(webGL2RenderingContext) } if let webGLRenderingContext: WebGLRenderingContext = value.fromJSValue() { return .webGLRenderingContext(webGLRenderingContext) } return nil } ``` `if let gpuCanvasContext: GPUCanvasContext = value.fromJSValue()` branch crashes on browsers that don't have `GPUCanvasContext` enabled. As we currently don't have a better way to handle unavailable features, I propose making the result type of `static var constructor` requirement optional. This means you can still declare classes that are unavailable in the host JS environment. Conditional type casts are also available as they were, they will just always return `nil`, and initializers for these classes will return `nil` as well.
This allows removing manual
OffscreenRenderingContext
andRenderingContext
declarations.