microsoft / microsoft/DirectXShaderCompiler

AnyHit Shader hits `llvm_unreachable("Unexpected matrix subscript use.")`

Open
#3,954 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug crash
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

We hit an internal compiler error with one of our Ray Tracing shaders:

Internal Compiler error: Unexpected matrix subscript use.
UNREACHABLE executed at DirectXShaderCompiler\lib\HLSL\HLMatrixSubscriptUseReplacer.cpp:91!

I reproduced the issue with the small sample shader below and tested it on the latest revision of the master branch:

struct Parameters {
    float3x3 Matrix;
};

struct Attributes {
    float3 Color;
};

struct Payload {
    float3 AccumulatedColor;
};

float3 TransformColor(inout Parameters Param, float3 Color) {
    float3 NewColor = Color * Param.Matrix[2].r.xxx; // INTERNAL ERROR
    return NewColor;
}

cbuffer Config {
    float3x3 GlobalMatrix;
}

[shader("anyhit")]
void MaterialAHS(inout Payload Data, in Attributes Attrib) {
    Parameters Param;
    Param.Matrix = GlobalMatrix;
    Data.AccumulatedColor += TransformColor(Param, Attrib.Color);
}

Using the expression Param.Matrix[2].xxx instead of Param.Matrix[2].r.xxx fixes the issue. Our HLSL generator produces a lot of redundant subscripts. We are trying to avoid this issue by improving the generated code, but it's probably worth mentioning. Also because this seems to only happen with Ray Tracing shaders.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal any-hit shader in the issue and reproduce the failure, then inspect DirectXShaderCompiler/lib/HLSL/HLMatrixSubscriptUseReplacer.cpp at line 91. Compare compilation of Param.Matrix[2].r.xxx with Param.Matrix[2].xxx; done means the redundant subscript form no longer reaches llvm_unreachable and the relevant regression coverage passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.