summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-04-25 23:21:06 +0800
committerGitHub <noreply@github.com>2023-04-25 23:21:06 +0800
commit58858297fd73602cfb7507ce23b0b9e3d9ded2be (patch)
tree8f43deb6fcae4a953feb1b8d5d5f138717884ee1 /source
parent7b7c095b37e85ca3a8f55eff1c3d9643d467b8e0 (diff)
Bump glm and stb + small neatenings (#2831)
* bump glm to fix c++20 warnings * bump stb_image to fix c++20 warnings * Use static_assert for SLANG_COMPILE_TIME_ASSERT * Remove uses of deprecated is_pod * Remove bit operations between different enums
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-allocator.h34
-rw-r--r--source/core/slang-chunked-list.h8
-rw-r--r--source/core/slang-crypto.h2
-rw-r--r--source/core/slang-memory-arena.h2
-rw-r--r--source/slang/slang-ir.cpp6
-rw-r--r--source/slang/slang-ir.h36
-rw-r--r--source/slang/slang-serialize-ir.cpp6
7 files changed, 48 insertions, 46 deletions
diff --git a/source/core/slang-allocator.h b/source/core/slang-allocator.h
index bc1b880f8..8942f993b 100644
--- a/source/core/slang-allocator.h
+++ b/source/core/slang-allocator.h
@@ -62,34 +62,6 @@ namespace Slang
}
};
- // Helper utilties for calling allocators.
- template<typename T, int isPOD>
- class Initializer;
-
- template<typename T>
- class Initializer<T, 0>
- {
- public:
- static void initialize(T* buffer, Index size)
- {
- for (Index i = 0; i < size; i++)
- new (buffer + i) T();
- }
- };
- template<typename T>
- class Initializer<T, 1>
- {
- public:
- static void initialize(T* buffer, Index size)
- {
- SLANG_UNUSED(buffer);
- SLANG_UNUSED(size);
- // It's pod so no initialization required
- //for (int i = 0; i < size; i++)
- // new (buffer + i) T;
- }
- };
-
template<typename T, typename TAllocator>
class AllocateMethod
{
@@ -98,7 +70,11 @@ namespace Slang
{
TAllocator allocator;
T* rs = (T*)allocator.allocate(count * sizeof(T));
- Initializer<T, std::is_pod<T>::value>::initialize(rs, count);
+ if (!std::is_trivially_constructible<T>::value)
+ {
+ for (Index i = 0; i < count; i++)
+ new (rs + i) T();
+ }
return rs;
}
static inline void deallocateArray(T* ptr, Index count)
diff --git a/source/core/slang-chunked-list.h b/source/core/slang-chunked-list.h
index 36f97cedd..0ac26c945 100644
--- a/source/core/slang-chunked-list.h
+++ b/source/core/slang-chunked-list.h
@@ -40,12 +40,16 @@ private:
resultChunk->size = 0;
resultChunk->next = nullptr;
auto firstItem = resultChunk->begin();
- Initializer<T, std::is_pod<T>::value>::initialize(firstItem, size);
+ if (!std::is_trivially_constructible_v<T>)
+ {
+ for (uint32_t i = 0; i < size; i++)
+ new (firstItem + i) T();
+ }
return resultChunk;
}
void freeChunk(Chunk* chunk)
{
- if (!std::is_trivially_destructible<T>::value)
+ if (!std::is_trivially_destructible_v<T>)
{
for (uint32_t i = 0; i < chunk->capacity; i++)
chunk->begin()[i].~T();
diff --git a/source/core/slang-crypto.h b/source/core/slang-crypto.h
index 0df02201c..94078861b 100644
--- a/source/core/slang-crypto.h
+++ b/source/core/slang-crypto.h
@@ -167,7 +167,7 @@ namespace Slang
append(digest.data, sizeof(digest.data));
}
- template<typename T, typename std::enable_if<std::is_pod<T>::value, int>::type = 0>
+ template<typename T, std::enable_if_t<std::has_unique_object_representations_v<T>, int> = 0>
void append(const List<T>& list)
{
append(list.getBuffer(), list.getCount() * sizeof(T));
diff --git a/source/core/slang-memory-arena.h b/source/core/slang-memory-arena.h
index a947de5a2..75f3faac3 100644
--- a/source/core/slang-memory-arena.h
+++ b/source/core/slang-memory-arena.h
@@ -377,7 +377,7 @@ SLANG_FORCE_INLINE T* MemoryArena::allocateArray(size_t numElems)
template <typename T>
SLANG_FORCE_INLINE T* MemoryArena::allocateAndCopyArray(const T* arr, size_t numElems)
{
- SLANG_COMPILE_TIME_ASSERT(std::is_pod<T>::value);
+ static_assert(std::is_trivially_copyable_v<T>);
if (numElems > 0)
{
const size_t totalSize = sizeof(T) * numElems;
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 185f31b30..ae830ca4f 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -96,7 +96,7 @@ namespace Slang
IROpInfo getIROpInfo(IROp opIn)
{
- const int op = opIn & kIROpMeta_OpMask;
+ const int op = opIn & kIROpMask_OpMask;
if (op < kIROpCount)
{
// It's a main op
@@ -6563,8 +6563,8 @@ namespace Slang
return false;
}
- const IROp opA = IROp(a->getOp() & kIROpMeta_OpMask);
- const IROp opB = IROp(b->getOp() & kIROpMeta_OpMask);
+ const IROp opA = IROp(a->getOp() & kIROpMask_OpMask);
+ const IROp opB = IROp(b->getOp() & kIROpMask_OpMask);
if (opA != opB)
{
diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h
index 6d42e9909..47aa5333a 100644
--- a/source/slang/slang-ir.h
+++ b/source/slang/slang-ir.h
@@ -7,6 +7,9 @@
// similar in spirit to LLVM (but much simpler).
//
+#if defined(__cpp_lib_bit_cast)
+#include <bit>
+#endif
#include <functional>
#include "../core/slang-basic.h"
@@ -47,7 +50,7 @@ enum : IROpFlags
MainOp | Other
Bit range: 0-10 | Remaining bits
-For doing range checks (for example for doing isa tests), the value is masked by kIROpMeta_OpMask, such that the Other bits don't interfere.
+For doing range checks (for example for doing isa tests), the value is masked by kIROpMask_OpMask, such that the Other bits don't interfere.
The other bits can be used for storage for anything that needs to identify as a different 'op' or 'type'. It is currently
used currently for storing the TextureFlavor of a IRResourceTypeBase derived types for example.
@@ -74,13 +77,32 @@ enum IROp : int32_t
#include "slang-ir-inst-defs.h"
};
-/* IROpMeta describe values for layout of IROp, as well as values for accessing aspects of IROp bits. */
+/* IROpMeta describes values for the layout of IROps */
enum IROpMeta
{
- kIROpMeta_OtherShift = 10, ///< Number of bits for op (shift right by this to get the other bits)
- kIROpMeta_OpMask = 0x3ff, ///< Mask for just opcode
+ kIROpMeta_OtherShift = 10, ///< Number of bits for op (shift right by this to get the other bits)
+};
+
+/* IROpMask contains bitmasks for accessing aspects of IROps */
+enum IROpMask : std::underlying_type_t<IROp>
+{
+ kIROpMask_OpMask = 0x3ff, ///< Mask for just opcode
};
+inline int32_t operator&(const IROpMask m, const IROp o)
+{
+#if defined(__cpp_lib_bit_cast)
+ return std::bit_cast<int32_t>(m) & std::bit_cast<int32_t>(o);
+#else
+ return (int32_t)m & (int32_t)o;
+#endif
+}
+
+inline int32_t operator&(const IROp o, const IROpMask m)
+{
+ return m & o;
+}
+
IROp findIROp(const UnownedStringSlice& name);
// A logical operation/opcode in the IR
@@ -911,8 +933,8 @@ typename IRFilteredInstList<T>::Iterator IRFilteredInstList<T>::end()
// Types
-#define IR_LEAF_ISA(NAME) static bool isaImpl(IROp op) { return (kIROpMeta_OpMask & op) == kIROp_##NAME; }
-#define IR_PARENT_ISA(NAME) static bool isaImpl(IROp opIn) { const int op = (kIROpMeta_OpMask & opIn); return op >= kIROp_First##NAME && op <= kIROp_Last##NAME; }
+#define IR_LEAF_ISA(NAME) static bool isaImpl(IROp op) { return (kIROpMask_OpMask & op) == kIROp_##NAME; }
+#define IR_PARENT_ISA(NAME) static bool isaImpl(IROp opIn) { const int op = (kIROpMask_OpMask & opIn); return op >= kIROp_First##NAME && op <= kIROp_Last##NAME; }
#define SIMPLE_IR_TYPE(NAME, BASE) struct IR##NAME : IR##BASE { IR_LEAF_ISA(NAME) };
#define SIMPLE_IR_PARENT_TYPE(NAME, BASE) struct IR##NAME : IR##BASE { IR_PARENT_ISA(NAME) };
@@ -929,7 +951,7 @@ struct IRType : IRInst
// `IR_PARENT_ISA` macro here.
static bool isaImpl(IROp opIn)
{
- const int op = (kIROpMeta_OpMask & opIn);
+ const int op = (kIROpMask_OpMask & opIn);
return (op >= kIROp_FirstType && op <= kIROp_LastType) || op == kIROp_Specialize;
}
};
diff --git a/source/slang/slang-serialize-ir.cpp b/source/slang/slang-serialize-ir.cpp
index d87fc38e2..2da923c43 100644
--- a/source/slang/slang-serialize-ir.cpp
+++ b/source/slang/slang-serialize-ir.cpp
@@ -12,13 +12,13 @@ namespace Slang {
static bool _isTextureTypeBase(IROp opIn)
{
- const int op = (kIROpMeta_OpMask & opIn);
+ const int op = (kIROpMask_OpMask & opIn);
return op >= kIROp_FirstTextureTypeBase && op <= kIROp_LastTextureTypeBase;
}
static bool _isConstant(IROp opIn)
{
- const int op = (kIROpMeta_OpMask & opIn);
+ const int op = (kIROpMask_OpMask & opIn);
return op >= kIROp_FirstConstant && op <= kIROp_LastConstant;
}
@@ -190,7 +190,7 @@ Result IRSerialWriter::write(IRModule* module, SerialSourceLocWriter* sourceLocW
IRInst* srcInst = m_insts[i];
Ser::Inst& dstInst = m_serialData->m_insts[i];
- dstInst.m_op = uint16_t(srcInst->getOp() & kIROpMeta_OpMask);
+ dstInst.m_op = uint16_t(srcInst->getOp() & kIROpMask_OpMask);
dstInst.m_payloadType = PayloadType::Empty;
dstInst.m_resultTypeIndex = getInstIndex(srcInst->getFullType());