diff --git a/src/backend/Buffer.cpp b/src/backend/Buffer.cpp index 9b23b7f8f3..4b4b008946 100644 --- a/src/backend/Buffer.cpp +++ b/src/backend/Buffer.cpp @@ -164,11 +164,8 @@ namespace backend { } bool BufferBase::IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage) { - const nxt::BufferUsageBit allReadBits = - nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferSrc | - nxt::BufferUsageBit::Index | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Uniform; bool allowed = (usage & allowedUsage) == usage; - bool readOnly = (usage & allReadBits) == usage; + bool readOnly = (usage & kReadOnlyBufferUsages) == usage; bool singleUse = nxt::HasZeroOrOneBits(usage); return allowed && (readOnly || singleUse); } diff --git a/src/backend/Buffer.h b/src/backend/Buffer.h index d1736b1342..a0acef1e60 100644 --- a/src/backend/Buffer.h +++ b/src/backend/Buffer.h @@ -23,6 +23,14 @@ namespace backend { + static constexpr nxt::BufferUsageBit kReadOnlyBufferUsages = + nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferSrc | + nxt::BufferUsageBit::Index | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Uniform; + + static constexpr nxt::BufferUsageBit kWritableBufferUsages = nxt::BufferUsageBit::MapWrite | + nxt::BufferUsageBit::TransferDst | + nxt::BufferUsageBit::Storage; + class BufferBase : public RefCounted { public: BufferBase(BufferBuilder* builder); diff --git a/src/include/nxt/EnumClassBitmasks.h b/src/include/nxt/EnumClassBitmasks.h index a17c505429..86979b0a91 100644 --- a/src/include/nxt/EnumClassBitmasks.h +++ b/src/include/nxt/EnumClassBitmasks.h @@ -53,16 +53,23 @@ namespace nxt { struct LowerBitmask::enable>::type> { static constexpr bool enable = true; using type = T; - static T Lower(T t) {return t;} + constexpr static T Lower(T t) { + return t; + } }; template struct BoolConvertible { using Integral = typename UnderlyingType::type; - BoolConvertible(Integral value) : value(value) {} - operator bool() const {return value != 0;} - operator T() const {return static_cast(value);} + constexpr BoolConvertible(Integral value) : value(value) { + } + constexpr operator bool() const { + return value != 0; + } + constexpr operator T() const { + return static_cast(value); + } Integral value; }; @@ -71,7 +78,9 @@ namespace nxt { struct LowerBitmask> { static constexpr bool enable = true; using type = T; - static type Lower(BoolConvertible t) {return t;} + static constexpr type Lower(BoolConvertible t) { + return t; + } }; template @@ -117,33 +126,35 @@ namespace nxt { return ~static_cast(LowerBitmask::Lower(t)); } - template::enable && LowerBitmask::enable - >::type> - T& operator &= (T& l, T2 right) { + template ::enable && + LowerBitmask::enable>::type> + constexpr T& operator&=(T& l, T2 right) { T r = LowerBitmask::Lower(right); l = l & r; return l; } - template::enable && LowerBitmask::enable - >::type> - T& operator |= (T& l, T2 right) { + template ::enable && + LowerBitmask::enable>::type> + constexpr T& operator|=(T& l, T2 right) { T r = LowerBitmask::Lower(right); l = l | r; return l; } - template::enable && LowerBitmask::enable - >::type> - T& operator ^= (T& l, T2 right) { + template ::enable && + LowerBitmask::enable>::type> + constexpr T& operator^=(T& l, T2 right) { T r = LowerBitmask::Lower(right); l = l ^ r; return l; } - } #endif // NXT_ENUM_CLASS_BITMASKS_H_