webgpu-native / webgpu-headers

https://webgpu-native.github.io/webgpu-headers/
BSD 3-Clause "New" or "Revised" License
341 stars 39 forks source link

Using fixed-length arrays for some output arrays? #302

Closed kainino0x closed 3 days ago

kainino0x commented 1 month ago

In Emscripten there were a few suggestions to use fixed-length arrays for some outputs to avoid needing FreeMembers. In particular AdapterInfo just has a few strings in it - we probably could get away with setting some fixed limit on their size, but description is the most unsure, since it might get wrapped repeatedly the way ANGLE does: ANGLE (Apple, ANGLE Metal Renderer: Apple M1 Pro, Version 14.5 (Build 23F79))

Discussion was here: https://github.com/emscripten-core/emscripten/pull/22031#discussion_r1624954986

Kangz commented 1 month ago

Do we know what the cost of a malloc is in emscripten? Something like AdapterGetInfo happens maybe once per application run so it doesn't seem super worth optimizing by having some arbitrary length hardcoded.

kainino0x commented 1 month ago

I'm definitely not concerned with the performance cost for AdapterGetInfo, given it should be called basically once. It's more of an ergonomic improvement as you wouldn't need FreeMembers at all for this struct. It's feasible to do similar things for other structs as well, like changing presentModes to a fixed-size array.

Kangz commented 1 month ago

Ah, that would be a problem only for C though and only in a few places so not super important either imho.

kainino0x commented 3 days ago

Jul 18 meeting: