HLSL Weirdness

Started by
2 comments, last by Vilem Otte 1 year ago

I've currently moved from OpenCL to HLSL in terms of my in-engine ray tracer (mainly due to core renderer being in D3D12 - and the interaction is just much better doing it in HLSL compute shaders). So far, it does seem very good - but I've hit into weirdness in HLSL … unsurprisingly in core of every ray tracer - traversal code.

In OpenCL I was using speculative while-while traversal, which yielded very good performance - when porting to HLSL I decided to first implement more simple traversal, I'm attaching code in the link here - https://pastebin.com/43yRFBHu​ - I've added some comments to make it a bit more clear what's happening.

The tricky part is - that using while (or infinite for) instead of fixed-size for is SIGNIFICANTLY slower. Attempting to do speculative approach in fixed-size for is a bit messy and also gets SIGNIFICANTLY slower (which is opposite to my observation in OpenCL implementation on the same hardware). Keep in mind that I added [loop] to the for, so it doesn't even attempt to unroll. I don't really have an explanation to this - the number of steps taken is in both cases the same (I checked it by outputting steps taken in color channel and performing histogram on the resulting image). For me this seems like some crazy DXC optimization running (which fails on infinite loop?).

I tried to force DXC to give me some sort of assembly-ish output, but they did look very similar to each other - nothing that would slap directly into eye.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Advertisement

Small follow up when taking it into RenderDoc

The for loop version has range of 59 steps - 245 steps within traversal

The while loop version has range of 40 steps - 217 steps within traversal

The view was NOT exactly the same, but very close (I suspected that something may go wrong in while loop). The while one looks like this:

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

For anyone interested, these are DXBC/DXIL results for 2 variants:

While - https://pastebin.com/LpgaVTfq

For - https://pastebin.com/ccUXun5w

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

This topic is closed to new replies.

Advertisement