Make templates webgpu_cpp.h and webgpu_cpp_print.h flexible

Rename webgpu_cpp.h to api_cpp.h and webgpu_cpp_print.h to api_cpp_print.h.

BUG=dawn:1201
Change-Id: Icceee0fd70fb6497a9e2b0891b5c5843787593f9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71720
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-07 00:46:35 +00:00 committed by Dawn LUCI CQ
parent 4539a48355
commit c7d4f2c9f1
4 changed files with 42 additions and 31 deletions

View File

@ -29,7 +29,7 @@
"category": "function",
"returns": "instance",
"args": [
{"name": "descriptor", "type": "instance descriptor", "annotation": "const*"}
{"name": "descriptor", "type": "instance descriptor", "annotation": "const*", "optional": true}
]
},
"proc": {

View File

@ -758,11 +758,11 @@ class MultiGeneratorFromDawnJSON(Generator):
metadata = params_dawn['metadata']
RENDER_PARAMS_BASE = make_base_render_params(metadata)
api_file_name = metadata.api.lower()
api = metadata.api.lower()
if 'dawn_headers' in targets:
prefix = metadata.proc_table_prefix.lower()
renders.append(
FileRender('api.h', 'src/include/dawn/' + api_file_name + '.h',
FileRender('api.h', 'src/include/dawn/' + api + '.h',
[RENDER_PARAMS_BASE, params_dawn]))
renders.append(
FileRender('dawn_proc_table.h',
@ -771,12 +771,12 @@ class MultiGeneratorFromDawnJSON(Generator):
if 'dawncpp_headers' in targets:
renders.append(
FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.h',
FileRender('api_cpp.h', 'src/include/dawn/' + api + '_cpp.h',
[RENDER_PARAMS_BASE, params_dawn]))
renders.append(
FileRender('webgpu_cpp_print.h',
'src/include/dawn/webgpu_cpp_print.h',
FileRender('api_cpp_print.h',
'src/include/dawn/' + api + '_cpp_print.h',
[RENDER_PARAMS_BASE, params_dawn]))
if 'dawn_proc' in targets:
@ -797,17 +797,17 @@ class MultiGeneratorFromDawnJSON(Generator):
params_upstream = parse_json(loaded_json,
enabled_tags=['upstream', 'native'])
renders.append(
FileRender('api.h', 'webgpu-headers/' + api_file_name + '.h',
FileRender('api.h', 'webgpu-headers/' + api + '.h',
[RENDER_PARAMS_BASE, params_upstream]))
if 'emscripten_bits' in targets:
params_emscripten = parse_json(
loaded_json, enabled_tags=['upstream', 'emscripten'])
renders.append(
FileRender('api.h', 'emscripten-bits/' + api_file_name + '.h',
FileRender('api.h', 'emscripten-bits/' + api + '.h',
[RENDER_PARAMS_BASE, params_emscripten]))
renders.append(
FileRender('webgpu_cpp.h', 'emscripten-bits/webgpu_cpp.h',
FileRender('api_cpp.h', 'emscripten-bits/' + api + '_cpp.h',
[RENDER_PARAMS_BASE, params_emscripten]))
renders.append(
FileRender('webgpu_cpp.cpp', 'emscripten-bits/webgpu_cpp.cpp',

View File

@ -11,13 +11,15 @@
//* 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 WEBGPU_CPP_H_
#define WEBGPU_CPP_H_
{% set API = metadata.api.upper() %}
{% set api = API.lower() %}
#ifndef {{API}}_CPP_H_
#define {{API}}_CPP_H_
#include "dawn/webgpu.h"
#include "dawn/{{api}}.h"
#include "dawn/EnumClassBitmasks.h"
namespace wgpu {
namespace {{metadata.namespace}} {
{% set c_prefix = metadata.c_prefix %}
{% for constant in by_category["constant"] %}
@ -75,10 +77,10 @@ namespace wgpu {
public:
ObjectBase() = default;
ObjectBase(CType handle): mHandle(handle) {
if (mHandle) Derived::WGPUReference(mHandle);
if (mHandle) Derived::{{c_prefix}}Reference(mHandle);
}
~ObjectBase() {
if (mHandle) Derived::WGPURelease(mHandle);
if (mHandle) Derived::{{c_prefix}}Release(mHandle);
}
ObjectBase(ObjectBase const& other)
@ -86,9 +88,9 @@ namespace wgpu {
}
Derived& operator=(ObjectBase const& other) {
if (&other != this) {
if (mHandle) Derived::WGPURelease(mHandle);
if (mHandle) Derived::{{c_prefix}}Release(mHandle);
mHandle = other.mHandle;
if (mHandle) Derived::WGPUReference(mHandle);
if (mHandle) Derived::{{c_prefix}}Reference(mHandle);
}
return static_cast<Derived&>(*this);
@ -100,7 +102,7 @@ namespace wgpu {
}
Derived& operator=(ObjectBase&& other) {
if (&other != this) {
if (mHandle) Derived::WGPURelease(mHandle);
if (mHandle) Derived::{{c_prefix}}Release(mHandle);
mHandle = other.mHandle;
other.mHandle = 0;
}
@ -111,7 +113,7 @@ namespace wgpu {
ObjectBase(std::nullptr_t) {}
Derived& operator=(std::nullptr_t) {
if (mHandle != nullptr) {
Derived::WGPURelease(mHandle);
Derived::{{c_prefix}}Release(mHandle);
mHandle = nullptr;
}
return static_cast<Derived&>(*this);
@ -188,14 +190,21 @@ namespace wgpu {
private:
friend ObjectBase<{{CppType}}, {{CType}}>;
static void WGPUReference({{CType}} handle);
static void WGPURelease({{CType}} handle);
static void {{c_prefix}}Reference({{CType}} handle);
static void {{c_prefix}}Release({{CType}} handle);
};
{% endfor %}
Instance CreateInstance(InstanceDescriptor const * descriptor = nullptr);
Proc GetProcAddress(Device const& device, const char* procName);
{% for function in by_category["function"] %}
{{as_cppType(function.return_type.name)}} {{as_cppType(function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}
{{as_annotated_cppType(arg)}}
{{render_cpp_default_value(arg, False)}}
{%- endfor -%}
);
{% endfor %}
struct ChainedStruct {
ChainedStruct const * nextInChain = nullptr;
@ -233,6 +242,6 @@ namespace wgpu {
};
{% endfor %}
} // namespace wgpu
} // namespace {{metadata.namespace}}
#endif // WEBGPU_CPP_H_
#endif // {{API}}_CPP_H_

View File

@ -12,17 +12,19 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#ifndef WEBGPU_CPP_PRINT_H_
#define WEBGPU_CPP_PRINT_H_
{% set API = metadata.api.upper() %}
{% set api = API.lower() %}
#ifndef {{API}}_CPP_PRINT_H_
#define {{API}}_CPP_PRINT_H_
#include "dawn/webgpu_cpp.h"
#include "dawn/{{api}}_cpp.h"
#include <iomanip>
#include <ios>
#include <ostream>
#include <type_traits>
namespace wgpu {
namespace {{metadata.namespace}} {
{% for type in by_category["enum"] %}
template <typename CharT, typename Traits>
@ -85,6 +87,6 @@ namespace wgpu {
}
{% endfor %}
} // namespace wgpu
} // namespace {{metadata.namespace}}
#endif // WEBGPU_CPP_PRINT_H_
#endif // {{API}}_CPP_PRINT_H_