Introduce the webgpu[_cpp].h headers.

webgpu.h is the "official" header for WebGPU in native and is being
developed in https://github.com/webgpu-native/webgpu-headers

dawn.h and dawncpp.h are changed to become webgpu.h and webgpu_cpp.h
respectively and use the new naming convention. New dawn.h and dawncpp.h
headers are created that just proxy the types, constants and functions
to their WebGPU counterpart.

Almost no naming change is done in Dawn in this commit, which help check
that the proxying headers work correctly. A couple changes were
necessary, in particular for tests of the internal of dawncpp.h, and a
workaround for a standard library bug for std::underlying_type was
removed because it is no longer needed and got in the way.

Finally since some templates were renamed to match the name of the file
they create instead of using the generic "api" name.

BUG=dawn:22

Change-Id: I12ee22d0b02ccb5b8a52ceccabb3e63ce74da007
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12480
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez
2019-10-21 20:04:10 +00:00
committed by Commit Bot service account
parent 16f1068025
commit 2c8b5c6370
23 changed files with 395 additions and 273 deletions

View File

@@ -349,6 +349,12 @@ def as_varName(*names):
return names[0].camelCase() + ''.join([name.CamelCase() for name in names[1:]])
def as_cType(name):
if name.native:
return name.concatcase()
else:
return 'WGPU' + name.CamelCase()
def as_cTypeDawn(name):
if name.native:
return name.concatcase()
else:
@@ -405,6 +411,10 @@ def annotated(typ, arg):
return decorate(name, typ, arg)
def as_cEnum(type_name, value_name):
assert(not type_name.native and not value_name.native)
return 'WGPU' + type_name.CamelCase() + '_' + value_name.CamelCase()
def as_cEnumDawn(type_name, value_name):
assert(not type_name.native and not value_name.native)
return 'DAWN' + '_' + type_name.SNAKE_CASE() + '_' + value_name.SNAKE_CASE()
@@ -415,6 +425,10 @@ def as_cppEnum(value_name):
return value_name.CamelCase()
def as_cMethod(type_name, method_name):
assert(not type_name.native and not method_name.native)
return 'wgpu' + type_name.CamelCase() + method_name.CamelCase()
def as_cMethodDawn(type_name, method_name):
assert(not type_name.native and not method_name.native)
return 'dawn' + type_name.CamelCase() + method_name.CamelCase()
@@ -423,6 +437,10 @@ def as_MethodSuffix(type_name, method_name):
return type_name.CamelCase() + method_name.CamelCase()
def as_cProc(type_name, method_name):
assert(not type_name.native and not method_name.native)
return 'WGPU' + 'Proc' + type_name.CamelCase() + method_name.CamelCase()
def as_cProcDawn(type_name, method_name):
assert(not type_name.native and not method_name.native)
return 'Dawn' + 'Proc' + type_name.CamelCase() + method_name.CamelCase()
@@ -488,11 +506,15 @@ class MultiGeneratorFromDawnJSON(Generator):
'as_annotated_cType': lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg),
'as_annotated_cppType': lambda arg: annotated(as_cppType(arg.type.name), arg),
'as_cEnum': as_cEnum,
'as_cEnumDawn': as_cEnumDawn,
'as_cppEnum': as_cppEnum,
'as_cMethod': as_cMethod,
'as_cMethodDawn': as_cMethodDawn,
'as_MethodSuffix': as_MethodSuffix,
'as_cProc': as_cProc,
'as_cProcDawn': as_cProcDawn,
'as_cType': as_cType,
'as_cTypeDawn': as_cTypeDawn,
'as_cppType': as_cppType,
'convert_cType_to_cppType': convert_cType_to_cppType,
'as_varName': as_varName,
@@ -506,17 +528,19 @@ class MultiGeneratorFromDawnJSON(Generator):
cpp_params = {'native_methods': lambda typ: cpp_native_methods(api_params['types'], typ)}
if 'dawn_headers' in targets:
renders.append(FileRender('api.h', 'src/include/dawn/dawn.h', [base_params, api_params, c_params]))
renders.append(FileRender('api_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params, c_params]))
renders.append(FileRender('webgpu.h', 'src/include/dawn/webgpu.h', [base_params, api_params, c_params]))
renders.append(FileRender('dawn.h', 'src/include/dawn/dawn.h', [base_params, api_params, c_params]))
renders.append(FileRender('dawn_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params, c_params]))
if 'dawncpp_headers' in targets:
renders.append(FileRender('apicpp.h', 'src/include/dawn/dawncpp.h', [base_params, api_params, cpp_params]))
renders.append(FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.h', [base_params, api_params, cpp_params]))
renders.append(FileRender('dawncpp.h', 'src/include/dawn/dawncpp.h', [base_params, api_params, cpp_params]))
if 'dawn_proc' in targets:
renders.append(FileRender('api_proc.c', 'src/dawn/dawn_proc.c', [base_params, api_params, c_params]))
renders.append(FileRender('dawn_proc.c', 'src/dawn/dawn_proc.c', [base_params, api_params, c_params]))
if 'dawncpp' in targets:
renders.append(FileRender('apicpp.cpp', 'src/dawn/dawncpp.cpp', [base_params, api_params, cpp_params]))
renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params, cpp_params]))
if 'mock_dawn' in targets:
renders.append(FileRender('mock_api.h', 'src/dawn/mock_dawn.h', [base_params, api_params, c_params]))

View File

@@ -1,118 +0,0 @@
//* 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 DAWN_DAWN_H_
#define DAWN_DAWN_H_
#include "dawn/dawn_export.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
const uint64_t DAWN_WHOLE_SIZE = 0xffffffffffffffffULL; // UINT64_MAX
typedef uint32_t WGPUFlags;
{% for type in by_category["object"] %}
typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}};
{% endfor %}
{% for type in by_category["enum"] + by_category["bitmask"] %}
typedef enum {{as_cType(type.name)}} {
{% for value in type.values %}
{{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "08X")}},
{% endfor %}
{{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF
} {{as_cType(type.name)}};
{% if type.category == "bitmask" %}
typedef WGPUFlags {{as_cType(type.name)}}Flags;
{% endif %}
{% endfor %}
{% for type in by_category["structure"] %}
typedef struct {{as_cType(type.name)}} {
{% if type.extensible %}
void const * nextInChain;
{% endif %}
{% for member in type.members %}
{{as_annotated_cType(member)}};
{% endfor %}
} {{as_cType(type.name)}};
{% endfor %}
#ifdef __cplusplus
extern "C" {
#endif
// Custom types depending on the target language
typedef void (*DawnBufferCreateMappedCallback)(DawnBufferMapAsyncStatus status,
DawnCreateBufferMappedResult result,
void* userdata);
typedef void (*DawnBufferMapReadCallback)(DawnBufferMapAsyncStatus status,
const void* data,
uint64_t dataLength,
void* userdata);
typedef void (*DawnBufferMapWriteCallback)(DawnBufferMapAsyncStatus status,
void* data,
uint64_t dataLength,
void* userdata);
typedef void (*DawnFenceOnCompletionCallback)(DawnFenceCompletionStatus status, void* userdata);
typedef void (*DawnErrorCallback)(DawnErrorType type, const char* message, void* userdata);
typedef void (*DawnProc)();
#if !defined(DAWN_SKIP_PROCS)
typedef DawnProc (*DawnProcGetProcAddress)(DawnDevice device, const char* procName);
{% for type in by_category["object"] %}
// Procs of {{type.name.CamelCase()}}
{% for method in native_methods(type) %}
typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})(
{{-as_cType(type.name)}} {{as_varName(type.name)}}
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endfor %}
{% endfor %}
#endif // !defined(DAWN_SKIP_PROCS)
#if !defined(DAWN_SKIP_DECLARATIONS)
DAWN_EXPORT DawnProc DawnGetProcAddress(DawnDevice device, const char* procName);
{% for type in by_category["object"] %}
// Methods of {{type.name.CamelCase()}}
{% for method in native_methods(type) %}
DAWN_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
{{-as_cType(type.name)}} {{as_varName(type.name)}}
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endfor %}
{% endfor %}
#endif // !defined(DAWN_SKIP_DECLARATIONS)
#ifdef __cplusplus
} // extern "C"
#endif
#endif // DAWN_DAWN_H_

