浏览代码

Support default matrix type as template argument (#1238)

Fixes #591
Helena Kotas 7 年之前
父节点
当前提交
c8dde7bc49

+ 3 - 1
tools/clang/lib/Parse/Parser.cpp

@@ -1416,7 +1416,9 @@ Parser::TryAnnotateName(bool IsAddressOfOperand,
     if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(EnteringContext, false, SS,
                                                   !WasScopeAnnotation))
       return ANK_Error;
-    return ANK_Unresolved;
+    // HLSL Change Starts - allow implicitly annotated templates
+    return (Tok.isNot(tok::annot_typename) || SS.isInvalid()) ? ANK_Unresolved : ANK_Success;
+    // HLSL Change End
   }
 
   IdentifierInfo *Name = Tok.getIdentifierInfo();

+ 15 - 0
tools/clang/test/CodeGenHLSL/quick-test/default-matrix-in-template.hlsl

@@ -0,0 +1,15 @@
+// RUN: %dxc -E main -T cs_6_0 %s  | FileCheck %s
+
+// CHECK: %class.StructuredBuffer = type { %class.matrix.float.4.4 }
+
+StructuredBuffer<matrix> buf1;
+// Should be equivalent to:
+// StructuredBuffer<matrix<float, 4, 4> > buf1;
+
+RWBuffer<float4> buf2;
+
+[RootSignature("DescriptorTable(SRV(t0), UAV(u0))")]
+[numthreads(8, 8, 1)]
+void main(uint3 tid : SV_DispatchThreadID) {
+  buf2[tid.x] = buf1[tid.x][tid.y];
+}