[dawn][emscripten] Move critical C declarations into webgpu.h

- Temporarily move the definition for emscripten_webgpu_get_device
  into webgpu.h headers so that we can migrate users to stop
  relying on <emscripten/html5_webgpu.h>.
- Also removes all the deprecated implementations in
  library_html5_webgpu.js.

Bug: 374150686
Change-Id: I70fae6acb43752b7f2d8e46439d7357ee896b07f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/211454
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/templates/api.h b/generator/templates/api.h
index 359b58c..132be07 100644
--- a/generator/templates/api.h
+++ b/generator/templates/api.h
@@ -248,6 +248,12 @@
 
 #if !defined({{API}}_SKIP_PROCS)
 
+// TODO(374150686): Remove these Emscripten specific declarations from the
+// header once they are fully deprecated.
+#ifdef __EMSCRIPTEN__
+{{API}}_EXPORT WGPUDevice emscripten_webgpu_get_device(void);
+#endif
+
 {% for function in by_category["function"] %}
     typedef {{as_cType(function.return_type.name)}} (*{{as_cProc(None, function.name)}})(
             {%- for arg in function.arguments -%}
diff --git a/src/emdawnwebgpu/BUILD.gn b/src/emdawnwebgpu/BUILD.gn
index 134b349..56ef3f2 100644
--- a/src/emdawnwebgpu/BUILD.gn
+++ b/src/emdawnwebgpu/BUILD.gn
@@ -150,8 +150,6 @@
           rebase_path("${target_gen_dir}/library_webgpu_generated_sig_info.js"),
       "--js-library=" +
           rebase_path("../../third_party/emdawnwebgpu/library_webgpu.js"),
-      "--js-library=" +
-          rebase_path("../../third_party/emdawnwebgpu/library_html5_webgpu.js"),
 
       # Emscripten only enables webgpu-externs.js with -sUSE_WEBGPU=1, so add them explicitly.
       "--closure-args=--externs=${dawn_emscripten_dir}/src/closure-externs/webgpu-externs.js",
@@ -182,7 +180,6 @@
     inputs = [
       # FIXME: Changing these files still doesn't cause a relink. Why?
       "../../third_party/emdawnwebgpu/library_webgpu.js",
-      "../../third_party/emdawnwebgpu/library_html5_webgpu.js",
     ]
   }
 }
diff --git a/src/emdawnwebgpu/CMakeLists.txt b/src/emdawnwebgpu/CMakeLists.txt
index d545432..68d40fa 100644
--- a/src/emdawnwebgpu/CMakeLists.txt
+++ b/src/emdawnwebgpu/CMakeLists.txt
@@ -201,7 +201,6 @@
         "--js-library=${EM_BUILD_GEN_DIR}/library_webgpu_generated_struct_info.js"
         "--js-library=${EM_BUILD_GEN_DIR}/library_webgpu_generated_sig_info.js"
         "--js-library=${DAWN_EMDAWNWEBGPU_DIR}/library_webgpu.js"
-        "--js-library=${DAWN_EMDAWNWEBGPU_DIR}/library_html5_webgpu.js"
         "--closure-args=--externs=${DAWN_EMSCRIPTEN_TOOLCHAIN}/src/closure-externs/webgpu-externs.js"
     )
 
