webgpu-native / webgpu-headers

**NOT STABLE YET!** See README.
https://webgpu-native.github.io/webgpu-headers/
BSD 3-Clause "New" or "Revised" License
394 stars 45 forks source link

Why FreeMembers functions take structs by value? #381

Closed liskar-dev closed 1 week ago

liskar-dev commented 1 month ago
void wgpuAdapterInfoFreeMembers(WGPUAdapterInfo adapterInfo)
void wgpuSupportedFeaturesFreeMembers(WGPUSupportedFeatures supportedFeatures)
void wgpuSurfaceCapabilitiesFreeMembers(WGPUSurfaceCapabilities surfaceCapabilities)

These function definitions seem to take whole structs by value. Why is it so? Was this intentional? Am I missing something?

kainino0x commented 1 month ago

IIRC it was mainly to signal that we will free the things inside the struct, but we will not free the struct itself. I don't think this is a really critical distinction though. Do you have a particular reason you think they should take pointers instead? (I do agree it feels a bit odd.)

PJB3005 commented 3 weeks ago

My understanding is that C APIs don't generally take raw structs due to inconsistencies between various ABIs making it a nightmare. It's probably fine:tm: on x86/ARM64 but for more niche architectures it's simpler/better defined to just take pointers for everything. And it doesn't matter for perf anyways in practice.

kainino0x commented 3 weeks ago

Ah yes, I forgot about that. I did some research before on this topic - e.g. https://www.reddit.com/r/C_Programming/comments/19cdr0e/abi_safety_of_passing_small_struct_by_value/ - and as far as I could tell it shouldn't be that much of a concern in this decade, and avoiding it is maybe too paranoid. To some extent we have to rely on the compiler to work correctly... and I have a hard time imagining webgpu.h would actually be used on any systems that don't even have well-maintained compilers.

kainino0x commented 1 week ago

Nov 21 meeting: