Skip to content

Commit e575e6a

Browse files
committed
Unified tests
1 parent 668f3f1 commit e575e6a

File tree

1 file changed

+142
-160
lines changed

1 file changed

+142
-160
lines changed

examples_tests/10.AllocatorTest/main.cpp

Lines changed: 142 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,41 @@
66
using namespace irr;
77
using namespace core;
88

9-
#define ALLOCATOR_TEST
10-
//#define ADDRESS_ALLOCATOR_TRAITS_TEST
11-
//#define ALLOC_PREF_TEST
9+
#define kNumHardwareInstancesX 10
10+
#define kNumHardwareInstancesY 20
11+
#define kNumHardwareInstancesZ 30
12+
13+
#define kHardwareInstancesTOTAL (kNumHardwareInstancesX*kNumHardwareInstancesY*kNumHardwareInstancesZ)
14+
15+
16+
//!Same As Last Example
17+
class MyEventReceiver : public IEventReceiver
18+
{
19+
public:
20+
21+
MyEventReceiver()
22+
{
23+
}
24+
25+
bool OnEvent(const SEvent& event)
26+
{
27+
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
28+
{
29+
switch (event.KeyInput.Key)
30+
{
31+
case irr::KEY_KEY_Q: // switch wire frame mode
32+
exit(0);
33+
return true;
34+
default:
35+
break;
36+
}
37+
}
1238

13-
#ifdef ALLOCATOR_TEST
39+
return false;
40+
}
41+
42+
private:
43+
};
1444

1545
constexpr size_t minTestsCnt = 10000u;
1646
constexpr size_t maxTestsCnt = 20000u;
@@ -261,178 +291,130 @@ void AllocatorHandler<core::LinearAddressAllocator<uint32_t>>::randFreeAllocated
261291
int main()
262292
{
263293

264-
294+
// Allocator test
265295
{
266-
AllocatorHandler<core::PoolAddressAllocator<uint32_t>> poolAlctrHandler;
267-
poolAlctrHandler.executeAllocatorTest();
268-
}
296+
{
297+
AllocatorHandler<core::PoolAddressAllocator<uint32_t>> poolAlctrHandler;
298+
poolAlctrHandler.executeAllocatorTest();
299+
}
269300

270-
{
271-
AllocatorHandler<core::LinearAddressAllocator<uint32_t>> linearAlctrHandler;
272-
linearAlctrHandler.executeAllocatorTest();
273-
}
301+
{
302+
AllocatorHandler<core::LinearAddressAllocator<uint32_t>> linearAlctrHandler;
303+
linearAlctrHandler.executeAllocatorTest();
304+
}
274305

275-
//crashes..
276-
{
277-
AllocatorHandler<core::StackAddressAllocator<uint32_t>> stackAlctrHandler;
278-
stackAlctrHandler.executeAllocatorTest();
306+
{
307+
AllocatorHandler<core::StackAddressAllocator<uint32_t>> stackAlctrHandler;
308+
stackAlctrHandler.executeAllocatorTest();
309+
}
310+
311+
{
312+
AllocatorHandler<core::GeneralpurposeAddressAllocator<uint32_t>> generalpurposeAlctrHandler;
313+
generalpurposeAlctrHandler.executeAllocatorTest();
314+
}
279315
}
280316

281-
//crashes..
282-
{
283-
AllocatorHandler<core::GeneralpurposeAddressAllocator<uint32_t>> generalpurposeAlctrHandler;
284-
generalpurposeAlctrHandler.executeAllocatorTest();
285-
}
286-
}
287-
288-
#endif
289-
290-
#ifdef ADDRESS_ALLOCATOR_TRAITS_TEST
291-
292-
int main()
293-
{
294-
printf("SINGLE THREADED======================================================\n");
295-
printf("Linear \n");
296-
irr::core::address_allocator_traits<core::LinearAddressAllocatorST<uint32_t> >::printDebugInfo();
297-
printf("Stack \n");
298-
irr::core::address_allocator_traits<core::StackAddressAllocatorST<uint32_t> >::printDebugInfo();
299-
printf("Pool \n");
300-
irr::core::address_allocator_traits<core::PoolAddressAllocatorST<uint32_t> >::printDebugInfo();
301-
printf("General \n");
302-
irr::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorST<uint32_t> >::printDebugInfo();
303-
304-
printf("MULTI THREADED=======================================================\n");
305-
printf("Linear \n");
306-
irr::core::address_allocator_traits<core::LinearAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
307-
printf("Pool \n");
308-
irr::core::address_allocator_traits<core::PoolAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
309-
printf("General \n");
310-
irr::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
311-
312-
return 0;
313-
}
314-
#endif
315317

