mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
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:
committed by
Commit Bot service account
parent
16f1068025
commit
2c8b5c6370
@@ -34,6 +34,7 @@ dawn_json_generator("dawn_headers_gen") {
|
||||
outputs = [
|
||||
"src/include/dawn/dawn.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 += [
|
||||
"${dawn_root}/src/include/dawn/dawn_export.h",
|
||||
"${dawn_root}/src/include/dawn/dawn_wsi.h",
|
||||
]
|
||||
sources += [ "${dawn_root}/src/include/dawn/dawn_wsi.h" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
@@ -58,6 +56,7 @@ dawn_json_generator("dawncpp_headers_gen") {
|
||||
target = "dawncpp_headers"
|
||||
outputs = [
|
||||
"src/include/dawn/dawncpp.h",
|
||||
"src/include/dawn/webgpu_cpp.h",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ source_set("dawncpp_headers") {
|
||||
dawn_json_generator("dawncpp_gen") {
|
||||
target = "dawncpp"
|
||||
outputs = [
|
||||
"src/dawn/dawncpp.cpp",
|
||||
"src/dawn/webgpu_cpp.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -102,7 +101,7 @@ dawn_json_generator("libdawn_proc_gen") {
|
||||
}
|
||||
|
||||
dawn_component("libdawn_proc") {
|
||||
DEFINE_PREFIX = "DAWN"
|
||||
DEFINE_PREFIX = "WGPU"
|
||||
|
||||
public_deps = [
|
||||
":dawn_headers",
|
||||
|
||||
@@ -243,7 +243,7 @@ namespace dawn_native {
|
||||
}
|
||||
|
||||
MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsage usage) {
|
||||
ASSERT(HasZeroOrOneBits(usage));
|
||||
ASSERT(dawn::HasZeroOrOneBits(usage));
|
||||
if (!(buffer->GetUsage() & 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) {
|
||||
ASSERT(HasZeroOrOneBits(usage));
|
||||
ASSERT(dawn::HasZeroOrOneBits(usage));
|
||||
if (!(texture->GetUsage() & usage)) {
|
||||
return DAWN_VALIDATION_ERROR("texture doesn't have the required usage.");
|
||||
}
|
||||
|
||||
@@ -19,10 +19,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dawn {
|
||||
namespace wgpu {
|
||||
enum class ErrorType : uint32_t;
|
||||
}
|
||||
|
||||
namespace dawn {
|
||||
using ErrorType = wgpu::ErrorType;
|
||||
}
|
||||
|
||||
namespace dawn_native {
|
||||
|
||||
enum class InternalErrorType : uint32_t;
|
||||
|
||||
@@ -19,24 +19,15 @@
|
||||
|
||||
namespace dawn {
|
||||
|
||||
// std::underlying_type doesn't work in old GLIBC still used in Chrome
|
||||
#define CR_GLIBCXX_4_7_0 20120322
|
||||
#define CR_GLIBCXX_4_5_4 20120702
|
||||
#define CR_GLIBCXX_4_6_4 20121127
|
||||
#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
|
||||
template <typename T>
|
||||
constexpr bool HasZeroOrOneBits(T value) {
|
||||
using Integral = typename std::underlying_type<T>::type;
|
||||
return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
|
||||
}
|
||||
|
||||
#if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX)
|
||||
template <typename T>
|
||||
struct UnderlyingType {
|
||||
using type = __underlying_type(T);
|
||||
};
|
||||
#else
|
||||
template <typename T>
|
||||
using UnderlyingType = std::underlying_type<T>;
|
||||
#endif
|
||||
} // namespace dawn
|
||||
|
||||
namespace wgpu {
|
||||
|
||||
template <typename T>
|
||||
struct IsDawnBitmask {
|
||||
@@ -59,7 +50,7 @@ namespace dawn {
|
||||
|
||||
template <typename T>
|
||||
struct BoolConvertible {
|
||||
using Integral = typename UnderlyingType<T>::type;
|
||||
using Integral = typename std::underlying_type<T>::type;
|
||||
|
||||
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,
|
||||
typename T2,
|
||||
typename = typename std::enable_if<LowerBitmask<T1>::enable &&
|
||||
LowerBitmask<T2>::enable>::type>
|
||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
|
||||
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)) |
|
||||
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
||||
}
|
||||
@@ -105,7 +90,7 @@ namespace dawn {
|
||||
LowerBitmask<T2>::enable>::type>
|
||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
|
||||
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)) &
|
||||
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
||||
}
|
||||
@@ -116,7 +101,7 @@ namespace dawn {
|
||||
LowerBitmask<T2>::enable>::type>
|
||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
|
||||
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)) ^
|
||||
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
|
||||
}
|
||||
@@ -124,7 +109,7 @@ namespace dawn {
|
||||
template <typename T1>
|
||||
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -157,6 +142,6 @@ namespace dawn {
|
||||
l = l ^ r;
|
||||
return l;
|
||||
}
|
||||
} // namespace dawn
|
||||
} // namespace wgpu
|
||||
|
||||
#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_
|
||||
#define DAWN_DAWN_PROC_H_
|
||||
|
||||
#include "dawn/dawn.h"
|
||||
#include "dawn/dawn_proc_table.h"
|
||||
#include "dawn/webgpu.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -27,7 +27,7 @@ extern "C" {
|
||||
// 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
|
||||
// unexpected function.
|
||||
DAWN_EXPORT void dawnProcSetProcs(const DawnProcTable* procs);
|
||||
WGPU_EXPORT void dawnProcSetProcs(const DawnProcTable* procs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
@@ -36,12 +36,13 @@ namespace dawn_wire {
|
||||
};
|
||||
|
||||
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,
|
||||
char* serializeBuffer);
|
||||
DAWN_WIRE_EXPORT bool DeserializeDawnDeviceProperties(DawnDeviceProperties* deviceProperties,
|
||||
|
||||
DAWN_WIRE_EXPORT bool DeserializeWGPUDeviceProperties(DawnDeviceProperties* deviceProperties,
|
||||
const volatile char* deserializeBuffer);
|
||||
|
||||
} // namespace dawn_wire
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "dawn/EnumClassBitmasks.h"
|
||||
|
||||
namespace dawn {
|
||||
namespace wgpu {
|
||||
|
||||
enum class Color : uint32_t {
|
||||
R = 1,
|
||||
@@ -80,14 +80,14 @@ namespace dawn {
|
||||
|
||||
TEST(BitmaskTests, ZeroOrOneBits) {
|
||||
Color zero = static_cast<Color>(0);
|
||||
ASSERT_TRUE(HasZeroOrOneBits(zero));
|
||||
ASSERT_TRUE(HasZeroOrOneBits(Color::R));
|
||||
ASSERT_TRUE(HasZeroOrOneBits(Color::G));
|
||||
ASSERT_TRUE(HasZeroOrOneBits(Color::B));
|
||||
ASSERT_TRUE(HasZeroOrOneBits(Color::A));
|
||||
ASSERT_FALSE(HasZeroOrOneBits(static_cast<Color>(Color::R | Color::G)));
|
||||
ASSERT_FALSE(HasZeroOrOneBits(static_cast<Color>(Color::G | Color::B)));
|
||||
ASSERT_FALSE(HasZeroOrOneBits(static_cast<Color>(Color::B | Color::A)));
|
||||
ASSERT_TRUE(dawn::HasZeroOrOneBits(zero));
|
||||
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::R));
|
||||
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::G));
|
||||
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::B));
|
||||
ASSERT_TRUE(dawn::HasZeroOrOneBits(Color::A));
|
||||
ASSERT_FALSE(dawn::HasZeroOrOneBits(static_cast<Color>(Color::R | Color::G)));
|
||||
ASSERT_FALSE(dawn::HasZeroOrOneBits(static_cast<Color>(Color::G | Color::B)));
|
||||
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_P(GetProcAddressTests, ValidExamples) {
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnDeviceCreateBuffer"),
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuDeviceCreateBuffer"),
|
||||
reinterpret_cast<DawnProc>(mProcs.deviceCreateBuffer));
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnDeviceCreateBuffer"),
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuDeviceCreateBuffer"),
|
||||
reinterpret_cast<DawnProc>(mProcs.deviceCreateBuffer));
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnQueueSubmit"),
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuQueueSubmit"),
|
||||
reinterpret_cast<DawnProc>(mProcs.queueSubmit));
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnQueueSubmit"),
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuQueueSubmit"),
|
||||
reinterpret_cast<DawnProc>(mProcs.queueSubmit));
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ namespace {
|
||||
|
||||
// Test GetProcAddress with and without devices on some invalid
|
||||
TEST_P(GetProcAddressTests, InvalidExamples) {
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnDeviceDoSomething"), nullptr);
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnDeviceDoSomething"), nullptr);
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuDeviceDoSomething"), nullptr);
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuDeviceDoSomething"), nullptr);
|
||||
|
||||
// Trigger the condition where lower_bound will return the end of the procMap.
|
||||
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
|
||||
// freestanding function and not a method on an object.
|
||||
TEST_P(GetProcAddressTests, GetProcAddressItself) {
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "dawnGetProcAddress"),
|
||||
ASSERT_EQ(mProcs.getProcAddress(nullptr, "wgpuGetProcAddress"),
|
||||
reinterpret_cast<DawnProc>(mProcs.getProcAddress));
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "dawnGetProcAddress"),
|
||||
ASSERT_EQ(mProcs.getProcAddress(mDevice.Get(), "wgpuGetProcAddress"),
|
||||
reinterpret_cast<DawnProc>(mProcs.getProcAddress));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
#include "dawn/dawncpp.h"
|
||||
|
||||
class Object : public dawn::ObjectBase<Object, int*> {
|
||||
public:
|
||||
using ObjectBase::ObjectBase;
|
||||
using ObjectBase::operator=;
|
||||
class Object : public wgpu::ObjectBase<Object, int*> {
|
||||
public:
|
||||
using ObjectBase::ObjectBase;
|
||||
using ObjectBase::operator=;
|
||||
|
||||
static void DawnReference(int* handle) {
|
||||
ASSERT_LE(0, *handle);
|
||||
*handle += 1;
|
||||
}
|
||||
static void DawnRelease(int* handle) {
|
||||
ASSERT_LT(0, *handle);
|
||||
*handle -= 1;
|
||||
}
|
||||
static void WGPUReference(int* handle) {
|
||||
ASSERT_LE(0, *handle);
|
||||
*handle += 1;
|
||||
}
|
||||
static void WGPURelease(int* handle) {
|
||||
ASSERT_LT(0, *handle);
|
||||
*handle -= 1;
|
||||
}
|
||||
};
|
||||
|
||||
// Test that creating an C++ object from a C object takes a ref.
|
||||
|
||||
@@ -25,12 +25,12 @@ TEST_F(WireDawnDevicePropertiesTests, SerializeDawnDeviceProperties) {
|
||||
sentDawnDeviceProperties.textureCompressionBC = true;
|
||||
|
||||
size_t sentDawnDevicePropertiesSize =
|
||||
dawn_wire::SerializedDawnDevicePropertiesSize(&sentDawnDeviceProperties);
|
||||
dawn_wire::SerializedWGPUDevicePropertiesSize(&sentDawnDeviceProperties);
|
||||
std::vector<char> buffer;
|
||||
buffer.resize(sentDawnDevicePropertiesSize);
|
||||
dawn_wire::SerializeDawnDeviceProperties(&sentDawnDeviceProperties, buffer.data());
|
||||
dawn_wire::SerializeWGPUDeviceProperties(&sentDawnDeviceProperties, buffer.data());
|
||||
|
||||
DawnDeviceProperties receivedDawnDeviceProperties;
|
||||
dawn_wire::DeserializeDawnDeviceProperties(&receivedDawnDeviceProperties, buffer.data());
|
||||
dawn_wire::DeserializeWGPUDeviceProperties(&receivedDawnDeviceProperties, buffer.data());
|
||||
ASSERT_TRUE(receivedDawnDeviceProperties.textureCompressionBC);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user