Skip to content

[SPIR-V] Intrinsics which are Termination Instructions fail Legalizations #7279

Open
@devshgraphicsprogramming

Description

Description

I added OpTerminateRayKHR with an inline SPIR-V intrinsic and put it in an if branch in place of AcceptHitAndEndSearch().

The shader fails to compile.

Steps to Reproduce

https://godbolt.org/z/sKWY1Kofa

[[vk::ext_capability(/*spv::CapabilityRayTracingKHR*/4479)]]
[[vk::ext_extension("SPV_KHR_ray_tracing")]]
[[vk::ext_instruction(/*spv::OpTerminateRayKHR*/4449)]]
void terminateRay();

struct [raypayload] OcclusionPayload
{
    float32_t attenuation : read(caller,anyhit,miss) : write(caller,anyhit,miss);
};

[shader("anyhit")]
void main(inout OcclusionPayload payload, in BuiltInTriangleIntersectionAttributes attribs)
{
    if (payload.attenuation<0.001)
        terminateRay();
    IgnoreHit();
}

Actual Behavior

Even with the -Vd option I see

fatal error: failed to optimize SPIR-V: terminator instruction outside basic block
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Compiler returned: 5

Also -O0 -Vd doin't let me see the SPIR-V that DXC tries to emit in this case.

Looking at the regular codegen, I can see that DXC does something really weird to my payload, even though I access it only to read it, it OpStores it back at the end of each branch. This may be dislodging the termination instruction.

Environment

  • DXC version: Godbolt trunk
  • Host Operating System : Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triagespirvWork related to SPIR-V

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions