Raytracing

The Partridge Family were neither partridges nor a family. Discuss.
ebergerly
Posts: 15
Joined: November 13th, 2019, 9:54 pm

Re: Raytracing

Post by ebergerly » November 15th, 2019, 12:38 am

It looks like the Chili framework creates the device and swapchain (Graphics.cpp), so I'm thinking the GPU is already set up for rendering. But if I look at Task Manager I don't see any/much GPU activity on any of the engines while rendering. But there is SOME activity in the GPU 3D engine that goes away when I stop the debugger. Hmmm....maybe it's already using the GPU. Maybe gfx.PutPixel() already uses the GPU and does that swapchain thang. But why doesn't it show up in the GPU engine usage charts as a big ol' usage? I'm doing 100 samples per pixel on a 1200 x 600 image. That's a lot of GPU thinkin' that needs to be done...

albinopapa
Posts: 3982
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Raytracing

Post by albinopapa » November 15th, 2019, 3:54 am

Nah, the chili framework does all processing on a system memory buffer, then copies it to a texture that is then rendered onto a quadrangle and presented to the front buffer.

PutPixel stored values in system memory.

EndFrame locks the graphics back buffer,
copies the system buffer to a texture in gpu memory
sets the pipeline state
renders the quadrangle using the texture
presents the rendered image to the screen.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

ebergerly
Posts: 15
Joined: November 13th, 2019, 9:54 pm

Re: Raytracing

Post by ebergerly » November 15th, 2019, 12:35 pm

Yeah I think you're right. So maybe my next step is to take the existing raytracing code with CUDA added (but prints pixel values to a ppm file rather than to a window), and try to integrate the Chili framework. Maybe have GenerateFrame do all the raytracing calcs via CUDA on GPU, then the ComposeFrame to swap the buffer to render to the screen. Unless theres some way to have Direct3D do all the raytracing calcs on GPU rather that CUDA. Has anyone here actually done any raytracing stuff before?

ebergerly
Posts: 15
Joined: November 13th, 2019, 9:54 pm

Re: Raytracing

Post by ebergerly » November 15th, 2019, 1:27 pm

Okay, so I checked the CUDA/raytracing code and it does all the intensive raytracing calcs on the GPU and places the rendered image in a framebuffer fb[ ]. Then the final step is a couple of nested for( ) loops to place each pixel RGB value from fb in a PPM file using cout. So I'm thinking I'll try replacing that cout with the framework PutPixel. A relatively slow draw I suppose, but I can investgate a faster swapbuffer later on. The real heavy lifting was already sped up by the GPU with all the raytracing.

albinopapa
Posts: 3982
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Raytracing

Post by albinopapa » November 15th, 2019, 6:10 pm

Yes, you can definitely use the Graphics::PutPixel() function like you described. Since you aren't looking for performance, this should be fine. Depending on what you plan on doing with it, you could/should abstract it away so the nested for loop isn't hanging out in the Game::ComposeFrame() function, especially if you are wanting to create a graphics pipeline of sorts.

Yes, DirectX12 with ray-tracing, AKA DXR or DirectX RT ( can't remember which lol ).

DX12 with raytracing is pretty new and may not be supported by older video cards, however, there is a fallback to use DirectXCompute though I don't remember which HLSL version is required.

Here's Microsoft's github repository for some samples/demos
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

ebergerly
Posts: 15
Joined: November 13th, 2019, 9:54 pm

Re: Raytracing

Post by ebergerly » November 15th, 2019, 7:49 pm

Thanks much. I was also looking at the CUDA/Direct3D interoperability stuff, which is a whole new world of headache. I was thinking maybe I can integrate the Chili framework Direct3D stuff to draw the rendered image. But there must be an easier way. Heck, I have a framebuffer from the CUDA render, there should be an easy way to send it to the screen just using CUDA.

But then if I want to implement IMGUI it's a whole new world of headache, trying to get it working with CUDA and the rest. Geesh.

albinopapa
Posts: 3982
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Raytracing

Post by albinopapa » November 16th, 2019, 9:37 am

there should be an easy way to send it to the screen just using CUDA
If there is, then it would probably be through the CUDA/D3D interop.
But then if I want to implement IMGUI it's a whole new world of headache, trying to get it working with CUDA and the rest. Geesh.
I wasn't paying attention to how chili implemented the ImGUI stuff, so I can't remember what it used for rendering it's user interface. The GitHub repo says that is agnostic for rendering, so you could use D3D/Ogl or whatever.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3892
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Raytracing

Post by chili » November 16th, 2019, 2:07 pm

You have to supply the impl code to actually render the imgui commands. I just used the reference impl provided for D3D11 and invoked it from somewhere in my code, but it is still defs using D3D11 calls. I don't see how it would be hard to get it working with CUDA shits, they would be mostly orthogonal concerns imo.
Chili

albinopapa
Posts: 3982
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Raytracing

Post by albinopapa » November 16th, 2019, 4:54 pm

People have even forked the imgui repository and made software rasterizers that either use x86 code or even one that uses SIMD instructions. I looked through the one with SIMD instructions and it is dependent on some third party libraries, one that I can remember is VectorialPlusPlus.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

ebergerly
Posts: 15
Joined: November 13th, 2019, 9:54 pm

Re: Raytracing

Post by ebergerly » November 17th, 2019, 12:51 pm

Thanks all. FWIW, after many months of bouncing around trying to figure how best to learn about and implement my own ray tracer, and being continually frustrated by the complexity of getting all the pieces hooked together, I've now decided to try NVIDIA's Optix ray tracer stuff. It seems to be a whole lot easier, and there's demo code where you can start from ray tracing a simple color gradient up to some real fancy object and materials, etc. And it even uses IMGUI. NVIDIA Gameworks has a video from last year giving a very nice "Intro to Optix", and on their website you can download the samples. Seems to be a much nicer, high-level way to do ray tracing, and it even is what they're using for the new RTX graphics cards.

My only issue now is trying to use CMake to build their sample code. Apparently it only likes VS 2015 and CUDA 9.0 or some such insanity. And I've never really figured out CMake, so it's a big mess. But it's amazing how little Optix code you need to do raytracing. Very cool.

Post Reply