A fun Haiku ray tracing demo

I love ray tracing and I love multi-threading, so I decided to combine the two. Here is a demo I put together that combines ray tracing and multi-threading in a simple demo package. It is a crude proof of concept with lots of bugs and crashes, but still fun.

It has 6 scenes that are built in, as menu options. It will not read scene files. This a result of the ray tracing code that was used.

Basic use:
select your rendering screen size, start with the smallest - 160X120. Then select the scene, start with scene 0. Then select Command/Start. Use the Haiku CPU indicator to determine when rendering has completed. Then select Draw.

If your CPU has multiple cores or hyperthreading, add more threads and you get a nice rendering speed up!

Use the wrong scene with too many threads and the app with run out of memory and crash. Have to fix that.

Here is the link the BeTracer demo:

  • https://onedrive.live.com/redir?resid=23646DEFC0827C85!3977&authkey=!AC9ascWSzjh5Nik&ithint=folder%2c

Have fun, comments appreciated.

Best regards for a happy 2016!
Andrew

Nice one :slight_smile:
A simple redar every second… once the raytracing is started would be awesom :slight_smile:

My goal is to automatically update the image 15 times per second :slight_smile:

Bugreport :-):

Reproducable crash with scene 3
Debug information for team /boot/home/downloads/BeTracer (6293):
CPU(s): 4x Intel Core i5
Memory: 3.80 GiB total, 406.92 MiB used
Haiku revision: hrev49974 Jan 3 2016 18:43:35 (BePC)

Active Threads:
thread 6293: BeTracer (main)
thread 6297: w>BeTracer
thread 6311: name
thread 6312: name
thread 6313: name
thread 6315: team 6293 debug task
thread 6314: name
state: Call (getNumAvailable() == 0)

	Frame		IP			Function Name
	-----------------------------------------------
	00000000	0x60d70112	commpage_syscall + 0x2 
		Disassembly:
			commpage_syscall:
			0x60d70110:             89e1  mov %esp, %ecx
			0x60d70112:             0f34  sysenter  <--

		Frame memory:
			
	0x7983f368	0x812a31	debugger + 0x31 
	0x7983f388	0x820193	__assert_fail + 0x43 
	0x7983f3a8	0x8118cf	/boot/system/lib/x86/libroot.so + 0x268cf 
	0x7983f3e0	0x898a26	BPrivate::hoardHeap::findAvailableSuperblock(int, BPrivate::block*&, BPrivate::processHeap*) + 0x416 
	0x7983f430	0x896b10	BPrivate::threadHeap::malloc(unsigned long) + 0x70 
	0x7983f470	0x896e47	malloc + 0xa7 
	0x7983f490	0x11bda60	operator new(unsigned long) + 0x20 
	0x7983f4e0	0xb3aa46	CSG::CSGIntersection::texture() + 0xd6 
	0x7983f530	0xb3a990	CSG::CSGIntersection::texture() + 0x20 
	0x7983f5a0	0xb4684b	LightRay::shoot(float&) + 0x11b 
	0x7983f630	0xb488e6	Texture::enlightLight(LightRay&, CameraRay const&) const + 0x36 
	0x7983f6c0	0xb4a2ed	PointLight::enlight(CameraRay const&, Texture const*, InsideList*) const + 0x4d 
	0x7983f7c0	0xb45f8f	Scene::intersectRec(CameraRay&) + 0x12f 
	0x7983f7f0	0xb4648c	Scene::intersect(CameraRay&) + 0x2c 
	0x7983f890	0xb399cf	CameraPerspective::evaluateAt(Vector3 const&) const + 0x12f 
	0x7983f940	0xb44852	RenderThread::Run() + 0x1a2 
	0x7983f960	0xb44c3c	ThreadPrimitive::RunBinder(void*) + 0xc 
	0x7983f988	0x818e79	thread_entry + 0x19 
	00000000	0x60d70250	commpage_thread_exit + 0 

	Registers:
		  eip:	0x60d70114
		  esp:	0x7983f34c
		  ebp:	0x7983f368
		  eax:	0x000000e1
		  ebx:	0x008ca164
		  ecx:	0x7983f34c
		  edx:	0x60d70114
		  esi:	0x008bc828
		  edi:	0x00000000
		   cs:	0x001b
		   ds:	0x0023
		   es:	0x0023
		   fs:	0x0063
		   gs:	0x0023
		   ss:	0x0023
		  st0:	16.9
		  st1:	1.06
		  st2:	-0.749
		  st3:	-0
		  st4:	-0
		  st5:	0.167
		  st6:	-1.44
		  st7:	-1.12
		  mm0:	{0, 0, 0xc800, 0x874e}
		  mm1:	{0x63e0, 0xe2d, 0x9171, 0x8814}
		  mm2:	{0, 0, 0xff00, 0xbfb7}
		  mm3:	{0, 0, 0, 0}
		  mm4:	{0, 0, 0, 0}
		  mm5:	{0x5cc8, 0xfffb, 0x4cff, 0xaaa6}
		  mm6:	{0x1a3b, 0xd62, 0xc3ed, 0xb8a2}
		  mm7:	{0x2668, 0xa050, 0x7e2a, 0x8fc8}
		 xmm0:	{0xa6a4, 0xefd6, 0xf254, 0x4cf1, 0x56a2, 0x9e14, 0x3726, 0x508e}
		 xmm1:	{0, 0, 0, 0, 0, 0, 0, 0}
		 xmm2:	{0, 0, 0, 0, 0, 0, 0, 0}
		 xmm3:	{0, 0, 0, 0, 0, 0, 0, 0}
		 xmm4:	{0, 0, 0, 0, 0, 0, 0, 0}
		 xmm5:	{0, 0, 0, 0, 0, 0, 0, 0}
		 xmm6:	{0, 0, 0, 0, 0, 0, 0, 0}
		 xmm7:	{0, 0, 0, 0, 0, 0, 0, 0}

