llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-hlsl

Author: Gregory Roth (pow2clk)

<details>
<summary>Changes</summary>

HLSL doesn't require template parameter braces if the type has default template 
parameter values. In particular, this allows declaring vectors, matrices, and 
buffers without any angle brackets. This builds on the work done to allow this 
for Texture2D (#<!-- -->184207) which limited the application based on number 
of template arguments. This allowed only for those valid cases that only had 
one template parameter. This also corrects mistakenly included default 
arguments for RW textures and adds them for Buffers.

Existing tests for matrix aliases, vector aliases, and buffers are modified to 
expect and verify the new behavior. Since they were not so well tested, Texture 
and RWTexture tests are added modeled after the existing Buffer counterparts. 
HLSL doesn't require template parameter braces if the type has default template 
parameter values.

---

Patch is 26.33 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/216834.diff


11 Files Affected:

- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+5-6) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+1-1) 
- (modified) clang/test/AST/HLSL/TypedBuffers-AST.hlsl (+7-1) 
- (modified) clang/test/AST/HLSL/matrix-alias.hlsl (+9-3) 
- (modified) clang/test/AST/HLSL/vector-alias.hlsl (+8-2) 
- (modified) clang/test/SemaHLSL/BuiltIns/Buffers.hlsl (+2-24) 
- (modified) clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl (+6-6) 
- (added) clang/test/SemaHLSL/BuiltIns/RWTextures.hlsl (+128) 
- (added) clang/test/SemaHLSL/BuiltIns/Textures.hlsl (+110) 
- (modified) clang/test/SemaHLSL/BuiltIns/matrix-errors.hlsl (-3) 
- (modified) clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl (-3) 


``````````diff
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 61998e5653a00..e02a75851d9f3 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -541,8 +541,10 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
         .completeDefinition();
   });
 
+  QualType Float4Ty = AST.getExtVectorType(AST.FloatTy, 4);
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Buffer")
-             .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
+             .addSimpleTemplateParams({"element_type"}, {Float4Ty},
+                                      TypedBufferConcept)
              .finalizeForwardDeclaration();
 
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
@@ -689,7 +691,6 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
     setupSamplerType(Decl, *SemaPtr).completeDefinition();
   });
 
-  QualType Float4Ty = AST.getExtVectorType(AST.FloatTy, 4);
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Texture2D")
              .addSimpleTemplateParams({"element_type"}, {Float4Ty},
                                       TypedBufferConcept)
