Debian Codegraph @

clang/test/SemaHLSL/resource_binding_attr_error_udt.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
2
3 template<typename T>
4 struct MyTemplatedUAV {
5 __hlsl_resource_t [[hlsl::resource_class(UAV)]] x;
6 };
7
8 struct MySRV {
9 __hlsl_resource_t [[hlsl::resource_class(SRV)]] x;
10 };
11
12 struct MySampler {
13 __hlsl_resource_t [[hlsl::resource_class(Sampler)]] x;
14 };
15
16 struct MyUAV {
17 __hlsl_resource_t [[hlsl::resource_class(UAV)]] x;
18 };
19
20 struct MyCBuffer {
21 __hlsl_resource_t [[hlsl::resource_class(CBuffer)]] x;
22 };
23
24 // Valid: f is skipped, SRVBuf is bound to t0, UAVBuf is bound to u0
25 struct Eg1 {
26 float f;
27 MySRV SRVBuf;
28 MyUAV UAVBuf;
29 };
30 Eg1 e1 : register(t0) : register(u0);
31
32 // Valid: f is skipped, SRVBuf is bound to t0, UAVBuf is bound to u0.
33 // UAVBuf2 gets automatically assigned to u1 even though there is no explicit binding for u1.
34 struct Eg2 {
35 float f;
36 MySRV SRVBuf;
37 MyUAV UAVBuf;
38 MyUAV UAVBuf2;
39 };
40 Eg2 e2 : register(t0) : register(u0);
41
42 // Valid: Bar, the struct within Eg3, has a valid resource that can be bound to t0.
43 struct Eg3 {
44 struct Bar {
45 MyUAV a;
46 };
47 Bar b;
48 };
49 Eg3 e3 : register(u0);
50
51 // Valid: the first sampler state object within 's' is bound to slot 5
52 struct Eg4 {
53 MySampler s[3];
54 };
55
56 Eg4 e4 : register(s5);
57
58
59 struct Eg5 {
60 float f;
61 };
62 // expected-warning@+1{{binding type 't' only applies to types containing SRV resources}}
63 Eg5 e5 : register(t0);
64
65 struct Eg6 {
66 float f;
67 };
68 // expected-warning@+1{{binding type 'u' only applies to types containing UAV resources}}
69 Eg6 e6 : register(u0);
70
71 struct Eg7 {
72 float f;
73 };
74 // expected-warning@+1{{binding type 'b' only applies to types containing constant buffer resources}}
75 Eg7 e7 : register(b0);
76
77 struct Eg8 {
78 float f;
79 };
80 // expected-warning@+1{{binding type 's' only applies to types containing sampler state}}
81 Eg8 e8 : register(s0);
82
83 struct Eg9 {
84 MySRV s;
85 };
86 // expected-warning@+1{{binding type 'c' only applies to types containing numeric types}}
87 Eg9 e9 : register(c0);
88
89 struct Eg10{
90 // expected-error@+1{{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
91 MyTemplatedUAV<int> a : register(u9);
92 };
93 Eg10 e10;
94
95
96 template<typename R>
97 struct Eg11 {
98 R b;
99 };
100 // expected-warning@+1{{binding type 'u' only applies to types containing UAV resources}}
101 Eg11<MySRV> e11 : register(u0);
102 // invalid because after template expansion, there are no valid resources inside Eg11 to bind as a UAV, only an SRV
103
104
105 struct Eg12{
106 MySRV s1;
107 MySRV s2;
108 };
109 // expected-warning@+2{{binding type 'u' only applies to types containing UAV resources}}
110 // expected-error@+1{{binding type 'u' cannot be applied more than once}}
111 Eg12 e12 : register(u9) : register(u10);
112
113 struct Eg13{
114 MySRV s1;
115 MySRV s2;
116 };
117 // expected-warning@+3{{binding type 'u' only applies to types containing UAV resources}}
118 // expected-error@+2{{binding type 'u' cannot be applied more than once}}
119 // expected-error@+1{{binding type 'u' cannot be applied more than once}}
120 Eg13 e13 : register(u9) : register(u10) : register(u11);
121
122 // expected-error@+1{{binding type 't' cannot be applied more than once}}
123 Eg13 e13_2 : register(t11) : register(t12);
124
125 struct Eg14{
126 MyTemplatedUAV<int> r1;
127 };
128 // expected-warning@+1{{binding type 't' only applies to types containing SRV resources}}
129 Eg14 e14 : register(t9);
130
131 struct Eg15 {
132 float f[4];
133 };
134 // expected no error
135 Eg15 e15 : register(c0);