Move EnumClassBitmasks from wgpu to dawn namespace

The EnumClassBitmasks is used by dawn/api_cpp.h that needs to be common.
Define a macro to export the operators from dawn to other various namespace.

BUG=dawn:1201
Change-Id: I20badd54e844fead6ecf12546a2c9e0afa2fd83f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71900
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
This commit is contained in:
fujunwei 2021-12-08 05:46:17 +00:00 committed by Dawn LUCI CQ
parent ef572ba7a1
commit ed33e05db1
9 changed files with 55 additions and 43 deletions

View File

@ -46,14 +46,6 @@ namespace {{metadata.namespace}} {
{% endfor %}
{% for type in by_category["bitmask"] %}
template<>
struct IsDawnBitmask<{{as_cppType(type.name)}}> {
static constexpr bool enable = true;
};
{% endfor %}
{% for type in by_category["function pointer"] %}
using {{as_cppType(type.name)}} = {{as_cType(type.name)}};
{% endfor %}
@ -242,6 +234,20 @@ namespace {{metadata.namespace}} {
};
{% endfor %}
// The operators of EnumClassBitmmasks in the dawn:: namespace need to be imported
// in the {{metadata.namespace}} namespace for Argument Dependent Lookup.
DAWN_IMPORT_BITMASK_OPERATORS
} // namespace {{metadata.namespace}}
namespace dawn {
{% for type in by_category["bitmask"] %}
template<>
struct IsDawnBitmask<{{metadata.namespace}}::{{as_cppType(type.name)}}> {
static constexpr bool enable = true;
};
{% endfor %}
} // namespace dawn
#endif // {{API}}_CPP_H_

View File

@ -19,8 +19,9 @@
namespace dawn_native {
// EnumClassBitmmasks is a WebGPU helper in the wgpu:: namespace.
// EnumClassBitmmasks is a helper in the dawn:: namespace.
// Re-export it in the dawn_native namespace.
DAWN_IMPORT_BITMASK_OPERATORS
// Specify this for usage with EnumMaskIterator
template <typename T>
@ -28,16 +29,6 @@ namespace dawn_native {
static constexpr unsigned value = 0;
};
using wgpu::operator|;
using wgpu::operator&;
using wgpu::operator^;
using wgpu::operator~;
using wgpu::operator&=;
using wgpu::operator|=;
using wgpu::operator^=;
using wgpu::HasZeroOrOneBits;
template <typename T>
constexpr bool HasOneBit(T value) {
return HasZeroOrOneBits(value) && value != T(0);

View File

@ -129,13 +129,13 @@ namespace dawn_native {
} // namespace dawn_native
namespace wgpu {
namespace dawn {
template <>
struct IsDawnBitmask<dawn_native::SampleTypeBit> {
static constexpr bool enable = true;
};
} // namespace wgpu
} // namespace dawn
#endif // DAWNNATIVE_FORMAT_H_

View File

@ -100,13 +100,13 @@ namespace dawn_native {
} // namespace dawn_native
namespace wgpu {
namespace dawn {
template <>
struct IsDawnBitmask<dawn_native::Aspect> {
static constexpr bool enable = true;
};
} // namespace wgpu
} // namespace dawn
#endif // DAWNNATIVE_SUBRESOURCE_H_

View File

@ -17,7 +17,19 @@
#include <type_traits>
namespace wgpu {
// The operators in dawn:: namespace need be introduced into other namespaces with
// using-declarations for C++ Argument Dependent Lookup to work.
#define DAWN_IMPORT_BITMASK_OPERATORS \
using dawn::operator|; \
using dawn::operator&; \
using dawn::operator^; \
using dawn::operator~; \
using dawn::operator&=; \
using dawn::operator|=; \
using dawn::operator^=; \
using dawn::HasZeroOrOneBits;
namespace dawn {
template <typename T>
struct IsDawnBitmask {
@ -139,6 +151,6 @@ namespace wgpu {
return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
}
} // namespace wgpu
} // namespace dawn
#endif // DAWN_ENUM_CLASS_BITMASKS_H_

View File

@ -34,12 +34,12 @@ enum class CheckIndex : uint32_t {
Instance = 0x0000002,
};
namespace wgpu {
namespace dawn {
template <>
struct IsDawnBitmask<CheckIndex> {
static constexpr bool enable = true;
};
} // namespace wgpu
} // namespace dawn
class FirstIndexOffsetTests : public DawnTest {
public:

View File

@ -16,7 +16,7 @@
#include "dawn/EnumClassBitmasks.h"
namespace wgpu {
namespace dawn {
enum class Color : uint32_t {
R = 1,
@ -80,14 +80,14 @@ namespace wgpu {
TEST(BitmaskTests, ZeroOrOneBits) {
Color zero = static_cast<Color>(0);
ASSERT_TRUE(wgpu::HasZeroOrOneBits(zero));
ASSERT_TRUE(wgpu::HasZeroOrOneBits(Color::R));
ASSERT_TRUE(wgpu::HasZeroOrOneBits(Color::G));
ASSERT_TRUE(wgpu::HasZeroOrOneBits(Color::B));
ASSERT_TRUE(wgpu::HasZeroOrOneBits(Color::A));
ASSERT_FALSE(wgpu::HasZeroOrOneBits(static_cast<Color>(Color::R | Color::G)));
ASSERT_FALSE(wgpu::HasZeroOrOneBits(static_cast<Color>(Color::G | Color::B)));
ASSERT_FALSE(wgpu::HasZeroOrOneBits(static_cast<Color>(Color::B | Color::A)));
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)));
}
} // namespace wgpu
} // namespace dawn

View File

@ -31,14 +31,14 @@ namespace dawn_native {
} // namespace dawn_native
namespace wgpu {
namespace dawn {
template <>
struct IsDawnBitmask<dawn_native::TestAspect> {
static constexpr bool enable = true;
};
} // namespace wgpu
} // namespace dawn
namespace dawn_native {

View File

@ -18,6 +18,7 @@
#include "dawn/EnumClassBitmasks.h"
#include <cmath>
#include "dawn/webgpu_cpp.h"
namespace wgpu {
enum class TestEnum {
@ -27,10 +28,12 @@ namespace wgpu {
};
} // namespace wgpu
template <>
struct wgpu::IsDawnBitmask<wgpu::TestEnum> {
static constexpr bool enable = true;
};
namespace dawn {
template <>
struct IsDawnBitmask<wgpu::TestEnum> {
static constexpr bool enable = true;
};
} // namespace dawn
// Tests for ScanForward
TEST(Math, ScanForward) {