@@ -710,8 +711,7 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   });
 
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWTexture2D")
-             .addSimpleTemplateParams({"element_type"}, {Float4Ty},
-                                      TypedBufferConcept)
+             .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
              .finalizeForwardDeclaration();
 
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
@@ -750,8 +750,7 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 
   // RWTexture2DArray — same as RWTexture2D but IsArray=true
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWTexture2DArray")
-             .addSimpleTemplateParams({"element_type"}, {Float4Ty},
-                                      TypedBufferConcept)
+             .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
              .finalizeForwardDeclaration();
 
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 184339044e5bf..66336cba257c7 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -6689,7 +6689,7 @@ QualType SemaHLSL::ActOnTemplateShorthand(TemplateDecl 
*Template,
     return QualType();
 
   TemplateParameterList *Params = Template->getTemplateParameters();
-  if (!Params || Params->size() != 1)
+  if (!Params)
     return QualType();
 
   if (!Template->isImplicit())
diff --git a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl 
b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
index a2708e0782bef..8122d1568abc1 100644
--- a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
@@ -2,7 +2,7 @@
 // RUN:   -DRESOURCE=RWBuffer %s | FileCheck -DRESOURCE=RWBuffer 
-check-prefix=EMPTY %s
 //
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY \
-// RUN:   -DRESOURCE=Buffer %s | FileCheck -DRESOURCE=Buffer 
-check-prefix=EMPTY %s
+// RUN:   -DRESOURCE=Buffer %s | FileCheck -DRESOURCE=Buffer 
-check-prefixes=EMPTY,EMPTY-SRV %s
 //
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump \
 // RUN:   -DRESOURCE=RWBuffer %s | FileCheck -DRESOURCE=RWBuffer \
@@ -26,6 +26,9 @@
 
 // EMPTY: ClassTemplateDecl {{.*}} implicit [[RESOURCE]]
 // EMPTY-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 
element_type
+// EMPTY-SRV-NEXT: TemplateArgument type 'vector<float, 4>'
+// EMPTY-SRV-NEXT: ExtVectorType {{.*}} 'vector<float, 4>'
+// EMPTY-SRV-NEXT: BuiltinType {{.*}} 'float'
 // EMPTY-NEXT: ConceptSpecializationExpr {{.*}} 'bool' Concept {{.*}} 
'__is_typed_resource_element_compatible'
 // EMPTY-NEXT: ImplicitConceptSpecializationDecl
 // EMPTY-NEXT: TemplateArgument type 'type-parameter-0-0'
@@ -48,6 +51,9 @@ RESOURCE<float> Buffer;
 
 // CHECK: ClassTemplateDecl {{.*}} implicit referenced [[RESOURCE]]
 // CHECK-NEXT: TemplateTypeParmDecl {{.*}} typename depth 0 index 0 
element_type
+// CHECK-SRV-NEXT: TemplateArgument type 'vector<float, 4>'
+// CHECK-SRV-NEXT: ExtVectorType {{.*}} 'vector<float, 4>'
+// CHECK-SRV-NEXT: BuiltinType {{.*}} 'float'
 // CHECK-NEXT: ConceptSpecializationExpr {{.*}} 'bool' Concept {{.*}}  
'__is_typed_resource_element_compatible'
 // CHECK-NEXT: ImplicitConceptSpecializationDecl
 // CHECK-NEXT: TemplateArgument type 'type-parameter-0-0'
diff --git a/clang/test/AST/HLSL/matrix-alias.hlsl 
b/clang/test/AST/HLSL/matrix-alias.hlsl
index e3a3c6c5dd015..13367659078cc 100644
--- a/clang/test/AST/HLSL/matrix-alias.hlsl
+++ b/clang/test/AST/HLSL/matrix-alias.hlsl
@@ -40,10 +40,16 @@ void entry() {
   // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:38:3, col:31>
   // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:24> col:24 Mat4x4d 
'matrix<double, 4, 4>'
 
-  // Verify that the implicit arguments generate the correct type.
-  matrix<> ImpMat4x4;
+  // Verify that the default arguments generate the correct type.
+  matrix<> DefMat4x4;
 
   // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:44:3, col:21>
-  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:12> col:12 ImpMat4x4 
'matrix<>':'matrix<float, 4, 4>'
+  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:12> col:12 DefMat4x4 
'matrix<>':'matrix<float, 4, 4>'
+
+  // Verify that the implicit arguments generate the correct type.
+  matrix ImpMat4x4;
+
+  // CHECK: DeclStmt 0x{{[0-9a-fA-F]+}} <line:50:3, col:19>
+  // CHECK-NEXT: VarDecl 0x{{[0-9a-fA-F]+}} <col:3, col:10> col:10 ImpMat4x4 
'hlsl::matrix<float, 4, 4>':'matrix<float, 4, 4>'
   return;
 }
diff --git a/clang/test/AST/HLSL/vector-alias.hlsl 
b/clang/test/AST/HLSL/vector-alias.hlsl
index f3d28d6d3d55e..10c11bc2f7761 100644
--- a/clang/test/AST/HLSL/vector-alias.hlsl
+++ b/clang/test/AST/HLSL/vector-alias.hlsl
@@ -44,10 +44,16 @@ void entry() {
   // CHECK: DeclStmt {{.*}}
   // CHECK-NEXT: VarDecl {{.*}} Vec3 'vector<double, 3>' cinit
 
+  // Verify that the default arguments generate the correct type.
+  vector<> DefVec4 = {1.0, 2.0, 3.0, 4.0};
+
+  // CHECK: DeclStmt
+  // CHECK-NEXT: VarDecl {{.*}} DefVec4 'vector<>':'vector<float, 4>' cinit
+
   // Verify that the implicit arguments generate the correct type.
-  vector<> ImpVec4 = {1.0, 2.0, 3.0, 4.0};
+  vector ImpVec4 = {1.0, 2.0, 3.0, 4.0};
 
   // CHECK: DeclStmt
-  // CHECK-NEXT: VarDecl {{.*}} ImpVec4 'vector<>':'vector<float, 4>' cinit
+  // CHECK-NEXT: VarDecl {{.*}} ImpVec4 'hlsl::vector<float, 
4>':'vector<float, 4>' cinit
   return;
 }
diff --git a/clang/test/SemaHLSL/BuiltIns/Buffers.hlsl 
b/clang/test/SemaHLSL/BuiltIns/Buffers.hlsl
index db4a6746f6fb3..0d106f74e4465 100644
--- a/clang/test/SemaHLSL/BuiltIns/Buffers.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/Buffers.hlsl
@@ -5,20 +5,13 @@ typedef vector<double, 2> double2;
 typedef vector<double, 3> double3;
 
 
-// expected-error@+1 {{class template 'Buffer' requires template arguments}}
-Buffer BufferErr1;
-
-// expected-error@+1 {{too few template arguments for class template 'Buffer'}}
-Buffer<> BufferErr2;
-
 // test implicit Buffer concept
 Buffer<int> r1;
 Buffer<float> r2;
 Buffer<float3> Buff;
 Buffer<double2> r4;
 
-// expected-error@+4 {{constraints not satisfied for class template 'Buffer'}}
-// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class Buffer}}
+// expected-error@+3 {{constraints not satisfied for class template 'Buffer'}}
 // expected-note@*:* {{because 'Buffer<int>' does not satisfy 
'__is_typed_resource_element_compatible'}}
 // expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(hlsl::Buffer<int>)' 
evaluated to false}}
 Buffer<Buffer<int> > r5;
@@ -38,8 +31,7 @@ template<typename T> struct TemplatedVector {
 };
 
 // structs not allowed
-// expected-error@+4 {{constraints not satisfied for class template 'Buffer'}}
-// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class Buffer}}
+// expected-error@+3 {{constraints not satisfied for class template 'Buffer'}}
 // expected-note@*:* {{because 's' does not satisfy 
'__is_typed_resource_element_compatible'}}
 // expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(s)' evaluated to false}}
 Buffer<s> r6;
@@ -116,17 +108,3 @@ void main() {
   // expected-note@* {{function 'operator[]' which returns const-qualified 
type 'vector<float, 3> const hlsl_device &' declared here}}
   Buff[0] = 0.0;
 }
-
-// expected-error@+2 {{class template 'Buffer' requires template arguments}}
-// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class Buffer {}}}
-void f1(Buffer B) {}
-
-// expected-error@+2 {{class template 'Buffer' requires template arguments}}
-// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class Buffer {}}}
-Buffer f2();
-
-struct S {
-  // expected-error@+2 {{class template 'Buffer' requires template arguments}}
-  // expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class Buffer {}}}
-  Buffer B;
-};
diff --git a/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl 
b/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
index a767743a0eccc..68f59d542970a 100644
--- a/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
@@ -5,10 +5,12 @@ typedef vector<double, 2> double2;
 typedef vector<double, 3> double3;
 
 
-// expected-error@+1 {{class template 'RWBuffer' requires template arguments}}
+// expected-error@+2 {{class template 'RWBuffer' requires template arguments}}
+// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWBuffer}}
 RWBuffer BufferErr1;
 
-// expected-error@+1 {{too few template arguments for class template 
'RWBuffer'}}
+// expected-error@+2 {{too few template arguments for class template 
'RWBuffer'}}
+// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWBuffer}}
 RWBuffer<> BufferErr2;
 
 // test implicit RWBuffer concept
@@ -17,8 +19,7 @@ RWBuffer<float> r2;
 RWBuffer<float3> Buff;
 RWBuffer<double2> r4;
 
-// expected-error@+4 {{constraints not satisfied for class template 
'RWBuffer'}}
-// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWBuffer}}
+// expected-error@+3 {{constraints not satisfied for class template 
'RWBuffer'}}
 // expected-note@*:* {{because 'RWBuffer<int>' does not satisfy 
'__is_typed_resource_element_compatible'}}
 // expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(hlsl::RWBuffer<int>)' 
evaluated to false}}
 RWBuffer<RWBuffer<int> > r5;
@@ -38,8 +39,7 @@ template<typename T> struct TemplatedVector {
 };
 
 // structs not allowed
-// expected-error@+4 {{constraints not satisfied for class template 
'RWBuffer'}}
-// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWBuffer}}
+// expected-error@+3 {{constraints not satisfied for class template 
'RWBuffer'}}
 // expected-note@*:* {{because 's' does not satisfy 
'__is_typed_resource_element_compatible'}}
 // expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(s)' evaluated to false}}
 RWBuffer<s> r6;
diff --git a/clang/test/SemaHLSL/BuiltIns/RWTextures.hlsl 
b/clang/test/SemaHLSL/BuiltIns/RWTextures.hlsl
new file mode 100644
index 0000000000000..e933c27712584
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/RWTextures.hlsl
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -Wno-hlsl-implicit-binding -triple 
dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify 
-DTEXTURE=RWTexture2D %s
+// RUN: %clang_cc1 -Wno-hlsl-implicit-binding -triple 
dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify 
-DTEXTURE=RWTexture2DArray %s
+
+typedef vector<float, 3> float3;
+typedef vector<double, 2> double2;
+typedef vector<double, 3> double3;
+
+// expected-error-re@+2 {{class template 'RWTexture{{.*}}' requires template 
arguments}}
+// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWTexture}}
+TEXTURE TextureErr1;
+
+// expected-error-re@+2 {{too few template arguments for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWTexture}}
+TEXTURE<> TextureErr2;
+
+// test implicit Texture concept
+TEXTURE<float3> Tex;
+TEXTURE<int> r1;
+TEXTURE<float> r2;
+TEXTURE<double2> r4;
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note-re@*:* {{because 'RWTexture{{.*}}<int>' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note-re@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(hlsl::RWTexture{{.*}}<int>)'
 evaluated to false}}
+TEXTURE<TEXTURE<int> > r5;
+
+struct s {
+    int x;
+};
+
+struct Empty {};
+
+template<typename T> struct TemplatedTexture {
+    T a;
+};
+
+template<typename T> struct TemplatedVector {
+    vector<T, 4> v;
+};
+
+// structs not allowed
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 's' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(s)' evaluated to false}}
+TEXTURE<s> r6;
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'Empty' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(Empty)' evaluated to 
false}}
+TEXTURE<Empty> r7;
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'TemplatedTexture<int>' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(TemplatedTexture<int>)' 
evaluated to false}}
+TEXTURE<TemplatedTexture<int> > r8;
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'TemplatedVector<int>' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(TemplatedVector<int>)' 
evaluated to false}}
+TEXTURE<TemplatedVector<int> > r9;
+
+// arrays not allowed
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'half[4]' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(half[4])' evaluated to 
false}}
+TEXTURE<half[4]> r10;
+
+typedef vector<int, 8> int8;
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'int8' (aka 'vector<int, 8>') does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(vector<int, 8>)' evaluated 
to false}}37
+TEXTURE<int8> r11;
+
+typedef int MyInt;
+TEXTURE<MyInt> r12;
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'bool' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(bool)' evaluated to false}}
+TEXTURE<bool> r13;
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'vector<bool, 2>' (vector of 2 'bool' values) 
does not satisfy '__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(vector<bool, 2>)' 
evaluated to false}}
+TEXTURE<vector<bool, 2>> r14;
+
+enum numbers { one, two, three };
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'numbers' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(numbers)' evaluated to 
false}}
+TEXTURE<numbers> r15;
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'double3' (aka 'vector<double, 3>') does not 
satisfy '__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(vector<double, 3>)' 
evaluated to false}}
+TEXTURE<double3> r16;
+
+
+struct threeDoubles {
+  double a;
+  double b;
+  double c;
+};
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'RWTexture{{.*}}'}}
+// expected-note@*:* {{because 'threeDoubles' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(threeDoubles)' evaluated 
to false}}
+TEXTURE<threeDoubles> TextureErr3;
+
+
+[numthreads(1,1,1)]
+void main() {
+  (void)Tex.__handle; // expected-error-re {{'__handle' is a private member of 
'hlsl::RWTexture{{.*}}<vector<float, 3>>'}}
+  // expected-note@* {{implicitly declared private here}}
+}
+
+// expected-error-re@+2 {{class template 'RWTexture{{.*}}' requires template 
arguments}}
+// expected-note-re@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWTexture{{.*}} {}}}
+void f1(TEXTURE B) {}
+
+// expected-error-re@+2 {{class template 'RWTexture{{.*}}' requires template 
arguments}}
+// expected-note-re@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWTexture{{.*}} {}}}
+TEXTURE f2();
+
+struct S {
+  // expected-error-re@+2 {{class template 'RWTexture{{.*}}' requires template 
arguments}}
+  // expected-note-re@*:* {{template declaration from hidden source: template 
<typename element_type> requires 
__is_typed_resource_element_compatible<element_type> class RWTexture{{.*}} {}}}
+  TEXTURE B;
+};
diff --git a/clang/test/SemaHLSL/BuiltIns/Textures.hlsl 
b/clang/test/SemaHLSL/BuiltIns/Textures.hlsl
new file mode 100644
index 0000000000000..6bec03f4e1c57
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/Textures.hlsl
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 -Wno-hlsl-implicit-binding -triple 
dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify 
-DTEXTURE=Texture2D %s
+// RUN: %clang_cc1 -Wno-hlsl-implicit-binding -triple 
dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify 
-DTEXTURE=Texture2DArray %s
+
+typedef vector<float, 3> float3;
+typedef vector<double, 2> double2;
+typedef vector<double, 3> double3;
+
+// test implicit Texture concept
+TEXTURE<float3> Tex;
+TEXTURE<int> r1;
+TEXTURE<float> r2;
+TEXTURE<double2> r4;
+
+// expected-error-re@+3 {{constraints not satisfied for class template 
'Texture{{.*}}'}}
+// expected-note-re@*:* {{because 'Texture{{.*}}<int>' does not satisfy 
'__is_typed_resource_element_compatible'}}
+// expected-note-re@*:* {{because 
'__builtin_hlsl_is_typed_resource_element_compatible(hlsl::Texture{{.*}}<int>)' 
evaluated to false}}
+TEXTURE<TEXTURE<int> > r5;
+
+struct s {
+    int x;
+};
+
+struct Empty {};
+
+template<typename T> struct TemplatedTexture {
+    T a...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/216834
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to