Skip to content

Commit b4c0d1c

Browse files
Merge pull request #76 from Devsh-Graphics-Programming/raytracing
Raytracing Example Refactor, Subgroup Op Fixes, FFT improvements
2 parents e827333 + 34ca630 commit b4c0d1c

File tree

83 files changed

+5099
-3597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+5099
-3597
lines changed

examples_tests/10.AllocatorTest/main.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ class AllocatorHandler
106106
alctr = AlctrType(reservedSpace, randAllocParams.offset, randAllocParams.alignOffset, randAllocParams.maxAlign, randAllocParams.addressSpaceSize, randAllocParams.blockSz);
107107
}
108108

109-
// variable shadowing and other problems @Przemog
110-
testsCnt = rng.getRndAllocCnt();
111-
for (size_t i = 0; i < testsCnt; i++)
109+
uint32_t subTestsCnt = rng.getRndAllocCnt();
110+
for (size_t i = 0; i < subTestsCnt; i++)
112111
executeForFrame(alctr, randAllocParams);
113112

114113
if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t>>::value)
@@ -122,6 +121,19 @@ class AllocatorHandler
122121
uint32_t outAddr = AlctrType::invalid_address;
123122
uint32_t size = 0u;
124123
uint32_t align = 0u;
124+
125+
inline bool operator==(const AllocationData& other) const
126+
{
127+
return outAddr==other.outAddr;
128+
}
129+
130+
struct Hash
131+
{
132+
inline size_t operator()(const AllocationData& _this) const
133+
{
134+
return std::hash<uint32_t>()(_this.outAddr);
135+
}
136+
};
125137
};
126138

127139
struct RandParams
@@ -146,11 +158,13 @@ class AllocatorHandler
146158
Traits::multi_alloc_addr(alctr, addressesToAllcate, allocDataSoA.outAddresses.data(), allocDataSoA.sizes.data(), allocDataSoA.alignments.data());
147159

148160
// record all successful alloc addresses to the `core::vector`
161+
if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t>>::value)
149162
for (uint32_t j = 0u; j < allocDataSoA.size; j++)
150163
{
151164
if (allocDataSoA.outAddresses[j] != AlctrType::invalid_address)
152165
results.push_back({ allocDataSoA.outAddresses[j], allocDataSoA.sizes[j], allocDataSoA.alignments[j] });
153166
}
167+
checkStillIteratable(alctr);
154168

155169
// run random dealloc function
156170
randFreeAllocatedAddresses(alctr);
@@ -173,10 +187,7 @@ class AllocatorHandler
173187
}
174188
}
175189
else
176-
{
177190
alctr.reset();
178-
results.clear();
179-
}
180191
}
181192

182193
// random dealloc function
@@ -188,10 +199,8 @@ class AllocatorHandler
188199
// randomly decide how many calls to `multi_free`
189200
const uint32_t multiFreeCnt = rng.getRandomNumber(1u, results.size());
190201

191-
if (std::is_same<AlctrType, core::GeneralpurposeAddressAllocator<uint32_t>>::value)
192-
{
202+
if constexpr (Traits::supportsArbitraryOrderFrees)
193203
std::shuffle(results.begin(), results.end(), rng.getMt());
194-
}
195204

196205
for (uint32_t i = 0u; (i < multiFreeCnt) && results.size(); i++)
197206
{
@@ -210,6 +219,7 @@ class AllocatorHandler
210219

211220
Traits::multi_free_addr(alctr, addressesToFreeCnt, allocDataSoA.outAddresses.data(), allocDataSoA.sizes.data());
212221
results.erase(results.end() - addressesToFreeCnt, results.end());
222+
checkStillIteratable(alctr);
213223
}
214224
}
215225

@@ -231,6 +241,19 @@ class AllocatorHandler
231241

232242
private:
233243
core::vector<AllocationData> results;
244+
inline void checkStillIteratable(const AlctrType& alctr)
245+
{
246+
if constexpr (std::is_same<AlctrType, core::IteratablePoolAddressAllocator<uint32_t>>::value)
247+
{
248+
core::unordered_set<AllocationData,AllocationData::Hash> allocationSet(results.begin(),results.end());
249+
for (auto addr : alctr)
250+
{
251+
AllocationData dummy; dummy.outAddr = addr;
252+
if (allocationSet.find(dummy)==allocationSet.end())
253+
exit(34);
254+
}
255+
}
256+
}
234257

235258
//these hold inputs for `multi_alloc_addr` and `multi_free_addr`
236259

@@ -247,7 +270,7 @@ class AllocatorHandler
247270
{
248271
// randomly decide sizes (but always less than `address_allocator_traits::max_size`)
249272

250-
if constexpr (std::is_same<AlctrType, core::PoolAddressAllocator<uint32_t>>::value)
273+
if constexpr (std::is_same_v<AlctrType,core::PoolAddressAllocator<uint32_t>>||std::is_same_v<AlctrType,core::IteratablePoolAddressAllocator<uint32_t>>)
251274
{
252275
sizes[j] = randAllocParams.blockSz;
253276
alignments[j] = randAllocParams.blockSz;
@@ -310,6 +333,11 @@ int main()
310333
poolAlctrHandler.executeAllocatorTest();
311334
}
312335

336+
{
337+
AllocatorHandler<core::IteratablePoolAddressAllocator<uint32_t>> iterPoolAlctrHandler;
338+
iterPoolAlctrHandler.executeAllocatorTest();
339+
}
340+
313341
{
314342
AllocatorHandler<core::LinearAddressAllocator<uint32_t>> linearAlctrHandler;
315343
linearAlctrHandler.executeAllocatorTest();
@@ -336,6 +364,8 @@ int main()
336364
nbl::core::address_allocator_traits<core::StackAddressAllocatorST<uint32_t> >::printDebugInfo();
337365
printf("Pool \n");
338366
nbl::core::address_allocator_traits<core::PoolAddressAllocatorST<uint32_t> >::printDebugInfo();
367+
printf("IteratablePool \n");
368+
nbl::core::address_allocator_traits<core::IteratablePoolAddressAllocatorST<uint32_t> >::printDebugInfo();
339369
printf("General \n");
340370
nbl::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorST<uint32_t> >::printDebugInfo();
341371

@@ -344,6 +374,8 @@ int main()
344374
nbl::core::address_allocator_traits<core::LinearAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
345375
printf("Pool \n");
346376
nbl::core::address_allocator_traits<core::PoolAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
377+
printf("Iteratable Pool \n");
378+
nbl::core::address_allocator_traits<core::IteratablePoolAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
347379
printf("General \n");
348380
nbl::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
349381
}

0 commit comments

Comments
 (0)