Add the wire client version of webgpu_cpp_print.h
This CL adds the generation of webgpu_cpp_print.h for wire client
(under the include/dawn/wire/client path). Currently some places in
Chromium (e.g. webgpu_test) that should use the wire client types are
actually using the native headers instead. However, with the addition
of ClientSharedImage and WebGPUTextureScopedAccess, the correct header
usage is now mandatory. This change serves as a prerequisite for the
header refactoring on the Chromium side.
Bug: 439767645, 40286368
Change-Id: I4f4a4afdcb35b6e5089e31c450a4c523f98024d6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/258095
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Mingjing Zhang <mjzhang@chromium.org>
Commit-Queue: Mingjing Zhang <mjzhang@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index b7eb2e9..e6d722e 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -1288,8 +1288,22 @@
renders.append(
FileRender('api_cpp_print.h',
- 'include/dawn/' + api + '_cpp_print.h',
- [RENDER_PARAMS_BASE, params_dawn]))
+ 'include/dawn/' + api + '_cpp_print.h', [
+ RENDER_PARAMS_BASE, params_dawn, {
+ 'cpp_header': api + '/' + api + '_cpp.h',
+ 'c_namespace': None,
+ }
+ ]))
+
+ renders.append(
+ FileRender(
+ 'api_cpp_print.h',
+ 'include/dawn/wire/client/' + api + '_cpp_print.h', [
+ RENDER_PARAMS_BASE, params_dawn, {
+ 'cpp_header': 'dawn/wire/client/' + api + '_cpp.h',
+ 'c_namespace': Name('dawn wire client'),
+ }
+ ]))
renders.append(
FileRender('api_cpp_chained_struct.h',
@@ -1349,7 +1363,12 @@
renders.append(
FileRender('api_cpp_print.h',
'src/emdawnwebgpu/include/dawn/webgpu_cpp_print.h',
- [RENDER_PARAMS_BASE, params_emscripten]))
+ [
+ RENDER_PARAMS_BASE, params_emscripten, {
+ 'cpp_header': api + '/' + api + '_cpp.h',
+ 'c_namespace': None,
+ }
+ ]))
if 'emdawnwebgpu_js' in targets:
assert api == 'webgpu'
diff --git a/generator/templates/api_cpp_print.h b/generator/templates/api_cpp_print.h
index 641306e..83f1084 100644
--- a/generator/templates/api_cpp_print.h
+++ b/generator/templates/api_cpp_print.h
@@ -27,10 +27,11 @@
{% set API = metadata.api.upper() %}
{% set api = API.lower() %}
-#ifndef {{API}}_CPP_PRINT_H_
-#define {{API}}_CPP_PRINT_H_
+{% set PREFIX = "" if not c_namespace else c_namespace.SNAKE_CASE() + "_" %}
+#ifndef {{PREFIX}}{{API}}_CPP_PRINT_H_
+#define {{PREFIX}}{{API}}_CPP_PRINT_H_
-#include "{{api}}/{{api}}_cpp.h"
+#include "{{cpp_header}}"
#include <iomanip>
#include <ios>
@@ -100,12 +101,17 @@
}
{% endfor %}
+} // namespace {{metadata.namespace}}
+
+{% set namespace = metadata.namespace if not c_namespace else metadata.namespace + '::' + c_namespace.namespace_case() %}
+namespace {{namespace}} {
+
template <typename CharT, typename Traits>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& o, StringView value) {
o << std::string_view(value);
return o;
}
-} // namespace {{metadata.namespace}}
+} // namespace {{namespace}}
-#endif // {{API}}_CPP_PRINT_H_
+#endif // {{PREFIX}}{{API}}_CPP_PRINT_H_
diff --git a/include/dawn/BUILD.gn b/include/dawn/BUILD.gn
index e73c9b9..ce2c6ac 100644
--- a/include/dawn/BUILD.gn
+++ b/include/dawn/BUILD.gn
@@ -61,6 +61,7 @@
"include/dawn/webgpu_cpp_print.h",
"include/webgpu/webgpu_cpp_chained_struct.h",
"include/dawn/wire/client/webgpu_cpp.h",
+ "include/dawn/wire/client/webgpu_cpp_print.h",
]
}