Loaded Images:
ID Text Base Text End Data Base Data End Type Name
--------------------------------------------------------------------------------
5842 0x00520000 0x0075f000 0x0075f000 0x0076c000 lib /boot/system/lib/x86/libicui18n.so.55.1
5848 0x00771000 0x00787000 0x00787000 0x00789000 lib /boot/system/lib/x86/libz.so.1.2.8
5837 0x007eb000 0x008c7000 0x008c7000 0x0090c000 lib /boot/system/lib/x86/libroot.so
5847 0x0097d000 0x00ae1000 0x00ae1000 0x00aef000 lib /boot/system/lib/x86/libicuuc.so.55.1
5836 0x00b29000 0x00b55000 0x00b55000 0x00b57000 app /boot/home/downloads/BeTracer
5846 0x00d90000 0x00db9000 0x00db9000 0x00ded000 lib /boot/system/lib/x86/libicutu.so.55.1
5839 0x0114e000 0x0129a000 0x0129a000 0x012a8000 lib /boot/system/lib/x86/libstdc++.so.6.0.21
5845 0x01327000 0x01331000 0x01331000 0x01332000 lib /boot/system/lib/x86/libiculx.so.55.1
5844 0x01486000 0x014d7000 0x014d7000 0x014d9000 lib /boot/system/lib/x86/libicule.so.55.1
5843 0x01a62000 0x01a6b000 0x01a6b000 0x01a6d000 lib /boot/system/lib/x86/libicuio.so.55.1
5840 0x01de5000 0x01dfd000 0x01dfd000 0x01dfe000 lib /boot/system/lib/x86/libgcc_s.so.1
5835 0x0229f000 0x022bd000 0x022bd000 0x022c0000 lib /boot/system/runtime_loader
5838 0x025c1000 0x02897000 0x02897000 0x028b2000 lib /boot/system/lib/x86/libbe.so
5841 0x029f1000 0x042a7000 0x042a7000 0x042a8000 lib /boot/system/lib/x86/libicudata.so.55.1
5834 0x60d70000 0x60d78000 0x00000000 0x00000000 system commpage

