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:
parent
16f1068025
commit
2c8b5c6370
|
@ -349,6 +349,12 @@ def as_varName(*names):
|
||||||
return names[0].camelCase() + ''.join([name.CamelCase() for name in names[1:]])
|
return names[0].camelCase() + ''.join([name.CamelCase() for name in names[1:]])
|
||||||
|
|
||||||
def as_cType(name):
|
def as_cType(name):
|
||||||
|
if name.native:
|
||||||
|
return name.concatcase()
|
||||||
|
else:
|
||||||
|
return 'WGPU' + name.CamelCase()
|
||||||
|
|
||||||
|
def as_cTypeDawn(name):
|
||||||
if name.native:
|
if name.native:
|
||||||
return name.concatcase()
|
return name.concatcase()
|
||||||
else:
|
else:
|
||||||
|
@ -405,6 +411,10 @@ def annotated(typ, arg):
|
||||||
return decorate(name, typ, arg)
|
return decorate(name, typ, arg)
|
||||||
|
|
||||||
def as_cEnum(type_name, value_name):
|
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)
|
assert(not type_name.native and not value_name.native)
|
||||||
return 'DAWN' + '_' + type_name.SNAKE_CASE() + '_' + value_name.SNAKE_CASE()
|
return 'DAWN' + '_' + type_name.SNAKE_CASE() + '_' + value_name.SNAKE_CASE()
|
||||||
|
|
||||||
|
@ -415,6 +425,10 @@ def as_cppEnum(value_name):
|
||||||
return value_name.CamelCase()
|
return value_name.CamelCase()
|
||||||
|
|
||||||
def as_cMethod(type_name, method_name):
|
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)
|
assert(not type_name.native and not method_name.native)
|
||||||
return 'dawn' + type_name.CamelCase() + method_name.CamelCase()
|
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()
|
return type_name.CamelCase() + method_name.CamelCase()
|
||||||
|
|
||||||
def as_cProc(type_name, method_name):
|
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)
|
assert(not type_name.native and not method_name.native)
|
||||||
return 'Dawn' + 'Proc' + type_name.CamelCase() + method_name.CamelCase()
|
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_cType': lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg),
|
||||||
'as_annotated_cppType': lambda arg: annotated(as_cppType(arg.type.name), arg),
|
'as_annotated_cppType': lambda arg: annotated(as_cppType(arg.type.name), arg),
|
||||||
'as_cEnum': as_cEnum,
|
'as_cEnum': as_cEnum,
|
||||||
|
'as_cEnumDawn': as_cEnumDawn,
|
||||||
'as_cppEnum': as_cppEnum,
|
'as_cppEnum': as_cppEnum,
|
||||||
'as_cMethod': as_cMethod,
|
'as_cMethod': as_cMethod,
|
||||||
|
'as_cMethodDawn': as_cMethodDawn,
|
||||||
'as_MethodSuffix': as_MethodSuffix,
|
'as_MethodSuffix': as_MethodSuffix,
|
||||||
'as_cProc': as_cProc,
|
'as_cProc': as_cProc,
|
||||||
|
'as_cProcDawn': as_cProcDawn,
|
||||||
'as_cType': as_cType,
|
'as_cType': as_cType,
|
||||||
|
'as_cTypeDawn': as_cTypeDawn,
|
||||||
'as_cppType': as_cppType,
|
'as_cppType': as_cppType,
|
||||||
'convert_cType_to_cppType': convert_cType_to_cppType,
|
'convert_cType_to_cppType': convert_cType_to_cppType,
|
||||||
'as_varName': as_varName,
|
'as_varName': as_varName,
|
||||||
|
@ -506,17 +528,19 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||||
cpp_params = {'native_methods': lambda typ: cpp_native_methods(api_params['types'], typ)}
|
cpp_params = {'native_methods': lambda typ: cpp_native_methods(api_params['types'], typ)}
|
||||||
|
|
||||||
if 'dawn_headers' in targets:
|
if 'dawn_headers' in targets:
|
||||||
renders.append(FileRender('api.h', 'src/include/dawn/dawn.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('api_proc_table.h', 'src/include/dawn/dawn_proc_table.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:
|
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:
|
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:
|
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:
|
if 'mock_dawn' in targets:
|
||||||
renders.append(FileRender('mock_api.h', 'src/dawn/mock_dawn.h', [base_params, api_params, c_params]))
|
renders.append(FileRender('mock_api.h', 'src/dawn/mock_dawn.h', [base_params, api_params, c_params]))
|
||||||
|
|
|
@ -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_
|
|
|
@ -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_
|
|
@ -99,7 +99,7 @@ namespace dawn_native {
|
||||||
return entry->proc;
|
return entry->proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(procName, "dawnGetProcAddress") == 0) {
|
if (strcmp(procName, "wgpuGetProcAddress") == 0) {
|
||||||
return reinterpret_cast<DawnProc>(NativeGetProcAddress);
|
return reinterpret_cast<DawnProc>(NativeGetProcAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
return procs.getProcAddress(device, procName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
#ifndef DAWN_DAWN_PROC_TABLE_H_
|
#ifndef DAWN_DAWN_PROC_TABLE_H_
|
||||||
#define DAWN_DAWN_PROC_TABLE_H_
|
#define DAWN_DAWN_PROC_TABLE_H_
|
||||||
|
|
||||||
#include "dawn/dawn.h"
|
#include "dawn/webgpu.h"
|
||||||
|
|
||||||
typedef struct DawnProcTable {
|
typedef struct DawnProcTable {
|
||||||
DawnProcGetProcAddress getProcAddress;
|
WGPUProcGetProcAddress getProcAddress;
|
||||||
|
|
||||||
{% for type in by_category["object"] %}
|
{% for type in by_category["object"] %}
|
||||||
{% for method in native_methods(type) %}
|
{% for method in native_methods(type) %}
|
|
@ -457,31 +457,31 @@ namespace dawn_wire {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
// Implementations of serialization/deserialization of DawnDeviceProperties.
|
// Implementations of serialization/deserialization of DawnDeviceProperties.
|
||||||
size_t SerializedDawnDevicePropertiesSize(const DawnDeviceProperties* deviceProperties) {
|
size_t SerializedWGPUDevicePropertiesSize(const DawnDeviceProperties* deviceProperties) {
|
||||||
return sizeof(DawnDeviceProperties) +
|
return sizeof(DawnDeviceProperties) +
|
||||||
DawnDevicePropertiesGetExtraRequiredSize(*deviceProperties);
|
WGPUDevicePropertiesGetExtraRequiredSize(*deviceProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializeDawnDeviceProperties(const DawnDeviceProperties* deviceProperties,
|
void SerializeWGPUDeviceProperties(const DawnDeviceProperties* deviceProperties,
|
||||||
char* serializeBuffer) {
|
char* serializeBuffer) {
|
||||||
size_t devicePropertiesSize = SerializedDawnDevicePropertiesSize(deviceProperties);
|
size_t devicePropertiesSize = SerializedWGPUDevicePropertiesSize(deviceProperties);
|
||||||
DawnDevicePropertiesTransfer* transfer =
|
WGPUDevicePropertiesTransfer* transfer =
|
||||||
reinterpret_cast<DawnDevicePropertiesTransfer*>(serializeBuffer);
|
reinterpret_cast<WGPUDevicePropertiesTransfer*>(serializeBuffer);
|
||||||
serializeBuffer += devicePropertiesSize;
|
serializeBuffer += devicePropertiesSize;
|
||||||
|
|
||||||
DawnDevicePropertiesSerialize(*deviceProperties, transfer, &serializeBuffer);
|
WGPUDevicePropertiesSerialize(*deviceProperties, transfer, &serializeBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeserializeDawnDeviceProperties(DawnDeviceProperties* deviceProperties,
|
bool DeserializeWGPUDeviceProperties(DawnDeviceProperties* deviceProperties,
|
||||||
const volatile char* deserializeBuffer) {
|
const volatile char* deserializeBuffer) {
|
||||||
size_t devicePropertiesSize = SerializedDawnDevicePropertiesSize(deviceProperties);
|
size_t devicePropertiesSize = SerializedWGPUDevicePropertiesSize(deviceProperties);
|
||||||
const volatile DawnDevicePropertiesTransfer* transfer = nullptr;
|
const volatile WGPUDevicePropertiesTransfer* transfer = nullptr;
|
||||||
if (GetPtrFromBuffer(&deserializeBuffer, &devicePropertiesSize, 1, &transfer) !=
|
if (GetPtrFromBuffer(&deserializeBuffer, &devicePropertiesSize, 1, &transfer) !=
|
||||||
DeserializeResult::Success) {
|
DeserializeResult::Success) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DawnDevicePropertiesDeserialize(deviceProperties, transfer, &deserializeBuffer,
|
return WGPUDevicePropertiesDeserialize(deviceProperties, transfer, &deserializeBuffer,
|
||||||
&devicePropertiesSize,
|
&devicePropertiesSize,
|
||||||
nullptr) == DeserializeResult::Success;
|
nullptr) == DeserializeResult::Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace dawn_wire { namespace client {
|
||||||
return entry->proc;
|
return entry->proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(procName, "dawnGetProcAddress") == 0) {
|
if (strcmp(procName, "wgpuGetProcAddress") == 0) {
|
||||||
return reinterpret_cast<DawnProc>(ClientGetProcAddress);
|
return reinterpret_cast<DawnProc>(ClientGetProcAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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_
|
|
@ -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_
|
|
@ -12,9 +12,9 @@
|
||||||
//* 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.
|
||||||
|
|
||||||
#include "dawn/dawncpp.h"
|
#include "dawn/webgpu_cpp.h"
|
||||||
|
|
||||||
namespace dawn {
|
namespace wgpu {
|
||||||
|
|
||||||
{% for type in by_category["enum"] %}
|
{% for type in by_category["enum"] %}
|
||||||
{% set CppType = as_cppType(type.name) %}
|
{% set CppType = as_cppType(type.name) %}
|
||||||
|
@ -112,12 +112,12 @@ namespace dawn {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
void {{CppType}}::DawnReference({{CType}} handle) {
|
void {{CppType}}::WGPUReference({{CType}} handle) {
|
||||||
if (handle != nullptr) {
|
if (handle != nullptr) {
|
||||||
{{as_cMethod(type.name, Name("reference"))}}(handle);
|
{{as_cMethod(type.name, Name("reference"))}}(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void {{CppType}}::DawnRelease({{CType}} handle) {
|
void {{CppType}}::WGPURelease({{CType}} handle) {
|
||||||
if (handle != nullptr) {
|
if (handle != nullptr) {
|
||||||
{{as_cMethod(type.name, Name("release"))}}(handle);
|
{{as_cMethod(type.name, Name("release"))}}(handle);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ namespace dawn {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
Proc GetProcAddress(Device const& device, const char* procName) {
|
Proc GetProcAddress(Device const& device, const char* procName) {
|
||||||
return reinterpret_cast<Proc>(DawnGetProcAddress(device.Get(), procName));
|
return reinterpret_cast<Proc>(WGPUGetProcAddress(device.Get(), procName));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -12,15 +12,15 @@
|
||||||
//* 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 DAWN_DAWNCPP_H_
|
#ifndef WEBGPU_CPP_H_
|
||||||
#define DAWN_DAWNCPP_H_
|
#define WEBGPU_CPP_H_
|
||||||
|
|
||||||
#include "dawn/dawn.h"
|
#include "dawn/webgpu.h"
|
||||||
#include "dawn/EnumClassBitmasks.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"] %}
|
{% for type in by_category["enum"] %}
|
||||||
enum class {{as_cppType(type.name)}} : uint32_t {
|
enum class {{as_cppType(type.name)}} : uint32_t {
|
||||||
|
@ -48,7 +48,7 @@ namespace dawn {
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
using Proc = DawnProc;
|
using Proc = WGPUProc;
|
||||||
{% for type in by_category["natively defined"] %}
|
{% for type in by_category["natively defined"] %}
|
||||||
using {{as_cppType(type.name)}} = {{as_cType(type.name)}};
|
using {{as_cppType(type.name)}} = {{as_cType(type.name)}};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -66,10 +66,10 @@ namespace dawn {
|
||||||
public:
|
public:
|
||||||
ObjectBase() = default;
|
ObjectBase() = default;
|
||||||
ObjectBase(CType handle): mHandle(handle) {
|
ObjectBase(CType handle): mHandle(handle) {
|
||||||
if (mHandle) Derived::DawnReference(mHandle);
|
if (mHandle) Derived::WGPUReference(mHandle);
|
||||||
}
|
}
|
||||||
~ObjectBase() {
|
~ObjectBase() {
|
||||||
if (mHandle) Derived::DawnRelease(mHandle);
|
if (mHandle) Derived::WGPURelease(mHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectBase(ObjectBase const& other)
|
ObjectBase(ObjectBase const& other)
|
||||||
|
@ -77,9 +77,9 @@ namespace dawn {
|
||||||
}
|
}
|
||||||
Derived& operator=(ObjectBase const& other) {
|
Derived& operator=(ObjectBase const& other) {
|
||||||
if (&other != this) {
|
if (&other != this) {
|
||||||
if (mHandle) Derived::DawnRelease(mHandle);
|
if (mHandle) Derived::WGPURelease(mHandle);
|
||||||
mHandle = other.mHandle;
|
mHandle = other.mHandle;
|
||||||
if (mHandle) Derived::DawnReference(mHandle);
|
if (mHandle) Derived::WGPUReference(mHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<Derived&>(*this);
|
return static_cast<Derived&>(*this);
|
||||||
|
@ -91,7 +91,7 @@ namespace dawn {
|
||||||
}
|
}
|
||||||
Derived& operator=(ObjectBase&& other) {
|
Derived& operator=(ObjectBase&& other) {
|
||||||
if (&other != this) {
|
if (&other != this) {
|
||||||
if (mHandle) Derived::DawnRelease(mHandle);
|
if (mHandle) Derived::WGPURelease(mHandle);
|
||||||
mHandle = other.mHandle;
|
mHandle = other.mHandle;
|
||||||
other.mHandle = 0;
|
other.mHandle = 0;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ namespace dawn {
|
||||||
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::DawnRelease(mHandle);
|
Derived::WGPURelease(mHandle);
|
||||||
mHandle = nullptr;
|
mHandle = nullptr;
|
||||||
}
|
}
|
||||||
return static_cast<Derived&>(*this);
|
return static_cast<Derived&>(*this);
|
||||||
|
@ -170,13 +170,13 @@ namespace dawn {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend ObjectBase<{{CppType}}, {{CType}}>;
|
friend ObjectBase<{{CppType}}, {{CType}}>;
|
||||||
static void DawnReference({{CType}} handle);
|
static void WGPUReference({{CType}} handle);
|
||||||
static void DawnRelease({{CType}} handle);
|
static void WGPURelease({{CType}} handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
{% endfor %}
|
{% 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"] %}
|
{% for type in by_category["structure"] %}
|
||||||
struct {{as_cppType(type.name)}} {
|
struct {{as_cppType(type.name)}} {
|
||||||
|
@ -190,6 +190,6 @@ namespace dawn {
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
} // namespace dawn
|
} // namespace wgpu
|
||||||
|
|
||||||
#endif // DAWN_DAWNCPP_H_
|
#endif // WEBGPU_CPP_H_
|
|
@ -34,6 +34,7 @@ dawn_json_generator("dawn_headers_gen") {
|
||||||
outputs = [
|
outputs = [
|
||||||
"src/include/dawn/dawn.h",
|
"src/include/dawn/dawn.h",
|
||||||
"src/include/dawn/dawn_proc_table.h",
|
"src/include/dawn/dawn_proc_table.h",
|
||||||
|
"src/include/dawn/webgpu.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +45,7 @@ source_set("dawn_headers") {
|
||||||
]
|
]
|
||||||
|
|
||||||
sources = get_target_outputs(":dawn_headers_gen")
|
sources = get_target_outputs(":dawn_headers_gen")
|
||||||
sources += [
|
sources += [ "${dawn_root}/src/include/dawn/dawn_wsi.h" ]
|
||||||
"${dawn_root}/src/include/dawn/dawn_export.h",
|
|
||||||
"${dawn_root}/src/include/dawn/dawn_wsi.h",
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -58,6 +56,7 @@ dawn_json_generator("dawncpp_headers_gen") {
|
||||||
target = "dawncpp_headers"
|
target = "dawncpp_headers"
|
||||||
outputs = [
|
outputs = [
|
||||||
"src/include/dawn/dawncpp.h",
|
"src/include/dawn/dawncpp.h",
|
||||||
|
"src/include/dawn/webgpu_cpp.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ source_set("dawncpp_headers") {
|
||||||
dawn_json_generator("dawncpp_gen") {
|
dawn_json_generator("dawncpp_gen") {
|
||||||
target = "dawncpp"
|
target = "dawncpp"
|
||||||
outputs = [
|
outputs = [
|
||||||
"src/dawn/dawncpp.cpp",
|
"src/dawn/webgpu_cpp.cpp",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +101,7 @@ dawn_json_generator("libdawn_proc_gen") {
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn_component("libdawn_proc") {
|
dawn_component("libdawn_proc") {
|
||||||
DEFINE_PREFIX = "DAWN"
|
DEFINE_PREFIX = "WGPU"
|
||||||
|
|
||||||
public_deps = [
|
public_deps = [
|
||||||
":dawn_headers",
|
":dawn_headers",
|
||||||
|
|
|
@ -243,7 +243,7 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsage usage) {
|
MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsage usage) {
|
||||||
ASSERT(HasZeroOrOneBits(usage));
|
ASSERT(dawn::HasZeroOrOneBits(usage));
|
||||||
if (!(buffer->GetUsage() & usage)) {
|
if (!(buffer->GetUsage() & usage)) {
|
||||||
return DAWN_VALIDATION_ERROR("buffer doesn't have the required usage.");
|
return DAWN_VALIDATION_ERROR("buffer doesn't have the required usage.");
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsage usage) {
|
MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsage usage) {
|
||||||
ASSERT(HasZeroOrOneBits(usage));
|
ASSERT(dawn::HasZeroOrOneBits(usage));
|
||||||
if (!(texture->GetUsage() & usage)) {
|
if (!(texture->GetUsage() & usage)) {
|
||||||
return DAWN_VALIDATION_ERROR("texture doesn't have the required usage.");
|
return DAWN_VALIDATION_ERROR("texture doesn't have the required usage.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace dawn {
|
namespace wgpu {
|
||||||
enum class ErrorType : uint32_t;
|
enum class ErrorType : uint32_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace dawn {
|
||||||
|
using ErrorType = wgpu::ErrorType;
|
||||||
|
}
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
enum class InternalErrorType : uint32_t;
|
enum class InternalErrorType : uint32_t;
|
||||||
|
|
|
@ -19,24 +19,15 @@
|
||||||
|
|
||||||
namespace dawn {
|
namespace dawn {
|
||||||
|
|
||||||
// std::underlying_type doesn't work in old GLIBC still used in Chrome
|
template <typename T>
|
||||||
#define CR_GLIBCXX_4_7_0 20120322
|
constexpr bool HasZeroOrOneBits(T value) {
|
||||||
#define CR_GLIBCXX_4_5_4 20120702
|
using Integral = typename std::underlying_type<T>::type;
|
||||||
#define CR_GLIBCXX_4_6_4 20121127
|
return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
|
||||||
#if defined(__GLIBCXX__) && (__GLIBCXX__ < CR_GLIBCXX_4_7_0 || __GLIBCXX__ == CR_GLIBCXX_4_5_4 || \
|
}
|
||||||
__GLIBCXX__ == CR_GLIBCXX_4_6_4)
|
|
||||||
# define CR_USE_FALLBACKS_FOR_OLD_GLIBCXX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX)
|
} // namespace dawn
|
||||||
template <typename T>
|
|
||||||
struct UnderlyingType {
|
namespace wgpu {
|
||||||
using type = __underlying_type(T);
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
template <typename T>
|
|
||||||
using UnderlyingType = std::underlying_type<T>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsDawnBitmask {
|
struct IsDawnBitmask {
|
||||||
|
@ -59,7 +50,7 @@ namespace dawn {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct BoolConvertible {
|
struct BoolConvertible {
|
||||||
using Integral = typename UnderlyingType<T>::type;
|
using Integral = typename std::underlying_type<T>::type;
|
||||||
|
|
||||||
constexpr BoolConvertible(Integral value) : value(value) {
|
constexpr BoolConvertible(Integral value) : value(value) {
|
||||||
}
|
}
|
||||||
|
@ -82,19 +73,13 @@ namespace dawn {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
constexpr bool HasZeroOrOneBits(T value) {
|
|
||||||
using Integral = typename UnderlyingType<T>::type;
|
|
||||||
return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T1,
|
template <typename T1,
|
||||||
typename T2,
|
typename T2,
|
||||||
typename = typename std::enable_if<LowerBitmask<T1>::enable &&
|
typename = typename std::enable_if<LowerBitmask<T1>::enable &&
|
||||||
LowerBitmask<T2>::enable>::type>
|
LowerBitmask<T2>::enable>::type>
|
||||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
|
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
|
||||||
using T = typename LowerBitmask<T1>::type;
|
using T = typename LowerBitmask<T1>::type;
|
||||||
using Integral = typename UnderlyingType<T>::type;
|
using Integral = typename std::underlying_type<T>::type;
|
||||||
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) |
|
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) |
|
||||||
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
||||||
}
|
}
|
||||||
|
@ -105,7 +90,7 @@ namespace dawn {
|
||||||
LowerBitmask<T2>::enable>::type>
|
LowerBitmask<T2>::enable>::type>
|
||||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
|
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
|
||||||
using T = typename LowerBitmask<T1>::type;
|
using T = typename LowerBitmask<T1>::type;
|
||||||
using Integral = typename UnderlyingType<T>::type;
|
using Integral = typename std::underlying_type<T>::type;
|
||||||
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) &
|
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) &
|
||||||
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
||||||
}
|
}
|
||||||
|
@ -116,7 +101,7 @@ namespace dawn {
|
||||||
LowerBitmask<T2>::enable>::type>
|
LowerBitmask<T2>::enable>::type>
|
||||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
|
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
|
||||||
using T = typename LowerBitmask<T1>::type;
|
using T = typename LowerBitmask<T1>::type;
|
||||||
using Integral = typename UnderlyingType<T>::type;
|
using Integral = typename std::underlying_type<T>::type;
|
||||||
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) ^
|
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) ^
|
||||||
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
||||||
}
|
}
|
||||||
|
@ -124,7 +109,7 @@ namespace dawn {
|
||||||
template <typename T1>
|
template <typename T1>
|
||||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
|
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
|
||||||
using T = typename LowerBitmask<T1>::type;
|
using T = typename LowerBitmask<T1>::type;
|
||||||
using Integral = typename UnderlyingType<T>::type;
|
using Integral = typename std::underlying_type<T>::type;
|
||||||
return ~static_cast<Integral>(LowerBitmask<T1>::Lower(t));
|
return ~static_cast<Integral>(LowerBitmask<T1>::Lower(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +142,6 @@ namespace dawn {
|
||||||
l = l ^ r;
|
l = l ^ r;
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
} // namespace dawn
|
} // namespace wgpu
|
||||||
|
|
||||||
#endif // DAWN_ENUM_CLASS_BITMASKS_H_
|
#endif // DAWN_ENUM_CLASS_BITMASKS_H_
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
#ifndef DAWN_EXPORT_H_
|
|
||||||
#define DAWN_EXPORT_H_
|
|
||||||
|
|
||||||
#if defined(DAWN_SHARED_LIBRARY)
|
|
||||||
# if defined(_WIN32)
|
|
||||||
# if defined(DAWN_IMPLEMENTATION)
|
|
||||||
# define DAWN_EXPORT __declspec(dllexport)
|
|
||||||
# else
|
|
||||||
# define DAWN_EXPORT __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
# else // defined(_WIN32)
|
|
||||||
# if defined(DAWN_IMPLEMENTATION)
|
|
||||||
# define DAWN_EXPORT __attribute__((visibility("default")))
|
|
||||||
# else
|
|
||||||
# define DAWN_EXPORT
|
|
||||||
# endif
|
|
||||||
# endif // defined(_WIN32)
|
|
||||||
#else // defined(DAWN_SHARED_LIBRARY)
|
|
||||||
# define DAWN_EXPORT
|
|
||||||
#endif // defined(DAWN_SHARED_LIBRARY)
|
|
||||||
|
|
||||||
#endif // DAWN_EXPORT_H_
|
|
|
@ -15,8 +15,8 @@
|
||||||
#ifndef DAWN_DAWN_PROC_H_
|
#ifndef DAWN_DAWN_PROC_H_
|
||||||
#define DAWN_DAWN_PROC_H_
|
#define DAWN_DAWN_PROC_H_
|
||||||
|
|
||||||
#include "dawn/dawn.h"
|
|
||||||
#include "dawn/dawn_proc_table.h"
|
#include "dawn/dawn_proc_table.h"
|
||||||
|
#include "dawn/webgpu.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -27,7 +27,7 @@ extern "C" {
|
||||||
// default value of the proctable. Setting the proctable back to null is good practice when you
|
// default value of the proctable. Setting the proctable back to null is good practice when you
|
||||||
// are done using libdawn_proc since further usage will cause a segfault instead of calling an
|
// are done using libdawn_proc since further usage will cause a segfault instead of calling an
|
||||||
// unexpected function.
|
// unexpected function.
|
||||||
DAWN_EXPORT void dawnProcSetProcs(const DawnProcTable* procs);
|
WGPU_EXPORT void dawnProcSetProcs(const DawnProcTable* procs);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
|
@ -36,12 +36,13 @@ namespace dawn_wire {
|
||||||
};
|
};
|
||||||
|
|
||||||
DAWN_WIRE_EXPORT size_t
|
DAWN_WIRE_EXPORT size_t
|
||||||
SerializedDawnDevicePropertiesSize(const DawnDeviceProperties* deviceProperties);
|
SerializedWGPUDevicePropertiesSize(const DawnDeviceProperties* deviceProperties);
|
||||||
|
|
||||||
DAWN_WIRE_EXPORT void SerializeDawnDeviceProperties(
|
DAWN_WIRE_EXPORT void SerializeWGPUDeviceProperties(
|
||||||
const DawnDeviceProperties* deviceProperties,
|
const DawnDeviceProperties* deviceProperties,
|
||||||
char* serializeBuffer);
|
char* serializeBuffer);
|
||||||
DAWN_WIRE_EXPORT bool DeserializeDawnDeviceProperties(DawnDeviceProperties* deviceProperties,
|
|
||||||
|
DAWN_WIRE_EXPORT bool DeserializeWGPUDeviceProperties(DawnDeviceProperties* deviceProperties,
|
||||||
const volatile char* deserializeBuffer);
|
const volatile char* deserializeBuffer);
|
||||||
|
|
||||||
} // namespace dawn_wire
|
} // namespace dawn_wire
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "dawn/EnumClassBitmasks.h"
|
#include "dawn/EnumClassBitmasks.h"
|
||||||
|
|
||||||
namespace dawn {
|
namespace wgpu {
|
||||||
|
|
||||||
enum class Color : uint32_t {
|
enum class Color : uint32_t {
|
||||||
R = 1,
|
R = 1,
|
||||||
|
@ -80,14 +80,14 @@ namespace dawn {
|
||||||
|
|
||||||
TEST(BitmaskTests, ZeroOrOneBits) {
|
TEST(BitmaskTests, ZeroOrOneBits) {
|
||||||
Color zero = static_cast<Color>(0);
|
Color zero = static_cast<Color>(0);
|
||||||
ASSERT_TRUE(HasZeroOrOneBits(zero));
|
ASSERT_TRUE(dawn::HasZeroOrOneBits(zero));
|
||||||
ASSERT_TRUE(HasZeroOrOneBits(Color::R));
|
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::R));
|
||||||
ASSERT_TRUE(HasZeroOrOneBits(Color::G));
|
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::G));
|
||||||
ASSERT_TRUE(HasZeroOrOneBits(Color::B));
|
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::B));
|
||||||
ASSERT_TRUE(HasZeroOrOneBits(Color::A));
|
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::A));
|
||||||
ASSERT_FALSE(HasZeroOrOneBits(static_cast<Color>(Color::R | Color::G)));
|
ASSERT_FALSE(dawn::HasZeroOrOneBits(static_cast<Color>(Color::R | Color::G)));
|
||||||
ASSERT_FALSE(HasZeroOrOneBits(static_cast<Color>(Color::G | Color::B)));
|
ASSERT_FALSE(dawn::HasZeroOrOneBits(static_cast<Color>(Color::G | Color::B)));
|
||||||
ASSERT_FALSE(HasZeroOrOneBits(static_cast<Color>(Color::B | Color::A)));
|
ASSERT_FALSE(dawn::HasZeroOrOneBits(static_cast<Color>(Color::B | Color::A)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn
|
} // namespace wgpu
|
||||||
|
|
|
@ -102,13 +102,13 @@ namespace {
|
||||||
|
|
||||||
// Test GetProcAddress with and without devices on some valid examples
|
// Test GetProcAddress with and without devices on some valid examples
|
||||||
TEST_P(GetProcAddressTests, ValidExamples) {
|
TEST_P(GetProcAddressTests, ValidExamples) {
|
||||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnDeviceCreateBuffer"),
|
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuDeviceCreateBuffer"),
|
||||||
reinterpret_cast<DawnProc>(mProcs.deviceCreateBuffer));
|
reinterpret_cast<DawnProc>(mProcs.deviceCreateBuffer));
|
||||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnDeviceCreateBuffer"),
|
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuDeviceCreateBuffer"),
|
||||||
reinterpret_cast<DawnProc>(mProcs.deviceCreateBuffer));
|
reinterpret_cast<DawnProc>(mProcs.deviceCreateBuffer));
|
||||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnQueueSubmit"),
|
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuQueueSubmit"),
|
||||||
reinterpret_cast<DawnProc>(mProcs.queueSubmit));
|
reinterpret_cast<DawnProc>(mProcs.queueSubmit));
|
||||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnQueueSubmit"),
|
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuQueueSubmit"),
|
||||||
reinterpret_cast<DawnProc>(mProcs.queueSubmit));
|
reinterpret_cast<DawnProc>(mProcs.queueSubmit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ namespace {
|
||||||
|
|
||||||
// Test GetProcAddress with and without devices on some invalid
|
// Test GetProcAddress with and without devices on some invalid
|
||||||
TEST_P(GetProcAddressTests, InvalidExamples) {
|
TEST_P(GetProcAddressTests, InvalidExamples) {
|
||||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnDeviceDoSomething"), nullptr);
|
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuDeviceDoSomething"), nullptr);
|
||||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnDeviceDoSomething"), nullptr);
|
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuDeviceDoSomething"), nullptr);
|
||||||
|
|
||||||
// Trigger the condition where lower_bound will return the end of the procMap.
|
// Trigger the condition where lower_bound will return the end of the procMap.
|
||||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "zzzzzzz"), nullptr);
|
ASSERT_EQ(mProcs.getProcAddress(nullptr, "zzzzzzz"), nullptr);
|
||||||
|
@ -139,9 +139,9 @@ namespace {
|
||||||
// Test that GetProcAddress supports itself: it is handled specially because it is a
|
// Test that GetProcAddress supports itself: it is handled specially because it is a
|
||||||
// freestanding function and not a method on an object.
|
// freestanding function and not a method on an object.
|
||||||
TEST_P(GetProcAddressTests, GetProcAddressItself) {
|
TEST_P(GetProcAddressTests, GetProcAddressItself) {
|
||||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnGetProcAddress"),
|
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuGetProcAddress"),
|
||||||
reinterpret_cast<DawnProc>(mProcs.getProcAddress));
|
reinterpret_cast<DawnProc>(mProcs.getProcAddress));
|
||||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnGetProcAddress"),
|
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuGetProcAddress"),
|
||||||
reinterpret_cast<DawnProc>(mProcs.getProcAddress));
|
reinterpret_cast<DawnProc>(mProcs.getProcAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,19 @@
|
||||||
|
|
||||||
#include "dawn/dawncpp.h"
|
#include "dawn/dawncpp.h"
|
||||||
|
|
||||||
class Object : public dawn::ObjectBase<Object, int*> {
|
class Object : public wgpu::ObjectBase<Object, int*> {
|
||||||
public:
|
public:
|
||||||
using ObjectBase::ObjectBase;
|
using ObjectBase::ObjectBase;
|
||||||
using ObjectBase::operator=;
|
using ObjectBase::operator=;
|
||||||
|
|
||||||
static void DawnReference(int* handle) {
|
static void WGPUReference(int* handle) {
|
||||||
ASSERT_LE(0, *handle);
|
ASSERT_LE(0, *handle);
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
}
|
}
|
||||||
static void DawnRelease(int* handle) {
|
static void WGPURelease(int* handle) {
|
||||||
ASSERT_LT(0, *handle);
|
ASSERT_LT(0, *handle);
|
||||||
*handle -= 1;
|
*handle -= 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test that creating an C++ object from a C object takes a ref.
|
// Test that creating an C++ object from a C object takes a ref.
|
||||||
|
|
|
@ -25,12 +25,12 @@ TEST_F(WireDawnDevicePropertiesTests, SerializeDawnDeviceProperties) {
|
||||||
sentDawnDeviceProperties.textureCompressionBC = true;
|
sentDawnDeviceProperties.textureCompressionBC = true;
|
||||||
|
|
||||||
size_t sentDawnDevicePropertiesSize =
|
size_t sentDawnDevicePropertiesSize =
|
||||||
dawn_wire::SerializedDawnDevicePropertiesSize(&sentDawnDeviceProperties);
|
dawn_wire::SerializedWGPUDevicePropertiesSize(&sentDawnDeviceProperties);
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
buffer.resize(sentDawnDevicePropertiesSize);
|
buffer.resize(sentDawnDevicePropertiesSize);
|
||||||
dawn_wire::SerializeDawnDeviceProperties(&sentDawnDeviceProperties, buffer.data());
|
dawn_wire::SerializeWGPUDeviceProperties(&sentDawnDeviceProperties, buffer.data());
|
||||||
|
|
||||||
DawnDeviceProperties receivedDawnDeviceProperties;
|
DawnDeviceProperties receivedDawnDeviceProperties;
|
||||||
dawn_wire::DeserializeDawnDeviceProperties(&receivedDawnDeviceProperties, buffer.data());
|
dawn_wire::DeserializeWGPUDeviceProperties(&receivedDawnDeviceProperties, buffer.data());
|
||||||
ASSERT_TRUE(receivedDawnDeviceProperties.textureCompressionBC);
|
ASSERT_TRUE(receivedDawnDeviceProperties.textureCompressionBC);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue