brintos

brintos / llvm-project-archived public Read only

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