Areas:
ID Base End Size (KiB) Protection Locking Name
--------------------------------------------------------------------------------
56149 0x00107000 0x00117000 64 rw- full rld heap
56150 0x00141000 0x00151000 64 rw- full rld heap
56148 0x00199000 0x001a1000 32 rw- full rld heap
56116 0x001bf000 0x001c0000 4 rw-S full rld_debug
56115 0x001d3000 0x001e3000 64 rw- full rld heap
56132 0x00520000 0x0075f000 2300 r-x full libicui18n.so.55.1_seg0ro
56133 0x0075f000 0x0076c000 52 rw- full libicui18n.so.55.1_seg1rw
56146 0x00771000 0x00787000 88 r-x full libz.so.1.2.8_seg0ro
56147 0x00787000 0x00789000 8 rw- full libz.so.1.2.8_seg1rw
56119 0x007eb000 0x008c7000 880 r-x full libroot.so_seg0ro
56120 0x008c7000 0x008d1000 40 rw- full libroot.so_seg1rw
56121 0x008d1000 0x0090c000 236 rw- full libroot.so_seg2rw
56143 0x0097d000 0x00ae1000 1424 r-x full libicuuc.so.55.1_seg0ro
56144 0x00ae1000 0x00aec000 44 rw- full libicuuc.so.55.1_seg1rw
56145 0x00aec000 0x00aef000 12 rw- full libicuuc.so.55.1_seg2rw
56117 0x00b29000 0x00b55000 176 r-x full BeTracer_seg0ro
56118 0x00b55000 0x00b57000 8 rw- full BeTracer_seg1rw
56140 0x00d90000 0x00db9000 164 r-x full libicutu.so.55.1_seg0ro
56141 0x00db9000 0x00dbb000 8 rw- full libicutu.so.55.1_seg1rw
56142 0x00dbb000 0x00ded000 200 rw- full libicutu.so.55.1_seg2rw
56125 0x0114e000 0x0129a000 1328 r-x full libstdc++.so.6.0.21_seg0ro
56126 0x0129a000 0x012a1000 28 rw- full libstdc++.so.6.0.21_seg1rw
56127 0x012a1000 0x012a8000 28 rw- full libstdc++.so.6.0.21_seg2rw
56138 0x01327000 0x01331000 40 r-x full libiculx.so.55.1_seg0ro
56139 0x01331000 0x01332000 4 rw- full libiculx.so.55.1_seg1rw
56136 0x01486000 0x014d7000 324 r-x full libicule.so.55.1_seg0ro
56137 0x014d7000 0x014d9000 8 rw- full libicule.so.55.1_seg1rw
56134 0x01a62000 0x01a6b000 36 r-x full libicuio.so.55.1_seg0ro
56135 0x01a6b000 0x01a6d000 8 rw- full libicuio.so.55.1_seg1rw
56128 0x01de5000 0x01dfd000 96 r-x full libgcc_s.so.1_seg0ro
56129 0x01dfd000 0x01dfe000 4 rw- full libgcc_s.so.1_seg1rw
56112 0x0229f000 0x022bd000 120 r-x full runtime_loader_seg0ro
56113 0x022bd000 0x022bf000 8 rw- full runtime_loader_seg1rw
56114 0x022bf000 0x022c0000 4 rw- full runtime_loader_bss1
56122 0x025c1000 0x02897000 2904 r-x full libbe.so_seg0ro
56123 0x02897000 0x028b1000 104 rw- full libbe.so_seg1rw
56124 0x028b1000 0x028b2000 4 rw- full libbe.so_seg2rw
56130 0x029f1000 0x042a7000 25304 r-x full libicudata.so.55.1_seg0ro
56131 0x042a7000 0x042a8000 4 rw- full libicudata.so.55.1_seg1rw
56203 0x0c2a8000 0x0c47d000 1876 rw-S full server_memory
56151 0x18044000 0x185d4000 5696 rw- full heap
56111 0x60d70000 0x60d78000 32 r-xSk full commpage
56108 0x61bf0000 0x61bf4000 16 rw- full user area
56156 0x61c70000 0x61c71000 4 rw-S full server_memory
56217 0x7021c000 0x70261000 276 rw-s full name_6311_stack
56110 0x707b3000 0x717b4000 16388 rw-s full BeTracer_6293_stack
56158 0x717b4000 0x717d4000 128 rw-S full server_memory
56223 0x797fc000 0x79841000 276 rw-s full name_6314_stack
56221 0x79883000 0x798c8000 276 rw-s full name_6313_stack
56219 0x798e1000 0x79926000 276 rw-s full name_6312_stack
56164 0x79bcf000 0x79c14000 276 rw-s full w>BeTracer_6297_stack

