Make dawn_native use its own header for Dawn datatypes

The dawn.h and dawncpp.h structure definitions references dawnFoo or
dawn::Foo respectively when it should reference dawn_native::FooBase* in
dawn_native. Autogenerate files to declare the dawn_native version of
the structs and change the ProcTable generation to use it instead.

This is important to make libdawn_native a shared library because
currently it was depending on dawncpp's definition of .Get().
This commit is contained in:
Corentin Wallez
2018-07-25 17:03:23 +02:00
committed by Corentin Wallez
parent 5d313225ff
commit 36afbb6a0d
67 changed files with 231 additions and 141 deletions

View File

@@ -479,6 +479,8 @@ def main():
if 'dawn_native_utils' in targets:
renders.append(FileRender('dawn_native/ValidationUtils.h', 'dawn_native/ValidationUtils_autogen.h', base_backend_params))
renders.append(FileRender('dawn_native/ValidationUtils.cpp', 'dawn_native/ValidationUtils_autogen.cpp', base_backend_params))
renders.append(FileRender('dawn_native/api_structs.h', 'dawn_native/dawn_structs_autogen.h', base_backend_params))
renders.append(FileRender('dawn_native/api_structs.cpp', 'dawn_native/dawn_structs_autogen.cpp', base_backend_params))
if 'wire' in targets:
renders.append(FileRender('wire/WireCmd.h', 'wire/WireCmd_autogen.h', base_backend_params))

View File

@@ -12,11 +12,9 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#include "dawn/dawn.h"
#include "dawn/dawncpp.h"
#include "common/Assert.h"
#include "dawn_native/dawn_platform.h"
#include "dawn_native/ErrorData.h"
#include "dawn_native/ValidationUtils_autogen.h"
#include "dawn_native/{{namespace}}/GeneratedCodeIncludes.h"
@@ -51,7 +49,7 @@ namespace {{namespace}} {
{%- if arg.type.category in ["enum", "bitmask"] -%}
static_cast<dawn::{{as_cppType(arg.type.name)}}>({{as_varName(arg.name)}})
{%- elif arg.type.category == "structure" and arg.annotation != "value" -%}
reinterpret_cast<const dawn::{{as_cppType(arg.type.name)}}*>({{as_varName(arg.name)}})
reinterpret_cast<const {{as_cppType(arg.type.name)}}*>({{as_varName(arg.name)}})
{%- else -%}
{{as_varName(arg.name)}}
{%- endif -%}
@@ -169,7 +167,7 @@ namespace {{namespace}} {
{%- if arg.type.category in ["enum", "bitmask"] -%}
static_cast<dawn::{{as_cppType(arg.type.name)}}>({{as_varName(arg.name)}})
{%- elif arg.type.category == "structure" and arg.annotation != "value" -%}
reinterpret_cast<const dawn::{{as_cppType(arg.type.name)}}*>({{as_varName(arg.name)}})
reinterpret_cast<const {{as_cppType(arg.type.name)}}*>({{as_varName(arg.name)}})
{%- else -%}
{{as_varName(arg.name)}}
{%- endif -%}

View File

@@ -0,0 +1,37 @@
//* Copyright 2018 The Dawn Authors
//*
//* Licensed under the Apache License, Version 2.0 (the "License");
//* you may not use this file except in compliance with the License.
//* You may obtain a copy of the License at
//*
//* http://www.apache.org/licenses/LICENSE-2.0
//*
//* Unless required by applicable law or agreed to in writing, software
//* distributed under the License is distributed on an "AS IS" BASIS,
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and
//* limitations under the License.
#include "dawn_native/dawn_structs_autogen.h"
namespace dawn_native {
{% for type in by_category["structure"] %}
{% set CppType = as_cppType(type.name) %}
{% set CType = as_cType(type.name) %}
static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
{% if type.extensible %}
static_assert(offsetof({{CppType}}, nextInChain) == offsetof({{CType}}, nextInChain),
"offsetof mismatch for {{CppType}}::nextInChain");
{% endif %}
{% for member in type.members %}
{% set memberName = member.name.camelCase() %}
static_assert(offsetof({{CppType}}, {{memberName}}) == offsetof({{CType}}, {{memberName}}),
"offsetof mismatch for {{CppType}}::{{memberName}}");
{% endfor %}
{% endfor %}
}

View File

@@ -0,0 +1,45 @@
//* Copyright 2017 The Dawn Authors
//*
//* Licensed under the Apache License, Version 2.0 (the "License");
//* you may not use this file except in compliance with the License.
//* You may obtain a copy of the License at
//*
//* http://www.apache.org/licenses/LICENSE-2.0
//*
//* Unless required by applicable law or agreed to in writing, software
//* distributed under the License is distributed on an "AS IS" BASIS,
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and
//* limitations under the License.
#ifndef DAWNNATIVE_DAWN_STRUCTS_H_
#define DAWNNATIVE_DAWN_STRUCTS_H_
#include "dawn/dawncpp.h"
#include "dawn_native/Forward.h"
namespace dawn_native {
{% for type in by_category["structure"] %}
struct {{as_cppType(type.name)}} {
{% if type.extensible %}
const void* nextInChain = nullptr;
{% endif %}
{% for member in type.members %}
{% if member.type.category == "object" %}
{{decorate(as_varName(member.name), as_cppType(member.type.name) + "Base*", member)}};
{% elif member.type.category == "structure" %}
{{as_annotated_cppType(member)}};
{% elif member.type.category in ["enum", "bitmask"] %}
{{decorate(as_varName(member.name), "dawn::" + as_cppType(member.type.name), member)}};
{% else %}
{{as_annotated_cppType(member)}};
{% endif %}
{% endfor %}
};
{% endfor %}
} // namespace dawn_native
#endif // DAWNNATIVE_DAWN_STRUCTS_H_