<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>237921</bug_id>
          
          <creation_ts>2022-03-15 14:30:33 -0700</creation_ts>
          <short_desc>See if we can get rid of all the WGPU stub structs</short_desc>
          <delta_ts>2022-03-16 23:19:54 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGPU</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>238001</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Myles C. Maxfield">mmaxfield</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1851501</commentid>
    <comment_count>0</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-03-15 14:30:33 -0700</bug_when>
    <thetext>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&lt;MTLDevice&gt; m_device;
    ...
}
}

I thought of 3 possible solutions:

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

2. Don&apos;t have nice names, and don&apos;t use &quot;namespace WebGPU&quot;:

struct WGPUDeviceImpl {
    ...
    id&lt;MTLDevice&gt; m_device;
    ...
}

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

3. Do a double-pointer-indirection:

struct WGPUDeviceImpl {
    Ref&lt;WebGPU::Device&gt; device;
};

This isn&apos;t great for performance (though it&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1852140</commentid>
    <comment_count>1</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-03-16 23:19:54 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 238001 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>