Protection Flags: r - read, w - write, x - execute, s - stack, o - overcommit, c - cloneable, S - shared, k - kernel

Semaphores:
ID Count Last Holder Name
------------------------------------------------------------
1017217 0 -2605 BMessageQueue Lock
1017218 0 0 AppLooperPort
1017328 0 2605 some BLocker
1017757 0 6297 some BBlockCache lock
1017758 0 0 Catalog
1017759 0 0 some BLocker
1017760 0 0 some BLocker
1017761 0 6310 token space
1017762 0 6297 BLooperList lock
1017763 0 6310 AppServerLink_sLock
1017764 0 0 LocaleRosterData
1017769 0 0 width buffer
1017776 0 0 screen list
1017777 0 0 clipboard
1017779 0 6297 BeTracer
1017782 0 0 BMessageQueue Lock
1017855 0 0 tool tip manager

Any chance you will have a zip file to include the source code for thennext update?

I would love to look at the code.

This crash looks like a crash in Haiku malloc(), not in the demo code :-(. I will report it as a bug but currently I’m not aware of of to fix it other than getting different scenes.

Sounds indeed like an issue in Haiku heap allocation code. Some assert() from src/system/libroot/malloc/*.h inline code fail.

You could try to gather more info running the crashy case with MALLOC_DEBUG enabled:

LD_PRELOAD=libroot_debug.so MALLOC_DEBUG=ges50 BeTracer > malloc_debug_report

Would be usefull too to retry running the demo in single thread mode, to see if it’s related or not.

If i start it with your terminal line:

 LD_PRELOAD=libroot_debug.so MALLOC_DEBUG=ges50 BeTracer > malloc_debug_report

i get …

runtime_loader: /boot/system/lib/x86/libstdc++.so.6.0.21: Could not resolve symbol '___tls_get_addr’
resolve symbol “___tls_get_addr” returned: -2147478780
runtime_loader: /boot/system/lib/x86/libstdc++.so.6.0.21: Troubles relocating: Symbol not found

not shure why he couldnt find this symbol … do i miss a installed lib or what?

Damned.

Seems a known issue:
https://dev.haiku-os.org/ticket/12214

Your could try to copy libgcc_s.so.1 and libroot_debug.so in a local lib folder as suggested in the issue ticket and retry pointing LD_PRELOAD the local libroot_debug.so copy this time.

Here’s an update to BeTracer. It now has menu defaults and real time display update, which is pretty cool.

There are some update glitches and it looks like scene 3 somehow broke itself.

I’ll be looking at either putting in a faster renderer or the ability to read scenes.

  • https://onedrive.live.com/redir?resid=23646DEFC0827C85!4432&authkey=!ACKfMiPTKZbcBP8&ithint=file%2c

Here is version 0.3 with many new scenes to render, it’s based on a rewrite of the rendering code so crashes will be different :slight_smile:

  • https://onedrive.live.com/redir?resid=23646DEFC0827C85!3977&authkey=!AC9ascWSzjh5Nik&ithint=folder%2c

Cool… first tests… went really well… :slight_smile:

Version 0.4 is uploaded with some nice additions:
Rendering is faster
X and Y axis slider bars to change your point of view
fixed start crash on some systems
fixed view update bug (Others still exist)
Added System Info which tells you how many cores Haiku thinks you have
Added menu options for 6 and 10 CPUs

  • https://onedrive.live.com/redir?resid=23646DEFC0827C85!3977&authkey=!AC9ascWSzjh5Nik&ithint=folder%2c