[clang] 43a9b92 - [Sema][HLSL] Fix naming of anyhit/closesthit shaders

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 25 13:17:31 PDT 2023


Author: Justin Bogner
Date: 2023-08-25T13:08:36-07:00
New Revision: 43a9b92d79ab6a59c3cfaa926bb32f161ef2facc

URL: https://github.com/llvm/llvm-project/commit/43a9b92d79ab6a59c3cfaa926bb32f161ef2facc
DIFF: https://github.com/llvm/llvm-project/commit/43a9b92d79ab6a59c3cfaa926bb32f161ef2facc.diff

LOG: [Sema][HLSL] Fix naming of anyhit/closesthit shaders

Also test all shader types and be a bit more careful to make shaders
reasonably valid in these tests.

Differential Revision: https://reviews.llvm.org/D158820

Added: 
    clang/test/SemaHLSL/valid-shader-stages.hlsl

Modified: 
    clang/include/clang/Basic/Attr.td
    clang/test/SemaHLSL/entry_shader.hlsl
    clang/test/SemaHLSL/shader_type_attr.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 8623bf1bb87b77..f7d19a3df25176 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4143,8 +4143,8 @@ def HLSLShader : InheritableAttr {
     EnumArgument<"Type", "ShaderType",
                  [
                    "pixel", "vertex", "geometry", "hull", "domain", "compute",
-                   "library", "raygeneration", "intersection", "anyHit",
-                   "closestHit", "miss", "callable", "mesh", "amplification"
+                   "library", "raygeneration", "intersection", "anyhit",
+                   "closesthit", "miss", "callable", "mesh", "amplification"
                  ],
                  [
                    "Pixel", "Vertex", "Geometry", "Hull", "Domain", "Compute",
@@ -4232,4 +4232,3 @@ def AvailableOnlyInDefaultEvalMethod : InheritableAttr {
   let Subjects = SubjectList<[TypedefName], ErrorDiag>;
   let Documentation = [Undocumented];
 }
-

diff  --git a/clang/test/SemaHLSL/entry_shader.hlsl b/clang/test/SemaHLSL/entry_shader.hlsl
index 75279f5e562d70..0ed6c0c9d417ec 100644
--- a/clang/test/SemaHLSL/entry_shader.hlsl
+++ b/clang/test/SemaHLSL/entry_shader.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"anyHit"' -verify
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"mesh"' -verify
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-compute -x hlsl -hlsl-entry foo  -o - %s -DSHADER='"compute"'
 
 // expected-error at +1 {{'shader' attribute on entry function does not match the target profile}}

diff  --git a/clang/test/SemaHLSL/shader_type_attr.hlsl b/clang/test/SemaHLSL/shader_type_attr.hlsl
index 2582aaad2907c8..d497b0582d1a72 100644
--- a/clang/test/SemaHLSL/shader_type_attr.hlsl
+++ b/clang/test/SemaHLSL/shader_type_attr.hlsl
@@ -28,7 +28,7 @@ static void oops() {}
 } // namespace spec
 
 // expected-error at +1 {{'shader' attribute parameters do not match the previous declaration}}
-[shader("compute")]
+[shader("pixel")]
 // expected-note at +1 {{conflicting attribute is here}}
 [shader("vertex")]
 int doubledUp() {
@@ -40,7 +40,7 @@ int doubledUp() {
 int forwardDecl();
 
 // expected-error at +1 {{'shader' attribute parameters do not match the previous declaration}}
-[shader("compute")]
+[shader("compute")][numthreads(8,1,1)]
 int forwardDecl() {
   return 1;
 }
@@ -57,19 +57,22 @@ int forwardDecl() {
 [shader("library")]
 #endif // END of FAIL
 
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}} <line:61:2, col:18> Compute
-[shader("compute")]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}} <line:62:2, col:18> Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <col:21, col:37> 8 1 1
+[shader("compute")][numthreads(8,1,1)]
 int entry() {
   return 1;
 }
 
 // Because these two attributes match, they should both appear in the AST
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}} <line:67:2, col:18> Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}} <line:68:2, col:18> Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <col:21, col:37> 8 1 1
 int secondFn();
 
-[shader("compute")]
-// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}} <line:71:2, col:18> Compute
+[shader("compute")][numthreads(8,1,1)]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}} <line:73:2, col:18> Compute
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <col:21, col:37> 8 1 1
 int secondFn() {
   return 1;
 }

diff  --git a/clang/test/SemaHLSL/valid-shader-stages.hlsl b/clang/test/SemaHLSL/valid-shader-stages.hlsl
new file mode 100644
index 00000000000000..523500c77c0abf
--- /dev/null
+++ b/clang/test/SemaHLSL/valid-shader-stages.hlsl
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -finclude-default-header -o - %s -verify
+
+// expected-no-diagnostics
+
+[shader("pixel")] void pixel() {}
+[shader("vertex")] void vertex() {}
+[shader("raygeneration")] void raygeneration() {}
+[shader("intersection")] void intersection() {}
+
+[numthreads(1,1,1)][shader("compute")] void compute() {}
+[numthreads(1,1,1)][shader("mesh")] void mesh() {}
+
+// Note: the rest of these have additional constraints that aren't implemented
+// yet, so here we just declare them to make sure the spelling works and
+// whatnot.
+[shader("geometry")] void geometry();
+[shader("hull")] void hull();
+[shader("domain")] void domain();
+[shader("callable")] void callable();
+[shader("closesthit")] void closesthit();
+[shader("anyhit")] void anyhit();
+[shader("miss")] void miss();
+
+[numthreads(1,1,1)][shader("amplification")] void amplification();


        


More information about the cfe-commits mailing list