llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.29k stars 12.1k forks source link

Invalid type description generated in DXIL IR for StructuredBuffer #114131

Open coopp opened 3 weeks ago

coopp commented 3 weeks ago

An invalid form of a type was being generated in the DXIL IR for the StructuredBuffer type. This form was causing 'opt' to fail with a syntax error while parsing the IR.

godbolt: https://godbolt.org/z/zf7TTWa5q

Shader compiled with -T cs_6_6

struct mystruct
{
    float4 Color;
};

StructuredBuffer<mystruct> my_buffer : register(t2, space4);

export float4 test()
{
    return my_buffer[0].Color;
}

[numthreads(1,1,1)]
void main() {}

See %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", %struct.mystruct = type { <4 x float> }, 0, 0), %struct.mystruct }

Type section for IR

%"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", %struct.mystruct = type { <4 x float> }, 0, 0), %struct.mystruct }
%struct.mystruct = type { <4 x float> }
%dx.types.Handle = type { ptr }
%dx.types.ResBind = type { i32, i32, i32, i8 }
%dx.types.ResourceProperties = type { i32, i32 }

The part "%struct.mystruct = type" is causing the parsing error.

I believe the expected form is:

%"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", { <4 x float> }, 0, 0), %struct.mystruct }
llvmbot commented 3 weeks ago

@llvm/issue-subscribers-bug

Author: Cooper Partin (coopp)

An invalid form of a type was being generated in the DXIL IR for the StructuredBuffer type. This form was causing 'opt' to fail with a syntax error while parsing the IR. godbolt: https://godbolt.org/z/zf7TTWa5q Shader compiled with -T cs_6_6 ``` struct mystruct { float4 Color; }; StructuredBuffer<mystruct> my_buffer : register(t2, space4); export float4 test() { return my_buffer[0].Color; } [numthreads(1,1,1)] void main() {} ``` See `%"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", %struct.mystruct = type { <4 x float> }, 0, 0), %struct.mystruct }` Type section for IR ``` %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", %struct.mystruct = type { <4 x float> }, 0, 0), %struct.mystruct } %struct.mystruct = type { <4 x float> } %dx.types.Handle = type { ptr } %dx.types.ResBind = type { i32, i32, i32, i8 } %dx.types.ResourceProperties = type { i32, i32 } ``` The part "%struct.mystruct = type" is causing the parsing error.