RTX On - Quickstart Guide to DXR

Setting Up DXR

Whew lad was it a pain to find the right library versions and piece together parts of the Microsoft and Nvidia (and other) githubs source to get the bare minimum needed to integrate DXR into my engine. Maybe I'm nuts but there's such a disparity between the Nvidia tutorial pages and the github they link to that it took me a whole night to get a device built and compiling with ray trace shaders built outside of their samples. Having the same problem? Look no further, I'm going to give you what you need and you can go on your merry way.

First download this zip with the DXR libraries. Plop those DLLs where your executable is, or loop them into your post build copy step, you do you.

Copy dxcompiler.lib to wherever your libraries sit and add it to your VC++ Directories -> Library Directories path. Add dxcompiler.lib to your Linker -> Input

Download the bare minimum DXR source headers. Stick these wherever you want in your project.

Wherever you were doing this:
"#include < d3d12.h >"
Do this instead to retarget to these new headers:
#include "[YourPathToTheSourceYouJustCopied]/d3d12.h"
#include "[YourPathToTheSourceYouJustCopied]/d3d12_1.h"
#include < atlbase.h > 
dxcapi.h and dxcapi.use.h will be needed when you want to go and build your DXR shaders, but aren't needed to just create the device, which we're about to do.

Wherever you create your device, before you create it, do this (with your new headers above included):
UUID experimentalFeatures[] = { D3D12ExperimentalShaderModels, D3D12RaytracingPrototype };
bool supportsDXR = D3D12EnableExperimentalFeatures(2, experimentalFeatures, NULL, NULL) == S_OK;
Check that supportsDXR is true on your DXR-enabled device (I'm on a 2080). Then, query for your DXR interface after you create your device:
ID3D12DeviceRaytracingPrototype *mDXRDevice;

//After device is created

And if I'm not dumb and forgot something (hopefully not!), you should be compiled, built, and running with your DXR device. If something went wrong that I haven't accounted for something, please let me know and I'll help out and update this.

What's next? I just got a ray traced triangle working myself. The real struggles came down to the clumsiness of some of the API, and the lack of debug errors. It was pretty much either getting it 100% correct, or the device hung and crashed. Both of those issues are expected of an experimental API.

Anyway, all the info you need to get started can be found here: https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-1 Though as I mentioned earlier (and the whole point this page exists), the sample github they link for DXR source/libs is a fair bit different from their tutorials. You'll be fine if you have the files I linked here though. The only ones of their "helper" files that I found very useful were the RaytracingPipelineGenerator and ShaderBindingTableGenerator. They hide a lot of the clumsy API implementation, and I preferred having that wrapped up because it was just a bunch of string passing.

If you'd like to see what one implementation might look like, you can download my ray trace manager. It's not something that would work for you out of the box because it accesses a few of my other files, and it has a few "Todo" and hacks still, but it might give you some ideas. I'm not going deep with the implementation details here yet because soon the final API will be in, and the experimental API won't be needed. I'll follow up when the final API is here.