View File

@@ -0,0 +1,61 @@
//* 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.
// This temporary header translates all the previous Dawn C API to the webgpu.h
// API so that during a small transition period both headers are supported.
#ifndef DAWN_DAWN_H_
#define DAWN_DAWN_H_
#include "webgpu.h"
#define DAWN_WHOLE_SIZE WGPU_WHOLE_SIZE
{% for type in by_category["object"] %}
typedef {{as_cType(type.name)}} {{as_cTypeDawn(type.name)}};
typedef {{as_cType(type.name)}}Impl {{as_cTypeDawn(type.name)}}Impl;
{% for method in native_methods(type) %}
typedef {{as_cProc(type.name, method.name)}} {{as_cProcDawn(type.name, method.name)}};
#define {{as_cMethodDawn(type.name, method.name)}} {{as_cMethod(type.name, method.name)}}
{% endfor %}
{% endfor %}
{% for type in by_category["enum"] + by_category["bitmask"] %}
typedef {{as_cType(type.name)}} {{as_cTypeDawn(type.name)}};
{% if type.category == "bitmask" %}
typedef {{as_cType(type.name)}}Flags {{as_cTypeDawn(type.name)}}Flags;
{% endif %}
{% for value in type.values %}
#define {{as_cEnumDawn(type.name, value.name)}} {{as_cEnum(type.name, value.name)}}
{% endfor %}
#define {{as_cEnumDawn(type.name, Name("force32"))}} {{as_cEnum(type.name, Name("force32"))}}
{% endfor %}
{% for type in by_category["structure"] %}
typedef {{as_cType(type.name)}} {{as_cTypeDawn(type.name)}};
{% endfor %}
typedef WGPUBufferCreateMappedCallback DawnBufferCreateMappedCallback;
typedef WGPUBufferMapReadCallback DawnBufferMapReadCallback;
typedef WGPUBufferMapWriteCallback DawnBufferMapWriteCallback;
typedef WGPUFenceOnCompletionCallback DawnFenceOnCompletionCallback;
typedef WGPUErrorCallback DawnErrorCallback;
typedef WGPUProc DawnProc;
typedef WGPUProcGetProcAddress DawnProcGetProcAddress;
#define DawnGetProcAddress WGPUGetProcAddress
#endif // DAWN_DAWN_H_

