Raytracing bugs on M1

Hi, I'm working on integrating Rayquery, into my game-engine. Vulkan/DX12 work fine on PC, but Metal(on Mac) doesn't:

Here is screenshot on how rendering looks:

And similar spot from XCode-debugger shows:

Ship, cannons, items are there - TLAS look as they should. Note: in game screenshoot above there are no shadows, but it not always the case:

Here only some parts of object do cast shadow.

Fragment shader: https://shader-playground.timjones.io/44de178b7b8a715ea235c7f12cd0aabc

// relevant part
bool isShadow(...)
{
    ...
    uint flags = 4u;
    flags |= 128u;
    rayQuery.reset(ray(rayOrigin, rayDirection, tMin, rayDistance), topLevelAS, spvMakeIntersectionParams(flags));
    for (;;) // spirv-cross not pretty here :(
    {
        bool _116 = rayQuery.next();
        if (_116)
        {
            continue;
        }
        else
        {
            break;
        }
    }
    
    uint _120 = uint(rayQuery.get_committed_intersection_type());
    if (_120 == 0u)
    {
        return false;
    }
    return true;
}
----
intersection_params spvMakeIntersectionParams(uint flags)
{
    // hacked this part, while debugging - setting up for simple most any-hit
    intersection_params ip;
    ip.force_opacity(forced_opacity::opaque);
    ip.accept_any_intersection(true);
    return ip;
}

After verifying TLAS and ray-query loop can conclude, that most likely it's a driver bug here, or generated shader code is wrong (but looks correct to me!).

PS: one more small thing about Metal-RT: Metal doc about MTL::AccelerationStructureTriangleGeometryDescriptor::setIndexBufferOffset says: "Specify an offset that is a multiple of the index data type size and a multiple of the platform’s buffer offset alignment." Buffer-offset-alignment (32 bytes in worst case) is very hard to workaround for multi-material meshes . No other api requires so, and there is no good workaround for this.

  • Is there any chance I can ask for a Feedback Assistant with a repro for this one? If the acceleration structure shows up in the viewer, at least the structure itself should be correct.

  • I'm not sure how to use Feedback-assistant, in this case: open XCode and click report bug? In mean time: project is opensource: https://github.com/Try/OpenGothic, so you can just grab sources from github

  • The Feedback Assistant application on your Mac can be found using Spotlight (command space). Alternatively it is available online at http://feedbackassistant.apple.com . Filing a feedback report here with a repro will get the issue routed to the engineers that will need to take a deeper diagnose at this. If you file a feedback assistant report, please post the feedback ID on here. Thanks!

Replies

UPD: macOS ventura 13.0.1 (22A400); no messages in validation layer

  • We've added support for ray tracing in Shader Validation to the macOS Sonoma Beta. Please try it out when you get the chance as it should help to catch any missing useResource calls or other issues.

  • There can't be missing useResource, as they do not required: no argument buffers are in use(or similar). Tested locally useResource(tlas) - no changes

  • You should call useResource on the primitive acceleration structures referenced by the instanced acceleration structure (top level). i.e. if you create an instanced acceleration structure that references 5 primitive acceleration structures, you would have 1 x setAccelerationStructure and 5 x useResource. If the primitive acceleration structures were inside a heap, you could alternatively use a single useHeap call.