Bug 237921 - See if we can get rid of all the WGPU stub structs
Summary: See if we can get rid of all the WGPU stub structs
Status: RESOLVED DUPLICATE of bug 238001
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGPU (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-15 14:30 PDT by Myles C. Maxfield
Modified: 2022-03-16 23:19 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2022-03-15 14:30:33 PDT
The shared WebGPU.h header has:

typedef struct WGPUDeviceImpl* WGPUDevice;

However, it would be convenient if we could have our own names like this:

namespace WebGPU {
class Device {
    ...
    id<MTLDevice> m_device;
    ...
}
}

I thought of 3 possible solutions:

1. Use reinterpret_cast<>() to freely convert between WGPUDeviceImpl* and WebGPU::Device*. This breaks C++'s type system, and is technically UB (I think) so I was hoping to avoid this option.

2. Don't have nice names, and don't use "namespace WebGPU":

struct WGPUDeviceImpl {
    ...
    id<MTLDevice> m_device;
    ...
}

This is unfortunate because it foregoes C++'s built-in namespace support in favor of prefixes, and isn't the pattern we use for the rest of WebKit

3. Do a double-pointer-indirection:

struct WGPUDeviceImpl {
    Ref<WebGPU::Device> device;
};

This isn't great for performance (though it's probably negligible) and has a somewhat bad smell about having two types which mean the same thing.

For the initial implementation, I chose option 3, under the assumption that it would be easy/mechanical to change later if a better option presents itself.

We should see if there is a better solution.
Comment 1 Myles C. Maxfield 2022-03-16 23:19:54 PDT

*** This bug has been marked as a duplicate of bug 238001 ***