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>
This commit is contained in:
fujunwei 2021-12-17 00:46:08 +00:00 committed by Dawn LUCI CQ
parent b6dc96055e
commit fc38f7d879
2 changed files with 18 additions and 10 deletions

View File

@ -870,7 +870,7 @@ class MultiGeneratorFromDawnJSON(Generator):
frontend_params)) frontend_params))
renders.append( renders.append(
FileRender('dawn_native/dawn_platform.h', FileRender('dawn_native/dawn_platform.h',
'src/dawn_native/dawn_platform_autogen.h', 'src/' + native_dir + '/' + prefix + '_platform_autogen.h',
frontend_params)) frontend_params))
renders.append( renders.append(
FileRender('dawn_native/wgpu_structs.h', FileRender('dawn_native/wgpu_structs.h',

View File

@ -12,17 +12,25 @@
//* See the License for the specific language governing permissions and //* See the License for the specific language governing permissions and
//* limitations under the License. //* limitations under the License.
#ifndef DAWNNATIVE_DAWN_PLATFORM_AUTOGEN_H_ {% set namespace_name = Name(metadata.native_namespace) %}
#define DAWNNATIVE_DAWN_PLATFORM_AUTOGEN_H_ {% 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" {% set api = metadata.api.lower() %}
#include "dawn_native/Forward.h" #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*) // (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"] %} {% for type in by_category["structure"] %}
inline const {{as_cType(type.name)}}* ToAPI(const {{as_cppType(type.name)}}* rhs) { inline const {{as_cType(type.name)}}* ToAPI(const {{as_cppType(type.name)}}* rhs) {
@ -65,10 +73,10 @@ namespace dawn_native {
{% for e in by_category["enum"] if e.contiguousFromZero %} {% for e in by_category["enum"] if e.contiguousFromZero %}
template<> template<>
struct EnumCount<wgpu::{{as_cppType(e.name)}}> { struct EnumCount<{{namespace}}::{{as_cppType(e.name)}}> {
static constexpr uint32_t value = {{len(e.values)}}; static constexpr uint32_t value = {{len(e.values)}};
}; };
{% endfor %} {% endfor %}
} }
#endif // DAWNNATIVE_DAWN_PLATFORM_AUTOGEN_H_ #endif // {{NATIVE_DIR}}_{{PREFIX}}_PLATFORM_AUTOGEN_H_