Make the templates of native struct flexible
Rename wgpu_structs.cpp/h to api_structs.cpp/h and replace hardcode contents with metadata. BUG=dawn:1201 Change-Id: I4f2978c6abec7b492da142499890733567e2cec3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/73300 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:
parent
f30f3a912d
commit
7f3f8ac004
|
@ -860,6 +860,7 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||
|
||||
impl_dir = metadata.impl_dir + '/' if metadata.impl_dir else ''
|
||||
native_dir = impl_dir + Name(metadata.native_namespace).snake_case()
|
||||
namespace = metadata.namespace
|
||||
renders.append(
|
||||
FileRender('dawn_native/ValidationUtils.h',
|
||||
'src/' + native_dir + '/ValidationUtils_autogen.h',
|
||||
|
@ -873,12 +874,12 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||
'src/' + native_dir + '/' + prefix + '_platform_autogen.h',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/wgpu_structs.h',
|
||||
'src/dawn_native/wgpu_structs_autogen.h',
|
||||
FileRender('dawn_native/api_structs.h',
|
||||
'src/' + native_dir + '/' + namespace + '_structs_autogen.h',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/wgpu_structs.cpp',
|
||||
'src/dawn_native/wgpu_structs_autogen.cpp',
|
||||
FileRender('dawn_native/api_structs.cpp',
|
||||
'src/' + native_dir + '/' + namespace + '_structs_autogen.cpp',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/ProcTable.cpp',
|
||||
|
|
|
@ -12,24 +12,29 @@
|
|||
//* See the License for the specific language governing permissions and
|
||||
//* limitations under the License.
|
||||
|
||||
#include "dawn_native/wgpu_structs_autogen.h"
|
||||
{% set native_namespace = Name(metadata.native_namespace).snake_case() %}
|
||||
{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %}
|
||||
{% set native_dir = impl_dir + native_namespace %}
|
||||
{% set namespace = metadata.namespace %}
|
||||
#include "{{native_dir}}/{{namespace}}_structs_autogen.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#ifdef __GNUC__
|
||||
// error: 'offsetof' within non-standard-layout type 'wgpu::XXX' is conditionally-supported
|
||||
// error: 'offsetof' within non-standard-layout type '{{namespace}}::XXX' is conditionally-supported
|
||||
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||
#endif
|
||||
|
||||
namespace dawn_native {
|
||||
namespace {{native_namespace}} {
|
||||
|
||||
static_assert(sizeof(ChainedStruct) == sizeof(WGPUChainedStruct),
|
||||
{% set c_prefix = metadata.c_prefix %}
|
||||
static_assert(sizeof(ChainedStruct) == sizeof({{c_prefix}}ChainedStruct),
|
||||
"sizeof mismatch for ChainedStruct");
|
||||
static_assert(alignof(ChainedStruct) == alignof(WGPUChainedStruct),
|
||||
static_assert(alignof(ChainedStruct) == alignof({{c_prefix}}ChainedStruct),
|
||||
"alignof mismatch for ChainedStruct");
|
||||
static_assert(offsetof(ChainedStruct, nextInChain) == offsetof(WGPUChainedStruct, next),
|
||||
static_assert(offsetof(ChainedStruct, nextInChain) == offsetof({{c_prefix}}ChainedStruct, next),
|
||||
"offsetof mismatch for ChainedStruct::nextInChain");
|
||||
static_assert(offsetof(ChainedStruct, sType) == offsetof(WGPUChainedStruct, sType),
|
||||
static_assert(offsetof(ChainedStruct, sType) == offsetof({{c_prefix}}ChainedStruct, sType),
|
||||
"offsetof mismatch for ChainedStruct::sType");
|
||||
|
||||
{% for type in by_category["structure"] %}
|
||||
|
@ -66,4 +71,4 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
{% endfor %}
|
||||
}
|
||||
} // namespace {{native_namespace}}
|
|
@ -12,13 +12,20 @@
|
|||
//* See the License for the specific language governing permissions and
|
||||
//* limitations under the License.
|
||||
|
||||
#ifndef DAWNNATIVE_WGPU_STRUCTS_H_
|
||||
#define DAWNNATIVE_WGPU_STRUCTS_H_
|
||||
{% set namespace_name = Name(metadata.native_namespace) %}
|
||||
{% set DIR = namespace_name.concatcase().upper() %}
|
||||
{% set namespace = metadata.namespace %}
|
||||
#ifndef {{DIR}}_{{namespace.upper()}}_STRUCTS_H_
|
||||
#define {{DIR}}_{{namespace.upper()}}_STRUCTS_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"
|
||||
|
||||
namespace dawn_native {
|
||||
namespace {{native_namespace}} {
|
||||
|
||||
{% macro render_cpp_default_value(member) -%}
|
||||
{%- if member.annotation in ["*", "const*"] and member.optional or member.default_value == "nullptr" -%}
|
||||
|
@ -26,7 +33,7 @@ namespace dawn_native {
|
|||
{%- elif member.type.category == "object" and member.optional -%}
|
||||
{{" "}}= nullptr
|
||||
{%- elif member.type.category in ["enum", "bitmask"] and member.default_value != None -%}
|
||||
{{" "}}= wgpu::{{as_cppType(member.type.name)}}::{{as_cppEnum(Name(member.default_value))}}
|
||||
{{" "}}= {{namespace}}::{{as_cppType(member.type.name)}}::{{as_cppEnum(Name(member.default_value))}}
|
||||
{%- elif member.type.category == "native" and member.default_value != None -%}
|
||||
{{" "}}= {{member.default_value}}
|
||||
{%- else -%}
|
||||
|
@ -36,14 +43,14 @@ namespace dawn_native {
|
|||
|
||||
struct ChainedStruct {
|
||||
ChainedStruct const * nextInChain = nullptr;
|
||||
wgpu::SType sType = wgpu::SType::Invalid;
|
||||
{{namespace}}::SType sType = {{namespace}}::SType::Invalid;
|
||||
};
|
||||
|
||||
{% for type in by_category["structure"] %}
|
||||
{% if type.chained %}
|
||||
struct {{as_cppType(type.name)}} : ChainedStruct {
|
||||
{{as_cppType(type.name)}}() {
|
||||
sType = wgpu::SType::{{type.name.CamelCase()}};
|
||||
sType = {{namespace}}::SType::{{type.name.CamelCase()}};
|
||||
}
|
||||
{% else %}
|
||||
struct {{as_cppType(type.name)}} {
|
||||
|
@ -72,6 +79,6 @@ namespace dawn_native {
|
|||
using {{as_cppType(typeDef.name)}} = {{as_cppType(typeDef.type.name)}};
|
||||
{% endfor %}
|
||||
|
||||
} // namespace dawn_native
|
||||
} // namespace {{native_namespace}}
|
||||
|
||||
#endif // DAWNNATIVE_WGPU_STRUCTS_H_
|
||||
#endif // {{DIR}}_{{namespace.upper()}}_STRUCTS_H_
|
Loading…
Reference in New Issue