Bug 237921

Summary: See if we can get rid of all the WGPU stub structs
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: WebGPUAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal    
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Myles C. Maxfield
Reported 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.
Attachments
Myles C. Maxfield
Comment 1 2022-03-16 23:19:54 PDT
*** This bug has been marked as a duplicate of bug 238001 ***
Note You need to log in before you can comment on or make changes to this bug.