Make dawn_platform.h template flexible
Replace hardcode content with metadata defined in api.json
BUG=dawn:1201
Change-Id: Ib6d6a9c7afc8fb89d3ff2d0129dbfba04adb542a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/73160
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 086f9cb..1d810ca 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -870,7 +870,7 @@
frontend_params))
renders.append(
FileRender('dawn_native/dawn_platform.h',
- 'src/dawn_native/dawn_platform_autogen.h',
+ 'src/' + native_dir + '/' + prefix + '_platform_autogen.h',
frontend_params))
renders.append(
FileRender('dawn_native/wgpu_structs.h',
diff --git a/generator/templates/dawn_native/dawn_platform.h b/generator/templates/dawn_native/dawn_platform.h
index 0690064..cffa2ae 100644
--- a/generator/templates/dawn_native/dawn_platform.h
+++ b/generator/templates/dawn_native/dawn_platform.h
@@ -12,17 +12,25 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
-#ifndef DAWNNATIVE_DAWN_PLATFORM_AUTOGEN_H_
-#define DAWNNATIVE_DAWN_PLATFORM_AUTOGEN_H_
+{% set namespace_name = Name(metadata.native_namespace) %}
+{% set NATIVE_DIR = namespace_name.concatcase().upper() %}
+{% set PREFIX = metadata.proc_table_prefix.upper() %}
+#ifndef {{NATIVE_DIR}}_{{PREFIX}}_PLATFORM_AUTOGEN_H_
+#define {{NATIVE_DIR}}_{{PREFIX}}_PLATFORM_AUTOGEN_H_
-#include "dawn/webgpu_cpp.h"
-#include "dawn_native/Forward.h"
+{% set api = metadata.api.lower() %}
+#include "dawn/{{api}}_cpp.h"
+{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %}
+{% set native_namespace = namespace_name.snake_case() %}
+{% set native_dir = impl_dir + native_namespace %}
+#include "{{native_dir}}/Forward.h"
-// Use our autogenerated version of the wgpu structures that point to dawn_native object types
+{% set namespace = metadata.namespace %}
+// Use our autogenerated version of the {{namespace}} structures that point to {{native_namespace}} object types
// (wgpu::Buffer is dawn_native::BufferBase*)
-#include <dawn_native/wgpu_structs_autogen.h>
+#include <{{native_dir}}/{{namespace}}_structs_autogen.h>
-namespace dawn_native {
+namespace {{native_namespace}} {
{% for type in by_category["structure"] %}
inline const {{as_cType(type.name)}}* ToAPI(const {{as_cppType(type.name)}}* rhs) {
@@ -65,10 +73,10 @@
{% for e in by_category["enum"] if e.contiguousFromZero %}
template<>
- struct EnumCount<wgpu::{{as_cppType(e.name)}}> {
+ struct EnumCount<{{namespace}}::{{as_cppType(e.name)}}> {
static constexpr uint32_t value = {{len(e.values)}};
};
{% endfor %}
}
-#endif // DAWNNATIVE_DAWN_PLATFORM_AUTOGEN_H_
\ No newline at end of file
+#endif // {{NATIVE_DIR}}_{{PREFIX}}_PLATFORM_AUTOGEN_H_
\ No newline at end of file