Author: Xiang Li Date: 2024-08-31T11:23:34-04:00 New Revision: e41579a31f77008eb76c418df5d192d0974421d2
URL: https://github.com/llvm/llvm-project/commit/e41579a31f77008eb76c418df5d192d0974421d2 DIFF: https://github.com/llvm/llvm-project/commit/e41579a31f77008eb76c418df5d192d0974421d2.diff LOG: [HLSL] AST support for WaveSize attribute. (#101240) First step for support WaveSize attribute in https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_WaveSize.html and https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html A new attribute HLSLWaveSizeAttr was supported in the AST. Implement both the wave size and the wave size range, rather than separately which might require more work. For #70118 Added: clang/test/AST/HLSL/WaveSize.hlsl clang/test/SemaHLSL/WaveSize-invalid-param.hlsl clang/test/SemaHLSL/WaveSize-invalid-profiles.hlsl clang/test/SemaHLSL/WaveSize-sm6.6-6.5.hlsl Modified: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/SemaHLSL.h clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaHLSL.cpp llvm/include/llvm/Support/DXILABI.h Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a83e908899c83b..0d4256433365c4 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4651,6 +4651,22 @@ def HLSLParamModifier : TypeAttr { let Args = [DefaultBoolArgument<"MergedSpelling", /*default*/0, /*fake*/1>]; } +def HLSLWaveSize: InheritableAttr { + let Spellings = [Microsoft<"WaveSize">]; + let Args = [IntArgument<"Min">, DefaultIntArgument<"Max", 0>, DefaultIntArgument<"Preferred", 0>]; + let Subjects = SubjectList<[HLSLEntry]>; + let LangOpts = [HLSL]; + let AdditionalMembers = [{ + private: + int SpelledArgsCount = 0; + + public: + void setSpelledArgsCount(int C) { SpelledArgsCount = C; } + int getSpelledArgsCount() const { return SpelledArgsCount; } + }]; + let Documentation = [WaveSizeDocs]; +} + def RandomizeLayout : InheritableAttr { let Spellings = [GCC<"randomize_layout">]; let Subjects = SubjectList<[Record]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index c2b9d7cb93c309..ef077db298831f 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7421,6 +7421,43 @@ flag. }]; } +def WaveSizeDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``WaveSize`` attribute specify a wave size on a shader entry point in order +to indicate either that a shader depends on or strongly prefers a specific wave +size. +There're 2 versions of the attribute: ``WaveSize`` and ``RangedWaveSize``. +The syntax for ``WaveSize`` is: + +.. code-block:: text + + ``[WaveSize(<numLanes>)]`` + +The allowed wave sizes that an HLSL shader may specify are the powers of 2 +between 4 and 128, inclusive. +In other words, the set: [4, 8, 16, 32, 64, 128]. + +The syntax for ``RangedWaveSize`` is: + +.. code-block:: text + + ``[WaveSize(<minWaveSize>, <maxWaveSize>, [prefWaveSize])]`` + +Where minWaveSize is the minimum wave size supported by the shader representing +the beginning of the allowed range, maxWaveSize is the maximum wave size +supported by the shader representing the end of the allowed range, and +prefWaveSize is the optional preferred wave size representing the size expected +to be the most optimal for this shader. + +``WaveSize`` is available for HLSL shader model 6.6 and later. +``RangedWaveSize`` available for HLSL shader model 6.8 and later. + +The full documentation is available here: https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_WaveSize.html +and https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html + }]; +} + def NumThreadsDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 28d315f63e5c47..c4c29942ee1cbd 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1550,6 +1550,9 @@ def HLSLAvailability : DiagGroup<"hlsl-availability">; // Warnings for legacy binding behavior def LegacyConstantRegisterBinding : DiagGroup<"legacy-constant-register-binding">; +// Warning for HLSL Attributes on Statement. +def HLSLAttributeStatement : DiagGroup<"attribute-statement">; + // Warnings and notes related to const_var_decl_type attribute checks def ReadOnlyPlacementChecks : DiagGroup<"read-only-types">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index edf22b909c4d57..2e759b5b67b68d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12384,6 +12384,16 @@ def warn_hlsl_availability_unavailable : def err_hlsl_export_not_on_function : Error< "export declaration can only be used on functions">; +def err_hlsl_attribute_in_wrong_shader_model: Error< + "attribute %0 requires shader model %1 or greater">; + +def warn_attr_min_eq_max: Warning< + "%0 attribute minimum and maximum arguments are equal">, + InGroup<HLSLAttributeStatement>, DefaultError; + +def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error< + "attribute %0 with %1 arguments requires shader model %2 or greater">; + // Layout randomization diagnostics. def err_non_designated_init_used : Error< "a randomized struct can only be initialized with a designated initializer">; diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 363a3ee6b4c1f2..210eb1167aa6ef 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -37,6 +37,9 @@ class SemaHLSL : public SemaBase { HLSLNumThreadsAttr *mergeNumThreadsAttr(Decl *D, const AttributeCommonInfo &AL, int X, int Y, int Z); + HLSLWaveSizeAttr *mergeWaveSizeAttr(Decl *D, const AttributeCommonInfo &AL, + int Min, int Max, int Preferred, + int SpelledArgsCount); HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, llvm::Triple::EnvironmentType ShaderType); HLSLParamModifierAttr * @@ -52,6 +55,7 @@ class SemaHLSL : public SemaBase { void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU); void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); + void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6327ae9b99aa4c..69b793b987e42c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2863,6 +2863,10 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D, else if (const auto *NT = dyn_cast<HLSLNumThreadsAttr>(Attr)) NewAttr = S.HLSL().mergeNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), NT->getZ()); + else if (const auto *WS = dyn_cast<HLSLWaveSizeAttr>(Attr)) + NewAttr = S.HLSL().mergeWaveSizeAttr(D, *WS, WS->getMin(), WS->getMax(), + WS->getPreferred(), + WS->getSpelledArgsCount()); else if (const auto *SA = dyn_cast<HLSLShaderAttr>(Attr)) NewAttr = S.HLSL().mergeShaderAttr(D, *SA, SA->getType()); else if (isa<SuppressAttr>(Attr)) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 1e074298ac5289..33547c2e6e1452 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6886,6 +6886,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLNumThreads: S.HLSL().handleNumThreadsAttr(D, AL); break; + case ParsedAttr::AT_HLSLWaveSize: + S.HLSL().handleWaveSizeAttr(D, AL); + break; case ParsedAttr::AT_HLSLSV_GroupIndex: handleSimpleAttribute<HLSLSV_GroupIndexAttr>(S, D, AL); break; diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 65972987458d70..1373c2ea034bf5 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/DXILABI.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/TargetParser/Triple.h" #include <iterator> @@ -153,6 +154,25 @@ HLSLNumThreadsAttr *SemaHLSL::mergeNumThreadsAttr(Decl *D, HLSLNumThreadsAttr(getASTContext(), AL, X, Y, Z); } +HLSLWaveSizeAttr *SemaHLSL::mergeWaveSizeAttr(Decl *D, + const AttributeCommonInfo &AL, + int Min, int Max, int Preferred, + int SpelledArgsCount) { + if (HLSLWaveSizeAttr *WS = D->getAttr<HLSLWaveSizeAttr>()) { + if (WS->getMin() != Min || WS->getMax() != Max || + WS->getPreferred() != Preferred || + WS->getSpelledArgsCount() != SpelledArgsCount) { + Diag(WS->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL; + Diag(AL.getLoc(), diag::note_conflicting_attribute); + } + return nullptr; + } + HLSLWaveSizeAttr *Result = ::new (getASTContext()) + HLSLWaveSizeAttr(getASTContext(), AL, Min, Max, Preferred); + Result->setSpelledArgsCount(SpelledArgsCount); + return Result; +} + HLSLShaderAttr * SemaHLSL::mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, llvm::Triple::EnvironmentType ShaderType) { @@ -224,7 +244,8 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) { const auto *ShaderAttr = FD->getAttr<HLSLShaderAttr>(); assert(ShaderAttr && "Entry point has no shader attribute"); llvm::Triple::EnvironmentType ST = ShaderAttr->getType(); - + auto &TargetInfo = getASTContext().getTargetInfo(); + VersionTuple Ver = TargetInfo.getTriple().getOSVersion(); switch (ST) { case llvm::Triple::Pixel: case llvm::Triple::Vertex: @@ -244,6 +265,13 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) { llvm::Triple::Mesh}); FD->setInvalidDecl(); } + if (const auto *WS = FD->getAttr<HLSLWaveSizeAttr>()) { + DiagnoseAttrStageMismatch(WS, ST, + {llvm::Triple::Compute, + llvm::Triple::Amplification, + llvm::Triple::Mesh}); + FD->setInvalidDecl(); + } break; case llvm::Triple::Compute: @@ -254,6 +282,19 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) { << llvm::Triple::getEnvironmentTypeName(ST); FD->setInvalidDecl(); } + if (const auto *WS = FD->getAttr<HLSLWaveSizeAttr>()) { + if (Ver < VersionTuple(6, 6)) { + Diag(WS->getLocation(), diag::err_hlsl_attribute_in_wrong_shader_model) + << WS << "6.6"; + FD->setInvalidDecl(); + } else if (WS->getSpelledArgsCount() > 1 && Ver < VersionTuple(6, 8)) { + Diag( + WS->getLocation(), + diag::err_hlsl_attribute_number_arguments_insufficient_shader_model) + << WS << WS->getSpelledArgsCount() << "6.8"; + FD->setInvalidDecl(); + } + } break; default: llvm_unreachable("Unhandled environment in triple"); @@ -357,6 +398,74 @@ void SemaHLSL::handleNumThreadsAttr(Decl *D, const ParsedAttr &AL) { D->addAttr(NewAttr); } +static bool isValidWaveSizeValue(unsigned Value) { + return llvm::isPowerOf2_32(Value) && Value >= 4 && Value <= 128; +} + +void SemaHLSL::handleWaveSizeAttr(Decl *D, const ParsedAttr &AL) { + // validate that the wavesize argument is a power of 2 between 4 and 128 + // inclusive + unsigned SpelledArgsCount = AL.getNumArgs(); + if (SpelledArgsCount == 0 || SpelledArgsCount > 3) + return; + + uint32_t Min; + if (!SemaRef.checkUInt32Argument(AL, AL.getArgAsExpr(0), Min)) + return; + + uint32_t Max = 0; + if (SpelledArgsCount > 1 && + !SemaRef.checkUInt32Argument(AL, AL.getArgAsExpr(1), Max)) + return; + + uint32_t Preferred = 0; + if (SpelledArgsCount > 2 && + !SemaRef.checkUInt32Argument(AL, AL.getArgAsExpr(2), Preferred)) + return; + + if (SpelledArgsCount > 2) { + if (!isValidWaveSizeValue(Preferred)) { + Diag(AL.getArgAsExpr(2)->getExprLoc(), + diag::err_attribute_power_of_two_in_range) + << AL << llvm::dxil::MinWaveSize << llvm::dxil::MaxWaveSize + << Preferred; + return; + } + // Preferred not in range. + if (Preferred < Min || Preferred > Max) { + Diag(AL.getArgAsExpr(2)->getExprLoc(), + diag::err_attribute_power_of_two_in_range) + << AL << Min << Max << Preferred; + return; + } + } else if (SpelledArgsCount > 1) { + if (!isValidWaveSizeValue(Max)) { + Diag(AL.getArgAsExpr(1)->getExprLoc(), + diag::err_attribute_power_of_two_in_range) + << AL << llvm::dxil::MinWaveSize << llvm::dxil::MaxWaveSize << Max; + return; + } + if (Max < Min) { + Diag(AL.getLoc(), diag::err_attribute_argument_invalid) << AL << 1; + return; + } else if (Max == Min) { + Diag(AL.getLoc(), diag::warn_attr_min_eq_max) << AL; + } + } else { + if (!isValidWaveSizeValue(Min)) { + Diag(AL.getArgAsExpr(0)->getExprLoc(), + diag::err_attribute_power_of_two_in_range) + << AL << llvm::dxil::MinWaveSize << llvm::dxil::MaxWaveSize << Min; + return; + } + } + + HLSLWaveSizeAttr *NewAttr = + mergeWaveSizeAttr(D, AL, Min, Max, Preferred, SpelledArgsCount); + if (NewAttr) + D->addAttr(NewAttr); +} + static bool isLegalTypeForHLSLSV_DispatchThreadID(QualType T) { if (!T->hasUnsignedIntegerRepresentation()) return false; diff --git a/clang/test/AST/HLSL/WaveSize.hlsl b/clang/test/AST/HLSL/WaveSize.hlsl new file mode 100644 index 00000000000000..44a7bfab1788b5 --- /dev/null +++ b/clang/test/AST/HLSL/WaveSize.hlsl @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-library -x hlsl -ast-dump -o - %s | FileCheck %s + +// CHECK-LABLE:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> w0 'void ()' +// CHECK:HLSLWaveSizeAttr 0x{{[0-9a-f]+}} <{{.*}}> 128 0 0 + [numthreads(8,8,1)] + [WaveSize(128)] + void w0() { + } + + + +// CHECK-LABLE:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> w1 'void ()' +// CHECK:HLSLWaveSizeAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 64 0 + [numthreads(8,8,1)] + [WaveSize(8, 64)] + void w1() { + } + + +// CHECK-LABLE:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> w2 'void ()' +// CHECK:HLSLWaveSizeAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 128 64 +// Duplicate WaveSize attribute will be ignored. +// CHECK-NOT:HLSLWaveSizeAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 128 64 + [numthreads(8,8,1)] + [WaveSize(8, 128, 64)] + [WaveSize(8, 128, 64)] + void w2() { + } diff --git a/clang/test/SemaHLSL/WaveSize-invalid-param.hlsl b/clang/test/SemaHLSL/WaveSize-invalid-param.hlsl new file mode 100644 index 00000000000000..e10be5a94df517 --- /dev/null +++ b/clang/test/SemaHLSL/WaveSize-invalid-param.hlsl @@ -0,0 +1,111 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-library -x hlsl %s -verify + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 1}} +[WaveSize(1)] +void e0() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 2}} +[WaveSize(4, 2)] +void e1() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 7}} +[WaveSize(4, 8, 7)] +void e2() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute argument is invalid: min must not be greater than max}} +[WaveSize(16, 8)] +void e3() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 16 and 128 inclusive; provided argument was 8}} +[WaveSize(16, 128, 8)] +void e4() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 8 and 16 inclusive; provided argument was 32}} +[WaveSize(8, 16, 32)] +void e5() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 0}} +[WaveSize(4, 0)] +void e6() { +} + + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 0}} +[WaveSize(4, 4, 0)] +void e7() { +} + + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute minimum and maximum arguments are equal}} +[WaveSize(16, 16)] +void e8() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 0}} +[WaveSize(0)] +void e9() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute requires an integer argument which is a constant power of two between 4 and 128 inclusive; provided argument was 4294967292}} +[WaveSize(-4)] +void e10() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute takes no more than 3 arguments}} +[WaveSize(16, 128, 64, 64)] +void e11() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute takes at least 1 argument}} +[WaveSize()] +void e12() { +} + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute takes at least 1 argument}} +[WaveSize] +void e13() { +} + + +[shader("compute")] +[numthreads(1,1,1)] +// expected-error@+1 {{'WaveSize' attribute parameters do not match the previous declaration}} +[WaveSize(8)] +// expected-note@+1 {{conflicting attribute is here}} +[WaveSize(16)] +void e14() { +} diff --git a/clang/test/SemaHLSL/WaveSize-invalid-profiles.hlsl b/clang/test/SemaHLSL/WaveSize-invalid-profiles.hlsl new file mode 100644 index 00000000000000..f14c0141816fd9 --- /dev/null +++ b/clang/test/SemaHLSL/WaveSize-invalid-profiles.hlsl @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-pixel -x hlsl %s -verify +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-vertex -x hlsl %s -verify +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-geometry -x hlsl %s -verify +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-hull -x hlsl %s -verify +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.8-domain -x hlsl %s -verify + +#if __SHADER_TARGET_STAGE == __SHADER_STAGE_PIXEL +// expected-error@#WaveSize {{attribute 'WaveSize' is unsupported in 'pixel' shaders, requires one of the following: compute, amplification, mesh}} +#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_VERTEX +// expected-error@#WaveSize {{attribute 'WaveSize' is unsupported in 'vertex' shaders, requires one of the following: compute, amplification, mesh}} +#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_GEOMETRY +// expected-error@#WaveSize {{attribute 'WaveSize' is unsupported in 'geometry' shaders, requires one of the following: compute, amplification, mesh}} +#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_HULL +// expected-error@#WaveSize {{attribute 'WaveSize' is unsupported in 'hull' shaders, requires one of the following: compute, amplification, mesh}} +#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_DOMAIN +// expected-error@#WaveSize {{attribute 'WaveSize' is unsupported in 'domain' shaders, requires one of the following: compute, amplification, mesh}} +#endif +[WaveSize(16)] // #WaveSize +void main() { +} diff --git a/clang/test/SemaHLSL/WaveSize-sm6.6-6.5.hlsl b/clang/test/SemaHLSL/WaveSize-sm6.6-6.5.hlsl new file mode 100644 index 00000000000000..c6718cfec8ef4c --- /dev/null +++ b/clang/test/SemaHLSL/WaveSize-sm6.6-6.5.hlsl @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -x hlsl %s -verify +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.5-library -x hlsl %s -verify + +[shader("compute")] +[numthreads(1,1,1)] +#if __SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR == 6 +// expected-error@+4 {{attribute 'WaveSize' with 3 arguments requires shader model 6.8 or greater}} +#elif __SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR == 5 +// expected-error@+2 {{attribute 'WaveSize' requires shader model 6.6 or greater}} +#endif +[WaveSize(4, 16, 8)] +void e0() { +} + +[shader("compute")] +[numthreads(1,1,1)] +#if __SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR == 6 +// expected-error@+4 {{attribute 'WaveSize' with 2 arguments requires shader model 6.8 or greater}} +#elif __SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR == 5 +// expected-error@+2 {{attribute 'WaveSize' requires shader model 6.6 or greater}} +#endif +[WaveSize(4, 16)] +void e1() { +} diff --git a/llvm/include/llvm/Support/DXILABI.h b/llvm/include/llvm/Support/DXILABI.h index cf2c42c689889d..b479f7c73eba36 100644 --- a/llvm/include/llvm/Support/DXILABI.h +++ b/llvm/include/llvm/Support/DXILABI.h @@ -96,6 +96,9 @@ enum class SamplerFeedbackType : uint32_t { MipRegionUsed = 1, }; +const unsigned MinWaveSize = 4; +const unsigned MaxWaveSize = 128; + } // namespace dxil } // namespace llvm _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits