Skip to content

Commit a0881e2

Browse files
committed
use iota_view
1 parent c692d01 commit a0881e2

File tree

1 file changed

+6
-59
lines changed

1 file changed

+6
-59
lines changed

src/nbl/asset/ICPUImage.cpp

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "nbl/asset/filters/CMatchedSizeInOutImageFilterCommon.h"
44
#include "nbl/asset/filters/CFlattenRegionsImageFilter.h"
55

6+
#include <ranges>
7+
68
using namespace nbl;
79
using namespace asset;
810

@@ -81,56 +83,6 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
8183

8284
using state_type = CState;
8385

84-
// A wrapper for an additive, in[de]crementable value, so you can use values as iterators
85-
template <typename Type, typename DiffType = std::ptrdiff_t>
86-
struct ValueIterator {
87-
88-
// Iterator type traits
89-
using iterator_category = std::random_access_iterator_tag;
90-
using difference_type = DiffType; //must be a signed integer-like type
91-
using value_type = Type;
92-
using reference = Type;
93-
using pointer = Type;
94-
95-
inline explicit ValueIterator(value_type value) : m_value(value) {};
96-
inline ValueIterator() : m_value{} {};
97-
ValueIterator(const ValueIterator& other) = default;
98-
ValueIterator(ValueIterator&& other) = default;
99-
100-
ValueIterator& operator=(const ValueIterator& other) = default;
101-
ValueIterator& operator=(ValueIterator&& other) = default;
102-
103-
// Iterator traits
104-
inline reference operator*() const { return m_value; }
105-
inline ValueIterator& operator++() { m_value++; return *this; }
106-
inline ValueIterator operator++(int) { ValueIterator tmp = *this; ++(*this); return tmp; }
107-
108-
// InputIterator traits
109-
inline bool operator==(const ValueIterator& other) const { return m_value == other.operator*(); }
110-
inline bool operator!=(const ValueIterator& other) const { return !operator==(other); }
111-
inline pointer operator->() const { return m_value; }
112-
113-
// BidirectionalIterator traits
114-
inline ValueIterator& operator--() { m_value--; return *this; }
115-
inline ValueIterator operator--(int) { ValueIterator tmp = *this; --(*this); return tmp; }
116-
117-
//RandomAccessIterator traits
118-
inline ValueIterator& operator+=(difference_type advance) { m_value += advance; return *this; }
119-
inline ValueIterator operator+(difference_type advance) const { return ValueIterator(m_value + advance); }
120-
friend inline ValueIterator operator+(difference_type advance, const ValueIterator& other) { return valueIterator(advance + *other); }
121-
inline ValueIterator& operator-=(difference_type advance) { m_value -= advance; return *this; }
122-
inline ValueIterator operator-(difference_type advance) const { return ValueIterator(m_value - advance); }
123-
inline value_type operator[] (int index) const { return m_value + index; }
124-
inline difference_type operator-(const ValueIterator& other) const { return m_value - *other; }
125-
inline bool operator< (const ValueIterator& other) const { return m_value < *other; }
126-
inline bool operator> (const ValueIterator& other) const { return m_value > *other; }
127-
inline bool operator>= (const ValueIterator& other) const { return m_value >= *other; }
128-
inline bool operator<= (const ValueIterator& other) const { return m_value <= *other; }
129-
130-
private:
131-
value_type m_value;
132-
};
133-
13486
static inline bool validate(state_type* state)
13587
{
13688
if (!state)
@@ -253,13 +205,8 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
253205
const auto texelOrBlockByteSize = asset::getTexelOrBlockBytesize(parameters.format);
254206
const uint8_t* inData = reinterpret_cast<const uint8_t*>(image->getBuffer()->getPointer());
255207

256-
struct range {
257-
ValueIterator<uint32_t> begin;
258-
ValueIterator<uint32_t> end;
259-
};
260-
261-
range layers = { .begin{0}, .end{parameters.arrayLayers} };
262-
range levels = { .begin{0}, .end{parameters.mipLevels} };
208+
auto layers = std::views::iota(0u, parameters.arrayLayers);
209+
auto levels = std::views::iota(0u, parameters.mipLevels);
263210

264211
/*
265212
we stream-hash texels per given mip level & layer
@@ -298,10 +245,10 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
298245
blake3_hasher_finalize(hasher, reinterpret_cast<uint8_t*>(hash), sizeof(CState::hash_t)); // finalize hash for layer + put it to heap for given mip level
299246
};
300247

301-
std::for_each(policy, layers.begin, layers.end, executePerLayer); // fire per layer for given given mip level with specified execution policy, yes you can use parallel policy here if you want at it will work
248+
std::for_each(policy, layers.begin(), layers.end(), executePerLayer); // fire per layer for given given mip level with specified execution policy, yes you can use parallel policy here if you want at it will work
302249
};
303250

304-
std::for_each(policy, levels.begin, levels.end, executePerMipLevel); // fire per block of layers for given mip level with specified execution policy, yes you can use parallel policy here if you want at it will work
251+
std::for_each(policy, levels.begin(), levels.end(), executePerMipLevel); // fire per block of layers for given mip level with specified execution policy, yes you can use parallel policy here if you want at it will work
305252

306253
/*
307254
scratch's heap is filled with all hashes,

0 commit comments

Comments
 (0)