316-
#ifdef ALLOC_PREF_TEST
317-
318-
#define kNumHardwareInstancesX 10
319-
#define kNumHardwareInstancesY 20
320-
#define kNumHardwareInstancesZ 30
321-
322-
#define kHardwareInstancesTOTAL (kNumHardwareInstancesX*kNumHardwareInstancesY*kNumHardwareInstancesZ)
323-
324-
325-
//!Same As Last Example
326-
class MyEventReceiver : public IEventReceiver
327-
{
328-
public:
329-
330-
MyEventReceiver()
318+
// Address allocator traits test
331319
{
320+
printf("SINGLE THREADED======================================================\n");
321+
printf("Linear \n");
322+
irr::core::address_allocator_traits<core::LinearAddressAllocatorST<uint32_t> >::printDebugInfo();
323+
printf("Stack \n");
324+
irr::core::address_allocator_traits<core::StackAddressAllocatorST<uint32_t> >::printDebugInfo();
325+
printf("Pool \n");
326+
irr::core::address_allocator_traits<core::PoolAddressAllocatorST<uint32_t> >::printDebugInfo();
327+
printf("General \n");
328+
irr::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorST<uint32_t> >::printDebugInfo();
329+
330+
printf("MULTI THREADED=======================================================\n");
331+
printf("Linear \n");
332+
irr::core::address_allocator_traits<core::LinearAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
333+
printf("Pool \n");
334+
irr::core::address_allocator_traits<core::PoolAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
335+
printf("General \n");
336+
irr::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorMT<uint32_t, std::recursive_mutex> >::printDebugInfo();
332337
}
333338

334-
bool OnEvent(const SEvent& event)
339+
// Alloc pref test
335340
{
336-
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
341+
// create device with full flexibility over creation parameters
342+
// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
343+
irr::SIrrlichtCreationParameters params;
344+
params.Bits = 24; //may have to set to 32bit for some platforms
345+
params.ZBufferBits = 24; //we'd like 32bit here
346+
params.DriverType = video::EDT_OPENGL; //! Only Well functioning driver, software renderer left for sake of 2D image drawing
347+
params.WindowSize = dimension2d<uint32_t>(1280, 720);
348+
params.Fullscreen = false;
349+
params.Vsync = false;
350+
params.Doublebuffer = true;
351+
params.Stencilbuffer = false; //! This will not even be a choice soon
352+
auto device = createDeviceEx(params);
353+
354+
if (!device)
355+
return 1; // could not create selected driver.
356+
357+
358+
video::IVideoDriver* driver = device->getVideoDriver();
359+
360+
size_t allocSize = 128;
361+
362+
constexpr size_t kMinAllocs = 10000u;
363+
constexpr size_t kMaxAllocs = 20000u;
364+
365+
366+
scene::ISceneManager* smgr = device->getSceneManager();
367+
MyEventReceiver receiver;
368+
device->setEventReceiver(&receiver);
369+
370+
371+
video::IDriverMemoryBacked::SDriverMemoryRequirements reqs;
372+
reqs.vulkanReqs.size = 0x1000000u;
373+
reqs.vulkanReqs.alignment = 4;
374+
reqs.vulkanReqs.memoryTypeBits = 0xffffffffu;
375+
reqs.memoryHeapLocation = video::IDriverMemoryAllocation::ESMT_DEVICE_LOCAL;
376+
reqs.mappingCapability = video::IDriverMemoryAllocation::EMCF_CAN_MAP_FOR_WRITE | video::IDriverMemoryAllocation::EMCF_COHERENT;
377+
reqs.prefersDedicatedAllocation = true;
378+
reqs.requiresDedicatedAllocation = true;
379+
auto buffer = core::make_smart_refctd_ptr<video::StreamingTransientDataBufferST<> >(driver, reqs);
380+
381+
std::mt19937 mt(0xdeadu);
382+
std::uniform_int_distribution<uint32_t> allocsPerFrame(kMinAllocs, kMaxAllocs);
383+
std::uniform_int_distribution<uint32_t> size(1, 1024 * 1024);
384+
std::uniform_int_distribution<uint32_t> alignment(1, 128);
385+
386+
uint64_t lastFPSTime = 0;
387+
while (device->run())
388+
//if (device->isWindowActive())
337389
{
338-
switch (event.KeyInput.Key)
390+
driver->beginScene(true, true, video::SColor(255, 0, 0, 255));
391+
392+
auto allocsThisFrame = allocsPerFrame(mt);
393+
uint32_t outAddr[kMaxAllocs];
394+
uint32_t sizes[kMaxAllocs];
395+
uint32_t alignments[kMaxAllocs];
396+
for (size_t i = 0; i < allocsThisFrame; i++)
339397
{
340-
case irr::KEY_KEY_Q: // switch wire frame mode
341-
exit(0);
342-
return true;
343-
default:
344-
break;
398+
outAddr[i] = video::StreamingTransientDataBufferST<>::invalid_address;
399+
sizes[i] = size(mt);
400+
alignments[i] = alignment(mt);
345401
}
346-
}
347402

348-
return false;
349-
}
350-
351-
private:
352-
};
403+
buffer->multi_alloc(allocsThisFrame, (uint32_t*)outAddr, (const uint32_t*)sizes, (const uint32_t*)alignments);
404+
buffer->multi_free(allocsThisFrame, (const uint32_t*)outAddr, (const uint32_t*)sizes, driver->placeFence());
353405

