Debian Codegraph @

clang/test/AST/HLSL/resource_binding_attr.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -ast-dump -o - %s | FileCheck %s -check-prefixes=CHECK,DXIL
2 // RUN: %clang_cc1 -triple spirv-unknown-vulkan-library -finclude-default-header -ast-dump -o - %s | FileCheck %s -check-prefixes=CHECK,SPV
3
4 // CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 4]]:9 cbuffer CB
5 // CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
6 // CHECK-NEXT: HLSLResourceBindingAttr {{.*}} "b3" "space2"
7 // CHECK-NEXT: VarDecl {{.*}} used a 'hlsl_constant float'
8 cbuffer CB : register(b3, space2) {
9 float a;
10 }
11
12 // CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 4]]:9 tbuffer TB
13 // CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit SRV
14 // CHECK-NEXT: HLSLResourceBindingAttr {{.*}} "t2" "space1"
15 // CHECK-NEXT: VarDecl {{.*}} used b 'hlsl_constant float'
16 tbuffer TB : register(t2, space1) {
17 float b;
18 }
19
20 export float foo() {
21 return a + b;
22 }
23
24 // CHECK: VarDecl {{.*}} UAV 'RWBuffer<float>':'hlsl::RWBuffer<float>'
25 // CHECK: HLSLResourceBindingAttr {{.*}} "u3" "space0"
26 RWBuffer<float> UAV : register(u3);
27
28 // CHECK: VarDecl {{.*}} UAV1 'RWBuffer<float>':'hlsl::RWBuffer<float>'
29 // CHECK: HLSLResourceBindingAttr {{.*}} "u2" "space0"
30 // CHECK: VarDecl {{.*}} UAV2 'RWBuffer<float>':'hlsl::RWBuffer<float>'
31 // CHECK: HLSLResourceBindingAttr {{.*}} "u4" "space0"
32 RWBuffer<float> UAV1 : register(u2), UAV2 : register(u4);
33
34 // CHECK: VarDecl {{.*}} UAV3 'RWBuffer<float>':'hlsl::RWBuffer<float>'
35 // CHECK: HLSLResourceBindingAttr {{.*}} "" "space5"
36 RWBuffer<float> UAV3 : register(space5);
37
38 // CHECK: VarDecl {{.*}} UAV_Array 'RWBuffer<float>[10]'
39 // CHECK: HLSLResourceBindingAttr {{.*}} "u10" "space6"
40 RWBuffer<float> UAV_Array[10] : register(u10, space6);
41
42 //
43 // Default constants ($Globals) layout annotations
44
45 // CHECK: VarDecl {{.*}} f 'hlsl_constant float'
46 // CHECK: HLSLResourceBindingAttr {{.*}} "c5" "space0"
47 float f : register(c5);
48
49 // CHECK: VarDecl {{.*}} intv 'hlsl_constant int4':'vector<int hlsl_constant, 4>'
50 // CHECK: HLSLResourceBindingAttr {{.*}} "c2" "space0"
51 int4 intv : register(c2);
52
53 // CHECK: VarDecl {{.*}} dar 'hlsl_constant double[5]'
54 // CHECK: HLSLResourceBindingAttr {{.*}} "c3" "space0"
55 double dar[5] : register(c3);
56
57 struct S {
58 int a;
59 };
60
61 // CHECK: VarDecl {{.*}} s 'hlsl_constant S'
62 // CHECK: HLSLResourceBindingAttr {{.*}} "c10" "space0
63 S s : register(c10);
64
65 //
66 // Implicit binding
67
68 // Constant buffers should have implicit binding attribute added by SemaHLSL,
69 // unless the target is SPIR-V and there is [[vk::binding]] attribute.
70 // CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 3]]:9 cbuffer CB2
71 // CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
72 // CHECK-NEXT: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
73 cbuffer CB2 {
74 float4 c;
75 }
76
77 // CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 7]]:9 cbuffer CB3
78 // CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
79 // DXIL: HLSLResourceBindingAttr {{.*}} Implicit
80 // DXIL-NOT: HLSLVkBindingAttr
81 // SPV: HLSLVkBindingAttr {{.*}} 1 0
82 // SPV-NOT: HLSLResourceBindingAttr {{.*}} Implicit
83 [[vk::binding(1)]]
84 cbuffer CB3 {
85 float2 d;
86 }
87
88 // Resource arrays should have implicit binding attribute added by SemaHLSL,
89 // unless the target is SPIR-V and there is [[vk::binding]] attribute.
90 // CHECK: VarDecl {{.*}} SB 'StructuredBuffer<float>[10]'
91 // CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
92 StructuredBuffer<float> SB[10];
93
94 // CHECK: VarDecl {{.*}} SB2 'StructuredBuffer<float>[10]'
95 // CHECK: HLSLVkBindingAttr {{.*}} 2 0
96 // DXIL: HLSLResourceBindingAttr {{.*}} Implicit
97 // SPV-NOT: HLSLResourceBindingAttr {{.*}} Implicit
98 [[vk::binding(2)]]
99 StructuredBuffer<float> SB2[10];
100
101 // $Globals should have implicit binding attribute added by SemaHLSL
102 // CHECK: HLSLBufferDecl {{.*}} implicit cbuffer $Globals
103 // CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"