mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-13 19:01:24 +00:00
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:
parent
4539a48355
commit
c7d4f2c9f1
@ -29,7 +29,7 @@
|
|||||||
"category": "function",
|
"category": "function",
|
||||||
"returns": "instance",
|
"returns": "instance",
|
||||||
"args": [
|
"args": [
|
||||||
{"name": "descriptor", "type": "instance descriptor", "annotation": "const*"}
|
{"name": "descriptor", "type": "instance descriptor", "annotation": "const*", "optional": true}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"proc": {
|
"proc": {
|
||||||
|
@ -758,11 +758,11 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||||||
metadata = params_dawn['metadata']
|
metadata = params_dawn['metadata']
|
||||||
RENDER_PARAMS_BASE = make_base_render_params(metadata)
|
RENDER_PARAMS_BASE = make_base_render_params(metadata)
|
||||||
|
|
||||||
api_file_name = metadata.api.lower()
|
api = metadata.api.lower()
|
||||||
if 'dawn_headers' in targets:
|
if 'dawn_headers' in targets:
|
||||||
prefix = metadata.proc_table_prefix.lower()
|
prefix = metadata.proc_table_prefix.lower()
|
||||||
renders.append(
|
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]))
|
[RENDER_PARAMS_BASE, params_dawn]))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('dawn_proc_table.h',
|
FileRender('dawn_proc_table.h',
|
||||||
@ -771,12 +771,12 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||||||
|
|
||||||
if 'dawncpp_headers' in targets:
|
if 'dawncpp_headers' in targets:
|
||||||
renders.append(
|
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]))
|
[RENDER_PARAMS_BASE, params_dawn]))
|
||||||
|
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('webgpu_cpp_print.h',
|
FileRender('api_cpp_print.h',
|
||||||
'src/include/dawn/webgpu_cpp_print.h',
|
'src/include/dawn/' + api + '_cpp_print.h',
|
||||||
[RENDER_PARAMS_BASE, params_dawn]))
|
[RENDER_PARAMS_BASE, params_dawn]))
|
||||||
|
|
||||||
if 'dawn_proc' in targets:
|
if 'dawn_proc' in targets:
|
||||||
@ -797,17 +797,17 @@ class MultiGeneratorFromDawnJSON(Generator):
|
|||||||
params_upstream = parse_json(loaded_json,
|
params_upstream = parse_json(loaded_json,
|
||||||
enabled_tags=['upstream', 'native'])
|
enabled_tags=['upstream', 'native'])
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('api.h', 'webgpu-headers/' + api_file_name + '.h',
|
FileRender('api.h', 'webgpu-headers/' + api + '.h',
|
||||||
[RENDER_PARAMS_BASE, params_upstream]))
|
[RENDER_PARAMS_BASE, params_upstream]))
|
||||||
|
|
||||||
if 'emscripten_bits' in targets:
|
if 'emscripten_bits' in targets:
|
||||||
params_emscripten = parse_json(
|
params_emscripten = parse_json(
|
||||||
loaded_json, enabled_tags=['upstream', 'emscripten'])
|
loaded_json, enabled_tags=['upstream', 'emscripten'])
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('api.h', 'emscripten-bits/' + api_file_name + '.h',
|
FileRender('api.h', 'emscripten-bits/' + api + '.h',
|
||||||
[RENDER_PARAMS_BASE, params_emscripten]))
|
[RENDER_PARAMS_BASE, params_emscripten]))
|
||||||
renders.append(
|
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]))
|
[RENDER_PARAMS_BASE, params_emscripten]))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('webgpu_cpp.cpp', 'emscripten-bits/webgpu_cpp.cpp',
|
FileRender('webgpu_cpp.cpp', 'emscripten-bits/webgpu_cpp.cpp',
|
||||||
|
@ -11,13 +11,15 @@
|
|||||||
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
//* 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 WEBGPU_CPP_H_
|
{% set API = metadata.api.upper() %}
|
||||||
#define WEBGPU_CPP_H_
|
{% set api = API.lower() %}
|
||||||
|
#ifndef {{API}}_CPP_H_
|
||||||
|
#define {{API}}_CPP_H_
|
||||||
|
|
||||||
#include "dawn/webgpu.h"
|
#include "dawn/{{api}}.h"
|
||||||
#include "dawn/EnumClassBitmasks.h"
|
#include "dawn/EnumClassBitmasks.h"
|
||||||
|
|
||||||
namespace wgpu {
|
namespace {{metadata.namespace}} {
|
||||||
|
|
||||||
{% set c_prefix = metadata.c_prefix %}
|
{% set c_prefix = metadata.c_prefix %}
|
||||||
{% for constant in by_category["constant"] %}
|
{% for constant in by_category["constant"] %}
|
||||||
@ -75,10 +77,10 @@ namespace wgpu {
|
|||||||
public:
|
public:
|
||||||
ObjectBase() = default;
|
ObjectBase() = default;
|
||||||
ObjectBase(CType handle): mHandle(handle) {
|
ObjectBase(CType handle): mHandle(handle) {
|
||||||
if (mHandle) Derived::WGPUReference(mHandle);
|
if (mHandle) Derived::{{c_prefix}}Reference(mHandle);
|
||||||
}
|
}
|
||||||
~ObjectBase() {
|
~ObjectBase() {
|
||||||
if (mHandle) Derived::WGPURelease(mHandle);
|
if (mHandle) Derived::{{c_prefix}}Release(mHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectBase(ObjectBase const& other)
|
ObjectBase(ObjectBase const& other)
|
||||||
@ -86,9 +88,9 @@ namespace wgpu {
|
|||||||
}
|
}
|
||||||
Derived& operator=(ObjectBase const& other) {
|
Derived& operator=(ObjectBase const& other) {
|
||||||
if (&other != this) {
|
if (&other != this) {
|
||||||
if (mHandle) Derived::WGPURelease(mHandle);
|
if (mHandle) Derived::{{c_prefix}}Release(mHandle);
|
||||||
mHandle = other.mHandle;
|
mHandle = other.mHandle;
|
||||||
if (mHandle) Derived::WGPUReference(mHandle);
|
if (mHandle) Derived::{{c_prefix}}Reference(mHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<Derived&>(*this);
|
return static_cast<Derived&>(*this);
|
||||||
@ -100,7 +102,7 @@ namespace wgpu {
|
|||||||
}
|
}
|
||||||
Derived& operator=(ObjectBase&& other) {
|
Derived& operator=(ObjectBase&& other) {
|
||||||
if (&other != this) {
|
if (&other != this) {
|
||||||
if (mHandle) Derived::WGPURelease(mHandle);
|
if (mHandle) Derived::{{c_prefix}}Release(mHandle);
|
||||||
mHandle = other.mHandle;
|
mHandle = other.mHandle;
|
||||||
other.mHandle = 0;
|
other.mHandle = 0;
|
||||||
}
|
}
|
||||||
@ -111,7 +113,7 @@ namespace wgpu {
|
|||||||
ObjectBase(std::nullptr_t) {}
|
ObjectBase(std::nullptr_t) {}
|
||||||
Derived& operator=(std::nullptr_t) {
|
Derived& operator=(std::nullptr_t) {
|
||||||
if (mHandle != nullptr) {
|
if (mHandle != nullptr) {
|
||||||
Derived::WGPURelease(mHandle);
|
Derived::{{c_prefix}}Release(mHandle);
|
||||||
mHandle = nullptr;
|
mHandle = nullptr;
|
||||||
}
|
}
|
||||||
return static_cast<Derived&>(*this);
|
return static_cast<Derived&>(*this);
|
||||||
@ -188,14 +190,21 @@ namespace wgpu {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend ObjectBase<{{CppType}}, {{CType}}>;
|
friend ObjectBase<{{CppType}}, {{CType}}>;
|
||||||
static void WGPUReference({{CType}} handle);
|
static void {{c_prefix}}Reference({{CType}} handle);
|
||||||
static void WGPURelease({{CType}} handle);
|
static void {{c_prefix}}Release({{CType}} handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
Instance CreateInstance(InstanceDescriptor const * descriptor = nullptr);
|
{% for function in by_category["function"] %}
|
||||||
Proc GetProcAddress(Device const& device, const char* procName);
|
{{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 {
|
struct ChainedStruct {
|
||||||
ChainedStruct const * nextInChain = nullptr;
|
ChainedStruct const * nextInChain = nullptr;
|
||||||
@ -233,6 +242,6 @@ namespace wgpu {
|
|||||||
};
|
};
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
} // namespace wgpu
|
} // namespace {{metadata.namespace}}
|
||||||
|
|
||||||
#endif // WEBGPU_CPP_H_
|
#endif // {{API}}_CPP_H_
|
@ -12,17 +12,19 @@
|
|||||||
//* 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 WEBGPU_CPP_PRINT_H_
|
{% set API = metadata.api.upper() %}
|
||||||
#define WEBGPU_CPP_PRINT_H_
|
{% 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 <iomanip>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace wgpu {
|
namespace {{metadata.namespace}} {
|
||||||
|
|
||||||
{% for type in by_category["enum"] %}
|
{% for type in by_category["enum"] %}
|
||||||
template <typename CharT, typename Traits>
|
template <typename CharT, typename Traits>
|
||||||
@ -85,6 +87,6 @@ namespace wgpu {
|
|||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
} // namespace wgpu
|
} // namespace {{metadata.namespace}}
|
||||||
|
|
||||||
#endif // WEBGPU_CPP_PRINT_H_
|
#endif // {{API}}_CPP_PRINT_H_
|
Loading…
x
Reference in New Issue
Block a user