406+
driver->endScene();
354407

355-
int main()
356-
{
357-
// create device with full flexibility over creation parameters
358-
// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
359-
irr::SIrrlichtCreationParameters params;
360-
params.Bits = 24; //may have to set to 32bit for some platforms
361-
params.ZBufferBits = 24; //we'd like 32bit here
362-
params.DriverType = video::EDT_OPENGL; //! Only Well functioning driver, software renderer left for sake of 2D image drawing
363-
params.WindowSize = dimension2d<uint32_t>(1280, 720);
364-
params.Fullscreen = false;
365-
params.Vsync = false;
366-
params.Doublebuffer = true;
367-
params.Stencilbuffer = false; //! This will not even be a choice soon
368-
auto device = createDeviceEx(params);
369-
370-
if (!device)
371-
return 1; // could not create selected driver.
372-
373-
374-
video::IVideoDriver* driver = device->getVideoDriver();
375-
376-
size_t allocSize = 128;
377-
378-
constexpr size_t kMinAllocs = 10000u;
379-
constexpr size_t kMaxAllocs = 20000u;
380-
381-
382-
scene::ISceneManager* smgr = device->getSceneManager();
383-
MyEventReceiver receiver;
384-
device->setEventReceiver(&receiver);
385-
386-
387-
video::IDriverMemoryBacked::SDriverMemoryRequirements reqs;
388-
reqs.vulkanReqs.size = 0x1000000u;
389-
reqs.vulkanReqs.alignment = 4;
390-
reqs.vulkanReqs.memoryTypeBits = 0xffffffffu;
391-
reqs.memoryHeapLocation = video::IDriverMemoryAllocation::ESMT_DEVICE_LOCAL;
392-
reqs.mappingCapability = video::IDriverMemoryAllocation::EMCF_CAN_MAP_FOR_WRITE | video::IDriverMemoryAllocation::EMCF_COHERENT;
393-
reqs.prefersDedicatedAllocation = true;
394-
reqs.requiresDedicatedAllocation = true;
395-
auto buffer = core::make_smart_refctd_ptr<video::StreamingTransientDataBufferST<> >(driver, reqs);
396-
397-
std::mt19937 mt(0xdeadu);
398-
std::uniform_int_distribution<uint32_t> allocsPerFrame(kMinAllocs, kMaxAllocs);
399-
std::uniform_int_distribution<uint32_t> size(1, 1024 * 1024);
400-
std::uniform_int_distribution<uint32_t> alignment(1, 128);
401-
402-
uint64_t lastFPSTime = 0;
403-
while (device->run())
404-
//if (device->isWindowActive())
405-
{
406-
driver->beginScene(true, true, video::SColor(255, 0, 0, 255));
407-
408-
auto allocsThisFrame = allocsPerFrame(mt);
409-
uint32_t outAddr[kMaxAllocs];
410-
uint32_t sizes[kMaxAllocs];
411-
uint32_t alignments[kMaxAllocs];
412-
for (size_t i = 0; i < allocsThisFrame; i++)
413-
{
414-
outAddr[i] = video::StreamingTransientDataBufferST<>::invalid_address;
415-
sizes[i] = size(mt);
416-
alignments[i] = alignment(mt);
417-
}
418-
419-
buffer->multi_alloc(allocsThisFrame, (uint32_t*)outAddr, (const uint32_t*)sizes, (const uint32_t*)alignments);
420-
buffer->multi_free(allocsThisFrame, (const uint32_t*)outAddr, (const uint32_t*)sizes, driver->placeFence());
421-
422-
driver->endScene();
423-
424-
// display frames per second in window title
425-
uint64_t time = device->getTimer()->getRealTime();
426-
if (time - lastFPSTime > 1000)
427-
{
428-
std::wostringstream sstr;
429-
sstr << L"Alloc Perf Test- Irrlicht Engine [" << driver->getName() << "] K-Allocs/second:" << driver->getFPS() * allocsThisFrame;
408+
// display frames per second in window title
409+
uint64_t time = device->getTimer()->getRealTime();
410+
if (time - lastFPSTime > 1000)
411+
{
412+
std::wostringstream sstr;
413+
sstr << L"Alloc Perf Test- Irrlicht Engine [" << driver->getName() << "] K-Allocs/second:" << driver->getFPS() * allocsThisFrame;
430414

431-
device->setWindowCaption(sstr.str().c_str());
432-
lastFPSTime = time;
415+
device->setWindowCaption(sstr.str().c_str());
416+
lastFPSTime = time;
417+
}
433418
}
434419
}
435-
436-
return 0;
437-
}
438-
#endif
420+
}

0 commit comments

Comments
 (0)