Skip to content

Commit 6c93071

Browse files
Unit test: IR->IR Dxilgen test
1 parent e70c140 commit 6c93071

2 files changed

Lines changed: 182 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// dxc.exe -T cs_6_9 -E cs_main %s
2+
3+
ByteAddressBuffer matrix_buffer;
4+
ByteAddressBuffer bias_buffer;
5+
RWByteAddressBuffer rw_matrix_buffer;
6+
7+
[Shader("compute")]
8+
[NumThreads(1,1,1)]
9+
void cs_main()
10+
{
11+
vector<float, 4> output_vector;
12+
static const uint is_output_unsigned = 0;
13+
14+
vector<float, 4> input_vector;
15+
const uint is_input_unsigned = 0;
16+
const uint input_interpretation = 9; /*F32*/
17+
18+
const uint matrix_offset = 0;
19+
const uint matrix_interpretation = 9; /*F32*/
20+
const uint matrix_dimM = 4;
21+
const uint matrix_dimK = 4;
22+
const uint matrix_layout = 0; /*RowMajor*/
23+
const bool matrix_is_transposed = false;
24+
const uint matrix_stride = 64;
25+
26+
__builtin_MatVecMul(output_vector, is_output_unsigned, input_vector,
27+
is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset,
28+
matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout,
29+
matrix_is_transposed, matrix_stride);
30+
31+
const uint bias_offset = 0;
32+
const uint bias_interpretation = 9; /*F32*/
33+
34+
__builtin_MatVecMulAdd(output_vector, is_output_unsigned, input_vector,
35+
is_input_unsigned, input_interpretation, matrix_buffer, matrix_offset,
36+
matrix_interpretation, matrix_dimM, matrix_dimK, matrix_layout,
37+
matrix_is_transposed, matrix_stride, bias_buffer, bias_offset,
38+
bias_interpretation);
39+
40+
vector<uint, 8> input_vector1;
41+
vector<uint, 8> input_vector2;
42+
const uint opa_matrix_offset = 0;
43+
const uint opa_matrix_interpretation = 5; /*U32*/
44+
const uint opa_matrix_layout = 3; /*OuterProductOptimal*/
45+
const uint opa_matrix_stride = 64;
46+
47+
__builtin_OuterProductAccumulate(input_vector1, input_vector2,
48+
rw_matrix_buffer, opa_matrix_offset, opa_matrix_interpretation,
49+
opa_matrix_layout, opa_matrix_stride);
50+
51+
const uint va_matrix_offset = 0;
52+
53+
__builtin_VectorAccumulate(input_vector1, rw_matrix_buffer,
54+
va_matrix_offset);
55+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
; RUN: %dxopt %s -hlsl-passes-resume -dxilgen -S | FileCheck %s
2+
3+
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
4+
target triple = "dxil-ms-dx"
5+
6+
%struct.ByteAddressBuffer = type { i32 }
7+
%struct.RWByteAddressBuffer = type { i32 }
8+
%dx.types.Handle = type { i8* }
9+
%dx.types.ResourceProperties = type { i32, i32 }
10+
11+
@"\01?matrix_buffer@@3UByteAddressBuffer@@A" = external global %struct.ByteAddressBuffer, align 4
12+
@"\01?bias_buffer@@3UByteAddressBuffer@@A" = external global %struct.ByteAddressBuffer, align 4
13+
@"\01?rw_matrix_buffer@@3URWByteAddressBuffer@@A" = external global %struct.RWByteAddressBuffer, align 4
14+
15+
; CHECK-LABEL: define void @cs_main()
16+
; Function Attrs: nounwind
17+
define void @cs_main() #0 {
18+
entry:
19+
%output_vector = alloca <4 x float>, align 4
20+
%tmp = bitcast <4 x float>* %output_vector to i8*, !dbg !19 ; line:9 col:2
21+
call void @llvm.lifetime.start(i64 16, i8* %tmp) #0, !dbg !19 ; line:9 col:2
22+
%tmp1 = load %struct.ByteAddressBuffer, %struct.ByteAddressBuffer* @"\01?matrix_buffer@@3UByteAddressBuffer@@A", !dbg !23 ; line:24 col:2
23+
%tmp2 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.ByteAddressBuffer)"(i32 0, %struct.ByteAddressBuffer %tmp1), !dbg !23 ; line:24 col:2
24+
%tmp3 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.ByteAddressBuffer)"(i32 14, %dx.types.Handle %tmp2, %dx.types.ResourceProperties { i32 11, i32 0 }, %struct.ByteAddressBuffer zeroinitializer), !dbg !23 ; line:24 col:2
25+
26+
;CHECK: call <4 x float> @dx.op.matVecMul.v4f32.v4f32(i32 305, <4 x float> undef, i1 false, i32 9, %dx.types.Handle %1, i32 0, i32 9, i32 4, i32 4, i32 0, i1 false, i32 64, i1 false)
27+
28+
call void @"dx.hl.op..void (i32, <4 x float>*, i1, <4 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32 360, <4 x float>* %output_vector, i1 false, <4 x float> undef, i1 false, i32 9, %dx.types.Handle %tmp3, i32 0, i32 9, i32 4, i32 4, i32 0, i1 false, i32 64), !dbg !23 ; line:24 col:2
29+
%tmp4 = load %struct.ByteAddressBuffer, %struct.ByteAddressBuffer* @"\01?matrix_buffer@@3UByteAddressBuffer@@A", !dbg !24 ; line:32 col:2
30+
%tmp5 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.ByteAddressBuffer)"(i32 0, %struct.ByteAddressBuffer %tmp4), !dbg !24 ; line:32 col:2
31+
%tmp6 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.ByteAddressBuffer)"(i32 14, %dx.types.Handle %tmp5, %dx.types.ResourceProperties { i32 11, i32 0 }, %struct.ByteAddressBuffer zeroinitializer), !dbg !24 ; line:32 col:2
32+
%tmp7 = load %struct.ByteAddressBuffer, %struct.ByteAddressBuffer* @"\01?bias_buffer@@3UByteAddressBuffer@@A", !dbg !24 ; line:32 col:2
33+
%tmp8 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.ByteAddressBuffer)"(i32 0, %struct.ByteAddressBuffer %tmp7), !dbg !24 ; line:32 col:2
34+
%tmp9 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.ByteAddressBuffer)"(i32 14, %dx.types.Handle %tmp8, %dx.types.ResourceProperties { i32 11, i32 0 }, %struct.ByteAddressBuffer zeroinitializer), !dbg !24 ; line:32 col:2
35+
36+
;CHECK: call <4 x float> @dx.op.matVecMulAdd.v4f32.v4f32(i32 306, <4 x float> undef, i1 false, i32 9, %dx.types.Handle %4, i32 0, i32 9, i32 4, i32 4, i32 0, i1 false, i32 64, %dx.types.Handle %6, i32 0, i32 9, i1 false)
37+
38+
call void @"dx.hl.op..void (i32, <4 x float>*, i1, <4 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32 361, <4 x float>* %output_vector, i1 false, <4 x float> undef, i1 false, i32 9, %dx.types.Handle %tmp6, i32 0, i32 9, i32 4, i32 4, i32 0, i1 false, i32 64, %dx.types.Handle %tmp9, i32 0, i32 9), !dbg !24 ; line:32 col:2
39+
%tmp10 = load %struct.RWByteAddressBuffer, %struct.RWByteAddressBuffer* @"\01?rw_matrix_buffer@@3URWByteAddressBuffer@@A", !dbg !25 ; line:45 col:2
40+
%tmp11 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.RWByteAddressBuffer)"(i32 0, %struct.RWByteAddressBuffer %tmp10), !dbg !25 ; line:45 col:2
41+
%tmp12 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer)"(i32 14, %dx.types.Handle %tmp11, %dx.types.ResourceProperties { i32 4107, i32 0 }, %struct.RWByteAddressBuffer zeroinitializer), !dbg !25 ; line:45 col:2
42+
;CHECK: call void @dx.op.outerProductAccumulate.v8i32.v8i32(i32 307, <8 x i32> undef, <8 x i32> undef, %dx.types.Handle %9, i32 0, i32 5, i32 3, i32 64)
43+
call void @"dx.hl.op..void (i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32)"(i32 362, <8 x i32> undef, <8 x i32> undef, %dx.types.Handle %tmp12, i32 0, i32 5, i32 3, i32 64), !dbg !25 ; line:45 col:2
44+
%tmp13 = load %struct.RWByteAddressBuffer, %struct.RWByteAddressBuffer* @"\01?rw_matrix_buffer@@3URWByteAddressBuffer@@A", !dbg !26 ; line:51 col:3
45+
%tmp14 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.RWByteAddressBuffer)"(i32 0, %struct.RWByteAddressBuffer %tmp13), !dbg !26 ; line:51 col:3
46+
%tmp15 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer)"(i32 14, %dx.types.Handle %tmp14, %dx.types.ResourceProperties { i32 4107, i32 0 }, %struct.RWByteAddressBuffer zeroinitializer), !dbg !26 ; line:51 col:3
47+
48+
;CHECK: call void @dx.op.vectorAccumulate.v8i32(i32 308, <8 x i32> undef, %dx.types.Handle %11, i32 0)
49+
50+
call void @"dx.hl.op..void (i32, <8 x i32>, %dx.types.Handle, i32)"(i32 363, <8 x i32> undef, %dx.types.Handle %tmp15, i32 0), !dbg !26 ; line:51 col:3
51+
%tmp16 = bitcast <4 x float>* %output_vector to i8*, !dbg !27 ; line:53 col:1
52+
call void @llvm.lifetime.end(i64 16, i8* %tmp16) #0, !dbg !27 ; line:53 col:1
53+
ret void, !dbg !27 ; line:53 col:1
54+
}
55+
56+
; Function Attrs: nounwind
57+
declare void @llvm.lifetime.start(i64, i8* nocapture) #0
58+
59+
; Function Attrs: nounwind
60+
declare void @llvm.lifetime.end(i64, i8* nocapture) #0
61+
62+
; Function Attrs: nounwind
63+
declare void @"dx.hl.op..void (i32, <4 x float>*, i1, <4 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32)"(i32, <4 x float>*, i1, <4 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32) #0
64+
65+
; Function Attrs: nounwind readnone
66+
declare %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.ByteAddressBuffer)"(i32, %struct.ByteAddressBuffer) #1
67+
68+
; Function Attrs: nounwind readnone
69+
declare %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.ByteAddressBuffer)"(i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.ByteAddressBuffer) #1
70+
71+
; Function Attrs: nounwind
72+
declare void @"dx.hl.op..void (i32, <4 x float>*, i1, <4 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32)"(i32, <4 x float>*, i1, <4 x float>, i1, i32, %dx.types.Handle, i32, i32, i32, i32, i32, i1, i32, %dx.types.Handle, i32, i32) #0
73+
74+
; Function Attrs: nounwind
75+
declare void @"dx.hl.op..void (i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32)"(i32, <8 x i32>, <8 x i32>, %dx.types.Handle, i32, i32, i32, i32) #0
76+
77+
; Function Attrs: nounwind readnone
78+
declare %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.RWByteAddressBuffer)"(i32, %struct.RWByteAddressBuffer) #1
79+
80+
; Function Attrs: nounwind readnone
81+
declare %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer)"(i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer) #1
82+
83+
; Function Attrs: nounwind
84+
declare void @"dx.hl.op..void (i32, <8 x i32>, %dx.types.Handle, i32)"(i32, <8 x i32>, %dx.types.Handle, i32) #0
85+
86+
attributes #0 = { nounwind }
87+
attributes #1 = { nounwind readnone }
88+
89+
!llvm.module.flags = !{!0}
90+
!pauseresume = !{!1}
91+
!llvm.ident = !{!2}
92+
!dx.version = !{!3}
93+
!dx.valver = !{!3}
94+
!dx.shaderModel = !{!4}
95+
!dx.typeAnnotations = !{!5}
96+
!dx.entryPoints = !{!9}
97+
!dx.fnprops = !{!16}
98+
!dx.options = !{!17, !18}
99+
100+
!0 = !{i32 2, !"Debug Info Version", i32 3}
101+
!1 = !{!"hlsl-hlemit", !"hlsl-hlensure"}
102+
!2 = !{!"dxc(private) 1.8.0.4884 (anupamac/coop-vec-5, df2877762-dirty)"}
103+
!3 = !{i32 1, i32 9}
104+
!4 = !{!"cs", i32 6, i32 9}
105+
!5 = !{i32 1, void ()* @cs_main, !6}
106+
!6 = !{!7}
107+
!7 = !{i32 1, !8, !8}
108+
!8 = !{}
109+
!9 = !{void ()* @cs_main, !"cs_main", null, !10, null}
110+
!10 = !{!11, !14, null, null}
111+
!11 = !{!12, !13}
112+
!12 = !{i32 0, %struct.ByteAddressBuffer* @"\01?matrix_buffer@@3UByteAddressBuffer@@A", !"matrix_buffer", i32 -1, i32 -1, i32 1, i32 11, i32 0, null}
113+
!13 = !{i32 1, %struct.ByteAddressBuffer* @"\01?bias_buffer@@3UByteAddressBuffer@@A", !"bias_buffer", i32 -1, i32 -1, i32 1, i32 11, i32 0, null}
114+
!14 = !{!15}
115+
!15 = !{i32 0, %struct.RWByteAddressBuffer* @"\01?rw_matrix_buffer@@3URWByteAddressBuffer@@A", !"rw_matrix_buffer", i32 -1, i32 -1, i32 1, i32 11, i1 false, i1 false, i1 false, null}
116+
!16 = !{void ()* @cs_main, i32 5, i32 1, i32 1, i32 1}
117+
!17 = !{i32 -2147483584}
118+
!18 = !{i32 -1}
119+
!19 = !DILocation(line: 9, column: 2, scope: !20)
120+
!20 = !DISubprogram(name: "cs_main", scope: !21, file: !21, line: 7, type: !22, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, function: void ()* @cs_main)
121+
!21 = !DIFile(filename: "D:\5Cgit\5Cgithub\5CDirectXShaderCompiler-acFork\5CDirectXShaderCompiler\5Ctools\5Cclang\5Ctest\5CCodeGenDXIL\5Chlsl\5Cintrinsics\5Clinang-builins.hlsl", directory: "")
122+
!22 = !DISubroutineType(types: !8)
123+
!23 = !DILocation(line: 24, column: 2, scope: !20)
124+
!24 = !DILocation(line: 32, column: 2, scope: !20)
125+
!25 = !DILocation(line: 45, column: 2, scope: !20)
126+
!26 = !DILocation(line: 51, column: 3, scope: !20)
127+
!27 = !DILocation(line: 53, column: 1, scope: !20)

0 commit comments

Comments
 (0)