View File

@@ -99,7 +99,7 @@ namespace dawn_native {
return entry->proc;
}
if (strcmp(procName, "dawnGetProcAddress") == 0) {
if (strcmp(procName, "wgpuGetProcAddress") == 0) {
return reinterpret_cast<DawnProc>(NativeGetProcAddress);
}

View File

@@ -26,7 +26,7 @@ void dawnProcSetProcs(const DawnProcTable* procs_) {
}
}
DawnProc DawnGetProcAddress(DawnDevice device, const char* procName) {
WGPUProc WGPUGetProcAddress(WGPUDevice device, const char* procName) {
return procs.getProcAddress(device, procName);
}

View File

@@ -15,10 +15,10 @@
#ifndef DAWN_DAWN_PROC_TABLE_H_
#define DAWN_DAWN_PROC_TABLE_H_
#include "dawn/dawn.h"
#include "dawn/webgpu.h"
typedef struct DawnProcTable {
DawnProcGetProcAddress getProcAddress;
WGPUProcGetProcAddress getProcAddress;
{% for type in by_category["object"] %}
{% for method in native_methods(type) %}

View File

@@ -457,31 +457,31 @@ namespace dawn_wire {
{% endfor %}
// Implementations of serialization/deserialization of DawnDeviceProperties.
size_t SerializedDawnDevicePropertiesSize(const DawnDeviceProperties* deviceProperties) {
size_t SerializedWGPUDevicePropertiesSize(const DawnDeviceProperties* deviceProperties) {
return sizeof(DawnDeviceProperties) +
DawnDevicePropertiesGetExtraRequiredSize(*deviceProperties);
WGPUDevicePropertiesGetExtraRequiredSize(*deviceProperties);
}
void SerializeDawnDeviceProperties(const DawnDeviceProperties* deviceProperties,
void SerializeWGPUDeviceProperties(const DawnDeviceProperties* deviceProperties,
char* serializeBuffer) {
size_t devicePropertiesSize = SerializedDawnDevicePropertiesSize(deviceProperties);
DawnDevicePropertiesTransfer* transfer =
reinterpret_cast<DawnDevicePropertiesTransfer*>(serializeBuffer);
size_t devicePropertiesSize = SerializedWGPUDevicePropertiesSize(deviceProperties);
WGPUDevicePropertiesTransfer* transfer =
reinterpret_cast<WGPUDevicePropertiesTransfer*>(serializeBuffer);
serializeBuffer += devicePropertiesSize;
DawnDevicePropertiesSerialize(*deviceProperties, transfer, &serializeBuffer);
WGPUDevicePropertiesSerialize(*deviceProperties, transfer, &serializeBuffer);
}
bool DeserializeDawnDeviceProperties(DawnDeviceProperties* deviceProperties,
bool DeserializeWGPUDeviceProperties(DawnDeviceProperties* deviceProperties,
const volatile char* deserializeBuffer) {
size_t devicePropertiesSize = SerializedDawnDevicePropertiesSize(deviceProperties);
const volatile DawnDevicePropertiesTransfer* transfer = nullptr;
size_t devicePropertiesSize = SerializedWGPUDevicePropertiesSize(deviceProperties);
const volatile WGPUDevicePropertiesTransfer* transfer = nullptr;
if (GetPtrFromBuffer(&deserializeBuffer, &devicePropertiesSize, 1, &transfer) !=
DeserializeResult::Success) {
return false;
}
return DawnDevicePropertiesDeserialize(deviceProperties, transfer, &deserializeBuffer,
return WGPUDevicePropertiesDeserialize(deviceProperties, transfer, &deserializeBuffer,
&devicePropertiesSize,
nullptr) == DeserializeResult::Success;
}

View File

@@ -121,7 +121,7 @@ namespace dawn_wire { namespace client {
return entry->proc;
}
if (strcmp(procName, "dawnGetProcAddress") == 0) {
if (strcmp(procName, "wgpuGetProcAddress") == 0) {
return reinterpret_cast<DawnProc>(ClientGetProcAddress);
}

View File

@@ -0,0 +1,54 @@
//* 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.
// This temporary header translates all the previous Dawn C++ API to the webgpu_cpp.h
// API so that during a small transition period both headers are supported.
#ifndef DAWN_DAWNCPP_H_
#define DAWN_DAWNCPP_H_
#include "dawn/dawn.h"
#include "dawn/webgpu_cpp.h"
namespace dawn {
static constexpr uint64_t kWholeSize = wgpu::kWholeSize;
{% for type in by_category["enum"] %}
using {{as_cppType(type.name)}} = wgpu::{{as_cppType(type.name)}};
{% endfor %}
{% for type in by_category["bitmask"] %}
using {{as_cppType(type.name)}} = wgpu::{{as_cppType(type.name)}};
{% endfor %}
using Proc = wgpu::Proc;
{% for type in by_category["natively defined"] %}
using {{as_cppType(type.name)}} = wgpu::{{as_cppType(type.name)}};
{% endfor %}
{% for type in by_category["object"] %}
using {{as_cppType(type.name)}} = wgpu::{{as_cppType(type.name)}};
{% endfor %}
{% for type in by_category["structure"] %}
using {{as_cppType(type.name)}} = wgpu::{{as_cppType(type.name)}};
{% endfor %}
static inline Proc GetProcAddress(Device const& device, const char* procName) {
return wgpu::GetProcAddress(device, procName);
}
} // namespace dawn
#endif // DAWN_DAWNCPP_H_

View File

@@ -0,0 +1,148 @@
// BSD 3-Clause License
//
// Copyright (c) 2019, "WebGPU native" developers
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef WEBGPU_H_
#define WEBGPU_H_
#if defined(WGPU_SHARED_LIBRARY)
# if defined(_WIN32)
# if defined(WGPU_IMPLEMENTATION)
# define WGPU_EXPORT __declspec(dllexport)
# else
# define WGPU_EXPORT __declspec(dllimport)
# endif
# else // defined(_WIN32)
# if defined(WGPU_IMPLEMENTATION)
# define WGPU_EXPORT __attribute__((visibility("default")))
# else
# define WGPU_EXPORT
# endif
# endif // defined(_WIN32)
#else // defined(WGPU_SHARED_LIBRARY)
# define WGPU_EXPORT
#endif // defined(WGPU_SHARED_LIBRARY)
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
const uint64_t WGPU_WHOLE_SIZE = 0xffffffffffffffffULL; // UINT64_MAX
typedef uint32_t WGPUFlags;
{% for type in by_category["object"] %}
typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}};
{% endfor %}
{% for type in by_category["enum"] + by_category["bitmask"] %}
typedef enum {{as_cType(type.name)}} {
{% for value in type.values %}
{{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "08X")}},
{% endfor %}
{{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF
} {{as_cType(type.name)}};
{% if type.category == "bitmask" %}
typedef WGPUFlags {{as_cType(type.name)}}Flags;
{% endif %}
{% endfor %}
{% for type in by_category["structure"] %}
typedef struct {{as_cType(type.name)}} {
{% if type.extensible %}
void const * nextInChain;
{% endif %}
{% for member in type.members %}
{{as_annotated_cType(member)}};
{% endfor %}
} {{as_cType(type.name)}};
{% endfor %}
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*WGPUBufferCreateMappedCallback)(WGPUBufferMapAsyncStatus status,
WGPUCreateBufferMappedResult result,
void* userdata);
typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status,
const void* data,
uint64_t dataLength,
void* userdata);
typedef void (*WGPUBufferMapWriteCallback)(WGPUBufferMapAsyncStatus status,
void* data,
uint64_t dataLength,
void* userdata);
typedef void (*WGPUFenceOnCompletionCallback)(WGPUFenceCompletionStatus status, void* userdata);
typedef void (*WGPUErrorCallback)(WGPUErrorType type, const char* message, void* userdata);
typedef void (*WGPUProc)();
#if !defined(WGPU_SKIP_PROCS)
typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, const char* procName);
{% for type in by_category["object"] if len(native_methods(type)) > 0 %}
// Procs of {{type.name.CamelCase()}}
{% for method in native_methods(type) %}
typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})(
{{-as_cType(type.name)}} {{as_varName(type.name)}}
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endfor %}
{% endfor %}
#endif // !defined(WGPU_SKIP_PROCS)
#if !defined(WGPU_SKIP_DECLARATIONS)
WGPU_EXPORT WGPUProc WGPUGetProcAddress(WGPUDevice device, const char* procName);
{% for type in by_category["object"] if len(native_methods(type)) > 0 %}
// Methods of {{type.name.CamelCase()}}
{% for method in native_methods(type) %}
WGPU_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
{{-as_cType(type.name)}} {{as_varName(type.name)}}
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endfor %}
{% endfor %}
#endif // !defined(WGPU_SKIP_DECLARATIONS)
#ifdef __cplusplus
} // extern "C"
#endif
#endif // WEBGPU_H_

View File

@@ -12,9 +12,9 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#include "dawn/dawncpp.h"
#include "dawn/webgpu_cpp.h"
namespace dawn {
namespace wgpu {
{% for type in by_category["enum"] %}
{% set CppType = as_cppType(type.name) %}
@@ -112,12 +112,12 @@ namespace dawn {
{% endif %}
}
{% endfor %}
void {{CppType}}::DawnReference({{CType}} handle) {
void {{CppType}}::WGPUReference({{CType}} handle) {
if (handle != nullptr) {
{{as_cMethod(type.name, Name("reference"))}}(handle);
}
}
void {{CppType}}::DawnRelease({{CType}} handle) {
void {{CppType}}::WGPURelease({{CType}} handle) {
if (handle != nullptr) {
{{as_cMethod(type.name, Name("release"))}}(handle);
}
@@ -126,7 +126,7 @@ namespace dawn {
{% endfor %}
Proc GetProcAddress(Device const& device, const char* procName) {
return reinterpret_cast<Proc>(DawnGetProcAddress(device.Get(), procName));
return reinterpret_cast<Proc>(WGPUGetProcAddress(device.Get(), procName));
}
}

View File

@@ -12,15 +12,15 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#ifndef DAWN_DAWNCPP_H_
#define DAWN_DAWNCPP_H_
#ifndef WEBGPU_CPP_H_
#define WEBGPU_CPP_H_
#include "dawn/dawn.h"
#include "dawn/webgpu.h"
#include "dawn/EnumClassBitmasks.h"
namespace dawn {
namespace wgpu {
static constexpr uint64_t kWholeSize = DAWN_WHOLE_SIZE;
static constexpr uint64_t kWholeSize = WGPU_WHOLE_SIZE;
{% for type in by_category["enum"] %}
enum class {{as_cppType(type.name)}} : uint32_t {
@@ -48,7 +48,7 @@ namespace dawn {
{% endfor %}
using Proc = DawnProc;
using Proc = WGPUProc;
{% for type in by_category["natively defined"] %}
using {{as_cppType(type.name)}} = {{as_cType(type.name)}};
{% endfor %}
@@ -66,10 +66,10 @@ namespace dawn {
public:
ObjectBase() = default;
ObjectBase(CType handle): mHandle(handle) {
if (mHandle) Derived::DawnReference(mHandle);
if (mHandle) Derived::WGPUReference(mHandle);
}
~ObjectBase() {
if (mHandle) Derived::DawnRelease(mHandle);
if (mHandle) Derived::WGPURelease(mHandle);
}
ObjectBase(ObjectBase const& other)
@@ -77,9 +77,9 @@ namespace dawn {
}
Derived& operator=(ObjectBase const& other) {
if (&other != this) {
if (mHandle) Derived::DawnRelease(mHandle);
if (mHandle) Derived::WGPURelease(mHandle);
mHandle = other.mHandle;
if (mHandle) Derived::DawnReference(mHandle);
if (mHandle) Derived::WGPUReference(mHandle);
}
return static_cast<Derived&>(*this);
@@ -91,7 +91,7 @@ namespace dawn {
}
Derived& operator=(ObjectBase&& other) {
if (&other != this) {
if (mHandle) Derived::DawnRelease(mHandle);
if (mHandle) Derived::WGPURelease(mHandle);
mHandle = other.mHandle;
other.mHandle = 0;
}
@@ -102,7 +102,7 @@ namespace dawn {
ObjectBase(std::nullptr_t) {}
Derived& operator=(std::nullptr_t) {
if (mHandle != nullptr) {
Derived::DawnRelease(mHandle);
Derived::WGPURelease(mHandle);
mHandle = nullptr;
}
return static_cast<Derived&>(*this);
@@ -170,13 +170,13 @@ namespace dawn {
private:
friend ObjectBase<{{CppType}}, {{CType}}>;
static void DawnReference({{CType}} handle);
static void DawnRelease({{CType}} handle);
static void WGPUReference({{CType}} handle);
static void WGPURelease({{CType}} handle);
};
{% endfor %}
DAWN_EXPORT Proc GetProcAddress(Device const& device, const char* procName);
Proc GetProcAddress(Device const& device, const char* procName);
{% for type in by_category["structure"] %}
struct {{as_cppType(type.name)}} {
@@ -190,6 +190,6 @@ namespace dawn {
{% endfor %}
} // namespace dawn
} // namespace wgpu
#endif // DAWN_DAWNCPP_H_
#endif // WEBGPU_CPP_H_