diff --git a/src/bvh/v2/index.h b/src/bvh/v2/index.h index beec4ae..7120031 100644 --- a/src/bvh/v2/index.h +++ b/src/bvh/v2/index.h @@ -36,6 +36,7 @@ struct Index { static constexpr size_t bits = Bits; static constexpr size_t prim_count_bits = PrimCountBits; static constexpr Type max_prim_count = make_bitmask(prim_count_bits); + static constexpr Type max_first_id = make_bitmask(bits - prim_count_bits); static_assert(PrimCountBits < Bits); @@ -52,29 +53,31 @@ struct Index { BVH_ALWAYS_INLINE bool is_leaf() const { return prim_count() != 0; } BVH_ALWAYS_INLINE bool is_inner() const { return !is_leaf(); } - BVH_ALWAYS_INLINE void set_first_id(Type first_id) { + BVH_ALWAYS_INLINE void set_first_id(size_t first_id) { *this = Index { first_id, prim_count() }; } - BVH_ALWAYS_INLINE void set_prim_count(Type prim_count) { + BVH_ALWAYS_INLINE void set_prim_count(size_t prim_count) { *this = Index { first_id(), prim_count }; } - static BVH_ALWAYS_INLINE Index make_leaf(Type first_prim, Type prim_count) { + static BVH_ALWAYS_INLINE Index make_leaf(size_t first_prim, size_t prim_count) { assert(prim_count != 0); return Index { first_prim, prim_count }; } - static BVH_ALWAYS_INLINE Index make_inner(Type first_child) { + static BVH_ALWAYS_INLINE Index make_inner(size_t first_child) { return Index { first_child, 0 }; } private: - explicit Index(Type first_id, Type prim_count) - : value((first_id << prim_count_bits) | (prim_count & max_prim_count)) + explicit Index(size_t first_id, size_t prim_count) + : Index( + (static_cast(first_id) << prim_count_bits) | + (static_cast(prim_count) & max_prim_count)) { - assert(first_id <= make_bitmask(Bits - PrimCountBits)); - assert(prim_count <= max_prim_count); + assert(first_id <= static_cast(max_first_id)); + assert(prim_count <= static_cast(max_prim_count)); } };