diff --git a/third_party/emdawnwebgpu/library_html5_webgpu.js b/third_party/emdawnwebgpu/library_html5_webgpu.js
deleted file mode 100644
index 95cff18..0000000
--- a/third_party/emdawnwebgpu/library_html5_webgpu.js
+++ /dev/null
@@ -1,90 +0,0 @@
-{{{
-  // Helper functions for code generation
-  globalThis.html5_gpu = {
-    makeImportExport: (snake_case) => {
-      return `
-LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
-LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (ptr) =>
-  WebGPU._tableInsert(JsValStore.get(ptr));
-
-LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
-LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (ptr) =>
-  JsValStore.add(WebGPU._tableGet(ptr));`
-    },
-  };
-  null;
-}}}
-
-var LibraryHTML5WebGPU = {
-  $JsValStore: {
-    values: {},
-    next_id: 1,
-
-    add(js_val) {
-      var id;
-      do {
-        id = JsValStore.next_id++;
-        if (JsValStore.next_id > 2147483647) JsValStore.next_id = 1; // Wraparound signed int32.
-      } while (id in JsValStore.values);
-
-      JsValStore.values[id] = js_val;
-      return id;
-    },
-    remove(id) {
-#if ASSERTIONS
-      assert(id in JsValStore.values);
-#endif
-      delete JsValStore.values[id];
-    },
-    get(id) {
-#if ASSERTIONS
-      assert(id === 0 || id in JsValStore.values);
-#endif
-      return JsValStore.values[id];
-    },
-  },
-
-  emscripten_webgpu_release_js_handle__deps: ['$JsValStore'],
-  emscripten_webgpu_release_js_handle: (id) => JsValStore.remove(id),
-
-  emscripten_webgpu_get_device__deps: ['$WebGPU','wgpuDeviceAddRef'],
-  emscripten_webgpu_get_device: () => {
-#if ASSERTIONS
-    assert(Module['preinitializedWebGPUDevice']);
-#endif
-    if (WebGPU.preinitializedDeviceId === undefined) {
-      WebGPU.preinitializedDeviceId = WebGPU.importJsDevice(Module['preinitializedWebGPUDevice']);
-    }
-    _wgpuDeviceAddRef(WebGPU.preinitializedDeviceId);
-    return WebGPU.preinitializedDeviceId;
-  },
-};
-
-{{{ html5_gpu.makeImportExport('surface') }}}
-{{{ html5_gpu.makeImportExport('swap_chain') }}}
-
-{{{ html5_gpu.makeImportExport('device') }}}
-{{{ html5_gpu.makeImportExport('queue') }}}
-
-{{{ html5_gpu.makeImportExport('command_buffer') }}}
-{{{ html5_gpu.makeImportExport('command_encoder') }}}
-{{{ html5_gpu.makeImportExport('render_pass_encoder') }}}
-{{{ html5_gpu.makeImportExport('compute_pass_encoder') }}}
-
-{{{ html5_gpu.makeImportExport('bind_group') }}}
-{{{ html5_gpu.makeImportExport('buffer') }}}
-{{{ html5_gpu.makeImportExport('sampler') }}}
-{{{ html5_gpu.makeImportExport('texture') }}}
-{{{ html5_gpu.makeImportExport('texture_view') }}}
-{{{ html5_gpu.makeImportExport('query_set') }}}
-
-{{{ html5_gpu.makeImportExport('bind_group_layout') }}}
-{{{ html5_gpu.makeImportExport('pipeline_layout') }}}
-{{{ html5_gpu.makeImportExport('render_pipeline') }}}
-{{{ html5_gpu.makeImportExport('compute_pipeline') }}}
-{{{ html5_gpu.makeImportExport('shader_module') }}}
-
-{{{ html5_gpu.makeImportExport('render_bundle_encoder') }}}
-{{{ html5_gpu.makeImportExport('render_bundle') }}}
-
-mergeInto(LibraryManager.library, LibraryHTML5WebGPU);
diff --git a/third_party/emdawnwebgpu/library_webgpu.js b/third_party/emdawnwebgpu/library_webgpu.js
index 1c53c27..1e5387e 100644
--- a/third_party/emdawnwebgpu/library_webgpu.js
+++ b/third_party/emdawnwebgpu/library_webgpu.js
@@ -547,6 +547,19 @@
     {{{ WEBGPU_INT_TO_STRING_TABLES }}}
   },
 
+  // TODO(374150686): Remove this once it has been fully deprecated in users.
+  emscripten_webgpu_get_device__deps: ['wgpuDeviceAddRef'],
+  emscripten_webgpu_get_device: () => {
+#if ASSERTIONS
+    assert(Module['preinitializedWebGPUDevice']);
+#endif
+    if (WebGPU.preinitializedDeviceId === undefined) {
+      WebGPU.preinitializedDeviceId = WebGPU.importJsDevice(Module['preinitializedWebGPUDevice']);
+    }
+    _wgpuDeviceAddRef(WebGPU.preinitializedDeviceId);
+    return WebGPU.preinitializedDeviceId;
+  },
+
   // ----------------------------------------------------------------------------
   // Definitions for standalone JS emwgpu functions (callable from webgpu.cpp and
   //   library_html5_html.js)