1// 2// Copyright 2021 The ANGLE Project Authors. All rights reserved. 3// Use of this source code is governed by a BSD-style license that can be 4// found in the LICENSE file. 5// 6// CLBitField.h: A bit field class that encapsulates the cl_bitfield type. 7 8#ifndef LIBANGLE_CLBITFIELD_H_ 9#define LIBANGLE_CLBITFIELD_H_ 10 11#include <angle_cl.h> 12 13namespace cl 14{ 15 16class BitField 17{ 18 public: 19 BitField() noexcept : mBits(0u) {} 20 explicit BitField(cl_bitfield bits) noexcept : mBits(bits) {} 21 22 BitField &operator=(cl_bitfield bits) 23 { 24 mBits = bits; 25 return *this; 26 } 27 28 bool operator==(cl_bitfield bits) const { return mBits == bits; } 29 bool operator!=(cl_bitfield bits) const { return mBits != bits; } 30 bool operator==(const BitField &other) const { return mBits == other.mBits; } 31 bool operator!=(const BitField &other) const { return mBits != other.mBits; } 32 33 cl_bitfield get() const { return mBits; } 34 35 bool isSet(cl_bitfield bits) const { return (mBits & bits) != 0u; } 36 bool isSet(const BitField &other) const { return (mBits & other.mBits) != 0u; } 37 bool isNotSet(cl_bitfield bits) const { return (mBits & bits) == 0u; } 38 bool isNotSet(const BitField &other) const { return (mBits & other.mBits) == 0u; } 39 40 bool hasOtherBitsThan(cl_bitfield bits) const { return (mBits & ~bits) != 0u; } 41 bool hasOtherBitsThan(const BitField &other) const { return (mBits & ~other.mBits) != 0u; } 42 43 bool areMutuallyExclusive(cl_bitfield bits1, cl_bitfield bits2) const 44 { 45 return (isSet(bits1) ? 1 : 0) + (isSet(bits2) ? 1 : 0) <= 1; 46 } 47 48 bool areMutuallyExclusive(cl_bitfield bits1, cl_bitfield bits2, cl_bitfield bits3) const 49 { 50 return (isSet(bits1) ? 1 : 0) + (isSet(bits2) ? 1 : 0) + (isSet(bits3) ? 1 : 0) <= 1; 51 } 52 53 BitField mask(cl_bitfield bits) const { return BitField(mBits & bits); } 54 BitField mask(const BitField &other) const { return BitField(mBits & other.mBits); } 55 56 void set(cl_bitfield bits) { mBits |= bits; } 57 void set(const BitField &other) { mBits |= other.mBits; } 58 void clear(cl_bitfield bits) { mBits &= ~bits; } 59 void clear(const BitField &other) { mBits &= ~other.mBits; } 60 61 private: 62 cl_bitfield mBits; 63}; 64 65static_assert(sizeof(BitField) == sizeof(cl_bitfield), "Type size mismatch"); 66 67using DeviceType = BitField; 68using DeviceFpConfig = BitField; 69using DeviceExecCapabilities = BitField; 70using DeviceSvmCapabilities = BitField; 71using CommandQueueProperties = BitField; 72using DeviceAffinityDomain = BitField; 73using MemFlags = BitField; 74using SVM_MemFlags = BitField; 75using MemMigrationFlags = BitField; 76using MapFlags = BitField; 77using KernelArgTypeQualifier = BitField; 78using DeviceAtomicCapabilities = BitField; 79using DeviceEnqueueCapabilities = BitField; 80 81} // namespace cl 82 83#endif // LIBANGLE_CLBITFIELD_H_ 84